Commit Graph

98 Commits

Author SHA1 Message Date
Don Cross
898276e130 Update copyrights, move AstroTime notes to correct file, copyediting. 2024-05-26 16:30:43 -04:00
Don Cross
2915cd9118 Improved contributor source editing experience by improved code generator markers.
I suddenly realized today that I could eliminate lots of red wavy
lines in the source editor when working on generate/template/astronomy.*
files, by tweaking the $ASTRO_... tokens to look like comments.
For some reason, I didn't think of doing this before now.
I was motivated by the Go language support, where the tokens were
breaking `go fmt`.
2023-10-04 21:03:21 -04:00
Don Cross
63ed3746b2 Misc fixes for Raspberry Pi 4 build.
On the Raspberry Pi 4, using latest versions of cppcheck
and pylint, a few more minor fixes were needed for eliminating
warnings.

Also had to soften a tolerance for the Kotlin unit tests.
2023-06-19 16:28:34 -04:00
Don Cross
cd8f9e9f4c Improved Python table for Jupiter moon models.
Updated the code generator so the Python version of
the Jupiter moon tables has better type checking
and is easier to understand.
2023-02-21 12:17:35 -05:00
Don Cross
23b45dd075 Improved Pluto state table in Python code.
The generated code for the Pluto state table in Python
now uses a class `_pstate` for better type checking.
It also makes the code easier to understand.
Moved class _TerseVector higher in the source file to
reduce the need for quoted forward type declarations.
2023-02-21 10:56:05 -05:00
Don Cross
a530069e99 Improved Python VSOP table generation.
The VSOP table generator for Python now is now
better type-checked using classes and tuples.
This also makes the code easier to understand.
2023-02-21 10:12:45 -05:00
Don Cross
f849c11258 Require type hints for all Python functions.
I added the mypy option `--disallow-untyped-defs` to fail
any function lacking complete type hints.
Then I fixed all the resulting errors.

I ended up changing the Python code generator to create
some tuple types instead of list, because it is possible
to write stricter type checks that way. This was in
the Pluto and Jupiter Moon tables.
I still should come back and do the same thing for the VSOP tables.

The type checking revealed a couple of places where I wasn't
checking for a search failure. I fixed those too.
2023-02-20 20:04:10 -05:00
Don Cross
62192357ba Updated copyrights for 2023.
Windows build process now updates copyright
years just like the Linux build process does.
Ran it to update the copyright years for 2023.
2023-01-07 17:13:07 -05:00
Don Cross
8a153315cf Simplified and optimized nutation formula.
While trying to convert ecliptic coordinates from mean
equinox of date to true equinox of date, I ran into excessive
overhead from the IAU2000B nutation model. The fact that it
uses 77 trigonometric terms made the calculations a lot slower.

https://apps.dtic.mil/sti/pdfs/AD1112517.pdf
Page 4 in the above document mentions a shorter series
“NOD version 2” that has 13 terms instead of 77 as used in IAU2000B.
I had not noticed NOD2 before, because it appears only in
the FORTRAN version of NOVAS 3.x, not the C version.

After reading the FORTRAN code, I realized NOD2 is the same
as IAU2000B, only it keeps the first 13 of 77 terms.
The terms are already arranged in descending order of
significance, so it is easy to truncate the series.

Based on this discovery, I realized I could achieve all of
the required accuracy needed for Astronomy Engine by
keeping only the first 5 terms of the nutation series.
This tremendously speeds up nutation calculations while
sacrificing only a couple of arcseconds of accuracy.

It also makes the minified JavaScript code smaller:
Before: 119500 bytes.
After:  116653 bytes.

So that's what I did here. Most of the work was updating
unit tests for accepting slightly different calculation
results.

The nutation formula change did trigger detection of a
lurking bug in the inverse_terra functions, which convert
a geocentric vector into latitude, longitude, and elevation
(i.e. an Observer object). The Newton's Method loop in
this function was not always converging, resulting in
an infinite loop. I fixed that by increasing the
convergence threshold and throwing an exception
if the loop iterates more than 10 times.

I also fixed a couple of bugs in the `demotest` scripts.
2022-12-04 10:31:15 -05:00
Don Cross
84621b4d33 Enable truncation of the IAU2000B nutation model.
Modified the code generator and source templates to allow
using fewer than 77 terms from the IAU2000B nutation model.
The number of terms causes calculations to be far slower than
I would  like, plus most of these terms provide far less than
one arcsecond of difference in the output.

I want to experiment with truncated versions of the series.

https://apps.dtic.mil/sti/pdfs/AD1112517.pdf
Page 4 in the above document references a shorter series
"NOD version 2" that has only 13 terms instead of 77 as used in IAU2000B.
I found that code and confirmed the 13 terms are the first 13
consecutive terms from the original 77.

This commit does not change the number of terms calculated;
it only enables doing so by changing a single #define in
generate/codegen.c.

Once I change the nutation model, I'm sure there will be multiple
tweaks to unit tests to get everything working again.
2022-12-03 21:29:59 -05:00
Don Cross
e879a67be7 Kotlin: Added constellation function. 2022-04-02 15:17:14 -04:00
Don Cross
503e31b0d9 Kotlin code style: remove semicolons, underscores. 2022-03-31 08:28:53 -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
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
490b5dee5c Kotlin: Generating VSOP87 model source code.
Added code generator for VSOP87 major planet models in Kotlin.
Added a lookup function for VSOP87 models to Kotlin template.
Moved IAU2000b delcaration outside class Astronomy.
2022-03-27 06:02:21 -04:00
Don Cross
9772ea9f47 Kotlin: starting precession and nutation.
Implemented the iau2000b nutation formula.
Implemented calculation of the precession
rotation matrix.

This is the very first use of a code generator
macro for the Kotlin code.  I am going to try
keeping all these macros toward the bottom
of the source tepmlate, so that as I look at
line numbers for compiler errors, they will match
between the target code and the template code.

I may go back and rework the other languges to
do this also. I'm not sure why I didn't think
of this before!
2022-03-25 21:00:11 -04: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
a5fd814ba1 Finished single-source-of-truth for Pluto constants.
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.
2021-11-12 15:30:56 -05:00
Don Cross
813bbf1c8e Pluto gravity sim: refactor constants for sharing.
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
2021-11-12 15:14:56 -05: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
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
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
d64a46d5e1 JS: Implemented calculation of Jupiter moons. 2021-04-12 16:19:33 -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
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
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
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
d776c3d453 Enabled --strict option in TypeScript compiler. Fixed resulting errors.
Improved the type checking by using tsc --strict.
Nothing substatial changed in the generated JavaScript, and no
actual bugs were found, but I removed a lot of loose/sloppy
type signatures. This should make mistakes less likely
in the JavaScript code going forward.
2021-02-05 20:46:56 -05:00
Don Cross
f34b700ce3 Updated copyrights for 2021. This resolves Travis CI broken build.
I forgot that my build process automatically updates
copyright years when the current year changes.
My Travis CI unit tests verify that there are no local
changes after running all the tests.
That test failed because the update_copyrights.py changed
all the "2019-2020" to "2019-2021".
2021-01-07 08:55:52 -05:00
Don Cross
f6f9df369e Removed obsolete code generators.
I no longer need code generators for Chebyshev and TOP2013 models.
2020-08-26 20:21:36 -04:00
Don Cross
8f16f0a5ae Pluto integrator: finished porting to Python.
I believe this wraps up the Python integrator.
It now works in all 4 languages and passes all tests.
Fixed up demo tests to match new output.
Turned on Travis CI checking in this branch again.
2020-08-24 20:54:20 -04:00
Don Cross
1a2508f68b Pluto integrator: ported to JavaScript. 2020-08-24 14:14:32 -04:00
Don Cross
304d10fc97 Pluto integrator: ported to C#.
Ported Pluto integrator to C#.

Along the way, I noticed that I had VSOP87 latitude and longitude
swapped in such a way that they worked, but were labeled wrong.
This confused me quite a bit as I tried to implement functions
to calculate the derivatives of the VSOP87 spherical coordinates.
Fixed this in the code generator and the C and C# template files.
2020-08-23 20:49:10 -04:00
Don Cross
3bcc44d0fc Reduced precision of generated PlutoStateTable.
The PlutoStateTable was slightly different when generated
in Linux and Windows, because there was so much precision
after the decimal point. Reduced precision until Linux
and Windows generated the exact same output.
2020-08-22 14:08:07 -04:00
Don Cross
bfaa2c185b Pluto integrator: cache all calculated segments.
Instead of remembering the most recent 3 segments of Pluto's orbits,
cache up to all 40 segments within the year span 0000..4000.
Use dynamic memory to allocate them instead of static memory.
Added Astronomy_Reset() to free memory before exit.
2020-08-22 12:01:20 -04:00
Don Cross
5c3e5a83d9 Pluto integrator: keep and recycle calculations over segments.
To make Pluto calculations have a low amortized time cost,
calculate up to 3 segments between adjacent pairs of
pre-calulcated states and recycle them. Do linear ramp
fade-mixing between them.

Currently, something is wrong with this because it fails
by inaccurately calculating horizontal coordinates of Pluto
in one test. I'm not sure what's going wrong there yet,
but likely related to multiple calls via search.
2020-08-20 13:49:21 -04:00
Don Cross
0fb4d86691 Reworked terse_vector_t to use (x, y, z) instead of c[3].
The code reads so much easier to use normal (x, y, z) coordinates.
2020-08-17 21:31:04 -04:00
Don Cross
2bfef280fd Starting work on using a gravitational simulator to calculate Pluto's movement.
Added PlutoStateTable to C code generator.
This is a table of known correct [tt, pos, vel] tuples for Pluto,
calculated using TOP2013. These serve as seed points from which
to integrate Pluto's motion.

Added PlutoCheck() function to ctest, just to get going.
I have a lot more peformance work to do in order to make
the full blown unit test to finish in a reasonable amount of
time.

Changes in astronomy.c:

Added some generic "terse vector" support.
A terse vector contains 3 components and nothing else.
This is handy for implementing compact formulas for various
vector expressions.

Created enhanced VSOP87 calculations that provide
velocity vectors as well as position vectors for
the Sun, Jupiter, Saturn, Uranus, and Neptune.
These are the "major" bodies that have significant
effects on the motion of Pluto. Also used to convert
heliocentric coordinates to barycentric coordinates.

Implemented first version of the integrator logic.
It is not accurate enough yet, and it is far too slow.
I need to debug the accuracy first, then I will work on
making it faster.
2020-08-17 17:33:03 -04:00
Don Cross
b6db310641 Keeping useful changes from abandoned branch small_pluto.
I was experimenting with an alternative way to calculate Pluto's position.
That idea didn't work out, but in the process, I did make some changes
I want to keep:

1. A typecast in generate/codegen.c that eliminates a build warning
   in Windows (Visual Studio 2015).

2. Expanded generate/vsop/vsop.c to calculate both position and velocity
   vectors. This was tricky to get working, and could come in handy.
2020-08-15 13:28:16 -04:00
Don Cross
e19d50c68c Fixed #72 - resolved build warnings in gcc 9.3.0.
Version 9.3.0 of gcc has extra warnings that detect snprintf
truncations and use of possibly uninitialized variables.
Fixed some warnings of both types.
2020-07-21 23:30:44 +00:00
Don Cross
9347fd0264 codegen: Eliminated unused 'body' parameter in Top2013_List(). 2020-07-08 15:57:26 -04:00
Don Cross
03609b2825 TOP2013: Ported new Pluto model to Python. 2020-07-08 15:42:52 -04:00
Don Cross
8b2880a925 TOP2013: Ported to JavaScript. 2020-07-08 14:35:19 -04:00
Don Cross
765902c542 TOP2013: Ported new Pluto model to C# code.
Also corrected code generator to output term coefficients
in scientific notation. In the C code, it was dropping signficant
digits by outputting in fixed point notation.
2020-07-08 11:10:02 -04:00