Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
IPSL
LMD
InTro
RoutingPP
Commits
3b41a20e
Commit
3b41a20e
authored
Feb 06, 2021
by
POLCHER Jan
🚴🏾
Browse files
First set of adjusted parameter and new calculation of maximum acceptable time step.
parent
d0a8f271
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
5 deletions
+42
-5
GraphHydro.py
GraphHydro.py
+38
-1
HydroGrid.py
HydroGrid.py
+4
-4
No files found.
GraphHydro.py
View file @
3b41a20e
...
@@ -25,6 +25,43 @@ import RPPtools as RPP
...
@@ -25,6 +25,43 @@ import RPPtools as RPP
#
#
NCFillValue
=
1.0e20
NCFillValue
=
1.0e20
#
#
# Function to compute quantiles with weights
#
def
weighted_quantile
(
values
,
quantiles
,
sample_weight
=
None
,
values_sorted
=
False
,
old_style
=
False
):
""" Very close to numpy.percentile, but supports weights.
NOTE: quantiles should be in [0, 1]!
:param values: numpy.array with data
:param quantiles: array-like with many quantiles needed
:param sample_weight: array-like of the same length as `array`
:param values_sorted: bool, if True, then will avoid sorting of
initial array
:param old_style: if True, will correct output to be consistent
with numpy.percentile.
:return: numpy.array with computed quantiles.
"""
values
=
np
.
array
(
values
)
quantiles
=
np
.
array
(
quantiles
)
if
sample_weight
is
None
:
sample_weight
=
np
.
ones
(
len
(
values
))
sample_weight
=
np
.
array
(
sample_weight
)
assert
np
.
all
(
quantiles
>=
0
)
and
np
.
all
(
quantiles
<=
1
),
\
'quantiles should be in [0, 1]'
if
not
values_sorted
:
sorter
=
np
.
argsort
(
values
)
values
=
values
[
sorter
]
sample_weight
=
sample_weight
[
sorter
]
weighted_quantiles
=
np
.
cumsum
(
sample_weight
)
-
0.5
*
sample_weight
if
old_style
:
# To be convenient with numpy.percentile
weighted_quantiles
-=
weighted_quantiles
[
0
]
weighted_quantiles
/=
weighted_quantiles
[
-
1
]
else
:
weighted_quantiles
/=
np
.
sum
(
sample_weight
)
return
np
.
interp
(
quantiles
,
weighted_quantiles
,
values
)
#
# Add time constants and possibly other prameters to the graph file
# Add time constants and possibly other prameters to the graph file
#
#
def
addparameters
(
outnf
,
version
,
part
,
tcst
,
vtyp
,
NCFillValue
)
:
def
addparameters
(
outnf
,
version
,
part
,
tcst
,
vtyp
,
NCFillValue
)
:
...
@@ -204,7 +241,7 @@ class HydroGraph :
...
@@ -204,7 +241,7 @@ class HydroGraph :
ncvar
.
units
=
"count"
ncvar
.
units
=
"count"
ncvar
[:]
=
thist
[:]
ncvar
[:]
=
thist
[:]
#
#
maxtstep
=
np
.
quantile
(
gvar
[
~
np
.
isnan
(
gvar
)]
,
0.1
)
maxtstep
=
weighted_
quantile
(
gvar
[
~
np
.
isnan
(
gvar
)]
*
tcst
.
stream_tcst
,
0.50
,
sample_weight
=
garea
[
~
np
.
isnan
(
gvar
)]
)
mtstep
=
outnf
.
createVariable
(
"MaxTimeStep"
,
vtyp
,
(
'dimpara'
),
fill_value
=
NCFillValue
)
mtstep
=
outnf
.
createVariable
(
"MaxTimeStep"
,
vtyp
,
(
'dimpara'
),
fill_value
=
NCFillValue
)
mtstep
.
title
=
"The maximum time-step possible given the distribution of HTU properties"
mtstep
.
title
=
"The maximum time-step possible given the distribution of HTU properties"
mtstep
.
units
=
"s"
mtstep
.
units
=
"s"
...
...
HydroGrid.py
View file @
3b41a20e
...
@@ -317,10 +317,10 @@ class HydroParameter :
...
@@ -317,10 +317,10 @@ class HydroParameter :
self
.
swamp_cst
=
0.2
self
.
swamp_cst
=
0.2
elif
hydrogrid
.
hd
>=
0.016
:
elif
hydrogrid
.
hd
>=
0.016
:
# Case for MERIT
# Case for MERIT
self
.
stream_tcst
=
0.0014
/
1000
*
RPP
.
OneDay
self
.
stream_tcst
=
2.6
self
.
fast_tcst
=
0.0
7
/
1000
*
RPP
.
OneDay
self
.
fast_tcst
=
55
0.0
self
.
slow_tcst
=
0.98
/
1000
*
RPP
.
OneDay
self
.
slow_tcst
=
7500.0
self
.
flood_tcst
=
4.0
/
1000
*
RPP
.
OneDay
self
.
flood_tcst
=
345.6
self
.
swamp_cst
=
0.2
self
.
swamp_cst
=
0.2
elif
hydrogrid
.
hd
>=
0.008
:
elif
hydrogrid
.
hd
>=
0.008
:
# Case for HydroSEHDS
# Case for HydroSEHDS
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment