Beispiel #1
0
 public double Semidiameter(SkyContext c)
 {
     return(SolarEphem.Semidiameter(c.Get(Ecliptical).Distance));
 }
 private CrdsHorizontal MarsMoon_Horizontal(SkyContext c, int m)
 {
     return(c.Get(MarsMoon_Equatorial, m).ToHorizontal(c.GeoLocation, c.SiderealTime));
 }
Beispiel #3
0
 /// <summary>
 /// Gets geocentric equatorial coordinates of the Sun
 /// </summary>
 public CrdsEquatorial Equatorial0(SkyContext c)
 {
     return(c.Get(Ecliptical).ToEquatorial(c.Epsilon));
 }
Beispiel #4
0
        public void GetInfo(CelestialObjectInfo <DeepSky> info)
        {
            DeepSky     ds            = info.Body;
            SkyContext  c             = info.Context;
            DeepSkyInfo details       = c.Get(ReadDeepSkyDetails, ds);
            string      constellation = Constellations.FindConstellation(c.Get(Equatorial, ds), c.JulianDay);

            info
            .SetSubtitle(Text.Get($"DeepSky.{ds.Status}.Type"))
            .SetTitle(string.Join(" / ", ds.Names))
            .AddRow("Constellation", constellation)

            .AddHeader(Text.Get("DeepSky.Equatorial"))
            .AddRow("Equatorial.Alpha", ds.Equatorial.Alpha)
            .AddRow("Equatorial.Delta", ds.Equatorial.Delta)

            .AddHeader(Text.Get("DeepSky.Equatorial0"))
            .AddRow("Equatorial0.Alpha", ds.Equatorial0.Alpha)
            .AddRow("Equatorial0.Delta", ds.Equatorial0.Delta)

            .AddHeader(Text.Get("DeepSky.Horizontal"))
            .AddRow("Horizontal.Azimuth", ds.Horizontal.Azimuth)
            .AddRow("Horizontal.Altitude", ds.Horizontal.Altitude)

            .AddHeader(Text.Get("DeepSky.RTS"))
            .AddRow("RTS.Rise")
            .AddRow("RTS.Transit")
            .AddRow("RTS.Set")
            .AddRow("RTS.Duration")

            .AddHeader(Text.Get("DeepSky.Visibility"))
            .AddRow("Visibility.Begin")
            .AddRow("Visibility.End")
            .AddRow("Visibility.Duration")
            .AddRow("Visibility.Period")

            .AddHeader(Text.Get("DeepSky.Properties"));

            info.AddRow("Type", details.ObjectType);
            if (ds.Mag != null)
            {
                info.AddRow("VisualMagnitude", ds.Mag, Formatters.Magnitude);
            }
            if (details.PhotoMagnitude != null)
            {
                info.AddRow("PhotoMagnitude", details.PhotoMagnitude, Formatters.Magnitude);
            }
            if (details.SurfaceBrightness != null)
            {
                info.AddRow("SurfaceBrightness", details.SurfaceBrightness, new Formatters.SignedDoubleFormatter(2, " mag/sq.arcsec"));
            }

            if (ds.SizeA > 0)
            {
                string size = $"{Formatters.Angle.Format(ds.SizeA / 60)}";
                if (ds.SizeB > 0)
                {
                    size += $" x {Formatters.Angle.Format(ds.SizeB / 60)}";
                }
                info.AddRow("AngularDiameter", size, Formatters.Simple);
            }
            if (ds.PA > 0)
            {
                info.AddRow("PositionAngle", ds.PA, new Formatters.UnsignedDoubleFormatter(2, "\u00B0"));
            }

            if (details.Identifiers.Any() || details.PGC != null)
            {
                info.AddHeader(Text.Get("DeepSky.Designations"));
                if (details.Identifiers.Any())
                {
                    info.AddRow("OtherCatalogsIdentifiers", string.Join(", ", details.Identifiers));
                }
                if (details.PGC != null)
                {
                    info.AddRow("PGCCatalogNumber", string.Join(", ", details.PGC));
                }
            }

            if (!string.IsNullOrEmpty(details.Remarks))
            {
                info.AddRow("Remarks", details.Remarks);
            }
        }
 private CrdsEquatorial MarsMoon_Equatorial0(SkyContext c, int m)
 {
     return(c.Get(MarsMoon_Ecliptical, m).ToEquatorial(c.Epsilon));
 }
Beispiel #6
0
        private bool IsActive(SkyContext ctx, Meteor m)
        {
            int dayOfYear = ctx.Get(DayOfYear);

            return(m.Begin <= dayOfYear && dayOfYear <= m.End);
        }
Beispiel #7
0
 public MapContext(SkyMap map, SkyContext skyContext)
 {
     this.map        = map;
     this.skyContext = skyContext;
 }
Beispiel #8
0
 /// <summary>
 /// Gets number of years (with fractions) since J2000.0 epoch
 /// </summary>
 private double YearsSince2000(SkyContext c)
 {
     return((c.JulianDay - Date.EPOCH_J2000) / 365.25);
 }
Beispiel #9
0
 public CarrinhoStore(SkyContext context)
 {
     this.Db = context;
 }
 private CrdsHorizontal GenericMoon_Horizontal(SkyContext c, int id)
 {
     return(c.Get(GenericMoon_Equatorial, id).ToHorizontal(c.GeoLocation, c.SiderealTime));
 }
Beispiel #11
0
 /// <summary>
 /// Calculates horizontal geocentric coordinates of star for current epoch
 /// </summary>
 /// <param name="c"><see cref="SkyContext"/> instance</param>
 /// <param name="star"><see cref="Tycho2Star"/> object</param>
 /// <returns>Horizontal geocentric coordinates of star for current epoch</returns>
 private CrdsHorizontal Horizontal(SkyContext c, Tycho2Star star)
 {
     return(c.Get(Equatorial, star).ToHorizontal(c.GeoLocation, c.SiderealTime));
 }
 private CrdsEquatorial GenericMoon_Equatorial0(SkyContext c, int id)
 {
     return(c.Get(GenericMoon_Ecliptical, id).ToEquatorial(c.Epsilon));
 }
Beispiel #13
0
 private Date Seasons(SkyContext c, Season s)
 {
     return(c.GetDate(SolarEphem.Season(c.JulianDay, s)));
 }
Beispiel #14
0
 private double CarringtonNumber(SkyContext c)
 {
     return(SolarEphem.CarringtonNumber(c.JulianDay));
 }
        private ICollection <AstroEvent> Conjunctions(AstroEventsContext context)
        {
            // resulting collection of events
            List <AstroEvent> events = new List <AstroEvent>();

            // planets ephemeris data for the requested period
            ICollection <PlanetData[]> data = context.Get(PlanetEphemeris);

            // current index in data array
            int day = 0;

            // current calculated value of Julian Day
            double jd = context.From;

            // Time shifts, in days, from starting point to each point in a range to be interpolated
            double[] t = { 0, 1, 2, 3, 4 };

            for (jd = context.From; jd < context.To; jd++)
            {
                // "diff" is a planet difference in longitude with the Sun
                double[] diff = new double[5];

                // p is a number of a planet
                for (int p = 1; p <= 8; p++)
                {
                    // Skip Earth
                    if (p != 3)
                    {
                        // "diff" is a planet difference in longitude with the Sun (5 points)
                        for (int i = 0; i < 5; i++)
                        {
                            diff[i] = data.ElementAt(day + i)[p].LongitudeDifference;
                        }

                        if (Math.Abs(diff[2]) < 5 && diff[2] * diff[3] <= 0)
                        {
                            Interpolation.FindRoot(t, diff, 1e-6, out double t0);
                            double jdConj = jd - 2 + t0;
                            string text;

                            if (p < 3)
                            {
                                string conjType = data.ElementAt(day + 2)[p].Ecliptical.Distance < 1 ?
                                                  "Inferior" : "Superior";

                                var    ctx = new SkyContext(jdConj, context.GeoLocation, false);
                                double sd  = solarCalc.Semidiameter(ctx) / 3600;
                                double ad  = Math.Abs(planetsCalc.Planet_Elongation(ctx, p));

                                text = Text.Get($"PlanetEvents.Conjunctions.{conjType}",
                                                ("planetName", GetPlanetName(p)),
                                                ("planetGenitiveName", GetPlanetGenitiveName(p)));

                                if (ad < sd)
                                {
                                    text = $"{text}{Text.Get("PlanetEvents.Conjunctions.Transit")}";
                                }
                            }
                            else
                            {
                                text = Text.Get($"PlanetEvents.Conjunctions.Text",
                                                ("planetName", GetPlanetName(p)),
                                                ("planetGenitiveName", GetPlanetGenitiveName(p)));
                            }

                            events.Add(new AstroEvent(jdConj, text));
                        }
                    }
                }

                day++;
            }

            return(events);
        }
Beispiel #16
0
        private void ConfigureContainer(IProgress <string> progress)
        {
            kernel.Bind <ICommandLineArgs>().ToConstant(commandLineArgs).InSingletonScope();
            kernel.Bind <ISettings, Settings>().To <Settings>().InSingletonScope();
            kernel.Bind <ISky, Sky>().To <Sky>().InSingletonScope();
            kernel.Bind <ISkyMap, SkyMap>().To <SkyMap>().InSingletonScope();
            kernel.Bind <IGeoLocationsManager, GeoLocationsManager>().To <GeoLocationsManager>().InSingletonScope();
            kernel.Bind <IMainWindow, MainVM>().To <MainVM>().InSingletonScope();
            kernel.Bind <UIElementsIntegration>().ToSelf().InSingletonScope();
            UIElementsIntegration uiIntegration = kernel.Get <UIElementsIntegration>();

            ICollection <AbstractPlugin> plugins = new List <AbstractPlugin>();

            string homeFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            IEnumerable <string> pluginPaths = Directory.EnumerateFiles(homeFolder, "Astrarium.Plugins.*.dll", SearchOption.AllDirectories);

            progress.Report("Loading plugins");

            foreach (string path in pluginPaths)
            {
                try
                {
                    var plugin = Assembly.UnsafeLoadFrom(path);

                    // get singletons defined in plugin
                    var singletons = plugin.GetExportedTypes().Where(t => t.IsDefined(typeof(SingletonAttribute), false)).ToArray();
                    foreach (var singletonImpl in singletons)
                    {
                        var singletonAttr = singletonImpl.GetCustomAttribute <SingletonAttribute>();
                        if (singletonAttr.InterfaceType != null)
                        {
                            if (!singletonAttr.InterfaceType.IsAssignableFrom(singletonImpl))
                            {
                                throw new Exception($"Interface type {singletonAttr.InterfaceType} is not assignable from {singletonImpl}");
                            }
                            kernel.Bind(singletonAttr.InterfaceType).To(singletonImpl).InSingletonScope();
                        }
                        else
                        {
                            kernel.Bind(singletonImpl).ToSelf().InSingletonScope();
                        }
                    }

                    Log.Info($"Loaded plugin {plugin.FullName}");
                }
                catch (Exception ex)
                {
                    Log.Error($"Unable to load plugin assembly with path {path}. {ex})");
                }
            }

            // collect all plugins implementations
            Type[] pluginTypes = AppDomain.CurrentDomain.GetAssemblies()
                                 .SelectMany(a => a.GetTypes())
                                 .Where(t => typeof(AbstractPlugin).IsAssignableFrom(t) && !t.IsAbstract)
                                 .ToArray();

            // collect all calculators types
            Type[] calcTypes = pluginTypes
                               .SelectMany(p => GetCalculators(p))
                               .ToArray();

            foreach (Type calcType in calcTypes)
            {
                var types = new[] { calcType }.Concat(calcType.GetInterfaces()).ToArray();
                kernel.Bind(types).To(calcType).InSingletonScope();
            }

            // collect all renderers types
            Type[] rendererTypes = pluginTypes
                                   .SelectMany(p => GetRenderers(p))
                                   .ToArray();

            foreach (Type rendererType in rendererTypes)
            {
                var types = new[] { rendererType }.Concat(rendererType.GetInterfaces()).ToArray();
                kernel.Bind(types).To(rendererType).InSingletonScope();
            }

            // collect all event provider implementations
            Type[] eventProviderTypes = pluginTypes
                                        .SelectMany(p => GetAstroEventProviders(p))
                                        .ToArray();

            foreach (Type eventProviderType in eventProviderTypes)
            {
                var types = new[] { eventProviderType }.Concat(eventProviderType.GetInterfaces()).ToArray();
                kernel.Bind(types).To(eventProviderType).InSingletonScope();
            }

            foreach (Type pluginType in pluginTypes)
            {
                progress.Report($"Creating plugin {pluginType}");

                try
                {
                    // plugin is a singleton
                    kernel.Bind(pluginType).ToSelf().InSingletonScope();
                    var plugin = kernel.Get(pluginType) as AbstractPlugin;

                    // add settings definitions
                    uiIntegration.SettingDefinitions.AddRange(plugin.SettingDefinitions);

                    // add settings sections
                    uiIntegration.SettingSections.AddRange(plugin.SettingSections);

                    // add configured toolbar buttons
                    uiIntegration.ToolbarButtons.AddRange(plugin.ToolbarItems);

                    // add menu items
                    uiIntegration.MenuItems.AddRange(plugin.MenuItems);

                    plugins.Add(plugin);
                }
                catch (Exception ex)
                {
                    Log.Error($"Unable to create plugin of type {pluginType.Name}: {ex}");
                    kernel.Unbind(pluginType);
                }
            }

            progress.Report($"Creating renderers");

            var renderers             = rendererTypes.Select(r => kernel.Get(r)).Cast <BaseRenderer>().ToArray();
            var defaultRenderingOrder = new RenderingOrder(renderers.OrderBy(r => r.Order).Select(r => new RenderingOrderItem(r)));

            uiIntegration.SettingDefinitions.Add(new SettingDefinition("RenderingOrder", defaultRenderingOrder, false));

            var settings = kernel.Get <ISettings>();

            settings.Define(uiIntegration.SettingDefinitions);
            settings.Save("Defaults");

            progress.Report($"Loading settings");

            settings.Load();

            SetLanguage(settings.Get <string>("Language"));
            SetColorSchema(settings.Get <ColorSchema>("Schema"), settings.Get("AppTheme", "DeepBlue"));

            SkyContext context = new SkyContext(
                new Date(DateTime.Now).ToJulianEphemerisDay(),
                new CrdsGeographical(settings.Get <CrdsGeographical>("ObserverLocation")));

            progress.Report($"Creating calculators");

            var calculators = calcTypes
                              .Select(c => kernel.Get(c))
                              .Cast <BaseCalc>()
                              .ToArray();

            progress.Report($"Creating event providers");

            var eventProviders = eventProviderTypes
                                 .Select(c => kernel.Get(c))
                                 .Cast <BaseAstroEventsProvider>()
                                 .ToArray();

            progress.Report($"Initializing sky");
            kernel.Get <Sky>().Initialize(context, calculators, eventProviders);

            progress.Report($"Initializing sky map");
            kernel.Get <SkyMap>().Initialize(context, renderers);

            Log.Debug("Application container has been configured.");

            progress.Report($"Initializing shell");

            settings.SettingValueChanged += (settingName, value) =>
            {
                if (settingName == "Schema" || settingName == "AppTheme")
                {
                    SetColorSchema(settings.Get("Schema", ColorSchema.Night), settings.Get("AppTheme", "DeepBlue"));
                }
                else if (settingName == "Language")
                {
                    SetLanguage((string)value);
                }
            };

            foreach (var plugin in plugins)
            {
                plugin.Initialize();
            }
        }
Beispiel #17
0
        private int DayOfYear(SkyContext ctx)
        {
            var date = new Date(ctx.JulianDay);

            return(Date.DayOfYear(date));
        }
Beispiel #18
0
 private CrdsRectangular JupiterMoonShadow_Rectangular(SkyContext c, int m)
 {
     return(c.Get(JupiterMoons_Positions)[m - 1, 1]);
 }
Beispiel #19
0
 private CrdsHorizontal Horizontal(SkyContext ctx, Meteor m)
 {
     return(ctx.Get(Equatorial, m).ToHorizontal(ctx.GeoLocation, ctx.SiderealTime));
 }
Beispiel #20
0
        private double JupiterMoon_CentralMeridian(SkyContext c, int m)
        {
            CrdsRectangular r = c.Get(JupiterMoon_Rectangular, m);

            return(GalileanMoons.MoonCentralMeridian(r));
        }
Beispiel #21
0
 /// <summary>
 /// Gets apparent horizontal coordinates of deep sky object for given instant
 /// </summary>
 private CrdsHorizontal Horizontal(SkyContext c, DeepSky ds)
 {
     return(c.Get(Equatorial, ds).ToHorizontal(c.GeoLocation, c.SiderealTime));
 }
Beispiel #22
0
 private CrdsRectangular SaturnMoon_Rectangular(SkyContext c, int m)
 {
     return(c.Get(SaturnMoons_Positions)[m - 1]);
 }
Beispiel #23
0
 /// <summary>
 /// Gets precessional elements to convert equatorial coordinates of stars to current epoch
 /// </summary>
 private PrecessionalElements GetPrecessionalElements(SkyContext c)
 {
     return(Precession.ElementsFK5(Date.EPOCH_J2000, c.JulianDay));
 }
Beispiel #24
0
 public override void Calculate(SkyContext context)
 {
     context.DayLightFactor = context.Get(DaylightFactor);
 }
 private CrdsEquatorial MarsMoon_Equatorial(SkyContext c, int m)
 {
     return(c.Get(MarsMoon_Equatorial0, m).ToTopocentric(c.GeoLocation, c.SiderealTime, c.Get(Planet_Parallax, Planet.MARS)));
 }
Beispiel #26
0
        private float DaylightFactor(SkyContext c)
        {
            var hSun = c.Get(solarCalc.Horizontal);

            double alt = hSun.Altitude;

            if (alt >= 0)
            {
                var hMoon  = c.Get(lunarCalc.Horizontal);
                var sdSun  = c.Get(solarCalc.Semidiameter);
                var sdMoon = c.Get(lunarCalc.Semidiameter);

                // Angular separation between Sun and Moon disks, in arcseconds
                double delta = Angle.Separation(hSun, hMoon) * 3600.0;

                if (delta < Math.Abs(sdSun - sdMoon))
                {
                    return(0);
                }

                // Solar eclipse (disks are overlapping)
                if (delta <= sdSun + sdMoon)
                {
                    // find overlapping area of two circles
                    // (https://abakbot.ru/online-2/73-ploshhad-peresecheniya-okruzhnostej)

                    double r1 = sdSun;
                    double r2 = sdMoon;
                    double f1 = 2 * Math.Acos((r1 * r1 - r2 * r2 + delta * delta) / (2 * r1 * delta));
                    double f2 = 2 * Math.Acos((r2 * r2 - r1 * r1 + delta * delta) / (2 * r2 * delta));

                    double s1 = r1 * r1 * Math.Sin(f1 - Math.Sin(f1)) / 2;
                    double s2 = r2 * r2 * Math.Sin(f2 - Math.Sin(f2)) / 2;

                    // area of overlapping area
                    double s = s1 + s2;

                    // area of Sun disk
                    double ss = Math.PI * r1 * r1;

                    double percentage = Math.Abs(s / ss);

                    if (percentage <= 0.1)
                    {
                        return((float)(percentage / 0.1));
                    }
                }
            }

            // Absolute value of solar altitude
            // at the end of Nautical twilight / beginning of Astronomical twilight
            const double nightAlt = 12;

            if (alt >= 0)
            {
                return(1);
            }
            else if (alt < 0 && alt > -nightAlt)
            {
                return(1 - (float)(-alt / nightAlt));
            }
            else
            {
                return(0);
            }
        }
        private double MarsMoon_Semidiameter(SkyContext c, int m)
        {
            var distance = c.Get(MarsMoon_Ecliptical, m).Distance;

            return(MartianMoons.Semidiameter(m, distance));
        }
        private ICollection <AstroEvent> CloseApproaches(AstroEventsContext context)
        {
            // resulting collection of events
            List <AstroEvent> events = new List <AstroEvent>();

            // planets ephemeris data for the requested period
            ICollection <PlanetData[]> data = context.Get(PlanetEphemeris);

            // current index in data array
            int day = 0;

            // current calculated value of Julian Day
            double jd = context.From;

            // Time shifts, in days, from starting point to each point in a range to be interpolated
            double[] t = { 0, 1, 2, 3, 4 };

            for (jd = context.From; jd < context.To; jd++)
            {
                // "ad" is a angular distance between two planets (5 points)
                double[] ad = new double[5];

                // p1 is a number of first planet
                for (int p1 = 1; p1 <= 8; p1++)
                {
                    // p2 is a number for second planet
                    for (int p2 = p1 + 1; p2 <= 8; p2++)
                    {
                        // skip Earth
                        if (p1 != 3 && p2 != 3)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                ad[i] = Angle.Separation(data.ElementAt(day + i)[p1].Ecliptical, data.ElementAt(day + i)[p2].Ecliptical);
                            }

                            // If central point has lowest distance, it's a minimum point
                            if (ad[2] < 10 && ad[1] >= ad[2] && ad[2] <= ad[3])
                            {
                                Interpolation.FindMinimum(t, ad, 1e-6, out double t0, out double ad0);

                                // find the exact value of angular distance at extremum point
                                var ctx = new SkyContext(jd - 2 + t0, context.GeoLocation, true);
                                ad0 = Angle.Separation(ctx.Get(planetsCalc.Planet_Ecliptical, p1), ctx.Get(planetsCalc.Planet_Ecliptical, p2));
                                string dist = conjunctionSeparationFormatter.Format(ad0);

                                // magnitude of the first planet
                                string mag1 = Formatters.Magnitude.Format(data.ElementAt(day + 2)[p1].Magnitude);

                                // magnitude of the second planet
                                string mag2 = Formatters.Magnitude.Format(data.ElementAt(day + 2)[p2].Magnitude);

                                events.Add(new AstroEvent(jd - 2 + t0,
                                                          Text.Get("PlanetEvents.CloseApproaches.Text",
                                                                   ("planetName1", GetPlanetName(p1)),
                                                                   ("planetGenitiveName1", GetPlanetGenitiveName(p1)),
                                                                   ("planetMagnitude1", mag1),
                                                                   ("angularDistance", dist),
                                                                   ("planetName2", GetPlanetName(p2)),
                                                                   ("planetGenitiveName2", GetPlanetGenitiveName(p2)),
                                                                   ("planetMagnitude2", mag2))));
                            }
                        }
                    }
                }

                day++;
            }

            return(events);
        }
Beispiel #29
0
 private double Parallax(SkyContext c)
 {
     return(SolarEphem.Parallax(c.Get(Ecliptical).Distance));
 }
Beispiel #30
0
 public CrdsHorizontal Horizontal(SkyContext c)
 {
     return(c.Get(Equatorial).ToHorizontal(c.GeoLocation, c.SiderealTime));
 }