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
273c5dd0
Commit
273c5dd0
authored
2 years ago
by
Martin Lange
Browse files
Options
Downloads
Patches
Plain Diff
simplify adapter, write tests
parent
17e235fb
Branches
lai-adapter
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/finam_mhm_module/lai_adapter.py
+1
-6
1 addition, 6 deletions
src/finam_mhm_module/lai_adapter.py
tests/test_lai_adapter.py
+37
-1
37 additions, 1 deletion
tests/test_lai_adapter.py
with
38 additions
and
7 deletions
src/finam_mhm_module/lai_adapter.py
+
1
−
6
View file @
273c5dd0
...
@@ -9,7 +9,6 @@ class YearlyToMonthly(AAdapter):
...
@@ -9,7 +9,6 @@ class YearlyToMonthly(AAdapter):
def
__init__
(
self
,
lai_curve
):
def
__init__
(
self
,
lai_curve
):
super
().
__init__
()
super
().
__init__
()
self
.
data
=
None
self
.
data
=
None
self
.
month
=
0
if
len
(
lai_curve
)
!=
12
:
if
len
(
lai_curve
)
!=
12
:
raise
ValueError
(
"
LAI curve must be an array of 12 values
"
)
raise
ValueError
(
"
LAI curve must be an array of 12 values
"
)
self
.
lai_curve
=
lai_curve
self
.
lai_curve
=
lai_curve
...
@@ -19,7 +18,6 @@ class YearlyToMonthly(AAdapter):
...
@@ -19,7 +18,6 @@ class YearlyToMonthly(AAdapter):
raise
ValueError
(
"
Time must be of type datetime
"
)
raise
ValueError
(
"
Time must be of type datetime
"
)
self
.
data
=
self
.
pull_data
(
time
)
self
.
data
=
self
.
pull_data
(
time
)
self
.
month
=
time
.
month
self
.
notify_targets
(
time
)
self
.
notify_targets
(
time
)
...
@@ -27,9 +25,6 @@ class YearlyToMonthly(AAdapter):
...
@@ -27,9 +25,6 @@ class YearlyToMonthly(AAdapter):
if
not
isinstance
(
time
,
datetime
):
if
not
isinstance
(
time
,
datetime
):
raise
ValueError
(
"
Time must be of type datetime
"
)
raise
ValueError
(
"
Time must be of type datetime
"
)
new_month
=
time
.
month
lai
=
[
self
.
data
*
self
.
lai_curve
[
m
]
for
m
in
range
(
0
,
len
(
self
.
lai_curve
))]
lai
=
[]
for
m
in
range
(
self
.
month
-
1
,
new_month
):
lai
.
append
(
self
.
data
*
self
.
lai_curve
[
m
])
return
lai
return
lai
This diff is collapsed.
Click to expand it.
tests/test_lai_adapter.py
+
37
−
1
View file @
273c5dd0
import
unittest
import
unittest
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
finam.modules.generators
import
CallbackGenerator
from
finam.data.grid
import
Grid
,
GridSpec
from
finam_mhm_module
import
YearlyToMonthly
from
finam_mhm_module
import
YearlyToMonthly
class
TestLaiAdapter
(
unittest
.
TestCase
):
class
TestLaiAdapter
(
unittest
.
TestCase
):
def
test_adapter
(
self
):
def
test_adapter
(
self
):
pass
grid
=
Grid
(
GridSpec
(
3
,
2
))
grid
.
fill
(
1.0
)
for
c
in
range
(
3
):
grid
.
set
(
c
,
0
,
2.0
)
source
=
CallbackGenerator
(
callbacks
=
{
"
LAI
"
:
lambda
t
:
grid
},
start
=
datetime
(
2000
,
1
,
1
),
step
=
timedelta
(
365.0
),
)
lai_curve
=
[
0.0
,
0.0
,
0.2
,
0.5
,
0.8
,
1.0
,
1.0
,
1.0
,
0.8
,
0.5
,
0.2
,
0.0
]
adapter
=
YearlyToMonthly
(
lai_curve
)
source
.
initialize
()
source
.
outputs
[
"
LAI
"
]
>>
adapter
source
.
connect
()
source
.
validate
()
lai_months
=
adapter
.
get_data
(
datetime
(
2000
,
1
,
1
,
0
))
self
.
assertEqual
(
len
(
lai_months
),
12
)
for
m
in
range
(
len
(
lai_months
)):
self
.
assertTrue
(
isinstance
(
lai_months
[
m
],
Grid
))
self
.
assertEqual
(
lai_months
[
m
],
grid
*
lai_curve
[
m
])
grid
.
fill
(
2.0
)
source
.
update
()
lai_months_2
=
adapter
.
get_data
(
datetime
(
2001
,
1
,
1
,
0
))
self
.
assertEqual
(
len
(
lai_months_2
),
12
)
for
m
in
range
(
len
(
lai_months_2
)):
self
.
assertTrue
(
isinstance
(
lai_months_2
[
m
],
Grid
))
self
.
assertEqual
(
lai_months_2
[
m
],
grid
*
lai_curve
[
m
])
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