Skip to content

Commit

Permalink
refactor(grid.py): relax requirement that parent and inset model grid…
Browse files Browse the repository at this point in the history
…s must exactly align when snap_to_parent=True. For example, we may want a model that is aligned, but only every n cells, because of grid size considerations.
  • Loading branch information
aleaf committed Aug 6, 2024
1 parent 61f90d6 commit b7ebed6
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions mfsetup/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,14 +986,14 @@ def setup_structured_grid(xoff=None, yoff=None, xul=None, yul=None,
if parent_model is not None and snap_to_parent:
to_grid_units_parent = convert_length_units(get_model_length_units(parent_model), grid_units)
# parent model grid spacing in meters
parent_delr_grid = np.round(parent_model.dis.delr.array[0] * to_grid_units_parent, 4)
if not parent_delr_grid % delr_grid % parent_delr_grid == 0:
raise ValueError('inset delr spacing of {} must be factor of parent spacing of {}'.format(delr_grid,
parent_delr_grid))
parent_delc_grid = np.round(parent_model.dis.delc.array[0] * to_grid_units_parent, 4)
if not parent_delc_grid % delc_grid % parent_delc_grid == 0:
raise ValueError('inset delc spacing of {} must be factor of parent spacing of {}'.format(delc_grid,
parent_delc_grid))
#parent_delr_grid = np.round(parent_model.dis.delr.array[0] * to_grid_units_parent, 4)
#if not parent_delr_grid % delr_grid % parent_delr_grid == 0:
# raise ValueError('inset delr spacing of {} must be factor of parent spacing of {}'.format(delr_grid,
# parent_delr_grid))
#parent_delc_grid = np.round(parent_model.dis.delc.array[0] * to_grid_units_parent, 4)
#if not parent_delc_grid % delc_grid % parent_delc_grid == 0:
# raise ValueError('inset delc spacing of {} must be factor of parent spacing of {}'.format(delc_grid,
# parent_delc_grid))

# option 1: make grid from xoff, yoff and specified dimensions
if xoff is not None and yoff is not None:
Expand Down Expand Up @@ -1057,6 +1057,10 @@ def setup_structured_grid(xoff=None, yoff=None, xul=None, yul=None,
df.to_crs(crs, inplace=True)
# use all features by default
features = df.geometry.tolist()
elif features is None and features_shapefile is not None:
raise ValueError(
"setup_grid: need one of xoff/yoff, xul/yul, features_shapefile or "
"features inputs")
# alternatively, accept features as an argument
# convert multiple features to a MultiPolygon
if isinstance(features, list):
Expand Down

0 comments on commit b7ebed6

Please sign in to comment.