Commit 9530b015 authored by Leal, Ricardo's avatar Leal, Ricardo
Browse files

Detector info I think it's final

parent c2db0604
Pipeline #57425 passed with stages
in 8 minutes and 10 seconds
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'])
......@@ -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.detectors['wing_detector']['x'] == 160
assert d.detectors['wing_detector']['y'] == 256
assert d.get_component_dimension('detector1') == (192, 256)
assert d.get_component_dimension('wing_detector') == (160, 256)
......@@ -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)
......@@ -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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment