From eaf9e3a64a70e0e2a29c6ba1e5ecf530f35fc589 Mon Sep 17 00:00:00 2001 From: Johan Strandgren Date: Mon, 21 Oct 2024 08:30:13 +0000 Subject: [PATCH] Fix seviri_l2_grib end_time property bug. --- satpy/readers/eum_l2_grib.py | 8 ++++++-- satpy/tests/reader_tests/test_eum_l2_grib.py | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/satpy/readers/eum_l2_grib.py b/satpy/readers/eum_l2_grib.py index 543aa71c30..4ed5901a65 100644 --- a/satpy/readers/eum_l2_grib.py +++ b/satpy/readers/eum_l2_grib.py @@ -78,8 +78,12 @@ def start_time(self): def end_time(self): """Return the sensing end time.""" if self.sensor == "seviri": - delta = SEVIRI_REPEAT_CYCLE_DURATION_RSS if self._ssp_lon == 9.5 else SEVIRI_REPEAT_CYCLE_DURATION - return self.start_time + dt.timedelta(minutes=delta) + try: + delta = SEVIRI_REPEAT_CYCLE_DURATION_RSS if self._ssp_lon == 9.5 else SEVIRI_REPEAT_CYCLE_DURATION + return self.start_time + dt.timedelta(minutes=delta) + except AttributeError: + # If dataset and metadata (ssp_lon) have not yet been loaded, return None + return None elif self.sensor == "fci": return self.filename_info["end_time"] diff --git a/satpy/tests/reader_tests/test_eum_l2_grib.py b/satpy/tests/reader_tests/test_eum_l2_grib.py index 50c6be5398..4172cf0ea0 100644 --- a/satpy/tests/reader_tests/test_eum_l2_grib.py +++ b/satpy/tests/reader_tests/test_eum_l2_grib.py @@ -133,12 +133,16 @@ def test_seviri_data_reading(da_, xr_, setup_reader): dataset_id = make_dataid(name="dummmy", resolution=3000) + # Check that end_time is None for SEVIRI before the dataset has been loaded + assert reader.end_time is None + common_checks(ec_, reader, mock_file, dataset_id) - # Check end_time + # Check that end_time is now a valid datetime.datetime object after the dataset has been loaded assert reader.end_time == datetime.datetime(year=2020, month=10, day=20, hour=19, minute=50, second=0) + # Checks the correct execution of the _get_global_attributes and _get_metadata_from_msg functions attributes = reader._get_attributes() expected_attributes = { @@ -234,12 +238,12 @@ def test_fci_data_reading(da_, xr_, setup_reader): dataset_id = make_dataid(name="dummmy", resolution=2000) - common_checks(ec_, reader, mock_file, dataset_id) - # Check end_time assert reader.end_time == datetime.datetime(year=2020, month=10, day=20, hour=19, minute=50, second=0) + common_checks(ec_, reader, mock_file, dataset_id) + # Checks the correct execution of the _get_global_attributes and _get_metadata_from_msg functions attributes = reader._get_attributes() expected_attributes = {