Skip to content

Commit

Permalink
update hru function
Browse files Browse the repository at this point in the history
  • Loading branch information
dustming committed Dec 15, 2021
1 parent 3ce1af3 commit 9a49f4a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
4 changes: 3 additions & 1 deletion basinmaker/basinmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ def Generate_HRUs(
Other_Ply_ID_1="O_ID_1"
Veg_ID="Veg_ID"
Other_Ply_ID_2="O_ID_2"


os.environ["GISDBASE"] = path_output_folder

generate_hrus_method(
Path_Subbasin_Ply=path_subbasin_polygon,
Landuse_info=path_landuse_info,
Expand Down
54 changes: 26 additions & 28 deletions basinmaker/hymodin/raveninput.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,6 @@ def Generate_Raven_Channel_rvp_rvh_String(
Model_rvh_string_list.append(
" :Units none none none km none"
) # orvh.write(" :Units none none none km none"+"\n")

catinfo_sub = catinfo.drop_duplicates(
"SubId", keep="first"
) ### remove duplicated subids, beacuse of including hrus in the dataframe
Expand Down Expand Up @@ -1512,33 +1511,32 @@ def Generate_Raven_Channel_rvp_rvh_String(
Model_rvh_string_list.append("\n") # orvh.write("\n")
##########################################

Model_rvh_string_list.append(":SubBasinProperties")
Model_rvh_string_list.append(":Parameters, TIME_TO_PEAK, TIME_CONC, TIME_LAG,")
Model_rvh_string_list.append(":Units , d , d, d,")


print(Tr)
for i in range(0, len(catinfo_sub)):
### Get catchment width and dpeth
catid = int(catinfo_sub["SubId"].values[i])
subarea = int(catinfo_sub["BasArea"].values[i]/1000/1000)
if (catinfo_sub["Lake_Cat"].values[i] <= 0):
routing_area = subarea
else:
routing_area = max(0.0001,subarea - catinfo_sub["LakeArea"].values[i]/1000/1000)

Tc = 0.76*routing_area**0.38
Tl = 0.6*Tc
Tp = Tr/2 +Tl

Tc = '{:>10.4f}'.format(Tc) + "," + tab
Tl = '{:>10.4f}'.format(Tl) + "," + tab
Tp = '{:>10.4f}'.format(Tp) + "," + tab
Model_rvh_string_list.append(tab + str(catid) + "," + tab + Tp + Tc + Tl)

Model_rvh_string_list.append(":EndSubBasinProperties")

Model_rvh_string_list.append("\n") # orvh.write("\n")
# Model_rvh_string_list.append(":SubBasinProperties")
# Model_rvh_string_list.append(":Parameters, TIME_TO_PEAK, TIME_CONC, TIME_LAG,")
# Model_rvh_string_list.append(":Units , d , d, d,")
#
#
# for i in range(0, len(catinfo_sub)):
# ### Get catchment width and dpeth
# catid = int(catinfo_sub["SubId"].values[i])
# subarea = int(catinfo_sub["BasArea"].values[i]/1000/1000)
# if (catinfo_sub["Lake_Cat"].values[i] <= 0):
# routing_area = subarea
# else:
# routing_area = max(0.0001,subarea - catinfo_sub["LakeArea"].values[i]/1000/1000)
#
# Tc = max(0.01,0.76*routing_area**0.38/24)
# Tl = 0.6*Tc
# Tp = Tr/2 +Tl
#
# Tc = '{:>10.4f}'.format(Tc) + "," + tab
# Tl = '{:>10.4f}'.format(Tl) + "," + tab
# Tp = '{:>10.4f}'.format(Tp) + "," + tab
# Model_rvh_string_list.append(tab + str(catid) + "," + tab + Tp + Tc + Tl)
#
# Model_rvh_string_list.append(":EndSubBasinProperties")
#
# Model_rvh_string_list.append("\n") # orvh.write("\n")

##########################################
Model_rvh_string_list.append(":HRUs") # orvh.write(":HRUs"+"\n")
Expand Down
8 changes: 3 additions & 5 deletions basinmaker/postprocessing/hru.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import tempfile
import os

import importlib


def GenerateHRUS_qgis(
Expand Down Expand Up @@ -929,9 +929,7 @@ def Union_Ply_Layers_And_Simplify(
layers
"""
num = str(np.random.randint(1, 10000 + 1))

if os.getenv("GISDBASE"):

if importlib.util.find_spec("grass.script") is not None and importlib.util.find_spec("grass_session") is not None:
import grass.script as grass
import grass.script.setup as gsetup
from grass.pygrass.modules import Module
Expand Down Expand Up @@ -999,7 +997,7 @@ def Union_Ply_Layers_And_Simplify(
)["OUTPUT"]


if os.getenv("GISDBASE"):
if importlib.util.find_spec("grass.script") is not None and importlib.util.find_spec("grass_session") is not None:

grass_layer_1 = qgis_vector_fix_geometries(
processing, context, INPUT=mem_union_fix_temp, OUTPUT=os.path.join(grassdb,'union_input_1_'+str(i)+'_.shp')
Expand Down

0 comments on commit 9a49f4a

Please sign in to comment.