private void btnOK_Click(object sender, EventArgs e) { m_ConfirmedDate = null; bool dayConfirmationRequired = (rbJulianDays.Checked || (rbMagnitude.Checked && cbxAtmExtExport.Checked)); if (dayConfirmationRequired) { DateTime firstTimestamp = LCFile.GetTimeForFrame(LCFile.Header.MinFrame); if (firstTimestamp.Year > 1900 && LCFile.Header.TimingType == MeasurementTimingType.EmbeddedTimeForEachFrame) { // No need to confirm the date. This is either an ADV file or an AAV file with time OCR-ed on the flly during the recording or AAV file with NTP timestamp } else { var frm = new frmConfirmDay(); frm.SelectedDay = firstTimestamp; frm.StartPosition = FormStartPosition.CenterParent; if (frm.ShowDialog(this) != DialogResult.OK) { return; } DateTime?selectedDate = frm.SelectedDay; if (selectedDate.HasValue) { m_ConfirmedDate = selectedDate.Value; } } } if (Binning && (nudExportStartFromFrame.Value != nudExportStartFromFrame.Minimum || cbxSpacingOptions.SelectedIndex > 0)) { MessageBox.Show(this, "When binning is used 'spacing' and a specific starting frame cannot be used as export options.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); tbxRA.Focus(); return; } if (cbxAtmExtExport.Checked) { try { if (string.IsNullOrWhiteSpace(tbxRA.Text)) { throw new FormatException(); } m_RAHours = AstroConvert.ToRightAcsension(tbxRA.Text); } catch (FormatException) { MessageBox.Show(this, "Please enter a valid Right Ascension value (e.g. 23 03 12)", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); tbxRA.Focus(); return; } try { if (string.IsNullOrWhiteSpace(tbxDec.Text)) { throw new FormatException(); } m_DEDeg = AstroConvert.ToDeclination(tbxDec.Text); } catch (FormatException) { MessageBox.Show(this, "Please enter a valid Declination value (e.g. +76 13 18)", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); tbxDec.Focus(); return; } try { if (string.IsNullOrWhiteSpace(tbxLatitude.Text)) { throw new FormatException(); } m_Latitude = AstroConvert.ToDeclination(tbxLatitude.Text); } catch (FormatException) { MessageBox.Show(this, "Please enter a valid Latitude value (e.g. -33 12 12)", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); tbxLatitude.Focus(); return; } try { if (string.IsNullOrWhiteSpace(tbxLongitude.Text)) { throw new FormatException(); } m_Longitude = AstroConvert.ToDeclination(tbxLongitude.Text); } catch (FormatException) { MessageBox.Show(this, "Please enter a valid Longitude value (e.g. -86 09 12)", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); tbxLongitude.Focus(); return; } try { if (string.IsNullOrWhiteSpace(tbxHeightKm.Text)) { throw new FormatException(); } m_HeightKm = double.Parse(tbxHeightKm.Text); } catch (FormatException) { MessageBox.Show(this, "Please enter a valid Height value (e.g. 0.150)", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); tbxHeightKm.Focus(); return; } var calc = new AtmosphericExtinctionCalculator(m_RAHours, m_DEDeg, m_Longitude, m_Latitude, m_HeightKm); DateTime firstTimestamp = LCFile.GetTimeForFrame(LCFile.Header.MinFrame); if (m_ConfirmedDate != null) { firstTimestamp = m_ConfirmedDate.Value.Date.AddTicks(firstTimestamp.Ticks - firstTimestamp.Date.Ticks); } double zenithAngle = calc.CalculateZenithAngle(firstTimestamp); if (zenithAngle > 90) { MessageBox.Show(this, "The object is below the horizon.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); } var savedSettings = new CoordsAndLocation() { RAHours = m_RAHours, DEDeg = m_DEDeg, LatitudeDeg = m_Latitude, LongitudeDeg = m_Longitude, HeightKM = m_HeightKm }; try { Properties.Settings.Default.AtmExtRememberedConfig = savedSettings.AsSerialized(); Properties.Settings.Default.Save(); } catch { } } // TODO: Confirm object is above horizon DialogResult = DialogResult.OK; Close(); }
internal void PopulateMasterSpectraObservationDetails(MasterSpectra spectra) { var dict = m_VideoController.GetVideoFileTags(); float lng = float.NaN; float lat = float.NaN; float ra = float.NaN; float dec = float.NaN; DateTime?centralTime = null; if (spectra.ObservationInfo == null) { spectra.ObservationInfo = new ObservationInfo(); } spectra.ObservationInfo.Reset(); if (dict.ContainsKey("Longitude")) { if (float.TryParse(dict["Longitude"], NumberStyles.Float, CultureInfo.InvariantCulture, out lng)) { spectra.ObservationInfo.AddProperty("Longitude", lng.ToString("0.0000", CultureInfo.InvariantCulture)); } } if (dict.ContainsKey("Latitude")) { if (float.TryParse(dict["Latitude"], NumberStyles.Float, CultureInfo.InvariantCulture, out lat)) { spectra.ObservationInfo.AddProperty("Latitude", lat.ToString("0.0000", CultureInfo.InvariantCulture)); } } if (dict.ContainsKey("RA")) { if (float.TryParse(dict["RA"], NumberStyles.Float, CultureInfo.InvariantCulture, out ra)) { spectra.ObservationInfo.AddProperty("RA", ra.ToString("0.0000", CultureInfo.InvariantCulture), "hours"); } } if (dict.ContainsKey("DEC")) { if (float.TryParse(dict["DEC"], NumberStyles.Float, CultureInfo.InvariantCulture, out dec)) { spectra.ObservationInfo.AddProperty("DEC", dec.ToString("0.0000", CultureInfo.InvariantCulture), "degrees"); } } if (spectra.MeasurementInfo.FirstFrameTimeStamp.HasValue && spectra.MeasurementInfo.LastFrameTimeStamp.HasValue) { centralTime = new DateTime((spectra.MeasurementInfo.FirstFrameTimeStamp.Value.Ticks + spectra.MeasurementInfo.LastFrameTimeStamp.Value.Ticks) / 2); double jd = JulianDayHelper.JDUtcAtDate(centralTime.Value); spectra.ObservationInfo.AddProperty("JD", jd.ToString("0.00000", CultureInfo.InvariantCulture), "UT"); } if (!float.IsNaN(lng) && !float.IsNaN(lat) && !float.IsNaN(ra) && !float.IsNaN(dec) && centralTime.HasValue) { var extCalc = new AtmosphericExtinctionCalculator(ra, dec, lng, lat, 0); double airMass; double altitudeDeg; extCalc.CalculateExtinction(centralTime.Value, out altitudeDeg, out airMass); spectra.ObservationInfo.AddProperty("X", airMass.ToString("0.000", CultureInfo.InvariantCulture), "air mass"); } if (!float.IsNaN(spectra.ZeroOrderFWHM)) { spectra.ObservationInfo.AddProperty("FWHM", spectra.ZeroOrderFWHM.ToString("0.00"), "zero order image FWHM"); } if (!float.IsNaN(spectra.MeasurementInfo.Gain)) { spectra.ObservationInfo.AddProperty("Gain", spectra.MeasurementInfo.Gain.ToString("0.0", CultureInfo.InvariantCulture), "dB"); } if (!float.IsNaN(spectra.MeasurementInfo.ExposureSeconds)) { spectra.ObservationInfo.AddProperty("Exposure", spectra.MeasurementInfo.ExposureSeconds.ToString("0.000", CultureInfo.InvariantCulture), "sec"); } if (dict.ContainsKey("ObjectName")) { spectra.ObservationInfo.AddProperty("Target", dict["ObjectName"]); } if (dict.ContainsKey("Instrument")) { spectra.ObservationInfo.AddProperty("Camera", dict["Instrument"]); } if (dict.ContainsKey("Telescope")) { spectra.ObservationInfo.AddProperty("Telescope", dict["Telescope"]); } if (dict.ContainsKey("Recorder")) { spectra.ObservationInfo.AddProperty("Recorder", dict["Recorder"]); } if (dict.ContainsKey("Observer")) { spectra.ObservationInfo.AddProperty("Observer", dict["Observer"]); } if (spectra.IsCalibrated()) { if (spectra.Calibration.PolynomialOrder == 1) { spectra.ObservationInfo.AddProperty("WavelengthCalibration", string.Format("1-st order[{0},{1}]", spectra.Calibration.A, spectra.Calibration.B)); } else if (spectra.Calibration.PolynomialOrder == 2) { spectra.ObservationInfo.AddProperty("WavelengthCalibration", string.Format("2-nd order[{0},{1},{2}]", spectra.Calibration.A, spectra.Calibration.B, spectra.Calibration.C)); } else if (spectra.Calibration.PolynomialOrder == 3) { spectra.ObservationInfo.AddProperty("WavelengthCalibration", string.Format("3-rd order[{0},{1},{2},{3}]", spectra.Calibration.A, spectra.Calibration.B, spectra.Calibration.C, spectra.Calibration.D)); } else if (spectra.Calibration.PolynomialOrder == 4) { spectra.ObservationInfo.AddProperty("WavelengthCalibration", string.Format("4-th order[{0},{1},{2},{3},{4}]", spectra.Calibration.A, spectra.Calibration.B, spectra.Calibration.C, spectra.Calibration.D, spectra.Calibration.E)); } spectra.ObservationInfo.AddProperty("Dispersion", spectra.Calibration.Dispersion.ToString("0.00", CultureInfo.InvariantCulture), "A/pix"); } }