SharpAstrology.SwissEph
0.5.2
dotnet add package SharpAstrology.SwissEph --version 0.5.2
NuGet\Install-Package SharpAstrology.SwissEph -Version 0.5.2
<PackageReference Include="SharpAstrology.SwissEph" Version="0.5.2" />
<PackageVersion Include="SharpAstrology.SwissEph" Version="0.5.2" />
<PackageReference Include="SharpAstrology.SwissEph" />
paket add SharpAstrology.SwissEph --version 0.5.2
#r "nuget: SharpAstrology.SwissEph, 0.5.2"
#:package SharpAstrology.SwissEph@0.5.2
#addin nuget:?package=SharpAstrology.SwissEph&version=0.5.2
#tool nuget:?package=SharpAstrology.SwissEph&version=0.5.2
SharpAstrology.SwissEph - Ephemerides for SharpAstrology
About
This package provides an implementation of the IEphemerides interface from SharpAstrology.Base. It attempts to mimic the behavior of the C library swisseph (version 2.10.3).
SharpAstrology Packages
| Package | Description | Licence |
|---|---|---|
| SharpAstrology.Base | Base library | MIT |
| SharpAstrology.SwissEph | Ephemerides package based on SwissEphNet | AGPL-3.0 |
| SharpAstrology.Symbols.BlazorComponents | Astrological symbols as Blazor components | MIT |
| SharpAstrology.HumanDesign | Extensions for the Human Design system | MIT |
| SharpAstrology.HumanDesign.BlazorComponents | Human Design charts as Blazor components | MIT |
| SharpAstrology.Vedic | Extensions for Vedic astrology systems | MIT |
| SharpAstrology.Vedic.BlazorComponents | Vedic astrology charts as Blazor components | MIT |
| SharpAstrology.West | Extensions for western astrology systems | MIT |
| SharpAstrology.West.BlazorComponents | Western astrology charts as Blazor components | MIT |
| SharpAstrology.WebApp | Blazor Server app built on the SharpAstrology packages | AGPL-3.0 |
Install
dotnet add package SharpAstrology.SwissEph
Tests
Run dotnet test Tests/SharpAstrology.SwissEph.Tests.csproj -c Release with the .NET 10 SDK or later. The suite includes 2,000 reference cases generated from the original Swiss Ephemeris C library, covering positions and velocities with Swiss files and Moshier.
Set SWISSEPH_EPHE_PATH to a directory containing sepl_18.se1 and semo_18.se1, or place them in an ephe directory above the test output. These data files are not bundled. The fixtures in Tests/TestData record the source and data hashes; the Python scripts in Tests/tools regenerate the fixtures or compare revisions against a local C checkout.
Simple usage
using System.Text.Json;
using SharpAstrology.Enums;
using SharpAstrology.Ephemerides;
using SharpAstrology.Interfaces;
// Use Moshier, so you don't need the swiss eph files or JPL files
var ephemeridesService = new SwissEphemeridesService(ephType: EphType.Moshier);
// Calculate positional information for Sun, Moon and Venus on January 1st 2024
//
// Use UTC time or it will throw
var pointInTime = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc);
using (IEphemerides eph = ephemeridesService.CreateContext())
{
var sunPosition = eph.PlanetsPosition(Planets.Sun, pointInTime);
Console.WriteLine(JsonSerializer.Serialize(sunPosition));
// {
// "Longitude":280.0390123591898,
// "Latitude":0.00016036961321834312,
// "Distance":0.9833183562567887,
// "SpeedLongitude":1.0189783966864485,
// "SpeedLatitude":-3.780307931918674E-05,
// "SpeedDistance":-1.1317598853344111E-05
// }
var moonPosition = eph.PlanetsPosition(Planets.Moon, pointInTime);
Console.WriteLine(JsonSerializer.Serialize(moonPosition));
// {
// "Longitude":155.9922487287969,
// "Latitude":3.567636008224304,
// "Distance":0.0027048134096186458,
// "SpeedLongitude":11.848401014998416,
// "SpeedLatitude":-0.7336498562140658,
// "SpeedDistance":4.901106714722023E-06
// }
var venusPosition = eph.PlanetsPosition(Planets.Venus, pointInTime);
Console.WriteLine(JsonSerializer.Serialize(venusPosition));
// {
// "Longitude":242.6123495376748,
// "Latitude":1.9498137075115765,
// "Distance":1.1819079026603012,
// "SpeedLongitude":1.2159947235695916,
// "SpeedLatitude":-0.029584567802327894,
// "SpeedDistance":0.006288212288100938
// }
// Calculate house cusp longitudes in the porphyrius system for location London
var houseCusps = eph.HouseCuspPositions(pointInTime, 51.509865, -0.118092, HouseSystems.Porphyrius);
Console.WriteLine(houseCusps.Cross[Cross.Asc]);
// 187,07504557640635
Console.WriteLine(houseCusps.Cross[Cross.Mc]);
// 99,22014310543506
Console.WriteLine(houseCusps.HouseCusps[Houses.House1]);
// 187,07504557640635
}
// Calculate sidereal position for Mars with Lahiri ayanamsa
using (IEphemerides eph = ephemeridesService.CreateContext(Ayanamsas.Lahiri))
{
var marsPosition = eph.PlanetsPosition(Planets.Mars, pointInTime, EphCalculationMode.Sidereal);
Console.WriteLine(JsonSerializer.Serialize(marsPosition));
// {
// "Longitude":243.11750614191982,
// "Latitude":-0.5505163268692346,
// "Distance":2.423806754147523,
// "SpeedLongitude"::0.7413840351773113,
// "SpeedLatitude":-0.009739411236392903,
// "SpeedDistance":-0.00303531177482181
// }
}
EphCalculationMode.Sidereal applies to every supported object, the lunar nodes and the
astrological Earth included. For all of them the sidereal longitude is the tropical longitude
minus the ayanamsa. The latitude and the distance stay untouched, and the longitude speed
differs by the proper motion of the ayanamsa alone.
Use swiss eph files or JPL files for more precision
Follow the instruction from the original swisseph project and download the files you want. Than save to files into a folder and use the path to that folder in the SwissEphemeridesService constructor.
using SharpAstrology.Ephemerides;
using SharpAstrology.Interfaces;
SwissEphemeridesService ephemeridesService;
// for swiss eph files
ephemeridesService = new SwissEphemeridesService(rootPathToEph: "[PATH_TO_SWISSEPH_ROOT_FOLDER]", EphType.Swiss);
using (IEphemerides eph = ephemeridesService.CreateContext())
{
// calculate positions here
}
// for JPL files
ephemeridesService = new SwissEphemeridesService(rootPathToEph: "[PATH_TO_JPL_ROOT_FOLDER]", EphType.Jpl);
using (IEphemerides eph = ephemeridesService.CreateContext())
{
// calculate positions here
}
A JPL folder should hold the swiss eph files as well. A JPL kernel contains the main
bodies only, so asteroids like Chiron are always read from the seas files, which is
what the original C library does too.
Fail instead of silently losing precision
By default a missing .se1 file makes the calculation fall back to Moshier for that
body, matching the C library. Applications that must not compute with a weaker source
behind the user's back can switch that off. A missing file then throws a
FileNotFoundException naming the expected path, and a missing folder throws a
DirectoryNotFoundException. House cusps and angles need no files at all and keep
working either way.
ephemeridesService = new SwissEphemeridesService(
rootPathToEph: "[PATH_TO_SWISSEPH_ROOT_FOLDER]",
ephType: EphType.Swiss,
allowMoshierFallback: false);
Note that the mean lunar node is implemented by the Moshier mean element series only. Without the Moshier fallback, only the true node is available.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- SharpAstrology.Base (>= 0.13.0)
- System.Numerics.Tensors (>= 10.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
0.5.2: Correct lunar light time and frame bias, true-node coordinate output, positions without Speed, and planetary velocities. Implement topocentric and Speed3 three-position velocities. Add 2,000 C-reference cases for Swiss files and Moshier.