From 1f00271fa5dbec037246e53fcbca9d9d3fda1c47 Mon Sep 17 00:00:00 2001
From: Niklas Reinhardt <janniklas.reinhardt@aei.mpg.de>
Date: Mon, 23 May 2022 15:38:23 +0200
Subject: [PATCH] Adjust definiion of physics sample offset

---
 lisainstrument/instrument.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/lisainstrument/instrument.py b/lisainstrument/instrument.py
index 39e6f58..7b98c98 100755
--- a/lisainstrument/instrument.py
+++ b/lisainstrument/instrument.py
@@ -222,6 +222,8 @@ class Instrument:
         self.physics_fs = self.fs * self.physics_upsampling
         logger.info("Computing physics time vector (size=%s, dt=%s)", self.physics_size, self.physics_dt)
         self.physics_t = self.t0 + np.arange(self.physics_size, dtype=np.float64) * self.physics_dt
+        # number of physics samples corresponding to the initial telemetry contacts
+        self.physics_sample_offset = int(num_initial_telemetry_contacts * physics_upsampling * telemetry_downsampling)
 
         # Instrument topology
         self.central_freq = float(central_freq)
@@ -799,11 +801,15 @@ class Instrument:
 
         logger.debug("Computing local timer deviations")
         self.local_timer_deviations = \
+            self.clock_offsets + \
+            self.clock_freqoffsets * self.physics_t + \
+            self.clock_freqlindrifts * self.physics_t**2 / 2 + \
+            self.clock_freqquaddrifts * self.physics_t**3 / 3 + \
             ForEachSC(lambda sc:
                 cumulative_trapezoid(np.broadcast_to(
-                    self.clock_noise_offsets[sc] + self.clock_noise_fluctuations[sc],
-                    self.physics_size),
-                dx=self.physics_dt, initial=0) + self.clock_offsets[sc]
+                    self.clock_noise_fluctuations_complete[sc],
+                    self.physics_size + self.physics_sample_offset),
+                dx=self.physics_dt, initial=0)[self.physics_sample_offset:]
             )
 
         ## Timer deviations from TCB
@@ -815,11 +821,11 @@ class Instrument:
             ForEachSC(lambda sc:
                 cumulative_trapezoid(np.broadcast_to(
                     self.clock_noise_fluctuations_complete[sc],
-                    self.physics_size + int(self.num_initial_telemetry_contacts * self.physics_upsampling * self.telemetry_downsampling)),
-                dx=self.physics_dt)[::self.physics_upsampling * self.telemetry_downsampling] + \
+                    self.physics_size + self.physics_sample_offset),
+                dx=self.physics_dt, initial=0)[::self.physics_upsampling * self.telemetry_downsampling] + \
                 self.tcb_sync_noises[sc]
                 # + \
-                #self.tps_proper_time_deviations[sc]
+                # self.tps_proper_time_deviations[sc]
             )
 
         ## TDIR tone
@@ -1332,13 +1338,12 @@ class Instrument:
 
         logger.debug("Generating clock noise fluctuations")
 
-        times_offset = int(self.num_initial_telemetry_contacts * self.physics_upsampling * self.telemetry_downsampling)
         self.clock_noise_fluctuations_complete = ForEachSC(lambda sc:
             noises.clock(self.physics_fs,
-                         self.physics_size + times_offset, self.clock_asds[sc])
+                         self.physics_size + self.physics_sample_offset, self.clock_asds[sc])
         )
         self.clock_noise_fluctuations = ForEachSC(lambda sc:
-            self.clock_noise_fluctuations_complete[sc][times_offset:]
+            self.clock_noise_fluctuations_complete[sc][self.physics_sample_offset:]
         )
 
         ## Modulation noise
-- 
GitLab