Skip to content

Commit

Permalink
Introduction of the variable prodlnox for EMAC (#2499)
Browse files Browse the repository at this point in the history
Co-authored-by: Manuel Schlund <[email protected]>
Co-authored-by: Manuel Schlund <[email protected]>
  • Loading branch information
3 people authored Aug 6, 2024
1 parent 03b6871 commit 9636505
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
28 changes: 28 additions & 0 deletions esmvalcore/cmor/_fixes/emac/emac.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,34 @@ def fix_metadata(self, cubes):
return CubeList([cube])


class Prodlnox(EmacFix):
"""Fixes for ``prodlnox``."""

def fix_metadata(self, cubes):
"""Fix metadata."""
noxcg_cube = self.get_cube(
cubes, var_name=['NOxcg_cav', 'NOxcg_ave', 'NOxcg']
)
noxic_cube = self.get_cube(
cubes, var_name=['NOxic_cav', 'NOxic_ave', 'NOxic']
)
dt_cube = self.get_cube(cubes, var_name='dt')

cube = ((
noxcg_cube.collapsed(
['longitude', 'latitude'], iris.analysis.SUM, weights=None
) +
noxic_cube.collapsed(
['longitude', 'latitude'], iris.analysis.SUM, weights=None
)) /
dt_cube
)
cube.units = 'kg s-1'
cube.var_name = self.vardef.short_name

return CubeList([cube])


Evspsbl = NegateData


Expand Down
20 changes: 20 additions & 0 deletions esmvalcore/cmor/tables/custom/CMOR_prodlnox.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SOURCE: CMIP6
!============
variable_entry: prodlnox
!============
modeling_realm: atmos
!----------------------------------
! Variable attributes:
!----------------------------------
standard_name:
units: kg s-1
long_name: Tendency of atmosphere mass content of NOx from lightning
comment: Production NOX (NO+NO2) by lightning globally integrated
!----------------------------------
! Additional variable information:
!----------------------------------
dimensions: time
out_name: prodlnox
type: real
!----------------------------------
!
2 changes: 2 additions & 0 deletions esmvalcore/config/extra_facets/emac-mappings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ EMAC:
prc:
raw_name: [aprc_cav, aprc_ave, aprc]
channel: Amon
prodlnox: # derived from NOxcg_*, NOxic_*
channel: Amon
prl: # non-CMOR variable
raw_name: [aprl_cav, aprl_ave, aprl]
channel: Amon
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/cmor/_fixes/emac/test_emac.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MP_SS_tot,
Od550aer,
Pr,
Prodlnox,
Rlds,
Rlus,
Rlut,
Expand Down Expand Up @@ -931,6 +932,36 @@ def test_clwvi_fix(cubes_2d):
np.testing.assert_allclose(cube.data, [[[2.0]]])


def test_get_prodlnox_fix():
"""Test getting of fix."""
fix = Fix.get_fixes('EMAC', 'EMAC', 'Amon', 'prodlnox')
assert fix == [Prodlnox(None), AllVars(None), GenericFix(None)]


def test_prodlnox_fix(cubes_2d):
"""Test fix."""
cubes_2d[0].var_name = 'NOxcg_cav'
cubes_2d[1].var_name = 'NOxic_cav'
cubes_2d[2].var_name = 'dt'
cubes_2d[0].units = 'kg'
cubes_2d[1].units = 'kg'
cubes_2d[2].units = 's'

fixed_cubes = fix_metadata(cubes_2d, 'Amon', 'prodlnox')

assert len(fixed_cubes) == 1
cube = fixed_cubes[0]
assert cube.var_name == 'prodlnox'
assert cube.standard_name is None
assert cube.long_name == (
'Tendency of atmosphere mass content of NOx from lightning'
)
assert cube.units == 'kg s-1'
assert 'positive' not in cube.attributes

np.testing.assert_allclose(cube.data, [[[2.0]]])


def test_get_co2mass_fix():
"""Test getting of fix."""
fix = Fix.get_fixes('EMAC', 'EMAC', 'Amon', 'co2mass')
Expand Down

0 comments on commit 9636505

Please sign in to comment.