Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
calng
Commits
d1df365e
Commit
d1df365e
authored
3 years ago
by
David Hammer
Browse files
Options
Downloads
Patches
Plain Diff
Allow downsampling like in FemDataAssembler
parent
c606771a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!12
Snapshot: field test deployed version as of end of run 202201
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/calng/SimpleAssembler.py
+55
-1
55 additions, 1 deletion
src/calng/SimpleAssembler.py
with
55 additions
and
1 deletion
src/calng/SimpleAssembler.py
+
55
−
1
View file @
d1df365e
...
...
@@ -3,7 +3,6 @@ import pickle
import
re
import
numpy
as
np
from
calng
import
utils
from
karabo.bound
import
(
FLOAT_ELEMENT
,
IMAGEDATA_ELEMENT
,
...
...
@@ -12,6 +11,7 @@ from karabo.bound import (
OUTPUT_CHANNEL
,
OVERWRITE_ELEMENT
,
STRING_ELEMENT
,
UINT32_ELEMENT
,
UINT64_ELEMENT
,
ChannelMetaData
,
Dims
,
...
...
@@ -42,6 +42,7 @@ preview_schema = Schema()
xtdf_source_re
=
re
.
compile
(
r
"
.*\/DET\/(\d+)CH0:xtdf
"
)
daq_source_re
=
re
.
compile
(
r
"
.*\/DET\/.*?(\d+):daqOutput
"
)
# TODO: merge scene with TrainMatcher's nice overview
@KARABO_CLASSINFO
(
"
SimpleAssembler
"
,
deviceVersion
)
class
SimpleAssembler
(
TrainMatcher
.
TrainMatcher
):
...
...
@@ -81,6 +82,28 @@ class SimpleAssembler(TrainMatcher.TrainMatcher):
.
defaultValue
(
"
image.data
"
)
.
commit
(),
UINT32_ELEMENT
(
expected
)
.
key
(
"
downsamplingFactor
"
)
.
description
(
"
If greater than 1, the assembled image will be downsampled by this
"
"
factor in x and y dimensions before sending. This is only to save
"
"
bandwidth in case GUI updates start lagging.
"
)
.
assignmentOptional
()
.
defaultValue
(
1
)
.
options
(
"
1,2,4,8
"
)
.
reconfigurable
()
.
commit
(),
STRING_ELEMENT
(
expected
)
.
key
(
"
downsamplingFunction
"
)
.
description
(
"
Reduction function used during downsampling.
"
)
.
assignmentOptional
()
.
defaultValue
(
"
nanmax
"
)
.
options
(
"
nanmax,nanmean,nanmin,nanmedian
"
)
.
reconfigurable
()
.
commit
(),
INPUT_CHANNEL
(
expected
)
.
key
(
"
geometryInput
"
)
.
displayedName
(
"
Geometry input
"
)
...
...
@@ -157,6 +180,14 @@ class SimpleAssembler(TrainMatcher.TrainMatcher):
# TODO: reusable output buffer to save on allocation
assembled
,
_
=
self
.
geometry
.
position_modules_fast
(
self
.
input_buffer
)
downsampling_factor
=
self
.
get
(
"
downsamplingFactor
"
)
if
downsampling_factor
>
1
:
assembled
=
downsample_2d
(
assembled
,
downsampling_factor
,
reduction_fun
=
getattr
(
np
,
self
.
get
(
"
downsamplingFunction
"
))
)
# TODO: optionally include control data
out_hash
=
Hash
(
"
image
"
,
...
...
@@ -197,3 +228,26 @@ class SimpleAssembler(TrainMatcher.TrainMatcher):
self
.
log
.
WARN
(
f
"
Couldn
'
t figure out index for source
{
source
}
"
)
return
0
def
downsample_2d
(
arr
,
factor
,
reduction_fun
=
np
.
nanmax
):
"""
Generalization of downsampling from FemDataAssembler
Expects first two dimensions of arr to be multiple of 2 ** factor
Useful if you
'
re sitting at home and ssh connection is slow to get full-resolution
previews.
"""
for
i
in
range
(
factor
//
2
):
arr
=
reduction_fun
(
(
arr
[:
-
1
:
2
],
arr
[
1
::
2
],
),
axis
=
0
)
arr
=
reduction_fun
(
(
arr
[:,
:
-
1
:
2
],
arr
[:,
1
::
2
],
),
axis
=
0
)
return
arr
This diff is collapsed.
Click to expand it.
David Hammer
@hammerd
mentioned in commit
3566342d
·
2 years ago
mentioned in commit
3566342d
mentioned in commit 3566342d031db1bb435b6430f100afdbaaa6c4bf
Toggle commit list
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