@@ -9514,7 +9514,8 @@ def domain_mask(self, **kwargs):
9514
9514
@_inplace_enabled(default=False)
9515
9515
@_manage_log_level_via_verbosity
9516
9516
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
9518
9519
):
9519
9520
"""Compute non-parametric vertical coordinates.
9520
9521
@@ -9622,9 +9623,16 @@ def compute_vertical_coordinates(
9622
9623
"""
9623
9624
f = _inplace_enabled_define_and_cleanup(self)
9624
9625
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
+
9625
9632
detail = is_log_level_detail(logger)
9626
9633
debug = is_log_level_debug(logger)
9627
9634
9635
+ return_key = None # in case there are no vertical coords to compute
9628
9636
for cr in f.coordinate_references(todict=True).values():
9629
9637
# --------------------------------------------------------
9630
9638
# Compute the non-parametric vertical coordinates, if
@@ -9666,20 +9674,25 @@ def compute_vertical_coordinates(
9666
9674
f"{c.dump(display=False, _level=1)}"
9667
9675
) # pragma: no cover
9668
9676
9669
- key = f.set_construct(c, axes=computed_axes, copy=False)
9677
+ return_key = f.set_construct(c, axes=computed_axes, copy=False)
9670
9678
9671
9679
# Reference the new coordinates from the coordinate
9672
9680
# reference construct
9673
- cr.set_coordinate(key )
9681
+ cr.set_coordinate(return_key )
9674
9682
9675
9683
if debug:
9676
9684
logger.debug(
9677
- f"Non-parametric coordinates construct key: {key!r}\n"
9685
+ "Non-parametric coordinates construct key: "
9686
+ f"{return_key!r}\n"
9678
9687
"Updated coordinate reference construct:\n"
9679
9688
f"{cr.dump(display=False, _level=1)}"
9680
9689
) # pragma: no cover
9681
9690
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
9683
9696
9684
9697
def match_by_construct(self, *identities, OR=False, **conditions):
9685
9698
"""Whether or not there are particular metadata constructs.
0 commit comments