Пример #1
0
        public bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    hzResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch    = URL_MPES_Search + MakeSearchQuery();
                hzResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message);
                return(false);
            };
            //Check result
            if (!hzResultText.Contains("Date"))
            {
                MessageBox.Show("Target not found");
                return(false);
            }
            //Convert Text to XML  -- JSON format is rudimentary and no better than text
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            char[]   spc          = { ' ' };
            string[] mpcLineItems = hzResultText.Split('\n');
            int      soeIdx       = FindLine(mpcLineItems, "Date") + 2;
            int      eoeIdx       = FindLine(mpcLineItems, " These calculations have been performed on the") - 2;
            XElement ephmList     = new XElement("Ephemeris");

            for (int i = soeIdx; i < eoeIdx; i++)
            {
                XElement ephmRecord  = new XElement("Data");
                string   mpcDataLine = mpcLineItems[i];
                ephmRecord.Add(new XElement(mUTDate, mpcDataLine.Substring(colUTDateY, 4) + "-" + mpcDataLine.Substring(colUTDateM, 2) + "-" + mpcDataLine.Substring(colUTDateD, 2)));
                string timestring = mpcDataLine.Substring(colUTHrMin, 6);
                string sTime      = timestring[0].ToString() + timestring[1].ToString() + ":" + timestring[2].ToString() + timestring[3].ToString() + ":" + timestring[4].ToString() + timestring[5].ToString();
                ephmRecord.Add(new XElement(mUTHrMin, sTime));
                ephmRecord.Add(new XElement(mRA, mpcDataLine.Substring(colRA, 8)));
                ephmRecord.Add(new XElement(mDec, mpcDataLine.Substring(colDec, 9)));
                ephmRecord.Add(new XElement(mDelta, mpcDataLine.Substring(colDelta, 9)));
                ephmRecord.Add(new XElement(mr, mpcDataLine.Substring(colr, 7)));
                ephmRecord.Add(new XElement(mEl, mpcDataLine.Substring(colEl, 6)));
                ephmRecord.Add(new XElement(mPh, mpcDataLine.Substring(colPh, 5)));
                ephmRecord.Add(new XElement(mV, mpcDataLine.Substring(colV, 5)));
                ephmRecord.Add(new XElement(mdRACosD, mpcDataLine.Substring(coldRACosD, 8)));
                ephmRecord.Add(new XElement(mdDec, mpcDataLine.Substring(coldDec, 8)));
                ephmRecord.Add(new XElement(mAzi, mpcDataLine.Substring(colAzi, 6)));
                ephmRecord.Add(new XElement(mAlt, mpcDataLine.Substring(colAlt, 5)));
                ephmRecord.Add(new XElement(mSunAlt, mpcDataLine.Substring(colSunAlt, 5)));
                ephmRecord.Add(new XElement(mMoonPhase, mpcDataLine.Substring(colMoonPhase, 6)));
                ephmRecord.Add(new XElement(mMoonDist, mpcDataLine.Substring(colMoonDist, 5)));
                ephmRecord.Add(new XElement(mMoonAlt, mpcDataLine.Substring(colMoonAlt, 4)));

                ephmList.Add(ephmRecord);
            }

            //Convert XML to speed vector array
            SpeedVector currentSpeedVector;

            foreach (XElement ephX in ephmList.Elements("Data"))
            {
                string   sDate         = ephX.Element(mUTDate).Value;
                string   sTime         = ephX.Element(mUTHrMin).Value;
                string   sUTDateTime   = sDate + " " + sTime;
                DateTime sUT           = Convert.ToDateTime(sUTDateTime);
                double   sRA_D         = Convert.ToDouble(ephX.Element(mRA).Value);
                double   sDec_D        = Convert.ToDouble(ephX.Element(mDec).Value);
                double   sElevation_KM = MPC_Observatory.BestObservatory.MySiteElev;
                //Compute PA
                double sdDecdt = Convert.ToDouble(ephX.Element(mdDec).Value);    //arcsec/min
                double sdRAdt  = Convert.ToDouble(ephX.Element(mdRACosD).Value); //arcsec/min
                double sPA_D   = Math.Atan2(sdDecdt, sdRAdt);
                double sRange  = Convert.ToDouble(ephX.Element(mr).Value);
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC = sUT,
                    Rate_RA_CosDec_ArcsecPerMinute = sdRAdt,
                    Rate_Dec_ArcsecPerMinute       = sdDecdt,
                    RA_Degrees   = sRA_D, //Scout delivers RA in degrees
                    Dec_Degrees  = sDec_D,
                    PA_Degrees   = sPA_D,
                    Range_AU     = sRange, //AU
                    Elevation_KM = sElevation_KM
                };
                BasicRateTable.Add(currentSpeedVector);
            }
            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                //must add interpolated ephemeras
                //Horizons delivers a full day worth of data at 1 minute intervals
                // throwaway all but the first hour (60 readings) so we don't run out of memory interpolating
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    if (BasicRateTable[bIdx].Time_UTC > DateTime.UtcNow && BasicRateTable[bIdx].Time_UTC < DateTime.UtcNow + TimeSpan.FromHours(1))
                    {
                        UpdateRateTable.Add(BasicRateTable[bIdx]);
                        Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                        foreach (SpeedVector sv in intp.WayPoints)
                        {
                            UpdateRateTable.Add(sv);
                        }
                    }
                }
            }

            return(true);
        }
Пример #2
0
        private bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    neoResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch     = URL_NEO_search + MakeSearchQuery(GetTargetName(), MPC_Observatory.BestObservatory.MPC_Code);
                neoResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message + "\n Possibly the NEO target is not available on Scout for ephemeris.");
                return(false);
            };
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            ScoutResultsX   = JsonConvert.DeserializeXNode(neoResultText, "Root");
            IEnumerable <XElement> sEphXList        = ScoutResultsX.Element("Root").Elements("eph");
            SpeedVector            priorSpeedVector = null;
            SpeedVector            currentSpeedVector;
            double changeRaArcSec  = 0;
            double changeDecArcSec = 0;

            foreach (XElement ephX in sEphXList)
            {
                IEnumerable <XElement> sPositionX    = ephX.Element("data").Elements("data");
                List <XElement>        sPositionList = sPositionX.ToList();
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC             = Convert.ToDateTime(ephX.Element("time").Value),
                    Rate_ArcsecPerMinute = Convert.ToDouble(sPositionList[idx_rate].Value), //Arcsec/min
                    PA_Degrees           = (Convert.ToDouble(sPositionList[idx_pa].Value)),
                    RA_Degrees           = Convert.ToDouble(sPositionList[idx_ra].Value),   //Scout delivers RA in degrees
                    Dec_Degrees          = Convert.ToDouble(sPositionList[idx_dec].Value),
                    Elevation_KM         = Convert.ToDouble(sPositionList[idx_el].Value),
                    Range_AU             = Convert.ToDouble(sPositionList[idx_reO].Value) //AU
                };

                if (priorSpeedVector != null)
                {
                    //This is not the first vector,
                    //  Calculate the change in RA and Dec, save it in the prior vector and save the prior vector
                    //  then set the current vector as the prior vector
                    double interval_Minutes = (currentSpeedVector.Time_UTC - priorSpeedVector.Time_UTC).TotalMinutes;
                    changeRaArcSec = Transform.DegreesToArcSec(currentSpeedVector.RA_Degrees - priorSpeedVector.RA_Degrees);
                    priorSpeedVector.Rate_RA_CosDec_ArcsecPerMinute = changeRaArcSec / interval_Minutes;
                    changeDecArcSec = Transform.DegreesToArcSec(currentSpeedVector.Dec_Degrees - priorSpeedVector.Dec_Degrees);
                    priorSpeedVector.Rate_Dec_ArcsecPerMinute = changeDecArcSec / interval_Minutes;
                    BasicRateTable.Add(priorSpeedVector);
                    priorSpeedVector = currentSpeedVector;
                }
                else
                {
                    priorSpeedVector = currentSpeedVector;   //This is the first vector.  Set it as prior and get the next one.
                }
            }
            //The last prior vector will not have been saved, nor the RA and Dec rates filled in
            //  and there is no next vector to calculate RA and Dec differences, so use the last ones because
            //  the Scout dRA/dDec data is all f****d up
            priorSpeedVector.Rate_RA_CosDec_ArcsecPerMinute = changeRaArcSec;
            priorSpeedVector.Rate_Dec_ArcsecPerMinute       = changeDecArcSec;
            BasicRateTable.Add(priorSpeedVector);

            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    UpdateRateTable.Add(BasicRateTable[bIdx]);
                    Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                    foreach (SpeedVector sv in intp.WayPoints)
                    {
                        UpdateRateTable.Add(sv);
                    }
                }
            }
            return(true);
        }
Пример #3
0
        public bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    hzResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch    = URL_Horizons_Search + MakeSearchQuery();
                hzResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message);
                return(false);
            };
            //Check result
            if (!hzResultText.Contains("$$SOE"))
            {
                MessageBox.Show("Target not found");
                return(false);
            }
            //Convert Text to XML  -- JSON format is rudimentary and no better than text
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            char[]   spc         = { ' ' };
            string[] hzLineItems = hzResultText.Split('\n');
            int      soeIdx      = Array.IndexOf(hzLineItems, "$$SOE");
            int      eoeIdx      = Array.IndexOf(hzLineItems, "$$EOE");

            string[] headers  = hzLineItems[soeIdx - 2].Split(spc, StringSplitOptions.RemoveEmptyEntries);
            XElement ephmList = new XElement("Ephemeris");

            for (int i = soeIdx + 1; i < eoeIdx; i++)
            {
                XElement ephmRecord = new XElement("Data");
                string   cleanLine  = hzLineItems[i].Remove(22, 2); //Clear out some garbage that Horizons leaves in the line for some reason -- minutes? seconds?
                string[] columns    = cleanLine.Split(spc, StringSplitOptions.RemoveEmptyEntries);
                for (int r = 0; r < headers.Count(); r++)
                {
                    ephmRecord.Add(new XElement(headerNames[r], columns[r]));
                }
                ephmList.Add(ephmRecord);
            }

            //Convert XML to speed vector array
            SpeedVector currentSpeedVector;

            foreach (XElement ephX in ephmList.Elements("Data"))
            {
                string sDate       = ephX.Element(hzUTDate).Value;
                string sTime       = ephX.Element(hzUTHrMin).Value;
                string sUTDateTime = sDate + " " + sTime;
                sUTDateTime = sUTDateTime.Replace('.', ' ');
                DateTime sUT           = Convert.ToDateTime(sUTDateTime);
                double   sRA_D         = Convert.ToDouble(ephX.Element(hzRA).Value);
                double   sDec_D        = Convert.ToDouble(ephX.Element(hzDec).Value);
                double   sElevation_KM = MPC_Observatory.BestObservatory.MySiteElev;
                //Compute PA
                double sdDecdt = Convert.ToDouble(ephX.Element(hzdDec).Value) / 60;    //convert to arcsec/min
                double sdRAdt  = Convert.ToDouble(ephX.Element(hzdRACosD).Value) / 60; //convert to arcsec/min
                double sPA_D   = Math.Atan2(sdDecdt, sdRAdt);
                double sRange  = Convert.ToDouble(ephX.Element(hzr).Value);
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC = sUT,
                    //Rate_ArcsecPerMinute = sRate,
                    Rate_RA_CosDec_ArcsecPerMinute = sdRAdt,
                    Rate_Dec_ArcsecPerMinute       = sdDecdt,
                    RA_Degrees   = sRA_D, //Scout delivers RA in degrees
                    Dec_Degrees  = sDec_D,
                    PA_Degrees   = sPA_D,
                    Range_AU     = sRange, //AU
                    Elevation_KM = sElevation_KM
                };
                BasicRateTable.Add(currentSpeedVector);
            }
            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                //must add interpolated ephemeras
                //Horizons delivers a full day worth of data at 1 minute intervals
                // throwaway all but the first hour (60 readings) so we don't run out of memory interpolating
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    if (BasicRateTable[bIdx].Time_UTC > DateTime.UtcNow && BasicRateTable[bIdx].Time_UTC < DateTime.UtcNow + TimeSpan.FromHours(1))
                    {
                        UpdateRateTable.Add(BasicRateTable[bIdx]);
                        Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                        foreach (SpeedVector sv in intp.WayPoints)
                        {
                            UpdateRateTable.Add(sv);
                        }
                    }
                }
            }

            return(true);
        }
Пример #4
0
        private bool ServerQueryToSpeedVectors(bool isMinutes, int updateInterval)
        {
            string    neoResultText;
            string    urlSearch;
            WebClient client = new WebClient();

            System.Net.ServicePointManager.ServerCertificateValidationCallback = (senderX, certificate, chain, sslPolicyErrors) => { return(true); };
            try
            {
                urlSearch     = URL_NEO_search + MakeSearchQuery(TgtName, MPC_Observatory.BestObservatory.MPC_Code);
                neoResultText = client.DownloadString(urlSearch);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Download Error: " + ex.Message + "\n Possibly the NEO target is not available on Scout for ephemeris.");
                return(false);
            };
            List <SpeedVector> BasicRateTable = new List <SpeedVector>();

            UpdateRateTable = new List <SpeedVector>();
            ScoutResultsX   = JsonConvert.DeserializeXNode(neoResultText, "Root");
            IEnumerable <XElement> sEphXList = ScoutResultsX.Element("Root").Elements("eph");
            SpeedVector            currentSpeedVector;

            foreach (XElement ephX in sEphXList)
            {
                IEnumerable <XElement> sPositionX    = ephX.Element("data").Elements("data");
                List <XElement>        sPositionList = sPositionX.ToList();
                currentSpeedVector = new SpeedVector
                {
                    Time_UTC             = Convert.ToDateTime(ephX.Element("time").Value),
                    Rate_ArcsecPerMinute = Convert.ToDouble(sPositionList[idx_rate].Value), //Arcsec/min
                    PA_Degrees           = (Convert.ToDouble(sPositionList[idx_pa].Value)),
                    RA_Degrees           = Convert.ToDouble(sPositionList[idx_ra].Value),   //Scout delivers RA in degrees
                    Dec_Degrees          = Convert.ToDouble(sPositionList[idx_dec].Value),
                    Elevation_KM         = Convert.ToDouble(sPositionList[idx_el].Value),
                    Range_AU             = Convert.ToDouble(sPositionList[idx_reO].Value) //AU
                };
                currentSpeedVector.Rate_RA_CosDec_ArcsecPerMinute = Utils.PARateToRA(currentSpeedVector.PA_Degrees, currentSpeedVector.Rate_ArcsecPerMinute);
                currentSpeedVector.Rate_Dec_ArcsecPerMinute       = Utils.PARateToDec(currentSpeedVector.PA_Degrees, currentSpeedVector.Rate_ArcsecPerMinute);
                BasicRateTable.Add(currentSpeedVector);
            }
            if (isMinutes)
            {
                UpdateRateTable = BasicRateTable;
            }
            else
            {
                //must add interpolated ephemeras
                for (int bIdx = 0; bIdx < BasicRateTable.Count - 1; bIdx++)
                {
                    UpdateRateTable.Add(BasicRateTable[bIdx]);
                    Interpolate intp = new Interpolate(BasicRateTable[bIdx], BasicRateTable[bIdx + 1], updateInterval);
                    foreach (SpeedVector sv in intp.WayPoints)
                    {
                        UpdateRateTable.Add(sv);
                    }
                }
            }
            return(true);
        }