Skip to content

Commit

Permalink
Merge pull request #52 from openstreams/alpha_fixed
Browse files Browse the repository at this point in the history
Alpha fixed
  • Loading branch information
verseve committed Mar 8, 2023
2 parents c24c589 + 98931af commit bdc9b79
Show file tree
Hide file tree
Showing 56 changed files with 5,878 additions and 4,483 deletions.
2 changes: 1 addition & 1 deletion tests/test_wflow_hbv.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def testapirun(self):

my_data = np.genfromtxt(os.path.join(caseName, runId, "run.csv"), delimiter=",")
print("Checking discharge ....")
self.assertAlmostEqual(1045.9400254567465, my_data[:, 2].mean(), places=4)
self.assertAlmostEqual(1045.9255285898844, my_data[:, 2].mean(), places=4)

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_wflow_hbv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def testapirunhr(self):

my_data = np.genfromtxt(os.path.join(caseName, runId, "run.csv"), delimiter=",")
print("Checking discharge ....")
self.assertAlmostEqual(163.88664160221816, my_data[:, 2].mean(), places=4)
self.assertAlmostEqual(163.9204001436631, my_data[:, 2].mean(), places=4)

if __name__ == "__main__":
unittest.main()
14 changes: 7 additions & 7 deletions wflow/JarvisCoefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def calcEp(self, k):
def calcEpSnow(self, k):
"""
REQUIRED INPUT:
daily input data
daily input data
"""
# resistenceAeroD(self)
# potential_evaporation(self,k)
Expand All @@ -55,7 +55,7 @@ def calcEpSnow(self, k):
def calcEpSnowHour(self, k):
"""
REQUIRED INPUT:
hourly input data
hourly input data
"""
# resistenceAeroD(self)
# potential_evaporation(self,k)
Expand Down Expand Up @@ -116,7 +116,7 @@ def JC_temperature(self, k):
pcr.ifthenelse(
pcr.pcrand(self.Tmean >= self.JC_Topt - 1, self.Tmean <= self.JC_Topt + 1),
1,
1 - self.JC_Topt ** -2 * (self.Tmean - self.JC_Topt) ** 2,
1 - self.JC_Topt**-2 * (self.Tmean - self.JC_Topt) ** 2,
),
)
self.JC_temp = pcr.ifthenelse(JC_temp1 < 0, 0, JC_temp1)
Expand All @@ -131,7 +131,7 @@ def JC_vapourDeficit(self, k):
- D05 (vapourpressure deficit halfway between 1 and Cd2, fixed at 1.5 kPa (Matsumoto et al. 2008))
- Cd1 (first vapour pressure parameter, fixed at 3 (Matsumoto et al. 2008))
- Cd2 (second vapour pressure parameter, fixed at 0.1 (Matsumoto et al. 2008))
"""
"""

denom = 1 + (self.vpd / self.JC_D05[k]) ** self.JC_cd1[k]
JC_vpd1 = (1 / denom) * (1 - self.JC_cd2[k]) + self.JC_cd2[k]
Expand All @@ -144,7 +144,7 @@ def JC_LAIeffective(self, k):
REQUIRED INPUT:
- LAI (-)
PARAMETERS:
- none (Allen et al., 2006 & Zhou et al., 2006)
- none (Allen et al., 2006 & Zhou et al., 2006)
"""

self.JC_laiEff = self.LAI / (0.2 * self.LAI + 1)
Expand Down Expand Up @@ -274,7 +274,7 @@ def downscale_evaporation(self, k):
- start of the day (derived from global radiation)
- end of the day (derived from global radiation)
PARAMETERS:
-
-
"""

# teller = numpy.nanmax(pcr.pcr2numpy(self.thestep,np.nan))
Expand Down Expand Up @@ -307,7 +307,7 @@ def downscale_evaporation_snow(self, k):
- start of the day (derived from global radiation)
- end of the day (derived from global radiation)
PARAMETERS:
-
-
"""

teller = pcr.pcr2numpy(self.thestep, np.nan)[0, 0]
Expand Down
2 changes: 2 additions & 0 deletions wflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# filter out matplotlib deprecation warning triggered by PyInstaller
# https://stackoverflow.com/q/57517371
import warnings

warnings.filterwarnings("ignore", "(?s).*MATPLOTLIBDATA.*", category=UserWarning)

# use the included gdal-data
Expand All @@ -40,6 +41,7 @@
proj_data_dir = os.path.join(basedir, "proj-data")
os.environ["PROJ_LIB"] = proj_data_dir
import pyproj.datadir

pyproj.datadir.set_data_dir(proj_data_dir)

import pyproj
Expand Down
164 changes: 82 additions & 82 deletions wflow/ops_scalar2grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ def usage(*args):

class WflowModel(pcraster.framework.DynamicModel):
"""
The user defined model class. This is your work!
"""
The user defined model class. This is your work!
"""

def __init__(self, cloneMap, Dir, RunDir, configfile):
"""
*Required*
The init function **must** contain what is shown below. Other functionality
may be added by you if needed.
"""
*Required*
The init function **must** contain what is shown below. Other functionality
may be added by you if needed.
"""
pcraster.framework.DynamicModel.__init__(self)
pcr.setclone(Dir + "/staticmaps/" + cloneMap)
self.runId = RunDir
Expand All @@ -52,22 +52,22 @@ def __init__(self, cloneMap, Dir, RunDir, configfile):

def parameters(self):
"""
List all the parameters (both static and forcing here). Use the wf_updateparameters()
function to update them in the initial section (static) and the dynamic section for
dynamic parameters and forcing date.
List all the parameters (both static and forcing here). Use the wf_updateparameters()
function to update them in the initial section (static) and the dynamic section for
dynamic parameters and forcing date.
Possible parameter types are:
Possible parameter types are:
+ staticmap: Read at startup from map
+ statictbl: Read at startup from tbl, fallback to map (need Landuse, Soil and TopoId (subcatch) maps!
+ timeseries: read map for each timestep
+ monthlyclim: read a map corresponding to the current month (12 maps in total)
+ dailyclim: read a map corresponding to the current day of the year
+ hourlyclim: read a map corresponding to the current hour of the day (24 in total)
+ staticmap: Read at startup from map
+ statictbl: Read at startup from tbl, fallback to map (need Landuse, Soil and TopoId (subcatch) maps!
+ timeseries: read map for each timestep
+ monthlyclim: read a map corresponding to the current month (12 maps in total)
+ dailyclim: read a map corresponding to the current day of the year
+ hourlyclim: read a map corresponding to the current hour of the day (24 in total)
:return: List of modelparameters
"""
:return: List of modelparameters
"""
modelparameters = []

# Static model parameters
Expand All @@ -85,53 +85,53 @@ def parameters(self):
return modelparameters

def stateVariables(self):
"""
*Required*
Returns a list of state variables that are essential to the model.
This list is essential for the resume and suspend functions to work.
This function is specific for each model and **must** be present. This is
where you specify the state variables of you model. If your model is stateless
this function must return and empty array (states = [])
In the simple example here the TSoil variable is a state
for the model.
:var TSoil: Temperature of the soil [oC]
"""
"""
*Required*
Returns a list of state variables that are essential to the model.
This list is essential for the resume and suspend functions to work.
This function is specific for each model and **must** be present. This is
where you specify the state variables of you model. If your model is stateless
this function must return and empty array (states = [])
In the simple example here the TSoil variable is a state
for the model.
:var TSoil: Temperature of the soil [oC]
"""
states = []

return states

def supplyCurrentTime(self):
"""
*Optional*
Supplies the current time in seconds after the start of the run
This function is optional. If it is not set the framework assumes
the model runs with daily timesteps.
Output:
- time in seconds since the start of the model run
"""
*Optional*
Supplies the current time in seconds after the start of the run
This function is optional. If it is not set the framework assumes
the model runs with daily timesteps.
Output:
- time in seconds since the start of the model run
"""

return self.currentTimeStep() * int(
configget(self.config, "model", "timestepsecs", "86400")
)

def suspend(self):
"""
*Required*
Suspends the model to disk. All variables needed to restart the model
are saved to disk as pcraster maps. Use resume() to re-read them
This function is required.
"""
*Required*
Suspends the model to disk. All variables needed to restart the model
are saved to disk as pcraster maps. Use resume() to re-read them
This function is required.
"""

self.logger.info("Saving initial conditions...")
#: It is advised to use the wf_suspend() function
Expand All @@ -142,16 +142,16 @@ def suspend(self):
def initial(self):

"""
*Required*
Initial part of the model, executed only once. It reads all static model
information (parameters) and sets-up the variables used in modelling.
This function is required. The contents is free. However, in order to
easily connect to other models it is advised to adhere to the directory
structure used in the other models.
"""
*Required*
Initial part of the model, executed only once. It reads all static model
information (parameters) and sets-up the variables used in modelling.
This function is required. The contents is free. However, in order to
easily connect to other models it is advised to adhere to the directory
structure used in the other models.
"""
#: pcraster option to calculate with units or cells. Not really an issue
#: in this model but always good to keep in mind.
pcr.setglobaloption("unittrue")
Expand All @@ -171,14 +171,14 @@ def initial(self):
self.logger.info("Starting Dynamic run...")

def resume(self):
"""
*Required*
"""
*Required*
This function is required. Read initial state maps (they are output of a
previous call to suspend()). The implementation shown here is the most basic
setup needed.
"""
This function is required. Read initial state maps (they are output of a
previous call to suspend()). The implementation shown here is the most basic
setup needed.
"""
self.logger.info("Reading initial conditions...")
#: It is advised to use the wf_resume() function
#: here which pick up the variable save by a call to wf_suspend()
Expand All @@ -191,20 +191,20 @@ def resume(self):

def default_summarymaps(self):
"""
*Optional*
*Optional*
Return a default list of variables to report as summary maps in the outsum dir.
The ini file has more options, including average and sum
"""
Return a default list of variables to report as summary maps in the outsum dir.
The ini file has more options, including average and sum
"""
return ["self.Stations"]

def dynamic(self):
"""
*Required*
This is where all the time dependent functions are executed. Time dependent
output should also be saved here.
"""
*Required*
This is where all the time dependent functions are executed. Time dependent
output should also be saved here.
"""

self.wf_updateparameters() # read the temperature map for each step (see parameters())

Expand Down Expand Up @@ -236,10 +236,10 @@ def dynamic(self):
def main(argv=None):
"""
*Optional but needed it you want to run the model from the command line*
Perform command line execution of the model. This example uses the getopt
module to parse the command line options.
The user can set the caseName, the runDir, the timestep and the configfile.
"""
global multpars
Expand Down
8 changes: 4 additions & 4 deletions wflow/pcrglobwb/groundwater.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ def __init__(self, iniItems, landmask, spinUp, Dir, staticmaps, cloneMap):

# calculate recessionCoeff (unit; day-1)
self.recessionCoeff = (
(math.pi ** 2.0)
(math.pi**2.0)
* aquiferThicknessForRecessionCoeff
/ (4.0 * self.specificYield * (aquiferWidth ** 2.0))
/ (4.0 * self.specificYield * (aquiferWidth**2.0))
)

# assign the reccession coefficient based on the given pcraster file
Expand All @@ -289,8 +289,8 @@ def __init__(self, iniItems, landmask, spinUp, Dir, staticmaps, cloneMap):
)
else:
minRecessionCoeff = (
1.0e-4
) # This is the minimum value used in Van Beek et al. (2011).
1.0e-4 # This is the minimum value used in Van Beek et al. (2011).
)
self.recessionCoeff = pcr.max(minRecessionCoeff, self.recessionCoeff)
#####################################################################################################################################################

Expand Down

0 comments on commit bdc9b79

Please sign in to comment.