diff --git a/satpy/readers/mviri_l1b_fiduceo_nc.py b/satpy/readers/mviri_l1b_fiduceo_nc.py index b2ad3fd22a..2c4154aec6 100644 --- a/satpy/readers/mviri_l1b_fiduceo_nc.py +++ b/satpy/readers/mviri_l1b_fiduceo_nc.py @@ -457,7 +457,20 @@ class DatasetWrapper: def __init__(self, nc): """Wrap the given dataset.""" - self.nc = nc + self._fix_duplicate_dimensions(nc) + self.nc = self._chunk(nc) + + def _fix_duplicate_dimensions(self, nc): + nc.variables["covariance_spectral_response_function_vis"].dims = ("srf_size_1", "srf_size_2") + + def _chunk(self, nc): + chunks = { + "x": CHUNK_SIZE, + "y": CHUNK_SIZE, + "x_ir_wv": CHUNK_SIZE, + "y_ir_wv": CHUNK_SIZE + } + return nc.chunk(chunks) @property def attrs(self): @@ -563,12 +576,8 @@ def __init__(self, filename, filename_info, filetype_info, # noqa: D417 self.mask_bad_quality = mask_bad_quality nc_raw = xr.open_dataset( filename, - # chunks={"x": CHUNK_SIZE, - # "y": CHUNK_SIZE, - # "x_ir_wv": CHUNK_SIZE, - # "y_ir_wv": CHUNK_SIZE}, decode_times=False, - decode_cf=False + decode_cf=False, ) self.nc = DatasetWrapper(nc_raw) diff --git a/satpy/tests/reader_tests/test_mviri_l1b_fiduceo_nc.py b/satpy/tests/reader_tests/test_mviri_l1b_fiduceo_nc.py index cf9573737c..ee9b14f41c 100644 --- a/satpy/tests/reader_tests/test_mviri_l1b_fiduceo_nc.py +++ b/satpy/tests/reader_tests/test_mviri_l1b_fiduceo_nc.py @@ -272,6 +272,7 @@ def fixture_fake_dataset(): dtype=np.uint8 ) ) + cov = da.from_array([[1, 2], [3, 4]]) time = np.arange(4) * 60 * 60 time_fill_value = 4294967295 time_add_offset = 0 @@ -308,6 +309,7 @@ def fixture_fake_dataset(): "sub_satellite_longitude_end": np.nan, "sub_satellite_latitude_start": np.nan, "sub_satellite_latitude_end": 0.1, + "covariance_spectral_response_function_vis": (("srf_size", "srf_size"), cov) }, coords={ "y": [1, 2, 3, 4], @@ -329,28 +331,34 @@ def fixture_fake_dataset(): return ds +@pytest.fixture(name="fake_file") +def fixture_fake_file(fake_dataset, tmp_path): + """Write a fake netcdf file.""" + filename = tmp_path / "test.nc" + fake_dataset.to_netcdf(filename) + return filename + + @pytest.fixture( name="file_handler", params=[FiduceoMviriEasyFcdrFileHandler, FiduceoMviriFullFcdrFileHandler] ) -def fixture_file_handler(fake_dataset, request): +def fixture_file_handler(fake_file, request): """Create mocked file handler.""" marker = request.node.get_closest_marker("file_handler_data") mask_bad_quality = True if marker: mask_bad_quality = marker.kwargs["mask_bad_quality"] fh_class = request.param - with mock.patch("satpy.readers.mviri_l1b_fiduceo_nc.xr.open_dataset") as open_dataset: - open_dataset.return_value = fake_dataset - return fh_class( - filename="filename", - filename_info={"platform": "MET7", - "sensor": "MVIRI", - "projection_longitude": "57.0"}, - filetype_info={"foo": "bar"}, - mask_bad_quality=mask_bad_quality - ) + return fh_class( + filename=fake_file, + filename_info={"platform": "MET7", + "sensor": "MVIRI", + "projection_longitude": "57.0"}, + filetype_info={"foo": "bar"}, + mask_bad_quality=mask_bad_quality + ) @pytest.fixture(name="reader")