def test_make_idomain(all_layers): top = all_layers[0].copy() botm = all_layers[1:].copy() nodata = -9999 botm[-1, 0, 0] = nodata botm[-2] = 2 botm[-2, 2, 2] = np.nan idomain = make_idomain(top, botm, nodata=nodata, minimum_layer_thickness=1, drop_thin_cells=True, tol=1e-4) # test idomain based on nans assert np.array_equal(idomain[:, 2, 2].astype(bool), ~np.isnan(botm[:, 2, 2])) # test idomain based on nodata assert idomain[-1, 0, 0] == 0 # test idomain based on layer thickness assert idomain[-1].sum() == 1 assert idomain[-2].sum() == 99 # test that nans in the model top result in the highest active botms being excluded # (these cells have valid botms, but no tops) assert idomain[:, 0, 0].sum() == 1 # in all_layers, cells with valid tops are idomain=0 # because all botms in layer 1 are nans assert idomain[0].sum() == 0 # test edge case of values that match the layer thickness when tol=0 idomain = make_idomain(top, botm, nodata=nodata, minimum_layer_thickness=1, drop_thin_cells=True, tol=0) assert idomain[-1].sum() == 99
def test_deactivate_idomain_above(all_layers): top = all_layers[0].copy() botm = all_layers[1:].copy() idomain = make_idomain(top, botm, minimum_layer_thickness=1, drop_thin_cells=True, tol=1e-4) packagedata = pd.DataFrame({'cellid': [(2, 2, 2), (8, 3, 3)]}) idomain2 = deactivate_idomain_above(idomain, packagedata) assert idomain2[:, 2, 2].sum() == idomain[:, 2, 2].sum() - 1 assert idomain2[:, 3, 3].sum() == 1
def _set_idomain(self): """Remake the idomain array from the source data, no data values in the top and bottom arrays, and so that cells above SFR reaches are inactive. Also remakes irch for the recharge package""" # loop thru LGR models and inactivate area of parent grid for each one lgr_idomain = np.ones(self.dis.idomain.array.shape, dtype=int) if isinstance(self.lgr, dict): for k, v in self.lgr.items(): lgr_idomain[v.idomain == 0] = 0 idomain_from_layer_elevations = make_idomain(self.dis.top.array, self.dis.botm.array, nodata=self._nodata_value, minimum_layer_thickness=self.cfg['dis'].get('minimum_layer_thickness', 1), drop_thin_cells=self._drop_thin_cells, tol=1e-4) # include cells that are active in the existing idomain array # and cells inactivated on the basis of layer elevations idomain = (self.dis.idomain.array == 1) & \ (idomain_from_layer_elevations == 1) & \ (lgr_idomain == 1) idomain = idomain.astype(int) # remove cells that conincide with lakes idomain[self.isbc == 1] = 0. # remove cells that are above stream cells if self.get_package('sfr') is not None: idomain = deactivate_idomain_above(idomain, self.sfr.packagedata) # inactivate any isolated cells that could cause problems with the solution idomain = find_remove_isolated_cells(idomain, minimum_cluster_size=20) # create pass-through cells in inactive cells that have an active cell above and below # by setting these cells to -1 idomain = create_vertical_pass_through_cells(idomain) self._idomain = idomain # take the updated idomain array and set cells != 1 to np.nan in layer botm array # including lake cells # effect is that the layer thicknesses in these cells will be set to zero # fill_cells_vertically will be run in the setup_array routine, # to collapse the nan cells to zero-thickness # (assign their layer botm to the next valid layer botm above) botm = self.dis.botm.array.copy() botm[(idomain != 1)] = np.nan # re-write the input files # todo: integrate this better with setup_dis # to reduce the number of times the arrays need to be remade self._setup_array('dis', 'botm', data={i: arr for i, arr in enumerate(botm)}, datatype='array3d', resample_method='linear', write_fmt='%.2f', dtype=float) self.dis.botm = self.cfg['dis']['griddata']['botm'] self._setup_array('dis', 'idomain', data={i: arr for i, arr in enumerate(idomain)}, datatype='array3d', resample_method='nearest', write_fmt='%d', dtype=int) self.dis.idomain = self.cfg['dis']['griddata']['idomain'] self._mg_resync = False self.setup_grid() # reset the model grid # rebuild irch to keep it in sync with idomain changes irch = make_irch(idomain) self._setup_array('rch', 'irch', data={0: irch}, datatype='array2d', write_fmt='%d', dtype=int)