Skip to content

Commit

Permalink
Add preprocessing method
Browse files Browse the repository at this point in the history
  • Loading branch information
sfinkens committed Nov 22, 2024
1 parent 49fd20a commit c7bbfe5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions satpy/readers/mviri_l1b_fiduceo_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,17 @@ def is_high_resol(resolution):
return resolution == HIGH_RESOL


class DatasetPreprocessor:
def preprocess_dataset(ds):
"""Preprocess the given dataset.
Performs steps that can be done once, such as decoding
according to CF conventions.
"""
preproc = _DatasetPreprocessor()
return preproc.preprocess(ds)


class _DatasetPreprocessor:
"""Helper class for preprocessing the dataset."""

def preprocess(self, ds):
Expand Down Expand Up @@ -534,7 +544,11 @@ def _cleanup_attrs(self, ds):


class DatasetAccessor:
"""Helper class for accessing the dataset."""
"""Helper class for accessing the dataset.
Performs steps that need to be done each time a variable
is accessed, such as renaming "y_*" coordinates to "y".
"""

def __init__(self, ds):
"""Wrap the given dataset."""
Expand Down Expand Up @@ -597,7 +611,7 @@ def open_dataset(filename):
decode_times=False,
mask_and_scale=False,
)
nc_preproc = DatasetPreprocessor().preprocess(nc_raw)
nc_preproc = preprocess_dataset(nc_raw)
return DatasetAccessor(nc_preproc)


Expand Down
4 changes: 2 additions & 2 deletions satpy/tests/reader_tests/test_mviri_l1b_fiduceo_nc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
ALTITUDE,
EQUATOR_RADIUS,
POLE_RADIUS,
DatasetPreprocessor,
FiduceoMviriEasyFcdrFileHandler,
FiduceoMviriFullFcdrFileHandler,
Interpolator,
preprocess_dataset,
)
from satpy.tests.utils import make_dataid

Expand Down Expand Up @@ -637,7 +637,7 @@ def fixture_dataset_exp(self):

def test_preprocess(self, dataset, dataset_exp):
"""Test dataset preprocessing."""
preprocessed = DatasetPreprocessor().preprocess(dataset)
preprocessed = preprocess_dataset(dataset)
xr.testing.assert_allclose(preprocessed, dataset_exp)


Expand Down

0 comments on commit c7bbfe5

Please sign in to comment.