Commit Graph

2227 Commits

Author SHA1 Message Date
Don Cross
23eb42f951 Removed unnecessary and risky method EventCollator.Append().
Once a collator has been created, and a caller starts
enumerating events, it does not make sense to be able to add
another enumerator to the collator. So I removed EventCollator.Append().
It was just opening up the possibility of bugs for no good reason.

Client code should decide up front what kind of events it wants
to enumerate and provide a complete list of enumerators.
Then it may use FindFirst/FindNext as many times as it wants
and everything will just work.
2021-05-12 20:36:32 -04:00
Don Cross
953ffef7a8 Calendar demo: added a moon quarter enumerator.
Added MoonQuarterEnumerator, which finds new moon, first quarter,
full moon, and third quarter events.
Changed the calendar start date to May 2021, so it is
more relevant to the time I'm testing it.
2021-05-12 19:54:09 -04:00
Don Cross
04ebd129dd Calendar demo now includes seasons. Also goes for 10 years instead of 1.
Generate solstices and equinoxes in the calendar event enumerator.
Generate 10 years of data instead of 1, to better test the seasons.
2021-05-12 19:37:34 -04:00
Don Cross
03f4e91bb9 Rough demo for how calendar enumerator will work.
This is an example of how multiple enumerators can be combined
into an EventCollator. The collator does the minimum amount
of work to keep searching for one event at a time, while always
emitting them in chronological order.
2021-05-12 19:00:21 -04:00
Don Cross
bba5b0b616 Calendar demo: apparently I don't need astronomy.d.ts for this to work. 2021-05-10 16:37:40 -04:00
Don Cross
398e8115c7 Added the new calendar demo to the JavaScript self-tests. 2021-05-09 21:00:54 -04:00
Don Cross
f299d15fd9 Starting to figure out how to make an Astronomy Engine demo in TypeScript. 2021-05-09 20:57:13 -04:00
Don Cross
1f2444c891 Starting to create a calendar event enumeration demo. 2021-05-09 18:11:00 -04:00
Don Cross
a57f8fc98e Made minified JS browser code a little smaller.
Decreased the minified browser code from 94918 bytes to 94221 bytes.
Did this by using a more efficient encoding of the IAU2000B nutation model:
instead of making {nals:[_], cls:[_]} objects, make lists of lists [[_], [_]].
2021-05-09 15:33:16 -04:00
Don Cross
d414bdda06 Fixed a few security vulnerabilities in the developer tools.
Ran 'npm audit fix' to resolve some security vulnerabilities
in the developer tools in the 'generate' directory.
None of the vulnerabilities affect the npm package
astronomy-engine, because it has no external dependencies.
The risk was only to developers who run the code generation
tools, not end users. Even then, the risk is minimal because
these tools run with well-defined inputs that are not subject
to external tampering.
2021-05-07 20:03:53 -04:00
Don Cross
b81a96cbdc Fixed #100 - Demo of searching for constellation change.
Added Python demo constellation.py that shows how to search
for when a body crosses the border between two constellations.
2021-04-30 20:00:52 -04:00
Don Cross
c7a48093c0 Fixed #101 - Added Python example of searching for lunar angle events with other bodies.
Finished the script demos/python/lunar_angles.py
that shows how to search for times when the Moon and other
solar system bodies reach apparent ecliptic longitude separations
as seen from the Earth.

This is also a good demo of how to perform a custom search
for events using Astronomy Engine. This is the same technique
used internally by Astronomy Engine to search for lunar phases,
eclipses, solstices, etc.
2021-04-28 12:29:01 -04:00
Don Cross
7ef9f71810 Work in progress: Python demo of searching for pair longitudes.
Started work on a Python demo for finding when the moon
reaches relative longitudes with other solar system bodies
that are multiples of 30 degrees. It is not finished yet,
but getting close.

Added operator overloads for the Python Time class so
that times can be compared against each other.
This makes it easier to sort a list of times, for example.
2021-04-27 22:08:24 -04:00
Don Cross
a8a3342a2f Added script pairlon.py to graph the behavior of PairLongitude functions.
This script will help me figure out how to tune the search algorithm
I'm about to write for searching for times that a pair of bodies
reach a given relative apparent ecliptic longitude.
2021-04-26 14:00:40 -04:00
Don Cross
d45bb771ac Python: Replaced LongitudeFromSun with more general PairLongitude. 2021-04-24 21:55:54 -04:00
Don Cross
a53e83d4af JS: Replaced LongitudeFromSun with more general PairLongitude. 2021-04-24 21:36:47 -04:00
Don Cross
2cf6419792 C#: Replaced LongitudeFromSun with more general PairLongitude. 2021-04-24 21:18:03 -04:00
Don Cross
a74e89bd24 Added C function Astronomy_PairLongitude.
This function is a generalization of Astronomy_LongitudeFromSun,
which it replaces. It calculates the relative ecliptic longitude of one body
with respect to another body, as seen from the Earth.

After implementing the same function in C#, JavaScript,
and Python, I will come back and create a generalized
search algorithm to find the next time two bodies are
at a given apparent relative longitude. Even though this
is a generalization of SearchRelativeLongitude, I will have
to figure out a more general way of tuning the search.
2021-04-24 19:52:33 -04:00
Don Cross
4f23e85524 Fixed #108 - Fail the build if C function, #define, enum, or typedef lacks documentation. 2021-04-23 20:54:09 -04:00
Don Cross
95b45d427d Removed Travis CI, added GitHub actions badge. 2021-04-21 21:01:37 -04:00
Don Cross
56d08a7370 Less verbose JupiterMoonTruncate. 2021-04-21 20:36:16 -04:00
Don Cross
06fc6651f8 One more tweak to diffcalc error thresholds for GitHub Actions. 2021-04-21 20:32:58 -04:00
Don Cross
c5b05f84d9 More changes for GitHub actions.
The test build failed because diffcalc reported a small
discrepancy between the C and C# output.
So I made the threshold more lenient for now.
I want to come back later and figure out if I can get back
to exact agreement between C and C# code.

Told wget not to output rediculous progress bar stuff
that eats thousands of lines of log output.
2021-04-21 20:09:52 -04:00
Don Cross
c23affd28c First attempt at doing a GitHub Actions test build for Astronomy Engine. 2021-04-21 19:40:42 -04:00
Don Cross
31ff4acc1e Experimenting with GitHub Actions as a replacement for Travis CI. 2021-04-21 19:27:30 -04:00
Don Cross
0e1f8dbdc2 Check all fgets() in C tests for partial line reads.
I ran into a problem recently that was confusing to debug.
It turned out that I was calling fgets() providing a line buffer
that was not long enough for all of the lines in the input file.
This caused the unread portion of the long line to appear as if
it were the beginning of another line, failing the test in
a weird way.

So I replaced all calls to fgets() in ctest.c with a new
wrapper function ReadLine(). It checks for this issue
and immediately aborts with a helpful diagnostic.
2021-04-21 13:34:04 -04:00
Don Cross
6d3f27cd4c Added diffcalc testing for Jupiter's moons: position and velocity vectors.
This test verifies that the calculations of Jupiter's moons
are consistent across C, C#, JavaScript, and Python.
2021-04-21 13:06:44 -04:00
Don Cross
ab32f548e8 Diffcalc: scale topocentric distances based on minimum distance to Earth. 2021-04-20 19:06:32 -04:00
Don Cross
932573ac2d More fixes needed for diffing calculations among languages.
It turns out different Node.js versions do math differently,
which caused a Travis CI build failure.

Scale topocentric distance the same way I scale heliocentric distance.
Adjusted diffcalc bash script and diffcalc.bat Windows batch file accordingly.

The differ now prints the final "score" so I'm less likely to make
a mistake spotting the correct maximum difference.

Removed unused variable in ctest.c DiffLine(): maxdiff.
2021-04-20 18:51:36 -04:00
Don Cross
1e2c24208c Fixed #103 - Scale body vector differences by orbital radius.
When comparing calculations of body vectors, scale
the size of the difference by the minimum orbital
radius (or typical radius in the case of the Solar
System Barycenter).

This concludes my investigations of discrepancies between
the various language calculations. I have done as much
as I can without implementing my own trig functions,
which is not worth the effort (or the loss of efficiency
in JavaScript).

Scaling the errors relative the measurement units reveals
that the discrepancies are reasonable for the 16-digit
precision one expects from 64-bit floating point numbers.
The worst case is C vs JavaScript, with a scaled error
of about 7.2e-15. I can live with that.
2021-04-20 17:23:29 -04:00
Don Cross
ce0290b7f6 diffcalc: Divide angular errors by their range of values.
A given amount of error in an angle measured in
sidereal hours is 15 times more important than the
same numeric error in an angle measured in degrees.
Scale angular errors by the range of values they
could take on. Longitude-like angles in degrees
have a range of 360, while latitude-like angles
range over 180 degrees (-90 to +90).

Split out separate Windows batch file diffcalc.bat,
just like I already split out bash script diffcalc.
2021-04-20 16:25:02 -04:00
Don Cross
ebade6c4c2 Updated Windows build to run diff checker with tolerance passed in.
Now that the Linux build process passes in a different
tolerance value for each of the diff checks, I updated
the Windows build accordingly.
2021-04-20 15:30:54 -04:00
Don Cross
e0a01a85fb Updated issue 103 tests for C and Python. 2021-04-19 21:49:51 -04:00
Don Cross
ed54fb9fc1 diffcalc: Generate PY and JS output in 18 digits of scientific notation. 2021-04-19 21:08:29 -04:00
Don Cross
13168d9839 C and C# are now producing identical check output!
I was able to get the diffcalc test to confirm that
the C and C# algorithms are producing absolutely identical
output values. I just needed to make the C code print its
output in scientific notation with 18 significant figures.
2021-04-19 20:27:57 -04:00
Don Cross
fe743affd4 Fixed bug in ctest(diff): was not even looking at helio z values.
All along, ctest(diff) has been treating the "v" lines as
v x y z
instead of
v tt x y z
and ignoring the z values. Fixed that. It was a relief
it didn't reveal any lurking problems in the z values.

Also, dramatically decreased the disagreement measured between the
C and C# code just by printing out more decimal places in both.

First  file: temp/c_check.txt
Second file: dotnet/csharp_test/csharp_check.txt
Tolerance = 5.600000e-17
            lnum                 a_value                 b_value   factor       diff  name
  OK        9269  4.3776373521942023e-05  4.3776373521942017e-05  1.00000  6.776e-21  helio_x
  OK        5589 -4.3623354680948618e-05 -4.3623354680948625e-05  1.00000  6.776e-21  helio_y
  OK         606 -4.3091817463880202e-05 -4.3091817463880195e-05  1.00000  6.776e-21  helio_z
  OK      199595 -2.5752073258047489e-05 -2.5752073258047493e-05  1.00000  3.388e-21  sky_j2000_dec

----------------------------------------------------------------------------------------------------

First  file: temp/c_check.txt
Second file: temp/js_check.txt
Tolerance = 1.200000e-12
            lnum                 a_value                 b_value   factor       diff  name
  OK      388830  1.0342029871624860e+01  1.0342029871624890e+01  1.00000  3.020e-14  helio_x
  OK       67200 -2.9057622338509663e+00 -2.9057622338509423e+00  1.00000  2.398e-14  helio_y
  OK       67200 -4.3874295048838763e-01 -4.3874295048837719e-01  1.00000  1.044e-14  helio_z
  OK      282864  4.2562907944628900e+00  4.2562907944628821e+00  0.94021  7.516e-15  sky_j2000_ra
  OK      333852 -9.3967798183388087e+00 -9.3967798183388513e+00  1.00000  4.263e-14  sky_j2000_dec
  OK      151220  3.0052362065237119e+01  3.0052362065237109e+01  1.00000  1.066e-14  sky_j2000_dist
  OK      123271  8.3934732121148897e+01  8.3934732121147533e+01  0.83370  1.137e-12  sky_hor_az
  OK      123271 -3.3519630572770836e+01 -3.3519630572771831e+01  1.00000  9.948e-13  sky_hor_alt

----------------------------------------------------------------------------------------------------

First  file: temp/c_check.txt
Second file: temp/py_check.txt
Tolerance = 5.100000e-14
            lnum                 a_value                 b_value   factor       diff  name
  OK          22 -2.5294053992874876e-01 -2.5294053992874882e-01  1.00000  5.551e-17  helio_x
  OK          29 -3.3385318243368106e-01 -3.3385318243368112e-01  1.00000  5.551e-17  helio_y
  OK          22  3.7850398890096215e-01  3.7850398890096221e-01  1.00000  5.551e-17  helio_z
  OK      135350  2.3433972116724325e-01  2.3433972116724319e-01  1.00000  5.551e-17  sky_j2000_ra
  OK         603  4.5414554731189877e-01  4.5414554731189882e-01  1.00000  5.551e-17  sky_j2000_dec
  OK         490  4.2751511640162104e-01  4.2751511640162099e-01  1.00000  5.551e-17  sky_j2000_dist
  OK       49066  3.2035956679701377e+02  3.2035956679701371e+02  0.88694  5.042e-14  sky_hor_az
  OK       49066 -2.7508172411136329e+01 -2.7508172411136300e+01  1.00000  2.842e-14  sky_hor_alt

----------------------------------------------------------------------------------------------------

First  file: temp/js_check.txt
Second file: temp/py_check.txt
Tolerance = 1.200000e-12
            lnum                 a_value                 b_value   factor       diff  name
  OK      388830  1.0342029871624890e+01  1.0342029871624860e+01  1.00000  3.020e-14  helio_x
  OK       67200 -2.9057622338509423e+00 -2.9057622338509663e+00  1.00000  2.398e-14  helio_y
  OK       67200 -4.3874295048837719e-01 -4.3874295048838757e-01  1.00000  1.038e-14  helio_z
  OK      282864  4.2562907944628821e+00  4.2562907944628900e+00  0.94021  7.516e-15  sky_j2000_ra
  OK      333852 -9.3967798183388513e+00 -9.3967798183388087e+00  1.00000  4.263e-14  sky_j2000_dec
  OK      151220  3.0052362065237109e+01  3.0052362065237119e+01  1.00000  1.066e-14  sky_j2000_dist
  OK      123271  8.3934732121147533e+01  8.3934732121148897e+01  0.83370  1.137e-12  sky_hor_az
  OK      123271 -3.3519630572771831e+01 -3.3519630572770836e+01  1.00000  9.948e-13  sky_hor_alt

----------------------------------------------------------------------------------------------------
2021-04-19 19:57:21 -04:00
Don Cross
3da6839fc1 More nuanced numerical comparison of output for different languages.
For angular results that are longitude-like, the severity
of the error decreases as the location approaches the
poles of that coordinate system. So scale the longitude
difference by the cosine of the latitude.

For example, in horizontal coordinates, the closer an object
is to the zenith, the less significant an error in its azimuth
becomes. At the zenith, azimuth loses all meaning.

Also, now we pass in the tolerance on the command line, because
there are known issues for each language. I expect C# and C
to be in very close agreement, and I want to know if they start
drifting apart. However, JS has known issues with atan2(), so I'm more
lenient with C vs JS.

Now track and report max difference independently for each
type of calculated value, instead of merging them all
together in one big soup.
2021-04-19 19:17:47 -04:00
Don Cross
cbcacc4b57 Improved agreement of precision among the 4 supported languages.
Before making these changes, I had the following discrepancies
between the calculations made by the different programming
language implementations of Astronomy Engine:

    C vs C#: 5.55112e-17, worst line number = 6
    C vs JS: 2.78533e-12, worst line number = 196936
    C vs PY: 1.52767e-12, worst line number = 159834

Now the results are:

    Diffing calculations: C vs C#
    ctest(Diff): Maximum numeric difference = 5.55112e-17, worst line number = 5

    Diffing calculations: C vs JS
    ctest(Diff): Maximum numeric difference = 1.02318e-12, worst line number = 133677

    Diffing calculations: C vs PY
    ctest(Diff): Maximum numeric difference = 5.68434e-14, worst line number = 49066

    Diffing calculations: JS vs PY
    ctest(Diff): Maximum numeric difference = 1.02318e-12, worst line number = 133677

Here is how I did this:

1. Use new constants HOUR2RAD, RAD2HOUR that directly convert between radians and sidereal hours.
   This reduces tiny roundoff errors in the conversions.

2. In VSOP longitude calculations, keep clamping the angular sum to
   the range [-2pi, +2pi], to prevent it from accumulating thousands
   of radians. This reduces the accumulated error in the final result
   before it is fed into trig functions.

The remaining discrepancies are largely because of an "azimuth amplification" effect:
When converting equatorial coordinates to horizontal coordinates, an object near
the zenith (or nadir) has an azimuth that is highly sensitive to the input
equatorial coordinates. A tiny change in right ascension (RA) can cause a much
larger change in azimuth.

I tracked down the RA discrepancy, and it is due to a different behavior
of the atan2 function in C and JavaScript. There are cases where the least
significant decimal digit is off by 1, as if due to a difference of opinion
about rounding policy.

My best thought is to go back and have a more nuanced diffcalc that
applies less strict tests for azimuth values than the other calculated values.
It seems like every other computed quantity is less sensitive, because solar
system bodies tend to stay away from "poles" of other angular coordinate
systems: their ecliptic latitudes and equatorial declinations are usually
reasonably close to zero. Therefore, right ascensions and ecliptic longitudes
are usually insensitive to changes in the cartesian coordinates they
are calculated from.
2021-04-18 21:15:17 -04:00
Don Cross
6b01510b33 Fixed #99 - Export the AngleBetween function for outside callers. 2021-04-16 20:18:25 -04:00
Don Cross
6f379397e8 Fixed #102 - generate more compact constellation boundary tables.
This change has no effect on client-facing behavior.
It just makes the internal data tables for the array of
constellation appear more compact in C, C#, and Python.
This is what the TypeScript/JavaScript code was already doing.
2021-04-16 19:43:14 -04:00
Don Cross
8b3e06994c Fixed #67 - Calculate position and velocity vectors of Jupiter's moons. npm_2.0.4 2021-04-15 21:10:38 -04:00
Don Cross
90a9f56375 Bumped npm package version to 2.0.4. 2021-04-15 21:00:40 -04:00
Don Cross
5a8daba7d5 Added Python demo of calculating Jupiter's moons.
The demo shows how to correct for light travel
time to render Jupiter's moons as they appear
from the Earth.

Created an addition operator for the Vector
class in the Python code, because it is handy.

Corrected a bug in the string representation
of the Python StateVector class.
2021-04-15 20:54:37 -04:00
Don Cross
1e2763af63 Finished defining Jupiter moon radii constants.
Now there are constants for the mean radii of Jupiter's
four major moons available in the C, C#, Python, and JavaScript
versions of Astronomy Engine.

Clarified that these are all mean radii.

Fixed some lingering "//" comments in the C code
(I want to keep ANSI C code as portable as possible.)
2021-04-15 13:20:55 -04:00
Don Cross
4f681919fb Python: defined constants for the radii of Jupiter's 4 largest moons.
To assist software that wants to depict Jupiter and its 4 major moons
as they would appear in a telescope, it is important to know their
physical sizes. I already had constants for Jupiter's equatorial
and polar radii. Here I add constants for the radii of the moons
Io, Europa, Ganymede, and Callisto. They are all nearly spherical,
so a single mean radius value is sufficient.
2021-04-15 12:39:33 -04:00
Don Cross
17900adcb2 Python Markdown generator: eliminate spurious warnings.
My pydown.py custom Markdown generator was printing bogus
warnings about unknown symbol types, when it was actually
generating correct documentation for those symbols.

Eliminated the warnings, and improved the output format
for global constant documentation: no more extraneous spaces.

If there really is an undocumented symbol detected, fail the build!
Don't just print a warning that slides up the screen unnoticed.
2021-04-15 08:47:13 -04:00
Don Cross
a3734bc60b Fixed #105 - Added functions to calculate a time object from TT.
Now callers can create time objects from either UT (UT1/UTC civil time)
or ephemeris/dynamical Terrestrial Time (TT). The new TT functions
numerically solve to find the UT that produces the given TT based
on the Delta-T value at that UT. This is always a very fast
numerical convergence, because TT and UT are almost perfectly
linear over brief time windows.
2021-04-14 19:42:03 -04:00
Don Cross
ef42841592 PY: Finished implementation of JupiterMoons function. 2021-04-14 06:41:24 -04:00
Don Cross
c080f15613 Windows build process: fixed compiler errors and test errors.
Some errors crept into the build process on Windows.
It's been a while since I ran everything on Windows;
I do my main development on Linux.
2021-04-13 16:33:21 -04:00
Don Cross
4f7a6e69cb C#: Implemented calculation of Jupiter's moons. 2021-04-13 11:45:03 -04:00