예제 #1
0
        private static MPCheckEntry ParseLine(string line)
        {
            // Object designation         R.A.      Decl.     V       Offsets     Motion/hr   Orbit  <a href="http://www.cfa.harvard.edu/iau/info/FurtherObs.html">Further observations?</a>
            //                           h  m  s     &#176;  '  "        R.A.   Decl.  R.A.  Decl.        Comment (Elong/Decl/V at date 1)
            //
            //                                                                                                     1         1         1         1         1
            //          1         2         3         4         5         6         7         8         9         0         1         2         3         4
            //012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
            //    (55) Pandora         22 18 26.2 -20 16 13  11.4   4.4W   7.2N    21-     8-   56o  None needed at this time.
            //(148989) 2001 YM73       22 18 35.1 -20 08 33  19.8   2.3W  14.9N    19-    17-    5o  None needed at this time.
            //         2008 HM2        22 17 34.4 -20 16 40  19.9  16.6W   6.8N    20-    12-    5o  Very desirable between 2009 Aug. 27-Sept. 26.  (166.0,-22.5,19.7)
            //  (1448) Lindbladia      22 18 04.5 -20 02 00  16.7   9.5W  21.5N    25-    13-   24o  None needed at this time.

            try
            {
                MPCheckEntry entry = new MPCheckEntry();
                entry.ObjectName = line.Substring(0, 22).Trim();
                entry.RAHours    = AstroConvert.ToRightAcsension(line.Substring(25, 10).Trim());
                entry.DEDeg      = AstroConvert.ToDeclination(line.Substring(36, 9).Trim());

                string magStr = line.Substring(47, 4).Trim();
                entry.Mag = string.IsNullOrEmpty(magStr)
                    ? 30
                    : double.Parse(magStr, CultureInfo.InvariantCulture);

                return(entry);
            }
            catch
            {
                return(null);
            }
        }
예제 #2
0
            private static MPEphEntry ParseLine(string line)
            {
                // 00055
                // Date       UT      R.A. (J2000) Decl.    Delta     r     El.    Ph.   V      Sky Motion        Object    Sun   Moon                Uncertainty info
                //            h m s                                                            "/min    P.A.    Azi. Alt.  Alt.  Phase Dist. Alt.    3-sig/" P.A.
                //                                                                                                     1         1         1         1         1
                //           1         2         3         4         5         6         7         8         9         0         1         2         3         4
                // 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
                // 2009 07 27 124800 22 18 36.1 -20 15 18   1.545   2.497  153.8  10.3  11.4    0.40    249.0    264  +47   -68   0.36   130  +03         0 318.1
                // 2010 12 11 130549 07 34 48.3 -17 52 01   0.342   1.220  126.5  40.5   7.9    0.54    235.0    261  +46   -32   0.31   137  -03

                try
                {
                    MPEphEntry retVal = new MPEphEntry();

                    int year  = int.Parse(line.Substring(0, 4).Trim());
                    int month = int.Parse(line.Substring(5, 2).Trim());
                    int day   = int.Parse(line.Substring(8, 2).Trim());
                    int hr    = int.Parse(line.Substring(11, 2).Trim());
                    int min   = int.Parse(line.Substring(13, 2).Trim());
                    int sec   = int.Parse(line.Substring(15, 2).Trim());

                    retVal.UtcDate   = new DateTime(year, month, day, hr, min, sec);
                    retVal.RAHours   = AstroConvert.ToRightAcsension(line.Substring(18, 10).Trim());
                    retVal.DEDeg     = AstroConvert.ToDeclination(line.Substring(29, 9).Trim());
                    retVal.Mag       = double.Parse(line.Substring(69, 4).Trim(), CultureInfo.InvariantCulture);
                    retVal.SkyMotion = double.Parse(line.Substring(74, 7).Trim(), CultureInfo.InvariantCulture);

                    return(retVal);
                }
                catch
                {
                    return(null);
                }
            }
예제 #3
0
        private bool ValidateParameters()
        {
            try
            {
                m_RA = AstroConvert.ToRightAcsension(tbxRA.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxRA.Focus();
                return(false);
            }

            try
            {
                m_DE = AstroConvert.ToDeclination(tbxDE.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxDE.Focus();
                return(false);
            }

            return(true);
        }
예제 #4
0
        public double GetObservationDEDeg()
        {
            try
            {
                return(AstroConvert.ToDeclination(m_DEString_45_56.Trim()));
            }
            catch (Exception)
            { }

            return(double.NaN);
        }
예제 #5
0
        public override void SaveSettings()
        {
            if (rbMPCCode.Checked)
            {
                TangraConfig.Settings.Astrometry.UseMPCCode         = true;
                TangraConfig.Settings.Astrometry.MPCObservatoryCode = tbxMPCCode.Text;
            }
            else
            {
                TangraConfig.Settings.Astrometry.UseMPCCode = false;
                if (!string.IsNullOrEmpty(tbxLongitude.Text))
                {
                    int sign = cbxLongitude.SelectedIndex == 1 ? -1 : 1;
                    TangraConfig.Settings.Generic.Longitude = sign * AstroConvert.ToDeclination(tbxLongitude.Text);
                }

                if (!string.IsNullOrEmpty(tbxLatitude.Text))
                {
                    int sign = cbxLatitude.SelectedIndex == 1 ? -1 : 1;
                    TangraConfig.Settings.Generic.Latitude = sign * AstroConvert.ToDeclination(tbxLatitude.Text);
                }
            }
        }
예제 #6
0
        private void BuildCalSpecDb()
        {
            var db       = new CalSpecDatabase();
            int totalBad = 0;

            string[] lines2 = File.ReadAllLines(@"F:\WORK\tangra3\Tangra 3\VideoOperations\Spectroscopy\AbsFluxCalibration\Standards\AbsFlux-TangraStars.csv");
            for (int i = 1; i < lines2.Length; i++)
            {
                string[] tokens = lines2[i].Split(',');

                string calSpecId    = tokens[0].Trim();
                string RA_FK5_Hours = tokens[1].Trim();
                string DEG_FK5_Deg  = tokens[2].Trim();
                string pmRA         = tokens[3].Trim();
                string pmDec        = tokens[4].Trim();
                string specType     = tokens[5].Trim();
                string magV         = tokens[6].Trim();
                string magBV        = tokens[7].Trim();
                string absFluxId    = tokens[8].Trim();
                string stisFlag     = tokens[9].Trim();
                string fitsFilePath = tokens[10].Trim();
                int    stisFrom     = int.Parse(tokens[11].Trim());
                int    stisTo       = int.Parse(tokens[12].Trim());
                string tyc2         = tokens[13].Trim();
                string ucac4        = tokens[14].Trim();

                if (!string.IsNullOrEmpty(pmRA) && !string.IsNullOrEmpty(pmDec))
                {
                    var star = new CalSpecStar()
                    {
                        CalSpecStarId  = calSpecId,
                        AbsFluxStarId  = absFluxId,
                        STIS_Flag      = stisFlag,
                        FITS_File      = fitsFilePath,
                        TYC2           = tyc2,
                        U4             = ucac4,
                        pmRA           = double.Parse(pmRA),
                        pmDE           = double.Parse(pmDec),
                        MagV           = double.Parse(magV),
                        MagBV          = double.Parse(magBV),
                        SpecType       = specType,
                        RA_J2000_Hours = AstroConvert.ToRightAcsension(RA_FK5_Hours),
                        DE_J2000_Deg   = AstroConvert.ToDeclination(DEG_FK5_Deg)
                    };

                    string filePath = Path.GetFullPath(@"Z:\CALSPEC\current_calspec\" + fitsFilePath);

                    using (var bf = new BufferedFile(filePath, FileAccess.Read, FileShare.ReadWrite))
                    {
                        var fitsFile = new Fits();
                        fitsFile.Read(bf);

                        BasicHDU imageHDU = fitsFile.GetHDU(1);

                        var      table         = (ColumnTable)imageHDU.Data.DataArray;
                        double[] wavelengths   = (double[])table.Columns[0];
                        float[]  fluxes        = (float[])table.Columns[1];
                        short[]  goodnessFlags = (short[])table.Columns[5];

                        for (int j = 0; j < fluxes.Length; j++)
                        {
                            if (wavelengths[j] < stisFrom)
                            {
                                continue;
                            }
                            if (wavelengths[j] > stisTo)
                            {
                                break;
                            }

                            if (goodnessFlags[j] != 0)
                            {
                                star.DataPoints.Add(wavelengths[j], fluxes[j]);
                            }
                            else
                            {
                                totalBad++;
                            }
                        }
                        fitsFile.Close();
                    }

                    db.Stars.Add(star);
                }
            }

            using (var compressedStream = new FileStream(@"F:\WORK\tangra3\Tangra 3\VideoOperations\Spectroscopy\AbsFluxCalibration\Standards\CalSpec.db", FileMode.CreateNew, FileAccess.Write))
                using (var deflateStream = new DeflateStream(compressedStream, CompressionMode.Compress, true))
                {
                    using (var writer = new BinaryWriter(deflateStream))
                    {
                        db.Serialize(writer);
                    }
                }

            using (var compressedStream = new FileStream(@"F:\WORK\tangra3\Tangra 3\VideoOperations\Spectroscopy\AbsFluxCalibration\Standards\CalSpec.db", FileMode.Open, FileAccess.Read))
                using (var deflateStream = new DeflateStream(compressedStream, CompressionMode.Decompress, true))
                {
                    using (var reader = new BinaryReader(deflateStream))
                    {
                        var db2 = new CalSpecDatabase(reader);
                        Trace.WriteLine(db2.Stars.Count);
                    }
                }

            MessageBox.Show(totalBad.ToString() + " bad entries excluded.");

            string[] fitsFiles = Directory.GetFiles(@"Z:\CALSPEC\current_calspec", "*.fit");

            var dist = new Dictionary <int, int>();

            foreach (string filePath in fitsFiles)
            {
                using (var bf = new BufferedFile(filePath, FileAccess.Read, FileShare.ReadWrite))
                {
                    var fitsFile = new Fits();
                    fitsFile.Read(bf);

                    var bld = new StringBuilder();

                    BasicHDU headerHDU = fitsFile.GetHDU(0);
                    BasicHDU imageHDU  = fitsFile.GetHDU(1);

                    for (int i = 0; i < headerHDU.Header.NumberOfCards; i++)
                    {
                        string cardString = headerHDU.Header.GetCard(i);
                        bld.AppendFormat("# {0}\r\n", cardString);
                    }

                    for (int i = 0; i < imageHDU.Header.NumberOfCards; i++)
                    {
                        string cardString = imageHDU.Header.GetCard(i);
                        bld.AppendFormat("# {0}\r\n", cardString);
                    }

                    var table = (ColumnTable)imageHDU.Data.DataArray;
                    if (table.Columns.Length == 7 &&
                        table.Columns[0] is double[] && table.Columns[1] is float[] && table.Columns[2] is float[] && table.Columns[3] is float[] &&
                        table.Columns[4] is float[] && table.Columns[5] is short[] && table.Columns[6] is float[])
                    {
                        double[] wavelengths   = (double[])table.Columns[0];
                        float[]  fluxes        = (float[])table.Columns[1];
                        float[]  col2          = (float[])table.Columns[2];
                        float[]  col3          = (float[])table.Columns[3];
                        float[]  col4          = (float[])table.Columns[4];
                        short[]  goodnessFlags = (short[])table.Columns[5];
                        float[]  exposures     = (float[])table.Columns[6];

                        for (int i = 0; i < fluxes.Length; i++)
                        {
                            if (wavelengths[i] < 2000)
                            {
                                continue;
                            }
                            if (wavelengths[i] > 15000)
                            {
                                break;
                            }

                            bld.Append(wavelengths[i].ToString().PadLeft(20));
                            bld.Append(fluxes[i].ToString().PadLeft(20));
                            bld.Append(col2[i].ToString().PadLeft(20));
                            bld.Append(col3[i].ToString().PadLeft(20));
                            bld.Append(col4[i].ToString().PadLeft(20));
                            bld.Append(goodnessFlags[i].ToString().PadLeft(15));
                            bld.Append(exposures[i].ToString().PadLeft(15));
                            bld.AppendLine();

                            int expMS = (int)Math.Round(exposures[i] * 1000);
                            if (!dist.ContainsKey(expMS))
                            {
                                dist.Add(expMS, 0);
                            }
                            dist[expMS]++;
                        }
                    }

                    string outFileName = Path.ChangeExtension(filePath, ".txt");
                    File.WriteAllText(outFileName, bld.ToString());
                    fitsFile.Close();
                }
            }

            var output = new StringBuilder();

            foreach (int key in dist.Keys)
            {
                output.AppendFormat("{0}s = {1}\r\n", (key / 1000.0).ToString("0.0"), dist[key]);
            }
            MessageBox.Show(output.ToString());
        }
예제 #7
0
        private bool ValidateHeader()
        {
            m_RA  = double.NaN;
            m_DEC = double.NaN;

            if (!string.IsNullOrEmpty(tbxRA.Text))
            {
                try
                {
                    m_RA = AstroConvert.ToRightAcsension(tbxRA.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show(this, "Please enter a valid Right Ascension value.\r\n\r\nAccepted formats: HH:MM:SS.S; HH:MM:SS; HH:MM.M; HH.H; HH MM SS.S; HH MM SS; HH MM.M; HH.H", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbxRA.SelectAll();
                    tbxRA.Focus();
                    return(false);
                }
            }

            if (!string.IsNullOrEmpty(tbxDE.Text))
            {
                try
                {
                    m_DEC = AstroConvert.ToDeclination(tbxDE.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show(this, "Please enter a valid Declination value.\r\n\r\nAccepted formats: +DD:MM:SS.S; +DD:MM:SS; +DD:MM.M; +DD.D; +DD MM SS.S; DD MM SS; DD MM.M; DD.D", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbxDE.SelectAll();
                    tbxDE.Focus();
                    return(false);
                }
            }

            bool hasRA = !double.IsNaN(m_RA);
            bool hasDE = !double.IsNaN(m_DEC);

            if (hasRA ^ hasDE)
            {
                MessageBox.Show(this, "Please enter both the Right Ascension and Declination", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (double.IsNaN(m_RA))
                {
                    tbxRA.SelectAll();
                    tbxRA.Focus();
                }
                else if (double.IsNaN(m_DEC))
                {
                    tbxDE.SelectAll();
                    tbxDE.Focus();
                }
                return(false);
            }

            if (cbxDateTime.Checked)
            {
                DateTime dt = dtpDate.Value.Date.Add(new TimeSpan(dtpTime.Value.Hour, dtpTime.Value.Minute, dtpTime.Value.Second));
                m_ExposureTime = dt.ToString("yyyy-MM-ddTHH:mm:ss");
            }

            return(true);
        }
예제 #8
0
        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();
        }
예제 #9
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            double raHours, deDeg, /*errDeg,*/ foclen, limmag;

            try
            {
                raHours = AstroConvert.ToRightAcsension(cbxRA.Text);
            }
            catch
            {
                MessageBox.Show(this, "Enter a valid RA value", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cbxRA.Focus();
                cbxRA.Select();
                return;
            }

            try
            {
                deDeg = AstroConvert.ToDeclination(cbxDE.Text);
            }
            catch
            {
                MessageBox.Show(this, "Enter a valid DE value", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                cbxDE.Focus();
                cbxDE.Select();
                return;
            }

            try
            {
                foclen = double.Parse(tbxFocalLength.Text);
                if (foclen < 30)
                {
                    MessageBox.Show(this, "The current minimum supported focal length is 30mm", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbxFocalLength.Focus();
                    tbxFocalLength.Select();
                    return;
                }
                if (foclen > 100000)
                {
                    MessageBox.Show(this, "The current maximum supported focal length is 100m", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbxFocalLength.Focus();
                    tbxFocalLength.Select();
                    return;
                }
            }
            catch
            {
                MessageBox.Show(this, "Enter a valid positive floating point value", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxFocalLength.Focus();
                tbxFocalLength.Select();
                return;
            }

            try
            {
                limmag = double.Parse(tbxLimitMag.Text);
                if (limmag < 5 || limmag > 20)
                {
                    throw new FormatException();
                }
            }
            catch
            {
                MessageBox.Show(this, "Enter a valid magnitude int the range ot 5 to 20", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxLimitMag.Focus();
                tbxLimitMag.Select();
                return;
            }


            AstroPlate image = m_AstrometryController.GetCurrentAstroPlate();

            image.EffectiveFocalLength = foclen;

            Context = new FieldSolveContext();

            Context.RADeg          = raHours * 15;
            Context.DEDeg          = deDeg;
            Context.FocalLength    = foclen;
            Context.LimitMagn      = limmag;
            Context.Epoch          = dtpEpoch.Value.Year + (dtpEpoch.Value.Month / 12.0);
            Context.ErrFoVs        = 2.5;
            Context.DataBaseServer = null;
            Context.DataBaseName   = null;
            Context.Method         = RecognitionMethod.KnownCenter;

            cbxRA.Persist();
            cbxDE.Persist();

            TangraConfig.Settings.LastUsed.FocalLength      = foclen;
            TangraConfig.Settings.LastUsed.AstrRAHours      = cbxRA.Text;
            TangraConfig.Settings.LastUsed.AstrDEDeg        = cbxDE.Text;
            TangraConfig.Settings.LastUsed.ObservationEpoch = dtpEpoch.Value;
            TangraConfig.Settings.Save();

            DialogResult = DialogResult.OK;
            Close();
        }
예제 #10
0
        private bool CheckInputAndLoadStars()
        {
            if (!TangraContext.Current.HasImageLoaded)
            {
                MessageBox.Show(this, "There is no loaded frame/image", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }

            m_RAHours = double.NaN;
            m_DEDeg   = double.NaN;

            Context.ObsCode = tbxObsCode.Text;

            if (rbKnownCenter.Checked)
            {
                try
                {
                    m_RAHours = AstroConvert.ToRightAcsension(cbxRA.Text);
                }
                catch
                {
                    MessageBox.Show(this, "Enter a valid RA value", "Validation Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    cbxRA.Focus();
                    cbxRA.Select();
                    return(false);
                }

                try
                {
                    m_DEDeg = AstroConvert.ToDeclination(cbxDE.Text);
                }
                catch
                {
                    MessageBox.Show(this, "Enter a valid DE value", "Validation Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    cbxDE.Focus();
                    cbxDE.Select();
                    return(false);
                }

                cbxRA.Persist();
                cbxDE.Persist();
            }
            else if (rbKnownObject.Checked)
            {
                // Connect to MPC to find the object coordinates
                MPEph2.MPEphEntry position = null;
                Cursor  = Cursors.WaitCursor;
                Enabled = false;
                try
                {
                    if (!TangraConfig.Settings.HasSiteCoordinatesOrCOD && string.IsNullOrEmpty(tbxObsCode.Text))
                    {
                        m_VideoController.ShowTangraSettingsDialog(false, true);

                        if (!TangraConfig.Settings.HasSiteCoordinatesOrCOD)
                        {
                            return(false);
                        }
                    }


                    Refresh();

                    frmIdentifyObjects frm;

                    if (TangraConfig.Settings.Astrometry.UseMPCCode || !string.IsNullOrEmpty(tbxObsCode.Text))
                    {
                        Context.ObsCode = tbxObsCode.Text;
                        frm             = new frmIdentifyObjects(cbxObject.Text, Context.UtcTime, Context.ObsCode);
                    }
                    else
                    {
                        frm = new frmIdentifyObjects(
                            cbxObject.Text, Context.UtcTime,
                            TangraConfig.Settings.Generic.Longitude,
                            TangraConfig.Settings.Generic.Latitude);
                    }


                    if (m_VideoController.ShowDialog(frm) == DialogResult.OK)
                    {
                        position = frm.Position;
                    }
                }
                finally
                {
                    Enabled = true;
                    Cursor  = Cursors.Default;
                }

                if (position == null)
                {
                    MessageBox.Show(
                        this,
                        string.Format(string.Format("Could not retrieve the position of '{0}' from MPC. Is your internet connection active? Is the designation correct?", cbxObject.Text)),
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    cbxObject.Focus();
                    cbxObject.Select();
                    return(false);
                }
                else
                {
                    m_RAHours = position.RAHours;
                    m_DEDeg   = position.DEDeg;

                    cbxObject.Persist();

                    Context.FoundObject = position;
                }
            }

            Context.RADeg   = m_RAHours * 15;
            Context.DEDeg   = m_DEDeg;
            Context.ErrFoVs = (double)nudError.Value;

            Context.Method = RecognitionMethod.KnownCenter;

            Context.LimitMagn = (double)nudFaintestMag.Value;

            float epoch = Context.UtcTime.Year + Context.UtcTime.DayOfYear / 365.25f;


            if (TangraConfig.Settings.TraceLevels.PlateSolving.TraceInfo())
            {
                Trace.WriteLine(string.Format("Loading stars in region ({0}, {1})",
                                              AstroConvert.ToStringValue(Context.RADeg / 15, "REC"),
                                              AstroConvert.ToStringValue(Context.DEDeg, "DEC")));
            }

            var facade = new StarCatalogueFacade(TangraConfig.Settings.StarCatalogue);

            m_CatalogueStars = facade.GetStarsInRegion(
                Context.RADeg,
                Context.DEDeg,
                (Context.ErrFoVs + 1.0) * m_Image.GetMaxFOVInArcSec() / 3600.0,
                Context.LimitMagn,
                epoch);

            Context.CatalogueStars      = m_CatalogueStars;
            Context.StarCatalogueFacade = facade;

            Context.DetermineAutoLimitMagnitude = rbAutomaticLimitMagnitude.Checked;
            Context.AutoLimitMagnitude          = double.NaN;

            return(true);
        }
예제 #11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbxLongitude.Text))
            {
                if (cbxLongitude.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select West or East latitude.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cbxLongitude.Focus();
                    return;
                }

                try
                {
                    int sign = cbxLongitude.SelectedIndex == 1 ? -1 : 1;
                    ObservatoryLocation.LongitudeInDeg = sign * AstroConvert.ToDeclination(tbxLongitude.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show(string.Format("'{0}' is not a valid longitude.", tbxLongitude.Text), "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbxLongitude.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please enter longitude.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);

                tbxLongitude.Focus();
                return;
            }

            if (!string.IsNullOrEmpty(tbxLatitude.Text))
            {
                if (cbxLatitude.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select North or South latitude.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cbxLatitude.Focus();
                    return;
                }

                try
                {
                    int sign = cbxLatitude.SelectedIndex == 1 ? -1 : 1;
                    ObservatoryLocation.LatitudeInDeg = sign * AstroConvert.ToDeclination(tbxLatitude.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show(string.Format("'{0}' is not a valid latitude.", tbxLatitude.Text), "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbxLatitude.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please enter latitude.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);

                tbxLongitude.Focus();
                return;
            }

            if (!string.IsNullOrEmpty(tbxAltitude.Text))
            {
                try
                {
                    ObservatoryLocation.AltitudeInMeters = double.Parse(tbxAltitude.Text.Trim());
                }
                catch (FormatException)
                {
                    MessageBox.Show(string.Format("'{0}' is not a valid altitude.", tbxAltitude.Text), "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tbxAltitude.Focus();
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please enter altitude.", "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxAltitude.Focus();
                return;
            }

            ObservatoryLocation.IsValid = true;

            TangraConfig.Settings.LastUsed.RovingLongitude = ObservatoryLocation.LongitudeInDeg;
            TangraConfig.Settings.LastUsed.RovingLatitude  = ObservatoryLocation.LatitudeInDeg;
            TangraConfig.Settings.LastUsed.RovingAltitude  = ObservatoryLocation.AltitudeInMeters;
            TangraConfig.Settings.Save();

            DialogResult = DialogResult.OK;
            Close();
        }