Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix seviri_l2_grib end_time property bug. #2943

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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
8 changes: 6 additions & 2 deletions satpy/readers/eum_l2_grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
10 changes: 7 additions & 3 deletions satpy/tests/reader_tests/test_eum_l2_grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,16 @@

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)


Check warning on line 145 in satpy/tests/reader_tests/test_eum_l2_grib.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Large Method

test_seviri_data_reading increases from 73 to 74 lines of code, threshold = 70. Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function.
Comment on lines +136 to +145
Copy link
Member

Choose a reason for hiding this comment

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

Could this test case be split into several specific tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hm, I've been trying to refactor this into something better, but so far with no satisfying results. I have previously created an issue to work on removing the mocking #2932, do you think we could move this test optimization to the PR that will deal with the mocking (since it will anyway lead to quite some refactoring)?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, sounds good! Feel free to merge.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Nah, you do it, you're the reviewer ;)

# Checks the correct execution of the _get_global_attributes and _get_metadata_from_msg functions
attributes = reader._get_attributes()
expected_attributes = {
Expand Down Expand Up @@ -234,12 +238,12 @@

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 = {
Expand Down
Loading