-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Labels
cmorRelated to the CMOR standardRelated to the CMOR standardfix for datasetRelated to dataset-specific fix filesRelated to dataset-specific fix files
Description
It would be nice to demo how we could use the character/fixes defined by dachar to fix data with daops and then convert that from an xarray to iris cube for use in the ESMValCore.
Example fixes:
Fix standard name:
ESMValCore/esmvalcore/cmor/_fixes/cmip5/hadgem2_cc.py
Lines 34 to 55 in ea6618c
| class O2(Fix): | |
| """Fixes for o2.""" | |
| def fix_metadata(self, cubes): | |
| """ | |
| Fix standard and long names. | |
| Parameters | |
| ---------- | |
| cube: iris.cube.CubeList | |
| Returns | |
| ------- | |
| iris.cube.CubeList | |
| """ | |
| std = 'mole_concentration_of_dissolved_molecular_oxygen_in_sea_water' | |
| long_name = 'Dissolved Oxygen Concentration' | |
| cubes[0].long_name = long_name | |
| cubes[0].standard_name = std | |
| return cubes |
Fix fill value:
ESMValCore/esmvalcore/cmor/_fixes/cmip5/cesm1_bgc.py
Lines 8 to 26 in ea6618c
| class Gpp(Fix): | |
| """Fixes for gpp variable.""" | |
| def fix_data(self, cube): | |
| """Fix data. | |
| Fix missing values. | |
| Parameters | |
| ---------- | |
| cube: iris.cube.Cube | |
| Returns | |
| ------- | |
| iris.cube.Cube | |
| """ | |
| data = da.ma.masked_equal(cube.core_data(), 1.0e33) | |
| return cube.copy(data) |
Fix hybrid sigma coordinate (more complicated, only if time permits):
ESMValCore/esmvalcore/cmor/_fixes/cmip6/cesm2.py
Lines 11 to 76 in ea6618c
| class Cl(Fix): | |
| """Fixes for ``cl``.""" | |
| def _fix_formula_terms(self, filepath, output_dir): | |
| """Fix ``formula_terms`` attribute.""" | |
| new_path = self.get_fixed_filepath(output_dir, filepath) | |
| copyfile(filepath, new_path) | |
| dataset = Dataset(new_path, mode='a') | |
| dataset.variables['lev'].formula_terms = 'p0: p0 a: a b: b ps: ps' | |
| dataset.variables['lev'].standard_name = ( | |
| 'atmosphere_hybrid_sigma_pressure_coordinate') | |
| dataset.close() | |
| return new_path | |
| def fix_data(self, cube): | |
| """Fix data. | |
| Fixed ordering of vertical coordinate. | |
| Parameters | |
| ---------- | |
| cube: iris.cube.Cube | |
| Input cube to fix. | |
| Returns | |
| ------- | |
| iris.cube.Cube | |
| """ | |
| (z_axis,) = cube.coord_dims(cube.coord(axis='Z', dim_coords=True)) | |
| indices = [slice(None)] * cube.ndim | |
| indices[z_axis] = slice(None, None, -1) | |
| cube = cube[tuple(indices)] | |
| return cube | |
| def fix_file(self, filepath, output_dir): | |
| """Fix hybrid pressure coordinate. | |
| Adds missing ``formula_terms`` attribute to file. | |
| Note | |
| ---- | |
| Fixing this with :mod:`iris` in ``fix_metadata`` or ``fix_data`` is | |
| **not** possible, since the bounds of the vertical coordinates ``a`` | |
| and ``b`` are not present in the loaded :class:`iris.cube.CubeList`, | |
| even when :func:`iris.load_raw` is used. | |
| Parameters | |
| ---------- | |
| filepath : str | |
| Path to the original file. | |
| output_dir : str | |
| Path of the directory where the fixed file is saved to. | |
| Returns | |
| ------- | |
| str | |
| Path to the fixed file. | |
| """ | |
| new_path = self._fix_formula_terms(filepath, output_dir) | |
| dataset = Dataset(new_path, mode='a') | |
| dataset.variables['a_bnds'][:] = dataset.variables['a_bnds'][::-1, :] | |
| dataset.variables['b_bnds'][:] = dataset.variables['b_bnds'][::-1, :] | |
| dataset.close() | |
| return new_path |
The plan is that:
- @agstephens or one of his team members will prepare the character and fix .json files with
dacharand possibly implement the fixes mentioned above indaops. - Someone from @ESMValGroup/esmvaltool-coreteam (@jvegasbsc would you have time?) Will make a demo how this could be used to load the fixed data into the ESMValCore.
Related to #755
valeriupredoi and jvegreg
Metadata
Metadata
Labels
cmorRelated to the CMOR standardRelated to the CMOR standardfix for datasetRelated to dataset-specific fix filesRelated to dataset-specific fix files