Skip to content

Commit

Permalink
Restored/removed all ESMValCore-related files
Browse files Browse the repository at this point in the history
  • Loading branch information
schlunma committed Nov 13, 2024
1 parent c240ca4 commit 7d4d214
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 307 deletions.
59 changes: 19 additions & 40 deletions esmvaltool/cmor/_fixes/CMIP5/GFDL_ESM2G.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
# pylint: disable=invalid-name, no-self-use, too-few-public-methods
"""Fixes for GFDL ESM2G."""
"""Fixes for GFDL ESM2G"""
import iris

from iris.coords import AuxCoord
from ..fix import Fix


def _get_and_remove(cubes, long_name):
try:
cube = cubes.extract_strict(long_name)
cubes.remove(cube)
except iris.exceptions.ConstraintMismatchError:
pass


class allvars(Fix):
"""Common fixes."""

def fix_metadata(self, cubes):
"""Fix metadata.
"""
Fix metadata.
Fixes bad standard names.
Fixes bad standard names
Parameters
----------
cubes: iris.cube.CubeList
Returns
-------
iris.cube.CubeList
iris.cube.Cube
"""
_get_and_remove(cubes, 'Start time for average period')
_get_and_remove(cubes, 'End time for average period')
_get_and_remove(cubes, 'Length of average period')
self._get_and_remove(cubes, 'Start time for average period')
self._get_and_remove(cubes, 'End time for average period')
self._get_and_remove(cubes, 'Length of average period')
return cubes

def _get_and_remove(self, cubes, long_name):
try:
cube = cubes.extract_strict(long_name)
cubes.remove(cube)
except iris.exceptions.ConstraintMismatchError:
pass


class co2(Fix):
"""Fixes for co2."""

def fix_data(self, cube):
"""Fix data.
"""
Fix data.
Fixes discrepancy between declared units and real units.
Fixes discrepancy between declared units and real units
Parameters
----------
Expand All @@ -57,25 +58,3 @@ def fix_data(self, cube):
cube *= 1e6
cube.metadata = metadata
return cube


class fgco2(Fix):
"""Fixes for fgco2."""

def fix_metadata(self, cubes):
"""Fix metadata.
Remove unnecessary variables prohibiting cube concatenation.
Parameters
----------
cubes: iris.cube.CubeList
Returns
-------
iris.cube.CubeList
"""
_get_and_remove(cubes, 'Latitude of tracer (h) points')
_get_and_remove(cubes, 'Longitude of tracer (h) points')
return cubes
31 changes: 0 additions & 31 deletions esmvaltool/cmor/_fixes/CMIP5/NorESM1_ME.py

This file was deleted.

29 changes: 0 additions & 29 deletions esmvaltool/cmor/_fixes/CMIP6/BCC_CSM2_MR.py

This file was deleted.

29 changes: 0 additions & 29 deletions esmvaltool/cmor/_fixes/CMIP6/IPSL_CM6A_LR.py

This file was deleted.

23 changes: 0 additions & 23 deletions esmvaltool/cmor/tables/custom/CMOR_fgco2_grid.dat

This file was deleted.

6 changes: 3 additions & 3 deletions esmvaltool/cmor/tables/custom/CMOR_nbp_grid.dat
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ modeling_realm: land
!----------------------------------
! Variable attributes:
!----------------------------------
standard_name:
units: kg s-1
standard_name:
units: kg m-2 s-1
cell_methods: time: mean area: mean
cell_measures: area: areacella
long_name: Carbon Mass Flux out of Atmosphere due to Net Biospheric Production on Land per grid cell
long_name: Carbon Mass Flux out of Atmosphere due to Net Biospheric Production on Land (relative to grid cell area)
comment: This is the net mass flux of carbon between land and atmosphere calculated as photosynthesis MINUS the sum of plant and soil respiration, carbonfluxes from fire, harvest, grazing and land use change. Positive flux is into the land.
!----------------------------------
! Additional variable information:
Expand Down
8 changes: 4 additions & 4 deletions esmvaltool/preprocessor/_derive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def get_required(short_name):
and occasionally mip or fx_files.
"""
derived_variable = ALL_DERIVED_VARIABLES[short_name]
variables = deepcopy(derived_variable().required)
DerivedVariable = ALL_DERIVED_VARIABLES[short_name]
variables = deepcopy(DerivedVariable().required)
return variables


Expand Down Expand Up @@ -107,8 +107,8 @@ def derive(cubes,
"'%s' not found", fx_var, short_name)

# Derive variable
derived_variable = ALL_DERIVED_VARIABLES[short_name]
cube = derived_variable().calculate(cubes)
DerivedVariable = ALL_DERIVED_VARIABLES[short_name]
cube = DerivedVariable().calculate(cubes)

# Set standard attributes
cube.var_name = short_name
Expand Down
109 changes: 0 additions & 109 deletions esmvaltool/preprocessor/_derive/_shared.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
"""Auxiliary derivation functions used for multiple variables."""

import logging

import dask.array as da
import iris
from iris import Constraint

logger = logging.getLogger(__name__)


def var_name_constraint(var_name):
""":mod:`iris.Constraint` using `var_name` of a :mod:`iris.cube.Cube`."""
return Constraint(cube_func=lambda c: c.var_name == var_name)


def shape_is_broadcastable(shape_1, shape_2):
"""Check if two :mod:`numpy.array' shapes are broadcastable."""
return all((m == n) or (m == 1) or (n == 1)
for (m, n) in zip(shape_1[::-1], shape_2[::-1]))


def cloud_area_fraction(cubes, tau_constraint, plev_constraint):
Expand All @@ -37,95 +20,3 @@ def cloud_area_fraction(cubes, tau_constraint, plev_constraint):
new_cube = new_cube.collapsed('air_pressure', iris.analysis.SUM)

return new_cube


def _get_fx_cube(cubes, standard_name, fx_land_name, fx_sea_name=None):
"""Extract desired fx cubes from list of cubes."""
cube = cubes.extract_strict(Constraint(name=standard_name))
fx_cube = None
invert = False
if fx_sea_name is not None:
try:
fx_cube = cubes.extract_strict(var_name_constraint(fx_sea_name))
except iris.exceptions.ConstraintMismatchError:
logger.debug(
"Cannot correct cube '%s' with '%s', fx file not found",
standard_name, fx_sea_name)
else:
if not shape_is_broadcastable(fx_cube.shape, cube.shape):
fx_cube = None
invert = True
logger.debug(
"Cannot broadcast fx cube '%s' to cube '%s', trying '%s'",
fx_sea_name, standard_name, fx_land_name)
else:
logger.debug("Using fx cube '%s' to fix '%s'", fx_sea_name,
standard_name)
if fx_cube is None:
try:
fx_cube = cubes.extract_strict(var_name_constraint(fx_land_name))
except iris.exceptions.ConstraintMismatchError:
logger.debug(
"Cannot correct cube '%s' with '%s', fx file not found",
standard_name, fx_land_name)
else:
if not shape_is_broadcastable(fx_cube.shape, cube.shape):
fx_cube = None
invert = False
logger.debug("Cannot broadcast fx cube '%s' to cube '%s'",
fx_land_name, standard_name)
else:
logger.debug("Using fx cube '%s' to fix '%s'", fx_land_name,
standard_name)
return (fx_cube, invert)


def grid_area_correction(cubes, standard_name, integrate=True, sea_var=False):
"""Correct (flux) variable defined relative to land area and integrate."""
cube = cubes.extract_strict(Constraint(name=standard_name))
core_data = cube.core_data()

# Area fraction
(fraction_cube, invert) = _get_fx_cube(
cubes,
standard_name,
fx_land_name='sftlf',
fx_sea_name='sftof' if sea_var else None)
if fraction_cube is not None:
if not invert:
core_data *= fraction_cube.core_data() / 100.0
else:
fraction = (da.ones_like(fraction_cube.core_data()) -
fraction_cube.core_data() / 100.0)
core_data *= fraction

# Area
if integrate:
(area_cube, _) = _get_fx_cube(
cubes,
standard_name,
fx_land_name='areacella',
fx_sea_name='areacello' if sea_var else None)
if area_cube is not None:
core_data *= area_cube.core_data()
cube.units *= area_cube.units
else:
try:
logger.debug(
"Area files for cube '%s' not found, trying to calculate "
"area using cell bounds", standard_name)
for coord_name in ('latitude', 'longitude'):
if not cube.coord(coord_name).has_bounds():
cube.coord(coord_name).guess_bounds()
area = iris.analysis.cartography.area_weights(cube)
core_data *= area
except iris.exceptions.CoordinateMultiDimError as exc:
logger.error(
"Cannot integrate irregular cube '%s', necessary area "
"files not found", standard_name)
logger.error(cube)
raise exc

# Return cube
cube = cube.copy(core_data)
return cube
31 changes: 0 additions & 31 deletions esmvaltool/preprocessor/_derive/fgco2_grid.py

This file was deleted.

Loading

0 comments on commit 7d4d214

Please sign in to comment.