Skip to content

Commit 94380ac

Browse files
committed
Optimize native SEVIRI scanline acq_time extraction with per-file caching
1 parent f5bd750 commit 94380ac

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

satpy/readers/seviri_l1b_native.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -683,23 +683,27 @@ def _add_scanline_acq_time(self, dataset, dataset_id):
683683
acq_time = get_cds_time(days=tline["Days"], msecs=tline["Milliseconds"])
684684
add_scanline_acq_time(dataset, acq_time)
685685

686+
@cached_property
687+
def _acq_time_hrv(self):
688+
tline = self._dask_array["hrv"]["acq_time"].compute()
689+
return tline.reshape(self.mda["hrv_number_of_lines"])
690+
691+
@cached_property
692+
def _acq_time_visir(self):
693+
return self._dask_array["visir"]["acq_time"].compute()
694+
686695
def _get_acq_time_hrv(self):
687696
"""Get raw acquisition time for HRV channel."""
688-
tline = self._dask_array["hrv"]["acq_time"]
689-
tline0 = tline[:, 0]
690-
tline1 = tline[:, 1]
691-
tline2 = tline[:, 2]
692-
return da.stack((tline0, tline1, tline2), axis=1).reshape(
693-
self.mda["hrv_number_of_lines"]).compute()
697+
return self._acq_time_hrv
694698

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

704708
def _update_attrs(self, dataset, dataset_info):
705709
"""Update dataset attributes."""

satpy/tests/reader_tests/test_seviri_l1b_native.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,20 @@ def test_get_dataset(self, file_handler):
10071007
assert file_handler.end_time == dt.datetime(2006, 1, 1, 12, 30, 0)
10081008
assert_attrs_equal(xarr.attrs, expected.attrs, tolerance=1e-4)
10091009

1010+
def test_get_acq_time_visir_uses_cached_values(self, file_handler):
1011+
"""Test VISIR acquisition-time reuse from cache."""
1012+
file_handler._get_acq_time_visir({"name": "VIS006"})
1013+
assert file_handler._acq_time_visir is not None
1014+
1015+
cached = np.empty_like(file_handler._acq_time_visir)
1016+
cached["Days"] = 42
1017+
cached["Milliseconds"] = 123456
1018+
file_handler._acq_time_visir = cached
1019+
1020+
tline = file_handler._get_acq_time_visir({"name": "IR_108"})
1021+
np.testing.assert_array_equal(tline["Days"], np.full(tline.shape, 42))
1022+
np.testing.assert_array_equal(tline["Milliseconds"], np.full(tline.shape, 123456))
1023+
10101024
def test_time(self, file_handler):
10111025
"""Test start/end nominal/observation time handling."""
10121026
assert dt.datetime(2006, 1, 1, 12, 15, 9, 304888) == file_handler.observation_start_time

0 commit comments

Comments
 (0)