def load(cls, yamlfile, load_only=None, verbose=False, forgive=False, check=False): """Load a model from a config file and set of MODFLOW files. """ print('\nLoading simulation in {}\n'.format(yamlfile)) t0 = time.time() cfg = load_cfg(yamlfile, verbose=verbose, default_file=cls.default_file) # '/mf6_defaults.yml') cfg = cls._parse_model_kwargs(cfg) kwargs = get_input_arguments(cfg['model'], mf6.ModflowGwf, exclude='packages') model = cls(cfg=cfg, **kwargs) model._load = True if 'grid' not in model.cfg.keys(): model.setup_grid() sim = model.cfg['model']['simulation'] # should be a flopy.mf6.MFSimulation instance models = [model] if isinstance(model.inset, dict): for inset_name, inset in model.inset.items(): models.append(inset) # execute the flopy load code on the pre-defined simulation and model instances # (so that the end result is a MFsetup.MF6model instance) # (kludgy) sim = flopy_mfsimulation_load(sim, models) # just return the parent model (inset models should be attached through the inset attribute, # in addition to through the .simulation flopy attribute) m = sim.get_model(model_name=model.name) print('finished loading model in {:.2f}s'.format(time.time() - t0)) return m
def test_load_cfg(pfl_nwt_test_cfg_path): cfg_pathed = load_cfg(pfl_nwt_test_cfg_path, default_file='/mfnwt_defaults.yml') cfg = load(pfl_nwt_test_cfg_path) config_file_location = os.path.split( os.path.abspath(pfl_nwt_test_cfg_path))[0] assert cfg_pathed['nwt']['use_existing_file'] is None p1 = os.path.normpath(cfg_pathed['model']['model_ws']) p2 = os.path.normpath( os.path.join(config_file_location, cfg['model']['model_ws'])) assert p1 == p2 p1 = os.path.normpath( cfg_pathed['rch']['source_data']['rech']['filenames'][0]) p2 = os.path.normpath( os.path.join(config_file_location, cfg['rch']['source_data']['rech']['filenames'][0])) assert p1 == p2 p1 = os.path.normpath(cfg_pathed['hyd']['source_data']['filenames'][0]) p2 = os.path.normpath( os.path.join(config_file_location, cfg['hyd']['source_data']['filenames'][0])) assert p1 == p2
def load(cls, yamlfile, load_only=None, verbose=False, forgive=False, check=False): """Load a model from a config file and set of MODFLOW files. """ cfg = load_cfg(yamlfile, verbose=verbose, default_file=cls.default_file) # '/mfnwt_defaults.yml') print('\nLoading {} model from data in {}\n'.format( cfg['model']['modelname'], yamlfile)) t0 = time.time() m = cls(cfg=cfg, **cfg['model']) if 'grid' not in m.cfg.keys(): grid_file = cfg['setup_grid']['output_files']['grid_file'] if os.path.exists(grid_file): print( 'Loading model grid definition from {}'.format(grid_file)) m.cfg['grid'] = load(grid_file) else: m.setup_grid() m = flopy_mf2005_load(m, load_only=load_only, forgive=forgive, check=check) print('finished loading model in {:.2f}s'.format(time.time() - t0)) return m
def test_packagelist(pfl_nwt_test_cfg_path): cfg = load_cfg(pfl_nwt_test_cfg_path, default_file='/mfnwt_defaults.yml') assert len(cfg['model']['packages']) > 0 kwargs = get_input_arguments(cfg['model'], MFnwtModel) m = MFnwtModel(cfg=cfg, **kwargs) assert m.package_list == [p for p in m._package_setup_order if p in cfg['model']['packages']]
def create_lgr_models(self): for k, v in self.cfg['setup_grid']['lgr'].items(): # load the config file for lgr inset model inset_cfg = load_cfg(v['filename'], default_file='/mf6_defaults.yml') # if lgr inset has already been created if inset_cfg['model']['modelname'] in self.simulation._models: return inset_cfg['model']['simulation'] = self.simulation if 'ims' in inset_cfg['model']['packages']: inset_cfg['model']['packages'].remove('ims') # set parent configuation dictionary here # (even though parent model is explicitly set below) # so that the LGR grid is snapped to the parent grid inset_cfg['parent'] = { 'namefile': self.namefile, 'model_ws': self.model_ws, 'version': 'mf6', 'hiKlakes_value': self.cfg['model']['hiKlakes_value'], 'default_source_data': True, 'length_units': self.length_units, 'time_units': self.time_units } inset_cfg = MF6model._parse_model_kwargs(inset_cfg) kwargs = get_input_arguments(inset_cfg['model'], mf6.ModflowGwf, exclude='packages') kwargs['parent'] = self # otherwise will try to load parent model inset_model = MF6model(cfg=inset_cfg, lgr=True, **kwargs) inset_model._load = self._load # whether model is being made or loaded from existing files inset_model.setup_grid() del inset_model.cfg['ims'] inset_model.cfg['tdis'] = self.cfg['tdis'] if self.inset is None: self.inset = {} self.lgr = {} self.inset[inset_model.name] = inset_model #self.inset[inset_model.name]._is_lgr = True # create idomain indicating area of parent grid that is LGR lgr_idomain = make_lgr_idomain( self.modelgrid, self.inset[inset_model.name].modelgrid) ncpp = int(self.modelgrid.delr[0] / self.inset[inset_model.name].modelgrid.delr[0]) ncppl = v.get('layer_refinement', 1) self.lgr[inset_model.name] = Lgr(self.nlay, self.nrow, self.ncol, self.dis.delr.array, self.dis.delc.array, self.dis.top.array, self.dis.botm.array, lgr_idomain, ncpp, ncppl) inset_model._perioddata = self.perioddata self._set_idomain()
def test_packagelist(shellmound_cfg_path): cfg = load_cfg(shellmound_cfg_path, default_file='/mf6_defaults.yml') packages = cfg['model']['packages'] kwargs = get_input_arguments(cfg['simulation'], mf6.MFSimulation) sim = mf6.MFSimulation(**kwargs) cfg['model']['simulation'] = sim cfg = MF6model._parse_model_kwargs(cfg) kwargs = get_input_arguments(cfg['model'], mf6.ModflowGwf, exclude='packages') m = MF6model(cfg=cfg, **kwargs) assert m.package_list == [p for p in m._package_setup_order if p in packages]
def pleasant_mf6_cfg(pleasant_mf6_test_cfg_path): cfg = load_cfg(pleasant_mf6_test_cfg_path, default_file='/mf6_defaults.yml') # add some stuff just for the tests cfg['gisdir'] = os.path.join(cfg['simulation']['sim_ws'], 'gis') return cfg
def shellmound_cfg(project_root_path): shellmound_cfg_path = project_root_path + '/mfsetup/tests/data/shellmound_flat_layers.yml' cfg = load_cfg(shellmound_cfg_path, default_file='/mf6_defaults.yml') # add some stuff just for the tests cfg['gisdir'] = os.path.join(cfg['simulation']['sim_ws'], 'gis') return cfg
def pfl_nwt_cfg(pfl_nwt_test_cfg_path): cfg = load_cfg(pfl_nwt_test_cfg_path, default_file='/mfnwt_defaults.yml') # add some stuff just for the tests cfg['gisdir'] = os.path.join(cfg['model']['model_ws'], 'gis') return cfg
def shellmound_tmr_cfg(shellmound_tmr_cfg_path): cfg = load_cfg(shellmound_tmr_cfg_path, default_file='/mf6_defaults.yml') # add some stuff just for the tests cfg['gisdir'] = os.path.join(cfg['simulation']['sim_ws'], 'gis') return cfg