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 __init__(self, simulation, parent=None, cfg=None, modelname='model', exe_name='mf6', version='mf6', lgr=False, **kwargs): mf6.ModflowGwf.__init__(self, simulation, modelname, exe_name=exe_name, version=version, **kwargs) MFsetupMixin.__init__(self, parent=parent) # default configuration self._is_lgr = lgr self._package_setup_order = ['tdis', 'dis', 'ic', 'npf', 'sto', 'rch', 'oc', 'ghb', 'sfr', 'lak', 'riv', 'wel', 'maw', 'obs'] self.cfg = load(self.source_path + self.default_file) #'/mf6_defaults.yml') self.cfg['filename'] = self.source_path + self.default_file #'/mf6_defaults.yml' self._set_cfg(cfg) # set up the model configuration dictionary self.relative_external_paths = self.cfg.get('model', {}).get('relative_external_paths', True) self.model_ws = self._get_model_ws() # property attributes self._idomain = None # other attributes self._features = {} # dictionary for caching shapefile datasets in memory self._drop_thin_cells = self.cfg.get('dis', {}).get('drop_thin_cells', True) # arrays remade during this session self.updated_arrays = set()
def pleasant_lgr_stand_alone_parent(pleasant_lgr_test_cfg_path, tmpdir): """Stand-alone version of lgr parent model for comparing with LGR results. """ # Edit the configuration file before the file paths within it are converted to absolute # (model.load_cfg converts the file paths) cfg = load(pleasant_lgr_test_cfg_path) del cfg['setup_grid']['lgr'] cfg['simulation']['sim_ws'] = os.path.join(tmpdir, 'pleasant_lgr_just_parent') # save out the edited configuration file path, fname = os.path.split(pleasant_lgr_test_cfg_path) new_file = os.path.join(path, 'pleasant_lgr_just_parent.yml') dump(new_file, cfg) # load in the edited configuration file, converting the paths to absolute cfg = MF6model.load_cfg(new_file) # add some stuff just for the tests cfg['gisdir'] = os.path.join(cfg['simulation']['sim_ws'], 'gis') m = MF6model.setup_from_cfg(cfg) m.write_input() #if hasattr(m, 'sfr'): # sfr_package_filename = os.path.join(m.model_ws, m.sfr.filename) # m.sfrdata.write_package(sfr_package_filename, # version='mf6' # ) return m
def __init__(self, parent=None, cfg=None, modelname='model', exe_name='mfnwt', version='mfnwt', model_ws='.', external_path='external/', **kwargs): Modflow.__init__(self, modelname, exe_name=exe_name, version=version, model_ws=model_ws, external_path=external_path, **kwargs) MFsetupMixin.__init__(self, parent=parent) # default configuration self._package_setup_order = [ 'dis', 'bas6', 'upw', 'rch', 'oc', 'ghb', 'lak', 'sfr', 'riv', 'wel', 'mnw2', 'gag', 'hyd' ] # default configuration (different for nwt vs mf6) self.cfg = load(self.source_path + self.default_file) # '/mfnwt_defaults.yml') self.cfg[ 'filename'] = self.source_path + self.default_file #'/mfnwt_defaults.yml' self._set_cfg(cfg) # set up the model configuration dictionary self.relative_external_paths = self.cfg.get('model', {}).get( 'relative_external_paths', True) self.model_ws = self._get_model_ws() # set the list file path self.lst.file_name = [ self.cfg['model']['list_filename_fmt'].format(self.name) ] # property arrays self._ibound = None