Commit Graph

188 Commits

Author SHA1 Message Date
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
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
c91fe513c1 PY ObserverState
Implemented the Python version of the ObserverState function.
2021-11-19 21:40:22 -05:00
Don Cross
9537296347 Added missing supported bodies to Python HelioState docs. 2021-11-15 21:14:40 -05:00
Don Cross
5c989be20c PY HelioState: calculates heliocentric position and velocity.
This is the Python version of a new function HelioState to
calculate heliocentric state vectors (position and velocity).
2021-11-15 20:37:09 -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
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
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
a9b9652c5d Added sample Python program stars_near_moon.py.
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.
2021-11-08 21:44:36 -05:00
Don Cross
3f788aaaee Fixed #126 - Added support for lunar libration.
There is now a Libration function in all 4 supported languages.
The returned structure contains libration angles in
ecliptic latitude and ecliptic longitude, along with
the Moon's ecliptic position and distance.
Also included is the Moon's apparent angular diameter.
2021-11-05 19:14:46 -04:00
Don Cross
296f23af76 Libration functions now calculate apparent angular diameter of the Moon.
All 4 languages have added a `diam_deg` field to the
structure returned by the Libration function.
It is the apparent angular diameter of the Moon as
seen from the center of the Earth, expressed in degrees.
2021-11-05 16:02:14 -04:00
Don Cross
f1e9313054 Implemented libration in Python. 2021-11-04 15:44:03 -04:00
Don Cross
adf65e1f1f Throw an exception for invalid refraction option.
In JavaScript and Python, throw an exception if provided
an invalid refraction option. Especially in JavaScript,
it was too easy to pass in a value like 'true', which did
not calculate refraction as expected.
2021-10-12 14:31:13 -04:00
Don Cross
25cba04356 Added pylint to unit tests. Fixed warnings. 2021-09-25 19:51:48 -04:00
Don Cross
d3621e7206 Implemented Python function SearchAltitude. 2021-09-23 14:27:56 -04:00
Don Cross
aa2eb01dbf Python ObserverGravity function. 2021-07-19 22:09:49 -04:00
Don Cross
0d23d46f74 Implemented Python function BaryState. 2021-07-13 20:43:50 -04:00
Don Cross
87926a71c1 Implemented C# 'triangulate' demo. Added doc links. 2021-06-22 13:51:14 -04:00
Don Cross
2eec19fc23 Implemented C version of demo 'triangulate'.
Just like the Python version, this program calculates
the best-fit intersection point for two lines of sight
as seen by two observers. It demonstrates converting
back and forth between geographic coordinates and
geocentric vectors.
2021-06-22 10:50:47 -04:00
Don Cross
8abda4ea30 Documentation fixes for VectorObserver functions. 2021-06-21 20:23:33 -04:00
Don Cross
90f5ea367e JS: Implemented VectorObserver. 2021-06-21 16:45:59 -04:00
Don Cross
7b543249b1 Implemented C version of VectorObserver. 2021-06-21 15:34:56 -04:00
Don Cross
72030c5bcf Python _inverse_terra uses Newton's Method.
Instead of the hack call to Search(), the latitude
solver now uses Newton's Method directly. This
significantly speeds up the code, and is more elegant.
2021-06-20 21:19:15 -04:00
Don Cross
2ba632694b Oops. Fixed typo in triangulate.py output. 2021-06-20 13:50:44 -04:00
Don Cross
4fc1f95c50 Print error estimate in triangulator.
The program triangulate.py finds the point in space
where two vantage lines come closest to each other.
It is the midpoint between the closest points on both lines.
Now I print the distance between those two points also,
as a measure of how much uncertainty there is in the
estimation of the target object.
2021-06-20 13:39:48 -04:00
Don Cross
829328a1d2 PY VectorObserver: stricter latitude tolerance.
Added more exhaustive testing of VectorObserver.
I found a few cases where the height calculation
was off by more than 5 millimeters.

In the VectorObserver function, require the latitude solver
to keep iterating until the error is less than one billionth
of a degree. Now the height error is always within 1 mm.
2021-06-20 12:04:21 -04:00
Don Cross
2aa26aba78 Python: implemented VectorObserver function.
I already had the function ObserverVector that converts geographic
coordinates (latitude, longitude, elevation) to an equatorial-of-date
(EQD) vector.

Now I'm in the process of adding the inverse function VectorObserver
that calculates geographic coordinates from an EQD vector.
This commit implements VectorObserver in Python.
The other languages will follow in future commits.

The motivation was from the following request:
https://github.com/cosinekitty/geocalc/issues/1
The goal is to find the near-intersection between two different lines
of sight from two different observers on the Earth's surface.
Added a demo program triangulate.py that solves this problem.
2021-06-20 10:57:12 -04:00
Don Cross
04ba909b30 Starting to solve triangulation math problem.
I believe I have solved for the closest pair of points
on a pair of skew lines. Not quite finished;
this is work in progress.
2021-06-17 21:58:53 -04:00
Don Cross
b9daddd04c Added demo program galactic.py.
This is the Python version of a demo to convert
galactic coordinates to horizontal coordinates for
a given time and geographic location.
2021-06-14 12:29:33 -04:00
Don Cross
52fb59b32e Python: Implemented EQJ/GAL conversions.
Ported conversion to/from galactic coordinates to Python.
Added unit test for new Python code.
Updated documentation for all 4 supported languages.
Fixed mistakes in JavaScript function documentation.
2021-06-10 20:48:11 -04:00
Don Cross
7e89ca6cda Demo to confirm I understand galactic coordinates.
I wrote a quick Python program based on an original reference
paper defining the galactic orientation system.
It generates a rotation matrix from first principles
that matches one inside the NOVAS function equ2gal(),
within the expected 2.3 arcsecond difference between
ICRS and EQJ.

NOVAS equ2gal matrix:

   double ag[3][3] = {
      {-0.0548755604, +0.4941094279, -0.8676661490},
      {-0.8734370902, -0.4448296300, -0.1980763734},
      {-0.4838350155, +0.7469822445, +0.4559837762}};

This program's generated matrix:

    B1950 = 1949-12-31T22:09:21.346Z
     -0.0548624779711344   0.4941095946388765  -0.8676668813529025
     -0.8734572784246782  -0.4447938112296831  -0.1980677870294097
     -0.4838000529948520   0.7470034631630423   0.4559861124470794

Also added some JPL Horizons test data to confirm
conversion back and forth between EQJ and GAL, which
I will use for future tests.
2021-06-06 17:49:24 -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
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. 2021-04-15 21:10:38 -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
ef42841592 PY: Finished implementation of JupiterMoons function. 2021-04-14 06:41:24 -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
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