Skip to content
This repository has been archived by the owner on May 2, 2024. It is now read-only.

Commit

Permalink
Enable broadcasting in vertical interpolation (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfkanesan authored Apr 17, 2024
1 parent cac54a8 commit 6be8648
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/idpi/operators/vertical_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,13 @@ def interpolate_k2p(
"interpolate_k2p: pressure field must be defined on model levels"
)
# Check that dimensions are the same for field and p_field
if (
field.origin_z != p_field.origin_z
or field.dims != p_field.dims
or field.size != p_field.size
):
if field.origin_z != p_field.origin_z:
raise RuntimeError(
"interpolate_k2p: field and p_field must have equal "
"origin, dimensions and size"
"interpolate_k2p: field and p_field must have equal vertical staggering"
)

# Prepare output field field_on_tc on target coordinates
field_on_tc = init_field_with_vcoord(field, tc, np.nan)
field_on_tc = init_field_with_vcoord(field.broadcast_like(p_field), tc, np.nan)

# Interpolate
# ... prepare interpolation
Expand Down Expand Up @@ -268,7 +263,7 @@ def interpolate_k2theta(
)

# Prepare output field field_on_tc on target coordinates
field_on_tc = init_field_with_vcoord(field, tc, np.nan)
field_on_tc = init_field_with_vcoord(field.broadcast_like(th_field), tc, np.nan)

# Interpolate
# ... prepare interpolation
Expand Down Expand Up @@ -375,7 +370,7 @@ def interpolate_k2any(
)

# Prepare output field field_on_tc on target coordinates
field_on_tc = init_field_with_vcoord(field, tc, np.nan)
field_on_tc = init_field_with_vcoord(field.broadcast_like(tc_field), tc, np.nan)

# Interpolate
# ... prepare interpolation
Expand Down
2 changes: 1 addition & 1 deletion tests/test_idpi/test_intpl_k2any.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_intpl_k2theta(data_dir, fieldextra):
reader = GribReader.from_files([cdatafile, datafile])
ds = reader.load_fieldnames(["DBZ", "HHL"])

hfl = destagger(ds["HHL"], "z")
hfl = destagger(ds["HHL"].squeeze(drop=True), "z")

# call interpolation operator
echo_top = interpolate_k2any(hfl, "high_fold", ds["DBZ"], tc_values, hfl)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_idpi/test_intpl_k2theta.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_intpl_k2theta(mode, data_dir, fieldextra):
ds = reader.load_fieldnames(["P", "T", "HHL"])

theta = compute_theta(ds["P"], ds["T"])
hfl = destagger(ds["HHL"], "z")
hfl = destagger(ds["HHL"].squeeze(drop=True), "z")

# call interpolation operator
t = interpolate_k2theta(ds["T"], mode, theta, tc_values, tc_units, hfl)
Expand Down

0 comments on commit 6be8648

Please sign in to comment.