private void RecomputeData()
        {
            NumericUpDown[] targetApertures = new NumericUpDown[] { nudAperture1, nudAperture2, nudAperture3, nudAperture4 };
            NumericUpDown[] targetFitAreas  = new NumericUpDown[] { nudFitArea1, nudFitArea2, nudFitArea3, nudFitArea4 };
            PictureBox[]    psfBoxes        = new PictureBox[] { picTarget1PSF, picTarget2PSF, picTarget3PSF, picTarget4PSF };

            MeasurementsHelper measurer = new MeasurementsHelper(
                m_Context.BitPix,
                m_Context.BackgroundMethod,
                TangraConfig.Settings.Photometry.SubPixelSquareSize,
                TangraConfig.Settings.Photometry.Saturation.GetSaturationForBpp(m_Context.BitPix, m_Context.MaxPixelValue));

            for (int i = 0; i < m_Header.ObjectCount; i++)
            {
                // Apply the selected filter, compute the PSF and then draw the data
                LCMeasurement reading = m_SelectedMeasurements[i];
                if (!LCMeasurement.IsEmpty(reading))
                {
                    LCMeasurement updatedReading = reading.Clone();

                    int x0Int = (int)Math.Round(reading.X0);
                    int y0Int = (int)Math.Round(reading.Y0);

                    updatedReading.PsfFit = new PSFFit(x0Int, y0Int);
                    updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit;
                    int pixelDataWidth  = updatedReading.PixelData.GetLength(0);
                    int pixelDataHeight = updatedReading.PixelData.GetLength(1);
                    updatedReading.PsfFit.Fit(
                        updatedReading.PixelData,
                        m_Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize,
                        x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1,
                        y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1,
                        false);


                    int fitArea = (int)targetFitAreas[i].Value;
                    measurer.FindBestFit(
                        reading.X0, reading.Y0,
                        GetCurrentFilter(), reading.PixelData, m_Context.BitPix,
                        ref fitArea, m_Header.FixedApertureFlags[i]);

                    updatedReading.PsfFit = measurer.FoundBestPSFFit;

                    updatedReading.PixelData  = measurer.PixelData;
                    m_SelectedMeasurements[i] = updatedReading;

                    psfBoxes[reading.TargetNo].Visible = true;
                    PlotSingleGaussian(
                        psfBoxes[reading.TargetNo],
                        updatedReading,
                        m_AllBrushes,
                        (float)targetApertures[i].Value,
                        m_Footer.ReductionContext.BitPix);
                }
            }
        }
Пример #2
0
        internal void HandleNewSelectedFrame(LCMeasurement[] selectedMeasurements)
        {
            m_SelectedMeasurements = selectedMeasurements;

            if (m_SelectedMeasurements != null)
            {
                for (int i = 0; i < m_SelectedMeasurements.Length; i++)
                {
                    LCMeasurement reading = m_SelectedMeasurements[i];
                    if (!LCMeasurement.IsEmpty(reading) &&
                        reading.TargetNo >= 0 &&
                        reading.TargetNo <= 3)
                    {
                        LCMeasurement updatedReading = reading.Clone();

                        int x0Int = (int)Math.Round(reading.X0);
                        int y0Int = (int)Math.Round(reading.Y0);

                        updatedReading.PsfFit = new PSFFit(x0Int, y0Int);
                        updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit;
                        int pixelDataWidth  = updatedReading.PixelData.GetLength(0);
                        int pixelDataHeight = updatedReading.PixelData.GetLength(1);

                        uint[,] pixelData = GetPixelData(updatedReading.PixelData);
                        updatedReading.PsfFit.Fit(
                            pixelData,
                            m_LCFile.Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize,
                            x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1,
                            y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1,
                            false);

                        PlotSingleGaussian(
                            m_TargetBoxes[reading.TargetNo],
                            updatedReading,
                            m_DisplaySettings.TargetBrushes,
                            m_LCFile.Footer.TrackedObjects[updatedReading.TargetNo].ApertureInPixels,
                            m_LCFile.Footer.ReductionContext.BitPix);
                    }
                    else
                    {
                        Bitmap bmp = m_TargetBoxes[i].Image as Bitmap;
                        if (bmp != null)
                        {
                            using (Graphics g = Graphics.FromImage(bmp))
                            {
                                g.Clear(m_DisplaySettings.BackgroundColor);
                                g.Save();
                            }
                        }
                        m_TargetBoxes[i].Refresh();
                    }
                }
            }
        }
        private void PlotMeasuredPixels()
        {
            if (!TangraContext.Current.CanProcessLightCurvePixels)
            {
                return;
            }

            PictureBox[]    targetBoxes     = new PictureBox[] { picTarget1Pixels, picTarget2Pixels, picTarget3Pixels, picTarget4Pixels };
            NumericUpDown[] targetApertures = new NumericUpDown[] { nudAperture1, nudAperture2, nudAperture3, nudAperture4 };
            NumericUpDown[] targetFitAreas  = new NumericUpDown[] { nudFitArea1, nudFitArea2, nudFitArea3, nudFitArea4 };

            uint allObjectsPeak = 0;

            for (int i = 0; i < m_SelectedMeasurements.Length; i++)
            {
                LCMeasurement reading = m_SelectedMeasurements[i];
                if (!LCMeasurement.IsEmpty(reading) &&
                    reading.TargetNo >= 0 &&
                    reading.TargetNo <= 3)
                {
                    for (int x = 0; x < 17; x++)
                    {
                        for (int y = 0; y < 17; y++)
                        {
                            // This is what is needed to get a 17x17 area in the middle of the 35x35 pixel data
                            uint pix = reading.PixelData[x + 9, y + 9];

                            if (allObjectsPeak < pix)
                            {
                                allObjectsPeak = pix;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < m_SelectedMeasurements.Length; i++)
            {
                LCMeasurement reading = m_SelectedMeasurements[i];
                if (!LCMeasurement.IsEmpty(reading) &&
                    reading.TargetNo >= 0 &&
                    reading.TargetNo <= 3)
                {
                    PlotSingleTargetPixels(
                        targetBoxes[reading.TargetNo],
                        reading,
                        (double)targetApertures[reading.TargetNo].Value,
                        (int)targetFitAreas[reading.TargetNo].Value,
                        allObjectsPeak);
                }
            }
        }
        private void PlotGaussians()
        {
            PictureBox[]    psfBoxes        = new PictureBox[] { picTarget1PSF, picTarget2PSF, picTarget3PSF, picTarget4PSF };
            NumericUpDown[] targetApertures = new NumericUpDown[] { nudAperture1, nudAperture2, nudAperture3, nudAperture4 };

            Label[] fwhmLabels = new Label[] { lblFWHM1, lblFWHM2, lblFWHM3, lblFWHM4 };

            for (int i = 0; i < m_SelectedMeasurements.Length; i++)
            {
                LCMeasurement reading = m_SelectedMeasurements[i];
                if (!LCMeasurement.IsEmpty(reading) &&
                    reading.TargetNo >= 0 &&
                    reading.TargetNo <= 3)
                {
                    LCMeasurement updatedReading = reading.Clone();

                    int x0Int = (int)Math.Round(reading.X0);
                    int y0Int = (int)Math.Round(reading.Y0);

                    updatedReading.PsfFit = new PSFFit(x0Int, y0Int);
                    updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit;
                    int pixelDataWidth  = updatedReading.PixelData.GetLength(0);
                    int pixelDataHeight = updatedReading.PixelData.GetLength(1);
                    updatedReading.PsfFit.Fit(
                        updatedReading.PixelData,
                        m_Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize,
                        x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1,
                        y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1,
                        false);

                    psfBoxes[reading.TargetNo].Visible = true;
                    PlotSingleGaussian(
                        psfBoxes[reading.TargetNo],
                        updatedReading,
                        m_AllBrushes,
                        (float)targetApertures[i].Value,
                        m_Footer.ReductionContext.BitPix);

                    fwhmLabels[updatedReading.TargetNo].Text =
                        string.Format("{0} px = {1} FWHM",
                                      targetApertures[updatedReading.TargetNo].Value.ToString("0.00"),
                                      ((double)targetApertures[updatedReading.TargetNo].Value / updatedReading.PsfFit.FWHM).ToString("0.0"));
                }
                else
                {
                    psfBoxes[i].Visible = false;
                    fwhmLabels[i].Text  = string.Empty;
                }
            }
        }
Пример #5
0
        private void PlotMeasuredPixels()
        {
            if (!TangraContext.Current.CanProcessLightCurvePixels)
            {
                return;
            }

            var targetBoxes = new PictureBox[] { picTarget1Pixels, picTarget2Pixels, picTarget3Pixels, picTarget4Pixels };

            if (m_AllObjectsPeak == 0)
            {
                if (m_SelectedMeasurements != null)
                {
                    for (int i = 0; i < m_SelectedMeasurements.Length; i++)
                    {
                        LCMeasurement reading = m_SelectedMeasurements[i];
                        if (!LCMeasurement.IsEmpty(reading) &&
                            reading.TargetNo >= 0 &&
                            reading.TargetNo <= 3)
                        {
                            uint[,] pixelsToDraw = GetPixelData(reading.PixelData);
                            for (int x = 0; x < 35; x++)
                            {
                                for (int y = 0; y < 35; y++)
                                {
                                    uint pix = pixelsToDraw[x, y];

                                    if (m_AllObjectsPeak < pix)
                                    {
                                        m_AllObjectsPeak = pix;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < m_LCFile.Header.ObjectCount; i++)
            {
                LCMeasurement reading = m_SelectedMeasurements != null ? m_SelectedMeasurements[i] : LCMeasurement.Empty;
                if (!LCMeasurement.IsEmpty(reading) &&
                    reading.TargetNo >= 0 &&
                    reading.TargetNo <= 3)
                {
                    PlotSingleTargetPixels(targetBoxes[reading.TargetNo], reading.TargetNo, reading, m_AllObjectsPeak);

                    if (cbxDrawApertures.Checked)
                    {
                        string message   = m_SelectedMeasurements[i].GetFlagsExplained().Trim();
                        bool   isWarning = false;
                        if (message != null)
                        {
                            if (message.Contains("W:"))
                            {
                                isWarning = true;
                                message   = message.Replace("W:", "");
                                message   = message.Replace("I:", "");
                            }
                            else
                            {
                                message = message.Replace("I:", "");
                            }
                        }
                        if (isWarning)
                        {
                            warningProvider.SetError(targetBoxes[reading.TargetNo], message);
                        }
                        else
                        {
                            infoProvider.SetError(targetBoxes[reading.TargetNo], message);
                        }
                    }
                    else
                    {
                        warningProvider.SetError(targetBoxes[reading.TargetNo], null);
                        infoProvider.SetError(targetBoxes[reading.TargetNo], null);
                    }
                }
                else
                {
                    Bitmap bmp = targetBoxes[i].Image as Bitmap;
                    if (bmp != null)
                    {
                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            g.Clear(m_DisplaySettings.BackgroundColor);
                            g.Save();
                        }
                    }
                    targetBoxes[i].Refresh();
                }
            }
        }
Пример #6
0
        internal void HandleNewSelectedFrame(LCMeasurement[] selectedMeasurements)
        {
            m_SelectedMeasurements = selectedMeasurements;

            if (m_SelectedMeasurements != null)
            {
                for (int i = 0; i < m_SelectedMeasurements.Length; i++)
                {
                    LCMeasurement reading = m_SelectedMeasurements[i];
                    if (!LCMeasurement.IsEmpty(reading) &&
                        reading.TargetNo >= 0 &&
                        reading.TargetNo <= 3)
                    {
                        LCMeasurement updatedReading = reading.Clone();

                        int pixelDataWidth  = updatedReading.PixelData.GetLength(0);
                        int pixelDataHeight = updatedReading.PixelData.GetLength(1);



                        Dictionary <uint, int> histogram = new Dictionary <uint, int>();
                        for (uint j = 0; j <= m_Context.MaxPixelValue; j++)
                        {
                            histogram.Add(j, 0);
                        }

                        for (int x = 0; x < pixelDataWidth; x++)
                        {
                            for (int y = 0; y < pixelDataHeight; y++)
                            {
                                histogram[updatedReading.PixelData[x, y]]++;
                            }
                        }

                        // TODO: Plot the histogram, then the values for the PSF, Average and Background Mode on it

                        int x0Int = (int)Math.Round(reading.X0);
                        int y0Int = (int)Math.Round(reading.Y0);

                        updatedReading.PsfFit = new PSFFit(x0Int, y0Int);
                        updatedReading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit;

                        updatedReading.PsfFit.Fit(
                            updatedReading.PixelData,
                            m_LCFile.Footer.TrackedObjects[updatedReading.TargetNo].PsfFitMatrixSize,
                            x0Int - updatedReading.PixelDataX0 + (pixelDataWidth / 2) + 1,
                            y0Int - updatedReading.PixelDataY0 + (pixelDataHeight / 2) + 1,
                            false);

                        double psfBackground = updatedReading.PsfFit.I0;

                        float aperture = m_Context.ReProcessApertures[reading.TargetNo];


                        List <uint> allKeys = histogram.Keys.ToList();
                        foreach (uint key in allKeys)
                        {
                            histogram[key] = (int)Math.Round(100 * Math.Log(histogram[key] + 1));
                        }

                        DrawHistogram(m_TargetBoxes[reading.TargetNo], histogram);
                    }
                }
            }
        }