Skip to content
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e019ab5
added custom CMOR tables for ESACCI-PERMAFROST
axel-lauer Feb 28, 2024
fbce425
added new coordinate to custom coordinate table
axel-lauer Feb 28, 2024
cc102fa
changed sdepth to depth
axel-lauer Mar 4, 2024
c38bda3
Merge branch 'main' into esacci-permafrost
axel-lauer Jun 12, 2024
659494d
added derivation script for permafrost extent (pfr)
axel-lauer Jun 14, 2024
b4f46b9
permafrost extent: switched from sftgif to mrsos
axel-lauer Jun 17, 2024
0c86835
Merge branch 'main' into esacci-permafrost
axel-lauer Jul 23, 2025
4db4a42
updated pfr.py
axel-lauer Jul 23, 2025
9ee7825
Update esmvalcore/preprocessor/_derive/pfr.py
axel-lauer Dec 19, 2025
480d33d
fix ruff issues
axel-lauer Dec 19, 2025
26c19da
update pfr.py
axel-lauer Dec 19, 2025
e562830
removed comments
axel-lauer Dec 19, 2025
f4fb071
Merge branch 'main' into esacci-permafrost
axel-lauer Dec 19, 2025
b616d92
non-working draft of pfr derivation unit test
axel-lauer Dec 19, 2025
8a92845
added test for derived variable pfr
axel-lauer Jan 9, 2026
1db80de
pre-commit results
axel-lauer Jan 9, 2026
5d0f518
Update esmvalcore/preprocessor/_derive/pfr.py
axel-lauer Jan 13, 2026
66eb70a
Merge branch 'main' into esacci-permafrost
axel-lauer Jan 13, 2026
b3d0fca
extended unit test for derivation of pfr
axel-lauer Jan 13, 2026
3177cd8
Merge branch 'esacci-permafrost' of github.com:ESMValGroup/ESMValCore…
axel-lauer Jan 13, 2026
d370a3b
update test_pfr.py
axel-lauer Jan 13, 2026
01c8227
Update esmvalcore/preprocessor/_derive/pfr.py
axel-lauer Jan 15, 2026
cce9088
Update esmvalcore/preprocessor/_derive/pfr.py
axel-lauer Jan 15, 2026
59bc9c0
Update esmvalcore/preprocessor/_derive/pfr.py
axel-lauer Jan 15, 2026
ee34de9
split unit tests into separate functions
axel-lauer Jan 15, 2026
f20e3d7
updated pfr
axel-lauer Jan 15, 2026
c5453bb
Merge branch 'main' into esacci-permafrost
axel-lauer Jan 15, 2026
6913302
Update esmvalcore/preprocessor/_derive/pfr.py
axel-lauer Jan 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
extended unit test for derivation of pfr
  • Loading branch information
axel-lauer committed Jan 13, 2026
commit b3d0fca2d50944e70527574dd824d47c1a8ef911
45 changes: 39 additions & 6 deletions tests/unit/preprocessor/_derive/test_pfr.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Test derivation of ``pfr``."""

import copy

import cf_units
import iris
import numpy as np
import pytest
from iris import NameConstraint

from esmvalcore.preprocessor._derive import pfr

Expand Down Expand Up @@ -79,8 +82,8 @@ def cubes():
)
coord_specs = [
(time_coord, 0),
(lat_coord, 1),
(lon_coord, 2),
(copy.deepcopy(lat_coord), 1),
(copy.deepcopy(lon_coord), 2),
]
mrsos_data = np.zeros(shape=(24, 2, 2))
mrsos_data[:, :, :] = 10.0
Expand All @@ -92,8 +95,8 @@ def cubes():
standard_name="mass_content_of_water_in_soil_layer",
)
coord_specs = [
(lat_coord, 0),
(lon_coord, 1),
(copy.deepcopy(lat_coord), 0),
(copy.deepcopy(lon_coord), 1),
]
sftlf_data = np.zeros(shape=(2, 2))
sftlf_data[:, :] = 100.0
Expand All @@ -110,13 +113,43 @@ def cubes():

def test_pfr_calculation(cubes):
"""Test function ``calculate``."""
in_cubes = cubes
derived_var = pfr.DerivedVariable()
out_cube = derived_var.calculate(cubes)
iris.save(out_cube, "./pfr.nc")
out_cube = derived_var.calculate(in_cubes)
assert out_cube.units == cf_units.Unit("%")
out_data = out_cube.data
expected = 100.0 * np.ones_like(out_cube.data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a test case where not the entire cube is permafrost because this doesn't really check that the calculation is correct.

np.testing.assert_array_equal(out_data, expected)
# test small differences in lat/lon coordinates in sftlf and mrsos
# (1) small deviations (< 1.0e-4)
for cube in in_cubes:
if cube.coords("year"):
cube.remove_coord("year")
sftlf_cube = in_cubes.extract_cube(NameConstraint(var_name="sftlf"))
x_coord = sftlf_cube.coord(axis="X")
y_coord = sftlf_cube.coord(axis="X")
x_coord.points = x_coord.core_points() + 1.0e-5
y_coord.points = y_coord.core_points() + 1.0e-5
out_cube = derived_var.calculate(in_cubes)
# small differences are corrected automatically --> expect same results
out_data = out_cube.data
np.testing.assert_array_equal(out_data, expected)
# (2) larger deviations in coordinates should trigger an error
# and thus need to be checked separately
# (a) latitudes
for cube in in_cubes:
if cube.coords("year"):
cube.remove_coord("year")
y_coord.points = y_coord.core_points() + 1.0e-2
with pytest.raises(ValueError):
derived_var.calculate(in_cubes)
# (b) longitudes
for cube in in_cubes:
if cube.coords("year"):
cube.remove_coord("year")
x_coord.points = x_coord.core_points() + 1.0e-2
with pytest.raises(ValueError):
derived_var.calculate(in_cubes)


def test_pfr_required():
Expand Down