Skip to content

Commit 011f851

Browse files
committed
Issue #191: Improve eclipse observation performance
1 parent 398630d commit 011f851

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/bsk_rl/utils/orbital.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,13 @@ def _init_simulator(self) -> None:
337337
].recorder()
338338
self.eclipse_log = self.eclipseObject.eclipseOutMsgs[0].recorder()
339339

340+
self._time_log = []
340341
self.AddModelToTask(simTaskName, self.sc_state_log)
342+
self._r_BN_N_log = []
341343
self.AddModelToTask(simTaskName, self.planet_state_log)
344+
self._J20002Pfix_log = []
342345
self.AddModelToTask(simTaskName, self.eclipse_log)
346+
self._shadowFactor_log = []
343347

344348
self.InitializeSimulation()
345349

@@ -351,7 +355,7 @@ def sim_time(self) -> float:
351355
@property
352356
def times(self) -> np.ndarray:
353357
"""Recorder times in seconds."""
354-
return np.array([macros.NANO2SEC * t for t in self.sc_state_log.times()])
358+
return macros.NANO2SEC * np.array(self._time_log)
355359

356360
def extend_to(self, t: float) -> None:
357361
"""Compute the trajectory of the satellite up to t.
@@ -363,12 +367,19 @@ def extend_to(self, t: float) -> None:
363367
return
364368
self.ConfigureStopTime(macros.sec2nano(t))
365369
self.ExecuteSimulation()
370+
self._time_log.extend(self.sc_state_log.times())
371+
self._r_BN_N_log.extend(self.sc_state_log.r_BN_N)
372+
self._J20002Pfix_log.extend(self.planet_state_log.J20002Pfix)
373+
self._shadowFactor_log.extend(self.eclipse_log.shadowFactor)
374+
self.sc_state_log.clear()
375+
self.planet_state_log.clear()
376+
self.eclipse_log.clear()
366377

367378
def _generate_eclipses(self, t: float) -> None:
368379
self.extend_to(t + self.dt)
369380
upcoming_times = self.times[self.times > self._eclipse_search_time]
370381
upcoming_eclipse = (
371-
self.eclipse_log.shadowFactor[self.times > self._eclipse_search_time] > 0
382+
np.array(self._shadowFactor_log)[self.times > self._eclipse_search_time] > 0
372383
).astype(float)
373384
for i in np.where(np.diff(upcoming_eclipse) == -1)[0]:
374385
self._eclipse_starts.append(upcoming_times[i])
@@ -412,7 +423,7 @@ def r_BN_N(self) -> interp1d:
412423
self.extend_to(self.dt * 3)
413424
return interp1d(
414425
self.times,
415-
self.sc_state_log.r_BN_N,
426+
self._r_BN_N_log,
416427
kind="cubic",
417428
axis=0,
418429
fill_value="extrapolate",
@@ -427,9 +438,7 @@ def r_BP_P(self) -> interp1d:
427438
self.times,
428439
[
429440
np.matmul(dcm, pos)
430-
for dcm, pos in zip(
431-
self.planet_state_log.J20002Pfix, self.sc_state_log.r_BN_N
432-
)
441+
for dcm, pos in zip(self._J20002Pfix_log, self._r_BN_N_log)
433442
],
434443
kind="cubic",
435444
axis=0,

0 commit comments

Comments
 (0)