Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions satpy/readers/seviri_l1b_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,23 +683,27 @@ def _add_scanline_acq_time(self, dataset, dataset_id):
acq_time = get_cds_time(days=tline["Days"], msecs=tline["Milliseconds"])
add_scanline_acq_time(dataset, acq_time)

@cached_property
def _acq_time_hrv(self):
tline = self._dask_array["hrv"]["acq_time"].compute()
return tline.reshape(self.mda["hrv_number_of_lines"])

@cached_property
def _acq_time_visir(self):
return self._dask_array["visir"]["acq_time"].compute()

def _get_acq_time_hrv(self):
"""Get raw acquisition time for HRV channel."""
tline = self._dask_array["hrv"]["acq_time"]
tline0 = tline[:, 0]
tline1 = tline[:, 1]
tline2 = tline[:, 2]
return da.stack((tline0, tline1, tline2), axis=1).reshape(
self.mda["hrv_number_of_lines"]).compute()
Comment on lines -688 to -693
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why I did it this way, but your solution is much cleaner and yields the same results 👍

return self._acq_time_hrv

def _get_acq_time_visir(self, dataset_id):
"""Get raw acquisition time for VIS/IR channels."""
# Check if there is only 1 channel in the list as a change
# is needed in the array assignment, i.e. channel id is not present
if len(self.mda["channel_list"]) == 1:
return self._dask_array["visir"]["acq_time"].compute()
return self._acq_time_visir
i = self.mda["channel_list"].index(dataset_id["name"])
return self._dask_array["visir"]["acq_time"][:, i].compute()
return self._acq_time_visir[:, i]

def _update_attrs(self, dataset, dataset_info):
"""Update dataset attributes."""
Expand Down
14 changes: 14 additions & 0 deletions satpy/tests/reader_tests/test_seviri_l1b_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,20 @@ def test_get_dataset(self, file_handler):
assert file_handler.end_time == dt.datetime(2006, 1, 1, 12, 30, 0)
assert_attrs_equal(xarr.attrs, expected.attrs, tolerance=1e-4)

def test_get_acq_time_visir_uses_cached_values(self, file_handler):
"""Test VISIR acquisition-time reuse from cache."""
file_handler._get_acq_time_visir({"name": "VIS006"})
assert file_handler._acq_time_visir is not None

cached = np.empty_like(file_handler._acq_time_visir)
cached["Days"] = 42
cached["Milliseconds"] = 123456
file_handler._acq_time_visir = cached

tline = file_handler._get_acq_time_visir({"name": "IR_108"})
np.testing.assert_array_equal(tline["Days"], np.full(tline.shape, 42))
np.testing.assert_array_equal(tline["Milliseconds"], np.full(tline.shape, 123456))

def test_time(self, file_handler):
"""Test start/end nominal/observation time handling."""
assert dt.datetime(2006, 1, 1, 12, 15, 9, 304888) == file_handler.observation_start_time
Expand Down