Skip to content

Commit

Permalink
fix(binaryfile/gridutil): avoid numpy deprecation warnings (#1868)
Browse files Browse the repository at this point in the history
* use ndarray.item() to retrieve single elements
* update gridutil get_disu_kwargs() docstrings
  • Loading branch information
wpbonelli committed Aug 25, 2023
1 parent fd40456 commit b1e6b77
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
12 changes: 6 additions & 6 deletions flopy/utils/binaryfile.py
Expand Up @@ -562,7 +562,7 @@ def get_ts(self, idx):
) # change ilay from header to zero-based
if ilay != k:
continue
ipos = int(self.iposarray[irec])
ipos = self.iposarray[irec].item()

# Calculate offset necessary to reach intended cell
self.file.seek(ipos + int(ioffset), 0)
Expand Down Expand Up @@ -1031,9 +1031,9 @@ def _build_index(self):
print(f"{itxt}: {s}")
print("file position: ", ipos)
if (
int(header["imeth"]) != 5
and int(header["imeth"]) != 6
and int(header["imeth"]) != 7
header["imeth"].item() != 5
and header["imeth"].item() != 6
and header["imeth"].item() != 7
):
print("")

Expand Down Expand Up @@ -1141,7 +1141,7 @@ def _get_header(self):
)
for name in temp.dtype.names:
header2[name] = temp[name]
if int(header2["imeth"]) == 6:
if header2["imeth"].item() == 6:
header2["modelnam"] = binaryread(self.file, str, charlen=16)
header2["paknam"] = binaryread(self.file, str, charlen=16)
header2["modelnam2"] = binaryread(self.file, str, charlen=16)
Expand Down Expand Up @@ -1689,7 +1689,7 @@ def get_record(self, idx, full3D=False):
idx = np.array([idx])

header = self.recordarray[idx]
ipos = int(self.iposarray[idx])
ipos = self.iposarray[idx].item()
self.file.seek(ipos, 0)
imeth = header["imeth"][0]

Expand Down
32 changes: 28 additions & 4 deletions flopy/utils/gridutil.py
Expand Up @@ -58,10 +58,34 @@ def get_lni(ncpl, nodes) -> List[Tuple[int, int]]:
return tuples


def get_disu_kwargs(nlay, nrow, ncol, delr, delc, tp, botm):
def get_disu_kwargs(
nlay,
nrow,
ncol,
delr,
delc,
tp,
botm,
):
"""
Simple utility for creating args needed to construct
a disu package
Create args needed to construct a DISU package.
Parameters
----------
nlay : int
Number of layers
nrow : int
Number of rows
ncol : int
Number of columns
delr : numpy.ndarray
Column spacing along a row
delc : numpy.ndarray
Row spacing along a column
tp : int or numpy.ndarray
Top elevation(s) of cells in the model's top layer
botm : numpy.ndarray
Bottom elevation(s) of all cells in the model
"""

def get_nn(k, i, j):
Expand All @@ -88,7 +112,7 @@ def get_nn(k, i, j):
cl12.append(n + 1)
hwva.append(n + 1)
if k == 0:
top[n] = tp
top[n] = tp.item() if isinstance(tp, np.ndarray) else tp
else:
top[n] = botm[k - 1]
bot[n] = botm[k]
Expand Down

0 comments on commit b1e6b77

Please sign in to comment.