Commit Graph

2245 Commits

Author SHA1 Message Date
Don Cross
8498d23c73 C RiseSet: print performance stats.
Track the maximum recursion depth in FindAscent.
Count the number of times the altitude_diff function is called.
These are important performance statistics that I want to
measure, so I can try a few optimization ideas.

Current results:

don@spearmint:~/github/astronomy/generate $ ./generate source && ./ctbuild && ./ctest -v riseset
./ctbuild: C compiler = gcc
./ctbuild: Built 'ctest' program.
C RiseSet: Moon    lat=-61.0 lon=103.0
C RiseSet: Moon    lat=-45.0 lon=150.0
C RiseSet: Moon    lat=29.0 lon=-81.0
C RiseSet: Moon    lat=80.0 lon=130.0
C RiseSet: Moon    lat=83.0 lon=105.0
C RiseSet: Moon    lat=84.0 lon=125.0
C RiseSet: Moon    lat=85.0 lon=135.0
C RiseSet: Moon    lat=85.0 lon=140.0
C RiseSet: Sun     lat=-90.0 lon=0.0
C RiseSet: Sun     lat=-88.0 lon=45.0
C RiseSet: Sun     lat=-60.0 lon=-150.0
C RiseSet: Sun     lat=15.0 lon=75.0
C RiseSet: Sun     lat=29.0 lon=-81.0
C RiseSet: Sun     lat=60.0 lon=0.0
C RiseSet: Sun     lat=89.0 lon=30.0
C RiseSet: Sun     lat=90.0 lon=0.0
C RiseSet: passed 5909 lines: time errors in minutes: rms=0.2904, max=1.1541, recur=19, altcount=171438
2022-11-13 09:36:48 -05:00
Don Cross
bfc7c80309 C: Cleanup of new function FindAscent(). 2022-11-12 21:52:38 -05:00
Don Cross
4602f619d3 C: Rise/set that works near the poles!
This is a whole new algorithm that efficiently finds
all rise/set events, even near the poles.
It uses a recursive bisection search that limits
recursion depth by knowing the maximum possible
|da/dt| = change in altitude with respect to time.
2022-11-12 21:40:20 -05:00
Don Cross
eede908314 Arcsine of (radius/dist) for more accuracy.
Finding apparent angular radius by dividing body radius
by distance is not quite as accurate as taking the
arcsine of the same ratio. Changed this for a slightly
more accurate answer.
2022-11-10 15:20:04 -05:00
Don Cross
bf20fb1c44 C: InternalSearchAltitude owns func + context.
Refactored so there is a single altitude function/context pair
instead of separate ones for SearchAltitude and SearchRiseSet.
This allows InternalSearchAltitude to fully understand the
problem to be solved, and also makes the code smaller.
InternalSearchAltitude will need to perform min/max altitude
calculations, which means it needs to know all the parameters
of the altitude search directly. They are no longer hidden
inside an opaque function pointer and context.

So now SearchAltitude and SearchRiseSet no longer create
contexts, nor pass in a function pointer. They just
pass the correct numeric parameters to the generic solver
InternalSearchAltitude, which packs the parameters into
the context for Search().

Unified the two context types into a single context type,
and the two callback functions into a single callback function.
2022-11-10 15:10:28 -05:00
Don Cross
6bfe2c2334 Merge branch 'matheo-master' v2.1.9 2022-11-08 21:01:05 -05:00
Don Cross
3679966931 Version 2.1.9: attempt fix for Deno/Node type info.
Updated the version number so I can create a new
npm package to test the pull request from @matheo
that should allow TypeScript types to be exported correctly.
2022-11-08 20:59:17 -05:00
Mateo Tibaquira
40cd7e3b0e Fix #263 - Update the npm package metadata 2022-11-08 18:05:51 -05:00
Don Cross
cd2df0bc6e Attempted fix of custom CodeQL configuration.
Apparently you have to put CodeQL paths-ignore statements
in a separate yml file from the GitHub Actions workflow yml,
and point to it by name. Trying that here.
2022-11-07 15:43:01 -05:00
Don Cross
5eca7d7760 CodeQL tweaks and fixes.
Updated CodeQL config to ignore source templates,
because they are not syntactically valid source code.
Ignore other stuff that is irrelevant to published
code quality.

Made various fixes based on helpful CodeQL analysis.
2022-11-07 15:31:05 -05:00
Don Cross
b05df95974 Merge pull request #262 from lgtm-migrator/codeql
Add CodeQL workflow for GitHub code scanning
2022-11-07 14:21:13 -05:00
LGTM Migrator
11ef704423 Add CodeQL workflow for GitHub code scanning 2022-11-07 18:24:59 +00:00
Don Cross
0674d69237 C RiseSet: starting algorithm without hour angles.
The rise/set search based on hour angles is complicated,
and doesn't handle oddities that happen close to the poles.
I'm starting to rework rise/set as a more brute force solution
that iterates through finite time steps.

I also added a series of Moon data for the arctic circle,
which includes some of the more painful special cases.
For example:

Moon  130  80 2034-05-16T13:21Z s
Moon  130  80 2034-05-16T13:51Z r

Here the Moon sets, then rises 30 minutes later.
So now I'm trying to figure out how to discover
arbitrarily brief intervals like this.
I want the time increments to scale intelligently
so that we don't waste time during long periods
of inactivity (body above or below the horizon continuously),
but without missing examples like the one above.
2022-11-05 20:58:04 -04:00
Don Cross
1bc61f714e BROKEN BUILD: added failing data for rise/set.
Added sunrise/sunset test data for locations
at or near the poles. This causes rise/set tests to fail.
I need to fix these cases!

Observations:

1. Sunrise/sunset at the poles has nothing to do with
   the Earth's rotation. It is based only on the Sun's
   declination. Therefore, it makes no sense to look
   at hour angles there.

2. At the poles, there is no such thing as a meridian.
   For example, at the north pole, no matter which way
   you turn, you are facing south!
   So the very notion of hour angles is meaningless.

3. At the poles, there is a single sunrise and a single sunset
   per calendar year. The sun rises near the spring solstice
   for that hemisphere, and sets near the autumn solstice.

4. Near the poles, sunrise/sunset behavior gets more complicated.
   It is possible for there to be more than one sunset or sunrise
   per 24-hour period, because of changes of Sun declination.
2022-11-04 21:06:41 -04:00
Don Cross
244acd2cab Custom sort for rise/set data.
When parsing the rise/set data, the Linux
`sort` utility had weird behavior. Fixed it
by making parse_riseset.py do its own sorting
in an order that makes sense, before writing
to riseset.txt.
2022-11-04 20:58:50 -04:00
Don Cross
cd08fe5402 Eliminate doxygen warnings by pruning Doxyfile.
I use a variety of doxygen versions among the systems
that run the unit tests, including my personal development
systems and GitHub Actions.

Older versions of doxygen complain about options in Doxyfile
they don't know about.

Newer versions of doxygen complain about obsolete options in Doxyfile.

I'm trying to get rid of all these noisy warnings by pruning
all options in Doxyfile that are equivalent to their default
values. I only keep the options that I need to be different
from the default.

Hopefully this quiets down the warnings.
2022-11-02 12:02:31 -04:00
Don Cross
d5ccc605b0 Another attempt to fix GitHub Actions warnings.
Based on a fix in an unrelated project:
https://github.com/airlift/airlift/pull/1018/files

Java setup action was updated to v3:
https://github.com/actions/setup-java/pull/390
2022-11-01 21:32:56 -04:00
Don Cross
599eba622b Updated GitHub Actions config.
Trying to get rid of warnings in GitHub Actions:

Warning: The `set-output` command is deprecated and will be disabled soon.
Please upgrade to using Environment Files. For more information see:
https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

Trying an educated guess by upgrading various versions in the yml file.
2022-11-01 21:21:07 -04:00
Don Cross
1caebb60cb Doxygen download bug fix. 2022-11-01 20:43:28 -04:00
Don Cross
7435134445 Scrape correct download link for Doxygen.
The Windows version of the GitHub Actions tests require
downloading Doxygen binaries. Every now and then this
step would break when Doxygen updates their version numbers.
Added a Python script to scrape the Doxygen website to
determine the correct URL to download.
commit_hook.bat calls the Python script to determine
the URL, so I don't have to keep manually updating it.
2022-11-01 20:33:42 -04:00
Don Cross
c8af73e1e7 Fixed #256 - added orbital period functions. v2.1.8 2022-11-01 19:40:30 -04:00
Don Cross
275e3a7c79 Kotlin: added function planetOrbitalPeriod. 2022-11-01 19:16:32 -04:00
Don Cross
23fd95a53f PY: Added PlanetOrbitalPeriod function. 2022-11-01 17:30:48 -04:00
Don Cross
fd49c25ae3 C#: exported function PlanetOrbitalPeriod. 2022-11-01 17:01:03 -04:00
Don Cross
bd115770e1 C: Added function Astronomy_PlanetOrbitalPeriod. 2022-11-01 16:38:57 -04:00
Don Cross
9e4fbecf55 JS: added OrbitalPeriod function. 2022-11-01 16:09:14 -04:00
Don Cross
6f25a3db85 Astronomy Engine v2.1.7: eclipse obscuration
This is my second attempt to release eclipse obscuration.
I discovered there was a missing unit test for obscuration
for lunar eclipses in the Kotlin library. It has been added.
v2.1.7
2022-10-20 19:13:47 -04:00
Don Cross
232da2c319 Astronomy Engine 2.1.6: eclipse obscuration v2.1.6 2022-10-20 18:34:27 -04:00
Don Cross
06b62887d2 Kotlin: obscuration for solar, lunar eclipses. 2022-10-20 17:31:21 -04:00
Don Cross
678866af02 C: define MOON_POLAR_RADIUS_AU for consistency 2022-10-20 13:07:02 -04:00
Don Cross
393f134c49 PY: solar eclipse obscuration
Also fixed missing improvements to C# PlanetShadow().
2022-10-20 12:32:11 -04:00
Don Cross
a90edfed0d PY: lunar eclipse obscuration 2022-10-19 20:44:22 -04:00
Don Cross
99db293317 PY Elongation test: better coding pattern. 2022-10-19 19:37:04 -04:00
Don Cross
223b75a69a JS: solar eclipse obscuration. 2022-10-19 16:47:33 -04:00
Don Cross
f81e5f0aea JS: more testing of obscuration in unit test lunar_eclipse. 2022-10-19 14:51:16 -04:00
Don Cross
f6c5bd0bba JS: lunar eclipse obscuration 2022-10-19 14:37:21 -04:00
Don Cross
f7787caf98 C#: solar eclipse obscuration and accuracy enhancements 2022-10-18 20:09:59 -04:00
Don Cross
c798c5015d C#: lunar eclipse obscuration 2022-10-18 16:21:15 -04:00
Don Cross
c53b8b8dd5 C: more accurate Sun positions for lunar eclipses, transits.
For consistency, I now calculate the Sun's apparent position
correcting for aberration, for lunar eclipses and transits.
This didn't make much difference for accuracy.

Before correcting for Sun aberration:

$ ./ctest transit
C TransitFile(eclipse/mercury.txt ): PASS - verified 94, max minutes = 10.709, max sep arcmin = 0.2120
C TransitFile(eclipse/venus.txt   ): PASS - verified 30, max minutes =  9.108, max sep arcmin = 0.6772

$ ./ctest -v lunar_fraction
C LunarFractionCase(2010-06-26) fraction error = 0.00900991
C LunarFractionCase(2012-06-04) fraction error = 0.00491535
C LunarFractionCase(2013-04-25) fraction error = 0.00143039
C LunarFractionCase(2017-08-07) fraction error = 0.00682336
C LunarFractionCase(2019-07-16) fraction error = 0.00572727
C LunarFractionCase(2021-11-19) fraction error = 0.00350680
C LunarFractionCase(2023-10-28) fraction error = 0.00370518
C LunarFractionCase(2024-09-18) fraction error = 0.00429906
C LunarFractionCase(2026-08-28) fraction error = 0.00322697
C LunarFractionCase(2028-01-12) fraction error = 0.00405870
C LunarFractionCase(2028-07-06) fraction error = 0.00857840
C LunarFractionCase(2030-06-15) fraction error = 0.00557106
C LunarFractionTest: PASS

After correcting for Sun aberration:

$ ./ctest transit
C TransitFile(eclipse/mercury.txt ): PASS - verified 94, max minutes = 10.709, max sep arcmin = 0.2120
C TransitFile(eclipse/venus.txt   ): PASS - verified 30, max minutes =  9.108, max sep arcmin = 0.6772

$ ./ctest -v lunar_fraction
C LunarFractionCase(2010-06-26) fraction error = 0.00762932
C LunarFractionCase(2012-06-04) fraction error = 0.00606322
C LunarFractionCase(2013-04-25) fraction error = 0.00111560
C LunarFractionCase(2017-08-07) fraction error = 0.00571542
C LunarFractionCase(2019-07-16) fraction error = 0.00713913
C LunarFractionCase(2021-11-19) fraction error = 0.00298979
C LunarFractionCase(2023-10-28) fraction error = 0.00448445
C LunarFractionCase(2024-09-18) fraction error = 0.00367044
C LunarFractionCase(2026-08-28) fraction error = 0.00405559
C LunarFractionCase(2028-01-12) fraction error = 0.00347340
C LunarFractionCase(2028-07-06) fraction error = 0.00729982
C LunarFractionCase(2030-06-15) fraction error = 0.00680776
C LunarFractionTest: PASS
2022-10-18 13:32:07 -04:00
Don Cross
b4f7f2c8a3 C: more accurate Sun positions for solar eclipses
I wondered why my obscuration numbers were less accurate
for partial eclipses than for annular eclipses.
I considered that the obscuration for an annular eclipse
is not sensitive to the relative positions of the Sun
and Moon, but it is for a partial eclipse.

Looking at the functions MoonShadow and LocalMoonShadow, I realized
that I was not correcting the Sun's position for aberration.
After fixing that, obscuration values are much more in
agreement with authoritative sources.

Soon I will study the same issue that exists in EarthShadow,
used for lunar eclipse calculations, and PlanetShadow,
used for transits.

Before correcting for Sun aberration:

C GlobalAnnularCase(2023-10-14) obscuration error = 0.00009036, expected = 0.90638000, calculated = 0.90647036
C GlobalAnnularCase(2024-10-02) obscuration error = 0.00005246, expected = 0.86975000, calculated = 0.86980246
C GlobalAnnularCase(2027-02-06) obscuration error = 0.00007237, expected = 0.86139000, calculated = 0.86146237
C GlobalAnnularCase(2028-01-26) obscuration error = 0.00003656, expected = 0.84787000, calculated = 0.84790656
C GlobalAnnularCase(2030-06-01) obscuration error = 0.00008605, expected = 0.89163000, calculated = 0.89171605
C LocalSolarCase(2023-10-14) obscuration diff =  0.00006323, expected =  0.90638000, calculated =  0.90644323
C LocalSolarCase(2023-10-14) obscuration diff = -0.00521043, expected =  0.57800000, calculated =  0.57278957
C LocalSolarCase(2023-10-14) obscuration diff = -0.00542845, expected =  0.88670000, calculated =  0.88127155
C LocalSolarCase(2024-04-08) obscuration diff =  0.00000000, expected =  1.00000000, calculated =  1.00000000
C LocalSolarCase(2024-04-08) obscuration diff =  0.00304558, expected =  0.34000000, calculated =  0.34304558
C LocalSolarCase(2024-10-02) obscuration diff =  0.00007858, expected =  0.86975000, calculated =  0.86982858
C LocalSolarCase(2024-10-02) obscuration diff = -0.00343797, expected =  0.43600000, calculated =  0.43256203
C LocalSolarCase(2030-06-01) obscuration diff =  0.00007259, expected =  0.89163000, calculated =  0.89170259
C LocalSolarCase(2030-06-01) obscuration diff = -0.00059871, expected =  0.67240000, calculated =  0.67180129
C LocalSolarCase(2030-06-01) obscuration diff = -0.00146303, expected =  0.67360000, calculated =  0.67213697
C SolarFractionTest: PASS

After correcting for Sun aberration:

C GlobalAnnularCase(2023-10-14) obscuration error = 0.00007930, expected = 0.90638000, calculated = 0.90645930
C GlobalAnnularCase(2024-10-02) obscuration error = 0.00006221, expected = 0.86975000, calculated = 0.86981221
C GlobalAnnularCase(2027-02-06) obscuration error = 0.00006058, expected = 0.86139000, calculated = 0.86145058
C GlobalAnnularCase(2028-01-26) obscuration error = 0.00004560, expected = 0.84787000, calculated = 0.84791560
C GlobalAnnularCase(2030-06-01) obscuration error = 0.00007078, expected = 0.89163000, calculated = 0.89170078
C LocalSolarCase(2023-10-14) obscuration diff =  0.00007997, expected =  0.90638000, calculated =  0.90645997
C LocalSolarCase(2023-10-14) obscuration diff =  0.00002298, expected =  0.57800000, calculated =  0.57802298
C LocalSolarCase(2023-10-14) obscuration diff = -0.00101535, expected =  0.88670000, calculated =  0.88568465
C LocalSolarCase(2024-04-08) obscuration diff =  0.00000000, expected =  1.00000000, calculated =  1.00000000
C LocalSolarCase(2024-04-08) obscuration diff = -0.00060338, expected =  0.34000000, calculated =  0.33939662
C LocalSolarCase(2024-10-02) obscuration diff =  0.00006096, expected =  0.86975000, calculated =  0.86981096
C LocalSolarCase(2024-10-02) obscuration diff = -0.00097934, expected =  0.43600000, calculated =  0.43502066
C LocalSolarCase(2030-06-01) obscuration diff =  0.00006606, expected =  0.89163000, calculated =  0.89169606
C LocalSolarCase(2030-06-01) obscuration diff =  0.00019620, expected =  0.67240000, calculated =  0.67259620
C LocalSolarCase(2030-06-01) obscuration diff = -0.00066619, expected =  0.67360000, calculated =  0.67293381
C SolarFractionTest: PASS
2022-10-18 12:34:25 -04:00
Don Cross
35936761f7 C: local solar eclipse obscuration
C function Astronomy_SearchLocalSolarEclipse now reports
obscuration for the peak of a solar eclipse seen at a given location.
Some of the test data from aa.usno.navy.mil looks suspiciously inaccurate.
I am finding better agreement with Fred Espenak's eclipsewise.com and
Xavier M. Jubier's xjubier.free.fr online calculators.
The larger obscuration differences are from aa.usno.navy.mil:

don@spearmint:~/github/astronomy/generate $ ./ctest -v solar_fraction
C GlobalAnnularCase(2023-10-14) obscuration error = 0.00009036, expected = 0.90638000, calculated = 0.90647036
C GlobalAnnularCase(2024-10-02) obscuration error = 0.00005246, expected = 0.86975000, calculated = 0.86980246
C GlobalAnnularCase(2027-02-06) obscuration error = 0.00007237, expected = 0.86139000, calculated = 0.86146237
C GlobalAnnularCase(2028-01-26) obscuration error = 0.00003656, expected = 0.84787000, calculated = 0.84790656
C GlobalAnnularCase(2030-06-01) obscuration error = 0.00008605, expected = 0.89163000, calculated = 0.89171605
C LocalSolarCase(2023-10-14) obscuration diff = 0.00006323, expected = 0.90638000, calculated = 0.90644323
C LocalSolarCase(2023-10-14) obscuration diff = -0.00521043, expected = 0.57800000, calculated = 0.57278957
C LocalSolarCase(2024-04-08) obscuration diff = 0.00000000, expected = 1.00000000, calculated = 1.00000000
C LocalSolarCase(2024-04-08) obscuration diff = 0.00304558, expected = 0.34000000, calculated = 0.34304558
C LocalSolarCase(2024-10-02) obscuration diff = 0.00007858, expected = 0.86975000, calculated = 0.86982858
C LocalSolarCase(2024-10-02) obscuration diff = -0.00343797, expected = 0.43600000, calculated = 0.43256203
C LocalSolarCase(2030-06-01) obscuration diff = 0.00007259, expected = 0.89163000, calculated = 0.89170259
C LocalSolarCase(2030-06-01) obscuration diff = -0.00059871, expected = 0.67240000, calculated = 0.67180129
C SolarFractionTest: PASS

I am going to rework using xjubier.free.fr in a subsequent commit.
2022-10-18 10:29:13 -04:00
Don Cross
14b881e0d9 C: global solar eclipse obscuration
Fixed bug in internal C function Obscuration().
It was not calculating obscuration correctly when
the second disc is completely inside the first disc,
i.e. the annular solar eclipse case.

Added C/C++ calculation of obscuration for global solar
eclipses that are total or annular at their peak
location and time. Obscuration is not calculated
for partial solar eclipses by SearchGlobalSolarEclipse.

Soon SearchLocalSolarEclipse will calculate obscuration
for partial solar eclipses at the geographic location
provided by the caller.
2022-10-17 16:31:05 -04:00
Don Cross
82be64ab2a C: lunar eclipse obscuration
Starting to add support for calculating the intensity
of lunar eclipses and solar eclipses in terms of "obscuration".

This commit adds calculation of obscuration for lunar eclipses
in C/C++. The structure returned by SearchLunarEclipse and
NextLunarEclipse now includes an `obscuration` field whose value
is in the range [0, 1], indicating what fraction of the Moon's
apparent disc is covered by the Earth's umbra at the eclipse's peak.
2022-10-17 11:25:10 -04:00
Don Cross
a9eadee3f1 Fixed #250 - handle years outside 0000..9999. v2.1.5 2022-10-06 22:05:44 -04:00
Don Cross
fde4c2c068 Kotlin: format dates for extreme year values. 2022-10-06 17:52:29 -04:00
Don Cross
1e95f0656b C, C#, Python: Support formatting calendar years -999999 to +999999. 2022-10-06 16:28:55 -04:00
Don Cross
a50436b535 C: Support formatting calendar years -999999 to +999999. 2022-10-06 15:29:24 -04:00
Don Cross
409e490728 Python: No longer limited to years 0000..9999.
I ported the NOVAS C 3.1 functions julian_date and cal_date to Python,
and removed the dependence on the standard datetime class for calculating UT.
Now we can create Time objects for a much wider range of year values.

Simplified the julian_date formula in C and C#.

In the Python version, I had to account for a difference
in the way integer division works for negative numbers.
In Python, integer division always rounds down, not toward
zero like it does in C/C#. So I reworked the formulas to
avoid dividing a negative integer (month-14), dividing the
positive quantity (14-month) instead and toggling addition
of the term with subtraction of the term.

I use the reworked (14-month) version in C and C# for consistency.
Also, the formatting of the formula was wacky and didn't make sense,
so now it easier to read and understand.

The Python regex for parsing dates has been expanded to allow
years before 0 and after 9999.
Allow converting Python Time to string for years before 0 and after 9999.
2022-10-06 10:56:17 -04:00
Don Cross
1327730324 C# AstroTime no longer limited to years 0000..9999.
The .NET type System.DateTime is limited to the years 0000..9999.
The Astronomy Engine type AstroTime was using System.DateTime to
convert a (year, month, day, hour, minute, second) tuple into a
fractional day value. This caused an exception for years outside
the supported range 0000..9999.

I ported the NOVAS C 3.1 functions julian_date and cal_date to C#,
and removed the dependence on System.DateTime.
Now we can create AstroTime for a much wider range of year values.
Allow converting AstroTime to string for years before 0 and after 9999.
2022-10-05 14:20:14 -04:00
Don Cross
4a56f18325 Astronomy Engine version 2.1.4 v2.1.4 2022-10-02 22:07:23 -04:00