Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(structuredgrid): add method to to get ij from point(s) in real world coordinates #1205

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions flopy/discretization/structuredgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,30 @@ def get_node(self, lrc_list):
v.append(node)
return v

def get_ij(self, x, y):
"""Return the row and column of a point or sequence of points
in real-world coordinates.

Parameters
----------
x : scalar or sequence of x coordinates
y : scalar or sequence of y coordinates

Returns
-------
i : row or sequence of rows (zero-based)
j : column or sequence of columns (zero-based)
"""
if np.isscalar(x):
c = (np.abs(self.xcellcenters[0] - x)).argmin()
r = (np.abs(self.ycellcenters[:, 0] - y)).argmin()
else:
xcp = np.array([self.xcellcenters[0]] * (len(x)))
ycp = np.array([self.ycellcenters[:, 0]] * (len(x)))
c = (np.abs(xcp.transpose() - x)).argmin(axis=0)
r = (np.abs(ycp.transpose() - y)).argmin(axis=0)
return r, c

def plot(self, **kwargs):
"""
Plot the grid lines.
Expand Down