Skip to content

Commit

Permalink
up example
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Mar 14, 2022
1 parent 65080ec commit fc1cbf8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 26 deletions.
5 changes: 5 additions & 0 deletions tests/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
In this directory, you will find several different example files for different purposes.

- create_model_condfiguration.py: this example, create a configuration file, you can edit this configuration and then use it for the actual simulation such as in the run_simulation.py

- run_simulation.py: this example uses a configuration file to run a simulation
55 changes: 55 additions & 0 deletions tests/example/create_model_condfiguration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import sys
from pathlib import Path
from os.path import realpath
import argparse
import logging
for handler in logging.root.handlers[:]:
logging.root.removeHandler(handler)

logging.basicConfig(format='%(asctime)s %(message)s')
logging.warning('is the time Pyflowline simulation started.')

from pyflowline.pyflowline_generate_template_configuration_json_file import pyflowline_generate_template_configuration_json_file

parser = argparse.ArgumentParser()
parser.add_argument("--sMesh_type", help = "sMesh_type", type = str)
parser.add_argument("--iCase_index", help = "iCase_index", type = int)
parser.add_argument("--dResolution_meter", help = "dResolution_meter", type = float)
parser.add_argument("--sDate", help = "sDate", type = str)

#example
#python notebook.py --sMesh_type hexagon --iCase_index 1 --dResolution_meter 50000 --sDate 20220201
pArgs = parser.parse_args()
if len(sys.argv) == 1:
sMesh_type = 'mpas'
iCase_index = 1
dResolution_meter=5000
sDate='20220308'
else:
if len(sys.argv)> 1:
sMesh_type = pArgs.sMesh_type
iCase_index = pArgs.iCase_index
dResolution_meter=pArgs.dResolution_meter
sDate = pArgs.sDate
print(sMesh_type, iCase_index, dResolution_meter, sDate)
else:
print(len(sys.argv), 'Missing arguments')
pass

sPath = str( Path().resolve() )
iFlag_option = 1
sWorkspace_data = realpath( sPath + '/data/susquehanna' )
sWorkspace_input = str(Path(sWorkspace_data) / 'input')
sWorkspace_output= str(Path(sWorkspace_data) / 'output')

sFilename_configuration_in = realpath( sPath + '/tests/configurations/template.json' )

oPyflowline = pyflowline_generate_template_configuration_json_file(sFilename_configuration_in,\
sWorkspace_input, sWorkspace_output, iFlag_use_mesh_dem_in = 1,sMesh_type_in=sMesh_type, iCase_index_in = iCase_index, sDate_in = sDate)

print(oPyflowline.tojson())

print('Finished')

logging.basicConfig(format='%(asctime)s %(message)s')
logging.warning('is the time Pyflowline simulation finished.')
40 changes: 14 additions & 26 deletions tests/example/full_example.py → tests/example/run_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,38 +44,26 @@
sWorkspace_input = str(Path(sWorkspace_data) / 'input')
sWorkspace_output= str(Path(sWorkspace_data) / 'output')

if iFlag_option ==1:
sFilename_configuration_in = realpath( sPath + '/tests/configurations/template.json' )

oPyflowline = pyflowline_generate_template_configuration_json_file(sFilename_configuration_in,\
sWorkspace_input, sWorkspace_output, iFlag_use_mesh_dem_in = 1,sMesh_type_in=sMesh_type, iCase_index_in = iCase_index, sDate_in = sDate)

print(oPyflowline.tojson())
else:
if iFlag_option == 2:
#an example configuration file is provided with the repository, but you need to update this file based on your own case study


#an example configuration file is provided with the repository, but you need to update this file based on your own case study
#linux


if sMesh_type=='hexagon':
sFilename_configuration_in = realpath( sPath + '/../configurations/pyflowline_susquehanna_hexagon.json' )
if sMesh_type=='hexagon':
sFilename_configuration_in = realpath( sPath + '/../configurations/pyflowline_susquehanna_hexagon.json' )
else:
if sMesh_type=='square':
sFilename_configuration_in = realpath( sPath + '/../configurations/pyflowline_susquehanna_square.json' )
else:
if sMesh_type=='latlon':
sFilename_configuration_in = realpath( sPath + '/../configurations/pyflowline_susquehanna_latlon.json' )
else:
if sMesh_type=='square':
sFilename_configuration_in = realpath( sPath + '/../configurations/pyflowline_susquehanna_square.json' )
else:
if sMesh_type=='latlon':
sFilename_configuration_in = realpath( sPath + '/../configurations/pyflowline_susquehanna_latlon.json' )
else:
sFilename_configuration_in = realpath( sPath + '/../configurations/)pyflowline_susquehanna_mpas.json' )


oPyflowline = pyflowline_read_model_configuration_file(sFilename_configuration_in, \
sFilename_configuration_in = realpath( sPath + '/../configurations/)pyflowline_susquehanna_mpas.json' )
oPyflowline = pyflowline_read_model_configuration_file(sFilename_configuration_in, \
iCase_index_in=iCase_index, dResolution_meter_in=dResolution_meter, sDate_in=sDate)


#pyflowline can process multiple basins within one singel run
#the total number of basin is controlled by the nOutlet variable
#convert the raw flowline into geojson in WGS84 system

oPyflowline.convert_flowline_to_json()
oPyflowline.aBasin[0].dLatitude_outlet_degree=39.4620
oPyflowline.aBasin[0].dLongitude_outlet_degree=-76.0093
Expand Down

0 comments on commit fc1cbf8

Please sign in to comment.