diff --git a/notebooks/mpas_example.ipynb b/notebooks/mpas_example.ipynb index 988058a..64a37fb 100644 --- a/notebooks/mpas_example.ipynb +++ b/notebooks/mpas_example.ipynb @@ -296,8 +296,12 @@ "outputs": [], "source": [ "#we need to update a few parameters in the configuration file before we can create the flowline object\n", - "sFilename_basins = realpath( sPath_parent + '/data/susquehanna/input//pyflowline_susquehanna_mpas_basins.json' )\n", - "change_json_key_value(sFilename_configuration_in, 'sFilename_basins', sMesh_type)" + "sFilename_basins = realpath( os.path.join(sFolder_input , 'pyflowline_susquehanna_mpas_basins.json' ))\n", + "sFilename_mesh_boundary = realpath(os.path.join(sFolder_input, 'boundary_wgs.geojson'))\n", + "\n", + "change_json_key_value(sFilename_configuration_in, 'sFilename_mesh_netcdf', sFilename_download)\n", + "change_json_key_value(sFilename_configuration_in, 'sFilename_mesh_boundary', sFilename_mesh_boundary)\n", + "change_json_key_value(sFilename_configuration_in, 'sFilename_basins', sFilename_basins)\n" ] }, { @@ -340,9 +344,7 @@ "oPyflowline.change_model_parameter('sFilename_mesh_netcdf', sFilename_download) #because the mpas mesh already contains elevation, we do not need to set the elevation file name\n", "#we will set the boundary file name\n", "#this file should be located in the input folder\n", - "\n", - "sFilename_mesh_boundary = os.path.join(sFolder_input, 'boundary_wgs.geojson')\n", - "oPyflowline.change_model_parameter('sFilename_boundary_netcdf', sFilename_mesh_boundary)\n", + "oPyflowline.change_model_parameter('sFilename_mesh_boundary', sFilename_mesh_boundary)\n", "\n", "#we can also set for individual basin in the domain, in this example, we only has one basin.\n", "#remember that, each basin can have different parameters, so if you want to set them different (for example, basin 1 has no dam, but basin 2 has dam), you should edit the basin json instead using this function.\n", diff --git a/pyflowline/classes/pycase.py b/pyflowline/classes/pycase.py index 15c7c2a..18be9c8 100644 --- a/pyflowline/classes/pycase.py +++ b/pyflowline/classes/pycase.py @@ -306,7 +306,7 @@ def __init__(self, aConfig_in, if self.iFlag_mesh_boundary==1: if not os.path.isfile(self.sFilename_mesh_boundary ): print("The mesh boundary file does not exist, you should update this parameter before running the model!") - #exit() + exit() pass if 'sFilename_spatial_reference' in aConfig_in: @@ -321,7 +321,7 @@ def __init__(self, aConfig_in, self.sFilename_dggrid = aConfig_in['sFilename_dggrid'] if not os.path.isfile(self.sFilename_dggrid ): print("The dggrid binary file does not exist, you need to update this parameter before running the model!") - #exit() + exit() pass else: @@ -416,7 +416,7 @@ def __init__(self, aConfig_in, else: if not os.path.isfile(self.sFilename_dem ): #why DEM is required? print("The DEM file does not exist!") - #exit() + exit() self.aBasin = list() @@ -428,7 +428,8 @@ def __init__(self, aConfig_in, else: print('This basin configuration file does not exist: ', self.sFilename_basins ) print('Please update this parameter before running the model!') - #exit() + exit() + with open(self.sFilename_basins) as json_file: dummy_data = json.load(json_file) for i in range(self.nOutlet): @@ -1014,8 +1015,7 @@ def change_model_parameter(self, sVariable_in, dValue, iFlag_basin_in = None): #get the data type of the input value sType_input = type(dValue) if sType_default == sType_input: - setattr(self, sVariable_in, dValue) - self.update_model() + setattr(self, sVariable_in, dValue) pass else: print('Incorrect data type for the input value: ' + sVariable_in) @@ -1042,27 +1042,7 @@ def change_model_parameter(self, sVariable_in, dValue, iFlag_basin_in = None): print("This model parameter is unknown, please check the full parameter list in the documentation: " + sVariable_in) return False - def update_model(self): - """This function should be called after the model parameter is changed - """ - #update subbasin - if self.iFlag_flowline==1: - if os.path.isfile(self.sFilename_basins): - pass - else: - print("Error: the basin file does not exist: " + self.sFilename_basins) - - self.aBasin.clear() - - with open(self.sFilename_basins) as json_file: - dummy_data = json.load(json_file) - for i in range(self.nOutlet): - sBasin = "{:08d}".format(i+1) - dummy_basin = dummy_data[i] - dummy_basin['sWorkspace_output_basin'] = str(Path(self.sWorkspace_output) / sBasin ) - pBasin = pybasin(dummy_basin) - self.aBasin.append(pBasin) - + def run(self): """