diff --git a/lisainstrument/instrument.py b/lisainstrument/instrument.py index 78f26dcddfb149926c9fdb59c9d8d3b9d731ac1f..1e07d12564886c8b6caab5db2f3b4626470a81ed 100755 --- a/lisainstrument/instrument.py +++ b/lisainstrument/instrument.py @@ -131,8 +131,9 @@ class Instrument: electro_delays: tuple (isi, tmi, rfi) of dictionaries for electronic delays [s] concurrent (bool): whether to use multiprocessing chunking_size (int): size of chunks when using dask - delay_isc_min (float): minimum interspacecraft delay that can occur in the simulation - delay_isc_max (float): maximum interspacecraft delay that can occur in the simulation + delay_isc_min (float): minimum interspacecraft delay [s] that can occur in the simulation + delay_isc_max (float): maximum interspacecraft delay [s] that can occur in the simulation + delay_clock_max (float): maximum absolute clock delays [s] that can occur in the simulation """ # pylint: disable=attribute-defined-outside-init @@ -287,6 +288,7 @@ class Instrument: chunking_size=256, delay_isc_min: float = 6.0, delay_isc_max: float = 12.0, + delay_clock_max: float = 50.0, ) -> None: # pylint: disable=too-many-arguments,too-many-positional-arguments,too-many-statements,too-many-locals,too-many-branches logger.info("Initializing instrumental simulation") @@ -620,7 +622,24 @@ class Instrument: # Interpolation and antialiasing filter self.init_interpolation(interpolation) - self.init_delays(interpolation, delay_isc_min, delay_isc_max) + + if delay_clock_max < 0: + msg = ( + f"Negative maximum absolute clock delay of {delay_clock_max} specified" + ) + raise ValueError(msg) + + if delay_isc_min < 0: + msg = ( + f"Negative minimum interspacecraft delay of {delay_isc_min} not allowed" + ) + raise ValueError(msg) + + if delay_isc_max < delay_isc_min: + msg = f"Maximum interspacecraft delay {delay_isc_min} below minimum delay {delay_isc_min} specified" + raise ValueError(msg) + + self.init_delays(interpolation, delay_isc_min, delay_isc_max, delay_clock_max) self.init_aafilter(aafilter) # Electronic delays @@ -654,7 +673,11 @@ class Instrument: return numpyfy_dask_multi(op, chunks=self.chunking_size) def init_delays( - self, interpolation: None | tuple, delay_isc_min: float, delay_isc_max: float + self, + interpolation: None | tuple, + delay_isc_min: float, + delay_isc_max: float, + delay_clock_max: float, ) -> None: """Initialize or design the interpolation functions for the delays @@ -685,6 +708,7 @@ class Instrument: interpolation: see `interpolation` docstring in `__init__()` delay_isc_min: Minimum allowed interspacecraft delay [s] delay_isc_max: Maximum allowed interspacecraft delay [s] + delay_clock_max: Maximum allowed absolute delay [s] between clocks/tpc/tcp """ match interpolation: @@ -703,11 +727,22 @@ class Instrument: ShiftBC.ZEROPAD, ShiftBC.ZEROPAD, ) + op_dyn_clock_ = make_dynamic_shift_lagrange_dask( + order, + -delay_clock_max * self.physics_fs, + delay_clock_max * self.physics_fs, + ShiftBC.FLAT, + ShiftBC.FLAT, + ) op_fix_ = make_fixed_shift_lagrange_dask( ShiftBC.ZEROPAD, ShiftBC.ZEROPAD, order ) + op_dyn_clock = self.numpyfy_dask_multi(op_dyn_clock_) op_dyn = self.numpyfy_dask_multi(op_dyn_) op_fix = self.numpyfy_dask_multi(op_fix_) + self.apply_shift_clock = AdaptiveShiftNumpy( + op_fix, op_dyn_clock, self.physics_fs + ) self.apply_shift = AdaptiveShiftNumpy(op_fix, op_dyn, self.physics_fs) self.apply_shift_electro = self.apply_shift.fixed case ( @@ -722,11 +757,23 @@ class Instrument: ShiftBC.ZEROPAD, ShiftBC.ZEROPAD, ) + op_dyn_clock_ = make_dynamic_shift_dsp_dask( + order, + -delay_clock_max * self.physics_fs, + delay_clock_max * self.physics_fs, + ShiftBC.FLAT, + ShiftBC.FLAT, + ) op_fix_ = make_fixed_shift_dsp_dask( ShiftBC.ZEROPAD, ShiftBC.ZEROPAD, order ) + op_dyn_clock = self.numpyfy_dask_multi(op_dyn_clock_) op_dyn = self.numpyfy_dask_multi(op_dyn_) op_fix = self.numpyfy_dask_multi(op_fix_) + + self.apply_shift_clock = AdaptiveShiftNumpy( + op_fix, op_dyn_clock, self.physics_fs + ) self.apply_shift = AdaptiveShiftNumpy(op_fix, op_dyn, self.physics_fs) self.apply_shift_electro = self.apply_shift.fixed case ("lagrange", int(order)): @@ -2094,7 +2141,7 @@ class Instrument: lambda sc, x: self.invert_scet_wrt_tps(x, sc), concurrent=self.concurrent ) - self.timestamped = lambda mosa, x: self.interpolate( + self.timestamped = lambda mosa, x: self.apply_shift_clock( x, -self.tps_wrt_scet.for_each_mosa()[mosa] )