Example #1
0
        public void MoonDistanceAndData_SelectDay(short Year, short Month, short Day, double Hour, double objRA, double objDEC, ref double distance, ref double bright, ref double moonRA, ref double moonDEC)
        {
            /*
             * El objRA y objDEC deben estar en las unidades comunes para este tipo de coordenadas
             * es decir RA en horas y DEC en grados, sin minutos y segundos ambos, deben ser por ejemplo
             * objRA = 18.25 (horas) y objDEC = 76.758 (grados)
             *
             * Devuelve la distancia a la luna y la luminosidad calculada en la fecha pasada por el parametro de entrada
             * dt.
             */

            //Inicialización de variables necesarias para calcular la posición de la luna

            ASCOM.Astrometry.Object3  moonObj3 = new ASCOM.Astrometry.Object3();
            ASCOM.Astrometry.Accuracy Accu;

            double JD        = 0;
            double rc        = 0;
            double moonDisUA = 0;


            //Creamos los objetos ASCOM que contienen los metodos necesarios para el calculo de la
            //posicion de la luna, de la luminosidad, del Julian Date y conversiones de datos.

            ASCOM.Astrometry.NOVAS.NOVAS31         ApASCOM2 = new ASCOM.Astrometry.NOVAS.NOVAS31();
            ASCOM.Astrometry.AstroUtils.AstroUtils ApASCOM1 = new ASCOM.Astrometry.AstroUtils.AstroUtils();

            //Creamos el objeto ASCOM de la luna

            moonObj3.Name   = "Moon";
            moonObj3.Type   = ASCOM.Astrometry.ObjectType.MajorPlanetSunOrMoon;
            moonObj3.Number = ASCOM.Astrometry.Body.Moon;

            //Definimos la precision del calculo

            Accu = ASCOM.Astrometry.Accuracy.Full;

            //Calculamos el Julian Date para el dia pasado por entrada

            JD = ApASCOM2.JulianDate(Year, Month, Day, Hour);


            //Calculamos las coordenadas de la luna en RA (Horas) y DEC (grados)
            //rc es un parámetro de control que dice si la función se ha ejecutado correctamente

            rc = ApASCOM2.AppPlanet(JD, moonObj3, Accu, ref moonRA, ref moonDEC, ref moonDisUA);

            //Calculamos el brillo de la luna en tanto por 1

            bright = ApASCOM1.MoonIllumination(JD);

            /* Pasamos al calculo de la distancia con el objeto que deseamos observar con el telescopio.
             * Para ello tendremos que cambiar los datos de coordenadas de ambos objetos ya que RA esta
             * en GRADOS y DEC en GRADOS SEXAGESIMALES. Con lo cual se haran las conversiones pertinentes para obtener radianes
             * tras los cálculos en radianes se devolverá el resultado en GRADOS.
             ****************************************************************************
             */
            moonRA  = moonRA * 15 * Math.PI / 180;    //Conversión a  radianes (pi/180) y a grados (15)
            moonDEC = moonDEC * Math.PI / 180;
            double objRA1  = objRA * Math.PI / 180;   //Conversión a radianes (pi/180)
            double objDEC1 = objDEC * Math.PI / 180;  //Solo necesitamos conversión a radianes.

            //La formula para calcular la distancia ha sido obtenida de la página web http://aa.quae.nl/en/reken/afstanden.html (equation 11 from polar coordinates)
            //Devuelve el resultado de distance en Grados Sexagesimales

            //q es una variable auxiliar para poder hacer los calculos de manera mas ordenada.
            //q is a auxiliar variable just to calculate the distance in a clearer way.


            double q  = Math.Pow(Math.Sin((0.5 * (objDEC1 - moonDEC))), (double)2) + Math.Cos(moonDEC) * Math.Cos(objDEC1) * Math.Pow(Math.Sin(0.5 * (objRA1 - moonRA)), (double)2);
            double q2 = Math.Pow(Math.Sin((0.5 * (objDEC1 + moonDEC))), (double)2) + Math.Cos(moonDEC) * Math.Cos(objDEC1) * Math.Pow(Math.Cos(0.5 * (objRA1 - moonRA)), (double)2);

            distance = Math.Abs(2 * Math.Atan(Math.Sqrt(q / q2)) * 180 / Math.PI);    //el resultado de ATAN es radianes de ahí que se multiplique por la conversión para pasar a grados.

            //Devolvemos a grados el moonRA y moonDEC

            moonRA  = Math.Round(moonRA * 180 / Math.PI, 12);    //Conversión a  grados (180/pi)
            moonDEC = Math.Round(moonDEC * 180 / Math.PI, 12);
        }
Example #2
0
        public void UpdateEnvironmentals()
        {
            //StartMJD =
            var      utils     = new ASCOM.Astrometry.AstroUtils.AstroUtils();
            DateTime startdate = SequenceStartDateTimePicker.SelectedDate.Value.Date;

            if (SequenceStartHour.SelectedIndex > -1)
            {
                startdate = startdate.AddHours(((double)SequenceStartHour.SelectedIndex));
            }
            if (SequenceStartMinute.SelectedIndex > -1)
            {
                startdate = startdate.AddMinutes((double)SequenceStartMinute.SelectedIndex);
            }

//            Console.WriteLine("Local: {0}", startdate);

            string MoonInfo  = "";
            string SunInfo   = "";
            string AstroInfo = "";


            //StartMJD = utils.CalendarToMJD(startdate.Day, startdate.Month, startdate.Year);
            //julian  utility.DateLocalToJulian(startdate);
            StartJulian = utility.DateLocalToJulian(startdate);

            //if (SequenceStartHour.SelectedIndex > -1) { StartMJD = StartMJD + ((double) SequenceStartHour.SelectedIndex / 24); }
            //if (SequenceStartMinute.SelectedIndex > -1) { StartMJD = StartMJD + ((double)SequenceStartMinute.SelectedIndex / 1440); }

            //Console.WriteLine("{0}", StartMJD);
            Console.WriteLine(" Illumination: {0}", utils.MoonIllumination(StartJulian));
            MoonInfo = utils.MoonIllumination(StartJulian).ToString("p") + " Illumination      \n";

            //ASCOM.Astrometry.AstroUtils.AstroUtils apUtil = new ASCOM.Astrometry.AstroUtils.AstroUtils();
            System.Collections.ArrayList astroNight  = new System.Collections.ArrayList();
            System.Collections.ArrayList civilNight  = new System.Collections.ArrayList();
            System.Collections.ArrayList sunRiseSet  = new System.Collections.ArrayList();
            System.Collections.ArrayList MoonRiseSet = new System.Collections.ArrayList();
            //DateTime lastUpdate = TimeZoneInfo.ConvertTimeToUtc(startdate, SequenceTimeZone);
            DateTime lastUpdate = startdate;

            double lat = SiteLat;
            double lon = SiteLong;

            civilNight  = apUtil.EventTimes(ASCOM.Astrometry.EventType.CivilTwilight, lastUpdate.Day, lastUpdate.Month, lastUpdate.Year, lat, lon, SequenceTimeZoneOffset.TotalHours);
            astroNight  = apUtil.EventTimes(ASCOM.Astrometry.EventType.AstronomicalTwilight, lastUpdate.Day, lastUpdate.Month, lastUpdate.Year, lat, lon, SequenceTimeZoneOffset.TotalHours);
            sunRiseSet  = apUtil.EventTimes(ASCOM.Astrometry.EventType.SunRiseSunset, lastUpdate.Day, lastUpdate.Month, lastUpdate.Year, lat, lon, SequenceTimeZoneOffset.TotalHours);
            MoonRiseSet = apUtil.EventTimes(ASCOM.Astrometry.EventType.MoonRiseMoonSet, lastUpdate.Day, lastUpdate.Month, lastUpdate.Year, lat, lon, SequenceTimeZoneOffset.TotalHours);


//            Console.WriteLine("SunSet: " + TimeSpan.FromHours((double)(sunRiseSet[4])).ToString("h\\:mm"));

            if (sunRiseSet.Count > 0)
            {
                int NumberOfRises = ((int)sunRiseSet[1]); //' Retrieve the number of sunsets
                int NumberOfSets  = ((int)sunRiseSet[2]); //' Retrieve the number of sunsets

                for (int sets = 0; sets < NumberOfRises; sets++)
                {
                    if ((double)(sunRiseSet[sets + 3]) > (double)(sunRiseSet[sets + 4]))
                    {
                        SunInfo += " Sunset: " + TimeSpan.FromHours((double)(sunRiseSet[sets + 4])).ToString("h\\:mm");
                        SunInfo += " Sunrise: " + TimeSpan.FromHours((double)(sunRiseSet[sets + 3])).ToString("h\\:mm");
                    }
                    else
                    {
                        SunInfo += " Sunrise: " + TimeSpan.FromHours((double)(sunRiseSet[sets + 3])).ToString("h\\:mm");
                        SunInfo += " Sunset: " + TimeSpan.FromHours((double)(sunRiseSet[sets + 4])).ToString("h\\:mm");
                    }
                }
            }
            Console.WriteLine("Suninfo : " + SunInfo);

            if (MoonRiseSet.Count > 0)
            {
                int NumberOfRises = ((int)MoonRiseSet[1]); //' Retrieve the number of sunsets
                int NumberOfSets  = ((int)MoonRiseSet[2]); //' Retrieve the number of sunsets
                for (int sets = 0; sets < NumberOfRises; sets++)
                {
                    if ((double)(MoonRiseSet[sets + 3]) > (double)(MoonRiseSet[sets + 4]))
                    {
                        MoonInfo += " Moonset: " + TimeSpan.FromHours((double)(MoonRiseSet[sets + 4])).ToString("h\\:mm");
                        MoonInfo += " Moonrise: " + TimeSpan.FromHours((double)(MoonRiseSet[sets + 3])).ToString("h\\:mm");
                    }
                    else
                    {
                        MoonInfo += " Moonrise: " + TimeSpan.FromHours((double)(MoonRiseSet[sets + 3])).ToString("h\\:mm");
                        MoonInfo += " Moonset: " + TimeSpan.FromHours((double)(MoonRiseSet[sets + 4])).ToString("h\\:mm");
                    }
                }
                //MoonInfo += TimeSpan.FromHours((double)(MoonRiseSet[NumberOfSets + 3])).ToString("h\\:mm");
            }
            Console.WriteLine("Mooninfo: " + MoonInfo);

            if (astroNight.Count > 0)
            {
                int NumberOfRises = ((int)astroNight[1]); //' Retrieve the number of sunsets
                int NumberOfSets  = ((int)astroNight[2]); //' Retrieve the number of sunsets
                for (int sets = 0; sets < NumberOfRises; sets++)
                {
                    if ((double)(astroNight[sets + 3]) > (double)(astroNight[sets + 4]))
                    {
                        AstroInfo += " AstroStart: " + TimeSpan.FromHours((double)(astroNight[sets + 4])).ToString("h\\:mm");
                        AstroInfo += " AstroEnd: " + TimeSpan.FromHours((double)(astroNight[sets + 3])).ToString("h\\:mm");
                    }
                    else
                    {
                        AstroInfo += " AstroEnd: " + TimeSpan.FromHours((double)(astroNight[sets + 3])).ToString("h\\:mm");
                        AstroInfo += " AstroStart: " + TimeSpan.FromHours((double)(astroNight[sets + 4])).ToString("h\\:mm");
                    }
                }
                //MoonInfo += TimeSpan.FromHours((double)(MoonRiseSet[NumberOfSets + 3])).ToString("h\\:mm");
            }
            Console.WriteLine("AstroInfo: " + AstroInfo);

            //Console.WriteLine("Event Times 1: " + EventTimes1);
            //Console.WriteLine("Event Times 2: " + EventTimes2);

            EnvironmentalTextBlock.Text = SunInfo + "\n" + AstroInfo;
            MoonInfoTextBlock.Text      = MoonInfo;

            /*
             * Console.WriteLine("Latitude: " + lat.ToString());
             * Console.WriteLine("Longitude:" + lon.ToString());
             * Console.WriteLine("Time" + lastUpdate.ToString());
             *
             *
             * Console.WriteLine("sunRiseSet cont :" + sunRiseSet.Count.ToString());
             * foreach (var e in sunRiseSet) Console.WriteLine("Array sunRiseSet:" + e.ToString());
             * Console.WriteLine("civilNignht cont :" + civilNight.Count.ToString());
             * foreach (var e in astroNight) Console.WriteLine("Array astro:" + e.ToString());
             *
             * Console.WriteLine("astroNight cont :" + astroNight.Count.ToString());
             *
             * DateTime objDateWoHour = lastUpdate.Date;*/
        }