|
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 |
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
Fix fill value:
ESMValCore/esmvalcore/cmor/_fixes/cmip5/cesm1_bgc.py
Lines 8 to 26 in ea6618c
Fix hybrid sigma coordinate (more complicated, only if time permits):
ESMValCore/esmvalcore/cmor/_fixes/cmip6/cesm2.py
Lines 11 to 76 in ea6618c
The plan is that:
dacharand possibly implement the fixes mentioned above indaops.Related to #755