Commit Graph

2245 Commits

Author SHA1 Message Date
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
Don Cross
a6b1963291 Decreased minified JS size from 98382 to 94490 bytes.
I increased the error tolerance slightly for the Jupiter moons model.
This shrank the model tables significantly, giving me some more
breathing room to stay under 100K download size.
2021-04-12 20:53:42 -04:00
Don Cross
7f26aa7c20 JS: Decreased minified browser code from 98413 to 98382 bytes.
I don't like how close I am to my 100K target size, now
that I'm calculating Jupiter's moons.
Simplified the spin() function so its minified code is smaller.
I will look for other things I can shrink too.
2021-04-12 19:27:45 -04:00
Don Cross
a0d88f2f00 JS: Added documentation for JupiterMoons function and return type. 2021-04-12 16:57:22 -04:00
Don Cross
d64a46d5e1 JS: Implemented calculation of Jupiter moons. 2021-04-12 16:19:33 -04:00
Don Cross
1c0c31de20 Removed the Stellarium data I used to verify initial Jupiter Moon implementation. 2021-04-11 20:01:39 -04:00
Don Cross
f879bc51a6 Skip Jupiter Moon model optimization if already calculated.
This will save a lot of time in my local unit tests, but
will verify it isn't broken when I push to GitHub.
2021-04-11 19:27:09 -04:00
Don Cross
5891cfdb5e Jupiter Moons: implemented optimizer that truncates series.
The optimizer makes the Jupiter moons series as short as
possible while keeping error within an acceptable limit.
This should help produce much smaller code, especially
for JavaScript where it really matters.
2021-04-11 17:27:03 -04:00
Don Cross
58c0fe342f Jupiter Moons: added debug prints to get a feel for series frequencies. 2021-04-11 14:45:45 -04:00
Don Cross
2a27673af4 Jupiter moons: keep the last known good generated model in git. 2021-04-11 13:45:24 -04:00
Don Cross
43d05b25bd Jupiter Moons: stubbed the idea of a model optimizer.
I want to experiment with truncating the L1.2 series to
sacrifice some accuracy for smaller generated code.
To that end, I implemented the ability to save the
Jupiter moons model after loading it. I added a 'jmopt'
command to the 'generate' program that will do this
optimization. For now, it just loads the model and
saves it back to a different file. Then the code generator
loads from the saved file instead of the original.
This commit verifies that everything is still working,
before I start truncating the series.
2021-04-11 13:42:23 -04:00
Don Cross
87f5dd1c95 Jupiter Moons: greatly increased JPL Horizons test data coverage.
I want to make sure I have thorough coverage of exercising
the Jupiter moon calculations before I start tinkering
with truncating the L1.2 models; the eventual goal is
to decrease the code size, especially later for JavaScript.
Only 101 test cases seemed far too small. Now there are 5001.

Increased the time range to cover the years 1931..2068.
Decreased the time step from 100 days to 10 days.
Eliminated all but the geometric data, because I'm testing
code without any light-time or aberration correction.

Updated the README.txt instructions for generating the
JPL Horizons test data.
2021-04-11 11:33:17 -04:00
Don Cross
260ef16781 C Jupiter Moons : cleaner generated code.
Output the Jupiter moon model data tables in a tidier format.
Format the amplitudes as fixed-point instead of exponential,
so that the JavaScript minifier will have an easier time
shrinking the data (later, when I get to the JavaScript version).
2021-04-11 10:30:32 -04:00
Don Cross
87cfae4ba0 C Jupiter Moons: added unit test to compare against JPL Horizons data. 2021-04-10 19:58:58 -04:00
Don Cross
9519407212 Made Stellarium comparison tolerances much stricter. 2021-04-10 16:34:20 -04:00
Don Cross
dcbd6fe243 Jupiter moons calculations are now consistent with Stellarium.
I translated the L1.2 FORTRAN code into C, and verified
that the calculations match the Stellarium code I modified
to produce EQJ coordinates. I still need to compare against
JPL Horizons data.
2021-04-10 16:29:10 -04:00
Don Cross
70a9fa5e27 Stubbed the unit test for Jupiter moon calculations.
This is the beginning of a unit test for the new C function
Astronomy_JupiterMoons(). It reads the stellarium file and
can iteratively solve for the ut corresponding to a given tt.
The test "passes" because it doesn't actually check the value
returned by Astronomy_JupiterMoons() yet.
2021-04-09 20:40:23 -04:00
Don Cross
69eb06e6a8 Jupiter Moons: updated data and reference code to generate EQJ.
Instead of calculating ECL coordinates that I will later
have to convert to EQJ, I re-ran all the JPL Horizons test
data sets for EQJ, and updated the rotation matrix in the
Stellarium sample code to generate EQJ output. I'm still
getting reasonably good fit between the two: the max
error is about 1 part in 5000. I was hoping for better,
so I still wonder if I'm just a tiny bit off in some respect.
2021-04-08 21:02:36 -04:00
Don Cross
38a14301e6 Compare Stellarium data with JPL Horizons data for Jupiter's moons.
Stellarium uses the same L1.2 model for Jupiter's moons that
I am implementing. I wanted to confirm that I have valid test
data that matches something authoritative.
2021-04-07 21:00:04 -04:00
Don Cross
5b1671f994 Added JPL Horizons test data for Jupiter's moons state vectors.
The file README.txt contains my instructions for how to reproduce
all of this data using the JPL Horizons online tool.
2021-04-07 17:27:51 -04:00
Don Cross
881664a5f0 C: Stubbed function for calculating Jupiter's moons.
Work in progress.
Generating the data tables for Jupiter's moons, but not using them yet.
Created a stub function Astronomy_JupiterMoons(), but it just
returns invalid vectors. The formulas have not yet been implemented.
2021-04-06 16:42:29 -04:00
Don Cross
c2ccfd33c6 Starting to implement the code generator for Jupiter's moon models.
This is work in progress. Not yet finished.
The code currently just loads the raw data models.
2021-04-06 14:27:47 -04:00
Don Cross
294cf5d14f Merge branch 'master' of https://github.com/cosinekitty/astronomy 2021-04-06 12:57:04 -04:00
Don Cross
df9d962400 Added python demo for calculating lunar days. 2021-04-06 12:56:36 -04:00
Don Cross
e8f4d1091a Script to validate the L1.2 model FORTRAN code for Jupiter's moons. 2021-04-05 15:04:52 -04:00
Don Cross
efc2f0d8cf Capturing some FORTRAN code for Jupiter's moons from ftp.imcce.fr.
I found some FORTRAN code for calculating the positions of Jupiter's
moons. I recorded its origin in README.md. I'm going to experiment
with using it as a basis for doing these calculations in Astronomy Engine.
2021-04-05 14:50:49 -04:00
Don Cross
6b0a966fe7 Tweaks to generating documentation for constants.
Python, C#: sort constants by name.
C#: use horizontal line separators between constants.
C: put a link to the [constants] section.
2021-04-04 21:40:45 -04:00
Don Cross
9b67e7f3f9 Starting development for calculating Jupiter's moons.
I am starting the process of implementing calculation
of Jupiter's four largest moons: Io, Europa, Ganymede, Callisto.
This commit just contains constant declarations for the
equatorial, polar, and volumetric mean radii of Jupiter.

The positions of the moons will be related to the center
of Jupiter and be expressed in Jupiter equatorial radius units,
so I felt it would be good to give users a way to convert to
kilometers, which can in turn be converted to AU.
2021-04-04 20:52:31 -04:00
Don Cross
19aa193dc1 Fixed #95 - automate reporting of minified JavaScript size in documentation
Automatically update the front page README.md to include the current
byte size of astronomy.browser.min.js. Fail the build process if
this file ever grows to 100000 bytes or larger.
2021-04-04 19:49:38 -04:00
Don Cross
6f943d9ea4 Fixed some minor documentation mistakes. JS: Export DEG2RAD, RAD2DEG. npm_2.0.3 2021-04-01 14:08:56 -04:00
Don Cross
bbd16d299a Minor cleanup in Python documentation. 2021-04-01 10:43:37 -04:00
Don Cross
4cc2a14a38 Python docs: provide mechanism for documenting constants.
Python docstrings don't work for variables, so I hacked
a special comment format for helping pydown generate Markdown
text for the README.md for the exported constant KM_PER_AU,
or any other constants I may want to expose in the future.
2021-04-01 09:39:51 -04:00
Don Cross
786afdd4eb Fixed broken link to KM_PER_AU in JavaScript documentation. 2021-03-31 22:42:50 -04:00