From 9a49f4aa3daabf98fb1af61423e4c54309bd1417 Mon Sep 17 00:00:00 2001 From: dustming Date: Tue, 14 Dec 2021 21:13:01 -0500 Subject: [PATCH] update hru function --- basinmaker/basinmaker.py | 4 ++- basinmaker/hymodin/raveninput.py | 54 +++++++++++++++----------------- basinmaker/postprocessing/hru.py | 8 ++--- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/basinmaker/basinmaker.py b/basinmaker/basinmaker.py index b9dbb968..fac35a6a 100644 --- a/basinmaker/basinmaker.py +++ b/basinmaker/basinmaker.py @@ -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, diff --git a/basinmaker/hymodin/raveninput.py b/basinmaker/hymodin/raveninput.py index c6ab4e26..3bf24151 100644 --- a/basinmaker/hymodin/raveninput.py +++ b/basinmaker/hymodin/raveninput.py @@ -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 @@ -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") diff --git a/basinmaker/postprocessing/hru.py b/basinmaker/postprocessing/hru.py index d75d6cb6..3f0512e3 100644 --- a/basinmaker/postprocessing/hru.py +++ b/basinmaker/postprocessing/hru.py @@ -6,7 +6,7 @@ import numpy as np import tempfile import os - +import importlib def GenerateHRUS_qgis( @@ -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 @@ -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')