Example #1
0
        public DialogResult CheckAavRate(VideoFileFormat videoFileFormat)
        {
            int totalIntegratedFrames = 0;

            m_VideoController.SetPictureBoxCursor(Cursors.WaitCursor);
            m_VideoController.NotifyFileProgress(-1, m_EndTimeFrame - m_StartTimeFrame);
            try
            {
                for (int i = m_StartTimeFrame; i < m_EndTimeFrame; i++)
                {
                    FrameStateData frameState = m_VideoController.GetFrameStateData(i);

                    totalIntegratedFrames += frameState.NumberIntegratedFrames.Value;
                    m_VideoController.NotifyFileProgress(i, m_EndTimeFrame - m_StartTimeFrame);
                }
            }
            finally
            {
                m_VideoController.NotifyFileProgress(-1, 0);
                m_VideoController.SetPictureBoxCursor(Cursors.Default);
            }

            // The actual integration could even be of PAL or NTSC frames

            TimeSpan ts = new TimeSpan(Math.Abs(m_EndFrameTime.Ticks - m_StartFrameTime.Ticks) /*Taking ABS to handle backwards measuring*/);
            double   videoTimeInSecPAL  = totalIntegratedFrames / 25.0;
            double   videoTimeInSecNTSC = totalIntegratedFrames / 29.97;

            double timeDiscrepancy_PAL = Math.Abs((videoTimeInSecPAL - ts.TotalSeconds) * 1000);
            bool   isTimeOk_PAL        = (videoTimeInSecPAL > 0 && timeDiscrepancy_PAL < TangraConfig.Settings.Special.MaxAllowedTimestampShiftInMilliSecs);;

            double timeDiscrepancy_NTSC = Math.Abs((videoTimeInSecNTSC - ts.TotalSeconds) * 1000);
            bool   isTimeOk_NTSC        = (videoTimeInSecNTSC > 0 && timeDiscrepancy_NTSC < TangraConfig.Settings.Special.MaxAllowedTimestampShiftInMilliSecs);

            bool   isTimeOk        = isTimeOk_NTSC || isTimeOk_PAL;
            double timeDiscrepancy = Math.Min(timeDiscrepancy_PAL, timeDiscrepancy_NTSC);

            if (!isTimeOk)
            {
                if (MessageBox.Show(
                        string.Format(
                            "The time computed from the measured number of frames in this AAV video is off by {0} ms from the entered time. This may indicate " +
                            "incorrectly entered start or end time or an almanac update or a leap second event. Please enter the start and end times again. The export operation can " +
                            "only continute if the times match exactly.",
                            timeDiscrepancy.ToString("0.00")),
                        "Error",
                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == DialogResult.Retry)
                {
                    return(DialogResult.Retry);
                }

                return(DialogResult.Abort);
            }

            return(DialogResult.OK);
        }
Example #2
0
        public void ShowStatus(FrameStateData frameState)
        {
            m_FrameState = frameState;

            var statusText = new StringBuilder();

            statusText.AppendLine(string.Format("Time Stamp: {0}", m_FrameState.SystemTime.ToString("dd MMM yyyy HH:mm:ss.fff")));

            lblStatusCombined.Text = statusText.ToString();
        }
        private void AddExtraNtpDebugTimes(ref FrameStateData stateData, AdvFrameInfo frameInfo)
        {
            if (stateData.AdditionalProperties == null)
            {
                stateData.AdditionalProperties = new SafeDictionary <string, object>();
            }

            stateData.AdditionalProperties.Add("MidTimeNTPRaw", stateData.EndFrameNtpTime.AddMilliseconds(-0.5 * stateData.ExposureInMilliseconds));
            stateData.AdditionalProperties.Add("MidTimeNTPFitted", stateData.CentralExposureTime);
            stateData.AdditionalProperties.Add("MidTimeWindowsRaw", frameInfo.EndExposureSecondaryTimeStamp.AddMilliseconds(-0.5 * stateData.ExposureInMilliseconds));
        }
        private FrameStateData GetCurrentFrameState(Adv.AdvFrameInfo frameInfo)
        {
            if (frameInfo != null)
            {
                var rv = new FrameStateData();
                rv.VideoCameraFrameId  = (long)frameInfo.VideoCameraFrameId;
                rv.CentralExposureTime = frameInfo.UtcMidExposureTime;
                rv.SystemTime          = frameInfo.SystemTimestamp;

                rv.ExposureInMilliseconds = frameInfo.Exposure / 10.0f;

                rv.NumberIntegratedFrames = 0;
                rv.NumberStackedFrames    = 0;

                int almanacStatus = frameInfo.GPSAlmanacStatus;
                int almanacOffset = frameInfo.GPSAlmanacOffset;

                //if (!frameInfo.AlmanacStatusIsGood && m_AlamanacOffsetLastFrameIsGood)
                //{
                //    // When the current almanac is not good, but last frame is, then apply the known almanac offset automatically
                //    almanacOffset = m_AlmanacOffsetLastFrame;
                //    rv.CentralExposureTime = rv.CentralExposureTime.AddSeconds(m_AlmanacOffsetLastFrame);
                //    almanacStatus = 2; // Certain
                //}

                rv.Gain  = frameInfo.Gain;
                rv.Gamma = frameInfo.Gamma;
                //rv.Temperature = frameInfo.Temperature;
                rv.Offset = frameInfo.Offset;

                rv.NumberSatellites = frameInfo.GPSTrackedSattelites;

                rv.AlmanacStatus = AdvStatusValuesHelper.TranslateGpsAlmanacStatus(almanacStatus);

                rv.AlmanacOffset = AdvStatusValuesHelper.TranslateGpsAlmanacOffset(almanacStatus, almanacOffset, almanacStatus > 0);

                rv.GPSFixStatus = frameInfo.GPSFixStatus.ToString("#");

                rv.Messages = string.Empty;

                if (frameInfo.HasErrorMessage)
                {
                    rv.Messages = Convert.ToString(frameInfo.Status["Error"]);
                }

                rv.IsVtiOsdCalibrationFrame = frameInfo.Status.ContainsKey("FRAME-TYPE") && Convert.ToString(frameInfo.Status["FRAME-TYPE"]) == "VTI-OSD-CALIBRATION";

                return(rv);
            }
            else
            {
                return(new FrameStateData());
            }
        }
Example #5
0
        public void OverlayStateForFrame(Bitmap currentImage, FrameStateData state, RenderFrameContext context, bool isAstroDigitalVideo, bool isAstroAnalogueVideo)
        {
            using (Graphics g = Graphics.FromImage(currentImage))
            {
                if (m_CurrentImageWidth != currentImage.Width)
                {
                    ComputeFontSizeAndTimeStampPosition(g, currentImage.Width, currentImage.Height);
                }

                if (isAstroDigitalVideo)
                {
                    OverlayADVState(g, currentImage, state, context);
                }
                else if (isAstroAnalogueVideo)
                {
                    OverlayAAVState(g, currentImage, state, context);
                }
            }

            m_LastFrameNo = context.CurrentFrameIndex;
        }
Example #6
0
        public DialogResult CheckAavRate()
        {
            int totalIntegratedFrames = 0;

            for (int i = m_StartTimeFrame; i < m_EndTimeFrame; i++)
            {
                FrameStateData frameState = m_VideoController.GetFrameStateData(i);

                totalIntegratedFrames += frameState.NumberIntegratedFrames.Value;
            }

            // The actual integration could even be of PAL or NTSC frames

            TimeSpan ts = new TimeSpan(Math.Abs(m_EndFrameTime.Ticks - m_StartFrameTime.Ticks) /*Taking ABS to handle backwards measuring*/);
            double   videoTimeInSecPAL  = totalIntegratedFrames / 25.0;
            double   videoTimeInSecNTSC = totalIntegratedFrames / 29.97;

            bool isTimeOk =
                (videoTimeInSecPAL > 0 && Math.Abs((videoTimeInSecPAL - ts.TotalSeconds) * 1000) < TangraConfig.Settings.Special.MaxAllowedTimestampShiftInMs) ||
                (videoTimeInSecNTSC > 0 && Math.Abs((videoTimeInSecNTSC - ts.TotalSeconds) * 1000) < TangraConfig.Settings.Special.MaxAllowedTimestampShiftInMs);

            if (!isTimeOk)
            {
                if (MessageBox.Show(
                        string.Format(
                            "The time computed from the measured number of frames in this AAV video is off by more than {0} ms from the entered time. This may indicate " +
                            "incorrectly entered start or end time or an almanac update or a leap second event. Please enter the start and end times again. The export operation can " +
                            "only continute if the times match exactly.",
                            (TangraConfig.Settings.Special.MaxAllowedTimestampShiftInMs).ToString("0.00")),
                        "Error",
                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == DialogResult.Retry)
                {
                    return(DialogResult.Retry);
                }

                return(DialogResult.Abort);
            }

            return(DialogResult.OK);
        }
        public int AstroAnalogueVideoNormaliseNtpDataIfNeeded(Action <int> progressCallback, out float oneSigmaError)
        {
            int ntpError = -1;

            oneSigmaError = float.NaN;

            if (NtpDataAvailable && !OcrDataAvailable && !m_UseNtpTimeAsCentralExposureTime)
            {
                if (m_CountFrames > 1 /* No Timestamp for first frame */ + 1 /* No Timestamp for last frame*/ + 3 /* Minimum timestamped frames for a FIT */)
                {
                    try
                    {
                        double frameDurationMilliseconds = 1000 / m_FrameRate;
                        var    lr = new LinearRegression();

                        long zeroPointTicks = -1;

                        int percentDone       = 0;
                        int percentDoneCalled = 0;
                        if (progressCallback != null)
                        {
                            progressCallback(percentDone);
                        }

                        long ntpTimestampErrorSum        = 0;
                        int  ntpTimestampErrorDatapoints = 0;

                        for (int i = m_FirstFrame; i < m_FirstFrame + m_CountFrames; i++)
                        {
                            FrameStateData stateChannel = GetFrameStatusChannel(i);
                            if (stateChannel.HasValidNtpTimeStamp)
                            {
                                long centralTicks = stateChannel.EndFrameNtpTime.AddMilliseconds(-0.5 * frameDurationMilliseconds).Ticks;
                                if (zeroPointTicks == -1)
                                {
                                    zeroPointTicks = centralTicks;
                                }
                                lr.AddDataPoint(i, new TimeSpan(centralTicks - zeroPointTicks).TotalMilliseconds);
                                ntpTimestampErrorSum += stateChannel.NtpTimeStampError;
                                ntpTimestampErrorDatapoints++;
                            }

                            percentDone = 100 * (i - m_FirstFrame) / m_CountFrames;
                            if (progressCallback != null && percentDone - percentDoneCalled > 5)
                            {
                                progressCallback(percentDone);
                                percentDoneCalled = percentDone;
                            }
                        }

                        if (lr.NumberOfDataPoints > 3)
                        {
                            lr.Solve();

                            m_CalibratedNtpTimeZeroPoint      = zeroPointTicks;
                            m_CalibratedNtpTimeSource         = lr;
                            m_UseNtpTimeAsCentralExposureTime = true;
                            m_NtpTimeFitSigma            = lr.StdDev;
                            m_NtpTimeAverageNetworkError = (ntpTimestampErrorSum * 1.0 / ntpTimestampErrorDatapoints);
                            ntpError = (int)Math.Round(m_NtpTimeFitSigma + m_NtpTimeAverageNetworkError);

                            Trace.WriteLine(string.Format("NTP Timebase Established. 1-Sigma = {0} ms", lr.StdDev.ToString("0.00")));

                            oneSigmaError = (float)m_NtpTimeFitSigma;
                        }

                        progressCallback(100);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex.GetFullStackTrace());
                    }
                }
            }

            return(ntpError);
        }
        private FrameStateData AdvFrameInfoToFrameStateData(AdvFrameInfo frameInfo, int frameIndex)
        {
            if (frameInfo != null)
            {
                var rv = new FrameStateData();
                rv.VideoCameraFrameId     = frameInfo.VideoCameraFrameId;
                rv.CentralExposureTime    = frameInfo.MiddleExposureTimeStamp;
                rv.SystemTime             = frameInfo.SystemTime;
                rv.EndFrameNtpTime        = frameInfo.EndExposureNtpTimeStamp;
                rv.NtpTimeStampError      = frameInfo.NtpTimeStampError;
                rv.ExposureInMilliseconds = frameInfo.Exposure10thMs / 10.0f;

                rv.NumberIntegratedFrames = (int)frameInfo.IntegratedFrames;

                int almanacStatus = frameInfo.GPSAlmanacStatus;
                int almanacOffset = frameInfo.GetSignedAlamancOffset();

                if (!frameInfo.AlmanacStatusIsGood && frameInfo.AlmanacStatusIsGood)
                {
                    // When the current almanac is not good, but last frame is, then apply the known almanac offset automatically
                    almanacOffset          = frameInfo.GPSAlmanacOffset;
                    rv.CentralExposureTime = rv.CentralExposureTime.AddSeconds(frameInfo.GPSAlmanacOffset);
                    almanacStatus          = 2;            // Certain
                }


                rv.Gain        = frameInfo.Gain;
                rv.Gamma       = frameInfo.Gamma;
                rv.Temperature = frameInfo.Temperature;
                rv.Offset      = frameInfo.Offset;

                rv.NumberSatellites = frameInfo.GPSTrackedSattelites;

                rv.AlmanacStatus = AdvStatusValuesHelper.TranslateGpsAlmanacStatus(almanacStatus);

                rv.AlmanacOffset = AdvStatusValuesHelper.TranslateGpsAlmanacOffset(almanacStatus, almanacOffset, almanacStatus > 0);

                rv.GPSFixStatus = frameInfo.GPSFixStatus.ToString("#");

                rv.Messages = string.Empty;
                if (frameInfo.SystemErrorString != null)
                {
                    rv.Messages = string.Concat(rv.Messages, frameInfo.SystemErrorString, "\r\n");
                }
                if (frameInfo.UserCommandString != null)
                {
                    rv.Messages = string.Concat(rv.Messages, frameInfo.UserCommandString, "\r\n");
                }
                if (frameInfo.GPSFixString != null)
                {
                    rv.Messages = string.Concat(rv.Messages, frameInfo.GPSFixString, "\r\n");
                }

                if (m_UseNtpTimeAsCentralExposureTime)
                {
                    rv.CentralExposureTime = ComputeCentralExposureTimeFromNtpTime(frameIndex, frameInfo.EndExposureNtpTimeStamp);
                }

                if (m_FrameRate > 0)
                {
                    rv.ExposureInMilliseconds = (float)(1000 / m_FrameRate);
                }

                if (m_UsesNtpTimestamps && !OcrDataAvailable && m_UseNtpTimeAsCentralExposureTime)
                {
                    AddExtraNtpDebugTimes(ref rv, frameInfo);
                }

                return(rv);
            }
            else
            {
                return(new FrameStateData());
            }
        }
Example #9
0
        public void ShowStatus(FrameStateData frameState)
        {
            m_FrameState = frameState;

            var statusText = new StringBuilder();

            if (m_AdvSettings.PopupSatellites)
            {
                statusText.AppendLine(string.Format("Tracked Satellites: {0}", m_FrameState.NumberSatellites));
            }

            if (m_AdvSettings.PopupAlmanac)
            {
                statusText.AppendLine(string.Format("Almanac Status: {0}", m_FrameState.AlmanacStatus));
                statusText.AppendLine(string.Format("Almanac Offset: {0}", m_FrameState.AlmanacOffset));
            }

            if (m_AdvSettings.PopupGPSFix)
            {
                int    intStatus;
                string strStatus;
                if (int.TryParse(m_FrameState.GPSFixStatus, out intStatus))
                {
                    strStatus = AdvStatusValuesHelper.TranslateGpsFixStatus(intStatus);
                }
                else
                {
                    strStatus = m_FrameState.GPSFixStatus;
                }

                statusText.AppendLine(string.Format("GPS Fix: {0}", strStatus));
            }

            if (m_AdvSettings.PopupSatellites || m_AdvSettings.PopupAlmanac || m_AdvSettings.PopupGPSFix)
            {
                statusText.AppendLine();
            }

            if (m_AdvSettings.PopupVideoCameraFrameId)
            {
                statusText.AppendLine(string.Format("Camera Frame #: {0}", m_FrameState.VideoCameraFrameId.ToString("###,###,###,##0")));
            }
            if (m_AdvSettings.PopupTimestamp)
            {
                statusText.AppendLine(string.Format("Central Exposure Time: {0}",
                                                    m_FrameState.HasValidTimeStamp
                            ? m_FrameState.CentralExposureTime.ToString("dd MMM yyyy HH:mm:ss.fff")
                            : "Embedded Timestamp Not Found"));
            }

            if (m_AdvSettings.PopupExposure)
            {
                statusText.AppendLine(m_FrameState.HasValidTimeStamp
                            ? string.Format("Exposure Duration: {0} ms", m_FrameState.ExposureInMilliseconds.ToString("0"))
                            : "Exposure Duration: Unknown");
            }

            if (m_AdvSettings.PopupTimestamp || m_AdvSettings.PopupExposure || m_AdvSettings.PopupVideoCameraFrameId)
            {
                statusText.AppendLine();
            }

            if (m_AdvSettings.PopupSystemTime)
            {
                statusText.AppendLine(string.Format("PC Clock Time: {0}", m_FrameState.SystemTime.ToString("dd MMM yyyy HH:mm:ss.fff")));
            }

            if (m_AdvSettings.PopupSystemTime)
            {
                statusText.AppendLine();
            }

            if (m_AdvSettings.PopupGamma)
            {
                statusText.AppendLine(string.Format("Gamma: {0:0.000} {1}", m_FrameState.Gamma, AdvStatusValuesHelper.GetWellKnownGammaForValue(m_FrameState.Gamma)));
            }
            if (m_AdvSettings.PopupGain)
            {
                statusText.AppendLine(m_FrameState.IsGainKnown
                    ? string.Format("Gain: {0:0} dB", m_FrameState.Gain)
                    : "Gain: Unknown");
            }
            if (m_AdvSettings.PopupOffset)
            {
                statusText.AppendLine(string.Format("Offset: {0:0.00} %", m_FrameState.Offset));
            }

            lblStatusCombined.Text = statusText.ToString();
            this.Height            = 197 /* Nominal height of the form */ - 117 /* Nominal height of the label*/ + lblStatusCombined.Height;
            this.Width             = 213 /* Nominal width of the form */ - 181 /* Nominal width of the label*/ + lblStatusCombined.Width;
            btnCopy.Top            = 141 /* Nominal top position of the button */ - 117 /* Nominal height of the label*/ + lblStatusCombined.Height;
            btnCopy.Left           = (this.Width - btnCopy.Width) / 2;
        }
Example #10
0
        private void OverlayADVState(Graphics g, Bitmap currentImage, FrameStateData state, RenderFrameContext context)
        {
            if (TangraConfig.Settings.ADVS.OverlayTimestamp)
            {
                string timeStampStr = state.HasValidTimeStamp
                                                ? string.Format("{0}.{1}", state.CentralExposureTime.ToString("dd MMM yyyy HH:mm:ss"), state.CentralExposureTime.Millisecond.ToString().PadLeft(3, '0'))
                                                : "Embedded Timestamp Not Found";
                g.DrawString(timeStampStr, s_TimeStampFont, s_TimeStampBrush, m_XPos, currentImage.Height - m_YPosUpper);
                g.Save();
            }

            int numTopLines = 0;

            if (TangraConfig.Settings.ADVS.OverlayObjectName && m_AdvFileMetadataInfo != null && !string.IsNullOrWhiteSpace(m_AdvFileMetadataInfo.ObjectName) &&
                (!m_ObjectInfoDisplayed || m_FirstFrameNo == context.CurrentFrameIndex))
            {
                string objectNameStr = string.Format(" {0}", m_AdvFileMetadataInfo.ObjectName);
                g.DrawString(objectNameStr, s_PropertiesFont, s_PropertiesGreenBrush, 10, 10 + numTopLines * (s_PropertiesFont.Size + 5));
                g.Save();
                numTopLines++;
                m_ObjectInfoDisplayed = true;
            }

            if (m_LastFrameNo + 1 != context.CurrentFrameIndex)
            {
                // When frames jump we stop displaying the message
                m_FramesLeftToDiplayMessage = 0;
            }

            if (TangraConfig.Settings.ADVS.OverlayAllMessages &&
                !string.IsNullOrEmpty(state.Messages) &&
                state.Messages.Trim().Length > 0)
            {
                m_LastMessage = state.Messages.Trim();
                m_FramesLeftToDiplayMessage = context.MovementType == MovementType.Step ? 1 : 10;
            }

            if ((TangraConfig.Settings.ADVS.OverlayAdvsInfo || TangraConfig.Settings.ADVS.OverlayCameraInfo || TangraConfig.Settings.ADVS.OverlayGeoLocation) &&
                (!m_EquipmentInfoDisplayed || m_FirstFrameNo == context.CurrentFrameIndex))
            {
                int numLines = 0;
                int lineNo   = 0;
                if (TangraConfig.Settings.ADVS.OverlayCameraInfo)
                {
                    numLines += 2;
                }
                if (TangraConfig.Settings.ADVS.OverlayAdvsInfo)
                {
                    numLines += 2;
                }
                if (TangraConfig.Settings.ADVS.OverlayGeoLocation)
                {
                    numLines += 1;
                }

                float startingY = currentImage.Height - numLines * (s_PropertiesFont.Size + 5) - 10;
                if (TangraConfig.Settings.ADVS.OverlayTimestamp)
                {
                    startingY -= m_YPosUpper;
                }

                if (TangraConfig.Settings.ADVS.OverlayAdvsInfo && m_AdvFileMetadataInfo != null)
                {
                    g.DrawString(m_AdvFileMetadataInfo.Recorder, s_PropertiesFont, s_PropertiesWhiteBrush, 10, startingY + lineNo * (s_PropertiesFont.Size + 5));
                    lineNo++;
                    if (!string.IsNullOrEmpty(m_AdvFileMetadataInfo.AdvrVersion))
                    {
                        g.DrawString(
                            string.Format("ADVR v{0} HTCC v{1}", m_AdvFileMetadataInfo.AdvrVersion, m_AdvFileMetadataInfo.HtccFirmareVersion),
                            s_PropertiesFont, s_PropertiesWhiteBrush, 10, startingY + lineNo * (s_PropertiesFont.Size + 5));
                    }
                    lineNo++;
                }

                if (TangraConfig.Settings.ADVS.OverlayCameraInfo && m_AdvFileMetadataInfo != null)
                {
                    if (!string.IsNullOrEmpty(m_AdvFileMetadataInfo.SensorInfo))
                    {
                        g.DrawString(m_AdvFileMetadataInfo.SensorInfo, s_PropertiesFont, s_PropertiesWhiteBrush, 10, startingY + lineNo * (s_PropertiesFont.Size + 5));
                    }
                    lineNo++;
                    if (!string.IsNullOrEmpty(m_AdvFileMetadataInfo.Camera))
                    {
                        g.DrawString(m_AdvFileMetadataInfo.Camera, s_PropertiesFont, s_PropertiesWhiteBrush, 10, startingY + lineNo * (s_PropertiesFont.Size + 5));
                    }
                    lineNo++;
                }

                if (TangraConfig.Settings.ADVS.OverlayGeoLocation && m_GeoLocation != null)
                {
                    g.DrawString(m_GeoLocation.GetFormattedGeoLocation(), s_PropertiesFont, s_PropertiesWhiteBrush, 10, startingY + lineNo * (s_PropertiesFont.Size + 5));
                    lineNo++;
                }

                g.Save();

                m_EquipmentInfoDisplayed = true;
            }

            if (m_FramesLeftToDiplayMessage > 0)
            {
                if (TangraConfig.Settings.ADVS.OverlayObjectName)
                {
                    numTopLines++;
                }

                g.DrawString(m_LastMessage, s_PropertiesFont, s_PropertiesYellowBrush, 10, 10 + numTopLines * (s_PropertiesFont.Size + 5));
                g.Save();
                m_FramesLeftToDiplayMessage--;
            }
        }
Example #11
0
        public void NextFrame(int frameNo, MovementType movementType, bool isLastFrame, AstroImage astroImage, int firstFrameInIntegrationPeriod, string fileName)
        {
            m_CurrentFrameNo = frameNo;

            if (m_OperationState == SpectroscopyState.RunningMeasurements)
            {
                if (m_FirstMeasuredFrame == null)
                {
                    m_FirstMeasuredFrame = m_CurrentFrameNo;
                    if (m_VideoController.HasEmbeddedTimeStamps())
                    {
                        m_FirstFrameTimeStamp = m_VideoController.GetCurrentFrameTime();
                    }
                    else if (m_VideoController.HasSystemTimeStamps())
                    {
                        m_FirstFrameTimeStamp = m_VideoController.GetCurrentFrameTime();
                    }
                    m_FrameBitmapPixels = astroImage.Pixelmap.DisplayBitmapPixels;
                }

                m_Tracker.NextFrame(frameNo, astroImage);
                if (m_Tracker.IsTrackedSuccessfully)
                {
                    TrackedObject trackedStar = m_Tracker.TrackedStar;
                    SelectedStar = trackedStar.Center;

                    m_Reader = new SpectraReader(astroImage, SelectedStarBestAngle, m_SpectroscopyController.SpectraReductionContext.PixelValueCoefficient);

                    Spectra thisFrameSpectra = m_Reader.ReadSpectra(
                        trackedStar.ThisFrameX,
                        trackedStar.ThisFrameY,
                        m_SpectroscopyController.SpectraReductionContext.MeasurementAreaWing,
                        m_SpectroscopyController.SpectraReductionContext.BackgroundAreaWing,
                        m_SpectroscopyController.SpectraReductionContext.BackgroundAreaGap,
                        m_SpectroscopyController.SpectraReductionContext.BackgroundMethod);

                    thisFrameSpectra.ZeroOrderFWHM = trackedStar.PSFFit != null ? (float)trackedStar.PSFFit.FWHM : float.NaN;

                    m_AllFramesSpectra.Add(thisFrameSpectra);
                }

                if (isLastFrame || m_CancelMeasurementsRequested || m_AllFramesSpectra.Count >= m_SpectroscopyController.SpectraReductionContext.FramesToMeasure)
                {
                    m_FramePlayer.Stop();

                    m_MasterSpectra = m_SpectroscopyController.ComputeResult(
                        m_AllFramesSpectra,
                        m_SpectroscopyController.SpectraReductionContext.FrameCombineMethod,
                        m_SpectroscopyController.SpectraReductionContext.UseFineAdjustments,
                        m_SpectroscopyController.SpectraReductionContext.AlignmentAbsorptionLinePos);

                    m_AllFramesSpectra.Clear();

                    m_MasterSpectra.MeasurementInfo = m_SpectroscopyController.GetMeasurementInfo();
                    m_MasterSpectra.MeasurementInfo.FirstMeasuredFrame  = m_FirstMeasuredFrame.Value;
                    m_MasterSpectra.MeasurementInfo.LastMeasuredFrame   = m_CurrentFrameNo;
                    m_MasterSpectra.MeasurementInfo.FirstFrameTimeStamp = m_FirstFrameTimeStamp;
                    if (m_VideoController.HasEmbeddedTimeStamps())
                    {
                        m_MasterSpectra.MeasurementInfo.LastFrameTimeStamp = m_VideoController.GetCurrentFrameTime();
                    }
                    else if (m_VideoController.HasSystemTimeStamps())
                    {
                        m_MasterSpectra.MeasurementInfo.LastFrameTimeStamp = m_VideoController.GetCurrentFrameTime();
                    }

                    FrameStateData frameStatus = m_VideoController.GetCurrentFrameState();
                    m_MasterSpectra.MeasurementInfo.Gain            = frameStatus.Gain;
                    m_MasterSpectra.MeasurementInfo.ExposureSeconds = m_SpectroscopyController.SpectraReductionContext.ExposureSeconds;

                    m_MasterSpectra.MeasurementInfo.FrameBitmapPixels = m_FrameBitmapPixels;

                    m_SpectroscopyController.PopulateMasterSpectraObservationDetails(m_MasterSpectra);

                    m_OperationState = SpectroscopyState.DisplayingMeasurements;
                    m_ControlPanel.MeasurementsFinished();
                    DisplaySpectra();
                }

                Application.DoEvents();
            }
        }
Example #12
0
        private void frmRunMultiFrameMeasurements_Load(object sender, EventArgs e)
        {
            cbxExpectedMotion.SelectedIndex = (int)m_MeasurementContext.MovementExpectation;
            cbxSignalType.SelectedIndex     = (int)m_MeasurementContext.ObjectExposureQuality;
            cbxFrameTimeType.SelectedIndex  = (int)m_MeasurementContext.FrameTimeType;
            nudInstrDelay.SetNUDValue(m_MeasurementContext.InstrumentalDelay);
            cbxInstDelayUnit.SelectedIndex = (int)m_MeasurementContext.InstrumentalDelayUnits;
            nudIntegratedFrames.SetNUDValue(m_MeasurementContext.IntegratedFramesCount);

            nudInstrDelay.Enabled        = true;
            cbxInstDelayUnit.Enabled     = true;
            nudIntegratedFrames.Enabled  = true;
            btnDetectIntegration.Enabled = true;

            cbxInstDelayCamera.SelectedIndex = cbxInstDelayCamera.Items.IndexOf(TangraConfig.Settings.PlateSolve.SelectedCameraModel);
            cbxInstDelayMode.SelectedIndex   = 0;           // Automatic
            if (cbxInstDelayCamera.SelectedIndex == -1)
            {
                cbxInstDelayCamera.SelectedIndex = 0;               // No camera selected
                cbxInstDelayMode.SelectedIndex   = 1;               // Manual
            }

            m_AavStacking     = false;
            m_AavIntegration  = false;
            m_VideoFileFormat = m_VideoController.GetVideoFileFormat();
            if (m_VideoFileFormat != VideoFileFormat.AVI)
            {
                cbxFrameTimeType.SelectedIndex = 0;
                cbxFrameTimeType.Enabled       = false;

                DateTime?timeStamp = m_VideoController.GetCurrentFrameTime();
                if (timeStamp != null && timeStamp != DateTime.MinValue)
                {
                    DateTime timestamp = timeStamp.Value;

                    if (m_VideoFileFormat.IsAAV())
                    {
                        m_NativeFormat = m_VideoController.GetVideoFormat(m_VideoFileFormat);

                        // Compute the first timestamp value
                        if (m_VideoController.HasTimestampOCR())
                        {
                            timestamp = m_FieldSolveContext.UtcTime.Date.Add(timestamp.TimeOfDay);
                        }
                        else
                        {
                            FrameStateData frameState = m_VideoController.GetCurrentFrameState();
                            timestamp = timestamp.AddMilliseconds(-0.5 * frameState.ExposureInMilliseconds);

                            if (m_NativeFormat == "PAL")
                            {
                                timestamp = timestamp.AddMilliseconds(20);
                            }
                            else if (m_NativeFormat == "NTSC")
                            {
                                timestamp = timestamp.AddMilliseconds(16.68);
                            }
                        }
                    }

                    ucUtcTimePicker.DateTimeUtc = timestamp;
                    ucUtcTimePicker.Enabled     = false;                 // The video has embedded timestamp so the users should not enter times manually
                }

                if (m_VideoFileFormat.IsAAV())
                {
                    nudIntegratedFrames.Enabled = false;

                    if (m_VideoController.AstroAnalogueVideoStackedFrameRate > 0)
                    {
                        cbxFrameTimeType.Items[0]    = "AAV stacked frame";
                        pnlIntegration.Visible       = true;
                        btnDetectIntegration.Visible = false;
                        lblFrames.Text            = string.Format("frames (stacking: {0} frames)", m_VideoController.AstroAnalogueVideoStackedFrameRate);
                        m_AavStacking             = true;
                        nudIntegratedFrames.Value = m_VideoController.AstroAnalogueVideoIntegratedAAVFrames;
                    }
                    else if (m_VideoController.AstroAnalogueVideoIntegratedAAVFrames > 0)
                    {
                        cbxFrameTimeType.Items[0]    = "AAV integrated frame";
                        pnlIntegration.Visible       = true;
                        btnDetectIntegration.Visible = false;
                        nudIntegratedFrames.Value    = m_VideoController.AstroAnalogueVideoIntegratedAAVFrames;
                        m_AavIntegration             = true;
                    }
                }
            }
            else
            {
                // This will be set in the exported CSV file and will then be used to identify repeated measurements from integrated AAV files
                m_NativeFormat = "AVI-Integrated";
            }

            activePage = 0;
            DisplayActivePage();

            // Allow time corrections to be set automatically even when the integration is not recognized ("use suggested value" button) or something
        }
Example #13
0
        private void OverlayAAVState(Graphics g, Bitmap currentImage, FrameStateData state, int currentFrameNo)
        {
            if (TangraConfig.Settings.AAV.Overlay_Timestamp)
            {
                string timeStampStr = state.HasValidTimeStamp
                                                ? string.Format("{0}.{1}", state.CentralExposureTime.ToString("dd MMM yyyy HH:mm:ss"), state.CentralExposureTime.Millisecond.ToString().PadLeft(3, '0'))
                        : "Embedded Timestamp Not Found";
                g.DrawString(timeStampStr, s_TimeStampFont, s_TimeStampBrush, m_XPos, currentImage.Height - m_YPosUpper - 15);
                g.Save();
            }

            int numTopLines = 0;

            if (TangraConfig.Settings.AAV.Overlay_ObjectName && m_AdvFileMetadataInfo != null && !string.IsNullOrWhiteSpace(m_AdvFileMetadataInfo.ObjectName) &&
                (!m_ObjectInfoDisplayed || m_FirstFrameNo == currentFrameNo))
            {
                string objectNameStr = string.Format(" {0}", m_AdvFileMetadataInfo.ObjectName);
                g.DrawString(objectNameStr, s_PropertiesFont, s_PropertiesGreenBrush, 10, 10 + numTopLines * (s_PropertiesFont.Size + 5));
                g.Save();
                numTopLines++;
                m_ObjectInfoDisplayed = true;
            }

            if (m_LastFrameNo + 1 != currentFrameNo)
            {
                // When frames jump we stop displaying the message
                m_FramesLeftToDiplayMessage = 0;
            }

            if (TangraConfig.Settings.AAV.Overlay_AllMessages &&
                !string.IsNullOrEmpty(state.Messages) &&
                state.Messages.Trim().Length > 0)
            {
                m_LastMessage = state.Messages.Trim();
                m_FramesLeftToDiplayMessage = 10;
            }

            if ((TangraConfig.Settings.AAV.Overlay_AdvsInfo || TangraConfig.Settings.AAV.Overlay_CameraInfo) &&
                (!m_EquipmentInfoDisplayed || m_FirstFrameNo == currentFrameNo))
            {
                int numLines = 0;
                int lineNo   = 0;
                if (TangraConfig.Settings.AAV.Overlay_CameraInfo)
                {
                    numLines += 1;
                }
                if (TangraConfig.Settings.AAV.Overlay_AdvsInfo)
                {
                    numLines += 1;
                }

                float startingY = currentImage.Height - numLines * (s_PropertiesFont.Size + 5) - 35;
                if (TangraConfig.Settings.AAV.Overlay_Timestamp)
                {
                    startingY -= m_YPosUpper;
                }

                if (TangraConfig.Settings.AAV.Overlay_AdvsInfo && m_AdvFileMetadataInfo != null)
                {
                    g.DrawString(m_AdvFileMetadataInfo.Recorder, s_PropertiesFont, s_PropertiesWhiteBrush, 10, startingY + lineNo * (s_PropertiesFont.Size + 5));
                    lineNo++;
                }

                if (TangraConfig.Settings.AAV.Overlay_CameraInfo && m_AdvFileMetadataInfo != null)
                {
                    if (!string.IsNullOrEmpty(m_AdvFileMetadataInfo.Camera))
                    {
                        g.DrawString(m_AdvFileMetadataInfo.Camera, s_PropertiesFont, s_PropertiesWhiteBrush, 10, startingY + lineNo * (s_PropertiesFont.Size + 5));
                    }
                    lineNo++;
                }

                g.Save();

                m_EquipmentInfoDisplayed = true;
            }
        }
Example #14
0
        public void ShowStatus(FrameStateData frameState)
        {
            m_FrameState = frameState;

            var statusText = new StringBuilder();

            if (m_AavSettings.Popup_Satellites)
            {
                statusText.AppendLine(string.Format("Tracked Satellites: {0}", m_FrameState.NumberSatellites));
            }

            if (m_AavSettings.Popup_Almanac)
            {
                statusText.AppendLine(string.Format("Almanac Status: {0}", m_FrameState.AlmanacStatus));
            }

            if (m_AavSettings.Popup_GPSFix)
            {
                int    intStatus;
                string strStatus;
                if (int.TryParse(m_FrameState.GPSFixStatus, out intStatus))
                {
                    strStatus = AdvStatusValuesHelper.TranslateGpsFixStatus(intStatus);
                }
                else
                {
                    strStatus = m_FrameState.GPSFixStatus;
                }

                statusText.AppendLine(string.Format("GPS Fix: {0}", strStatus));
            }

            if (m_AavSettings.Popup_Satellites || m_AavSettings.Popup_Almanac || m_AavSettings.Popup_GPSFix)
            {
                statusText.AppendLine();
            }

            if (m_AavSettings.Popup_Timestamp)
            {
                statusText.AppendLine(string.Format("Central Exposure Time: {0}",
                                                    m_FrameState.HasValidTimeStamp
                            ? m_FrameState.CentralExposureTime.ToString("dd MMM yyyy HH:mm:ss.fff")
                            : "Embedded Timestamp Not Found"));
            }

            if (m_AavSettings.Popup_Exposure)
            {
                if (m_FrameState.HasValidTimeStamp)
                {
                    statusText.AppendLine(string.Format("Exposure Duration: {0} ms", m_FrameState.ExposureInMilliseconds.ToString("0")));
                }
                else if (m_FrameState.NumberStackedFrames.HasValue && m_FrameState.NumberStackedFrames.Value > 0)
                {
                    string timestamp = string.Format("Exposure Duration: x{0} stack", m_FrameState.NumberStackedFrames.Value.ToString("0"));
                    if (m_FrameState.ExposureInMilliseconds > 0)
                    {
                        timestamp += string.Format(" ({0} ms)", m_FrameState.ExposureInMilliseconds.ToString("0"));
                    }

                    statusText.AppendLine(timestamp);
                }
                else if (m_FrameState.NumberIntegratedFrames.HasValue && m_FrameState.NumberIntegratedFrames.Value > 0)
                {
                    string timestamp = string.Format("Exposure Duration: x{0} integration", m_FrameState.NumberIntegratedFrames.Value.ToString("0"));
                    if (m_FrameState.ExposureInMilliseconds > 0)
                    {
                        timestamp += string.Format(" ({0} ms)", m_FrameState.ExposureInMilliseconds.ToString("0"));
                    }

                    statusText.AppendLine(timestamp);
                }
                else
                {
                    statusText.AppendLine("Exposure Duration: Unknown");
                }
            }

            if (m_AavSettings.Popup_Timestamp || m_AavSettings.Popup_Exposure)
            {
                statusText.AppendLine();
            }

            if (m_AavSettings.Popup_Gain)
            {
                statusText.AppendLine(m_FrameState.Gain > 0
                                                        ? string.Format("Gain: {0} dB", m_FrameState.Gain.ToString("0"))
                                                        : "Gain: Unknown");
            }

            if (m_AavSettings.Popup_Gamma)
            {
                statusText.AppendLine(m_FrameState.Gamma > 0
                                                        ? string.Format("Gamma: {0}", m_FrameState.Gamma.ToString("0.000"))
                                                        : "Gamma: Unknown");
            }

            if (m_AavSettings.Popup_Temperature)
            {
                statusText.AppendLine(m_FrameState.Temperature > 0
                                                        ? string.Format("Temperature: {0}", m_FrameState.Temperature.ToString("0.0"))
                                                        : "Temperature: Unknown");
            }

            if (m_AavSettings.Popup_Gain || m_AavSettings.Popup_Gamma)
            {
                statusText.AppendLine();
            }

            if (m_AavSettings.Popup_NtpTimestamp)
            {
                statusText.AppendLine(string.Format("NTP Timestamp: {0}", m_FrameState.HasValidNtpTimeStamp ? m_FrameState.EndFrameNtpTime.ToString("dd MMM yyyy HH:mm:ss.fff") : ""));
            }

            if (m_AavSettings.Popup_SystemTime)
            {
                statusText.AppendLine(string.Format("PC Clock Time: {0}", m_FrameState.SystemTime.ToString("dd MMM yyyy HH:mm:ss.fff")));
            }

            if (m_AavSettings.Popup_SystemTime)
            {
                statusText.AppendLine();
            }

            lblStatusCombined.Text = statusText.ToString();
            this.Height            = 182 /* Nominal height of the form */ - 117 /* Nominal height of the label*/ + lblStatusCombined.Height;
            this.Width             = 213 /* Nominal width of the form */ - 181 /* Nominal width of the label*/ + lblStatusCombined.Width;
            btnCopy.Top            = 126 /* Nominal top position of the button */ - 117 /* Nominal height of the label*/ + lblStatusCombined.Height;
            btnCopy.Left           = (this.Width - btnCopy.Width) / 2;
        }
Example #15
0
        public void ShowStatus(FrameStateData frameState)
        {
            var dataList = frameState.AdditionalProperties != null?frameState.AdditionalProperties.Select(kvp => new TagValuePair(kvp.Key, Convert.ToString(kvp.Value))).ToList() : null;

            dataGridView.DataSource = dataList;
        }