Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix positive attributes in custom CMOR variables #2380

Merged
merged 4 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion esmvalcore/cmor/tables/custom/CMOR_clhmtisccp.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
!----------------------------------
!
1 change: 0 additions & 1 deletion esmvalcore/cmor/tables/custom/CMOR_clhtkisccp.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
!----------------------------------
!
1 change: 0 additions & 1 deletion esmvalcore/cmor/tables/custom/CMOR_cllmtisccp.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
!----------------------------------
!
1 change: 0 additions & 1 deletion esmvalcore/cmor/tables/custom/CMOR_clltkisccp.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
!----------------------------------
!
1 change: 0 additions & 1 deletion esmvalcore/cmor/tables/custom/CMOR_clmmtisccp.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
!----------------------------------
!
1 change: 0 additions & 1 deletion esmvalcore/cmor/tables/custom/CMOR_clmtkisccp.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
!----------------------------------
!
2 changes: 1 addition & 1 deletion esmvalcore/cmor/tables/custom/CMOR_lwcre.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
positive: down
!----------------------------------
!
2 changes: 1 addition & 1 deletion esmvalcore/cmor/tables/custom/CMOR_netcre.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
positive: down
!----------------------------------
!
2 changes: 1 addition & 1 deletion esmvalcore/cmor/tables/custom/CMOR_rsnt.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
positive: down
!----------------------------------
!
2 changes: 1 addition & 1 deletion esmvalcore/cmor/tables/custom/CMOR_swcre.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ comment: at the top of the atmosphere (to be compared with satellite m
!----------------------------------
dimensions: longitude latitude time
type: real
positive: up
positive: down
!----------------------------------
!
1 change: 1 addition & 0 deletions esmvalcore/preprocessor/_derive/lwcre.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ def calculate(cubes):

lwcre_cube = rlutcs_cube - rlut_cube
lwcre_cube.units = rlut_cube.units
lwcre_cube.attributes['positive'] = 'down'

return lwcre_cube
1 change: 1 addition & 0 deletions esmvalcore/preprocessor/_derive/netcre.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ def calculate(cubes):

netcre_cube = lwcre_cube + swcre_cube
netcre_cube.units = lwcre_cube.units
netcre_cube.attributes['positive'] = 'down'

return netcre_cube
2 changes: 2 additions & 0 deletions esmvalcore/preprocessor/_derive/rsnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ def calculate(cubes):
Constraint(name='toa_outgoing_shortwave_flux'))

rsnt_cube = rsdt_cube - rsut_cube
rsnt_cube.units = rsdt_cube.units
rsnt_cube.attributes['positive'] = 'down'

return rsnt_cube
2 changes: 2 additions & 0 deletions esmvalcore/preprocessor/_derive/swcre.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ def calculate(cubes):
Constraint(name='toa_outgoing_shortwave_flux_assuming_clear_sky'))

swcre_cube = rsutcs_cube - rsut_cube
swcre_cube.units = rsut_cube.units
swcre_cube.attributes['positive'] = 'down'

return swcre_cube
28 changes: 28 additions & 0 deletions tests/unit/preprocessor/_derive/test_lwcre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Test derivation of `lwcre`."""
import numpy as np
import pytest
from iris.cube import Cube, CubeList

import esmvalcore.preprocessor._derive.lwcre as lwcre


@pytest.fixture
def cubes():
rlut_cube = Cube(
3, standard_name='toa_outgoing_longwave_flux', units='W m-2'
)
rlutcs_cube = Cube(
1,
standard_name='toa_outgoing_longwave_flux_assuming_clear_sky',
units='W m-2',
)
return CubeList([rlut_cube, rlutcs_cube])


def test_lwcre_calculation(cubes):
"""Test calculation of `lwcre`."""
derived_var = lwcre.DerivedVariable()
out_cube = derived_var.calculate(cubes)
np.testing.assert_equal(out_cube.data, -2)
assert out_cube.units == 'W m-2'
assert out_cube.attributes['positive'] == 'down'
36 changes: 36 additions & 0 deletions tests/unit/preprocessor/_derive/test_netcre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Test derivation of `netcre`."""
import numpy as np
import pytest
from iris.cube import Cube, CubeList

import esmvalcore.preprocessor._derive.netcre as netcre


@pytest.fixture
def cubes():
rlut_cube = Cube(
3, standard_name='toa_outgoing_longwave_flux', units='W m-2'
)
rlutcs_cube = Cube(
1,
standard_name='toa_outgoing_longwave_flux_assuming_clear_sky',
units='W m-2',
)
rsut_cube = Cube(
3, standard_name='toa_outgoing_shortwave_flux', units='W m-2'
)
rsutcs_cube = Cube(
1,
standard_name='toa_outgoing_shortwave_flux_assuming_clear_sky',
units='W m-2',
)
return CubeList([rlut_cube, rlutcs_cube, rsut_cube, rsutcs_cube])


def test_netcre_calculation(cubes):
"""Test calculation of `netcre`."""
derived_var = netcre.DerivedVariable()
out_cube = derived_var.calculate(cubes)
np.testing.assert_equal(out_cube.data, -4)
assert out_cube.units == 'W m-2'
assert out_cube.attributes['positive'] == 'down'
26 changes: 26 additions & 0 deletions tests/unit/preprocessor/_derive/test_rsnt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Test derivation of `rsnt`."""
import numpy as np
import pytest
from iris.cube import Cube, CubeList

import esmvalcore.preprocessor._derive.rsnt as rsnt


@pytest.fixture
def cubes():
rsdt_cube = Cube(
3, standard_name='toa_incoming_shortwave_flux', units='W m-2'
)
rsut_cube = Cube(
1, standard_name='toa_outgoing_shortwave_flux', units='W m-2'
)
return CubeList([rsdt_cube, rsut_cube])


def test_rsnt_calculation(cubes):
"""Test calculation of `rsnt`."""
derived_var = rsnt.DerivedVariable()
out_cube = derived_var.calculate(cubes)
np.testing.assert_equal(out_cube.data, 2)
assert out_cube.units == 'W m-2'
assert out_cube.attributes['positive'] == 'down'
28 changes: 28 additions & 0 deletions tests/unit/preprocessor/_derive/test_swcre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Test derivation of `swcre`."""
import numpy as np
import pytest
from iris.cube import Cube, CubeList

import esmvalcore.preprocessor._derive.swcre as swcre


@pytest.fixture
def cubes():
rsut_cube = Cube(
3, standard_name='toa_outgoing_shortwave_flux', units='W m-2'
)
rsutcs_cube = Cube(
1,
standard_name='toa_outgoing_shortwave_flux_assuming_clear_sky',
units='W m-2',
)
return CubeList([rsut_cube, rsutcs_cube])


def test_swcre_calculation(cubes):
"""Test calculation of `swcre`."""
derived_var = swcre.DerivedVariable()
out_cube = derived_var.calculate(cubes)
np.testing.assert_equal(out_cube.data, -2)
assert out_cube.units == 'W m-2'
assert out_cube.attributes['positive'] == 'down'