Skip to content

Lazy derivation of vegfrac #2452

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
31 changes: 24 additions & 7 deletions esmvalcore/preprocessor/_derive/vegfrac.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Derivation of variable `vegFrac`."""

import dask.array as da
import iris
from iris import NameConstraint

from .._regrid import regrid
from .._shared import broadcast_to_shape
from ._baseclass import DerivedVariableBase


Expand All @@ -15,9 +15,16 @@
def required(project):
"""Declare the variables needed for derivation."""
required = [
{"short_name": "baresoilFrac"},
{"short_name": "residualFrac"},
{"short_name": "sftlf", "mip": "fx"},
{
"short_name": "baresoilFrac",
},
{
"short_name": "residualFrac",
},
{
"short_name": "sftlf",
"mip": "fx",
},
]
return required

Expand All @@ -34,11 +41,21 @@

# Add time dimension to sftlf
target_shape_sftlf = (baresoilfrac_cube.shape[0], *sftlf_cube.shape)
sftlf_data = iris.util.broadcast_to_shape(
sftlf_cube.data, target_shape_sftlf, (1, 2)
target_chunks_sftlf = (

Check warning on line 44 in esmvalcore/preprocessor/_derive/vegfrac.py

View check run for this annotation

Codecov / codecov/patch

esmvalcore/preprocessor/_derive/vegfrac.py#L44

Added line #L44 was not covered by tests
tuple(
baresoilfrac_cube.lazy_data().chunks[0],
*sftlf_cube.lazy_data().chunks,
)
if baresoilfrac_cube.has_lazy_data()
else None
)
sftlf_data = broadcast_to_shape(

Check warning on line 52 in esmvalcore/preprocessor/_derive/vegfrac.py

View check run for this annotation

Codecov / codecov/patch

esmvalcore/preprocessor/_derive/vegfrac.py#L52

Added line #L52 was not covered by tests
sftlf_cube.core_data(),
target_shape_sftlf,
dim_map=(1, 2),
chunks=target_chunks_sftlf,
)
sftlf_cube = baresoilfrac_cube.copy(sftlf_data)
sftlf_cube.data = sftlf_cube.lazy_data()

# Regrid sftlf if necessary and adapt mask
if sftlf_cube.shape != baresoilfrac_cube.shape:
Expand Down