Skip to content

Commit

Permalink
fix(grb): update binary grid file reader for new grid types (#2157)
Browse files Browse the repository at this point in the history
* fix(grb): update binary grid file reader for new grid types

* more updates to support other grid types

* try more general way that may prevent us from getting locked

* try to implement methods in a way that does not required grid type
  • Loading branch information
langevin-usgs authored Apr 17, 2024
1 parent 57cf82e commit 30e0349
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions flopy/mf6/utils/binarygrid_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,9 @@ def nlay(self):
-------
nlay : int
"""
if self._grid_type in ("DIS", "DISV"):
nlay = None
if "NLAY" in self._datadict:
nlay = self._datadict["NLAY"]
else:
nlay = None
return nlay

@property
Expand All @@ -376,10 +375,9 @@ def nrow(self):
-------
nrow : int
"""
if self._grid_type == "DIS":
nrow = None
if "NROW" in self._datadict:
nrow = self._datadict["NROW"]
else:
nrow = None
return nrow

@property
Expand All @@ -391,10 +389,9 @@ def ncol(self):
-------
ncol : int
"""
if self._grid_type == "DIS":
ncol = None
if "NCOL" in self._datadict:
ncol = self._datadict["NCOL"]
else:
ncol = None
return ncol

@property
Expand All @@ -406,12 +403,9 @@ def ncpl(self):
-------
ncpl : int
"""
if self._grid_type == "DISV":
ncpl = None
if "NCPL" in self._datadict:
ncpl = self._datadict["NCPL"]
if self._grid_type == "DIS":
ncpl = self.nrow * self.ncol
else:
None
return ncpl

@property
Expand All @@ -423,10 +417,14 @@ def ncells(self):
-------
ncells : int
"""
if self._grid_type in ("DIS", "DISV"):
# disu is the only grid that has the number of cells
# set to nodes. All other grids use NCELLS in grb
if "NCELLS" in self._datadict:
ncells = self._datadict["NCELLS"]
else:
elif "NODES" in self._datadict:
ncells = self._datadict["NODES"]
else:
ncells = None
return ncells

@property
Expand All @@ -438,10 +436,7 @@ def nodes(self):
-------
nodes : int
"""
if self._grid_type in ("DIS", "DISV"):
nodes = self.ncells
else:
nodes = self._datadict["NODES"]
nodes = self.ncells
return nodes

@property
Expand All @@ -455,10 +450,18 @@ def shape(self):
"""
if self._grid_type == "DIS":
shape = (self.nlay, self.nrow, self.ncol)
elif self._grid_type == "DIS2D":
shape = (self.nrow, self.ncol)
elif self._grid_type == "DISV":
shape = (self.nlay, self.ncpl)
else:
elif self._grid_type == "DISV2D":
shape = (self.ncells,)
elif self._grid_type == "DISV1D":
shape = (self.ncells,)
elif self._grid_type == "DISU":
shape = (self.nodes,)
else:
shape = None
return shape

@property
Expand Down Expand Up @@ -535,10 +538,9 @@ def delr(self):
-------
delr : ndarray of floats
"""
if self.grid_type == "DIS":
delr = None
if "DELR" in self._datadict:
delr = self._datadict["DELR"]
else:
delr = None
return delr

@property
Expand All @@ -551,10 +553,9 @@ def delc(self):
-------
delc : ndarray of floats
"""
if self.grid_type == "DIS":
delc = None
if "DELC" in self._datadict:
delc = self._datadict["DELC"]
else:
delc = None
return delc

@property
Expand All @@ -567,7 +568,10 @@ def top(self):
-------
top : ndarray of floats
"""
return self._datadict["TOP"]
top = None
if "TOP" in self._datadict:
top = self._datadict["TOP"]
return top

@property
def bot(self):
Expand All @@ -578,9 +582,10 @@ def bot(self):
-------
bot : ndarray of floats
"""
if self.grid_type in ("DIS", "DISV"):
bot = None
if "BOTM" in self._datadict:
bot = self._datadict["BOTM"]
else:
elif "BOT" in self._datadict:
bot = self._datadict["BOT"]
return bot

Expand Down Expand Up @@ -733,7 +738,7 @@ def cell2d(self):
-------
cell2d : list of lists
"""
if self._grid_type == "DISV":
if self._grid_type in ("DISV", "DISV2D", "DISV1D"):
vertices, cell2d = self.__build_vertices_cell2d()
else:
vertices, cell2d = None, None
Expand Down

0 comments on commit 30e0349

Please sign in to comment.