Skip to content

Commit ce60db7

Browse files
committed
Remove search2D from UxGrid.search
1 parent 8c01bf0 commit ce60db7

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

parcels/uxgrid.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
from typing import Literal
4+
35
import numpy as np
46
import uxarray as ux
57
from uxarray.grid.neighbors import _barycentric_coordinates
@@ -8,6 +10,8 @@
810

911
from .basegrid import BaseGrid
1012

13+
_UXGRID_AXES = Literal["Z", "CELL"]
14+
1115

1216
class UxGrid(BaseGrid):
1317
"""
@@ -49,9 +53,7 @@ def depth(self):
4953
return np.zeros(1)
5054
return self.z.values
5155

52-
def search(
53-
self, z: float, y: float, x: float, ei: int | None = None, search2D: bool = False
54-
) -> tuple[np.ndarray, int]:
56+
def search(self, z, y, x, ei=None):
5557
tol = 1e-10
5658

5759
def try_face(fid):
@@ -61,18 +63,15 @@ def try_face(fid):
6163
return None, None
6264

6365
def find_vertical_index() -> int:
64-
if search2D:
66+
nz = self.z.shape[0]
67+
if nz == 1:
6568
return 0
66-
else:
67-
nz = self.z.shape[0]
68-
if nz == 1:
69-
return 0
70-
zf = self.z.values
71-
# Return zi such that zf[zi] <= z < zf[zi+1]
72-
zi = np.searchsorted(zf, z, side="right") - 1 # Search assumes that z is positive and increasing with i
73-
if zi < 0 or zi >= nz - 1:
74-
raise FieldOutOfBoundError(z, y, x)
75-
return zi
69+
zf = self.z.values
70+
# Return zi such that zf[zi] <= z < zf[zi+1]
71+
zi = np.searchsorted(zf, z, side="right") - 1 # Search assumes that z is positive and increasing with i
72+
if zi < 0 or zi >= nz - 1:
73+
raise FieldOutOfBoundError(z, y, x)
74+
return zi
7675

7776
zi = find_vertical_index() # Find the vertical cell center nearest to z
7877

0 commit comments

Comments
 (0)