Skip to content

Commit

Permalink
Merge pull request #182 from changliao1025/development
Browse files Browse the repository at this point in the history
update config change
  • Loading branch information
changliao1025 authored Sep 27, 2023
2 parents 6694b55 + 4542206 commit 6c92d49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
12 changes: 7 additions & 5 deletions notebooks/mpas_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down
34 changes: 7 additions & 27 deletions pyflowline/classes/pycase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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()

Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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):
"""
Expand Down

0 comments on commit 6c92d49

Please sign in to comment.