Exemple #1
0
        public void SetPosition(double raHours, double deDeg, DateTime utcTime, bool isVideoNormalPosition, bool highPrecision = false)
        {
            double roundedTime = (utcTime.Hour + utcTime.Minute / 60.0 + (utcTime.Second + (utcTime.Millisecond / 1000.0)) / 3600.0) / 24;
            string format      = "00.000000";

            if (isVideoNormalPosition)
            {
                roundedTime = Math.Truncate(Math.Round(roundedTime * 1000000)) / 1000000;
                format      = "00.000000";
            }
            else
            {
                roundedTime = Math.Truncate(Math.Round(roundedTime * 100000)) / 100000;
                format      = "00.00000";
            }

            m_TimeString_16_32 = (utcTime.ToString("yyyy MM ") + (utcTime.Day + roundedTime).ToString(format, CultureInfo.InvariantCulture)).PadRight(17).Substring(0, 17);

            if (highPrecision)
            {
                m_RAString_33_44 = AstroConvert.ToStringValue(raHours, "HH MM SS.TTT").PadRight(13).Substring(0, 13);
                m_DEString_45_56 = AstroConvert.ToStringValue(deDeg, "+HH MM SS.TT").PadRight(13).Substring(0, 13);
            }
            else
            {
                m_RAString_33_44 = AstroConvert.ToStringValue(raHours, "HH MM SS.TT").PadRight(12).Substring(0, 12);
                m_DEString_45_56 = AstroConvert.ToStringValue(deDeg, "+HH MM SS.T").PadRight(12).Substring(0, 12);
            }

            SetVideoNormalPosition(isVideoNormalPosition);
        }
        public void ShowImageHeader(AstroImage currentImage)
        {
            try
            {
                var hdr = new QHYImageHeader(currentImage);

                lblSeqNo.Text  = hdr.SeqNumber.ToString();
                lblTempNo.Text = hdr.TempNumber.ToString();

                lblGpsState.Text = hdr.GPSStatus.ToString();
                lblMaxClock.Text = hdr.MaxClock.ToString();
                try
                {
                    lblStartTime.Text = hdr.StartTime.ToString("yyyy-MM-dd  HH:mm:ss.fffffff");
                    lblEndTime.Text   = hdr.EndTime.ToString("yyyy-MM-dd  HH:mm:ss.fffffff");
                }
                catch { }

                lblStartFlag.Text = "0x" + Convert.ToString(hdr.StartFlag, 16).PadLeft(2, '0');
                lblEndFlag.Text   = "0x" + Convert.ToString(hdr.EndFlag, 16).PadLeft(2, '0');
                lblNowFlag.Text   = "0x" + Convert.ToString(hdr.NowFlag, 16).PadLeft(2, '0');

                lblLongitude.Text = AstroConvert.ToStringValue(hdr.ParseLongitude, "+DD°MM'SS.TT\"");
                lblLatitude.Text  = AstroConvert.ToStringValue(hdr.ParseLatitude, "+DD°MM'SS.TT\"");
                lblImageSize.Text = string.Format("{0} x {1}", hdr.Width, hdr.Height);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex);
            }
        }
Exemple #3
0
        public static List <MPCheckEntry> CheckRegion(
            DateTime utcDate, double raDeg, double deDeg, double radiusArcMin, double magLimit, string observatoryCode)
        {
            Trace.WriteLine(String.Format("Checking potential objects around RA:{0:0.0000}, DEC:{1:0.0000} at {2} UTC for observatory code {3})", raDeg / 15, deDeg, utcDate.ToString("yyyy-MMM-dd HH:mm:ss"), observatoryCode));

            double dayPart = utcDate.Day + (utcDate.Hour + utcDate.Minute / 60.0 + (utcDate.Second + (utcDate.Millisecond / 1000.0)) / 3600.0) / 24.0;

            string requestUrl =
                string.Format(
                    TangraConfig.Settings.Urls.MPCheckHttpsServiceUrl + "?year={0}&month={1}&day={2}&which=pos&ra={3}&decl={4}&TextArea=&radius={5}&limit={6}&oc={7}&sort=d&mot=h&tmot=s&pdes=u&needed=f&ps=n&type=p",
                    utcDate.Year, utcDate.Month, dayPart.ToString("0.000"),
                    AstroConvert.ToStringValue(raDeg / 15.0, "HH MM SS"),
                    AstroConvert.ToStringValue(deDeg, "+DD MM SS"),
                    radiusArcMin.ToString("0"),
                    magLimit.ToString("0.0"),
                    observatoryCode);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUrl);

                Version ver = Assembly.GetExecutingAssembly().GetName().Version;
                req.UserAgent = "Tangra, ver " + ver.ToString();

                HttpWebResponse response       = (HttpWebResponse)req.GetResponse();
                Stream          responseStream = response.GetResponseStream();
                string          responseString = null;
                using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
                {
                    responseString = reader.ReadToEnd();
                }

                int startIdx = responseString.IndexOf("<pre>");
                int endIdx   = responseString.IndexOf("</pre>");

                if (startIdx > -1)
                {
                    List <MPCheckEntry> parsedData = ParseMPCheckResponse(responseString.Substring(startIdx + 5, endIdx - startIdx - 5));

                    return(parsedData);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }

            return(new List <MPCheckEntry>());
        }
        public frmRovingObsLocation()
        {
            InitializeComponent();

            if (TangraConfig.Settings.LastUsed.RovingLongitude == null)
            {
                cbxLongitude.SelectedIndex = -1;
                tbxLongitude.Text          = string.Empty;
            }
            else
            {
                double longNoSign = Math.Abs(TangraConfig.Settings.LastUsed.RovingLongitude.Value);
                tbxLongitude.Text = AstroConvert.ToStringValue(longNoSign, "DD MM SS");
                if (TangraConfig.Settings.LastUsed.RovingLongitude.Value < 0)
                {
                    cbxLongitude.SelectedIndex = 1;
                }
                else
                {
                    cbxLongitude.SelectedIndex = 0;
                }
            }

            if (TangraConfig.Settings.LastUsed.RovingLatitude == null)
            {
                cbxLatitude.SelectedIndex = -1;
                tbxLatitude.Text          = string.Empty;
            }
            else
            {
                double latNoSign = Math.Abs(TangraConfig.Settings.LastUsed.RovingLatitude.Value);
                tbxLatitude.Text = AstroConvert.ToStringValue(latNoSign, "DD MM SS");
                if (TangraConfig.Settings.LastUsed.RovingLatitude.Value < 0)
                {
                    cbxLatitude.SelectedIndex = 1;
                }
                else
                {
                    cbxLatitude.SelectedIndex = 0;
                }
            }

            if (TangraConfig.Settings.LastUsed.RovingAltitude != null)
            {
                tbxAltitude.Text = string.Format("{0:0}", TangraConfig.Settings.LastUsed.RovingAltitude.Value);
            }
            else
            {
                tbxAltitude.Text = string.Empty;
            }
        }
Exemple #5
0
        private void SaveHeader()
        {
            Header.AddValue("HISTORY", "Fits header populated by Tangra v0.1", string.Empty);

            if (!string.IsNullOrEmpty(tbxObject.Text))
            {
                Header.AddValue("OBJECT", tbxObject.Text, null);
            }

            if (!string.IsNullOrEmpty(tbxScope.Text))
            {
                Header.AddValue("TELESCO", tbxScope.Text, null);
            }

            if (!string.IsNullOrEmpty(tbxCamera.Text))
            {
                Header.AddValue("INSTRUME", tbxCamera.Text, null);
            }

            if (!string.IsNullOrEmpty(tbxObserver.Text))
            {
                Header.AddValue("OBSERVER", tbxObserver.Text, null);
            }

            if (!string.IsNullOrEmpty(tbxNotes.Text))
            {
                Header.AddValue("NOTES", tbxNotes.Text, null);
            }

            if (!string.IsNullOrEmpty(tbxRA.Text))
            {
                Header.AddValue("OBJCTRA", AstroConvert.ToStringValue(m_RA, "HH MM SS.TT"), string.Empty);
                Header.AddValue("RA", AstroConvert.ToStringValue(m_RA, "HH MM SS.TT"), string.Empty);
            }

            if (!string.IsNullOrEmpty(tbxDE.Text))
            {
                Header.AddValue("OBJCTDEC", AstroConvert.ToStringValue(m_DEC, "DD MM SS.T"), string.Empty);
                Header.AddValue("DEC", AstroConvert.ToStringValue(m_DEC, "DD MM SS.T"), string.Empty);
            }

            if (cbxDateTime.Checked)
            {
                Header.AddValue("DATE-OBS", m_ExposureTime, string.Empty);
                Header.AddValue("TIMESYS", "UTC", "Default time system");
            }

            Header.AddValue("CLRBAND", "R", string.Empty);
        }
Exemple #6
0
        public override void LoadSettings()
        {
            m_CatalogValidator = new StarCatalogueFacade(TangraConfig.Settings.StarCatalogue);

            if (double.IsNaN(TangraConfig.Settings.Generic.Longitude))
            {
                cbxLongitude.SelectedIndex = -1;
                tbxLongitude.Text          = string.Empty;
            }
            else
            {
                double longNoSign = Math.Abs(TangraConfig.Settings.Generic.Longitude);
                tbxLongitude.Text = AstroConvert.ToStringValue(longNoSign, "DD MM SS");
                if (TangraConfig.Settings.Generic.Longitude < 0)
                {
                    cbxLongitude.SelectedIndex = 1;
                }
                else
                {
                    cbxLongitude.SelectedIndex = 0;
                }
            }

            rbMPCCode.Checked = TangraConfig.Settings.Astrometry.UseMPCCode;
            tbxMPCCode.Text   = TangraConfig.Settings.Astrometry.MPCObservatoryCode;

            if (double.IsNaN(TangraConfig.Settings.Generic.Latitude))
            {
                cbxLatitude.SelectedIndex = -1;
                tbxLatitude.Text          = string.Empty;
            }
            else
            {
                double latNoSign = Math.Abs(TangraConfig.Settings.Generic.Latitude);
                tbxLatitude.Text = AstroConvert.ToStringValue(latNoSign, "DD MM SS");
                if (TangraConfig.Settings.Generic.Latitude < 0)
                {
                    cbxLatitude.SelectedIndex = 1;
                }
                else
                {
                    cbxLatitude.SelectedIndex = 0;
                }
            }
        }
        internal void SelectStar(PlateConstStarPair selectedPair, PSFFit psfFit)
        {
            if (selectedPair != null)
            {
                lblStarNo.Text = selectedPair.StarNo.ToString();
                lblRA.Text     = AstroConvert.ToStringValue(selectedPair.RADeg / 15.0, "HH MM SS.TT");
                lblDE.Text     = AstroConvert.ToStringValue(selectedPair.DEDeg, "+DD MM SS.T");
                lblX.Text      = selectedPair.x.ToString("0.00");
                lblY.Text      = selectedPair.y.ToString("0.00");
                lblResRA.Text  = string.Format("{0}\"", selectedPair.FitInfo.ResidualRAArcSec.ToString("0.00"));
                lblResDE.Text  = string.Format("{0}\"", selectedPair.FitInfo.ResidualDEArcSec.ToString("0.00"));

                m_SelectedPSF = psfFit;
            }
            else
            {
                m_SelectedPSF = null;
            }

            pnlSelectedStar.Visible = selectedPair != null;
        }
        public frmConfigureCsvExport()
        {
            InitializeComponent();

            TrackedObjects = new List <TrackedObjectConfig>();

            pb1.Image = new Bitmap(pb1.Width, pb1.Height, PixelFormat.Format24bppRgb);
            pb2.Image = new Bitmap(pb2.Width, pb1.Height, PixelFormat.Format24bppRgb);
            pb3.Image = new Bitmap(pb3.Width, pb1.Height, PixelFormat.Format24bppRgb);
            pb4.Image = new Bitmap(pb4.Width, pb1.Height, PixelFormat.Format24bppRgb);

            try
            {
                CoordsAndLocation savedSettings = Properties.Settings.Default.AtmExtRememberedConfig.Deserialize <CoordsAndLocation>();
                tbxRA.Text        = AstroConvert.ToStringValue(savedSettings.RAHours, "HH MM SS");
                tbxDec.Text       = AstroConvert.ToStringValue(savedSettings.DEDeg, "+DD MM SS");
                tbxLatitude.Text  = AstroConvert.ToStringValue(savedSettings.LatitudeDeg, "+DD MM SS");
                tbxLongitude.Text = AstroConvert.ToStringValue(savedSettings.LongitudeDeg, "DDD MM SS");
                tbxHeightKm.Text  = savedSettings.HeightKM.ToString("0.000");
            }
            catch { }
        }
Exemple #9
0
        public override void MouseMove(Point location)
        {
            if (m_State == FittingsState.Activated)
            {
                base.MouseMove(location);
            }
            else if (m_State == FittingsState.Solved && m_SolvedPlate != null)
            {
                double ra, de;
                m_SolvedPlate.GetRADEFromImageCoords(location.X, location.Y, out ra, out de);

                string info = string.Format("RA={0} DE={1}", AstroConvert.ToStringValue(ra / 15, "HHhMMmSS.Ts"), AstroConvert.ToStringValue(de, "+DD°MM'SS\""));
                m_VideoController.DisplayCursorPositionDetails(location, info);
            }
            else
            {
                if (m_State == FittingsState.Configuring)
                {
                    m_OSDExcluderTool.MouseMove(location);
                }

                m_VideoController.DisplayCursorPositionDetails(location, null);
            }
        }
Exemple #10
0
        public override void MouseMove(Point location)
        {
            IStarMap map = AstrometryContext.Current.StarMap;

            if (map == null)
            {
                return;
            }

            bool nearbyStarFound = false;

            AstrometricState state = AstrometryContext.Current.AstrometricState;

            if (state != null)
            {
                if (state.AstrometricFit != null)
                {
                    for (int radius = 1; radius < 8; radius++)
                    {
                        ImagePixel centroid = map.GetCentroid(location.X, location.Y, radius);
                        if (centroid == null)
                        {
                            continue;
                        }


                        foreach (PlateConstStarPair star in state.AstrometricFit.FitInfo.AllStarPairs)
                        {
                            if (Math.Abs(star.x - centroid.XDouble) < radius &&
                                Math.Abs(star.y - centroid.YDouble) < radius)
                            {
                                m_Object = star;

                                nearbyStarFound = true;
                                break;
                            }
                        }

                        if (nearbyStarFound)
                        {
                            break;
                        }
                    }

                    if (!nearbyStarFound)
                    {
                        m_State = SelectObjectState.NoObject;
                    }
                    else
                    {
                        m_State = SelectObjectState.ObjectLocked;
                    }


                    if (m_AstrometricState.MeasuringState == AstrometryInFramesState.Ready)
                    {
                        double ra, de;
                        state.AstrometricFit.GetRADEFromImageCoords(location.X, location.Y, out ra, out de);

                        string moreInfo = string.Format("RA={0} DE={1}", AstroConvert.ToStringValue(ra / 15, "HHhMMmSS.Ts"), AstroConvert.ToStringValue(de, "+DD°MM'SS\""));
                        m_VideoController.DisplayCursorPositionDetails(location, moreInfo);
                    }
                }
                else
                {
                    StarMapFeature nearbyFeature = map.GetFeatureInRadius(location.X, location.Y, 8);
                    nearbyStarFound = nearbyFeature != null && nearbyFeature.PixelCount > 4;
                }

                m_VideoController.SetPictureBoxCursor(nearbyStarFound ? Cursors.Hand : (state.ManualStarIdentificationMode ? Cursors.Cross : Cursors.Default));
            }
        }
Exemple #11
0
        private void btnGenerateVideo_Click(object sender, EventArgs e)
        {
            if (!ValidateParameters())
            {
                return;
            }

            if (cbxVideoFormat.SelectedIndex == 0)
            {
                saveFileDialog.Filter     = "AAV Files (*.aav)|*.aav";
                saveFileDialog.DefaultExt = "aav";
            }
            else if (cbxVideoFormat.SelectedIndex == 1)
            {
                saveFileDialog.Filter     = "AVI Files (*.avi)|*.avi";
                saveFileDialog.DefaultExt = "avi";
            }

            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                UsageStats.Instance.ModelVideosGenerated++;
                UsageStats.Instance.Save();

                var config = new ModelConfig()
                {
                    FileName                   = saveFileDialog.FileName,
                    IsAAVFile                  = cbxVideoFormat.SelectedIndex == 0,
                    Integration                = (int)Math.Pow(2, cbxAAVIntegration.SelectedIndex),
                    TotalFrames                = (int)nudTotalFrames.Value,
                    FrameWidth                 = (int)nudFrameWidth.Value,
                    FrameHeight                = (int)nudFrameHeight.Value,
                    NoiseMean                  = (int)nudNoiseMean.Value,
                    NoiseStdDev                = (int)nudNoiseStdDev.Value,
                    FlickeringStdDev           = (int)nudStarFlickering.Value,
                    FWHM                       = (double)nudStar1FWHM.Value,
                    BrighestUnsaturatedStarMag = (double)nudFirstSaturatedMag.Value,
                    LimitStarMag               = (double)nudLimitMag.Value,
                    RADeg2000                  = m_RA * 15,
                    DEDeg2000                  = m_DE,
                    PlatePixWidth              = (double)nudPlatePixWidth.Value,
                    PlatePixHeight             = (double)nudPlatePixHeight.Value,
                    PlateFocLength             = (double)nudPlateFocLength.Value,
                    PhotometricFilter          = (ModelledFilter)cbxPhotometricFilter.SelectedIndex,
                    BVSlope                    = (double)nudBVSlope.Value,
                    LinearityCoefficient       = (double)nudNonLinearity.Value,
                    DarkFrameMean              = cbxProduceDark.Checked ? (int)nudDarkMean.Value : 0,
                    CheckMagnitudes            = cbxCheckMagnitudes.Checked,
                    PSFMagnitudeModelling      = cbxPSFStarModelling.Checked
                };

                config.PlateRotAngleRadians = (double)nudPlateRotation.Value * Math.PI / 180.0;
                config.MatrixToImageScaleX  = config.FrameWidth / (double)nudMatrixWidth.Value;
                config.MatrixToImageScaleY  = config.FrameHeight / (double)nudMatrixHeight.Value;

                config.InfoLine1 = string.Format("Model Video Generated by Tangra v.{0}", ((AssemblyFileVersionAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true)[0]).Version);
                config.InfoLine2 = string.Format("Noise: {0} +/- {1}, Flickering: {2}, FWHM: {3}", config.NoiseMean, config.NoiseStdDev, config.FlickeringStdDev, config.FWHM.ToString("0.0"));
                config.InfoLine3 = String.Format("Field Center: RA={0} DE={1}", AstroConvert.ToStringValue(m_RA, "HHh MMm SSs"), AstroConvert.ToStringValue(m_DE, "+DDo MM' SS\""));
                config.InfoLine4 = "";

                ThreadPool.QueueUserWorkItem(new WaitCallback(GenerateSimulatedVideo), config);
            }
        }
Exemple #12
0
        public ProcessingReturnValues FitAndPlotSlowMotion(
            Dictionary <int, SingleMultiFrameMeasurement> measurements,
            FlybyMeasurementContext meaContext,
            GetProcessingValueCallback getValueCallback,
            Graphics g, FlybyPlottingContext plottingContext, float xScale, float yScale, int imageWidth)
        {
            // Compute median, use median based exclusion rules
            // Report the median position for the time at the middle of the measured interval
            // Do not expect elongated image (no corrections from the exposure)
            // May apply instrumental delay corrections for the frame time

            var rv = new ProcessingReturnValues();

            double sum           = 0;
            double userSum       = 0;
            double stdDevUserSum = 0;
            int    numFramesUser = 0;

            double userMidFrom = meaContext.UserMidValue - meaContext.MaxStdDev;
            double userMidTo   = meaContext.UserMidValue + meaContext.MaxStdDev;

            rv.EarliestFrame = int.MaxValue;
            rv.LatestFrame   = int.MinValue;

            List <double> medianList              = new List <double>();
            List <double> medianWeightsList       = new List <double>();
            var           minPosUncertaintyArcSec = TangraConfig.Settings.Astrometry.AssumedPositionUncertaintyPixels * meaContext.ArsSecsInPixel;

            foreach (SingleMultiFrameMeasurement measurement in measurements.Values)
            {
                float            x         = (measurement.FrameNo - meaContext.MinFrameNo) * xScale + 5;
                ProcessingValues val       = getValueCallback(measurement);
                double           valueFrom = val.Value - val.StdDev;
                double           valueTo   = val.Value + val.StdDev;

                float yFrom = (float)(valueFrom - plottingContext.MinValue) * yScale + 5;
                float yTo   = (float)(valueTo - plottingContext.MinValue) * yScale + 5;

                sum += val.Value;

                Pen mPen = plottingContext.IncludedPen;
                if (!double.IsNaN(meaContext.UserMidValue))
                {
                    if ((valueFrom >= userMidFrom && valueFrom <= userMidTo) ||
                        (valueTo >= userMidFrom && valueTo <= userMidTo))
                    {
                        numFramesUser++;
                        userSum += val.Value;
                        medianList.Add(val.Value);
                        medianWeightsList.Add(ComputePositionWeight(val.StdDev, measurement, minPosUncertaintyArcSec, WeightingMode.SNR));

                        stdDevUserSum += val.StdDev * val.StdDev;
                        if (rv.EarliestFrame > measurement.FrameNo)
                        {
                            rv.EarliestFrame = measurement.FrameNo;
                        }
                        if (rv.LatestFrame < measurement.FrameNo)
                        {
                            rv.LatestFrame = measurement.FrameNo;
                        }
                    }
                    else
                    {
                        mPen = plottingContext.ExcludedPen;
                    }
                }


                g.DrawLine(mPen, x, yFrom, x, yTo);
                g.DrawLine(mPen, x - 1, yFrom, x + 1, yFrom);
                g.DrawLine(mPen, x - 1, yTo, x + 1, yTo);
            }

            if (!double.IsNaN(meaContext.UserMidValue) && numFramesUser > 0)
            {
                double average = userSum / numFramesUser;
                double err     = Math.Sqrt(stdDevUserSum) / (numFramesUser - 1);
                float  yAve    = (float)(average - plottingContext.MinValue) * yScale + 5;
                g.DrawLine(plottingContext.AveragePen, 5, yAve - 1, imageWidth - 5, yAve - 1);
                g.DrawLine(plottingContext.AveragePen, 5, yAve, imageWidth - 5, yAve);
                g.DrawLine(plottingContext.AveragePen, 5, yAve + 1, imageWidth - 5, yAve + 1);

                float yMin = (float)(userMidFrom - plottingContext.MinValue) * yScale + 5;
                float yMax = (float)(userMidTo - plottingContext.MinValue) * yScale + 5;
                g.DrawLine(plottingContext.AveragePen, 5, yMin, imageWidth - 5, yMin);
                g.DrawLine(plottingContext.AveragePen, 5, yMax, imageWidth - 5, yMax);

                double median;
                double medianWeight;

                WeightedMedian(Tuple.Create(medianList, medianWeightsList), out median, out medianWeight);

                double standardMedian = medianList.Median();

                Trace.WriteLine(string.Format("{0}; Included: {1}; Average: {2}; Wighted Median: {3}; Standard Median: {4}",
                                              meaContext.UserMidValue.ToString("0.00000"),
                                              numFramesUser, AstroConvert.ToStringValue(average, "+HH MM SS.TTT"),
                                              AstroConvert.ToStringValue(median, "+HH MM SS.TTT"),
                                              AstroConvert.ToStringValue(standardMedian, "+HH MM SS.TTT")));

                rv.FittedValue = median;

                var stdDevArcSec = 3600 * Math.Sqrt(medianList.Sum(x => (x - median) * (x - median)) / (medianList.Count - 1));
                var tCoeff95     = TDistribution.CalculateCriticalValue(medianList.Count, (1 - 0.95), 0.0001);
                var error95      = 1.253 * tCoeff95 * stdDevArcSec / Math.Sqrt(medianList.Count);
                rv.FittedValueUncertaintyArcSec = error95;
                rv.IsVideoNormalPosition        = false;
            }
            else
            {
                double average = sum / measurements.Count;
                float  yAve    = (float)(average - plottingContext.MinValue) * yScale + 5;
                g.DrawLine(Pens.WhiteSmoke, 5, yAve, imageWidth - 5, yAve);

                rv.FittedValue = double.NaN;
            }

            return(rv);
        }
Exemple #13
0
 private string IAU_Id()
 {
     return(string.Format("PPMXL {0}{1}",
                          AstroConvert.ToStringValue(m_RADeg, "HHMMSS.T"),
                          AstroConvert.ToStringValue(m_DEDeg, "+DDMMSS")));
 }
Exemple #14
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);
        }
        private AstroDigitalVideoStreamV2(string fileName, ref AdvFileMetadataInfo fileMetadataInfo, ref GeoLocationInfo geoLocation)
        {
            //CheckAdvFileFormat(fileName, ref fileMetadataInfo, ref geoLocation);

            m_FileName = fileName;

            m_AdvFile = new AdvFile2(fileName);

            m_FirstFrame  = 0;
            m_CountFrames = m_AdvFile.MainSteamInfo.FrameCount;

            m_BitPix        = m_AdvFile.DataBpp;
            m_Width         = m_AdvFile.Width;
            m_Height        = m_AdvFile.Height;
            m_MaxPixelValue = (uint)m_AdvFile.MaxPixelValue;

            m_FrameRate    = 0;
            m_AAVVersion   = 0;
            m_StackingRate = 0;

            m_Engine = "ADV2";

            fileMetadataInfo.Recorder = GetFileTag("RECORDER-SOFTWARE");
            CameraModel             = fileMetadataInfo.Camera = GetFileTag("CAMERA-MODEL");
            fileMetadataInfo.Engine = GetFileTag("FSTF-TYPE");

            fileMetadataInfo.AdvrVersion = GetFileTag("RECORDER-SOFTWARE-VERSION");
            fileMetadataInfo.SensorInfo  = GetFileTag("CAMERA-SENSOR-INFO");

            fileMetadataInfo.ObjectName = GetFileTag("OBJNAME");

            int aavVersion;

            if (int.TryParse(GetFileTag("AAV-VERSION"), out aavVersion))
            {
                m_AAVVersion    = aavVersion;
                m_VideoStandard = GetFileTag("NATIVE-VIDEO-STANDARD");
                double.TryParse(GetFileTag("NATIVE-FRAME-RATE"), NumberStyles.Float, CultureInfo.InvariantCulture, out m_NativeFrameRate);

                int.TryParse(GetFileTag("OSD-FIRST-LINE"), out m_OsdFirstLine);
                int.TryParse(GetFileTag("OSD-LAST-LINE"), out m_OsdLastLine);

                if (m_OsdLastLine > m_Height)
                {
                    m_OsdLastLine = m_Height;
                }
                if (m_OsdFirstLine < 0)
                {
                    m_OsdFirstLine = 0;
                }

                m_IntegratedAAVFrames = -1;

                if (double.TryParse(GetFileTag("EFFECTIVE-FRAME-RATE"), NumberStyles.Float, CultureInfo.InvariantCulture, out m_EffectiveFrameRate) && m_NativeFrameRate != 0)
                {
                    m_IntegratedAAVFrames = (int)Math.Round(m_NativeFrameRate / m_EffectiveFrameRate);
                    m_FrameRate           = m_EffectiveFrameRate; // This is important for OCR-ing as the frame rate is used to derive the frame exposure
                }

                int.TryParse(GetFileTag("FRAME-STACKING-RATE"), out m_StackingRate);
                if (m_StackingRate == 1)
                {
                    m_StackingRate = 0;                      // Video stacked at x1 is a non-stacked video
                }
                m_Engine = string.Format("AAV{0}", aavVersion);
            }

            this.geoLocation = new GeoLocationInfo();
            double lng;
            double lat;

            if (
                double.TryParse(GetFileTag("LONGITUDE"), NumberStyles.Float, CultureInfo.InvariantCulture, out lng) &&
                double.TryParse(GetFileTag("LATITUDE"), NumberStyles.Float, CultureInfo.InvariantCulture, out lat))
            {
                this.geoLocation.Altitude  = GetFileTag("ALTITUDE");
                this.geoLocation.Longitude = AstroConvert.ToStringValue(lng, "DD°MM'SS.T\"");
                this.geoLocation.Latitude  = AstroConvert.ToStringValue(lat, "DD°MM'SS.T\"");
            }

            geoLocation = this.geoLocation;
        }
Exemple #16
0
        public void TestRAUncertainty()
        {
            var regressionRA      = new LinearRegression();
            var regressionRACosDE = new LinearRegression();
            var regressionDE      = new LinearRegression();

            #region DATA

            var data3 = new double[100, 2]
            {
                { 107.739483057629, 23.1727860863356 },
                { 107.739758423225, 23.1725858289442 },
                { 107.739270316112, 23.1727265176296 },
                { 107.740138616241, 23.1726236358575 },
                { 107.739635635855, 23.1720172219518 },
                { 107.739770516897, 23.1729142307849 },
                { 107.73978035157, 23.1724868171702 },
                { 107.7402464908, 23.1722211800014 },
                { 107.740153319844, 23.17248806658 },
                { 107.739638162317, 23.1721297891023 },
                { 107.740152592624, 23.1724840894266 },
                { 107.73958378293, 23.1723613227751 },
                { 107.740253757515, 23.172044928013 },
                { 107.739869281082, 23.1718262300426 },
                { 107.739789179397, 23.1719229687229 },
                { 107.740109562638, 23.1722060231074 },
                { 107.740283891099, 23.1718843884705 },
                { 107.739908616613, 23.1721244581715 },
                { 107.740456941346, 23.171955354053 },
                { 107.739775905586, 23.1718647897894 },
                { 107.739910899659, 23.1717039889273 },
                { 107.740289075343, 23.1716186337573 },
                { 107.739949394724, 23.171506240555 },
                { 107.739932221015, 23.1716027243754 },
                { 107.740295228809, 23.1716475314679 },
                { 107.740110388037, 23.1713426960706 },
                { 107.740000979798, 23.1716693560547 },
                { 107.740683952325, 23.1709681704731 },
                { 107.740203119785, 23.1714519510736 },
                { 107.740273707513, 23.1713702195282 },
                { 107.740715664145, 23.1708006096487 },
                { 107.740242143812, 23.1714449185373 },
                { 107.740687548443, 23.1714370988362 },
                { 107.740393828828, 23.1711679651411 },
                { 107.740547330181, 23.1707733940985 },
                { 107.740304974691, 23.1709983145174 },
                { 107.74034540204, 23.1710469626238 },
                { 107.740904365499, 23.1712337543625 },
                { 107.740271422439, 23.1707876401664 },
                { 107.740473226403, 23.1707728540074 },
                { 107.740636055235, 23.1704881107108 },
                { 107.740425649522, 23.1706972672815 },
                { 107.741075014634, 23.1711886612524 },
                { 107.740786717375, 23.1703917179741 },
                { 107.740612480474, 23.1707997640991 },
                { 107.740513888292, 23.1702033095878 },
                { 107.740861057518, 23.1707917436653 },
                { 107.740431450664, 23.1704962321596 },
                { 107.740894364108, 23.1706460451468 },
                { 107.740737653969, 23.1699454114361 },
                { 107.741167338868, 23.1704390641158 },
                { 107.7413536072, 23.1702117449598 },
                { 107.741086391515, 23.1708025027409 },
                { 107.740817260861, 23.1707126761071 },
                { 107.741221711022, 23.1703529560508 },
                { 107.740861537438, 23.1703420196572 },
                { 107.74133696574, 23.1699266624604 },
                { 107.741008974082, 23.1698332023904 },
                { 107.741330374957, 23.1699747581779 },
                { 107.740956577025, 23.1699971703065 },
                { 107.741383593614, 23.1700614545797 },
                { 107.741111473117, 23.1693429455465 },
                { 107.741121545844, 23.1698626383014 },
                { 107.740820518692, 23.1696821611261 },
                { 107.740916798005, 23.1696481452449 },
                { 107.741407098196, 23.1697794065368 },
                { 107.741287855641, 23.1694896025056 },
                { 107.741231209856, 23.1697278715938 },
                { 107.741571326879, 23.1696485314836 },
                { 107.741256422563, 23.1692796164232 },
                { 107.741083941569, 23.1692085591873 },
                { 107.742137813992, 23.1692501809322 },
                { 107.741681536193, 23.1691250721346 },
                { 107.741303539868, 23.1692497992003 },
                { 107.741635549928, 23.1696783769589 },
                { 107.741659390834, 23.1692018221502 },
                { 107.741519314827, 23.1689582724524 },
                { 107.741584255568, 23.1690406639767 },
                { 107.741457448448, 23.1689571870363 },
                { 107.741598496613, 23.1690963575179 },
                { 107.741640939783, 23.1689548869089 },
                { 107.741369971733, 23.1688034552239 },
                { 107.741859029521, 23.1688553893107 },
                { 107.741963565581, 23.1683666431612 },
                { 107.741666822527, 23.1688987338326 },
                { 107.741641792823, 23.1689634685279 },
                { 107.742023968239, 23.1690510611327 },
                { 107.741962846523, 23.1688076089897 },
                { 107.741683243803, 23.1683235937605 },
                { 107.742121706882, 23.1689619396987 },
                { 107.741538062532, 23.168283426697 },
                { 107.742422013432, 23.1687801621234 },
                { 107.741896618583, 23.1686362544736 },
                { 107.741972513575, 23.1686551496664 },
                { 107.74206679923, 23.168500337937 },
                { 107.742405073144, 23.1684770104653 },
                { 107.742032294448, 23.1683475533958 },
                { 107.742230287337, 23.1682284222132 },
                { 107.742201384546, 23.1682279605208 },
                { 107.741884032454, 23.1682565185304 }
            };

            var data2 = new double[100, 2]
            {
                { 107.739477771965, 69.1728347555165 },
                { 107.73961196667, 69.1726830767986 },
                { 107.739409817125, 69.1725933008645 },
                { 107.74019077671, 69.172494940147 },
                { 107.740585586026, 69.1726077103564 },
                { 107.74059838218, 69.1722819118463 },
                { 107.740208274081, 69.1723120729806 },
                { 107.740712281929, 69.1720791829606 },
                { 107.74033612626, 69.1723780587458 },
                { 107.741242715081, 69.1721192003436 },
                { 107.741266002392, 69.1722343854433 },
                { 107.741105006249, 69.1721003309252 },
                { 107.741363419742, 69.172088671089 },
                { 107.741690798727, 69.1722568414364 },
                { 107.741666861184, 69.17205417308 },
                { 107.741361837266, 69.1720675384819 },
                { 107.742084712903, 69.1718874998462 },
                { 107.742042010619, 69.1719175816475 },
                { 107.742280817921, 69.1719094396275 },
                { 107.742577304285, 69.1717986068223 },
                { 107.741966244595, 69.1718798130166 },
                { 107.742684141694, 69.1718510228511 },
                { 107.742976630078, 69.17157595174 },
                { 107.743352294911, 69.1715857376448 },
                { 107.743061556848, 69.1714241326127 },
                { 107.743090113926, 69.1714458284253 },
                { 107.743275509384, 69.1715522559223 },
                { 107.743176399757, 69.1714823812197 },
                { 107.743814300524, 69.1713901151672 },
                { 107.743767969983, 69.1714428793583 },
                { 107.743858065548, 69.1713035534992 },
                { 107.743822885639, 69.1712307918348 },
                { 107.744334295083, 69.1713055626603 },
                { 107.744427875787, 69.1712388751409 },
                { 107.744340783728, 69.1710928940912 },
                { 107.744805413896, 69.1710055991679 },
                { 107.74502108349, 69.1709137441353 },
                { 107.744828974649, 69.1709496406011 },
                { 107.74512401154, 69.1708573778863 },
                { 107.745281281021, 69.1708161629737 },
                { 107.745576469803, 69.1710203029433 },
                { 107.745740147716, 69.1707075932863 },
                { 107.745502577032, 69.1708074622807 },
                { 107.745623997879, 69.1706684821245 },
                { 107.746509028511, 69.1708362938784 },
                { 107.74602549245, 69.1706568551002 },
                { 107.745897609677, 69.170596921634 },
                { 107.746469521491, 69.1704027875192 },
                { 107.746277468908, 69.1703449453588 },
                { 107.74672857027, 69.1705498632184 },
                { 107.746946720371, 69.1702725215642 },
                { 107.746884661238, 69.1704713141467 },
                { 107.746860604767, 69.1702156222331 },
                { 107.747294089089, 69.1701998357532 },
                { 107.747620144745, 69.1702161529364 },
                { 107.747858455982, 69.170059426359 },
                { 107.747632580795, 69.1700516486805 },
                { 107.747755094573, 69.1698765265442 },
                { 107.747994751954, 69.1701514424405 },
                { 107.748121399878, 69.1700667592208 },
                { 107.748172662863, 69.1698849007696 },
                { 107.748228803142, 69.1699923304849 },
                { 107.749014214424, 69.1697868133965 },
                { 107.748792915115, 69.1700161340914 },
                { 107.748638559821, 69.1698409328545 },
                { 107.748636809009, 69.1697153039492 },
                { 107.749136438823, 69.1697074633957 },
                { 107.749338377121, 69.1697654496001 },
                { 107.749569612206, 69.1697500026688 },
                { 107.749595422398, 69.169419529115 },
                { 107.750383523525, 69.1696656542994 },
                { 107.75048831811, 69.1692035028989 },
                { 107.750352623105, 69.1693815488115 },
                { 107.750761537512, 69.1692866838914 },
                { 107.750685403332, 69.1693024139098 },
                { 107.750705748086, 69.1692717484141 },
                { 107.750843059166, 69.1692580533525 },
                { 107.750716179597, 69.1691529497331 },
                { 107.75072202975, 69.1691168107163 },
                { 107.75108559747, 69.1691834005496 },
                { 107.751493043153, 69.1691522809292 },
                { 107.751596829163, 69.169012841963 },
                { 107.75131727043, 69.1688012714158 },
                { 107.751666922544, 69.1689359714136 },
                { 107.751578388338, 69.1687399323656 },
                { 107.751905351653, 69.1688376229061 },
                { 107.752250104552, 69.1687619831483 },
                { 107.752678677296, 69.1687244251449 },
                { 107.752525957028, 69.1686536798413 },
                { 107.752373714866, 69.1686287601216 },
                { 107.753019411842, 69.1686380478501 },
                { 107.752741905599, 69.1684961094107 },
                { 107.753018243388, 69.1683971436757 },
                { 107.752942371889, 69.1684595315802 },
                { 107.753259742823, 69.1684806579804 },
                { 107.753511849838, 69.168268224757 },
                { 107.75342673874, 69.1685388792275 },
                { 107.753991832751, 69.1681999371544 },
                { 107.753606583523, 69.1682240722345 },
                { 107.753806764198, 69.1682937040626 },
            };

            var data = new double[100, 2]
            {
                { 107.73935730677, 69.172711754819 },
                { 107.739941719805, 69.1725607327368 },
                { 107.739969545763, 69.1728020832412 },
                { 107.739725613496, 69.1724948444009 },
                { 107.739031353708, 69.1726159366499 },
                { 107.739747958109, 69.1721826902977 },
                { 107.74074663056, 69.1722130865804 },
                { 107.739619292955, 69.1724872676585 },
                { 107.739526386824, 69.1723097829692 },
                { 107.7410771233, 69.1725703918204 },
                { 107.740739660076, 69.1724144742981 },
                { 107.740697636644, 69.1721550394849 },
                { 107.741880544558, 69.1719738870443 },
                { 107.741833247397, 69.1721940884685 },
                { 107.742314186337, 69.17193450189 },
                { 107.740926254247, 69.1721384298611 },
                { 107.741970497859, 69.1721455511604 },
                { 107.742119450987, 69.1721636360282 },
                { 107.742132805385, 69.1719603779096 },
                { 107.742777129314, 69.1714210932301 },
                { 107.743075397391, 69.1714527431053 },
                { 107.743768675633, 69.1715943552255 },
                { 107.742542542626, 69.1716645234002 },
                { 107.743524460336, 69.1716088168889 },
                { 107.743350115709, 69.1717882604853 },
                { 107.743489485345, 69.1721692852173 },
                { 107.74401344733, 69.1717430018303 },
                { 107.743001358569, 69.171745750306 },
                { 107.744101155658, 69.1715995718388 },
                { 107.743357827113, 69.1709192593056 },
                { 107.744693317033, 69.1716866797303 },
                { 107.74508962137, 69.1713006067015 },
                { 107.743997983147, 69.1708910615953 },
                { 107.743996491802, 69.1715212096561 },
                { 107.74373222623, 69.1709626863127 },
                { 107.744993875976, 69.1714069871322 },
                { 107.744573043011, 69.1710885783853 },
                { 107.744610440986, 69.1709524781463 },
                { 107.744515880438, 69.171012647055 },
                { 107.745021853434, 69.1706795177817 },
                { 107.745928469586, 69.1709513201446 },
                { 107.746274328526, 69.1709990525173 },
                { 107.746003621776, 69.1703636654999 },
                { 107.746860479622, 69.1707788370646 },
                { 107.746015994963, 69.170532070676 },
                { 107.745308266138, 69.1703833282827 },
                { 107.747434171025, 69.1707583505672 },
                { 107.746380716695, 69.1707477283657 },
                { 107.746322773734, 69.1705759472448 },
                { 107.747195770778, 69.1704783387962 },
                { 107.746726832268, 69.1705445287354 },
                { 107.746479807916, 69.170295182694 },
                { 107.746858852632, 69.170151842435 },
                { 107.748005552167, 69.1701324143026 },
                { 107.746440725163, 69.1702997117708 },
                { 107.747632752596, 69.1699714950714 },
                { 107.746288060495, 69.170247112624 },
                { 107.748643753256, 69.1698662806951 },
                { 107.74881046717, 69.1699979516342 },
                { 107.747535292112, 69.170078645581 },
                { 107.747766333879, 69.1699744718271 },
                { 107.748809227233, 69.1700193921839 },
                { 107.749697498078, 69.1695793718616 },
                { 107.74893998829, 69.1698713857366 },
                { 107.748878487794, 69.1695228880432 },
                { 107.74904534252, 69.1698472549382 },
                { 107.749463140037, 69.1696628177742 },
                { 107.749830174792, 69.1698519550262 },
                { 107.749699649195, 69.1695956041761 },
                { 107.750502343619, 69.1693099555417 },
                { 107.750326261356, 69.1691415029809 },
                { 107.748673873243, 69.1692620977489 },
                { 107.75106313072, 69.1690631812159 },
                { 107.75052688368, 69.1691938573698 },
                { 107.750543324985, 69.1695068538202 },
                { 107.751031016666, 69.1692150774484 },
                { 107.751096804392, 69.1688797213772 },
                { 107.75042386222, 69.1690032179007 },
                { 107.750153005185, 69.169176739356 },
                { 107.751104742713, 69.1687864249361 },
                { 107.751084417858, 69.1690641095538 },
                { 107.751285471877, 69.1690996992436 },
                { 107.751597211541, 69.169157134543 },
                { 107.751909360988, 69.1690350795147 },
                { 107.752462310445, 69.1684796654783 },
                { 107.751635885797, 69.1688208914861 },
                { 107.752428595531, 69.1685312843568 },
                { 107.753169064017, 69.1685892661358 },
                { 107.752228822227, 69.1685323946141 },
                { 107.753263916127, 69.168469632772 },
                { 107.753442528401, 69.1684911064022 },
                { 107.753490171167, 69.168976339076 },
                { 107.753304279553, 69.1685787342008 },
                { 107.75333647205, 69.1683355355218 },
                { 107.753820078749, 69.1683194672346 },
                { 107.753790511111, 69.1683609672304 },
                { 107.754442898298, 69.1681319406902 },
                { 107.753649542414, 69.1683447688382 },
                { 107.754436235939, 69.1684819745314 },
                { 107.754808387808, 69.1680718218884 },
            };
            #endregion

            double SEC_TO_DAY = 1.0 / (24 * 3600);

            for (int i = 0; i < 100; i++)
            {
                var ra = data[i, 0];
                var de = data[i, 1];

                regressionRA.AddDataPoint(i * SEC_TO_DAY, ra);
                regressionDE.AddDataPoint(i * SEC_TO_DAY, de);

                regressionRACosDE.AddDataPoint(i * SEC_TO_DAY, ra * Math.Cos(de * Math.PI / 180.0));
            }

            regressionRA.Solve();
            regressionDE.Solve();
            regressionRACosDE.Solve();

            double      timeOfDay = 50 * SEC_TO_DAY;
            ErrorMethod errMethod = ErrorMethod.HalfStdDev;

            double errRAArcSec;
            double errDEArcSec;

            var raHours = regressionRA.ComputeYWithError(timeOfDay, out errRAArcSec, errMethod) / 15.0;
            var deDeg   = regressionDE.ComputeYWithError(timeOfDay, out errDEArcSec, errMethod);

            double cosDEFactor = Math.Cos(deDeg * Math.PI / 180);


            double errRACosDEArcSec = errRAArcSec * cosDEFactor * 3600;
            errDEArcSec *= 3600;

            Trace.WriteLine(string.Format("RA = {0} +/- {1:0.00}\" StdDev={4:0.000}; DE={2} +/- {3:0.00}\"",
                                          AstroConvert.ToStringValue(raHours, "HH MM SS.TT"), errRACosDEArcSec, AstroConvert.ToStringValue(deDeg, "+DD MM SS.T"), errDEArcSec, regressionRA.StdDevUnscaled * cosDEFactor * 3600));

            double errRA2;
            var    raHoursCosDE = regressionRACosDE.ComputeYWithError(timeOfDay, out errRA2, errMethod) / 15.0;
            raHours = raHoursCosDE / cosDEFactor;
            errRA2 *= 3600;

            Trace.WriteLine(string.Format("RA = {0} +/- {1:0.00}\" StdDev={4:0.000}; DE={2} +/- {3:0.00}\"",
                                          AstroConvert.ToStringValue(raHours, "HH MM SS.TT"), errRA2, AstroConvert.ToStringValue(deDeg, "+DD MM SS.T"), errDEArcSec, regressionRACosDE.StdDevUnscaled * 3600));

            Assert.IsTrue(regressionRA.StdDevUnscaled * cosDEFactor < regressionRACosDE.StdDevUnscaled);

            // NOTE: StdDev in the RA fit appears to be smaller in RA.CosDE terms when the fitting is done in RA, compared to when it is done in RA.CosDE.
            // Therefore we continue to use the RA fitting, rather than RA.CosDE fitting.
            // TODO: This needs to be looked through and proper mathematical evaluation needs to be done for the uncertainties before the RA.CosDE fitting can be used directly
        }
Exemple #17
0
        private void BuildAbsFlux()
        {
            var indexFile = new StringBuilder();

            indexFile.AppendLine("BD and HD CALSPEC stars with STIS fluxes between 3000 and 10000 Angstroms");
            indexFile.AppendLine("Name            FK5_Coordinates_J2000      Type    Mag    B-V   File_Name");

            foreach (CalSpecStar star in CalSpecDatabase.Instance.Stars)
            {
                if (star.AbsFluxStarId.StartsWith("TYC"))
                {
                    continue;
                }
                string modifiedId = star.AbsFluxStarId.Replace(" ", "_");
                if (modifiedId.Length < 10)
                {
                    modifiedId += "_";
                }
                while (modifiedId.Length < 10)
                {
                    int firstUnderScorePos = modifiedId.IndexOf("_");
                    modifiedId = modifiedId.Substring(0, firstUnderScorePos) + "_" + modifiedId.Substring(firstUnderScorePos);
                }
                string raStr        = AstroConvert.ToStringValue(star.RA_J2000_Hours, "HH MM SS.TTT");
                string deStr        = AstroConvert.ToStringValue(star.DE_J2000_Deg, "+DD MM SS.TT");
                string dataFileName = Path.GetFileNameWithoutExtension(star.FITS_File) + "_t1.txt";
                string line         = string.Format("{0}{1} {2}    {3}{4}  {5}  {6}\r\n",
                                                    modifiedId.PadRight(14), raStr, deStr,
                                                    star.SpecType.PadRight(7),
                                                    star.MagV.ToString("0.00").PadLeft(5),
                                                    star.MagBV.ToString("0.00").PadLeft(5),
                                                    dataFileName);
                indexFile.Append(line);

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

                double wavelengthFrom = star.DataPoints.Keys.Min();
                double wavelengthTo   = star.DataPoints.Keys.Max();
                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];
                    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];

                    var dataFile = new StringBuilder();
                    dataFile.AppendLine("      WAVELENGTH          FLUX     STATERROR      SYSERROR         FWHM     DATAQUAL      TOTEXP");
                    dataFile.AppendLine("              1D            1E            1E            1E           1E           1I          1E");
                    dataFile.AppendLine("       ANGSTROMS          FLAM          FLAM          FLAM    ANGSTROMS         NONE         SEC");

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

                        string dataLine = string.Format("{0}{1}{2}{3}{4}            {5}{6}",
                                                        ((int)Math.Round(wavelengths[j])).ToString().PadLeft(16),
                                                        fluxes[j].ToString("E4").PadLeft(14),
                                                        col2[j].ToString("E4").PadLeft(14),
                                                        col3[j].ToString("E4").PadLeft(14),
                                                        col4[j].ToString("#.0").PadLeft(13),
                                                        goodnessFlags[j].ToString(),
                                                        exposures[j].ToString("E1").PadLeft(12));

                        dataFile.AppendLine(dataLine);
                    }

                    fitsFile.Close();

                    File.WriteAllText(@"Z:\AbsFlux\v3\" + dataFileName, dataFile.ToString());
                }
            }
            File.WriteAllText(@"Z:\AbsFlux\v3\AbsFluxCALSPECstars.txt", indexFile.ToString());
        }
Exemple #18
0
        public ProcessingReturnValues FitAndPlotSlowFlyby(
            Dictionary <int, SingleMultiFrameMeasurement> measurements,
            FlybyMeasurementContext meaContext,
            FittingContext fittingContext,
            FittingValue fittingValue,
            GetFrameStateDataCallback getFrameStateDataCallback,
            Graphics g, FlybyPlottingContext plottingContext, float xScale, float yScale, int imageWidth, int imageHight,
            out double motionRate)
        {
            try
            {
                #region Building Test Cases
                if (m_DumpTestCaseData)
                {
                    var mvSer = new XmlSerializer(typeof(FlybyMeasurementContext));
                    var sb    = new StringBuilder();
                    using (var wrt = new StringWriter(sb))
                    {
                        mvSer.Serialize(wrt, meaContext);
                    }
                    Trace.WriteLine(sb.ToString());
                    var fcSer = new XmlSerializer(typeof(FittingContext));
                    sb.Clear();
                    using (var wrt = new StringWriter(sb))
                    {
                        fcSer.Serialize(wrt, fittingContext);
                    }
                    Trace.WriteLine(sb.ToString());

                    var smfmSer = new XmlSerializer(typeof(SingleMultiFrameMeasurement));
                    foreach (int key in measurements.Keys)
                    {
                        sb.Clear();
                        using (var wrt2 = new StringWriter(sb))
                        {
                            smfmSer.Serialize(wrt2, measurements[key]);
                            if (measurements[key].FrameNo != key)
                            {
                                throw new InvalidOperationException();
                            }
                            Trace.WriteLine(sb.ToString());
                        }
                    }
                }
                #endregion

                // Do linear regression, use residual based exclusion rules
                // Report the interpolated position at the middle of the measured interva
                // Don't forget to add the video normal position flag in the OBS file
                // Expect elongated images and apply instrumental delay corrections

                motionRate = double.NaN;

                var rv = new ProcessingReturnValues();

                int numFramesUser = 0;

                rv.EarliestFrame = int.MaxValue;
                rv.LatestFrame   = int.MinValue;

                var intervalValues  = new Dictionary <int, Tuple <List <double>, List <double> > >();
                var intervalMedians = new Dictionary <double, double>();
                var intervalWeights = new Dictionary <double, double>();

                LinearRegression regression = null;
                if (measurements.Values.Count > 1)
                {
                    rv.EarliestFrame = measurements.Values.Select(m => m.FrameNo).Min();
                    rv.LatestFrame   = measurements.Values.Select(m => m.FrameNo).Max();

                    var minUncertainty = meaContext.MinPositionUncertaintyPixels * meaContext.ArsSecsInPixel;

                    foreach (SingleMultiFrameMeasurement measurement in measurements.Values)
                    {
                        int integrationInterval = (measurement.FrameNo - fittingContext.FirstFrameIdInIntegrationPeroid) / fittingContext.IntegratedFramesCount;

                        Tuple <List <double>, List <double> > intPoints;
                        if (!intervalValues.TryGetValue(integrationInterval, out intPoints))
                        {
                            intPoints = Tuple.Create(new List <double>(), new List <double>());
                            intervalValues.Add(integrationInterval, intPoints);
                        }

                        if (fittingValue == FittingValue.RA)
                        {
                            intPoints.Item1.Add(measurement.RADeg);
                            intPoints.Item2.Add(ComputePositionWeight(measurement.SolutionUncertaintyRACosDEArcSec, measurement, minUncertainty, fittingContext.Weighting));
                        }
                        else
                        {
                            intPoints.Item1.Add(measurement.DEDeg);
                            intPoints.Item2.Add(ComputePositionWeight(measurement.SolutionUncertaintyDEArcSec, measurement, minUncertainty, fittingContext.Weighting));
                        }
                    }

                    if (intervalValues.Count > 2)
                    {
                        regression = new LinearRegression();

                        foreach (int integratedFrameNo in intervalValues.Keys)
                        {
                            Tuple <List <double>, List <double> > data = intervalValues[integratedFrameNo];

                            double median;
                            double medianWeight;

                            WeightedMedian(data, out median, out medianWeight);

                            // Assign the data point to the middle of the integration interval (using frame numbers)
                            //
                            // |--|--|--|--|--|--|--|--|
                            // |           |           |
                            //
                            // Because the time associated with the first frame is the middle of the frame, but the
                            // time associated with the middle of the interval is the end of the field then the correction
                            // is (N / 2) - 0.5 frames when integration is used or no correction when integration of x1 is used.

                            double dataPointFrameNo =
                                rv.EarliestFrame +
                                fittingContext.IntegratedFramesCount * integratedFrameNo
                                + (fittingContext.IntegratedFramesCount / 2)
                                - (fittingContext.IntegratedFramesCount > 1 ? 0.5 : 0);

                            intervalMedians.Add(dataPointFrameNo, median);
                            intervalWeights.Add(dataPointFrameNo, medianWeight);
                            if (fittingContext.Weighting != WeightingMode.None)
                            {
                                regression.AddDataPoint(dataPointFrameNo, median, medianWeight);
                            }
                            else
                            {
                                regression.AddDataPoint(dataPointFrameNo, median);
                            }
                        }

                        regression.Solve();

                        var    firstPos       = measurements[rv.EarliestFrame];
                        var    lastPos        = measurements[rv.LatestFrame];
                        double distanceArcSec = AngleUtility.Elongation(firstPos.RADeg, firstPos.DEDeg, lastPos.RADeg, lastPos.DEDeg) * 3600;
                        var    firstTime      = GetTimeForFrame(fittingContext, rv.EarliestFrame, meaContext.FirstVideoFrame, getFrameStateDataCallback, firstPos.FrameTimeStamp);
                        var    lastTime       = GetTimeForFrame(fittingContext, rv.LatestFrame, meaContext.FirstVideoFrame, getFrameStateDataCallback, lastPos.FrameTimeStamp);
                        double elapsedSec     = new TimeSpan(lastTime.UT.Ticks - firstTime.UT.Ticks).TotalSeconds;
                        motionRate = distanceArcSec / elapsedSec;
                    }
                }

                FrameTime resolvedTime = null;
                if (int.MinValue != meaContext.UserMidFrame)
                {
                    // Find the closest video 'normal' MPC time and compute the frame number for it
                    // Now compute the RA/DE for the computed 'normal' frame
                    resolvedTime = GetTimeForFrame(fittingContext, meaContext.UserMidFrame, meaContext.FirstVideoFrame, getFrameStateDataCallback, measurements[meaContext.UserMidFrame].FrameTimeStamp);

                    #region Plotting Code
                    if (g != null)
                    {
                        float xPosBeg = (float)(resolvedTime.ClosestNormalIntervalFirstFrameNo - rv.EarliestFrame) * xScale + 5;
                        float xPosEnd = (float)(resolvedTime.ClosestNormalIntervalLastFrameNo - rv.EarliestFrame) * xScale + 5;

                        g.FillRectangle(s_NormalTimeIntervalHighlightBrush, xPosBeg, 1, (xPosEnd - xPosBeg), imageHight - 2);
                    }
                    #endregion
                }

                Dictionary <double, double> secondPassData = new Dictionary <double, double>();

                int minFrameId = measurements.Keys.Min();

                #region Plotting Code
                if (g != null)
                {
                    foreach (SingleMultiFrameMeasurement measurement in measurements.Values)
                    {
                        float x = (measurement.FrameNo - minFrameId) * xScale + 5;

                        ProcessingValues val = new ProcessingValues()
                        {
                            Value  = fittingValue == FittingValue.RA ? measurement.RADeg : measurement.DEDeg,
                            StdDev = fittingValue == FittingValue.RA ? measurement.StdDevRAArcSec / 3600.0 : measurement.StdDevDEArcSec / 3600.0
                        };

                        double valueFrom = val.Value - val.StdDev;
                        double valueTo   = val.Value + val.StdDev;

                        float yFrom = (float)(valueFrom - plottingContext.MinValue) * yScale + 5;
                        float yTo   = (float)(valueTo - plottingContext.MinValue) * yScale + 5;

                        g.DrawLine(plottingContext.IncludedPen, x, yFrom, x, yTo);
                        g.DrawLine(plottingContext.IncludedPen, x - 1, yFrom, x + 1, yFrom);
                        g.DrawLine(plottingContext.IncludedPen, x - 1, yTo, x + 1, yTo);
                    }
                }
                #endregion

                foreach (double integrFrameNo in intervalMedians.Keys)
                {
                    double val = intervalMedians[integrFrameNo];

                    double fittedValAtFrame = regression != null
                        ? regression.ComputeY(integrFrameNo)
                        : double.NaN;

                    bool included = Math.Abs(fittedValAtFrame - val) < 3 * regression.StdDev;

                    #region Plotting Code
                    if (g != null)
                    {
                        if (fittingContext.IntegratedFramesCount > 1)
                        {
                            Pen mPen = included ? plottingContext.IncludedPen : plottingContext.ExcludedPen;

                            float x = (float)(integrFrameNo - minFrameId) * xScale + 5;
                            float y = (float)(val - plottingContext.MinValue) * yScale + 5;

                            g.DrawEllipse(mPen, x - 3, y - 3, 6, 6);
                            g.DrawLine(mPen, x - 5, y - 5, x + 5, y + 5);
                            g.DrawLine(mPen, x + 5, y - 5, x - 5, y + 5);
                        }
                    }
                    #endregion

                    if (included)
                    {
                        secondPassData.Add(integrFrameNo, val);
                    }
                }

                #region Second Pass
                regression = null;
                if (secondPassData.Count > 2)
                {
                    regression = new LinearRegression();
                    foreach (double frameNo in secondPassData.Keys)
                    {
                        if (fittingContext.Weighting != WeightingMode.None)
                        {
                            regression.AddDataPoint(frameNo, secondPassData[frameNo], intervalWeights[frameNo]);
                        }
                        else
                        {
                            regression.AddDataPoint(frameNo, secondPassData[frameNo]);
                        }
                    }
                    regression.Solve();
                }
                #endregion

                if (regression != null)
                {
                    #region Plotting Code
                    if (g != null)
                    {
                        double leftFittedVal  = regression.ComputeY(rv.EarliestFrame);
                        double rightFittedVal = regression.ComputeY(rv.LatestFrame);

                        double err = 3 * regression.StdDev;

                        float leftAve  = (float)(leftFittedVal - plottingContext.MinValue) * yScale + 5;
                        float rightAve = (float)(rightFittedVal - plottingContext.MinValue) * yScale + 5;
                        float leftX    = 5 + (float)(rv.EarliestFrame - rv.EarliestFrame) * xScale;
                        float rightX   = 5 + (float)(rv.LatestFrame - rv.EarliestFrame) * xScale;

                        g.DrawLine(plottingContext.AveragePen, leftX, leftAve - 1, rightX, rightAve - 1);
                        g.DrawLine(plottingContext.AveragePen, leftX, leftAve, rightX, rightAve);
                        g.DrawLine(plottingContext.AveragePen, leftX, leftAve + 1, rightX, rightAve + 1);

                        float leftMin  = (float)(leftFittedVal - err - plottingContext.MinValue) * yScale + 5;
                        float leftMax  = (float)(leftFittedVal + err - plottingContext.MinValue) * yScale + 5;
                        float rightMin = (float)(rightFittedVal - err - plottingContext.MinValue) * yScale + 5;
                        float rightMax = (float)(rightFittedVal + err - plottingContext.MinValue) * yScale + 5;

                        g.DrawLine(plottingContext.AveragePen, leftX, leftMin, rightX, rightMin);
                        g.DrawLine(plottingContext.AveragePen, leftX, leftMax, rightX, rightMax);
                    }
                    #endregion

                    if (int.MinValue != meaContext.UserMidFrame &&
                        resolvedTime != null)
                    {
                        // Find the closest video 'normal' MPC time and compute the frame number for it
                        // Now compute the RA/DE for the computed 'normal' frame

                        double fittedValueUncertainty;
                        double fittedValueAtMiddleFrame = regression.ComputeYWithError(resolvedTime.ClosestNormalFrameNo, out fittedValueUncertainty);

                        Trace.WriteLine(string.Format("{0}; Included: {1}; Normal Frame No: {2}; Fitted Val: {3} +/- {4:0.00}",
                                                      meaContext.UserMidValue.ToString("0.00000"),
                                                      numFramesUser, resolvedTime.ClosestNormalFrameNo,
                                                      AstroConvert.ToStringValue(fittedValueAtMiddleFrame, "+HH MM SS.T"),
                                                      regression.StdDev * 60 * 60));

                        // Report the interpolated position at the middle of the measured interval
                        // Don't forget to add the video normal position flag in the OBS file
                        // Expect elongated images and apply instrumental delay corrections

                        rv.FittedValue                  = fittedValueAtMiddleFrame;
                        rv.FittedValueTime              = resolvedTime.ClosestNormalFrameTime;
                        rv.IsVideoNormalPosition        = true;
                        rv.FittedNormalFrame            = resolvedTime.ClosestNormalFrameNo;
                        rv.FittedValueUncertaintyArcSec = fittedValueUncertainty * 60 * 60;

                        #region Plotting Code
                        if (g != null)
                        {
                            // Plot the frame
                            float xPos = (float)(resolvedTime.ClosestNormalFrameNo - rv.EarliestFrame) * xScale + 5;
                            float yPos = (float)(rv.FittedValue - plottingContext.MinValue) * yScale + 5;
                            g.DrawLine(Pens.Yellow, xPos, 1, xPos, imageHight - 2);
                            g.FillEllipse(Brushes.Yellow, xPos - 3, yPos - 3, 6, 6);
                        }
                        #endregion
                    }
                    else
                    {
                        rv.FittedValue = double.NaN;
                    }
                }
                else
                {
                    rv.FittedValue = double.NaN;
                }

                return(rv);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.GetFullStackTrace());
                motionRate = 0;
                return(null);
            }
        }