def test_wavelength_range_cf_roundtrip(): """Test the wavelength range object roundtrip to cf.""" from satpy.dataset.dataid import WavelengthRange wr = WavelengthRange(1, 2, 3) assert WavelengthRange.from_cf(wr.to_cf()) == wr assert WavelengthRange.from_cf([str(item) for item in wr]) == wr
def _assign_ds_info(self, var_name, val): """Assign ds_info.""" ds_info = dict(val.attrs) ds_info['file_type'] = self.filetype_info['file_type'] ds_info['name'] = ds_info['nc_store_name'] = var_name if 'original_name' in ds_info: ds_info['name'] = ds_info['original_name'] elif self._numeric_name_prefix and var_name.startswith(self._numeric_name_prefix): ds_info['name'] = var_name.replace(self._numeric_name_prefix, '') try: ds_info['wavelength'] = WavelengthRange.from_cf(ds_info['wavelength']) except KeyError: pass return ds_info
def _dynamic_datasets(self): """Add information of dynamic datasets.""" nc = xr.open_dataset(self.filename, engine=self.engine) # get dynamic variables known to this file (that we created) for var_name, val in nc.data_vars.items(): ds_info = dict(val.attrs) ds_info['file_type'] = self.filetype_info['file_type'] ds_info['name'] = var_name try: ds_info['wavelength'] = WavelengthRange.from_cf( ds_info['wavelength']) except KeyError: pass self.fix_modifier_attr(ds_info) yield True, ds_info