From ce170bd8abc8a506a1e8c7f6146c0d2e09054f5e Mon Sep 17 00:00:00 2001 From: Stephan Finkensieper Date: Mon, 22 Mar 2021 13:45:11 +0000 Subject: [PATCH 1/2] Fix SEVIRI Native file pattern matching Match algorithm version in filename instead of using a fixed one. --- satpy/etc/readers/seviri_l1b_native.yaml | 6 ++-- .../reader_tests/test_seviri_l1b_native.py | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/satpy/etc/readers/seviri_l1b_native.yaml b/satpy/etc/readers/seviri_l1b_native.yaml index de5bbc362d..d08c86b0e5 100644 --- a/satpy/etc/readers/seviri_l1b_native.yaml +++ b/satpy/etc/readers/seviri_l1b_native.yaml @@ -13,9 +13,9 @@ reader: file_types: native_msg: file_reader: !!python/name:satpy.readers.seviri_l1b_native.NativeMSGFileHandler - file_patterns: ['{satid:4s}-{instr:4s}-MSG{product_level:2d}-0100-NA-{end_time:%Y%m%d%H%M%S.%f}000Z-{processing_time:%Y%m%d%H%M%S}-{order_id:s}.nat', - '{satid:4s}-{instr:4s}-MSG{product_level:2d}-0100-NA-{end_time:%Y%m%d%H%M%S.%f}000Z-{order_id:s}.nat', - '{satid:4s}-{instr:4s}-MSG{product_level:2d}-0100-NA-{end_time:%Y%m%d%H%M%S.%f}000Z' + file_patterns: ['{satid:4s}-{instr:4s}-MSG{product_level:2d}-{base_algorithm_version:4s}-NA-{end_time:%Y%m%d%H%M%S.%f}000Z-{processing_time:%Y%m%d%H%M%S}-{order_id:s}.nat', + '{satid:4s}-{instr:4s}-MSG{product_level:2d}-{base_algorithm_version:4s}-NA-{end_time:%Y%m%d%H%M%S.%f}000Z-{order_id:s}.nat', + '{satid:4s}-{instr:4s}-MSG{product_level:2d}-{base_algorithm_version:4s}-NA-{end_time:%Y%m%d%H%M%S.%f}000Z' ] # Note: the end_time value in the SEVIRI native filenames is officially called Nominal Image Time (SNIT field in # the 15_MAIN_PRODUCT_HEADER) marking the time where the product is defined to be valid. This time always matches diff --git a/satpy/tests/reader_tests/test_seviri_l1b_native.py b/satpy/tests/reader_tests/test_seviri_l1b_native.py index 99c2f4c205..2de31135c1 100644 --- a/satpy/tests/reader_tests/test_seviri_l1b_native.py +++ b/satpy/tests/reader_tests/test_seviri_l1b_native.py @@ -17,6 +17,7 @@ # satpy. If not, see . """Unittesting the Native SEVIRI reader.""" +import os import unittest from unittest import mock @@ -1101,3 +1102,33 @@ def test_padder_fes_hrv(self): """Test padder for FES HRV data.""" calculated, expected = self.prepare_padder(TEST_PADDER_FES_HRV) np.testing.assert_array_equal(calculated, expected) + + +class TestNativeMSGFilenames: + """Test identification of Native format filenames.""" + + @pytest.fixture + def reader(self): + """Return reader for SEVIRI Native format.""" + from satpy._config import config_search_paths + from satpy.readers import load_reader + + reader_configs = config_search_paths( + os.path.join("readers", "seviri_l1b_native.yaml")) + reader = load_reader(reader_configs) + return reader + + def test_file_pattern(self, reader): + """Test file pattern matching.""" + filenames = [ + # Valid + "MSG2-SEVI-MSG15-0100-NA-20080219094242.289000000Z", + "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z", + "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z-123456.nat", + "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z-20201231181545-123456.nat", + # Invalid + "MSG2-SEVI-MSG15-0100-NA-20080219094242.289000000", + "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z-123456", + ] + files = reader.select_files_from_pathnames(filenames) + assert len(files) == 4 From 27e76d25cf0b2c9e716f43af4f58d20db71c76a8 Mon Sep 17 00:00:00 2001 From: Stephan Finkensieper Date: Mon, 22 Mar 2021 13:50:23 +0000 Subject: [PATCH 2/2] Update test --- satpy/tests/reader_tests/test_seviri_l1b_native.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/satpy/tests/reader_tests/test_seviri_l1b_native.py b/satpy/tests/reader_tests/test_seviri_l1b_native.py index 2de31135c1..0babb3a3b5 100644 --- a/satpy/tests/reader_tests/test_seviri_l1b_native.py +++ b/satpy/tests/reader_tests/test_seviri_l1b_native.py @@ -1124,11 +1124,10 @@ def test_file_pattern(self, reader): # Valid "MSG2-SEVI-MSG15-0100-NA-20080219094242.289000000Z", "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z", - "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z-123456.nat", - "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z-20201231181545-123456.nat", + "MSG2-SEVI-MSG15-0301-NA-20080219094242.289000000Z-123456.nat", + "MSG2-SEVI-MSG15-0401-NA-20080219094242.289000000Z-20201231181545-123456.nat", # Invalid - "MSG2-SEVI-MSG15-0100-NA-20080219094242.289000000", - "MSG2-SEVI-MSG15-0201-NA-20080219094242.289000000Z-123456", + "MSG2-SEVI-MSG15-010-NA-20080219094242.289000000Z", ] files = reader.select_files_from_pathnames(filenames) assert len(files) == 4