Skip to content

Commit

Permalink
Added fix for wrong units of clt for CIESM and FIO-ESM-2-0 (#2330)
Browse files Browse the repository at this point in the history
  • Loading branch information
schlunma authored Feb 9, 2024
1 parent 6f879cf commit c6fda9f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
29 changes: 26 additions & 3 deletions esmvalcore/cmor/_fixes/cmip6/ciesm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,32 @@ def fix_data(self, cube):
-------
iris.cube.Cube
"""
metadata = cube.metadata
cube *= 100
cube.metadata = metadata
if cube.core_data().max() <= 1.0:
cube.units = '1'
cube.convert_units('%')
return cube


class Clt(Fix):
"""Fixes for clt."""

def fix_data(self, cube):
"""Fix data.
Fixes discrepancy between declared units and real units.
Parameters
----------
cube: iris.cube.Cube
Input cube.
Returns
-------
iris.cube.Cube
"""
if cube.core_data().max() <= 1.0:
cube.units = '1'
cube.convert_units('%')
return cube


Expand Down
23 changes: 23 additions & 0 deletions esmvalcore/cmor/_fixes/cmip6/fio_esm_2_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,26 @@ def fix_metadata(self, cubes):
longitude.bounds = None
longitude.guess_bounds()
return cubes


class Clt(Fix):
"""Fixes for clt."""

def fix_data(self, cube):
"""Fix data.
Fixes discrepancy between declared units and real units.
Parameters
----------
cube: iris.cube.Cube
Input cube.
Returns
-------
iris.cube.Cube
"""
if cube.core_data().max() <= 1.0:
cube.units = '1'
cube.convert_units('%')
return cube
12 changes: 11 additions & 1 deletion tests/integration/cmor/_fixes/cmip6/test_ciesm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Tests for the fixes of CIESM."""
import iris.cube
import numpy as np
import pytest

from esmvalcore.cmor._fixes.cmip6.ciesm import Cl
Expand Down Expand Up @@ -38,8 +39,17 @@ def test_cl_fix_data(cl_cube):
assert out_cube.data == [100.0]


def test_clt_fix():
"""Test `Clt.fix_data`."""
cube = iris.cube.Cube(0.5)
fix = Fix.get_fixes('CMIP6', 'CIESM', 'Amon', 'clt')[0]
out_cube = fix.fix_data(cube)
np.testing.assert_allclose(out_cube.data, 50.0)
assert out_cube.units == '%'


def test_pr_fix():
"""Test `Pr.fix_metadata`."""
"""Test `Pr.fix_data`."""
cube = iris.cube.Cube(
[2.82e-08],
var_name='pr',
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/cmor/_fixes/cmip6/test_fio_esm_2_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
from esmvalcore.cmor.table import get_var_info


def test_clt_fix():
"""Test `Clt.fix_data`."""
cube = iris.cube.Cube(0.5)
fix = Fix.get_fixes('CMIP6', 'FIO-ESM-2-0', 'Amon', 'clt')[0]
out_cube = fix.fix_data(cube)
np.testing.assert_allclose(out_cube.data, 50.0)
assert out_cube.units == '%'


def test_get_tas_fix():
"""Test getting of fix."""
fix = Fix.get_fixes('CMIP6', 'FIO-ESM-2-0', 'Amon', 'tas')
Expand Down

0 comments on commit c6fda9f

Please sign in to comment.