From b7a8c093510f433203c7670f9f3cad77703074a4 Mon Sep 17 00:00:00 2001 From: Remi Kazeroni Date: Thu, 17 Dec 2020 13:56:54 +0100 Subject: [PATCH 1/4] fix for all vars --- .../cmor/_fixes/cmip6/awi_esm_1_1_lr.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py diff --git a/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py b/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py new file mode 100644 index 0000000000..fc02a80f17 --- /dev/null +++ b/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py @@ -0,0 +1,30 @@ +"""Fixes for AWI-ESM-1-1-LR model.""" +from ..fix import Fix + + +class AllVars(Fix): + """Fixes for all vars.""" + + def fix_metadata(self, cubes): + """ + Fix parent time units. + + Parameters + ---------- + cubes : iris.cube.CubeList + Input cubes. + + Returns + ------- + iris.cube.CubeList + + """ + parent_units = 'parent_time_units' + bad_value = 'days since 0000-01-01 00:00:00' + for cube in cubes: + try: + if cube.attributes[parent_units] == bad_value: + cube.attributes[parent_units] = 'days since 0001-01-01 00:00:00' + except: + pass + return cubes From 66126a05d4468c0ff69fc1f6acda5afee80b8ffe Mon Sep 17 00:00:00 2001 From: Remi Kazeroni Date: Mon, 25 Jan 2021 16:25:50 +0100 Subject: [PATCH 2/4] test created --- .../cmor/_fixes/cmip6/test_awi_esm_1_1_lr.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/integration/cmor/_fixes/cmip6/test_awi_esm_1_1_lr.py diff --git a/tests/integration/cmor/_fixes/cmip6/test_awi_esm_1_1_lr.py b/tests/integration/cmor/_fixes/cmip6/test_awi_esm_1_1_lr.py new file mode 100644 index 0000000000..eba75631e2 --- /dev/null +++ b/tests/integration/cmor/_fixes/cmip6/test_awi_esm_1_1_lr.py @@ -0,0 +1,38 @@ +"""Tests for the fixes of AWI-ESM-1-1-LR.""" +import iris +import pytest + +from esmvalcore.cmor._fixes.cmip6.awi_esm_1_1_lr import AllVars +from esmvalcore.cmor.fix import Fix + + +@pytest.fixture +def sample_cubes(): + ta_cube = iris.cube.Cube([1.0], var_name='ta') + tas_cube = iris.cube.Cube([3.0], var_name='tas') + return iris.cube.CubeList([ta_cube, tas_cube]) + + +def test_get_tas_fix(): + fix = Fix.get_fixes('CMIP6', 'AWI-ESM-1-1-LR', 'Amon', 'tas') + assert fix == [AllVars(None)] + + +def test_allvars_fix_metadata(sample_cubes): + for cube in sample_cubes: + cube.attributes['parent_time_units'] = 'days since 0001-01-01 00:00:00' + out_cubes = AllVars(None).fix_metadata(sample_cubes) + assert out_cubes is sample_cubes + for cube in out_cubes: + assert cube.attributes[ + 'parent_time_units'] == 'days since 0001-01-01 00:00:00' + + +def test_allvars_no_need_tofix_metadata(sample_cubes): + for cube in sample_cubes: + cube.attributes['parent_time_units'] = 'days since 0001-01-01 00:00:00' + out_cubes = AllVars(None).fix_metadata(sample_cubes) + assert out_cubes is sample_cubes + for cube in out_cubes: + assert cube.attributes[ + 'parent_time_units'] == 'days since 0001-01-01 00:00:00' From e64940ad2d2d4f5bec9ad32a5eefaf2de3ef966e Mon Sep 17 00:00:00 2001 From: Remi Kazeroni Date: Tue, 26 Jan 2021 13:51:05 +0100 Subject: [PATCH 3/4] fix failing tests --- esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py b/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py index fc02a80f17..79f6200114 100644 --- a/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py +++ b/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py @@ -4,10 +4,8 @@ class AllVars(Fix): """Fixes for all vars.""" - def fix_metadata(self, cubes): - """ - Fix parent time units. + """Fix parent time units. Parameters ---------- @@ -17,14 +15,14 @@ def fix_metadata(self, cubes): Returns ------- iris.cube.CubeList - """ parent_units = 'parent_time_units' bad_value = 'days since 0000-01-01 00:00:00' for cube in cubes: try: if cube.attributes[parent_units] == bad_value: - cube.attributes[parent_units] = 'days since 0001-01-01 00:00:00' - except: + cube.attributes[parent_units] = 'days since 0001-01-01 ' \ + + '00:00:00' + except AttributeError: pass return cubes From f1243c22cd6f9f6022beb2b38d5c2872a4abe5ed Mon Sep 17 00:00:00 2001 From: Remi Kazeroni Date: Tue, 26 Jan 2021 14:05:46 +0100 Subject: [PATCH 4/4] fix codacy --- esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py b/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py index 79f6200114..2c53d38fb4 100644 --- a/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py +++ b/esmvalcore/cmor/_fixes/cmip6/awi_esm_1_1_lr.py @@ -4,6 +4,7 @@ class AllVars(Fix): """Fixes for all vars.""" + def fix_metadata(self, cubes): """Fix parent time units.