You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: extract_model/extract_model.py
+9-3Lines changed: 9 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -698,10 +698,13 @@ def sel2d(
698
698
mask: Optional[DataArray] =None,
699
699
use_xoak: bool=True,
700
700
return_info: bool=False,
701
+
k: Optional[int] =None,
701
702
**kwargs,
702
703
):
703
704
"""Find the value of the var at closest location to inputs, optionally respecting mask.
704
705
706
+
Note: I don't think this function selects for time or depth, only for horizontal coordinates. If you need to select for time or depth, use `select` instead.
707
+
705
708
This is meant to mimic `xarray` `.sel()` in API and idea, except that the horizontal selection is done for 2D coordinates instead of 1D coordinates, since `xarray` cannot yet handle 2D coordinates. This wraps `xoak`.
706
709
707
710
Order of inputs is important:
@@ -729,10 +732,12 @@ def sel2d(
729
732
If True, use xoak to find nearest 1 point. If False, use BallTree directly to find distances and nearest 4 points.
730
733
return_info: bool
731
734
If True, return a dict of extra information that depends on what processes were run.
735
+
k: int, optional
736
+
For not xoak — number of nearest neighbors to find. Default is either 1 or 50 depending on if a mask is input, but can be overridden by user with this input.
732
737
733
738
Returns
734
739
-------
735
-
An xarray object of the same type as input as var which is selected in horizontal coordinates to input locations and, in input, to time and vertical selections. If not selected, other dimensions are brought along. Other items returned in kwargs include:
740
+
An xarray object of the same type as input as var which is selected in horizontal coordinates to input locations and, if input, to time and vertical selections. If not selected, other dimensions are brought along. Other items returned in kwargs include:
736
741
737
742
* distances: the distances from the requested points to the returned nearest points
738
743
@@ -900,6 +905,7 @@ def sel2d(
900
905
901
906
# make sure the mask matches
902
907
ifmaskisnotNone:
908
+
# import pdb; pdb.set_trace()
903
909
msg=f"Mask {mask.name} dimensions do not match horizontal var {var.name} dimensions. mask dims: {mask.dims}, var dims: {var.dims}"
904
910
assertlen(set(mask.dims) -set(var.dims)) ==0, msg
905
911
@@ -908,11 +914,11 @@ def sel2d(
908
914
# if no mask, assume user just wants 1 nearest point to each input lons/lats pair
909
915
# probably should expand this later to be more generic
910
916
ifmaskisNone:
911
-
k=1
917
+
k=kor1
912
918
# if user inputs mask, use it to only return the nearest point that is active
0 commit comments