I noticed on a freshly-cloned Astronomy Engine on Windows,
I started getting JavaScript test failures. The problem was the
script generate/test.js had an inconsistent way of reading text
from files and splitting it into lines. Some of the tests
did not account for \r\n line endings in Windows text files.
So I created a unified approach: a new function ReadLines
that works correctly for Linux and Windows, regardless
of the variant line endings.
This may not work on Mac OS, but I don't have an easy
way of testing that myself. But at least now I can fix
issues like that in one place.
I'm trying to make it easier for first-time visitors to
this project to find the source code and documentation
to get started quickly. Moved directories that are only
used by contributors (mostly myself) out of the root
and into the 'generate' directory where they are less
distracting.
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.
The reason SSB vector errors were larger than other bodies
is because the Sun/Barycenter relationship does not have
position and velocity vectors of a "typical" size.
The distance of a planet from the SSB is fairly constant,
and the speed a planet travels is fairly constant.
Therefore, comparing errors by dividing by the magnitude
of the correct vector usually makes sense for scaling.
But for the barycentric Sun (or the heliocentric SSB),
the magnitude of the vectors can become arbitrarily small,
nearly zero in fact, resulting in surprisingly large ratios.
I compensated for this in all the tests by adding a new rule.
When the error thresholds r_thresh and v_thresh are negative,
it is a flag that indicates they are absolute, not relative.
In other words, r_thresh < 0 indicates that abs(r_thresh) is
the maximum number of astronomical units allowed in position
errors, and v_thresh < 0 specifies maximum AU/day.
This results in more consistent numbers that give confidence
the errors are indeed very small and not worth worrying about.
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.
In the C unit test for barystate, heliostate, and topostate,
I had switched from checking absolute differences to relative
differences. I forgot to do that in the other 3 languages
until now. They are all working consistently in how they
measure calculation errors.
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.
Made the internal data structure for the C version of barystate
use named fields in a struct for Sun...Neptune, instead of
an array. This makes the C code look more like the other 3
language implementations. I am going to experiment with adding
more bodies to see if it helps accuracy, and this makes the
code easier to modify for that experiment.
Instead of measuring absolute state vector position/velocity
errors, measure them relatively by dividing by the magnitude
of the scalar length of the correct vectors. This gives a better
feel for how much error each calculation contains.
In the process, I discovered that the barycentric Sun calculation
is off by more than 1 percent, which is surprising and deserves
more attention. I wonder if including the inner planets would
make it more accurate?
The unit test uses two JPL Horizons data sets: the center of
the Earth as seen from the surface of the Earth, and the
Earth/Moon Barycenter (EMB) as seen from the surface of the Earth.
Simplified the C unit tests for barystate and heliostate
so they use common code for parsing the JPL Horizons
data files. The only thing really different about them
is which function is called to compare against the state
vectors in the files. Pass in a pointer to a context.
Right now the context just contains a pointer to a function
to call, but later it may contain other parameters if needed.
I am starting to work on a function to find the position
and velocity vectors for an observer on the surface of the Earth.
I created the C function Astronomy_ObserverState(), but I don't
yet have a unit test for it.
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.
The function ParseArgs (used by many of the C demo programs)
now allows an alternative command line usage. If the '-e'
option is specified, it looks for the environment variable setting:
ASTRONOMY_ENGINE_OBSERVER='latitude longitude'
This form allows the demo programs to be configured for a given site.
Now the C 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).
Astronomy_BaryState() now supports body == BODY_EMB.
Added a new function Astronomy_GeoEmbState() to calculate
the geocentric state for the EMB.
Both have been verified using test data generated by JPL Horizons.
I wanted to test the geocentric Moon state vector I
calculate for the sake of the Moon state relative to
the Solar System Barycenter (SSB). Because the geocentric
portion has such a small magnitude, I decided to go ahead
and expose GeoMoonState as part of the API, and create
a test for it specifically. I used JPL Horizons to generate
the test file GeoMoon.txt.
The C function Astronomy_BaryState() now supports BODY_MOON.
Because of the complexity of the CalcMoon() function, I ended
up calculating two positions close together in time, and
using dr/dt to estimate the velocity vector.
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!
A slight difference (7.9e-17) in calculation now exists between
the C and C# horizontal angle calculations on Windows.
This is not surprising because the atan2() function is
known to return slightly different values on other
compilers/platforms. Adjusted the tolerance for this tiny
amount of roundoff discrepancy.
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.
The Pluto gravity simulator constants now come from
a single source: pluto_gravsim.h. This will allow me
to experiment with the Pluto state table to get a better
compromise between size and accuracy.
Reworked the Pluto gravity sim constants so they are defined
in one place: a new header file gravsim/pluto_gravsim.h.
Then the code generator writes the #defines to the C code, instead
of having two independent versions of the same constants.
I will continue down the road of having a single-source-of-truth
for these constants across all 4 supported languages.
Also, confusingly, I had one constant called PLUTO_DT in codegen.c
that was called PLUTO_TIME_STEP in astronomy.c. Also, astronomy.c
had a different constant PLUTO_DT that didn't mean the same thing.
I reworked the naming to be consistent in all places.
I already had a TopPosition() function that knows how to calculate
exact equatorial coordinates, so I eliminated the redundant logic
from gravsim_test.c
While I'm tinkering with Pluto gravsim algorithms in C,
I don't want to fail the unit tests that compare it against
the original gravsim algorithm in JavaScript, C#, and Python.
So I turned that part off for now. I will have to take this
back out when they are all unified again.
Significantly decreased the calculation error:
0.20 arcmin to 0.12 arcmin in my test metric.
However, the amount of extra work may not be
worth the accuracy, compared to just stepping more
increments between the segments, or simply making
more segments in the first place.
As they say in government-funded academia,
"more research is needed."
I have gravsim_test.c to the point where it calculates a
standard deviation of error between TOP2013 and Astronomy Engine
for calculating the position of Pluto over 10 worst-case samples.
My baseline is now 0.205303 arcminutes of heliocentric position error.
For Runge-Kutta (or some other method) to be an improvement, it
has to beat that score without incurring significant extra work
or larger memory consumption.
I updated gravsim_test.c to calculate the Pluto model
at every (exact) state table entry, and every halfway point.
I compare it against (exact) TOP2013 calculations.
As expected, the errors alternate between 0 and nonzero.
I'm interested in understanding drift error calculation
between the known-correct state waypoints for Pluto's orbit.
I'm trying to figure out whether there is some unintended
asymmetry between the forward calculation and the reverse
calculation. I will likely have to compare against TOP2013
data for the major planets, because I am using truncated
VSOP87, which also introduces position errors.
I should also validate TOP2013 versus VSOP87, both
untruncated, for Jupiter..Neptune, which they both cover.
I'm trying to get a better feel for the amount of error
in my gravity simulator calculations for the movement of Pluto.
Added conditionally-compiled code to log state vectors calculated
in the forward and reverse time directions, along with the
exact endpoints that frame the interpolated values.
Also log errors measured between both directions.
There is a curious asymmetry in the first case I tried
(roughly the years 2000..2100), where the forward calculation
seems less accurate than the reverse calculation.
For bodies other than the Sun, Moon, or Saturn, the
C function Astronomy_Illumination calls an internal function
VisualMagnitude. If VisualMagnitude is passed an invalid body,
it returns an error code. Astronomy_Illumination was not checking
for an error code. In the case of being passed a pseudo-body
like BODY_SSB (the Solar System Barycenter) or BODY_EMB
(the Earth/Moon Barycenter), VisualMagnitude is called and
returns the error ASTRO_INVALID_BODY. Astronomy_Illumination was
ignoring the error and returning ASTRO_SUCCESS to the caller,
even though the magnitude was NAN (the "not a number" value).
Note that other invalid bodies than EMB and SSB would not
cause this problem, because the earlier call to HelioVector
would fail and be noticed.
I added unit tests that confirmed this bug, then made fixes
to the code so that the unit tests pass.
I confirmed this same problem does NOT exist in the Python,
JavaScript, or C# versions of Astronomy Engine. In all
the other languages, this case causes VisualMagnitude to
throw an exception, so no error checking is needed in the
Illumination functions.
Tonight as I was walking outside, I saw a fairly bright
star about half a degree away from the edge of the Moon.
I wondered what it was, so I decided to write a quick
program to find out.
This Python demo program scans the HYG Database
(https://github.com/astronexus/HYG-Database)
to find which bright stars are within a small angular
distance of the Moon, as seen at a given time, latitude, and longitude.
It turns out the star I saw was Nunki (Sigma Sagittarii).
It was handy to do vector subtraction to implement this program,
and it was trivial to do in the Python code's Vector class,
so I went ahead and added that.