Skip to content

Commit f7f1154

Browse files
committed
updating snow calculation in HBV
1 parent c51fba5 commit f7f1154

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

MATILDA/MATILDA_slim/MATILDA.py

+35-5
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def glacier_change(output_DDM, lookup_table, glacier_profile, parameter):
509509
in the unit mm / day.
510510
"""
511511

512-
def hbv_simulation(input_df_catchment, parameter):
512+
def hbv_simulation(input_df_catchment, parameter, glacier_area=None):
513513
print("Running HBV routine")
514514
# 1. new temporary dataframe from input with daily values
515515
if "PE" in input_df_catchment.columns:
@@ -573,7 +573,21 @@ def hbv_simulation(input_df_catchment, parameter):
573573
SNOW_cal = snowfrac_cal * Prec_cal
574574
# snow correction factor
575575
SNOW_cal = parameter.SFCF * SNOW_cal
576-
SNOW_cal =SNOW_cal * (1-(parameter.area_glac / parameter.area_cat))
576+
# get the new glacier area for each year
577+
if glacier_area is not None:
578+
glacier_area = glacier_area.iloc[1:, :]
579+
glacier_area["time"] = glacier_area["time"].astype(str).astype(float).astype(int)
580+
SNOW2 = pd.DataFrame(SNOW_cal)
581+
SNOW2["area"] = 0
582+
for year in range(len(glacier_area)):
583+
SNOW2["area"] = np.where(SNOW2.index.year == glacier_area["time"].iloc[year],
584+
glacier_area["glacier_area"].iloc[year],
585+
SNOW2["area"])
586+
587+
SNOW2["T2"] = SNOW2["T2"] * (1 - (SNOW2["area"] / parameter.area_cat))
588+
SNOW_cal = SNOW2['T2'].squeeze()
589+
else:
590+
SNOW_cal["T2"] = SNOW_cal["T2"] * (1 - (parameter.area_glac / parameter.area_cat))
577591
# evaporation correction
578592
# a. calculate long-term averages of daily temperature
579593
Temp_mean_cal = np.array([Temp_cal.loc[Temp_cal.index.dayofyear == x].mean() \
@@ -676,8 +690,21 @@ def hbv_simulation(input_df_catchment, parameter):
676690
SNOW = parameter.SFCF * SNOW
677691
# snow correction factor
678692
SNOW = parameter.SFCF * SNOW
679-
SNOW = SNOW * (1-(parameter.area_glac / parameter.area_cat))
680-
# evaporation correction
693+
# get the new glacier area for each year
694+
if glacier_area is not None:
695+
glacier_area = glacier_area.iloc[1:, :]
696+
glacier_area["time"] = glacier_area["time"].astype(str).astype(float).astype(int)
697+
SNOW2 = pd.DataFrame(SNOW)
698+
SNOW2["area"] = 0
699+
for year in range(len(glacier_area)):
700+
SNOW2["area"] = np.where(SNOW2.index.year == glacier_area["time"].iloc[year],
701+
glacier_area["glacier_area"].iloc[year],
702+
SNOW2["area"])
703+
704+
SNOW2["T2"] = SNOW2["T2"] * (1 - (SNOW2["area"] / parameter.area_cat))
705+
SNOW = SNOW2['T2'].squeeze()
706+
else:
707+
SNOW["T2"] = SNOW["T2"] * (1 - (parameter.area_glac / parameter.area_cat)) # evaporation correction
681708
# a. calculate long-term averages of daily temperature
682709
Temp_mean = np.array([Temp.loc[Temp.index.dayofyear == x].mean() \
683710
for x in range(1, 367)])
@@ -815,7 +842,10 @@ def hbv_simulation(input_df_catchment, parameter):
815842
print("Finished HBV routine")
816843
return hbv_results
817844

818-
output_HBV = hbv_simulation(input_df_catchment, parameter)
845+
if glacier_profile is not None:
846+
output_HBV = hbv_simulation(input_df_catchment, parameter, glacier_area=glacier_change_area)
847+
else:
848+
output_HBV = hbv_simulation(input_df_catchment, parameter)
819849
output_HBV = output_HBV[parameter.sim_start:parameter.sim_end]
820850

821851
# Output postprocessing

MATILDA/run_MATILDA.py

-13
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,4 @@
5454
output_MATILDA[4].show()
5555

5656
output_MATILDA[0].Q_Total
57-
<<<<<<< HEAD
58-
=======
5957

60-
##
61-
obs = pd.read_csv("/home/ana/Seafile/Ana-Lena_Phillip/data/input_output/input/observations/bash_kaindy/runoff_bashkaindy_04_2019-11_2020_temp_limit.csv")
62-
obs_poly = pd.read_csv("/home/ana/Seafile/Masterarbeit/Data/Input/discharge_bashkaingdy_polyfitted_2019-04_11-2020.csv")
63-
64-
plt.plot(obs["Qobs"], label="Obs old (mm?)")
65-
#plt.plot(obs_poly["discharge_poly"], label="Obs poly (m3/s)")
66-
#plt.plot((obs["Qobs"] / 86400*(46.232*1000000)/1000), label="Obs (old) calc from mm to m/3")
67-
plt.plot((obs_poly["discharge_poly"] * 86400 / (46.232 * 1000000) * 1000), label="Obs poly from m/3 to mm")
68-
plt.legend()
69-
plt.show()
70-
>>>>>>> 235dfbba2e4a1bcf29f4d78aee722abb240fd595

Test_area/MATILDA_hourly.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
MATILDA (Modeling wATer resources In gLacierizeD cAtchments) is a combination of a degree day model and the HBV model (Bergstöm 1976) to compute total runoff of glacierized catchments.
44
This file may use the input files created by the COSIPY-utility "aws2cosipy" as forcing data and or a simple dataframe with temperature, precipitation and if possible evapotranspiration and additional observation runoff data to validate it.
55
"""
6-
# Import all necessary python packages
6+
## Import all necessary python packages
77
import xarray as xr
88
import numpy as np
99
import pandas as pd
@@ -16,7 +16,7 @@
1616
from matplotlib.offsetbox import AnchoredText
1717
from MATILDA_slim import MATILDA
1818

19-
19+
##
2020
# Setting the parameter for the MATILDA simulation
2121
def MATILDA_parameter(input_df, set_up_start=None, set_up_end=None, sim_start=None, sim_end=None, freq="D",
2222
lat= None, area_cat=None, area_glac=None, ele_dat=None, ele_glac=None, ele_cat=None, parameter_df = None,
@@ -1152,9 +1152,10 @@ def MATILDA_simulation(input_df, obs=None, glacier_profile=None, output=None, se
11521152

11531153
parameter = MATILDA.MATILDA_parameter(df, set_up_start='2018-01-01 00:00:00', set_up_end='2018-12-31 23:00:00',
11541154
sim_start='2019-01-01 00:00:00', sim_end='2020-11-01 23:00:00', freq="D",
1155-
lat=41, area_cat=46.23, area_glac=2.566, ele_dat=2250, ele_glac=4035,
1155+
lat=41, area_cat=46.23, area_glac=2.566, ele_dat=3864, ele_glac=4035,
11561156
ele_cat=3485, CFMAX_ice=5.5, CFMAX_snow=3)
11571157

1158+
11581159
# load the right package for the right resolution
11591160
input_df_glacier = df[parameter.sim_start:parameter.sim_end]
11601161
if parameter.area_glac > 0:

0 commit comments

Comments
 (0)