Skip to content

Commit 937d440

Browse files
Update compute_vertical_coordinates for new parameter 'key'
1 parent 2cac6e9 commit 937d440

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

cf/field.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9514,7 +9514,8 @@ def domain_mask(self, **kwargs):
95149514
@_inplace_enabled(default=False)
95159515
@_manage_log_level_via_verbosity
95169516
def compute_vertical_coordinates(
9517-
self, default_to_zero=True, strict=True, inplace=False, verbose=None
9517+
self, default_to_zero=True,
9518+
strict=True, inplace=False, verbose=None, key=False
95189519
):
95199520
"""Compute non-parametric vertical coordinates.
95209521

@@ -9622,9 +9623,16 @@ def compute_vertical_coordinates(
96229623
"""
96239624
f = _inplace_enabled_define_and_cleanup(self)
96249625

9626+
if inplace and key:
9627+
raise ValueError(
9628+
"Can't set both key=True and inplace=True, since inplace "
9629+
"will always do the operation in-place and return None."
9630+
)
9631+
96259632
detail = is_log_level_detail(logger)
96269633
debug = is_log_level_debug(logger)
96279634

9635+
return_key = None # in case there are no vertical coords to compute
96289636
for cr in f.coordinate_references(todict=True).values():
96299637
# --------------------------------------------------------
96309638
# Compute the non-parametric vertical coordinates, if
@@ -9666,20 +9674,25 @@ def compute_vertical_coordinates(
96669674
f"{c.dump(display=False, _level=1)}"
96679675
) # pragma: no cover
96689676

9669-
key = f.set_construct(c, axes=computed_axes, copy=False)
9677+
return_key = f.set_construct(c, axes=computed_axes, copy=False)
96709678

96719679
# Reference the new coordinates from the coordinate
96729680
# reference construct
9673-
cr.set_coordinate(key)
9681+
cr.set_coordinate(return_key)
96749682

96759683
if debug:
96769684
logger.debug(
9677-
f"Non-parametric coordinates construct key: {key!r}\n"
9685+
"Non-parametric coordinates construct key: "
9686+
f"{return_key!r}\n"
96789687
"Updated coordinate reference construct:\n"
96799688
f"{cr.dump(display=False, _level=1)}"
96809689
) # pragma: no cover
96819690

9682-
return f
9691+
if key:
9692+
# 2-tuple, where return_key will be None if nothing was computed
9693+
return f, return_key
9694+
else:
9695+
return f
96839696

96849697
def match_by_construct(self, *identities, OR=False, **conditions):
96859698
"""Whether or not there are particular metadata constructs.

0 commit comments

Comments
 (0)