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

Already on GitHub? Sign in to your account

fix geopotential_height chunks #281

Merged
merged 1 commit into from
Dec 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Fix the `ERA5` interface when making a pressure-level request with a single pressure level. This change accommodates CDS-Beta server behavior. Previously, a ValueError was raised in this case.
- Bypass the ValueError raised by `dask.array.gradient` when the input array is not correctly chunk along the level dimension. Previously, `Cocip` would raise an error when computing tau cirrus in the case that the `met` data had single chunks along the level dimension.

## v0.54.3

Expand Down
9 changes: 8 additions & 1 deletion pycontrails/models/tau_cirrus.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ def tau_cirrus(met: MetDataset) -> xr.DataArray:
met.data["air_pressure"],
)

dz = -dask.array.gradient(geopotential_height, axis=geopotential_height.get_axis_num("level"))
# dask.array.gradient expects at least 2 elements in each chunk
level_axis = geopotential_height.get_axis_num("level")
if geopotential_height.chunks:
level_chunks = geopotential_height.chunks[level_axis] # type: ignore[call-overload, index]
if any(chunk < 2 for chunk in level_chunks):
geopotential_height = geopotential_height.chunk(level=-1)

dz = -dask.array.gradient(geopotential_height, axis=level_axis)
dz = xr.DataArray(dz, dims=geopotential_height.dims)

da = beta_e * dz
Expand Down
Loading