Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
sns-hfir-scse
sans
sans-backend
Commits
9530b015
Commit
9530b015
authored
Apr 30, 2019
by
Leal, Ricardo
Browse files
Detector info I think it's final
parent
c2db0604
Pipeline
#57425
passed with stages
in 8 minutes and 10 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ornl/detectors.py
View file @
9530b015
from
__future__
import
absolute_import
,
division
,
print_function
from
collections
import
OrderedDict
class
InstrumentDetectors
(
object
):
'''
...
...
@@ -7,29 +9,41 @@ class InstrumentDetectors(object):
'''
def
__init__
(
self
,
workspace
,
component_names
):
"""[summary]
"""
Parameters
----------
workspace :
[type]
[description]
workspace :
MatrixWorkspace
Workspace to get the detector info from
component_names : list
list with component names relative to detectors
"""
self
.
instrument
=
workspace
.
getInstrument
()
self
.
detectors
=
dict
()
self
.
_instrument
=
workspace
.
getInstrument
()
self
.
_detectors
=
OrderedDict
()
self
.
_set_detectors_details
(
component_names
)
def
_set_detectors_details
(
self
,
component_names
):
for
component_name
in
component_names
:
n_tubes
,
n_pixels
=
self
.
_get_detector_details
(
component_name
)
self
.
detectors
[
component_name
]
=
dict
(
x
=
n_tubes
,
y
=
n_pixels
)
self
.
_
detectors
[
component_name
]
=
dict
(
x
=
n_tubes
,
y
=
n_pixels
)
def
_get_detector_details
(
self
,
component_name
):
"""For every component name sets its dimensions
Parameters
----------
component_name : string
the component name of the detector. e.g. detector1, wing_detector
component
=
self
.
instrument
.
getComponentByName
(
component_name
)
Returns
-------
tuple
tuple of ints (x,y) of detector dimensions
"""
component
=
self
.
_instrument
.
getComponentByName
(
component_name
)
n_tubes
=
component
.
nelements
()
if
component
[
0
].
nelements
()
==
1
:
...
...
@@ -39,3 +53,31 @@ class InstrumentDetectors(object):
# Handles BioSANS/GPSANS
n_pixels_per_tube
=
component
[
0
].
nelements
()
return
n_tubes
,
n_pixels_per_tube
def
get_detectors_dimension
(
self
):
"""
Returns
-------
List
Returns a list of tuples: component name : detector dimensions
[('detector1', {'x': 192, 'y': 256}),
('wing_detector', {'x': 160, 'y': 256})]
"""
return
list
(
self
.
_detectors
.
items
())
def
get_component_dimension
(
self
,
component_name
):
"""Given a component name returns its dimensions
Parameters
----------
component_name : string
valid component name. E.g. detector1, wing_detector
Returns
-------
tuple
tuple of ints (x,y) of detector dimensions
"""
return
(
self
.
_detectors
[
component_name
][
'x'
],
self
.
_detectors
[
component_name
][
'y'
])
tests/unit/new/ornl/sans/hfir/biosans/test_detectors.py
View file @
9530b015
...
...
@@ -20,8 +20,9 @@ def test_detectors(biosans_f):
d
=
InstrumentDetectors
(
ws
,
[
'detector1'
,
'wing_detector'
])
assert
d
.
detectors
[
'detector1'
][
'x'
]
==
192
assert
d
.
detectors
[
'detector1'
][
'y'
]
==
256
assert
d
.
get_detectors_dimension
()
==
[
(
'detector1'
,
{
'x'
:
192
,
'y'
:
256
}),
(
'wing_detector'
,
{
'x'
:
160
,
'y'
:
256
})]
assert
d
.
d
et
ectors
[
'wing_detector'
][
'x'
]
==
160
assert
d
.
d
et
ectors
[
'wing_detector'
][
'y'
]
==
256
assert
d
.
g
et
_component_dimension
(
'detector1'
)
==
(
192
,
256
)
assert
d
.
g
et
_component_dimension
(
'wing_detector'
)
==
(
160
,
256
)
tests/unit/new/ornl/sans/hfir/gpsans/test_detectors.py
View file @
9530b015
...
...
@@ -19,5 +19,8 @@ def test_detectors(gpsans_f):
OutputWorkspace
=
unique_workspace_name
())
d
=
InstrumentDetectors
(
ws
,
[
'detector1'
])
assert
d
.
detectors
[
'detector1'
][
'x'
]
==
192
assert
d
.
detectors
[
'detector1'
][
'y'
]
==
256
assert
d
.
get_detectors_dimension
()
==
[
(
'detector1'
,
{
'x'
:
192
,
'y'
:
256
}),
]
assert
d
.
get_component_dimension
(
'detector1'
)
==
(
192
,
256
)
tests/unit/new/ornl/sans/sns/eqsans/test_detectors.py
View file @
9530b015
...
...
@@ -18,5 +18,8 @@ def test_detectors(gpsans_f):
OutputWorkspace
=
unique_workspace_name
())
d
=
InstrumentDetectors
(
ws
,
[
'detector1'
])
assert
d
.
detectors
[
'detector1'
][
'x'
]
==
192
assert
d
.
detectors
[
'detector1'
][
'y'
]
==
256
assert
d
.
get_detectors_dimension
()
==
[
(
'detector1'
,
{
'x'
:
192
,
'y'
:
256
}),
]
assert
d
.
get_component_dimension
(
'detector1'
)
==
(
192
,
256
)
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment