Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VIIRS L1B I-band angle names being inconsistent with VIIRS SDR #2260

Merged
merged 1 commit into from Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions satpy/etc/readers/viirs_l1b.yaml
Expand Up @@ -185,31 +185,31 @@ datasets:
coordinates: [i_lon, i_lat]
file_type: vl1bi
I_SOLZ:
name: i_solar_zenith_angle
name: solar_zenith_angle
standard_name: solar_zenith_angle
resolution: 371
units: degrees
coordinates: [i_lon, i_lat]
file_type: vgeoi
file_key: geolocation_data/solar_zenith
I_SOLA:
name: i_solar_azimuth_angle
name: solar_azimuth_angle
standard_name: solar_azimuth_angle
resolution: 371
units: degrees
coordinates: [i_lon, i_lat]
file_type: vgeoi
file_key: geolocation_data/solar_azimuth
I_SENZ:
name: i_satellite_zenith_angle
name: satellite_zenith_angle
standard_name: sensor_zenith_angle
resolution: 371
units: degrees
coordinates: [i_lon, i_lat]
file_type: vgeoi
file_key: geolocation_data/sensor_zenith
I_SENA:
name: i_satellite_azimuth_angle
name: satellite_azimuth_angle
standard_name: sensor_azimuth_angle
resolution: 371
units: degrees
Expand Down
86 changes: 43 additions & 43 deletions satpy/readers/yaml_reader.py
Expand Up @@ -742,34 +742,6 @@ def _load_area_def(self, dsid, file_handlers, **kwargs):
"""Load the area definition of *dsid*."""
return _load_area_def(dsid, file_handlers)

def _get_coordinates_for_dataset_key(self, dsid):
"""Get the coordinate dataset keys for *dsid*."""
ds_info = self.all_ids[dsid]
cids = []
for cinfo in ds_info.get('coordinates', []):
if not isinstance(cinfo, dict):
cinfo = {'name': cinfo}

for key in self._co_keys:
if key == 'name':
continue
if key in ds_info:
if ds_info[key] is not None:
cinfo[key] = ds_info[key]
cid = DataQuery.from_dict(cinfo)

cids.append(self.get_dataset_key(cid))

return cids

def _get_coordinates_for_dataset_keys(self, dsids):
"""Get all coordinates."""
coordinates = {}
for dsid in dsids:
cids = self._get_coordinates_for_dataset_key(dsid)
coordinates.setdefault(dsid, []).extend(cids)
return coordinates

def _get_file_handlers(self, dsid):
"""Get the file handler to load this dataset."""
ds_info = self.all_ids[dsid]
Expand All @@ -781,6 +753,21 @@ def _get_file_handlers(self, dsid):
else:
return self.file_handlers[filetype]

def _load_dataset_area(self, dsid, file_handlers, coords, **kwargs):
"""Get the area for *dsid*."""
try:
return self._load_area_def(dsid, file_handlers, **kwargs)
except NotImplementedError:
if any(x is None for x in coords):
logger.warning(
"Failed to load coordinates for '{}'".format(dsid))
return None

area = self._make_area_from_coords(coords)
if area is None:
logger.debug("No coordinates found for %s", str(dsid))
return area

def _make_area_from_coords(self, coords):
"""Create an appropriate area with the given *coords*."""
if len(coords) == 2:
Expand Down Expand Up @@ -822,21 +809,6 @@ def _make_swath_definition_from_lons_lats(self, lons, lats):
FileYAMLReader._coords_cache[key] = sdef
return sdef

def _load_dataset_area(self, dsid, file_handlers, coords, **kwargs):
"""Get the area for *dsid*."""
try:
return self._load_area_def(dsid, file_handlers, **kwargs)
except NotImplementedError:
if any(x is None for x in coords):
logger.warning(
"Failed to load coordinates for '{}'".format(dsid))
return None

area = self._make_area_from_coords(coords)
if area is None:
logger.debug("No coordinates found for %s", str(dsid))
return area

def _load_dataset_with_area(self, dsid, coords, **kwargs):
"""Load *dsid* and its area if available."""
file_handlers = self._get_file_handlers(dsid)
Expand Down Expand Up @@ -965,6 +937,34 @@ def load(self, dataset_keys, previous_datasets=None, **kwargs):

return datasets

def _get_coordinates_for_dataset_keys(self, dsids):
"""Get all coordinates."""
coordinates = {}
for dsid in dsids:
cids = self._get_coordinates_for_dataset_key(dsid)
coordinates.setdefault(dsid, []).extend(cids)
return coordinates

def _get_coordinates_for_dataset_key(self, dsid):
"""Get the coordinate dataset keys for *dsid*."""
ds_info = self.all_ids[dsid]
cids = []
for cinfo in ds_info.get('coordinates', []):
if not isinstance(cinfo, dict):
cinfo = {'name': cinfo}

for key in self._co_keys:
if key == 'name':
continue
if key in ds_info:
if ds_info[key] is not None:
cinfo[key] = ds_info[key]
cid = DataQuery.from_dict(cinfo)

cids.append(self.get_dataset_key(cid))

return cids


def _load_area_def(dsid, file_handlers):
"""Load the area definition of *dsid*."""
Expand Down
23 changes: 23 additions & 0 deletions satpy/tests/reader_tests/test_viirs_l1b.py
Expand Up @@ -272,6 +272,29 @@ def test_load_every_m_band_rad(self):
assert v.attrs['area'].lats.attrs['rows_per_scan'] == 2
assert v.attrs['sensor'] == "viirs"

def test_load_i_band_angles(self):
"""Test loading all M bands as radiances."""
from satpy.readers import load_reader
from satpy.tests.utils import make_dataid
r = load_reader(self.reader_configs)
loadables = r.select_files_from_pathnames([
'VL1BI_snpp_d20161130_t012400_c20161130054822.nc',
'VL1BM_snpp_d20161130_t012400_c20161130054822.nc',
'VGEOI_snpp_d20161130_t012400_c20161130054822.nc',
'VGEOM_snpp_d20161130_t012400_c20161130054822.nc',
])
r.create_filehandlers(loadables)
datasets = r.load([
make_dataid(name='satellite_zenith_angle'),
make_dataid(name='satellite_azimuth_angle'),
make_dataid(name='solar_azimuth_angle'),
make_dataid(name='solar_zenith_angle'),
])
assert len(datasets) == 4
for v in datasets.values():
assert v.attrs['resolution'] == 371
assert v.attrs['sensor'] == "viirs"

def test_load_dnb_radiance(self):
"""Test loading the main DNB dataset."""
from satpy.readers import load_reader
Expand Down