Skip to content

Commit

Permalink
Merge pull request #75 from changliao1025/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
changliao1025 authored May 17, 2023
2 parents 661e32b + 4d6db96 commit 08470b6
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools wheel twine
python -m pip install setuptools wheel
- name: Build external package
run: python setup.py build_external

- name: Build source distribution
run: |
python setup.py sdist bdist_wheel
python setup.py bdist_wheel
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

25 changes: 16 additions & 9 deletions meta.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package:
name: "hexwatershed"
version: "0.2.23"
version: "0.2.24"

source:
git_rev: v0.2.23
git_rev: v0.2.24
git_url: https://github.com/changliao1025/pyhexwatershed

build:
Expand All @@ -12,8 +12,7 @@ build:
host:
platform: linux-64
script:
- python setup.py build_external
# Build the package for macOS (64-bit)
- python setup.py build_external
host:
platform: osx-64
script:
Expand All @@ -33,19 +32,27 @@ requirements:
- make
- python
- setuptool
- pip
run:
- python
- numpy
- matplotlib
- matplotlib-base
- gdal
- pyflowline

test:
imports:
- pyhexwatershed
commands:
- pip check
requires:
- pip

about:
home: https://github.com/changliao1025/pyhexwatershed
license: MIT
license_familY: MIT
license_file: LICENSE
summary: "HexWatershed"
summary: A mesh-independent flow direction model for hydrologic models
license: BSD-2-Clause
license_file: LICENSE.md

extra:
recipe-maintainers:
Expand Down
21 changes: 8 additions & 13 deletions pyhexwatershed/classes/_visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import matplotlib.cm as cm
import matplotlib.animation as animation
from matplotlib.animation import FuncAnimation
import matplotlib

mpl.use("Agg")
from shapely.wkt import loads
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
Expand Down Expand Up @@ -371,6 +371,7 @@ def _plot_mesh_with_variable(self, sFilename_in, sVariable_in, aExtent_in=None,
dLat_max = aLocation[k,1]
if aLocation[k,1] < dLat_min:
dLat_min = aLocation[k,1]

pProjection_map = ccrs.Orthographic(central_longitude = 0.50*(dLon_max+dLon_min), central_latitude = 0.50*(dLat_max+dLat_min), globe=None)
fig = plt.figure( dpi=300 )
fig.set_figwidth( iFigwidth )
Expand Down Expand Up @@ -551,18 +552,12 @@ def _plot_flow_direction(self, sFilename_in, aExtent_in=None, iFigwidth_in=None
dummy0 = loads( pGeometry_in.ExportToWkt() )
aCoords_gcs = dummy0.coords
aCoords_gcs= np.array(aCoords_gcs)
nvertex = len(aCoords_gcs)
for i in range(nvertex):
dLon = aCoords_gcs[i][0]
dLat = aCoords_gcs[i][1]
if dLon > dLon_max:
dLon_max = dLon
if dLon < dLon_min:
dLon_min = dLon
if dLat > dLat_max:
dLat_max = dLat
if dLat < dLat_min:
dLat_min = dLat
aCoords_gcs = aCoords_gcs[:,0:2]
dLon_max = np.max( [dLon_max, np.max(aCoords_gcs[:,0])] )
dLon_min = np.min( [dLon_min, np.min(aCoords_gcs[:,0])] )
dLat_max = np.max( [dLat_max, np.max(aCoords_gcs[:,1])] )
dLat_min = np.min( [dLat_min, np.min(aCoords_gcs[:,1])] )

pProjection_map = ccrs.Orthographic(central_longitude = 0.50*(dLon_max+dLon_min), central_latitude = 0.50*(dLat_max+dLat_min), globe=None)
fig = plt.figure( dpi=300)
fig.set_figwidth( iFigwidth )
Expand Down
89 changes: 71 additions & 18 deletions pyhexwatershed/classes/pycase.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class hexwatershedcase(object):
iMesh_type = 4
iFlag_save_mesh = 0
iFlag_use_mesh_dem=0
iFlag_user_provided_binary= 0
iFlag_slurm = 0
nOutlet=1
dResolution_degree=0.0
Expand All @@ -67,6 +68,7 @@ class hexwatershedcase(object):
sFilename_mesh_info=''
sFilename_flowline_info=''
sFilename_basins=''
sFilename_hexwatershed_bin=''
sWorkspace_model_region=''

sRegion=''
Expand Down Expand Up @@ -167,6 +169,11 @@ def __init__(self, aConfig_in):

if 'iFlag_elevation_profile' in aConfig_in:
self.iFlag_elevation_profile = int(aConfig_in[ 'iFlag_elevation_profile'])

if 'iFlag_user_provided_binary' in aConfig_in:
self.iFlag_user_provided_binary = int(aConfig_in[ 'iFlag_user_provided_binary'])
else:
self.iFlag_user_provided_binary = 0

if 'nOutlet' in aConfig_in:
self.nOutlet = int(aConfig_in[ 'nOutlet'])
Expand All @@ -191,6 +198,27 @@ def __init__(self, aConfig_in):
if 'sFilename_mesh_netcdf' in aConfig_in:
self.sFilename_mesh_netcdf = aConfig_in['sFilename_mesh_netcdf']

if self.iFlag_user_provided_binary == 1:
print('The model will use the user provided binary file')
if 'sFilename_hexwatershed_bin' in aConfig_in:
self.sFilename_hexwatershed_bin = aConfig_in['sFilename_hexwatershed_bin']
#check file exist
if not os.path.exists(self.sFilename_hexwatershed_bin):
print('The user provided binary file does not exist. The model will use the default binary file')
self.iFlag_user_provided_binary = 0
pass
else:
print(self.sFilename_hexwatershed_bin)

else:
print('The binray file is not provided. The model will use the default binary file')
self.iFlag_user_provided_binary = 0
pass
else:
print('The model will use the default binary file')
pass


if 'iCase_index' in aConfig_in:
iCase_index = int(aConfig_in['iCase_index'])
else:
Expand Down Expand Up @@ -257,8 +285,6 @@ def __init__(self, aConfig_in):

if 'sJob' in aConfig_in:
self.sJob = aConfig_in['sJob']



if 'sFilename_basins' in aConfig_in:
self.sFilename_basins = aConfig_in['sFilename_basins']
Expand Down Expand Up @@ -329,25 +355,52 @@ def setup(self):
self.pPyFlowline.setup()
#setup the hexwatershed
system = platform.system()
# Get the distribution object for the package
distribution = pkg_resources.get_distribution('hexwatershed')
# Get the installation path for the package
sPath_installation = distribution.location
if platform.system() == 'Windows':
sFilename_executable = 'hexwatershed.exe'
sFilename_hexwatershed_bin = os.path.join(str(Path(sPath_installation + '/pyhexwatershed/_bin/') ) , sFilename_executable )
#copy the binary file
iFlag_found_binary = 0


#if user provided the binary, then use the user provided binary
if self.iFlag_user_provided_binary == 1:
sFilename_executable = 'hexwatershed'
#copy the binary
iFlag_found_binary = 1
sFilename_new = os.path.join(str(Path(self.sWorkspace_output_hexwatershed) ) , sFilename_executable )
copy2(sFilename_hexwatershed_bin, sFilename_new)
copy2(self.sFilename_hexwatershed_bin, sFilename_new)
os.chmod(sFilename_new, stat.S_IRWXU )
pass
else:

# Get the distribution object for the package
distribution = pkg_resources.get_distribution('hexwatershed')
# Get the installation path for the package
sPath_installation = distribution.location

if system == 'Windows':
sFilename_executable = 'hexwatershed.exe'
else:
sFilename_executable = 'hexwatershed'

#search for system wide binary in the system path
for folder in os.environ['PATH'].split(os.pathsep):
sFilename_hexwatershed_bin = os.path.join(folder, sFilename_executable)
if os.path.isfile(sFilename_hexwatershed_bin):
print('Found binary at:', sFilename_hexwatershed_bin)
iFlag_found_binary = 1
break
else:
print('Binary not found in system path.')
if iFlag_found_binary ==1:
pass
else:
sFilename_hexwatershed_bin = os.path.join(str(Path(sPath_installation + '/pyhexwatershed/_bin/') ) , sFilename_executable )
if os.path.isfile(sFilename_hexwatershed_bin):
iFlag_found_binary=1
#copy the binary file
sFilename_new = os.path.join(str(Path(self.sWorkspace_output_hexwatershed) ) , sFilename_executable )
copy2(sFilename_hexwatershed_bin, sFilename_new)
os.chmod(sFilename_new, stat.S_IRWXU )
else:
iFlag_found_binary = 0

else:
sFilename_executable = 'hexwatershed'
sFilename_hexwatershed_bin = os.path.join(str(Path(sPath_installation + '/pyhexwatershed/_bin/') ) , sFilename_executable )
#copy the binary file
sFilename_new = os.path.join(str(Path(self.sWorkspace_output_hexwatershed) ) , sFilename_executable )
copy2(sFilename_hexwatershed_bin, sFilename_new)
os.chmod(sFilename_new, stat.S_IRWXU )

return

Expand Down
78 changes: 39 additions & 39 deletions pyhexwatershed/pyhexwatershed_read_model_configuration_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import os
import sys #used to add system path
import datetime
import json
Expand All @@ -9,20 +9,20 @@
pDate = datetime.datetime.today()
sDate_default = "{:04d}".format(pDate.year) + "{:02d}".format(pDate.month) + "{:02d}".format(pDate.day)

def pyhexwatershed_read_model_configuration_file(sFilename_configuration_in,\
iCase_index_in=None, \
iFlag_stream_burning_topology_in = None,\
iFlag_elevation_profile_in = None,\
iFlag_use_mesh_dem_in= None,\
dResolution_meter_in = None,\
sDate_in = None,\
sMesh_type_in=None):
def pyhexwatershed_read_model_configuration_file(sFilename_configuration_in,
iCase_index_in=None,
iFlag_stream_burning_topology_in = None,
iFlag_elevation_profile_in = None,
iFlag_use_mesh_dem_in= None,
dResolution_meter_in = None,
sDate_in = None,
sMesh_type_in=None):



# Opening JSON file
with open(sFilename_configuration_in) as json_file:
aConfig = json.load(json_file)
aConfig = json.load(json_file)

if sDate_in is not None:
sDate = sDate_in
else:
Expand All @@ -35,53 +35,53 @@ def pyhexwatershed_read_model_configuration_file(sFilename_configuration_in,\
sMesh_type = aConfig["sMesh_type"]
pass

if iCase_index_in is not None:
if iCase_index_in is not None:
iCase_index = iCase_index_in
else:
else:
iCase_index = int( aConfig['iCase_index'])
pass
pass

if iFlag_stream_burning_topology_in is not None:
if iFlag_stream_burning_topology_in is not None:
iFlag_stream_burning_topology = iFlag_stream_burning_topology_in
else:
else:
iFlag_stream_burning_topology = int( aConfig['iFlag_stream_burning_topology'])
pass
if iFlag_elevation_profile_in is not None:
pass

if iFlag_elevation_profile_in is not None:
iFlag_elevation_profile = iFlag_elevation_profile_in
else:
else:
iFlag_elevation_profile = int( aConfig['iFlag_elevation_profile'])
pass
if iFlag_use_mesh_dem_in is not None:
pass

if iFlag_use_mesh_dem_in is not None:
iFlag_use_mesh_dem = iFlag_use_mesh_dem_in
else:
else:
iFlag_use_mesh_dem = int( aConfig['iFlag_use_mesh_dem'])
pass
pass


if dResolution_meter_in is not None:
if dResolution_meter_in is not None:
dResolution_meter = dResolution_meter_in
else:
else:
dResolution_meter = float( aConfig['dResolution_meter'])
pass
pass

aConfig["sDate"] = sDate
aConfig["sMesh_type"] = sMesh_type
aConfig["iCase_index"] = iCase_index
aConfig["iFlag_stream_burning_topology"] = iFlag_stream_burning_topology
aConfig["iFlag_elevation_profile"] = iFlag_elevation_profile
aConfig["iFlag_use_mesh_dem"] = iFlag_use_mesh_dem

aConfig["dResolution_meter"] = dResolution_meter
aConfig["sFilename_model_configuration"] = sFilename_configuration_in


oPyhexwatershed = hexwatershedcase(aConfig)
oPyflowline = flowlinecase(aConfig , iFlag_standalone_in = 0,\
sModel_in = 'pyflowline',\
sWorkspace_output_in = oPyhexwatershed.sWorkspace_output_pyflowline)
oPyflowline = flowlinecase(aConfig , iFlag_standalone_in = 0,
sModel_in = 'pyflowline',
sWorkspace_output_in = oPyhexwatershed.sWorkspace_output_pyflowline)

oPyhexwatershed.pPyFlowline = oPyflowline
return oPyhexwatershed

return oPyhexwatershed
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.23
current_version = 0.2.24
commit = True
tag = True

Expand Down
Loading

0 comments on commit 08470b6

Please sign in to comment.