Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
bliss
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
492
Issues
492
List
Boards
Labels
Service Desk
Milestones
Jira
Jira
Merge Requests
134
Merge Requests
134
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bliss
bliss
Commits
7df9f31a
Commit
7df9f31a
authored
Feb 05, 2020
by
Valentin Valls
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a min state item
parent
4195a1c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
0 deletions
+91
-0
bliss/flint/model/plot_state_model.py
bliss/flint/model/plot_state_model.py
+74
-0
tests/flint/model/test_plot_state_model.py
tests/flint/model/test_plot_state_model.py
+17
-0
No files found.
bliss/flint/model/plot_state_model.py
View file @
7df9f31a
...
...
@@ -314,3 +314,77 @@ class MaxCurveItem(plot_model.AbstractIncrementalComputableItem, CurveStatisticM
max_index
,
max_location_y
,
max_location_x
,
min_y_value
,
nb
+
len
(
xx
)
)
return
result
class
MinData
(
NamedTuple
):
min_index
:
int
min_location_y
:
float
min_location_x
:
float
max_y_value
:
float
nb_points
:
int
class
MinCurveItem
(
plot_model
.
AbstractIncrementalComputableItem
,
CurveStatisticMixIn
):
"""Statistic identifying the minimum location of a curve."""
def
isResultValid
(
self
,
result
):
return
result
is
not
None
def
compute
(
self
,
scan
:
scan_model
.
Scan
)
->
Optional
[
MinData
]:
sourceItem
=
self
.
source
()
xx
=
sourceItem
.
xArray
(
scan
)
yy
=
sourceItem
.
yArray
(
scan
)
if
xx
is
None
or
yy
is
None
:
return
None
min_index
=
numpy
.
argmin
(
yy
)
max_y_value
=
numpy
.
max
(
yy
)
min_location_x
,
min_location_y
=
xx
[
min_index
],
yy
[
min_index
]
result
=
MinData
(
min_index
,
min_location_y
,
min_location_x
,
max_y_value
,
len
(
xx
)
)
return
result
def
incrementalCompute
(
self
,
previousResult
:
MinData
,
scan
:
scan_model
.
Scan
)
->
MinData
:
sourceItem
=
self
.
source
()
xx
=
sourceItem
.
xArray
(
scan
)
yy
=
sourceItem
.
yArray
(
scan
)
if
xx
is
None
or
yy
is
None
:
raise
ValueError
(
"Non empty data is expected"
)
nb
=
previousResult
.
nb_points
if
nb
==
len
(
xx
):
# obviously nothing to compute
return
previousResult
xx
=
xx
[
nb
:]
yy
=
yy
[
nb
:]
min_index
=
numpy
.
argmin
(
yy
)
max_y_value
=
numpy
.
max
(
yy
)
min_location_x
,
min_location_y
=
xx
[
min_index
],
yy
[
min_index
]
min_index
=
min_index
+
nb
if
previousResult
.
max_y_value
<
max_y_value
:
max_y_value
=
previousResult
.
max_y_value
if
previousResult
.
min_location_y
<
min_location_y
:
# Update and return the previous result
return
MinData
(
previousResult
.
min_index
,
previousResult
.
min_location_y
,
previousResult
.
min_location_x
,
max_y_value
,
nb
+
len
(
xx
),
)
# Update and new return the previous result
result
=
MinData
(
min_index
,
min_location_y
,
min_location_x
,
max_y_value
,
nb
+
len
(
xx
)
)
return
result
tests/flint/model/test_plot_state_model.py
View file @
7df9f31a
...
...
@@ -41,6 +41,23 @@ def test_max_compute():
assert
result
.
min_y_value
==
-
10
def
test_min_compute
():
scan
=
None
yy
=
[
0
,
-
10
,
2
,
5
,
9
,
500
,
100
]
xx
=
numpy
.
arange
(
len
(
yy
))
*
10
item
=
plot_state_model
.
MinCurveItem
()
curveItem
=
CurveMock
(
xx
=
xx
,
yy
=
yy
)
item
.
setSource
(
curveItem
)
result
=
item
.
compute
(
scan
)
assert
result
.
nb_points
==
len
(
xx
)
assert
result
.
min_index
==
1
assert
result
.
min_location_x
==
10
assert
result
.
min_location_y
==
-
10
assert
result
.
max_y_value
==
500
def
test_max_incremental_compute_1
():
"""The result is part of the increment"""
scan
=
None
...
...
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