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

Add warning for SEVIRI native reader in case of bad data #2198

Merged
merged 2 commits into from Sep 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions satpy/readers/seviri_l1b_native.py
Expand Up @@ -26,6 +26,7 @@
"""

import logging
import warnings
from datetime import datetime

import dask.array as da
Expand Down Expand Up @@ -295,6 +296,9 @@ def _read_header(self):
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)

def _read_trailer(self):

hdr_size = self.header_type.itemsize
Expand Down
1 change: 0 additions & 1 deletion satpy/readers/seviri_l1b_native_hdr.py
Expand Up @@ -713,7 +713,6 @@ def seviri_l15_trailer(self):
('GeometricQuality', self.geometric_quality),
('TimelinessAndCompleteness', self.timeliness_and_completeness)
]

return record

@property
Expand Down
43 changes: 41 additions & 2 deletions satpy/tests/reader_tests/test_seviri_l1b_native.py
Expand Up @@ -528,7 +528,7 @@ class TestNativeMSGArea(unittest.TestCase):
"""

@staticmethod
def create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan):
def create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan, good_qual='OK'):
"""Create mocked NativeMSGFileHandler.

Contains sufficient attributes for NativeMSGFileHandler.get_area_extent to be able to execute.
Expand Down Expand Up @@ -572,8 +572,11 @@ def create_test_header(earth_model, dataset_id, is_full_disk, is_rapid_scan):
n_hrv_cols = n_visir_cols * 3
n_hrv_lines = n_visir_lines * 3
ssp_lon = 0

header = {
'15_MAIN_PRODUCT_HEADER': {
'QQOV': {'Name': 'QQOV',
'Value': good_qual}
},
'15_DATA_HEADER': {
'ImageDescription': {
reference_grid: {
Expand Down Expand Up @@ -1368,3 +1371,39 @@ def test_header_type(file_content, exp_header_size):
fh = NativeMSGFileHandler('myfile', {}, None)
assert fh.header_type.itemsize == exp_header_size
assert '15_SECONDARY_PRODUCT_HEADER' in fh.header


def test_header_warning():
"""Test warning is raised for NOK quality flag."""
header_good = TestNativeMSGArea.create_test_header(
dataset_id=make_dataid(name='VIS006', resolution=3000),
earth_model=1,
is_full_disk=True,
is_rapid_scan=0,
good_qual='OK'
)
header_bad = TestNativeMSGArea.create_test_header(
dataset_id=make_dataid(name='VIS006', resolution=3000),
earth_model=1,
is_full_disk=True,
is_rapid_scan=0,
good_qual='NOK'
)

with mock.patch('satpy.readers.seviri_l1b_native.np.fromfile') as fromfile, \
mock.patch('satpy.readers.seviri_l1b_native.recarray2dict') as recarray2dict, \
mock.patch('satpy.readers.seviri_l1b_native.NativeMSGFileHandler._get_memmap') as _get_memmap, \
mock.patch('satpy.readers.seviri_l1b_native.NativeMSGFileHandler._read_trailer'), \
mock.patch("builtins.open", mock.mock_open(read_data=b'FormatName : NATIVE')):
recarray2dict.side_effect = (lambda x: x)
_get_memmap.return_value = np.arange(3)

exp_warning = "The quality flag for this file indicates not OK. Use this data with caution!"

fromfile.return_value = header_good
with pytest.warns(None):
NativeMSGFileHandler('myfile', {}, None)

fromfile.return_value = header_bad
with pytest.warns(UserWarning, match=exp_warning):
NativeMSGFileHandler('myfile', {}, None)