Commit Graph

276 Commits

Author SHA1 Message Date
Don Cross
94eabbd4a9 C#: Adding missing checks for unexpected search failures.
There were a few more places where C# code called
Search() but did not check for a search failure.
Throw InternalError exceptions if these ever occur,
because these particular searches should always succeed.
2022-04-05 13:22:50 -04:00
Don Cross
d7e86fae52 C#: Search cleanup, add InternalError exception.
Added an InternalError class to explicitly indicate
that an exception occurs due to an internal assertion
failure inside Astronomy Engine. Any InternalError
should be considered a bug in Astronomy Engine, not
a bug in calling code.

Upon reviewing the code for searching moon phases,
I discovered that there was inconsistent behavior
in SearchMoonPhase. It was sometimes returning null,
other times throwing an exception. Because the caller
passes in `limitDays`, it makes sense to simply
return `null` in any case where the search fails.
This is to support callers that intentionally want
to find whether or not a moon phase occurs in a given
small window of time.

Updated internal callers of SearchMoonPhase to throw
an InternalError when they know they should always
find an event.

Internal function FindSeasonChange did not check to
make sure SearchSunLongitude succeeded. There is no
known case where this failure happens, but if it did,
a null AstroTime would have been stored in SeasonsInfo.
It is better to fail early with an explicit InternalError.

Other miscellaneous C# code cleanup.

In the Python code, I found a couple of `raise Error`
that needed to be changed to `raise InternalError`.
2022-04-05 12:30:13 -04:00
Don Cross
10bb3f30de Kotlin: implemented seasons search.
Implemented the following related functions in Kotlin:

    sunPosition
    searchSunLongitude
    seasons

C#: fail Astronomy.Seasons with an exception if any of the
equinox/solstice searches fail. If this ever happens, it is
an internal error. It should not be the burden of the caller
to check for nulls!  Fixed mistake in documentation for
searchSunLongitude.
2022-04-03 20:02:11 -04:00
Don Cross
075a80fde8 Kotlin: Implemented Astronomy.search.
Implemented the low-level search function that will be used
to implement all the special-purpose search functions to come.

Added missing documentation to class NodeEventInfo members.

Minor cleanup in the C# function `Astronomy.Search`:
- removed an unused output parameter.
- deleted confusing sentence in documentation.
2022-04-03 10:37:12 -04:00
Don Cross
9d6294d7fe Miscellaneous documentation fixes.
While working on the Kotlin implementation, I have
found a few documentation mistakes in the other language
implementations. These have been accumulating in the
`kotlin` branch. I migrated these changes back into
the released code for now, because I don't want to wait
until Kotlin is ready.
2022-04-02 16:52:54 -04:00
Don Cross
6ea35232d8 Updated C# readme based on changes in C# docstring. 2022-04-02 15:28:05 -04:00
Don Cross
e879a67be7 Kotlin: Added constellation function. 2022-04-02 15:17:14 -04:00
Don Cross
3c2f8c0cc9 Kotlin: rotationEqjHor, rotationHorEqj.
Added two more rotation functions.

Corrected a typo in the documentation for Rotation_HOR_EQJ
in the other 4 languages.
2022-04-01 19:19:24 -04:00
Don Cross
397c259bc6 Kotlin: Jupiter's moons.
Implemented Kotlin functions and code generator
for calculating the state vectors of Jupiter's
largest 4 moons.

Added cautionary comments about needing to correct
Jupiter's moons for light travel time.

This is the first pass to get everything needed
for the AstroCheck tests. I tried comparing
C output to Kotlin output, and there are some
serious problems to debug:

    $ ./ctest diff 2.8e-16 temp/{c,k}_check.txt
    First  file: temp/c_check.txt
    Second file: temp/k_check.txt
    Tolerance = 2.800e-16

                lnum                 a_value                 b_value     factor       diff  name
    FAIL      137746  4.2937184148112564e+01  4.2944101081740065e+01    0.03364  2.327e-04  helio_x
    FAIL      373510  1.4197190315274938e+01  1.4193716564905307e+01    0.03364  1.168e-04  helio_y
    FAIL      137746 -6.5897675150466091e+00 -6.5929481589493522e+00    0.03364  1.070e-04  helio_z
    FAIL       59150  1.8035183339348251e+01  1.8035909197904104e+01    0.01730  1.255e-05  sky_j2000_ra
    FAIL      137747 -8.1222057639092533e+00 -8.1250990689970894e+00    0.00556  1.607e-05  sky_j2000_dec
    FAIL      137747  4.8436159305823310e+01  4.8441487614058218e+01    0.03481  1.855e-04  sky_j2000_dist
    FAIL      322846  8.7596368704201495e+01  2.6760770774700188e+02    0.00278  4.995e-01  sky_hor_az
    FAIL      405828 -6.5075824596574279e+01  5.6922941329250996e+01    0.00556  6.778e-01  sky_hor_alt
      OK       92717  4.1268347083494783e-03  4.1268347083494774e-03  223.21429  1.936e-16  jm_x
      OK       45091 -8.0149190392649894e-03 -8.0149190392649929e-03   79.42812  2.756e-16  jm_y
      OK      135377  1.5470777280065808e-03  1.5470777280065804e-03  223.21429  9.680e-17  jm_z
      OK      216836  4.5725777238332412e-03  4.5725777238332394e-03  126.58228  2.196e-16  jm_vx
      OK      351647  5.1351566793199944e-03  5.1351566793199962e-03  126.58228  2.196e-16  jm_vy
      OK      351647  2.5217607180929289e-03  2.5217607180929298e-03  126.58228  1.098e-16  jm_vz

    Score = 6.778e-01
    ctest(Diff): EXCEEDED ERROR TOLERANCE.

So I'm checking this in as work-in-progress.
2022-03-30 22:49:22 -04:00
Don Cross
9d38dac2f1 Kotlin: Gravity simulator, Pluto calculation.
Added calculation of heliocentric and barycentric
state vectors for Pluto. This is done using
a gravity simulator that treats Pluto as a negligible
mass that is affected by the major masses of the
Solar System: Sun, Jupiter, Saturn, Uranus, Neptune.

Updated the code generator to write the Kotlin
version of the Pluto state table, a lookup table
of known-correct state vectors of Pluto at long
intervals, derived from the TOP2013 model.

The gravity simulator interpolates state vectors
of Pluto between these known-correct states.

Minor code style cleanup in the Kotlin source.

Fixed a possible thread-safety issue in the C# code.
2022-03-29 19:22:40 -04:00
Don Cross
044ecfb774 Kotlin: VSOP87 position, velocity vectors.
Implemented the VSOP87 calculation functions for
heliocentric position vectors, heliocentric velocity vectors,
and heliocentric distances.
Implemented Astronomy.helioVector for everything except Pluto and SSB.

Corrected small errors in C# documentation.
2022-03-28 12:33:01 -04:00
Don Cross
2d5ef05536 Kotlin: implemented geocentric Moon.
Implemented the Montenbruck/Pfleger version of the NAO1954
geocentric Moon model in Kotlin.

In the process, code review helped simplify parts of the C# code.
I may want to go back and see if I can simplify the CalcMoon
code in the other languages too.
2022-03-27 20:39:43 -04:00
Don Cross
a96c8358b9 Kotlin: Added Astronomy.rotationAxis().
Added the rotationAxis, which calculates dynamic orientation
of planet, Sun, and Moon rotation axes. Added the first
unit test that verifies against JPL Horizons data.

Eliminated more redundant time parameters in precession functions.

More cleanup of C# code: I realized the private function
vector2radec was redundant with the public function EquatorFromVector.
Deleted vector2radec.
2022-03-26 20:42:14 -04:00
Don Cross
bec202ba37 Kotlin: added nutation matrix/vector functions.
Added functions for generating rotation matrices,
rotating position vectors, and rotating state vectors,
for the Earth's axial nutation.

Simplified gyration functions in C#:
it turns out the `time` parameters were redundant,
because time is included in the `t` field of the vector
passed in. I reworked the C# code to eliminate those time
parameters.

The Kotlin code follows suit.
2022-03-26 13:40:52 -04:00
Don Cross
62405be175 Kotlin: Convert observer <==> state vector.
Implemented the functions `terra` and `inverseTerra`.

`terra` converts geographic coordinates and time into
a geocentric state vector.

`inverseTerra` converts a position vector and time
into geographic coordinates.

I realized the C# function `inverse_terra` could be
simplified. It does not need to be passed a separate
time, because the sidereal time can be derived
from, or has already been stored inside, the vector's
time field `ovec.t`.

There were a couple of other minor cleanups to the C# code.
2022-03-26 11:51:36 -04:00
Don Cross
9b4223193b Kotlin: sidereal time
Implemented Astronomy.siderealTime() in Kotlin.

Updated all languages' unit tests for sidereal time
to verify exact conformity between them, rather than
to an externally derived value. I wanted to make
sure all languages, including Kotlin, are calculating
the exact same value.

I don't need an external authoritative test for
sidereal time, because it will be indirectly tested
through its involvement in thousands of other calculations
that depend on it. I just need a quick sanity check
before implementing those other things that depend on it.
2022-03-26 02:07:15 -04:00
Don Cross
6cb7ab7cce Kotlin: added constants and massProduct function. 2022-03-25 18:28:51 -04:00
Don Cross
8c923d49d6 Kotlin: added more data types.
Ported the following types to the Kotlin code:

    GlobalSolarEclipseInfo
    EclipseEvent
    LocalSolarEclipseInfo
    TransitInfo
    ShadowInfo
    IllumInfo
    AxisInfo
    NodeEventKind
    NodeEventInfo

Made some wording fixes in the documentation for the
other languages.
2022-03-25 15:52:27 -04:00
Don Cross
b8fc1bc975 Fixed #177 - Incorrect text in Python documentation for enum EclipseKind. 2022-03-24 20:35:30 -04:00
Don Cross
f0c4eb05db Kotlin: Ported some more data types.
Ecliptic
Topocentric
SeasonsInfo
MoonQuarterInfo
LibrationInfo
HourAngleInfo
ElongationInfo
ApsisKind
ApsisInfo
EclipseKind
LunarEclipseInfo
2022-03-24 20:17:14 -04:00
Don Cross
40e0fb7b4f Kotlin: Another batch of functions ported.
Converting between radians and degrees.
Clamping angles to a desired range of degrees.
Converting between vector, spherical, horizontal.
Refraction and inverse refraction.
2022-03-23 17:21:37 -04:00
Don Cross
b0929b1b49 Kotlin: added rotation matrix functions and unit tests.
Implemented most of the RotationMatrix functions.
Added unit tests for combining rotation matrices, using a
rotation matrix to rotate a vector, and pivoting a rotation
matrix around its axes.

Replaced AstroVector operator '*' with infix function 'dot',
because it removes ambiguity between vector dot products
and vector cross products.
Later I will add a 'cross' infix function too.

Corrected minor typo in documentation for Python, C, C#, JavaScript.
"trasnform" -> "transform"
2022-03-23 14:25:32 -04:00
Don Cross
79d66bb00b Kotlin: added a few more type definitions.
StateVector
JupiterMoonsInfo
RotationMatrix
Spherical
Observer
EquatorEpoch
Aberration
Refraction
Direction
Visibility
Equatorial
2022-03-22 20:52:07 -04:00
Don Cross
8fd8d7b624 Kotlin AstroTime: millisecond resolution, ISO 8601
Allow floating point values for seconds when initializing
an AstroTime from (year, month, ..., seconds).
AstroTime can now represent date/time to millisecond resolution.

Represent AstroTime strings in ISO 8601 format:
yyyy-mm-ddThh:mm:ss.sssZ

Minor docstring fixes.

Rename target file to 'astronomy.kt'.
2022-03-21 13:28:49 -04:00
Don Cross
0943f058c9 Fixed #165 - expose sidereal time function.
There was already an internal function for calculating
Greenwich Apparent Sidereal Time (GAST). By request,
I have exposed this function for outside users.

Added a minimal unit test to verify the function is
callable and returns the correct result for one case.
This function is already exhaustively tested by unit
tests that verify other functions that already called
this function when it was internal, so minimal testing
is sufficient in this case.
2022-03-15 20:48:02 -04:00
Don Cross
d843775122 Fixed #148 - calculate Lagrange points.
Added the following new functions to all 4 languages:

MassProduct: find the GM product for all Solar System bodies.

LagrangePoint: calculate L1..L5 state vectors for a pair of bodies.

LagrangePointFast: calculate L1..L5 state vectors given
state vectors and GM products of a pair of bodies.
2022-03-13 20:56:32 -04:00
Don Cross
b773834349 Implemented Python Lagrange point calculation. 2022-03-13 17:47:40 -04:00
Don Cross
eba8c2e87f Implemented JavaScript Lagrange point functions. 2022-03-12 20:31:07 -05:00
Don Cross
45dbdd87d4 Implemented C# Lagrange point functions. 2022-03-12 17:08:56 -05:00
Don Cross
871389c9cf Fixed C# .NET Framework 4 compile error.
There is no function double.IsFinite() in .NET Framework.
Reworked the sanity check in Astronomy.Pivot so the C# code
builds in these older .NET platforms.
2022-02-21 10:54:01 -05:00
Don Cross
19007ebfd5 JS EclipticGeoMoon, SearchMoonNode, NextMoonNode. 2022-02-06 16:11:24 -05:00
Don Cross
eb5cc8ea9a C# EclipticGeoMoon, SearchMoonNode, NextMoonNode.
Implemented the C# versions of these functions.
Ported the unit tests from C to C# to validate them.
2022-02-06 12:57:51 -05:00
Don Cross
e4b2911c97 Clarify GeoMoon and GeoMoonState calculating EQJ.
Changed the documentation for the GeoMoon and GeoMoonState
functions to make it explicit that they calculate coordinates
oriented with respect to the Earth's J2000 equator (EQJ).
This is because I will soon add ecliptic (ECL) counterparts
for the GeoMoon function, to more directly search for ascending
and descending nodes of the Moon.
2022-02-03 19:43:18 -05:00
Don Cross
90a9839d18 Optimize for map-making calculation patterns.
See this discussion:
https://github.com/cosinekitty/astronomy/issues/150

For the case of calculating a map, where each pixel
on the map represents a different location on the Earth,
it is more efficient to factor out expensive calculation
of sidereal times, assuming the entire map represents
some phenomenon at a single moment in time.

For example, to determine whether the Moon is visible
at different places on the Earth, the following
functions can be calculated across thousands of
different (lat, lon) geographic coordinates around
the world:

    ObserverVector
    Rotation_EQD_HOR

Before iterating over the map pixels, a program
can call GeoMoon, then convert EQJ coordinates to EQD.

Then by passing the same time value in a loop to
ObserverVector and Rotation_EQD_HOR, the program
can calculate a vector from the observer to the Moon
in EQD coordinates, then convert EQD to HOR.
The z-coordinate of the horizontal coordinates
determines whether the Moon is above or below the
observer's horizon at that point on the Earth.

This calculation pattern performed redundant
sidereal time calculations for each pixel on the map.
I changed the code for all 4 languages to cache
sidereal time so that it only needs to be calculated
once.

In the C version of Astronomy Engine, this resulted
in a speedup factor of about 2.3 in the above use case.
(See the function MapPerformanceTest in generate/ctest.c.)
2022-01-22 20:47:46 -05:00
Don Cross
15d1312060 Made Jupiter rotation matrix code gen one digit shorter.
This is another attempt to get consistent generated code
between Linux and macOS.
2022-01-07 21:38:41 -05:00
Don Cross
1ace122c9e Consistent generated tables between Linux, macOS.
The code generator was creating slightly different numeric
values for the Pluto state tables and the Jupiter rotation matrix.
I decreased the output precision by one decimal digit.
This should allow the code generator to produce identical
source code on both Linux and macOS.
2022-01-07 21:02:59 -05:00
Don Cross
b2f9219b56 Updated copyrights for 2022. 2022-01-04 18:55:20 -05:00
Don Cross
210319d407 Python documentation fixes.
The documentation for the Python function `SearchAltitude`
was missing a mention of the `altitude` parameter.
I searched for similar mistakes in Python, C#, and C,
having just completed the same exercise in the JavaScript code.

I also found several places where extraneous newlines
between the parameter documentation caused the Markdown
to be rendered incorrectly.
2021-12-10 20:32:43 -05:00
Don Cross
f994d8d04c Fixed #141 - Upgrade C# code to .NET 6.
Now that Microsoft has officially released .NET 6,
I have upgraded the C# version of Astronomy Engine to use it.
No source code changes were needed. I just bumped the
version number in the project files, and targeted .NET 6
in the GitHub Actions continuous integration tests.
Fixed some obsolete wording in generate/README.md.
2021-12-07 17:06:04 -05:00
Don Cross
945e70a98f Fixed #106 - Calculate rotation axis of Sun, Moon, and planets. 2021-12-07 15:31:54 -05:00
Don Cross
c36f16e1be PY RotationAxis function. 2021-12-02 16:11:50 -05:00
Don Cross
df518aeb84 Implemented C# RotationAxis. Improved C RotationAxis docs. 2021-11-30 22:12:34 -05:00
Don Cross
d02039c78f Trying to make it easier for newcomers to find the code.
I'm concerned that a first-time visitor to the Astronomy Engine
repo on GitHub will get lost. I made it more obvious where to
quickly find the source code needed for a given language.
2021-11-23 20:43:17 -05:00
Don Cross
6b744edd71 Completed implementation of ObserverState.
Fixed a few lingering issues in the documentation of
the C# version of the ObserverState function.
This completes the implementation across all 4 languages.

ObserverState calculates the position vector of a point
on the surface of the Earth, and the velocity vector
of that point, both relative to the center of the Earth.
2021-11-19 22:15:02 -05:00
Don Cross
7e2b0a73eb C# ObserverState
Implemented the C# version of the ObserverState function.
This returns the geocentric position and velocity for
a point on the Earth's surface at a given time.
2021-11-19 17:30:52 -05:00
Don Cross
295221339c C# HelioState: calculates heliocentric position and velocity.
This is the C# version of a new function HelioState to
calculate heliocentric state vectors (position and velocity).
2021-11-15 19:37:26 -05:00
Don Cross
19f157e71c Full support for geocentric and barycentric EMB.
Now the Python version of Astronomy Engine supports calculating
the Earth/Moon Barycenter (EMB) state vector (position and velocity)
relative to the Earth's center (geocentric) or relative
to the Solar System Barycenter (SSB).

This completes support for this feature across C, C#, JavaScript, and Python.
2021-11-14 11:54:57 -05:00
Don Cross
e4f9e68630 C#: Calculate state vectors for barycentric/geocentric moon, EMB. 2021-11-13 23:29:07 -05:00
Don Cross
71cb92df08 Calculate barycentric state of Pluto.
The BaryState function did not support Pluto before.
Refactored the code so that the internal CalcPluto function
returns both the position and velocity, and its caller
can select from heliocentric or barycentric coordinates.
HelioVector asks for heliocentric coordinates and keeps
only the position vector. BaryState asks for barycentric
coordinates and returns both position and velocity.

I added test data for Pluto generated by JPL Horizons.
It turns out the Pluto system barycenter is the best fit
for TOP2013, presumably because Charon causes Pluto to
wobble quite a bit.

I also generated JPL Horizons test data for the Moon
and the Earth/Moon barycenter, anticipating that I will
support calculating their barycentric state vectors soon.

I had to increase the enforced size limit for minified
JavaScript from 100000 bytes to 120000 bytes.
I guess this is like raising the "debt ceiling".

Fixed a bug in Python unit tests: if "-v" verbose option
was specified, it was printing a summary line for every
single line of input, instead of a single summary after
processing the whole file, as was intended. This is one
of those Python whitespace indentation bugs!
2021-11-13 16:07:00 -05:00
Don Cross
4e6cb282f5 Use original Pluto gravsim with finer time steps.
I'm getting much better accuracy sticking with my original
gravity simulator, just with smaller time increments, than
I was with the Runge-Kutta 4 method. The PlutoStateTable
gets a bit larger (51 state vectors instead of 41), but the
accuracy is so much higher.

Removed the Runge-Kutta code because I won't be going back to it.
2021-11-12 16:22:14 -05:00