diff --git a/tests/example/README.md b/tests/example/README.md new file mode 100644 index 0000000..740323f --- /dev/null +++ b/tests/example/README.md @@ -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 \ No newline at end of file diff --git a/tests/example/create_model_condfiguration.py b/tests/example/create_model_condfiguration.py new file mode 100644 index 0000000..ead5d18 --- /dev/null +++ b/tests/example/create_model_condfiguration.py @@ -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.') diff --git a/tests/example/full_example.py b/tests/example/run_simulation.py similarity index 63% rename from tests/example/full_example.py rename to tests/example/run_simulation.py index cc95395..f2ad543 100644 --- a/tests/example/full_example.py +++ b/tests/example/run_simulation.py @@ -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