From 90f87f2932e17955dee68ec53347c9d06178f94a Mon Sep 17 00:00:00 2001 From: w-bonelli Date: Wed, 12 Jul 2023 14:46:56 -0400 Subject: [PATCH] fix(binaryfile/gridutil): avoid numpy deprecation warnings (#1868) * use ndarray.item() to retrieve single elements * update gridutil get_disu_kwargs() docstrings --- flopy/utils/binaryfile.py | 12 ++++++------ flopy/utils/gridutil.py | 32 ++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/flopy/utils/binaryfile.py b/flopy/utils/binaryfile.py index cb5b585af..8ed15bf54 100644 --- a/flopy/utils/binaryfile.py +++ b/flopy/utils/binaryfile.py @@ -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) @@ -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("") @@ -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) @@ -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] diff --git a/flopy/utils/gridutil.py b/flopy/utils/gridutil.py index 953ee97a6..d9ca28c19 100644 --- a/flopy/utils/gridutil.py +++ b/flopy/utils/gridutil.py @@ -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): @@ -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]