AstroCalc 0.9.5
See the version list below for details.
dotnet add package AstroCalc --version 0.9.5
NuGet\Install-Package AstroCalc -Version 0.9.5
<PackageReference Include="AstroCalc" Version="0.9.5" />
<PackageVersion Include="AstroCalc" Version="0.9.5" />
<PackageReference Include="AstroCalc" />
paket add AstroCalc --version 0.9.5
#r "nuget: AstroCalc, 0.9.5"
#:package AstroCalc@0.9.5
#addin nuget:?package=AstroCalc&version=0.9.5
#tool nuget:?package=AstroCalc&version=0.9.5
๐ญ AstroCalc
A .NET 9 library for astronomical calculations โ from Julian dates to sunsets, planetary positions to eclipses.
โจ Overview
AstroCalc implements classical computational astronomy formulas in a modern, strongly-typed, immutable .NET library. Every algorithm is referenced to its original source and verified against published almanac data.
using AstroCalc.Core;
using AstroCalc.SolarSystem;
using AstroCalc.Time;
// ๐
Calculate sunrise and sunset for Rome, Italy
var rome = GeographicCoordinate.FromDms(41, 54, 0, 12, 29, 0, 37);
var result = SunriseSunset.Calculate(2026, 3, 8, rome);
var (hRise, mRise) = SunriseSunset.ToHoursMinutes(result.Sunrise);
var (hSet, mSet) = SunriseSunset.ToHoursMinutes(result.Sunset);
Console.WriteLine($"Sunrise: {hRise}:{mRise:D2} UT");
Console.WriteLine($"Sunset: {hSet}:{mSet:D2} UT");
// ๐ Moon position
var jd = JulianDate.FromCalendar(2026, 3, 8);
var moon = LunarPosition.Calculate(jd);
Console.WriteLine($"Moon: ฮป={moon.Position.Longitude.Degrees:F2}ยฐ, distance={moon.DistanceKm:F0} km");
// ๐ญ Can I see M42 tonight?
var report = VisibilityPlanner.CheckMessier(42, 2026, 1, 15, rome, telescopeApertureMm: 200);
Console.WriteLine(report); // โ
M42: EXCELLENT โ alt 41ยฐ, Moon 120ยฐ away
๐ฆ Project structure
AstroCalc/
โโโ ๐ src/AstroCalc/
โ โโโ Core/ # Foundation types: Angle, GeographicCoordinate, SexagesimalConverter
โ โโโ Time/ # Julian dates, sidereal time, Easter date
โ โโโ Coordinates/ # Coordinate systems and transformations
โ โโโ Corrections/ # Precession, nutation, aberration, refraction, parallax
โ โโโ SolarSystem/ # Sun, Moon, planets, Jovian moons, Saturn rings, comets
โ โโโ Phenomena/ # Eclipses, conjunctions, oppositions, Moon phase info
โ โโโ Optics/ # Telescope calculations, visual magnitude, Bortle scale
โ โโโ Observation/ # Observing session planning, rise/transit/set, dark sky windows
โ
โโโ ๐งช tests/AstroCalc.Tests/ # 127 xUnit tests verified against almanac data
๐งฎ Namespaces and classes
AstroCalc.Core โ Foundation types
| Class | Description |
|---|---|
Angle |
Immutable value type: degrees, radians, DMS, HMS with arithmetic operators and trigonometry |
GeographicCoordinate |
Observer latitude, longitude and elevation |
SexagesimalConverter |
Sexagesimal โ decimal conversions |
AstroCalc.Time โ Calendar and time
| Class | Description |
|---|---|
JulianDate |
Julian Day Number โ calendar conversions (Gregorian reform handled) |
SiderealTime |
Greenwich and local mean sidereal time |
Easter |
Easter date computation (Meeus Ch.9) |
AstroCalc.Coordinates โ Celestial coordinates
| Class | Description |
|---|---|
EquatorialCoordinate |
Right ascension and declination |
EclipticCoordinate |
Ecliptic longitude and latitude |
HorizontalCoordinate |
Azimuth and altitude |
GalacticCoordinate |
Galactic coordinates (l, b) |
CoordinateTransform |
Transformations between all coordinate systems |
AstroCalc.Corrections โ Atmospheric and geometric corrections
| Class | Description |
|---|---|
Precession |
Precession of the equinoxes (Lieske 1979) |
Nutation |
Nutation in longitude and obliquity |
Aberration |
Annual aberration of starlight |
Refraction |
Atmospheric refraction (Sรฆmundsson/Bennett formula) |
Parallax |
Geocentric โ topocentric parallax correction |
AstroCalc.SolarSystem โ Sun, Moon and planets
| Class | Description |
|---|---|
SolarPosition |
Solar coordinates (low and medium precision), equation of time |
SunriseSunset |
Sunrise, sunset, twilight (civil, nautical, astronomical) |
LunarPosition |
Lunar position and phase |
PlanetaryPosition |
Geocentric positions for all planets (MercuryโNeptune) |
PlanetaryMagnitude |
Visual magnitude of planets from phase angle and distance |
JovianMoons |
Positions of Galilean satellites (Io, Europa, Ganymede, Callisto) |
SaturnRings |
Ring tilt, position angle, and apparent dimensions |
CometPosition |
Position from parabolic, elliptical, or hyperbolic orbital elements |
AstroCalc.Phenomena โ Observable events
| Class | Description |
|---|---|
Eclipse |
Solar and lunar eclipse prediction |
PlanetaryPhenomena |
Elongations, oppositions, conjunctions |
MoonPhaseInfo |
Phase name, lunar age, illumination, next phase dates |
AstroCalc.Optics โ Telescope and visual calculations ๐ฌ
| Class | Description |
|---|---|
Telescope |
Magnification, exit pupil, FOV, limiting magnitude, Dawes/Rayleigh limits, light-gathering power |
VisualMagnitude |
Pogson's law, combined magnitudes, airmass, atmospheric extinction, surface brightness, Bortle scale |
AstroCalc.Observation โ Observing session planning ๐
| Class | Description |
|---|---|
RiseTransitSet |
Rise, transit, and set times for any celestial object, the Sun, or Moon |
ObservingWindow |
Dark sky window, Moon interference assessment, sky quality rating |
VisibilityPlanner |
"Can I See It Tonight?" โ combines horizon, darkness, Moon, airmass, and telescope limits |
MonthlyPlanner |
Best objects for any month โ deep-sky, doubles, meteor showers, and lunar features |
AstroCalc.Catalogs โ Built-in object databases ๐
| Class | Description |
|---|---|
MessierCatalog |
All 110 Messier objects with coordinates, magnitude, size, type, and constellation |
BrightStarCatalog |
50 brightest named stars with J2000.0 coordinates and proper motion |
DoubleStarCatalog |
36 notable double/multiple stars with separation, PA, magnitudes, and color notes |
MeteorShowerCatalog |
16 major meteor showers with radiant coords, ZHR, active periods, parent bodies |
LunarFeatureCatalog |
45 lunar features (craters, maria, mountains, rilles) with selenographic coordinates |
ConstellationIdentifier |
Identify constellation from RA/Dec; all 88 IAU constellations with names and meanings |
AstroCalc.Coordinates โ Additional features
| Class | Description |
|---|---|
EpochConverter |
Proper motion correction and epoch conversion (J2000.0 โ any date) |
AstroCalc.Time โ Additional features
| Class | Description |
|---|---|
TimeZoneHelper |
UT โ local time conversion with DST support for US and EU |
๐ Quick start
Prerequisites
Build and test
# Clone the repository
git clone https://github.com/<your-username>/AstroCalc.git
cd AstroCalc
# Build
dotnet build
# Run all tests
dotnet test
# Run a single test
dotnet test --filter "MathcadExample_MmtObservatory_19880115"
Use in your project
# Add as a project reference
dotnet add reference path/to/AstroCalc.csproj
๐ References
The implemented formulas come from four classical texts in computational astronomy:
๐ Jean Meeus โ Astronomical Formulae for Calculators (3rd ed., Willmann-Bell, 1985)
The primary reference for most algorithms. Chapters used:
| Chapter | Topic | AstroCalc class |
|---|---|---|
| Ch. 7 | Julian Day Number | JulianDate |
| Ch. 9 | Easter date | Easter |
| Ch. 12 | Sidereal time | SiderealTime |
| Ch. 13 | Coordinate transformations | CoordinateTransform |
| Ch. 16 | Atmospheric refraction | Refraction |
| Ch. 17 | Angular separation | CoordinateTransform.AngularSeparation |
| Ch. 21 | Precession | Precession |
| Ch. 22 | Nutation | Nutation |
| Ch. 23 | Aberration | Aberration |
| Ch. 25 | Solar coordinates | SolarPosition |
| Ch. 31โ36 | Planetary positions | PlanetaryPosition |
| Ch. 33โ34 | Comet positions from orbital elements | CometPosition |
| Ch. 40 | Parallax | Parallax |
| Ch. 41 | Planetary visual magnitudes | PlanetaryMagnitude |
| Ch. 47 | Lunar position | LunarPosition |
| Ch. 48 | Lunar phase | LunarPosition.Phase |
| Ch. 49 | Lunar phases (new/full moon) | Eclipse |
| Ch. 54 | Eclipses | Eclipse |
| Ch. 44 | Galilean satellite positions | JovianMoons |
| Ch. 45 | Saturn ring geometry | SaturnRings |
๐ U.S. Naval Observatory โ Almanac for Computers
Algorithm for computing sunrise, sunset and twilight times. Implemented via a Mathcad worksheet (Ch. 3 โ Astronomical Phenomena) that includes a verified worked example:
MMT Observatory, Arizona โ 31ยฐ41'18" N, 110ยฐ53'06" W, 2608 m
Date: January 15, 1988
Computes sunrise, sunset and all three twilight types with observer elevation correction.
๐ W.M. Smart โ Textbook on Spherical Astronomy (6th ed., Cambridge University Press, 1977)
Reference for spherical trigonometry and coordinate system transformations:
- Ch. 2โ3: Equatorial โ ecliptic โ horizontal โ galactic transformations
- Ch. 4: Precession of the equinoxes
- Ch. 5: Annual and diurnal aberration
๐ H. Karttunen et al. โ Fundamental Astronomy (3rd ed., Springer, 2003)
Supporting reference for modern theory and updated astronomical constants.
๐ ๏ธ Technology stack
| Technology | Role |
|---|---|
| Target framework | |
| Language (record structs, pattern matching, primary constructors) | |
| Test framework (127 tests) | |
| AI assistant for code and test generation |
๐ค Built with GitHub Copilot CLI
This project was entirely designed and implemented with GitHub Copilot CLI (powered by Claude), which:
- ๐ Analyzed the astronomy textbook PDFs to extract formulas and algorithms
- ๐๏ธ Designed the library architecture (6 namespaces, 24 classes)
- ๐ป Generated all source code and tests
- โ Verified results against published almanac data
- ๐ Iterated to fix compilation errors and failing tests
๐ Accuracy
| Calculation | Typical accuracy | Method |
|---|---|---|
| Julian dates | Exact | Meeus Ch.7 |
| Solar coordinates (low) | ~1' | USNO |
| Solar coordinates (medium) | ~0.01ยฐ | Meeus Ch.25 |
| Sunrise/sunset | ยฑ2 min | USNO Almanac |
| Lunar position | ~10' lon, ~3' lat | Meeus Ch.47 (simplified) |
| Planetary positions | ~1โ2' | Truncated VSOP87 |
| Coordinate transforms | ~0.01ยฐ | Rigorous spherical trigonometry |
๐ฏ Design principles
- Immutability โ all value types are
readonly structorrecord struct - Pure functions โ no side effects, easy to test
- Strong typing โ
Angleinstead ofdoubleto prevent degree/radian confusion - Fully referenced โ every algorithm cites the chapter and equation from the original source
doubleprecision โ sufficient for arc-second accuracy
๐ License
This project is licensed under the MIT License.
๐ Acknowledgements
- Jean Meeus for his foundational collections of astronomical algorithms
- U.S. Naval Observatory for the sunrise/sunset algorithm
- GitHub Copilot CLI for assistance in design and implementation
<p align="center"> <i>โญ If you find this library useful, please give it a star!</i> </p>
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v0.9.5 โ Initial public preview
โข Core: Angle, GeographicCoordinate, SexagesimalConverter
โข Time: JulianDate, SiderealTime, Easter, TimeZoneHelper
โข Coordinates: Equatorial/Ecliptic/Horizontal/Galactic transforms, EpochConverter
โข Corrections: Precession, Nutation, Aberration, Refraction, Parallax
โข SolarSystem: Sun, Moon, 8 planets, comets, Jovian moons, Saturn rings, magnitudes
โข Phenomena: Eclipses, Moon phases, planetary elongations
โข Optics: Telescope calculations, visual magnitude, Bortle scale
โข Observation: Rise/Transit/Set, ObservingWindow, VisibilityPlanner, MonthlyPlanner
โข Catalogs: 110 Messier, 50 bright stars, 36 double stars, 16 meteor showers, 45 lunar features, 88 constellations
โข 186 unit tests