@@ -64,21 +64,27 @@ def __init__(self, update_bcrs_every=0.0, *args, **kwargs):
6464 super ().__init__ (* args , ** kwargs )
6565 self .update_bcrs_every = update_bcrs_every * un .s
6666
67- def setup (self ):
68- """Standard setup, as well as storing the cartesian representation of ECI."""
69- super ().setup ()
67+ # Do one rotation to warm up the cache. This reads the IERS table.
68+ frame = AltAz (obstime = self .times [0 ], location = self .telescope_loc )
69+ self .skycoords [0 ].transform_to (frame )
70+ self ._time_of_last_evaluation = None
71+
72+ # These are unchanging over time, so init them outside the setup() to save
73+ # memory when multi-processing.
7074 self ._eci = self .xp .asarray (
7175 point_source_crd_eq (self .skycoords .ra , self .skycoords .dec )
7276 )
7377
78+ def setup (self ):
79+ """Standard setup, as well as storing the cartesian representation of ECI."""
80+ super ().setup ()
81+
7482 # BCRS holds the deflected, aberrated bnp-d coordinates, which don't change
7583 # significantly over time.
76- self ._bcrs = self ._eci .copy ()
77- self ._time_of_last_evaluation = None
78-
79- # Do one rotation to warm up the cache.
80- frame = AltAz (obstime = self .times [0 ], location = self .telescope_loc )
81- self .skycoords [0 ].transform_to (frame )
84+ if not hasattr (self , "_bcrs" ):
85+ self ._bcrs = self .xp .full (
86+ self ._eci .shape , dtype = self ._eci .dtype , fill_value = 0.0
87+ )
8288
8389 def _atioq (self , xyz : np .ndarray , astrom ):
8490 # cirs to hadec rot
@@ -177,21 +183,22 @@ def _apco(self, observed_frame):
177183 def _get_obsf (self , obstime , location ):
178184 return AltAz (obstime = obstime , location = location )
179185
180- def rotate (self , t : int ) -> tuple [np .ndarray , np .ndarray ]:
181- """Rotate the coordinates into the observed frame."""
182- obsf = self ._get_obsf (self .times [t ], self .telescope_loc )
183- astrom = self ._apco (obsf )
184-
185- # Copy the eci coordinates, because these routines modify them in-place
186-
186+ def _set_bcrs (self , t , astrom = None ):
187187 # convert to topocentric CIRS
188188 # together, _ld + _ab take ~90% of the time.
189+ if astrom is None :
190+ obsf = self ._get_obsf (self .times [t ], self .telescope_loc )
191+ astrom = self ._apco (obsf )
192+
189193 if (
190194 self ._time_of_last_evaluation is None
191195 or self .times [t ] - self .times [self ._time_of_last_evaluation ]
192196 > self .update_bcrs_every
193197 ):
194- self ._bcrs [:] = self ._eci [:]
198+ if hasattr (self , "_bcrs" ):
199+ self ._bcrs [:] = self ._eci [:]
200+ else :
201+ self ._bcrs = self ._eci .copy ()
195202
196203 # Light deflection by the Sun, giving BCRS natural direction.
197204 self ._ld (self ._bcrs , self .xp .asarray (astrom ["eh" ]), astrom ["em" ], 1e-6 )
@@ -207,6 +214,13 @@ def rotate(self, t: int) -> tuple[np.ndarray, np.ndarray]:
207214
208215 self ._time_of_last_evaluation = t
209216
217+ def rotate (self , t : int ) -> tuple [np .ndarray , np .ndarray ]:
218+ """Rotate the coordinates into the observed frame."""
219+ obsf = self ._get_obsf (self .times [t ], self .telescope_loc )
220+ astrom = self ._apco (obsf )
221+
222+ self ._set_bcrs (t , astrom )
223+
210224 self .all_coords_topo [:] = self ._bcrs [:]
211225
212226 # now perform observed conversion
0 commit comments