Exemplo n.º 1
0
        internal CSVExportOptions GetSelectedOptions()
        {
            var rv = new CSVExportOptions();

            if (rbTimeString.Checked)
            {
                rv.TimeFormat = TimeFormat.String;
            }
            else if (rbDecimalDays.Checked)
            {
                rv.TimeFormat = TimeFormat.DecimalDays;
            }
            else if (rbJulianDays.Checked)
            {
                rv.TimeFormat = TimeFormat.DecimalJulianDays;
            }

            rv.ExcelFriendly = cbExcelFriendly.Checked;

            if (rbFlux.Checked)
            {
                rv.PhotometricFormat = PhotometricFormat.RelativeFlux;
            }
            else if (rbMagnitude.Checked)
            {
                rv.PhotometricFormat = PhotometricFormat.Magnitudes;
            }

            rv.M0 = m_M0;

            rv.ExportAtmosphericExtinction = cbxAtmExtExport.Checked;
            rv.ExportObjectPosition        = cbxExportPositions.Checked;
            rv.ExportPsfParameters         = cbxExportFSPParameters.Checked;
            if (cbxAtmExtExport.Checked)
            {
                rv.RAHours      = m_RAHours;
                rv.DEDeg        = m_DEDeg;
                rv.LongitudeDeg = m_Longitude;
                rv.LatitudeDeg  = m_Latitude;
                rv.HeightKM     = m_HeightKm;
            }

            if (m_ConfirmedDate.HasValue)
            {
                rv.FistMeasurementDay       = m_ConfirmedDate;
                rv.FistMeasurementTimeStamp = LCFile.GetTimeForFrame(LCFile.Header.MinFrame);
            }

            rv.Spacing                    = cbxSpacingOptions.SelectedIndex + 1;
            rv.ExportStartingFrame        = (int)nudExportStartFromFrame.Value;
            rv.ForceSignalMinusBackground = this.OnlyExportSignalMunusBg || rbSeriesSmB.Checked;

            return(rv);
        }
Exemplo n.º 2
0
        internal CSVExportOptions GetSelectedOptions()
        {
            var rv = new CSVExportOptions();

            if (rbTimeString.Checked) rv.TimeFormat = TimeFormat.String;
            else if (rbDecimalDays.Checked) rv.TimeFormat = TimeFormat.DecimalDays;
            else if (rbJulianDays.Checked) rv.TimeFormat = TimeFormat.DecimalJulianDays;

            rv.ExcelFriendly = cbExcelFriendly.Checked;

            if (rbFlux.Checked) rv.PhotometricFormat = PhotometricFormat.RelativeFlux;
            else if (rbMagnitude.Checked) rv.PhotometricFormat = PhotometricFormat.Magnitudes;

            rv.M0 = m_M0;

            rv.ExportAtmosphericExtinction = cbxAtmExtExport.Checked;
            rv.ExportObjectPosition = cbxExportPositions.Checked;
            rv.ExportPsfParameters = cbxExportFSPParameters.Checked;
            if (cbxAtmExtExport.Checked)
            {
                rv.RAHours = m_RAHours;
                rv.DEDeg = m_DEDeg;
                rv.LongitudeDeg = m_Longitude;
                rv.LatitudeDeg = m_Latitude;
                rv.HeightKM = m_HeightKm;
            }

            if (m_ConfirmedDate.HasValue)
            {
                rv.FistMeasurementDay = m_ConfirmedDate;
                rv.FistMeasurementTimeStamp = LCFile.GetTimeForFrame(LCFile.Header.MinFrame);
            }

            rv.Spacing = cbxSpacingOptions.SelectedIndex + 1;
            rv.ExportStartingFrame = (int)nudExportStartFromFrame.Value;
            rv.ForceSignalMinusBackground = this.OnlyExportSignalMunusBg || rbSeriesSmB.Checked;

            return rv;
        }
Exemplo n.º 3
0
        private void CSVExportAddCommonHeader(StringBuilder output, CSVExportOptions options, bool binning)
        {
            Version ver = Assembly.GetExecutingAssembly().GetName().Version;

            output.AppendFormat("Tangra v{0}", ver.ToString()); output.AppendLine();
            if (binning)
                output.AppendFormat("Measurments of {0} objects; Bins of {1} frames starting at frame {2}; Binned Measurement = {3}", m_Header.ObjectCount, m_LightCurveController.Context.Binning, m_LightCurveController.Context.BinningFirstFrame, m_LightCurveController.Context.ProcessingType);
            else
                output.AppendFormat("Measurments of {0} objects", m_Header.ObjectCount);

            output.AppendLine();
            output.Append(m_Header.PathToVideoFile); output.AppendLine();
            string timeSource = TranslateTimingType(m_Header.TimingType);
            if (m_Header.SerTimingType != SerUseTimeStamp.None) timeSource += string.Format(" ({0})", m_Header.SerTimingType);
            output.AppendFormat("{0} {1}, Time: {2}", m_Header.ReductionType, m_Header.SourceInfo, timeSource); output.AppendLine();
            output.AppendLine();output.AppendLine();
            bool addPSFReductionDetails = m_LightCurveController.Context.SignalMethod != TangraConfig.PhotometryReductionMethod.AperturePhotometry;
            bool addPSFAverageModelDetails = addPSFReductionDetails && m_LightCurveController.Context.PsfFittingMethod == TangraConfig.PsfFittingMethod.LinearFitOfAveragedModel;
            bool addIntegrationInfo = m_Footer.ReductionContext.FrameIntegratingMode != FrameIntegratingMode.NoIntegration;

            string instrumentalDelayStatus = "Not Applied";
            if (m_LightCurveController.Context.TimingType == MeasurementTimingType.EmbeddedTimeForEachFrame && m_LightCurveController.Context.InstrumentalDelayCorrectionsNotRequired)
                instrumentalDelayStatus = "Not Required";
            else if (!string.IsNullOrEmpty(m_LightCurveController.Context.InstrumentalDelayConfigName) && m_LightCurveController.Context.TimingType != MeasurementTimingType.UserEnteredFrameReferences)
                instrumentalDelayStatus = "Applied";

            output.Append("Reversed Gamma, Colour, Measured Band, Integration, Digital Filter, Signal Method, Background Method, Instrumental Delay Corrections, Camera, AAV Integration, First Frame, Last Frame, Reversed Camera Response");
            if (addPSFReductionDetails) output.Append(", PSF Fitting");
            if (addPSFAverageModelDetails) output.Append(", Modeled FWHM, Average FWHM");
            if (options.PhotometricFormat == PhotometricFormat.Magnitudes) output.Append(", Zero Magnitude");
            output.AppendLine();
            output.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}",
                m_LightCurveController.Context.EncodingGamma.ToString("0.00"),
                m_Footer.ReductionContext.IsColourVideo ? "yes" : "no",
                m_Footer.ReductionContext.ColourChannel,
                addIntegrationInfo
                    ? string.Format("{0} {1} of {2} frames", m_Footer.ReductionContext.PixelIntegrationType, m_Footer.ReductionContext.FrameIntegratingMode, m_Footer.ReductionContext.NumberFramesToIntegrate)
                    : "no",
                m_LightCurveController.Context.Filter,
                m_LightCurveController.Context.SignalMethod,
                m_LightCurveController.Context.BackgroundMethod,
                instrumentalDelayStatus,
                !string.IsNullOrEmpty(m_LightCurveController.Context.CameraName) ?  m_LightCurveController.Context.CameraName : m_LightCurveController.Context.InstrumentalDelayConfigName,
                m_LightCurveController.Context.AAVFrameIntegration == -1 ? "" : m_LightCurveController.Context.AAVFrameIntegration.ToString(),
                m_LightCurveController.Context.MinFrame,
                m_LightCurveController.Context.MaxFrame,
                m_LightCurveController.Context.ReverseCameraResponse == TangraConfig.KnownCameraResponse.Undefined ? "" : m_LightCurveController.Context.ReverseCameraResponse.ToString());

            if (addPSFReductionDetails) output.AppendFormat(",{0}", m_LightCurveController.Context.PsfFittingMethod);
            if (addPSFAverageModelDetails) output.AppendFormat(",{0},{1}", float.IsNaN(m_LightCurveController.Context.ManualAverageFWHM) ? "auto" : "manual", !float.IsNaN(m_LightCurveController.Context.ManualAverageFWHM) ? m_LightCurveController.Context.ManualAverageFWHM.ToString("0.00") : m_Footer.RefinedAverageFWHM.ToString("0.00"));
            if (options.PhotometricFormat == PhotometricFormat.Magnitudes) output.AppendFormat(",{0}", options.M0.ToString("0.000"));

            output.AppendLine();output.AppendLine();
            output.Append("Object, Type, Aperture, Tolerance, FWHM, Measured, StartingX, StartingY, Fixed"); output.AppendLine();
            for (int j = 0; j < m_Header.ObjectCount; j++)
            {
                TrackedObjectConfig obj = m_Footer.TrackedObjects[j];
                output.AppendFormat("{0},{1},{2},{3},{4},{5},{6},{7},{8}",
                    j + 1, obj.TrackingType.ToString(), m_LightCurveController.Context.ReProcessApertures[j].ToString("0.00"),
                    obj.TrackingType == TrackingType.OccultedStar ? obj.PositionTolerance.ToString("0.00") : "", obj.RefinedFWHM.ToString("0.00"),
                    obj.MeasureThisObject ? "yes" : "no",
                    obj.ApertureStartingX.ToString("0.0"), obj.ApertureStartingY.ToString("0.0"), obj.IsFixedAperture ? "yes" : "no");
                output.AppendLine();
            }
            output.AppendLine(); output.AppendLine();
        }
Exemplo n.º 4
0
        public bool ExportToCSV(string fileName, CSVExportOptions options)
        {
            var output = new StringBuilder();

            AtmosphericExtinctionCalculator atmExtCalc = null;
            if (options.ExportAtmosphericExtinction)
                atmExtCalc = new AtmosphericExtinctionCalculator(options.RAHours, options.DEDeg, options.LongitudeDeg, options.LatitudeDeg, options.HeightKM);

            string videoSystem;
            double absoluteTimeError = m_TimestampDiscrepencyFlag
                                           ? Math.Abs(m_Header.GetAbsoluteTimeDeltaInMilliseconds(out videoSystem))
                                           : 0;

            uint objCount = m_Header.ObjectCount;
            if (m_LightCurveController.Context.Binning > 0)
            {
                // Binned frames
                int count = m_AllBinnedReadings[0].Count;
                int firstFrameNoInBin = (int)m_Header.MinFrame;

                CSVExportAddCommonHeader(output, options, true);

                output.Append(string.Format("BinNo,Time ({0})", options.FormatTimeLabel()));

                for (int j = 0; j < objCount; j++)
                {
                    output.Append(options.FormatPhotometricValueHeaderForObject(j + 1, false, true));
                }

                bool isBadTime = false;
                double timePrecisionSec = 0;

                double resolutionInSecs = m_LightCurveController.Context.Binning / (2.0 * m_Header.FramesPerSecond);

                if (double.IsInfinity(resolutionInSecs) || double.IsNaN(resolutionInSecs)
                    && m_Header.LcFile != null && m_Header.LcFile.FrameTiming != null && m_Header.LcFile.FrameTiming.Count > 0)
                {

                    List<int> allExposures = m_Header.LcFile.FrameTiming.Select(x => x.FrameDurationInMilliseconds).ToList();
                    allExposures.Sort();
                    resolutionInSecs = m_LightCurveController.Context.Binning * allExposures[allExposures.Count / 2] / 1000.0;
                }

                if (resolutionInSecs < 0.1)
                {
                    timePrecisionSec = 0.001;
                    if (absoluteTimeError > 5) isBadTime = true;
                }
                else if (resolutionInSecs < 1)
                {
                    timePrecisionSec = 0.01;
                    if (absoluteTimeError > 5) isBadTime = true;
                }
                else if (resolutionInSecs < 10)
                {
                    timePrecisionSec = 0.1;
                    if (absoluteTimeError > 50) isBadTime = true;
                }
                else if (absoluteTimeError > 500)
                {
                    timePrecisionSec = 0.01;
                    isBadTime = true;
                }
                else if (!m_LCFile.Footer.ReductionContext.HasEmbeddedTimeStamps
                    /* If the times are entered by the user, only include the times for the frames enterred by the user. Unless the calculated timing descrepency is small (m_TimestampDiscrepencyFlag = false) */)
                {
                    timePrecisionSec = 0.01;
                    isBadTime = m_TimestampDiscrepencyFlag;
                }

                if (isBadTime &&
                    m_LCFile.Footer.ReductionContext.LightCurveReductionType == LightCurveReductionType.MutualEvent && absoluteTimeError/500 < resolutionInSecs)
                {
                    // Force export the time for mutual events where half the resolution is better than the absolute timing error
                    isBadTime = false;
                }

                if (options.PhotometricFormat == PhotometricFormat.Magnitudes && atmExtCalc != null)
                {
                    output.Append(", Atmospheric Extinction, Altitude (deg), Air Mass");
                }

                output.AppendLine();

                for (int i = 0; i < count; i++)
                {
                    if (options.Spacing > 1 && (i - options.ExportStartingFrame) % options.Spacing != 0)
                        // Skip all frames in the 'spaces'
                        continue;

                    if (i < (options.ExportStartingFrame - m_LightCurveController.Context.MinFrame))
                        // Skip all frames before the first frame configured to begin the export from
                        continue;

                    string isCorrectedForInstrumentalDelay;
                    double midBinFrameNumber =  firstFrameNoInBin < m_LightCurveController.Context.BinningFirstFrame
                            ? ((m_LightCurveController.Context.BinningFirstFrame - m_LightCurveController.Context.MinFrame) / 2.0) - 0.5
                            : firstFrameNoInBin + (m_LightCurveController.Context.Binning / 2.0) - 0.5;

                    DateTime middleBinTime = DateTime.MinValue;

                    if (midBinFrameNumber <= m_Header.MaxFrame && midBinFrameNumber >= m_Header.MinFrame)
                    {
                        int midBinFrameNumberInt = (int)midBinFrameNumber;
                        double midBinFrameNumberFrac = midBinFrameNumber - midBinFrameNumberInt;

                        middleBinTime = m_LCFile.GetTimeForFrame(midBinFrameNumberInt, out isCorrectedForInstrumentalDelay);
                        if (middleBinTime > DateTime.MinValue && midBinFrameNumberFrac > 0.00001 && midBinFrameNumberInt + 1 <= m_Header.MaxFrame)
                        {
                            DateTime middleBinPlusOneTime = m_LCFile.GetTimeForFrame(midBinFrameNumberInt + 1, out isCorrectedForInstrumentalDelay);
                            middleBinTime = middleBinTime.AddTicks((long)((middleBinPlusOneTime.Ticks - middleBinTime.Ticks) * midBinFrameNumberFrac));
                        }
                    }

                    string timeStr;
                    if (isBadTime)
                    {
                        if (m_Header.FirstTimedFrameNo >= firstFrameNoInBin && m_Header.FirstTimedFrameNo <= firstFrameNoInBin + m_LightCurveController.Context.Binning)
                            timeStr = options.FormatTime(m_Header.FirstTimedFrameTime, timePrecisionSec);
                        else if (m_Header.LastTimedFrameNo >= firstFrameNoInBin && m_Header.LastTimedFrameNo <= firstFrameNoInBin + m_LightCurveController.Context.Binning)
                            timeStr = options.FormatTime(m_Header.SecondTimedFrameTime, timePrecisionSec);
                        else
                            timeStr = options.FormatInvalidTime(timePrecisionSec);
                    }
                    else
                    {
                        if (middleBinTime == DateTime.MinValue || middleBinTime == DateTime.MaxValue)
                            timeStr = "";
                        else
                            timeStr = options.FormatTime(middleBinTime, timePrecisionSec);
                    }

                    output.AppendFormat("{0},{1}", i + 1, timeStr);

                    for (int j = 0; j < objCount; j++)
                    {
                        BinnedValue reading = m_AllBinnedReadings[j][i];
                        output.Append(options.FormatPhotometricValue(reading.IsSuccessfulReading, reading.AdjustedValue, 0, false, true));
                    }

                    if (options.PhotometricFormat == PhotometricFormat.Magnitudes && atmExtCalc != null &&
                        middleBinTime != DateTime.MinValue && middleBinTime != DateTime.MaxValue)
                    {
                        double altitudeDeg;
                        double airMass;
                        double extinction = atmExtCalc.CalculateExtinction(middleBinTime, out altitudeDeg, out airMass);
                        output.AppendFormat(",{0},{1},{2}", extinction.ToString(5), altitudeDeg.ToString(3), airMass.ToString(5));
                    }

                    output.AppendLine();

                    if (firstFrameNoInBin < m_LightCurveController.Context.BinningFirstFrame)
                        // If this is the first incomplete bin, then next bin's first frame is the first binning frame
                        firstFrameNoInBin = m_LightCurveController.Context.BinningFirstFrame;
                    else
                        firstFrameNoInBin += m_LightCurveController.Context.Binning;
                }
            }
            else
            {
                CSVExportAddCommonHeader(output, options, false);

                int count = m_LightCurveController.Context.AllReadings[0].Count;

                output.Append(string.Format("FrameNo,Time ({0})", options.FormatTimeLabel()));

                for (int j = 0; j < objCount; j++)
                {
                    output.Append(options.FormatPhotometricValueHeaderForObject(j + 1, options.ForceSignalMinusBackground, false));
                }

                for (int j = 0; j < objCount; j++)
                {
                    if (options.ExportObjectPosition) output.AppendFormat(",X ({0}) ,Y ({0})", j + 1);
                    if (options.ExportPsfParameters) output.AppendFormat(",PSF-I0 ({0}) ,PSF-FWHM ({0})", j + 1);
                }

                bool isBadTime = false;
                double timePrecisionSec = 0;

                if (absoluteTimeError > 5)
                {
                    timePrecisionSec = 0.001;
                    isBadTime = true;
                }
                else if (!m_LCFile.Footer.ReductionContext.HasEmbeddedTimeStamps
                    /* If the times are entered by the user, only include the times for the frames enterred by the user. Unless the calculated timing descrepency is small (m_TimestampDiscrepencyFlag = false) */)
                {
                    timePrecisionSec = 0.001;
                    isBadTime = m_TimestampDiscrepencyFlag;
                }
                else
                    timePrecisionSec = 0.001;

                if (options.PhotometricFormat == PhotometricFormat.Magnitudes && atmExtCalc != null)
                {
                    output.Append(", Atmospheric Extinction, Altitude (deg), Air Mass");
                }
                output.AppendLine();

                for (int i = 0; i < count; i++)
                {
                    if (options.Spacing > 1 && (i - options.ExportStartingFrame) % options.Spacing != 0)
                        // Skip all frames in the 'spaces'
                        continue;

                    if (i < (options.ExportStartingFrame - m_LightCurveController.Context.MinFrame))
                        // Skip all frames before the first frame configured to begin the export from
                        continue;

                    uint frameNo = m_LightCurveController.Context.AllReadings[0][i].CurrFrameNo;
                    string isCorrectedForInstrumentalDelay;
                    DateTime currFrameTime = m_LCFile.GetTimeForFrame(frameNo, out isCorrectedForInstrumentalDelay);

                    if (!string.IsNullOrEmpty(m_LightCurveController.Context.InstrumentalDelayConfigName) && isCorrectedForInstrumentalDelay == null)
                        // Single frames not corrected for instrumental delays, where instrumental delays are known, are considered bad times
                        currFrameTime = DateTime.MaxValue;

                    string timeStr;
                    if (isBadTime)
                    {
                        if (currFrameTime == DateTime.MinValue || currFrameTime == DateTime.MaxValue)
                            timeStr = "";
                        else if (frameNo == m_Header.FirstTimedFrameNo)
                            timeStr = options.FormatTime(m_Header.FirstTimedFrameTime, timePrecisionSec);
                        else if (frameNo == m_Header.LastTimedFrameNo)
                            timeStr = options.FormatTime(m_Header.SecondTimedFrameTime, timePrecisionSec);
                        else
                            timeStr = options.FormatInvalidTime(timePrecisionSec);
                    }
                    else
                    {
                        if (currFrameTime == DateTime.MinValue || currFrameTime == DateTime.MaxValue)
                            timeStr = "";
                        else
                            timeStr = options.FormatTime(currFrameTime, timePrecisionSec);
                    }

                    output.AppendFormat("{0},{1}", frameNo, timeStr);

                    for (int j = 0; j < objCount; j++)
                    {
                        LCMeasurement reading = m_LightCurveController.Context.AllReadings[j][i];
                        output.Append(options.FormatPhotometricValue(reading.IsSuccessfulReading, (int)reading.TotalReading, (int)reading.TotalBackground, options.ForceSignalMinusBackground, false));
                    }

                    for (int j = 0; j < objCount; j++)
                    {
                        LCMeasurement reading = m_LightCurveController.Context.AllReadings[j][i];
                        if (options.ExportObjectPosition) output.AppendFormat(",{0},{1}", reading.X0.ToString("0.0"), reading.Y0.ToString("0.0"));
                        if (options.ExportPsfParameters)
                        {
                            if (reading.PsfFit == null)
                            {
                                int x0Int = (int)Math.Round(reading.X0);
                                int y0Int = (int)Math.Round(reading.Y0);

                                reading.PsfFit = new PSFFit(x0Int, y0Int);
                                reading.PsfFit.FittingMethod = PSFFittingMethod.NonLinearFit;
                                int pixelDataWidth = reading.PixelData.GetLength(0);
                                int pixelDataHeight = reading.PixelData.GetLength(1);
                                reading.PsfFit.Fit(
                                    reading.PixelData,
                                    m_LightCurveController.Context.ReProcessFitAreas[reading.TargetNo],
                                    x0Int - reading.PixelDataX0 + (pixelDataWidth / 2) + 1,
                                    y0Int - reading.PixelDataY0 + (pixelDataHeight / 2) + 1,
                                    false);
                            }

                            output.AppendFormat(",{0},{1}", reading.PsfFit.I0.ToString("0.0"), reading.PsfFit.FWHM.ToString("0.000"));
                        }
                    }

                    if (options.PhotometricFormat == PhotometricFormat.Magnitudes && atmExtCalc != null &&
                        currFrameTime != DateTime.MinValue && currFrameTime != DateTime.MaxValue)
                    {
                        double altitudeDeg;
                        double airMass;
                        double extinction = atmExtCalc.CalculateExtinction(currFrameTime, out altitudeDeg, out airMass);
                        output.AppendFormat(",{0},{1},{2}", extinction.ToString(5), altitudeDeg.ToString(3), airMass.ToString(5));
                    }

                    output.AppendLine();
                }
            }

            try
            {
                File.WriteAllText(fileName, output.ToString());
                return true;
            }
            catch(IOException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
        }