Skip to content

Commit

Permalink
debug and test
Browse files Browse the repository at this point in the history
  • Loading branch information
changliao1025 committed Apr 8, 2022
1 parent 703b8f3 commit 34955ff
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 47 deletions.
5 changes: 0 additions & 5 deletions LICENSE

This file was deleted.

14 changes: 14 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
HexWatershed
A mesh independent flow direction model for hydrologic models.

Copyright © 2022, Battelle Memorial Institute

1. Battelle Memorial Institute (hereinafter Battelle) hereby grants permission to any person or entity lawfully obtaining a copy of this software and associated documentation files (hereinafter “the Software”) to redistribute and use the Software in source and binary forms, with or without modification. Such person or entity may use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and may permit others to do so, subject to the following conditions:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Other than as used herein, neither the name Battelle Memorial Institute or Battelle may be used in any form whatsoever without the express written consent of Battelle.

2. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BATTELLE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
## `HexWatershed: A hexagon mesh grid based watershed delineation model`
## `HexWatershed: A mesh independent flow direction model for hydrologic models`

<p align="middle">
<img src = "./external/hexwatershed/example/figure/stream_topology.png" width="50%" hspace="0.55%">
</p>

`HexWatershed` is a hydrologic routing model based on the hexagon mesh framework.

This package provides a <a href="http://www.python.org">`Python`</a> based scripting interface to the underlying `HexWatershed` model, including a range of additional facilities for file I/O, visualisation and pre/post-processing operations.
This Python package provides a <a href="http://www.python.org">`Python`</a> based interface to the underlying `HexWatershed` model.

`HexWatershed` has been compiled and tested on various `64-bit` `Linux` and `Mac` based platforms.

Expand All @@ -16,31 +11,31 @@ This package provides a <a href="http://www.python.org">`Python`</a> based scrip
Clone/download + unpack this repository.
python3 setup.py build_external
python3 setup.py install
python3 example.py --IDnumber=0


Note: installation of `HexWatershed` requires a `c++` compiler and the `cmake` utility. Besides, the `GDAL` is required to build the model.

### `Function Listing`

See `HexWatershed` for a description of the various functions available.

setup.py - compile and install HexWatershed's c++ backend using cmake.


### `Example Problems`
### `Acknowledgement`

Run `python3 example.py --IDnumber=N` to call the `N-th` example. `*.vtk` output is saved to `../cache` and can be visualised with, for example, <a href=https://www.paraview.org/>Paraview</a>.
This work was supported by the Earth System Model Development program areas of the U.S. Department of Energy, Office of Science, Office of Biological and Environmental Research as part of the multi-program, collaborative Integrated Coastal Modeling (ICoM) project. The data used for model simulations can be downloaded through the USGS website (https://www.usgs.gov/national-hydrography). The Pyflowline model can be accessed through the Python Conda system (https://anaconda.org/conda-forge/pyflowline).

### `License`

This program may be freely redistributed under the condition that the copyright notices (including this entire header) are not removed, and no compensation is received through use of the software. Private, research, and institutional use is free. You may distribute modified versions of this code `UNDER THE CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE TO IT IN THE SAME FILE REMAIN UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH SOURCE AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT CHARGE, AND CLEAR NOTICE IS GIVEN OF THE MODIFICATIONS`. Distribution of this code as part of a commercial system is permissible `ONLY BY DIRECT ARRANGEMENT WITH THE AUTHOR`. (If you are not directly supplying this code to a customer, and you are instead telling them how they can obtain it for free, then you are not required to make any arrangement with me.)

Please see the LICENSE file.


### `References`

There are a number of publications that describe the algorithms used in `HexWatershed` in detail. If you make use of `HexWatershed` in your work, please consider including a reference to the following:

Liao, C., Tesfa, T., Duan, Z., & Leung, L. R. (2020). Watershed delineation on a hexagonal mesh grid. Environmental Modelling & Software, 128, 104702. https://doi.org/10.1016/j.envsoft.2020.104702

* Liao, Chang, Tian Zhou, Donghui Xu, Richard Barnes, Gautam Bisht, Hong-Yi Li, Zeli Tan, et al. (02/2022AD) 2022. “Advances In Hexagon Mesh-Based Flow Direction Modeling”. Advances In Water Resources 160. Elsevier BV: 104099.
https://doi.org/10.1016/j.advwatres.2021.104099.

* Liao, C., Tesfa, T., Duan, Z., & Leung, L. R. (2020). Watershed delineation on a hexagonal mesh grid. Environmental Modelling & Software, 128, 104702. https://doi.org/10.1016/j.envsoft.2020.104702

* Liao. C. (2022) Pyflowline: a mesh-independent river networks generator for hydrologic models. Zenodo.
https://doi.org/10.5281/zenodo.6407299


44 changes: 44 additions & 0 deletions tests/configurations/pyhexwatershed_susquehanna_latlon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"dAccumulation_threshold": 100000.0,
"dLatitude_bot": -90.0,
"dLatitude_top": 90.0,
"dLongitude_left": -180.0,
"dLongitude_right": 180.0,
"dResolution_degree": 0.5,
"dResolution_meter": 10000.0,
"iCase_index": 5,
"iFlag_create_mesh": 1,
"iFlag_elevation_profile": 0,
"iFlag_flowline": 1,
"iFlag_global": 0,
"iFlag_intersect": 1,
"iFlag_multiple_outlet": 0,
"iFlag_resample_method": 2,
"iFlag_save_elevation": 1,
"iFlag_save_mesh": 1,
"iFlag_simplification": 1,
"iFlag_stream_burning_topology": 1,
"iFlag_use_mesh_dem": 0,
"iMesh_type": 3,
"nOutlet": 1,
"pPyFlowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline",
"sCase": "pyhexwatershed20220404005",
"sDate": "20220404",
"sFilename_basins": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/configuration_basin.json",
"sFilename_dem": "/qfs/people/liao313/data/hexwatershed/susquehanna/raster/dem/dem_ext.tif",
"sFilename_elevation": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/latlon_elevation.json",
"sFilename_hexwatershed": "hexwatershed",
"sFilename_mesh": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/latlon.json",
"sFilename_mesh_info": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/latlon_mesh_info.json",
"sFilename_mesh_netcdf": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/lnd_cull_mesh.nc",
"sFilename_model_configuration": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/configuration.json",
"sFilename_spatial_reference": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/boundary_proj.shp",
"sJob": "pyhexwatershed",
"sMesh_type": "latlon",
"sModel": "pyhexwatershed",
"sRegion": "susquehanna",
"sWorkspace_bin": "/qfs/people/liao313/workspace/python/pyhexwatershed/bin",
"sWorkspace_output": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/",
"sWorkspace_output_hexwatershed": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/hexwatershed",
"sWorkspace_output_pyflowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline"
}
30 changes: 30 additions & 0 deletions tests/configurations/pyhexwatershed_susquehanna_latlon_basins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"dAccumulation_threshold": -90.0,
"dLatitude_outlet_degree": -180.0,
"dLongitude_outlet_degree": 180.0,
"dThreshold_small_river": 90.0,
"iFlag_dam": 0,
"iFlag_disconnected": 0,
"lBasinID": 1,
"lCellID_outlet": -1,
"sBasinID": "001",
"sFilename_area_of_difference": "area_of_difference.json",
"sFilename_basin_info": "basin_info.json",
"sFilename_confluence_conceptual_info": "confluence_conceptual_info.json",
"sFilename_confluence_simplified_info": "confluence_simplified_info.json",
"sFilename_dam": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/ICoM_dams.csv",
"sFilename_flowline_conceptual": "flowline_conceptual.json",
"sFilename_flowline_conceptual_info": "flowline_conceptual_info.json",
"sFilename_flowline_edge": "flowline_edge.json",
"sFilename_flowline_filter": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/streamord7above.shp",
"sFilename_flowline_filter_json": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/001/flowline_filter.json",
"sFilename_flowline_intersect": "flowline_intersect_mesh.json",
"sFilename_flowline_raw": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/allflowline.shp",
"sFilename_flowline_segment_index_before_intersect": "flowline_segment_index_before_intersect.json",
"sFilename_flowline_simplified": "flowline_simplified.json",
"sFilename_flowline_simplified_info": "flowline_simplified_info.json",
"sFilename_flowline_topo": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/flowline.csv",
"sWorkspace_output_basin": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/001"
}
]
28 changes: 14 additions & 14 deletions tests/configurations/pyhexwatershed_susquehanna_square.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dLongitude_right": 180.0,
"dResolution_degree": 0.5,
"dResolution_meter": 10000.0,
"iCase_index": 3,
"iCase_index": 5,
"iFlag_create_mesh": 1,
"iFlag_elevation_profile": 0,
"iFlag_flowline": 1,
Expand All @@ -19,26 +19,26 @@
"iFlag_simplification": 1,
"iFlag_stream_burning_topology": 1,
"iFlag_use_mesh_dem": 0,
"iMesh_type": 2,
"iMesh_type": 3,
"nOutlet": 1,
"pPyFlowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline",
"sCase": "pyhexwatershed20220404003",
"pPyFlowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline",
"sCase": "pyhexwatershed20220404005",
"sDate": "20220404",
"sFilename_basins": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/configuration_basin.json",
"sFilename_dem": "/qfs/people/liao313/data/hexwatershed/susquehanna/raster/dem/dem_ext.tif",
"sFilename_elevation": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/square_elevation.json",
"sFilename_basins": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/configuration_basin.json",
"sFilename_dem": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/dem_ext.tif",
"sFilename_elevation": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/latlon_elevation.json",
"sFilename_hexwatershed": "hexwatershed",
"sFilename_mesh": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/square.json",
"sFilename_mesh_info": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/square_mesh_info.json",
"sFilename_mesh": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/latlon.json",
"sFilename_mesh_info": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/latlon_mesh_info.json",
"sFilename_mesh_netcdf": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/lnd_cull_mesh.nc",
"sFilename_model_configuration": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/configuration.json",
"sFilename_model_configuration": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/configuration.json",
"sFilename_spatial_reference": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/boundary_proj.shp",
"sJob": "pyhexwatershed",
"sMesh_type": "square",
"sMesh_type": "latlon",
"sModel": "pyhexwatershed",
"sRegion": "susquehanna",
"sWorkspace_bin": "/qfs/people/liao313/workspace/python/pyhexwatershed/bin",
"sWorkspace_output": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/",
"sWorkspace_output_hexwatershed": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/hexwatershed",
"sWorkspace_output_pyflowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline"
"sWorkspace_output": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005",
"sWorkspace_output_hexwatershed": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/hexwatershed",
"sWorkspace_output_pyflowline": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"sFilename_flowline_conceptual_info": "flowline_conceptual_info.json",
"sFilename_flowline_edge": "flowline_edge.json",
"sFilename_flowline_filter": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/streamord7above.shp",
"sFilename_flowline_filter_json": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/001/flowline_filter.json",
"sFilename_flowline_filter_json": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/001/flowline_filter.json",
"sFilename_flowline_intersect": "flowline_intersect_mesh.json",
"sFilename_flowline_raw": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/allflowline.shp",
"sFilename_flowline_segment_index_before_intersect": "flowline_segment_index_before_intersect.json",
"sFilename_flowline_simplified": "flowline_simplified.json",
"sFilename_flowline_simplified_info": "flowline_simplified_info.json",
"sFilename_flowline_topo": "/qfs/people/liao313/workspace/python/pyhexwatershed/data/susquehanna/input/flowline.csv",
"sWorkspace_output_basin": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404003/pyflowline/001"
"sWorkspace_output_basin": "/compyfs/liao313/04model/pyhexwatershed/susquehanna/pyhexwatershed20220404005/pyflowline/001"
}
]
8 changes: 4 additions & 4 deletions tests/example/create_model_condfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#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 = 'square'
iCase_index = 3
dResolution_meter=5000
sMesh_type = 'latlon'
iCase_index = 5
dResolution_meter=10000
sDate='20220404'
else:
if len(sys.argv)> 1:
Expand All @@ -47,7 +47,7 @@
sWorkspace_output = '/compyfs/liao313/04model/pyhexwatershed/susquehanna'
sWorkspace_bin = realpath( sPath + '/bin' )

sFilename_configuration_in = sPath + '/tests/configurations/pyhexwatershed_susquehanna_square.json'
sFilename_configuration_in = sPath + '/tests/configurations/pyhexwatershed_susquehanna_latlon.json'
sWorkspace_data = realpath( sPath + '/data/susquehanna' )
oPyhexwatershed = pyhexwatershed_generate_template_configuration_file(sFilename_configuration_in,sWorkspace_bin, sWorkspace_input, sWorkspace_output, iFlag_use_mesh_dem_in = 0, sMesh_type_in=sMesh_type, iCase_index_in = iCase_index, sDate_in = sDate)
print(oPyhexwatershed.tojson())
Expand Down
7 changes: 4 additions & 3 deletions tests/example/run_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#python notebook.py --sMesh_type hexagon --iCase_index 1 --dResolution_meter 50000 --sDate 20220201
pArgs = parser.parse_args()

sMesh_type = 'square'
iCase_index = 3
sMesh_type = 'hexagon'
iCase_index = 2
dResolution_meter=5000
sDate='20220404'
sPath = str( Path().resolve() )
Expand Down Expand Up @@ -103,7 +103,7 @@
aCell_out = oPyhexwatershed.assign_elevation_to_cells()
oPyhexwatershed.pPyFlowline.export()
oPyhexwatershed.export_config_to_json()
#exit()

oPyhexwatershed.run_hexwatershed()
oPyhexwatershed.analyze()
oPyhexwatershed.export()
Expand All @@ -123,6 +123,7 @@
oPyhexwatershed.pPyFlowline.dLatitude_bot= 39.20
oPyhexwatershed.pPyFlowline.dLatitude_top= 42.8
oPyhexwatershed.run_pyflowline()
oPyhexwatershed.pPyFlowline.export()
oPyhexwatershed.export_config_to_json()
oPyhexwatershed.run_hexwatershed()
oPyhexwatershed.analyze()
Expand Down

0 comments on commit 34955ff

Please sign in to comment.