Skip to content

Demo use of dachar and daops for fixing data #787

@bouweandela

Description

@bouweandela

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:

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:

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):

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 dachar and possibly implement the fixes mentioned above in daops.
  • 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

Metadata

Metadata

Labels

cmorRelated to the CMOR standardfix for datasetRelated to dataset-specific fix files

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions