示例#1
0
        internal void SetCurrentMeasurements(LCMeasurement[] measurements, LightCurveContext context, int occultedStarIndex)
        {
            m_Context = context;
            m_OccultedStarIndex = occultedStarIndex;

            m_AllTargetColors = new Color[]
            {
                TangraConfig.Settings.Color.Target1,
                TangraConfig.Settings.Color.Target2,
                TangraConfig.Settings.Color.Target3,
                TangraConfig.Settings.Color.Target4
            };

            pb1.BackColor = m_AllTargetColors[0];
            pb2.BackColor = m_AllTargetColors[1];
            pb3.BackColor = m_AllTargetColors[2];
            pb4.BackColor = m_AllTargetColors[3];

            pnl1.Visible = false;
            pnl2.Visible = false;
            pnl3.Visible = false;
            pnl4.Visible = false;

            if (measurements == null || measurements.Length == 0)
            {
                int numFramesMedian = Math.Min(context.AllReadings[1].Count, TangraConfig.Settings.Photometry.SNFrameWindow);

                // If there is current selection then use the first reading from the LC file
                m_Intensities = new int[context.ObjectCount];
                m_Intensities[0] = context.AllReadings[0].Take(numFramesMedian).Select(x => x.AdjustedReading).ToList().Median();
                if (context.ObjectCount > 1) m_Intensities[1] = context.AllReadings[1].Take(numFramesMedian).Select(x => x.AdjustedReading).ToList().Median();
                if (context.ObjectCount > 2) m_Intensities[2] = context.AllReadings[2].Take(numFramesMedian).Select(x => x.AdjustedReading).ToList().Median();
                if (context.ObjectCount > 3) m_Intensities[3] = context.AllReadings[3].Take(numFramesMedian).Select(x => x.AdjustedReading).ToList().Median();
            }
        }
示例#2
0
        private void ProcessSingleUnitSet(
            List <LCMeasurement> units,
            bool useLowPass,
            bool useLowPassDiff,
            MeasurementsHelper measurer)
        {
            for (int i = 0; i < units.Count; i++)
            {
                LCMeasurement reading          = units[i];
                IImagePixel[] groupCenters     = new IImagePixel[0];
                float[]       aperturesInGroup = new float[0];

                TrackedObjectConfig        objConfig     = Footer.TrackedObjects[reading.TargetNo];
                List <TrackedObjectConfig> gropedObjects = Footer.TrackedObjects.Where(x => objConfig.GroupId >= 0 && x.GroupId == objConfig.GroupId).ToList();
                if (gropedObjects.Count > 1)
                {
                    groupCenters     = new IImagePixel[gropedObjects.Count];
                    aperturesInGroup = new float[gropedObjects.Count];

                    for (int j = 0; j < gropedObjects.Count; j++)
                    {
                        LCMeasurement mea = units[Footer.TrackedObjects.IndexOf(gropedObjects[j])];
                        groupCenters[j]     = new ImagePixel(mea.X0, mea.Y0);
                        aperturesInGroup[j] = gropedObjects[j].ApertureInPixels;
                    }
                }

                units[i] = ProcessSingleUnit(
                    reading, useLowPass, useLowPassDiff,
                    Context.ReProcessFitAreas[i], Context.ReProcessApertures[i], Header.FixedApertureFlags[i],
                    measurer, groupCenters, aperturesInGroup);
            }
        }
示例#3
0
        internal SingleMeasurement(LCMeasurement lcMeasurement, double frameNo, LCFile lcFile, bool dontIncludeTimes)
        {
            CurrFrameNo = (int)lcMeasurement.CurrFrameNo;
            TargetNo = lcMeasurement.TargetNo;
            Measurement = lcMeasurement.IsSuccessfulReading ? 1.0f * lcMeasurement.AdjustedReading : INVALID_MEASUREMENT_VALUE;
            Background = lcMeasurement.IsSuccessfulReading
                // NOTE: Make sure negative backgrounds are sent as negative values (not as the serialized UINTs)
                ? 1.0f * (int)lcMeasurement.TotalBackground
                : INVALID_MEASUREMENT_VALUE;
            string isCorrectedForInstrumentalDelay;

            if (dontIncludeTimes ||
                !lcFile.Footer.ReductionContext.HasEmbeddedTimeStamps /* If the times are entered by the user, only include the times for the frames enterred by the user*/)
            {
                Timestamp = DateTime.MinValue;
                isCorrectedForInstrumentalDelay = null;

                if ((int)frameNo == lcFile.Header.FirstTimedFrameNo)
                    Timestamp = lcFile.Header.FirstTimedFrameTime;
                else if ((int)frameNo == lcFile.Header.LastTimedFrameNo)
                    Timestamp = lcFile.Header.SecondTimedFrameTime;
            }
            else
            {
                Timestamp = lcFile.GetTimeForFrame(frameNo, out isCorrectedForInstrumentalDelay);
            }

            IsCorrectedForInstrumentalDelay = lcFile.Header.InstrumentalDelayCorrectionsNotRequired() || !string.IsNullOrEmpty(isCorrectedForInstrumentalDelay);
            IsSuccessful = lcMeasurement.IsSuccessfulReading;
        }
示例#4
0
        internal SingleMeasurement(LCMeasurement lcMeasurement, double frameNo, LCFile lcFile, bool dontIncludeTimes)
        {
            CurrFrameNo = (int)lcMeasurement.CurrFrameNo;
            TargetNo    = lcMeasurement.TargetNo;
            Measurement = lcMeasurement.IsSuccessfulReading ? 1.0f * lcMeasurement.AdjustedReading : INVALID_MEASUREMENT_VALUE;
            Background  = lcMeasurement.IsSuccessfulReading
                          // NOTE: Make sure negative backgrounds are sent as negative values (not as the serialized UINTs)
                                ? 1.0f * (int)lcMeasurement.TotalBackground
                                : INVALID_MEASUREMENT_VALUE;
            string isCorrectedForInstrumentalDelay;

            if (dontIncludeTimes ||
                !lcFile.Footer.ReductionContext.HasEmbeddedTimeStamps /* If the times are entered by the user, only include the times for the frames enterred by the user*/)
            {
                Timestamp = DateTime.MinValue;
                isCorrectedForInstrumentalDelay = null;

                if ((int)frameNo == lcFile.Header.FirstTimedFrameNo)
                {
                    Timestamp = lcFile.Header.FirstTimedFrameTime;
                }
                else if ((int)frameNo == lcFile.Header.LastTimedFrameNo)
                {
                    Timestamp = lcFile.Header.SecondTimedFrameTime;
                }
            }
            else
            {
                Timestamp = lcFile.GetTimeForFrame(frameNo, out isCorrectedForInstrumentalDelay);
            }

            IsCorrectedForInstrumentalDelay = lcFile.Header.InstrumentalDelayCorrectionsNotRequired() || !string.IsNullOrEmpty(isCorrectedForInstrumentalDelay);
            IsSuccessful = lcMeasurement.IsSuccessfulReading;
        }
示例#5
0
 internal LCFileSeriesEntry(int numObjects, uint frameNo, LCMeasurement measurement1, LCMeasurement measurement2, LCMeasurement measurement3, LCMeasurement measurement4)
 {
     NumObjects = numObjects;
     FrameNumber = frameNo;
     m_Measurement1 = measurement1;
     m_Measurement2 = measurement2;
     m_Measurement3 = measurement3;
     m_Measurement4 = measurement4;
 }
示例#6
0
 internal LCFileSeriesEntry(int numObjects, uint frameNo, LCMeasurement measurement1, LCMeasurement measurement2, LCMeasurement measurement3, LCMeasurement measurement4)
 {
     NumObjects     = numObjects;
     FrameNumber    = frameNo;
     m_Measurement1 = measurement1;
     m_Measurement2 = measurement2;
     m_Measurement3 = measurement3;
     m_Measurement4 = measurement4;
 }
        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);
                    }
                }
            }
        }
        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);
                }
            }
        }
示例#9
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();
                    }
                }
            }
        }
示例#10
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;
                }
            }
        }
示例#13
0
        internal static void PlotSingleGaussian(
			PictureBox pictureBox,
			LCMeasurement reading,
			Brush[] allBrushes,
			double aperture,
			int bpp)
        {
            Bitmap bmp = pictureBox.Image as Bitmap;
            if (bmp != null)
            {
                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

                using (Graphics g = Graphics.FromImage(bmp))
                {
                    reading.PsfFit.DrawInternalPoints(g, rect, (float)aperture, allBrushes[reading.TargetNo], bpp);
                    g.Save();
                }
            }

            pictureBox.Refresh();
        }
        internal static void PlotSingleGaussian(
            PictureBox pictureBox,
            LCMeasurement reading,
            Brush[] allBrushes,
            double aperture,
            int bpp)
        {
            Bitmap bmp = pictureBox.Image as Bitmap;

            if (bmp != null && reading.PsfFit != null)
            {
                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

                using (Graphics g = Graphics.FromImage(bmp))
                {
                    reading.PsfFit.DrawInternalPoints(g, rect, (float)aperture, allBrushes[reading.TargetNo], bpp);
                    g.Save();
                }
            }

            pictureBox.Refresh();
        }
示例#15
0
        public int[,] GetPixelArray(int frameNo, System.Drawing.Rectangle rect)
        {
            if (rect.Width != 32 || rect.Height != 32)
            {
                throw new NotSupportedException();
            }

            int[,] rv = new int[32, 32];

            if (frameNo >= m_LCFile.Header.MinFrame && frameNo < m_LCFile.Header.MaxFrame)
            {
                LCMeasurement mea = m_LCFile.Data[0][frameNo - (int)m_LCFile.Header.MinFrame];
                for (int x = 0; x < 32; x++)
                {
                    for (int y = 0; y < 32; y++)
                    {
                        rv[x, y] = (int)mea.PixelData[x, y]; // NOTE: PixelData is 35x35
                    }
                }
            }

            return(rv);
        }
        internal int SkipCurrentFrame(bool synchronise)
        {
            if (m_VideoController.CurrentFrameIndex < m_VideoController.VideoLastFrame)
            {
                m_TotalFrames++;

                m_ProcessedFrames++;
                if (!m_Tracker.IsTrackedSuccessfully) m_UnsuccessfulFrames++;
                if (m_Tracker.IsTrackedSuccessfully && m_Tracker.TrackedObjects.Any(x => !x.IsLocated))
                    m_PartiallySuccessfulFrames++;

                SaveEmbeddedOrORCedTimeStamp(m_CurrFrameNo);

                m_PrevMeasuredFrame = m_CurrFrameNo;

                foreach (ITrackedObject trackedObject in m_Tracker.TrackedObjects)
                {
                    IImagePixel center = trackedObject.LastKnownGoodPosition;

                    uint[,] data = m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaPixels((int)Math.Round(center.XDouble), (int)Math.Round(center.YDouble), 35);

                    var measuredObject = new LCMeasurement()
                    {
                        CurrFrameNo = (uint)m_CurrFrameNo,
                        TargetNo = (byte)trackedObject.TargetNo,
                        X0 = (float)center.XDouble,
                        Y0 = (float)center.YDouble,
                        PixelDataX0 = center.X,
                        PixelDataY0 = center.Y,
                        OSDTimeStamp = m_OCRedTimeStamp,
                        FlagsDWORD = 7 /* FitSuspectAsNoGuidingStarsAreLocated */,
                        PixelData = data,
                        PsfGroupId = trackedObject.OriginalObject.GroupId
                    };

                    bool lockTaken = false;

                    if (synchronise)
                        m_WriterLock.TryEnter(ref lockTaken);

                    try
                    {
                        measuredObject.TotalReading = m_LastTotalReading[trackedObject.TargetNo];
                        measuredObject.TotalBackground = m_LastTotalBackground[trackedObject.TargetNo];
                        measuredObject.ApertureX = m_LastApertureX[trackedObject.TargetNo];
                        measuredObject.ApertureY = m_LastApertureY[trackedObject.TargetNo];
                        measuredObject.ApertureSize = m_LastApertureSize[trackedObject.TargetNo];
                        measuredObject.OSDTimeStamp = m_LastOCRedTimeStamp[trackedObject.TargetNo];

                        LCFile.SaveOnTheFlyMeasurement(measuredObject);
                    }
                    finally
                    {
                        if (synchronise && lockTaken)
                            m_WriterLock.Exit();
                    }
                }

                m_VideoController.StepForward();
            }

            return m_CurrFrameNo;
        }
示例#17
0
        internal void HandleNewSelectedFrame(LCMeasurement[] selectedMeasurements)
        {
            m_SelectedMeasurements = selectedMeasurements;

            for (int i = 0; i < m_TargetBoxes.Length; i++)
            {
                infoProvider.SetError(m_TargetBoxes[i], null);
                warningProvider.SetError(m_TargetBoxes[i], null);
            }

            PlotMeasuredPixels();
        }
示例#18
0
        internal void OnNewSelectedMeasurements(LCMeasurement[] selectedMeasurements)
        {
            if (m_frmZoomedPixels != null && m_frmZoomedPixels.Visible)
                m_frmZoomedPixels.HandleNewSelectedFrame(selectedMeasurements);

            if (m_frmPSFFits != null && m_frmPSFFits.Visible)
                m_frmPSFFits.HandleNewSelectedFrame(selectedMeasurements);

            if (m_frmBackgroundHistograms != null && m_frmBackgroundHistograms.Visible)
                m_frmBackgroundHistograms.HandleNewSelectedFrame(selectedMeasurements);

            if (m_SelectedMeasurements == null ||
                selectedMeasurements[0].CurrFrameNo != m_SelectedMeasurements[0].CurrFrameNo)
            {
                m_SelectedMeasurements = selectedMeasurements;
                SelectMeasurement((int)(selectedMeasurements[0].CurrFrameNo - m_Header.MinFrame));
                DisplayCurrentMeasurements();
            }
        }
示例#19
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();
                }
            }
        }
示例#20
0
        private void PlotSingleTargetPixels(PictureBox pictureBox, int targetNo, LCMeasurement reading, uint allObjectsPeak)
        {
            int MAGN = 4;

            Bitmap image = new Bitmap(35 * MAGN, 35 * MAGN, PixelFormat.Format24bppRgb);

            int pixelsCenterX = (int)Math.Round(reading.X0);
            int pixelsCenterY = (int)Math.Round(reading.Y0);

            uint[,] pixelsToDraw = GetPixelData(reading.PixelData);

            for (int x = 0; x < 35; x++)
                for (int y = 0; y < 35; y++)
                {

                    uint pixelValue = pixelsToDraw[x, y];
                    Color pixelcolor;

                    if (pixelValue < m_Saturation)
                    {
                        uint modifiedValue = (uint)Math.Min(m_Context.MaxPixelValue, (pixelValue + Math.Round((m_Context.MaxPixelValue - pixelValue) * (pixelValue * 1.0 / allObjectsPeak) * tbIntensity.Value / 100.0)));
                        byte byteValue = (byte)Math.Round((modifiedValue * 255.0 / m_Context.MaxPixelValue));
                        pixelcolor = Color.FromArgb(byteValue, byteValue, byteValue);
                    }
                    else
                        pixelcolor = TangraConfig.Settings.Color.Saturation;

                    // TODO: THIS IS SOOO SLOW !!!
                    for (int i = 0; i < MAGN; i++)
                    {
                        for (int j = 0; j < MAGN; j++)
                        {
                            image.SetPixel(MAGN * x + i, MAGN * y + j, pixelcolor);
                        }
                    }
                }

            m_LightcurveController.ApplyDisplayModeAdjustments(image);

            pictureBox.Image = image;

            using (Graphics g = Graphics.FromImage(pictureBox.Image))
            {
                if (cbxDrawApertures.Checked)
                {
                    float radius = m_Context.ReProcessApertures[reading.TargetNo];

                    Pen pen = reading.IsSuccessfulReading
                        ? m_DisplaySettings.TargetPens[reading.TargetNo]
                        : Pens.Gray;

                    bool isInGroup = m_ObjectinGroup[reading.TargetNo];
                    bool appertureInGroup = isInGroup && m_Context.SignalMethod == TangraConfig.PhotometryReductionMethod.AperturePhotometry;

                    float ax = appertureInGroup && reading.ApertureX > 0 ? reading.ApertureX : 17.5f;
                    float ay = appertureInGroup && reading.ApertureY > 0 ? reading.ApertureY : 17.5f;
                    float ap = appertureInGroup && reading.ApertureSize > 0 ? reading.ApertureSize : radius;

                    g.DrawEllipse(
                        pen,
                        (float)(MAGN * (reading.X0 - pixelsCenterX + ax - ap)),
                        (float)(MAGN * (reading.Y0 - pixelsCenterY + ay - ap)),
                        2 * ap * MAGN,
                        2 * ap * MAGN);

                    if (m_LightcurveController.Context.BackgroundMethod != TangraConfig.BackgroundMethod.Background3DPolynomial &&
                        m_LightcurveController.Context.BackgroundMethod != TangraConfig.BackgroundMethod.PSFBackground)
                    {
                        Pen bgPen = reading.IsSuccessfulReading
                            ? m_DisplaySettings.TargetBackgroundPens[reading.TargetNo]
                            : new Pen(Color.FromArgb(64, Color.Gray.R, Color.Gray.G, Color.Gray.B));

                        // If Average Background is used, then plot the background annulus
                        float innerRadius = ap * TangraConfig.Settings.Photometry.AnnulusInnerRadius;
                        float outerRadius = (float)Math.Sqrt(TangraConfig.Settings.Photometry.AnnulusMinPixels / Math.PI + innerRadius * innerRadius);

                        g.DrawEllipse(
                            bgPen,
                            (float)(MAGN * (reading.X0 - pixelsCenterX + ax - innerRadius)),
                            (float)(MAGN * (reading.Y0 - pixelsCenterY + ay - innerRadius)),
                            2 * innerRadius * MAGN,
                            2 * innerRadius * MAGN);

                        g.DrawEllipse(
                            bgPen,
                            (float)(MAGN * (reading.X0 - pixelsCenterX + ax - outerRadius)),
                            (float)(MAGN * (reading.Y0 - pixelsCenterY + ay - outerRadius)),
                            2 * outerRadius * MAGN,
                            2 * outerRadius * MAGN);
                    }

                    string title = m_ObjectTitles[reading.TargetNo];
                    SizeF fntSize = g.MeasureString(title, s_TitleFont);
                    g.DrawString(
                        title, s_TitleFont, m_DisplaySettings.TargetBrushes[reading.TargetNo],
                        pictureBox.Width - fntSize.Width - 5,
                        pictureBox.Height - fntSize.Height - 5);

                    if (isInGroup)
                        g.DrawString("Grouped", s_TitleFont, m_DisplaySettings.TargetBrushes[reading.TargetNo], 2, pictureBox.Height - fntSize.Height - 5);

                    string coords = string.Format("{0}, {1}", reading.X0.ToString("0.0"), reading.Y0.ToString("0.0"));
                    fntSize = g.MeasureString(coords, s_CoordsFont);

                    g.DrawString(
                        coords, s_CoordsFont, m_DisplaySettings.TargetBrushes[reading.TargetNo], pictureBox.Width - fntSize.Width - 2, 2);
                }

                g.Save();
            }

            pictureBox.Refresh();
        }
示例#21
0
        private LCMeasurement ProcessSingleUnit(
            LCMeasurement reading,
            bool useLowPass,
            bool useLowPassDiff,
            int newFitMatrixSize,
            float newSignalAperture,
            bool fixedAperture,
            MeasurementsHelper measurer,
            IImagePixel[] groupCenters,
            float[] aperturesInGroup)
        {
            reading.ReProcessingPsfFitMatrixSize = newFitMatrixSize;

            TrackedObjectConfig objConfig = Footer.TrackedObjects[reading.TargetNo];
            ImagePixel          center    = new ImagePixel(reading.X0, reading.Y0);

            int areaSize = groupCenters != null && groupCenters.Length > 1 ? 35 : 17;

            if (Context.Filter != LightCurveContext.FilterType.NoFilter)
            {
                areaSize += 2;
            }

            uint[,] data = BitmapFilter.CutArrayEdges(reading.PixelData, (35 - areaSize) / 2);

            var filter = TangraConfig.PreProcessingFilter.NoFilter;

            if (useLowPassDiff)
            {
                filter = TangraConfig.PreProcessingFilter.LowPassDifferenceFilter;
            }
            else if (useLowPass)
            {
                filter = TangraConfig.PreProcessingFilter.LowPassFilter;
            }

            NotMeasuredReasons rv = ReduceLightCurveOperation.MeasureObject(
                center,
                data,
                reading.PixelData,
                Context.BitPix,
                measurer,
                filter,
                Context.SignalMethod,
                Context.PsfQuadratureMethod,
                Context.PsfFittingMethod,
                newSignalAperture,
                objConfig.RefinedFWHM,
                Footer.RefinedAverageFWHM,
                reading,
                groupCenters,
                aperturesInGroup,
                Footer.ReductionContext.FullDisappearance);

            reading.SetIsMeasured(rv);
            reading.TotalReading    = (uint)measurer.TotalReading;
            reading.TotalBackground = (uint)measurer.TotalBackground;
            reading.ApertureX       = measurer.XCenter;
            reading.ApertureY       = measurer.YCenter;
            reading.ApertureSize    = measurer.Aperture;

            return(reading);
        }
示例#22
0
        private void PlotSingleTargetPixels(
            PictureBox pictureBox, LCMeasurement reading,
            double aperture, int psfFitArea, uint allObjectsPeak)
        {
            int MAGN = 4;

            Bitmap image = new Bitmap(35 * MAGN, 35 * MAGN, PixelFormat.Format24bppRgb);

            int pixelsCenterX = (int)Math.Round(reading.X0) - 1;
            int pixelsCenterY = (int)Math.Round(reading.Y0) - 1;

            uint peak = 0;
            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 (peak < pix) peak = pix;
                }

            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 pixelValue = reading.PixelData[x + 9, y + 9];

                    Color pixelcolor = SystemColors.Control;

                    if (pixelValue < m_Saturation)
                    {
                        uint modifiedValue = (uint)Math.Min(m_Context.MaxPixelValue, (pixelValue + Math.Round((m_Context.MaxPixelValue - pixelValue) * (pixelValue * 1.0 / allObjectsPeak) * tbIntensity.Value / 100.0)));
                        byte byteValue = (byte)Math.Round((modifiedValue * 255.0 / m_Context.MaxPixelValue));
                        pixelcolor = Color.FromArgb(byteValue, byteValue, byteValue);
                    }
                    else
                        pixelcolor = TangraConfig.Settings.Color.Saturation;

                    // TODO: THIS IS SLOW, but pixels are not too many
                    for (int i = 0; i < MAGN; i++)
                    {
                        for (int j = 0; j < MAGN; j++)
                        {
                            image.SetPixel(MAGN * x + i, MAGN * y + j, pixelcolor);
                        }
                    }
                }

            pictureBox.Image = image;
            using (Graphics g = Graphics.FromImage(pictureBox.Image))
            {
                try
                {
                    // ??
                }
                catch (OverflowException)
                {
                    float radius = (float)aperture * 4;
                    float shift = 7.5f;
                    if (reading.PsfFit != null)
                    {
                        g.DrawEllipse(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.PsfFit.XCenter - pixelsCenterX + shift) - radius),
                            (float)(4 * (reading.PsfFit.YCenter - pixelsCenterY + shift) - radius),
                            2 * radius,
                            2 * radius);

                        g.DrawRectangle(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.PsfFit.XCenter - pixelsCenterX + shift) - psfFitArea * 2),
                            (float)(4 * (reading.PsfFit.YCenter - pixelsCenterY + shift) - psfFitArea * 2),
                            4 * psfFitArea,
                            4 * psfFitArea);

                    }
                    else
                    {
                        g.DrawEllipse(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.X0 - pixelsCenterX + shift) - radius),
                            (float)(4 * (reading.Y0 - pixelsCenterY + shift) - radius),
                            2 * radius,
                            2 * radius);

                        g.DrawRectangle(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.X0 - pixelsCenterX + shift) - psfFitArea * 2),
                            (float)(4 * (reading.Y0 - pixelsCenterY + shift) - psfFitArea * 2),
                            4 * psfFitArea,
                            4 * psfFitArea);
                    }

                }

                g.Save();
            }

            pictureBox.Refresh();
            //}
        }
示例#23
0
 internal void OnNewSelectedMeasurements(LCMeasurement[] selectedMeasurements)
 {
     if (selectedMeasurements != null &&
         selectedMeasurements.Length > 0)
     {
         m_LightCurveForm.OnNewSelectedMeasurements(selectedMeasurements);
     }
 }
示例#24
0
        private void PlotSingleTargetPixels(PictureBox pictureBox, int targetNo, LCMeasurement reading, uint allObjectsPeak)
        {
            int MAGN = 4;

            Bitmap image = new Bitmap(35 * MAGN, 35 * MAGN, PixelFormat.Format24bppRgb);

            int pixelsCenterX = (int)Math.Round(reading.X0);
            int pixelsCenterY = (int)Math.Round(reading.Y0);

            uint[,] pixelsToDraw = GetPixelData(reading.PixelData);


            for (int x = 0; x < 35; x++)
            {
                for (int y = 0; y < 35; y++)
                {
                    uint  pixelValue = pixelsToDraw[x, y];
                    Color pixelcolor;

                    if (pixelValue < m_Saturation)
                    {
                        uint modifiedValue = (uint)Math.Min(m_Context.MaxPixelValue, (pixelValue + Math.Round((m_Context.MaxPixelValue - pixelValue) * (pixelValue * 1.0 / allObjectsPeak) * tbIntensity.Value / 100.0)));
                        byte byteValue     = (byte)Math.Round((modifiedValue * 255.0 / m_Context.MaxPixelValue));
                        pixelcolor = Color.FromArgb(byteValue, byteValue, byteValue);
                    }
                    else
                    {
                        pixelcolor = TangraConfig.Settings.Color.Saturation;
                    }

                    // TODO: THIS IS SOOO SLOW !!!
                    for (int i = 0; i < MAGN; i++)
                    {
                        for (int j = 0; j < MAGN; j++)
                        {
                            image.SetPixel(MAGN * x + i, MAGN * y + j, pixelcolor);
                        }
                    }
                }
            }

            m_LightcurveController.ApplyDisplayModeAdjustments(image);

            pictureBox.Image = image;

            using (Graphics g = Graphics.FromImage(pictureBox.Image))
            {
                if (cbxDrawApertures.Checked)
                {
                    float radius = m_Context.ReProcessApertures[reading.TargetNo];

                    Pen pen = reading.IsSuccessfulReading
                                                ? m_DisplaySettings.TargetPens[reading.TargetNo]
                                                : Pens.Gray;

                    bool isInGroup        = m_ObjectinGroup[reading.TargetNo];
                    bool appertureInGroup = isInGroup && m_Context.SignalMethod == TangraConfig.PhotometryReductionMethod.AperturePhotometry;

                    float ax = appertureInGroup && reading.ApertureX > 0 ? reading.ApertureX : 17.5f;
                    float ay = appertureInGroup && reading.ApertureY > 0 ? reading.ApertureY : 17.5f;
                    float ap = appertureInGroup && reading.ApertureSize > 0 ? reading.ApertureSize : radius;

                    g.DrawEllipse(
                        pen,
                        (float)(MAGN * (reading.X0 - pixelsCenterX + ax - ap)),
                        (float)(MAGN * (reading.Y0 - pixelsCenterY + ay - ap)),
                        2 * ap * MAGN,
                        2 * ap * MAGN);

                    if (m_LightcurveController.Context.BackgroundMethod != TangraConfig.BackgroundMethod.Background3DPolynomial &&
                        m_LightcurveController.Context.BackgroundMethod != TangraConfig.BackgroundMethod.PSFBackground)
                    {
                        Pen bgPen = reading.IsSuccessfulReading
                                                        ? m_DisplaySettings.TargetBackgroundPens[reading.TargetNo]
                                                        : new Pen(Color.FromArgb(64, Color.Gray.R, Color.Gray.G, Color.Gray.B));

                        // If Average Background is used, then plot the background annulus
                        float innerRadius = ap * TangraConfig.Settings.Photometry.AnnulusInnerRadius;
                        float outerRadius = (float)Math.Sqrt(TangraConfig.Settings.Photometry.AnnulusMinPixels / Math.PI + innerRadius * innerRadius);

                        g.DrawEllipse(
                            bgPen,
                            (float)(MAGN * (reading.X0 - pixelsCenterX + ax - innerRadius)),
                            (float)(MAGN * (reading.Y0 - pixelsCenterY + ay - innerRadius)),
                            2 * innerRadius * MAGN,
                            2 * innerRadius * MAGN);

                        g.DrawEllipse(
                            bgPen,
                            (float)(MAGN * (reading.X0 - pixelsCenterX + ax - outerRadius)),
                            (float)(MAGN * (reading.Y0 - pixelsCenterY + ay - outerRadius)),
                            2 * outerRadius * MAGN,
                            2 * outerRadius * MAGN);
                    }

                    string title   = m_ObjectTitles[reading.TargetNo];
                    SizeF  fntSize = g.MeasureString(title, s_TitleFont);
                    g.DrawString(
                        title, s_TitleFont, m_DisplaySettings.TargetBrushes[reading.TargetNo],
                        pictureBox.Width - fntSize.Width - 5,
                        pictureBox.Height - fntSize.Height - 5);

                    if (isInGroup)
                    {
                        g.DrawString("Grouped", s_TitleFont, m_DisplaySettings.TargetBrushes[reading.TargetNo], 2, pictureBox.Height - fntSize.Height - 5);
                    }

                    string coords = string.Format("{0}, {1}", reading.X0.ToString("0.0"), reading.Y0.ToString("0.0"));
                    fntSize = g.MeasureString(coords, s_CoordsFont);

                    g.DrawString(
                        coords, s_CoordsFont, m_DisplaySettings.TargetBrushes[reading.TargetNo], pictureBox.Width - fntSize.Width - 2, 2);
                }

                g.Save();
            }

            pictureBox.Refresh();
        }
示例#25
0
 internal double[] ComputeMagnitudes(LCMeasurement[] mesurements)
 {
     return ComputeMagnitudes(mesurements.Select(x => x.AdjustedReading).ToArray());
 }
示例#26
0
        private LCMeasurement ProcessSingleUnit(
            LCMeasurement reading,
            bool useLowPass,
            bool useLowPassDiff,
            int newFitMatrixSize,
            float newSignalAperture,
            bool fixedAperture,
            MeasurementsHelper measurer,
			IImagePixel[] groupCenters,
			float[] aperturesInGroup)
        {
            reading.ReProcessingPsfFitMatrixSize = newFitMatrixSize;

            TrackedObjectConfig objConfig = Footer.TrackedObjects[reading.TargetNo];
            ImagePixel center = new ImagePixel(reading.X0, reading.Y0);

            int areaSize = groupCenters != null && groupCenters.Length > 1 ? 35 : 17;

            if (Context.Filter != LightCurveContext.FilterType.NoFilter) areaSize += 2;

            uint[,] data = BitmapFilter.CutArrayEdges(reading.PixelData, (35 - areaSize) / 2);

            var filter = TangraConfig.PreProcessingFilter.NoFilter;
            if (useLowPassDiff) filter = TangraConfig.PreProcessingFilter.LowPassDifferenceFilter;
            else if (useLowPass) filter = TangraConfig.PreProcessingFilter.LowPassFilter;

            NotMeasuredReasons rv = ReduceLightCurveOperation.MeasureObject(
                center,
                data,
                reading.PixelData,
                Context.BitPix,
                measurer,
                filter,
                Context.SignalMethod,
                Context.PsfQuadratureMethod,
                Context.PsfFittingMethod,
                newSignalAperture,
                objConfig.RefinedFWHM,
                Footer.RefinedAverageFWHM,
                reading,
                groupCenters,
                aperturesInGroup,
                Footer.ReductionContext.FullDisappearance);

            reading.SetIsMeasured(rv);
            reading.TotalReading = (uint)measurer.TotalReading;
            reading.TotalBackground = (uint)measurer.TotalBackground;
            reading.ApertureX = measurer.XCenter;
            reading.ApertureY = measurer.YCenter;
            reading.ApertureSize = measurer.Aperture;

            return reading;
        }
        public void NextFrame(int frameNo, MovementType movementType, bool isLastFrame, AstroImage astroImage, int firstFrameInIntegrationPeriod, string fileName)
        {
            m_AstroImage = astroImage;
            m_CurrFrameNo = frameNo;
            m_CurrFileName = fileName;

            TangraContext.Current.CrashReportInfo.FrameNumber = frameNo;

            if (m_Correcting)
                // Do not track or process the frame while correcting the tracking
                return;

            if (m_Configuring)
            {
                if (m_CurrFrameNo != frameNo) m_StackedAstroImage = null;
                if (frameNo != m_StateMachine.SelectedObjectFrameNo) m_StateMachine.SelectedObject = null;
            }

            if (m_Refining || m_Measuring)
            {
                if (m_VideoController.IsAstroAnalogueVideo && frameNo == 0)
                {
                    // Do not attempt refining on the first AAV frame as it has unique dynamic range and the refining is not going to work at all.
                }
                else
                {
                    m_Tracker.NextFrame(frameNo, astroImage);

                    if (!m_Tracker.IsTrackedSuccessfully) m_NumberFramesWithBadTracking++;

                    m_VideoController.SetDisplayHueBackgroundModeTargets(m_Tracker.TrackedObjects);

                    if (m_Refining)
                    {
                        if (m_Tracker.RefiningPercentageWorkLeft <= 0)
                        {
                            bool canSwitchFromRefiningToMeasuringNow = true;

                            if (m_VideoController.IsUsingSteppedAveraging)
                            {
                                // When using stepped averaging the measurements should start at the first frame of an integration 'step'
                                // which means we need to flip the switch from 'Refining' to 'Measuring' one frame before that
                                if (firstFrameInIntegrationPeriod + m_VideoController.FramesToIntegrate - 1 > frameNo)
                                {
                                    Trace.WriteLine(string.Format("Skipping frame {0}, waiting for the first frame in the next integration period to start measurments.", frameNo));
                                    canSwitchFromRefiningToMeasuringNow = false;
                                }
                            }

                            if (canSwitchFromRefiningToMeasuringNow)
                            {
                                float oneSigma;
                                m_AavNtpTimestampError = m_VideoController.AstroAnalogueVideoNormaliseNtpDataIfNeeded(out oneSigma);
                                m_AavNtpFitOneSigmaError = oneSigma;
                                // Begin measurements
                                m_Measuring = true;
                                m_Refining = false;

                                m_ProcessedFrames = 0;
                                m_UnsuccessfulFrames = 0;
                                m_PartiallySuccessfulFrames = 0;
                                m_StopWatch.Reset();
                                m_StopWatch.Start();

                                m_Tracker.BeginMeasurements(astroImage);

                                // IMPORTANT: The finalHeader must be changed as well if changing this
                                LCFile.NewOnTheFlyOutputFile(
                                    m_VideoController.CurrentVideoFileName,
                                    string.Format("Video ({0})", m_VideoController.CurrentVideoFileType),
                                    (byte)m_Tracker.TrackedObjects.Count, (float)m_Tracker.PositionTolerance,
                                    LightCurveReductionContext.Instance.LightCurveReductionType == LightCurveReductionType.TotalLunarReppearance);

                                m_MinFrame = uint.MaxValue;
                                m_MaxFrame = uint.MinValue;
                                m_TotalFrames = 0;
                                m_FirstMeasuredFrame = frameNo;

                                m_AverageFWHM = astroImage.GetAverageFWHM();

                                m_VideoController.StatusChanged("Measuring");
                            }
                        }
                    }
                }

                if (m_Measuring)
                {
                    if (!m_Tracker.IsTrackedSuccessfully &&
                         LightCurveReductionContext.Instance.StopOnLostTracking)
                    {
                        m_ControlPanel.StopMeasurements(ucLightCurves.StopReason.LostTracking);

                        if (TangraConfig.Settings.Tracking.PlaySound)
                            Console.Beep(800, 750);

                        if (TangraConfig.Settings.Tracking.PopUpOnLostTracking)
                            m_VideoController.ShowMessageBox(
                                "Use the mouse to pan the object apertures back to the object location and press 'Continue' to continue with the measurements. You can also do adjustments to the objects individually or skip the frame all together.",
                                "Tracking has been lost",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                        return;
                    }

                    m_ProcessedFrames++;
                    if (!m_Tracker.IsTrackedSuccessfully) m_UnsuccessfulFrames++;
                    if (m_Tracker.IsTrackedSuccessfully && m_Tracker.TrackedObjects.Any(x => !x.IsLocated))
                        m_PartiallySuccessfulFrames++;

                    SaveEmbeddedOrORCedTimeStamp(frameNo);

                    MeasureObjects();

                    m_PrevMeasuredFrame = m_CurrFrameNo;

                    m_StopWatch.Stop();
                    m_ControlPanel.UpdateProcessedFrames(m_ProcessedFrames, m_UnsuccessfulFrames, m_PartiallySuccessfulFrames, (int)(m_StopWatch.ElapsedMilliseconds / 1000));
                    m_StopWatch.Start();
                }
            }
            else if (m_ViewingLightCurve && m_LightCurveController.LcFile != null)
            {
                var currentSelection = new LCMeasurement[m_LightCurveController.LcFile.Header.ObjectCount];

                if (m_LightCurveController.LcFile.Header.MinFrame <= m_CurrFrameNo &&
                    m_LightCurveController.LcFile.Header.MaxFrame >= m_CurrFrameNo)
                {
                    for (int i = 0; i < m_LightCurveController.LcFile.Header.ObjectCount; i++)
                    {
                        List<LCMeasurement> measurements = m_LightCurveController.Context.AllReadings[i];
                        currentSelection[i] = measurements[(int)(m_CurrFrameNo - m_LightCurveController.LcFile.Header.MinFrame)];
                    }

                    m_LightCurveController.OnNewSelectedMeasurements(currentSelection.ToArray());
                }
            }

            if (m_ControlPanel != null)
                m_ControlPanel.UpdateState();
            if (isLastFrame)
            {
                if (m_Refining)
                {
                    m_ControlPanel.StopRefining();
                    if (TangraConfig.Settings.Tracking.PlaySound)
                        Console.Beep();
                }
                else if (m_Measuring)
                {
                    m_ControlPanel.StopMeasurements(ucLightCurves.StopReason.EndOfFile);

                    if (TangraConfig.Settings.Tracking.PlaySound)
                        Console.Beep();

                    m_ControlPanel.StoppedAtLastFrame();
                }
            }
        }
        private void MeasureTrackedObject2(
			ITrackedObject trackedObject,
			MeasurementsHelper measurer,
			TangraConfig.PreProcessingFilter filter,
			bool synchronise,
			List<ITrackedObject> objectsInGroup,
			float refinedFWHM,
			float averageFWHM)
        {
            IImagePixel center = trackedObject.Center;
            int areaSize = 17;
            if ((objectsInGroup != null && objectsInGroup.Count > 1) || LightCurveReductionContext.Instance.NoiseMethod == TangraConfig.BackgroundMethod.Background3DPolynomial)
                // for double PSF fits and/or 3d polynomial background fits we need the largest area
                areaSize = 35;

            IImagePixel[] groupCenters = new IImagePixel[0];
            float[] aperturesInGroup = new float[0];

            if (objectsInGroup != null && objectsInGroup.Count > 1)
            {
                groupCenters = new IImagePixel[objectsInGroup.Count];
                aperturesInGroup = new float[objectsInGroup.Count];

                for (int i = 0; i < objectsInGroup.Count; i++)
                {
                    groupCenters[i] = objectsInGroup[i].Center;
                    aperturesInGroup[i] = objectsInGroup[i].OriginalObject.ApertureInPixels;
                }
            }

            int areaDigitalFilterEdge = 0;
            if (LightCurveReductionContext.Instance.DigitalFilter != TangraConfig.PreProcessingFilter.NoFilter)
                areaDigitalFilterEdge = 2; // The extra 2 pixels will be cut after the filter is applied before the measurement

            int centerX = (int)Math.Round(center.XDouble);
            int centerY = (int)Math.Round(center.YDouble);

            uint[,] data = m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaPixels(centerX, centerY, areaSize + areaDigitalFilterEdge);
            uint[,] backgroundPixels = m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaPixels(centerX, centerY, 35 + areaDigitalFilterEdge);

            float msrX0 = (float)trackedObject.Center.XDouble;
            float msrY0 = (float)trackedObject.Center.YDouble;

            var measuredObject = new LCMeasurement()
            {
                CurrFrameNo = (uint) m_CurrFrameNo,
                CurrFileName = m_CurrFileName,
                TargetNo = (byte) trackedObject.TargetNo,
                X0 = msrX0,
                Y0 = msrY0,
                PixelDataX0 = centerX,
                PixelDataY0 = centerY,
                OSDTimeStamp = m_OCRedTimeStamp,
                FlagsDWORD = trackedObject.GetTrackingFlags()
            };

            IMeasurableObject measurableObject = (IMeasurableObject)trackedObject;

            NotMeasuredReasons rv = MeasureObject(
                center,
                data,
                backgroundPixels,
                m_VideoController.VideoBitPix,
                measurer,
                filter,
                LightCurveReductionContext.Instance.ReductionMethod,
                LightCurveReductionContext.Instance.PsfQuadratureMethod,
                TangraConfig.Settings.Photometry.PsfFittingMethod,
                trackedObject.OriginalObject.ApertureInPixels,
                refinedFWHM,
                averageFWHM,
                measurableObject,
                groupCenters,
                aperturesInGroup,
                LightCurveReductionContext.Instance.FullDisappearance);

            measuredObject.SetIsMeasured(rv);

            uint[,] pixelsToSave = trackedObject.IsOffScreen
                                       ? new uint[35, 35]
                                       // As the background may have been pre-processed for measuring, we need to take another copy for saving in the file
                                       : m_VideoController.GetCurrentAstroImage(false).GetMeasurableAreaPixels(centerX, centerY, 35);

            bool lockTaken = false;

            if (synchronise)
                m_WriterLock.TryEnter(ref lockTaken);

            try
            {
                uint flags = trackedObject.GetTrackingFlags();

                measuredObject.TotalReading = (uint)Math.Round(measurer.TotalReading);
                measuredObject.TotalBackground = (uint)Math.Round(measurer.TotalBackground);
                measuredObject.PixelData = pixelsToSave; /* save the original non filtered data */
                measuredObject.FlagsDWORD |= flags;
                measuredObject.ApertureX = measurer.XCenter;
                measuredObject.ApertureY = measurer.YCenter;
                measuredObject.ApertureSize = measurer.Aperture;

                m_LastTotalReading[trackedObject.TargetNo] = measuredObject.TotalReading;
                m_LastTotalBackground[trackedObject.TargetNo] = measuredObject.TotalBackground;
                m_LastApertureX[trackedObject.TargetNo] = measuredObject.ApertureX;
                m_LastApertureY[trackedObject.TargetNo] = measuredObject.ApertureY;
                m_LastApertureSize[trackedObject.TargetNo] = measuredObject.ApertureSize;
                m_LastOCRedTimeStamp[trackedObject.TargetNo] = measuredObject.OSDTimeStamp;

                LCFile.SaveOnTheFlyMeasurement(measuredObject);
            }
            finally
            {
                if (synchronise && lockTaken)
                    m_WriterLock.Exit();
            }
        }
示例#29
0
        private void PlotSingleTargetPixels(PictureBox pictureBox, LCMeasurement reading)
        {
            if (!TangraContext.Current.CanProcessLightCurvePixels)
                return;

            Bitmap bmp = pictureBox.Image as Bitmap;
            if (bmp != null)
            {

                int pixelsCenterX = (int)Math.Round(reading.X0);
                int pixelsCenterY = (int)Math.Round(reading.Y0);

                for (int x = 0; x < 17; x++)
                    for (int y = 0; y < 17; y++)
                    {
                        // NOTE: Need the +9 to convert from 17x17 coordinates to 35x35
                        uint pixelValue = reading.PixelData[x + 9, y + 9];
                        byte pixcolor = m_LightCurveController.Context.DisplayBitmapConverter.ToDisplayBitmapByte(pixelValue);
                        Color pixelcolor = Color.FromArgb(pixcolor, pixcolor, pixcolor);
                        bmp.SetPixel(2 * x, 2 * y, pixelcolor);
                        bmp.SetPixel(2 * x + 1, 2 * y, pixelcolor);
                        bmp.SetPixel(2 * x, 2 * y + 1, pixelcolor);
                        bmp.SetPixel(2 * x + 1, 2 * y + 1, pixelcolor);
                    }

                using (Graphics g = Graphics.FromImage(bmp))
                {
                    float radius = m_LightCurveController.Context.ReProcessApertures[reading.TargetNo]*2;

                    g.DrawEllipse(
                            m_DisplaySettings.TargetPens[reading.TargetNo],
                            (float)(2 * (reading.X0 - pixelsCenterX) + 17 - radius),
                            (float)(2 * (reading.Y0 - pixelsCenterY) + 17 - radius),
                            2 * radius,
                            2 * radius);

                    g.Save();
                }

                pictureBox.Refresh();
            }
        }
        private void PlotSingleTargetPixels(
            PictureBox pictureBox, LCMeasurement reading,
            double aperture, int psfFitArea, uint allObjectsPeak)
        {
            int MAGN = 4;

            Bitmap image = new Bitmap(35 * MAGN, 35 * MAGN, PixelFormat.Format24bppRgb);

            int pixelsCenterX = (int)Math.Round(reading.X0) - 1;
            int pixelsCenterY = (int)Math.Round(reading.Y0) - 1;

            uint peak = 0;

            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 (peak < pix)
                    {
                        peak = pix;
                    }
                }
            }

            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 pixelValue = reading.PixelData[x + 9, y + 9];

                    Color pixelcolor = SystemColors.Control;

                    if (pixelValue < m_Saturation)
                    {
                        uint modifiedValue = (uint)Math.Min(m_Context.MaxPixelValue, (pixelValue + Math.Round((m_Context.MaxPixelValue - pixelValue) * (pixelValue * 1.0 / allObjectsPeak) * tbIntensity.Value / 100.0)));
                        byte byteValue     = (byte)Math.Round((modifiedValue * 255.0 / m_Context.MaxPixelValue));
                        pixelcolor = Color.FromArgb(byteValue, byteValue, byteValue);
                    }
                    else
                    {
                        pixelcolor = TangraConfig.Settings.Color.Saturation;
                    }


                    // TODO: THIS IS SLOW, but pixels are not too many
                    for (int i = 0; i < MAGN; i++)
                    {
                        for (int j = 0; j < MAGN; j++)
                        {
                            image.SetPixel(MAGN * x + i, MAGN * y + j, pixelcolor);
                        }
                    }
                }
            }


            pictureBox.Image = image;
            using (Graphics g = Graphics.FromImage(pictureBox.Image))
            {
                try
                {
                    // ??
                }
                catch (OverflowException)
                {
                    float radius = (float)aperture * 4;
                    float shift  = 7.5f;
                    if (reading.PsfFit != null)
                    {
                        g.DrawEllipse(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.PsfFit.XCenter - pixelsCenterX + shift) - radius),
                            (float)(4 * (reading.PsfFit.YCenter - pixelsCenterY + shift) - radius),
                            2 * radius,
                            2 * radius);

                        g.DrawRectangle(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.PsfFit.XCenter - pixelsCenterX + shift) - psfFitArea * 2),
                            (float)(4 * (reading.PsfFit.YCenter - pixelsCenterY + shift) - psfFitArea * 2),
                            4 * psfFitArea,
                            4 * psfFitArea);
                    }
                    else
                    {
                        g.DrawEllipse(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.X0 - pixelsCenterX + shift) - radius),
                            (float)(4 * (reading.Y0 - pixelsCenterY + shift) - radius),
                            2 * radius,
                            2 * radius);

                        g.DrawRectangle(
                            m_AllPens[reading.TargetNo],
                            (float)(4 * (reading.X0 - pixelsCenterX + shift) - psfFitArea * 2),
                            (float)(4 * (reading.Y0 - pixelsCenterY + shift) - psfFitArea * 2),
                            4 * psfFitArea,
                            4 * psfFitArea);
                    }
                }

                g.Save();
            }

            pictureBox.Refresh();
            //}
        }
示例#31
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);
                    }
                }
            }
        }