Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam-mhm
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Afid Nur Kholis
finam-mhm
Commits
259e2133
Commit
259e2133
authored
3 years ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
Add first draft of mhm module
parent
eb5468c3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/simple_viewer.py
+33
-1
33 additions, 1 deletion
examples/simple_viewer.py
src/finam_mhm_module/__init__.py
+1
-0
1 addition, 0 deletions
src/finam_mhm_module/__init__.py
src/finam_mhm_module/mhm.py
+91
-1
91 additions, 1 deletion
src/finam_mhm_module/mhm.py
with
125 additions
and
2 deletions
examples/simple_viewer.py
+
33
−
1
View file @
259e2133
"""
Simple live viewer for a mHM run.
"""
"""
Simple coupling setup using live view modules.
"""
from
datetime
import
timedelta
,
datetime
import
numpy
as
np
from
finam.adapters
import
time
,
base
from
finam.core.schedule
import
Composition
from
finam.modules.visual
import
time_series
from
finam_mhm_module
import
Mhm
def
grid_select
(
grid
):
return
grid
.
get
(
col
=
3
,
row
=
5
)
plot
=
time_series
.
TimeSeriesView
(
start
=
datetime
(
1990
,
1
,
1
),
step
=
timedelta
(
days
=
1
),
inputs
=
[
"
Linear (1)
"
],
intervals
=
[
1
],
)
mhm
=
Mhm
(
cwd
=
"
../../MHM/mhm
"
)
composition
=
Composition
([
mhm
,
plot
])
composition
.
initialize
()
grid_value
=
mhm
.
outputs
[
"
runoff
"
]
>>
base
.
GridToValue
(
func
=
grid_select
)
grid_value
>>
time
.
LinearInterpolation
()
>>
plot
.
inputs
[
"
Linear (1)
"
]
composition
.
run
(
datetime
(
1991
,
1
,
1
))
This diff is collapsed.
Click to expand it.
src/finam_mhm_module/__init__.py
+
1
−
0
View file @
259e2133
from
.mhm
import
Mhm
This diff is collapsed.
Click to expand it.
src/finam_mhm_module/mhm.py
+
91
−
1
View file @
259e2133
"""
F
inam
mHM module.
F
INAM
mHM module.
"""
from
datetime
import
datetime
import
mhm_pybind
as
mp
from
finam.core.sdk
import
ATimeComponent
,
Output
from
finam.core.interfaces
import
ComponentStatus
from
finam.data.grid
import
Grid
,
GridSpec
class
Mhm
(
ATimeComponent
):
def
__init__
(
self
,
namelist_mhm
=
"
mhm.nml
"
,
namelist_mhm_param
=
"
mhm_parameter.nml
"
,
namelist_mhm_output
=
"
mhm_outputs.nml
"
,
namelist_mrm_output
=
"
mrm_outputs.nml
"
,
cwd
=
"
.
"
,
):
super
(
Mhm
,
self
).
__init__
()
mp
.
mhm
.
init
(
namelist_mhm
=
namelist_mhm
,
namelist_mhm_param
=
namelist_mhm_param
,
namelist_mhm_output
=
namelist_mhm_output
,
namelist_mrm_output
=
namelist_mrm_output
,
cwd
=
cwd
,
)
self
.
_status
=
ComponentStatus
.
CREATED
def
initialize
(
self
):
super
().
initialize
()
mp
.
run
.
prepare
()
mp
.
run
.
prepare_domain
()
# set time
year
,
month
,
day
,
hour
=
mp
.
run
.
current_time
()
self
.
_time
=
datetime
(
year
=
year
,
month
=
month
,
day
=
day
,
hour
=
hour
)
# get grid info
ncols
,
nrows
,
ncells
,
xll
,
yll
,
cell_size
,
no_data
=
mp
.
get
.
L1_domain_info
()
self
.
no_data
=
no_data
self
.
gridspec
=
GridSpec
(
ncols
=
ncols
,
nrows
=
nrows
,
cell_size
=
cell_size
,
xll
=
xll
,
yll
=
yll
)
self
.
outputs
[
"
runoff
"
]
=
Output
()
self
.
_status
=
ComponentStatus
.
INITIALIZED
def
connect
(
self
):
super
().
connect
()
runoff
=
mp
.
get_variable
(
"
L1_total_runoff
"
)
self
.
_outputs
[
"
runoff
"
].
push_data
(
data
=
Grid
(
spec
=
self
.
gridspec
,
no_data
=
self
.
no_data
,
data
=
runoff
.
filled
().
reshape
(
-
1
),
),
time
=
self
.
time
,
)
self
.
_status
=
ComponentStatus
.
CONNECTED
def
validate
(
self
):
super
().
validate
()
self
.
_status
=
ComponentStatus
.
VALIDATED
def
update
(
self
):
super
().
update
()
# Don't run further than mHM can
if
mp
.
run
.
finished
():
return
mp
.
run
.
do_time_step
()
mp
.
run
.
write_output
()
# do we want this here?
# update time
year
,
month
,
day
,
hour
=
mp
.
run
.
current_time
()
self
.
_time
=
datetime
(
year
=
year
,
month
=
month
,
day
=
day
,
hour
=
hour
)
# push outputs
runoff
=
mp
.
get_variable
(
"
L1_total_runoff
"
)
self
.
_outputs
[
"
runoff
"
].
push_data
(
data
=
Grid
(
spec
=
self
.
gridspec
,
no_data
=
self
.
no_data
,
data
=
runoff
.
filled
().
reshape
(
-
1
),
),
time
=
self
.
time
,
)
self
.
_status
=
ComponentStatus
.
UPDATED
def
finalize
(
self
):
super
().
finalize
()
mp
.
run
.
finalize_domain
()
mp
.
run
.
finalize
()
mp
.
mhm
.
finalize
()
self
.
_status
=
ComponentStatus
.
FINALIZED
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment