-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqme_vars.py
98 lines (79 loc) · 2.65 KB
/
qme_vars.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import numpy as np
from qme_utils import qme_var
def get_qme_var(var):
"""
Return a default set of options for a given variable name.
This is convenient for commonly used variables and can be added to or adjusted as required.
Example comments are included for pr.
"""
# var is already an instance of the qme_var class
# this is here to save checking at other times
if isinstance(var, qme_var):
return var
# defaults in case they are not set
max_bin = 500
scaling = 'linear'
if var == "pr":
# expected units: mm/day
# lower limit for the given variable - anything lower will be set to this value
lower_lim = 0
# upper limit for the variable - anything higher will be set to this value
upper_lim = 1250
# The bin count for calculating distributions (noting that 1 will be added later as the range is inclusive)
# Increasing this increases the resolution of the bias correction at the cost of computation speed and memory
max_bin = 500
# Scaling mode for calculating distribution bins
# Values are mapped from between lower_lim and upper_lim to between 0 and max_bin
# Mode can either be "linear" or "log" to define how values are distributed
scaling = "log"
elif var == "tasmax":
# expected units: C
lower_lim = -35
upper_lim = 65
max_bin = 500
scaling = "linear"
elif var == "tasmin":
# expected units: C
lower_lim = -55
upper_lim = 45
max_bin = 500
scaling = "linear"
elif var == "wswd":
# expected units: m/s
lower_lim = 0
upper_lim = 50
max_bin = 500
scaling = "linear"
elif var == "sfcWindmax":
# expected units: m/s
lower_lim = 0
upper_lim = 50
max_bin = 500
scaling = "linear"
elif var == "rsds":
# expected units: W m-2
lower_lim = 0
upper_lim = 500
max_bin = 500
scaling = "linear"
elif var == "rh":
# expected units: %
lower_lim = 0
upper_lim = 125
max_bin = 500
scaling = "linear"
elif var == "hursmax":
# expected units: %
lower_lim = 0
upper_lim = 100
max_bin = 500
scaling = "linear"
elif var == "hursmin":
# expected units: %
lower_lim = 0
upper_lim = 100
max_bin = 500
scaling = "linear"
else:
raise ValueError("Cannot find a matching variable from given input, check qme_vars.py")
return qme_var(lower_lim, upper_lim, max_bin, scaling)