mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-05-19 06:17:03 -04:00
Huge performance boost to Python code: re-use e_tilt calculations.
Calculate _e_tilt() no more than once per Time instance. Cache the value in the Time instance and re-use it. This reduced astro_check time from 5.0 minutes to 2.0 minutes.
This commit is contained in:
@@ -259,6 +259,7 @@ class Time:
|
||||
def __init__(self, ut):
|
||||
self.ut = ut
|
||||
self.tt = _TerrestrialTime(ut)
|
||||
self.etilt = None
|
||||
|
||||
@staticmethod
|
||||
def Make(year, month, day, hour, minute, second):
|
||||
@@ -284,6 +285,14 @@ class Time:
|
||||
def Utc(self):
|
||||
return _EPOCH + datetime.timedelta(days=self.ut)
|
||||
|
||||
def _etilt(self):
|
||||
# Calculates precession and nutation of the Earth's axis.
|
||||
# The calculations are very expensive, so lazy-evaluate and cache
|
||||
# the result inside this Time object.
|
||||
if self.etilt is None:
|
||||
self.etilt = _e_tilt(self)
|
||||
return self.etilt
|
||||
|
||||
|
||||
class Observer:
|
||||
def __init__(self, latitude, longitude, height=0):
|
||||
@@ -594,7 +603,7 @@ def _vector2radec(pos):
|
||||
|
||||
|
||||
def _nutation(time, direction, inpos):
|
||||
tilt = _e_tilt(time)
|
||||
tilt = time._etilt()
|
||||
oblm = tilt.mobl * _DEG2RAD
|
||||
oblt = tilt.tobl * _DEG2RAD
|
||||
psi = tilt.dpsi * _ASEC2RAD
|
||||
@@ -641,7 +650,7 @@ def _era(time): # Earth Rotation Angle
|
||||
|
||||
def _sidereal_time(time):
|
||||
t = time.tt / 36525.0
|
||||
eqeq = 15.0 * _e_tilt(time).ee # Replace with eqeq=0 to get GMST instead of GAST (if we ever need it)
|
||||
eqeq = 15.0 * time._etilt().ee # Replace with eqeq=0 to get GMST instead of GAST (if we ever need it)
|
||||
theta = _era(time)
|
||||
st = (eqeq + 0.014506 +
|
||||
(((( - 0.0000000368 * t
|
||||
|
||||
Reference in New Issue
Block a user