Skip to content

Commit

Permalink
Looking at _CalcVsop as the possible origin of numeric errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinekitty committed May 28, 2024
1 parent f66515d commit 5dbede1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions demo/python/astronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import enum
import re
import abc
from os import getenv
from typing import Any, List, Tuple, Optional, Union, Callable, Dict

def _cbrt(x: float) -> float:
Expand Down Expand Up @@ -3180,12 +3181,16 @@ def _VsopSphereToRect(lon: float, lat: float, rad: float) -> _TerseVector:
rad * math.sin(lat)
)

_ProblemDebug:bool = ('1' == getenv('ASTRONOMY_ENGINE_PYTHON_PROBLEM'))

def _CalcVsop(model: _vsop_model_t, time: Time) -> Vector:
t = time.tt / _DAYS_PER_MILLENNIUM
lon = _VsopFormula(model.lon, t, True)
lat = _VsopFormula(model.lat, t, False)
rad = _VsopFormula(model.rad, t, False)
eclip = _VsopSphereToRect(lon, lat, rad)
if _ProblemDebug:
print('_CalcVsop: lon={:0.16g}, lat={:0.16g}, rad={:0.16g}, eclip=({:0.16g}, {:0.16g}, {:0.16g})'.format(lon, lat, rad, eclip.x, eclip.y, eclip.z))
return _VsopRotate(eclip).ToAstroVector(time)

class _body_state_t:
Expand Down
1 change: 1 addition & 0 deletions generate/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ obj/
profile/
private/
node_modules/
precision_problem.txt
2 changes: 1 addition & 1 deletion generate/commit_hook
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#/bin/bash
[[ -d generate ]] && cd generate
python3 test.py precision || exit $?
ASTRONOMY_ENGINE_PYTHON_PROBLEM=1 python3 test.py precision || exit $?
rm -f output/vsop*.txt output/*.eph output/jupiter_moons.txt
./run || exit $?
./verify_clean || exit $?
Expand Down
3 changes: 2 additions & 1 deletion generate/commit_hook.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ REM Astronomy Engine - GitHub Actions steps for Windows.
REM This batch file is executed on every push to GitHub.
REM --------------------------------------------------------------------------------

REM **** HACK **** Just test the Python precision problem and quit.
cd %~dp0
set ASTRONOMY_ENGINE_PYTHON_PROBLEM=1
py test.py precision || exit /b 1
set ASTRONOMY_ENGINE_PYTHON_PROBLEM=

REM Change to project/repo root directory.
cd %~dp0\..
Expand Down
5 changes: 5 additions & 0 deletions generate/template/astronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import enum
import re
import abc
from os import getenv
from typing import Any, List, Tuple, Optional, Union, Callable, Dict

def _cbrt(x: float) -> float:
Expand Down Expand Up @@ -1865,12 +1866,16 @@ def _VsopSphereToRect(lon: float, lat: float, rad: float) -> _TerseVector:
rad * math.sin(lat)
)

_ProblemDebug:bool = ('1' == getenv('ASTRONOMY_ENGINE_PYTHON_PROBLEM'))

def _CalcVsop(model: _vsop_model_t, time: Time) -> Vector:
t = time.tt / _DAYS_PER_MILLENNIUM
lon = _VsopFormula(model.lon, t, True)
lat = _VsopFormula(model.lat, t, False)
rad = _VsopFormula(model.rad, t, False)
eclip = _VsopSphereToRect(lon, lat, rad)
if _ProblemDebug:
print('_CalcVsop: lon={:0.16g}, lat={:0.16g}, rad={:0.16g}, eclip=({:0.16g}, {:0.16g}, {:0.16g})'.format(lon, lat, rad, eclip.x, eclip.y, eclip.z))
return _VsopRotate(eclip).ToAstroVector(time)

class _body_state_t:
Expand Down
9 changes: 9 additions & 0 deletions source/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3567,3 +3567,12 @@ latitude, longitude, and elevation for that vector.
The geographic latitude, longitude, and elevation above sea level
that corresponds to the given equatorial vector.

---

<a name="getenv"></a>
### getenv(key, default=None)

Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default.
key, default and the result are str.

5 changes: 5 additions & 0 deletions source/python/astronomy/astronomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import enum
import re
import abc
from os import getenv
from typing import Any, List, Tuple, Optional, Union, Callable, Dict

def _cbrt(x: float) -> float:
Expand Down Expand Up @@ -3180,12 +3181,16 @@ def _VsopSphereToRect(lon: float, lat: float, rad: float) -> _TerseVector:
rad * math.sin(lat)
)

_ProblemDebug:bool = ('1' == getenv('ASTRONOMY_ENGINE_PYTHON_PROBLEM'))

def _CalcVsop(model: _vsop_model_t, time: Time) -> Vector:
t = time.tt / _DAYS_PER_MILLENNIUM
lon = _VsopFormula(model.lon, t, True)
lat = _VsopFormula(model.lat, t, False)
rad = _VsopFormula(model.rad, t, False)
eclip = _VsopSphereToRect(lon, lat, rad)
if _ProblemDebug:
print('_CalcVsop: lon={:0.16g}, lat={:0.16g}, rad={:0.16g}, eclip=({:0.16g}, {:0.16g}, {:0.16g})'.format(lon, lat, rad, eclip.x, eclip.y, eclip.z))
return _VsopRotate(eclip).ToAstroVector(time)

class _body_state_t:
Expand Down

0 comments on commit 5dbede1

Please sign in to comment.