Skip to content

Commit

Permalink
Fix duplicate dimension names
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed May 17, 2024
1 parent 5beedea commit 82eb8cd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
21 changes: 15 additions & 6 deletions satpy/readers/mviri_l1b_fiduceo_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 19 additions & 11 deletions satpy/tests/reader_tests/test_mviri_l1b_fiduceo_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
Expand All @@ -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")
Expand Down

0 comments on commit 82eb8cd

Please sign in to comment.