Skip to content

Commit

Permalink
Don't add coordinates where we shouldn't
Browse files Browse the repository at this point in the history
In the dynamic available datasets for the iasil2snd reader, don't add
coordinates to variables that don't have corresponding dimensions.
  • Loading branch information
gerritholl committed Jul 26, 2023
1 parent f9b400a commit 7fce13a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions satpy/readers/iasi_l2_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import collections
import datetime
import itertools
import logging

import dask.array as da
import numpy as np
Expand All @@ -36,6 +37,8 @@
from . import epsnative_reader
from .file_handlers import BaseFileHandler

logger = logging.getLogger(__name__)


class EPSIASIL2FileHandler(BaseFileHandler):
"""EPS level 2 reader for IASI data.
Expand Down Expand Up @@ -68,6 +71,7 @@ def get_dataset(self, dataid, dataset_info):

def _get_xarray_dataset(self):
"""Get full xarray dataset."""
logger.debug(f"Pre-loading {self.filename!s}")
input_product = self.filename
descriptor = epsnative_reader.assemble_descriptor("IASISND02")
ipr_sequence = epsnative_reader.read_ipr_sequence(input_product)
Expand All @@ -83,12 +87,16 @@ def _get_xarray_dataset(self):

def available_datasets(self, configured_datasets):
"""Get available datasets."""
common = {"file_type": "iasi_l2_eps", "resolution": 12000,
"coordinates": ["lon", "lat"]}
common = {"file_type": "iasi_l2_eps", "resolution": 12000}
coords = {"y": "lon", "x": "lat"}
if self._nc is None:
self._nc = self._get_xarray_dataset()
for var in self._nc.data_vars:
yield (True, {"name": var} | common | self._nc[var].attrs)
extra = {}
coor = [coords[x] for x in self._nc[var].dims if x in coords]
if coor:
extra["coordinates"] = coor
yield (True, {"name": var} | common | extra | self._nc[var].attrs)


missing_values = {
Expand Down
3 changes: 2 additions & 1 deletion satpy/tests/reader_tests/test_iasisnd02.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_load(iasisndl2_file, tmp_path):
with dask.config.set(scheduler=CustomScheduler(max_computes=0)):
sc = Scene(filenames=[iasisndl2_file], reader=["iasi_l2_eps"])
sc.load(["surface_temperature", "atmospheric_temperature",
"atmospheric_water_vapour"])
"atmospheric_water_vapour", "pressure_levels_temp"])
assert sc["surface_temperature"].dims == ("y", "x")
np.testing.assert_allclose(
sc["surface_temperature"][0, 100:104],
Expand All @@ -226,3 +226,4 @@ def test_load(iasisndl2_file, tmp_path):
pyresample.SwathDefinition)
assert sc["surface_temperature"].attrs["standard_name"] == "surface_temperature"
assert sc["surface_temperature"].attrs["units"] == "K"
assert "area" not in sc["pressure_levels_temp"].attrs

0 comments on commit 7fce13a

Please sign in to comment.