Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam
Manage
Activity
Members
Labels
Plan
Issues
32
Issue boards
Milestones
Code
Merge requests
3
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
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
FINAM
finam
Commits
03586180
Commit
03586180
authored
2 years ago
by
Martin Lange
Browse files
Options
Downloads
Patches
Plain Diff
simply re-assign equivalen units, add benchmarks
parent
dee40d9b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!237
Optimize units etc.
Pipeline
#134892
passed with stages
in 5 minutes and 11 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
benchmarks/sdk/test_io.py
+51
-14
51 additions, 14 deletions
benchmarks/sdk/test_io.py
src/finam/data/tools.py
+7
-2
7 additions, 2 deletions
src/finam/data/tools.py
src/finam/sdk/input.py
+1
-1
1 addition, 1 deletion
src/finam/sdk/input.py
with
59 additions
and
17 deletions
benchmarks/sdk/test_io.py
+
51
−
14
View file @
03586180
...
...
@@ -17,13 +17,14 @@ class TestPushPull(unittest.TestCase):
data
=
self
.
data
[
self
.
counter
%
2
]
self
.
out
.
push_data
(
data
,
self
.
time
)
_
=
self
.
inp
.
pull_data
(
self
.
time
)
data
=
self
.
inp
.
pull_data
(
self
.
time
)
self
.
time
+=
dt
.
timedelta
(
days
=
1
)
self
.
counter
+=
1
return
data
def
setup_link
(
self
,
grid
,
target_units
):
self
.
time
=
dt
.
datetime
(
2000
,
1
,
1
)
info1
=
fm
.
Info
(
time
=
self
.
time
,
grid
=
grid
,
units
=
"
m
"
)
info1
=
fm
.
Info
(
time
=
self
.
time
,
grid
=
grid
,
units
=
"
m
m
"
)
info2
=
fm
.
Info
(
time
=
self
.
time
,
grid
=
grid
,
units
=
target_units
)
self
.
data
=
[
...
...
@@ -42,47 +43,83 @@ class TestPushPull(unittest.TestCase):
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_01_2x1
(
self
):
grid
=
fm
.
UniformGrid
((
2
,
1
))
self
.
setup_link
(
grid
,
target_units
=
"
m
"
)
self
.
benchmark
(
self
.
push_pull
)
self
.
setup_link
(
grid
,
target_units
=
"
mm
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
millimeter
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_02_512x256
(
self
):
grid
=
fm
.
UniformGrid
((
512
,
256
))
self
.
setup_link
(
grid
,
target_units
=
"
m
"
)
self
.
benchmark
(
self
.
push_pull
)
self
.
setup_link
(
grid
,
target_units
=
"
mm
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
millimeter
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_03_1024x512
(
self
):
grid
=
fm
.
UniformGrid
((
1024
,
512
))
self
.
setup_link
(
grid
,
target_units
=
"
m
"
)
self
.
benchmark
(
self
.
push_pull
)
self
.
setup_link
(
grid
,
target_units
=
"
mm
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
millimeter
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_04_2048x1024
(
self
):
grid
=
fm
.
UniformGrid
((
2048
,
1024
))
self
.
setup_link
(
grid
,
target_units
=
"
m
"
)
self
.
benchmark
(
self
.
push_pull
)
self
.
setup_link
(
grid
,
target_units
=
"
mm
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
millimeter
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_units_01_2x1
(
self
):
grid
=
fm
.
UniformGrid
((
2
,
1
))
self
.
setup_link
(
grid
,
target_units
=
"
km
"
)
self
.
benchmark
(
self
.
push_pull
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
kilometer
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_units_02_512x256
(
self
):
grid
=
fm
.
UniformGrid
((
512
,
256
))
self
.
setup_link
(
grid
,
target_units
=
"
km
"
)
self
.
benchmark
(
self
.
push_pull
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
kilometer
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_units_03_1024x512
(
self
):
grid
=
fm
.
UniformGrid
((
1024
,
512
))
self
.
setup_link
(
grid
,
target_units
=
"
km
"
)
self
.
benchmark
(
self
.
push_pull
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
kilometer
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_units_04_2048x1024
(
self
):
grid
=
fm
.
UniformGrid
((
2048
,
1024
))
self
.
setup_link
(
grid
,
target_units
=
"
km
"
)
self
.
benchmark
(
self
.
push_pull
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
kilometer
,
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_equiv_01_2x1
(
self
):
grid
=
fm
.
UniformGrid
((
2
,
1
))
self
.
setup_link
(
grid
,
target_units
=
"
L/m^2
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
Unit
(
"
L/m^2
"
),
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_equiv_02_512x256
(
self
):
grid
=
fm
.
UniformGrid
((
512
,
256
))
self
.
setup_link
(
grid
,
target_units
=
"
L/m^2
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
Unit
(
"
L/m^2
"
),
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_equiv_03_1024x512
(
self
):
grid
=
fm
.
UniformGrid
((
1024
,
512
))
self
.
setup_link
(
grid
,
target_units
=
"
L/m^2
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
Unit
(
"
L/m^2
"
),
data
.
units
)
@pytest.mark.benchmark
(
group
=
"
sdk-io
"
)
def
test_push_pull_np_equiv_04_2048x1024
(
self
):
grid
=
fm
.
UniformGrid
((
2048
,
1024
))
self
.
setup_link
(
grid
,
target_units
=
"
L/m^2
"
)
data
=
self
.
benchmark
(
self
.
push_pull
)
self
.
assertEqual
(
fm
.
UNITS
.
Unit
(
"
L/m^2
"
),
data
.
units
)
This diff is collapsed.
Click to expand it.
src/finam/data/tools.py
+
7
−
2
View file @
03586180
...
...
@@ -272,7 +272,7 @@ def get_dimensionality(xdata):
return
xdata
.
dimensionality
def
to_units
(
xdata
,
units
):
def
to_units
(
xdata
,
units
,
check_equivalent
=
False
):
"""
Convert data to given units.
...
...
@@ -282,6 +282,8 @@ def to_units(xdata, units):
The given data array.
units : str or pint.Unit
Desired units.
check_equivalent : bool, optional
Checks for equivalent units and simply re-assigns if possible.
Returns
-------
...
...
@@ -290,8 +292,11 @@ def to_units(xdata, units):
"""
check_quantified
(
xdata
,
"
to_units
"
)
units
=
_get_pint_units
(
units
)
if
units
==
xdata
.
units
:
units2
=
xdata
.
units
if
units
==
units2
:
return
xdata
if
check_equivalent
and
equivalent_units
(
units
,
units2
):
return
UNITS
.
Quantity
(
xdata
.
magnitude
,
units
)
return
xdata
.
to
(
units
)
...
...
This diff is collapsed.
Click to expand it.
src/finam/sdk/input.py
+
1
−
1
View file @
03586180
...
...
@@ -122,7 +122,7 @@ class Input(IInput, Loggable):
data
=
self
.
source
.
get_data
(
time
,
target
or
self
)
with
ErrorLogger
(
self
.
logger
):
data
=
tools
.
to_units
(
data
,
self
.
_input_info
.
units
)
data
=
tools
.
to_units
(
data
,
self
.
_input_info
.
units
,
check_equivalent
=
True
)
tools
.
check
(
data
,
self
.
_input_info
)
return
data
...
...
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