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 native reader failing when missing main header #2516

Merged
merged 3 commits into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions satpy/readers/seviri_l1b_native.py
Expand Up @@ -370,13 +370,16 @@
self.mda['hrv_number_of_lines'] = int(sec15hd["NumberLinesHRV"]['Value'])
self.mda['hrv_number_of_columns'] = cols_hrv

if self.header['15_MAIN_PRODUCT_HEADER']['QQOV']['Value'] == 'NOK':
warnings.warn(
"The quality flag for this file indicates not OK. "
"Use this data with caution!",
UserWarning,
stacklevel=2
)
if '15_MAIN_PRODUCT_HEADER' not in self.header:
logger.info("Quality flag check was not possible due to missing 15_MAIN_PRODUCT_HEADER.")
djhoese marked this conversation as resolved.
Show resolved Hide resolved
else:
if self.header['15_MAIN_PRODUCT_HEADER']['QQOV']['Value'] == 'NOK':
ameraner marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(
"The quality flag for this file indicates not OK. "
"Use this data with caution!",
UserWarning,
stacklevel=2
)

Check warning on line 382 in satpy/readers/seviri_l1b_native.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ Getting worse: Complex Method

NativeMSGFileHandler._read_header increases in cyclomatic complexity from 11 to 13, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

def _read_trailer(self):

Expand Down
8 changes: 8 additions & 0 deletions satpy/tests/reader_tests/test_seviri_l1b_native.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python

Check notice on line 1 in satpy/tests/reader_tests/test_seviri_l1b_native.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 766 to 772, improve code health by reducing it to 600. The number of Lines of Code in a single file. More Lines of Code lowers the code health.
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2019 Satpy developers
#
Expand Down Expand Up @@ -1423,6 +1423,14 @@
with pytest.warns(UserWarning, match=exp_warning):
NativeMSGFileHandler('myfile', {}, None)

# check that without Main Header the code doesn't crash
header_missing = header_good.copy()
header_missing.pop('15_MAIN_PRODUCT_HEADER')
fromfile.return_value = header_missing
with warnings.catch_warnings():
warnings.simplefilter("error")
NativeMSGFileHandler('myfile', {}, None)


@pytest.mark.parametrize(
"starts_with, expected",
Expand Down