From ec981ac2e72ced2201d07a8db79634405d6ecd6e Mon Sep 17 00:00:00 2001 From: Amy Stamile Date: Thu, 7 Mar 2024 10:49:24 -0700 Subject: [PATCH] Adds band time offset --- ale/base/type_sensor.py | 2 +- ale/drivers/ody_drivers.py | 54 ++- tests/pytests/data/isds/themisvis_isd.json | 464 +++++++++++---------- tests/pytests/test_themis_drivers.py | 12 +- 4 files changed, 294 insertions(+), 238 deletions(-) diff --git a/ale/base/type_sensor.py b/ale/base/type_sensor.py index 584bdf054..bb86ddd30 100644 --- a/ale/base/type_sensor.py +++ b/ale/base/type_sensor.py @@ -162,7 +162,7 @@ def ephemeris_stop_time(self): : double Center ephemeris time for an image """ - return self.ephemeris_start_time + (self.interframe_delay) * (self.num_frames - 1) + self.exposure_duration + return self.ephemeris_start_time + (self.interframe_delay * self.num_frames) diff --git a/ale/drivers/ody_drivers.py b/ale/drivers/ody_drivers.py index cffe34989..21d165271 100644 --- a/ale/drivers/ody_drivers.py +++ b/ale/drivers/ody_drivers.py @@ -203,7 +203,7 @@ def ikid(self): return self.label['IsisCube']['Kernels']['NaifFrameCode'] @property - def ephemeris_start_time(self): + def start_time(self): """ The starting ephemeris time, in seconds @@ -214,7 +214,7 @@ def ephemeris_start_time(self): : double Starting ephemeris time in seconds """ - og_start_time = super().ephemeris_start_time + og_start_time = spice.str2et(self.utc_start_time.strftime("%Y-%m-%d %H:%M:%S.%f")) offset = self.label["IsisCube"]["Instrument"]["SpacecraftClockOffset"] if isinstance(offset, pvl.collections.Quantity): @@ -225,7 +225,21 @@ def ephemeris_start_time(self): # if not milliseconds, the units are probably seconds offset = offset.value - return og_start_time + offset - ((self.exposure_duration / 1000) / 2) + return og_start_time + offset - (self.exposure_duration / 2) + + @property + def ephemeris_start_time(self): + """ + Returns the ephemeris start time of the image. + Expects spacecraft_id to be defined. This should be the integer + Naif ID code for the spacecraft. + + Returns + ------- + : float + ephemeris start time of the image + """ + return self.band_times[0] @property def focal_length(self): @@ -264,13 +278,29 @@ def sampling_factor(self): return self.label['IsisCube']['Instrument']['SpatialSumming'] @property - def filter_number(self): - """ - Return the filter number from the cube label + def interframe_delay(self): + return self.label['IsisCube']['Instrument']['InterframeDelay'] + + @property + def band_times(self): + self._num_bands = self.label["IsisCube"]["Core"]["Dimensions"]["Bands"] + times = [] - Returns - ------- - : int - The filter number - """ - return self.label['IsisCube']['BandBin']['FilterNumber'] \ No newline at end of file + org_bands = self.label["IsisCube"]["BandBin"]["FilterNumber"] + + for vband in range(self._num_bands): + if isinstance(org_bands, (list, tuple)): + timeband = org_bands[vband] + else: + timeband = org_bands + + if 'ReferenceBand' in self.label['IsisCube']['Instrument']: + ref_band = self.label['IsisCube']['Instrument']['ReferenceBand'] + wavelength_to_timeband = [2, 5, 3, 4, 1] + timeband = wavelength_to_timeband[ref_band - 1] + + band_offset = ((timeband - 1) * self.interframe_delay) - (self.exposure_duration / 2.0) + + time = self.start_time + band_offset + times.append(time) + return times \ No newline at end of file diff --git a/tests/pytests/data/isds/themisvis_isd.json b/tests/pytests/data/isds/themisvis_isd.json index 7eb32d66a..0218861da 100644 --- a/tests/pytests/data/isds/themisvis_isd.json +++ b/tests/pytests/data/isds/themisvis_isd.json @@ -10,11 +10,11 @@ "unit": "m" }, "name_model": "USGS_ASTRO_PUSH_FRAME_SENSOR_MODEL", - "starting_ephemeris_time": 392211095.6221267, - "ending_ephemeris_time": 392211095.6431267, - "center_ephemeris_time": 392211095.6326267, + "starting_ephemeris_time": 392211098.2249755, + "ending_ephemeris_time": 392211115.32497555, + "center_ephemeris_time": 392211106.77497554, "exposure_duration": 0.0048, - "interframe_delay": 0.0009000000000000001, + "interframe_delay": 0.9, "framelet_order_reversed": false, "framelets_flipped": false, "framelet_height": 192.0, @@ -29,37 +29,37 @@ 10014, 1 ], - "ck_table_start_time": 392211095.6245267, - "ck_table_end_time": 392211095.64342606, + "ck_table_start_time": 392211098.2273755, + "ck_table_end_time": 392211115.32737505, "ck_table_original_size": 2, "ephemeris_times": [ - 392211095.6245267, - 392211095.64342606 + 392211098.2273755, + 392211115.32737505 ], "quaternions": [ [ - -0.6613201839051095, - 0.31813079278143863, - 0.010572019526757378, - 0.679217671624562 + -0.6612575247551072, + 0.3181317666738237, + 0.010542672615475755, + 0.6792786740667364 ], [ - -0.6613197289556324, - 0.31813079986265436, - 0.010571806438375995, - 0.6792181145857539 + -0.6608457315134592, + 0.3181380975623106, + 0.010349869277289786, + 0.6796792995419367 ] ], "angular_velocities": [ [ - 3.162359550994491e-05, - -2.880731353999401e-05, - 5.651876115812601e-05 + 3.162359550993753e-05, + -2.8807313540075695e-05, + 5.651876115808852e-05 ], [ - 3.162359550994488e-05, - -2.880731353999459e-05, - 5.651876115812574e-05 + 3.162359550988913e-05, + -2.8807313540612206e-05, + 5.6518761157842135e-05 ] ], "reference_frame": 1 @@ -70,37 +70,85 @@ 16, 1 ], - "ck_table_start_time": 392211090.50885653, - "ck_table_end_time": 392211096.50884634, - "ck_table_original_size": 2, + "ck_table_start_time": 392211096.50884634, + "ck_table_end_time": 392211116.1103755, + "ck_table_original_size": 6, "ephemeris_times": [ - 392211090.50885653, - 392211096.50884634 + 392211096.50884634, + 392211102.50883615, + 392211105.508831, + 392211108.50882596, + 392211114.50881577, + 392211116.1103755 ], "quaternions": [ - [ - 0.6232311997724646, - 0.25434613981903603, - 0.5148612876044842, - -0.5308566353692702 - ], [ 0.6218381088509845, 0.2557255994133679, 0.5141656436368092, -0.5324992723834004 + ], + [ + 0.6204276365853051, + 0.25708754461395245, + 0.5134575215995619, + -0.5341693698429152 + ], + [ + 0.6197209554934142, + 0.2577705510429805, + 0.5131127344678361, + -0.5349912168103959 + ], + [ + 0.6189949366169276, + 0.2584378170645526, + 0.5127323554773737, + -0.5358737675984325 + ], + [ + 0.6175697935104822, + 0.25979850092621476, + 0.5120244036606457, + -0.5375344631889868 + ], + [ + 0.6171848525456073, + 0.26015919696803447, + 0.5118309957286522, + -0.5379861353535246 ] ], "angular_velocities": [ - [ - -0.0008017636998109326, - -0.00020660785271218372, - 0.00027824065332562723 - ], [ -0.0008120775843023604, -0.00019687152047367077, 0.0002973949951161031 + ], + [ + -0.0008110971353811019, + -0.0001980016107356367, + 0.0003007261924193413 + ], + [ + -0.0008228702127818994, + -0.00018959248283095353, + 0.0003143221112970268 + ], + [ + -0.0008259115892644698, + -0.0001875070883939631, + 0.0003168111516995482 + ], + [ + -0.0008177515258053572, + -0.00019502529480012397, + 0.0003085148428501708 + ], + [ + -0.0008225132660195446, + -0.0001920179316116607, + 0.00031021965879509436 ] ], "reference_frame": 1, @@ -219,289 +267,267 @@ "starting_detector_line": 0, "starting_detector_sample": 0, "instrument_position": { - "spk_table_start_time": 392211095.6245267, - "spk_table_end_time": 392211095.64342606, - "spk_table_original_size": 22, + "spk_table_start_time": 392211098.2273755, + "spk_table_end_time": 392211115.32737505, + "spk_table_original_size": 20, "ephemeris_times": [ - 392211095.6245267, - 392211095.62542665, - 392211095.6263266, - 392211095.6272266, - 392211095.62812656, - 392211095.62902653, - 392211095.6299265, - 392211095.6308265, - 392211095.63172644, - 392211095.6326264, - 392211095.6335264, - 392211095.63442636, - 392211095.6353263, - 392211095.6362263, - 392211095.63712627, - 392211095.63802624, - 392211095.6389262, - 392211095.6398262, - 392211095.64072615, - 392211095.6416261, - 392211095.6425261, - 392211095.64342606 + 392211098.2273755, + 392211099.1273755, + 392211100.02737546, + 392211100.92737544, + 392211101.8273754, + 392211102.7273754, + 392211103.62737536, + 392211104.52737534, + 392211105.4273753, + 392211106.3273753, + 392211107.22737527, + 392211108.12737525, + 392211109.0273752, + 392211109.9273752, + 392211110.8273752, + 392211111.72737515, + 392211112.6273751, + 392211113.5273751, + 392211114.4273751, + 392211115.32737505 ], "positions": [ [ - 87.54015832992951, - 3034.7947742962697, - 2293.0640583463746 + 84.03858766507439, + 3039.614572232974, + 2286.6808762530973 ], [ - 87.53894768406154, - 3034.79644358073, - 2293.0618533698953 + 82.82772523442777, + 3041.2774066775874, + 2284.4709184502076 ], [ - 87.53773708019399, - 3034.7981128686574, - 2293.059648388359 + 81.6168097371278, + 3042.9383209413136, + 2282.259516498635 ], [ - 87.5365264221332, - 3034.799782149649, - 2293.057443416932 + 80.40584085095453, + 3044.597315806561, + 2280.0466730537223 ], [ - 87.5353157640734, - 3034.801451430642, - 2293.055238438056 + 79.19482043603313, + 3046.254388325898, + 2277.832388192539 ], [ - 87.5341051778135, - 3034.8031207001977, - 2293.0530334466716 + 77.98374813493417, + 3047.9095392439626, + 2275.616664590115 ], [ - 87.53289450214238, - 3034.8047899697567, - 2293.0508284552893 + 76.77262534316105, + 3049.5627665853835, + 2273.3995029666767 ], [ - 87.53168386846903, - 3034.8064592427836, - 2293.0486234737514 + 75.56145332338043, + 3051.2140682496706, + 2271.1809040504813 ], [ - 87.53047328221076, - 3034.8081284974387, - 2293.046418474916 + 74.35023174257698, + 3052.863445092709, + 2268.960870506433 ], [ - 87.5292626065379, - 3034.809797766999, - 2293.044213483534 + 73.13896249605739, + 3054.510894055827, + 2266.7394024440855 ], [ - 87.52805197286344, - 3034.8114670400237, - 2293.042008487095 + 71.92764524545485, + 3056.1564160167436, + 2264.516502488399 ], [ - 87.52684133241395, - 3034.813136287744, - 2293.039803498368 + 70.71628121138521, + 3057.8000089311167, + 2262.292171395066 ], [ - 87.52563068654301, - 3034.814805557302, - 2293.0375985069836 + 69.50487193300849, + 3059.441670755993, + 2260.066409881626 ], [ - 87.52442004067719, - 3034.816474826859, - 2293.0353935081484 + 68.29341685502551, + 3061.0814022817594, + 2257.839220658288 ], [ - 87.5232094246113, - 3034.818144066612, - 2293.0331885093115 + 67.08191795678087, + 3062.7192005460847, + 2255.61060377977 ], [ - 87.52199879093887, - 3034.819813324735, - 2293.03098350542 + 65.8703748456788, + 3064.3550663452515, + 2253.380561940773 ], [ - 87.52078814506996, - 3034.8214825942923, - 2293.028778506585 + 64.6587895308836, + 3065.9889967467307, + 2251.1490951960036 ], [ - 87.51957751681458, - 3034.823151845479, - 2293.026573505351 + 63.44716145707428, + 3067.6209925260096, + 2248.9162062631417 ], [ - 87.51836685875227, - 3034.824821081766, - 2293.0243685115697 + 62.235492079389864, + 3069.2510516928114, + 2246.681895869857 ], [ - 87.5171562548838, - 3034.8264903398876, - 2293.0221635002263 - ], - [ - 87.51594560901442, - 3034.828159579642, - 2293.0199584939382 - ], - [ - 87.51473496314743, - 3034.829828834297, - 2293.0177534801983 + 61.02378276357049, + 3070.8791721972575, + 2244.446164736363 ] ], "velocities": [ [ - -1.3451941491646657, - 1.8548178999680645, - -2.4500572664080202 - ], - [ - -1.3451942120413647, - 1.8548157723074683, - -2.450058876165866 - ], - [ - -1.3451942749154573, - 1.8548136446455754, - -2.4500604859232173 + -1.3453724351684715, + 1.8486592764270746, + -2.4547065774724754 ], [ - -1.3451943377922064, - 1.8548115169826171, - -2.4500620956770107 + -1.3454324232237123, + 1.8465274024714515, + -2.4563112347493434 ], [ - -1.3451944006680994, - 1.8548093893184205, - -2.450063705429284 + -1.3454915587709726, + 1.8443943094974988, + -2.4579143702797173 ], [ - -1.3451944635413877, - 1.8548072616529312, - -2.450065315181062 + -1.3455498417210945, + 1.842259999100468, + -2.459515982747381 ], [ - -1.345194526413827, - 1.8548051339862117, - -2.4500669249313214 + -1.3456072720030037, + 1.8401244723127852, + -2.461116071266014 ], [ - -1.3451945892836534, - 1.8548030063182013, - -2.450068534681087 + -1.3456638495332156, + 1.8379877307332548, + -2.4627146345253794 ], [ - -1.3451946521543818, - 1.8548008786490462, - -2.4500701444283117 + -1.3457195742364352, + 1.8358497755373877, + -2.4643116715359716 ], [ - -1.3451947150242602, - 1.8547987509786583, - -2.450071754174021 + -1.3457744460478458, + 1.8337106079019267, + -2.4659071813028874 ], [ - -1.3451947778915332, - 1.854796623306975, - -2.4500733639192314 + -1.3458284648826586, + 1.8315702294288507, + -2.4675011625213545 ], [ - -1.3451948407632155, - 1.854794495634286, - -2.4500749736598615 + -1.3458816306755408, + 1.8294286411548428, + -2.4690936143068174 ], [ - -1.345194903630545, - 1.854792367960228, - -2.4500765834010174 + -1.3459339433398503, + 1.8272858446839078, + -2.470684535358774 ], [ - -1.3451949664970162, - 1.854790240284951, - -2.450078193140655 + -1.3459854028145797, + 1.825141841196716, + -2.472273924685119 ], [ - -1.3451950293626314, - 1.8547881126084476, - -2.4500798028787796 + -1.3460360090242263, + 1.8229966318735924, + -2.4738617813031096 ], [ - -1.3451950922256386, - 1.8547859849306436, - -2.4500814126164023 + -1.346085761897403, + 1.8208502183227853, + -2.4754481039079304 ], [ - -1.3451951550895573, - 1.8547838572516926, - -2.4500830223514884 + -1.3461346613678051, + 1.818702601584768, + -2.477032891620801 ], [ - -1.3451952179543736, - 1.8547817295715894, - -2.450084632084034 + -1.3461827073556667, + 1.8165537832693437, + -2.4786161431450617 ], [ - -1.3451952808183418, - 1.8547796018902665, - -2.4500862418150686 + -1.3462298997957207, + 1.814403764418543, + -2.480197857603437 ], [ - -1.3451953436779438, - 1.8547774742075602, - -2.4500878515466207 + -1.3462762386192237, + 1.8122525466451032, + -2.4817780336958535 ], [ - -1.3451954065384484, - 1.8547753465237207, - -2.450089461275637 + -1.3463217237573908, + 1.8101001311350944, + -2.4833566704431 ], [ - -1.3451954693981014, - 1.8547732188386492, - -2.4500910710031345 + -1.346366355141844, + 1.8079465190751351, + -2.4849337668665084 ] ], "reference_frame": 1 }, "sun_position": { - "spk_table_start_time": 392211095.6245267, - "spk_table_end_time": 392211095.64342606, + "spk_table_start_time": 392211098.2273755, + "spk_table_end_time": 392211115.32737505, "spk_table_original_size": 2, "ephemeris_times": [ - 392211095.6245267, - 392211095.64342606 + 392211098.2273755, + 392211115.32737505 ], "positions": [ [ - 216567473.71634883, - 97116285.51471177, - 38695479.81483528 + 216567443.9454486, + 97116331.96889849, + 38695501.926110946 ], [ - 216567473.50018135, - 97116285.85201734, - 38695479.97538609 + 216567248.3584897, + 97116637.1599484, + 38695647.19103659 ] ], "velocities": [ [ - -11.43781110549625, - 17.847440629873425, - 8.495029234338551 + -11.437816484647803, + 17.847438217766584, + 8.495028273258358 ], [ - -11.437811144552194, - 17.847440612349658, - 8.495029227361083 + -11.437851824189536, + 17.847422370865942, + 8.49502195920609 ] ], "reference_frame": 1 diff --git a/tests/pytests/test_themis_drivers.py b/tests/pytests/test_themis_drivers.py index d8a642b03..7f826cad1 100644 --- a/tests/pytests/test_themis_drivers.py +++ b/tests/pytests/test_themis_drivers.py @@ -88,11 +88,11 @@ def test_instrument_id(self): def test_spacecraft_name(self): assert self.driver.spacecraft_name == "MARS ODYSSEY" - def test_ephemeris_start_time(self): - with patch('ale.drivers.mro_drivers.spice.scs2e', return_value=0) as scs2e: + def test_start_time(self): + with patch("ale.drivers.ody_drivers.spice.str2et", return_value=0) as str2et: self.driver.label["IsisCube"]["Instrument"]["SpacecraftClockOffset"] = 10 - assert self.driver.ephemeris_start_time == (10 - (self.driver.exposure_duration / 1000) / 2) - scs2e.assert_called_with(-53, '1023406812.23') + assert self.driver.start_time == (10 - (self.driver.exposure_duration) / 2) + str2et.assert_called_with('2012-06-05 23:30:30.245000') def test_sensor_model_version(self): assert self.driver.sensor_model_version == 1 @@ -109,5 +109,5 @@ def test_num_frames(self): def test_framelet_height(self): assert self.driver.framelet_height == 21.05263157894737 - def test_filter_number(self): - assert self.driver.filter_number == 3 \ No newline at end of file + def interframe_delay(self): + assert self.driver.interframe_delay == 0.9 \ No newline at end of file