本文整理汇总了Python中sans.common.enums.DetectorType.to_string方法的典型用法代码示例。如果您正苦于以下问题:Python DetectorType.to_string方法的具体用法?Python DetectorType.to_string怎么用?Python DetectorType.to_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sans.common.enums.DetectorType
的用法示例。
在下文中一共展示了DetectorType.to_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PyInit
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def PyInit(self):
# State
self.declareProperty(PropertyManagerProperty('SANSState'),
doc='A property manager which fulfills the SANSState contract.')
# Input workspaces
workspace_validator = CompositeValidator()
workspace_validator.add(WorkspaceUnitValidator("Wavelength"))
self.declareProperty(MatrixWorkspaceProperty("TransmissionWorkspace", '',
optional=PropertyMode.Optional, direction=Direction.Input,
validator=workspace_validator),
doc='The calculated transmission workspace in wavelength units.')
self.declareProperty(MatrixWorkspaceProperty("NormalizeToMonitorWorkspace", '',
optional=PropertyMode.Mandatory, direction=Direction.Input,
validator=workspace_validator),
doc='The monitor normalization workspace in wavelength units.')
allowed_detector_types = StringListValidator([DetectorType.to_string(DetectorType.HAB),
DetectorType.to_string(DetectorType.LAB)])
self.declareProperty("Component", DetectorType.to_string(DetectorType.LAB),
validator=allowed_detector_types, direction=Direction.Input,
doc="The component of the instrument which is currently being investigated.")
# Output workspace
self.declareProperty(MatrixWorkspaceProperty("OutputWorkspaceWavelengthAdjustment", '',
direction=Direction.Output),
doc='A wavelength adjustment output workspace.')
self.declareProperty(MatrixWorkspaceProperty("OutputWorkspacePixelAdjustment", '',
direction=Direction.Output),
doc='A pixel adjustment output workspace.')
示例2: test_that_missing_beam_centre_is_taken_from_move_state
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def test_that_missing_beam_centre_is_taken_from_move_state(self):
# Arrange
file_name = "SANS2D00028784"
lab_z_translation_correction = 123.
workspace = load_workspace(file_name)
state = SANSMoveTest._get_simple_state(sample_scatter=file_name,
lab_z_translation_correction=lab_z_translation_correction)
# These values should be used instead of an explicitly specified beam centre
state.move.detectors[DetectorType.to_string(DetectorType.HAB)].sample_centre_pos1 = 26.
state.move.detectors[DetectorType.to_string(DetectorType.HAB)].sample_centre_pos2 = 98.
# Act
# The component input is not relevant for SANS2D's initial move. All detectors are moved
component = "front-detector"
self._run_move(state, workspace=workspace, move_type="InitialMove", component=component)
# Assert for initial move for high angle bank
# These values are on the workspace and in the sample logs
component_to_investigate = DetectorType.to_string(DetectorType.HAB)
initial_x_position = 1.1
x_correction = -0.187987540973
initial_z_position = 23.281
z_correction = 1.00575649188
total_x = initial_x_position + x_correction
total_y = 0.
total_z = initial_z_position + z_correction
expected_position = V3D(total_x - 26., total_y - 98., total_z)
expected_rotation = Quat(0.9968998362876025, 0., 0.07868110579898738, 0.)
self.compare_expected_position(expected_position, expected_rotation,
component_to_investigate, state.move, workspace)
示例3: run_integral
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def run_integral(integral_ranges, mask, integral, detector, state):
ranges = parse_range(integral_ranges)
input_workspaces = load_workspace(state)
is_multi_range = len (ranges) > 1
output_workspaces = []
for input_workspace in input_workspaces:
input_workspace_name = input_workspace.name()
if is_multi_range:
AnalysisDataService.remove(input_workspace_name + '_ranges')
input_workspace = crop_workspace(DetectorType.to_string(detector), input_workspace)
if mask:
input_workspace = apply_mask(state, input_workspace, DetectorType.to_string(detector))
x_dim, y_dim = get_detector_size_from_sans_file(state, detector)
output_workspace = integrate_ranges(ranges, integral, mask, detector, input_workspace_name, input_workspace, x_dim, y_dim,
is_multi_range)
plot_graph(output_workspace)
output_workspaces.append(output_workspace)
return output_workspaces
示例4: test_that_wavelength_and_pixel_adjustment_state_can_be_built
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def test_that_wavelength_and_pixel_adjustment_state_can_be_built(self):
# Arrange
facility = SANSFacility.ISIS
file_information = SANSFileInformationMock(instrument=SANSInstrument.LOQ, run_number=74044)
data_builder = get_data_builder(facility, file_information)
data_builder.set_sample_scatter("LOQ74044")
data_info = data_builder.build()
# Act
builder = get_wavelength_and_pixel_adjustment_builder(data_info)
self.assertTrue(builder)
builder.set_HAB_pixel_adjustment_file("test")
builder.set_HAB_wavelength_adjustment_file("test2")
builder.set_wavelength_low([1.5])
builder.set_wavelength_high([2.7])
builder.set_wavelength_step(0.5)
builder.set_wavelength_step_type(RangeStepType.Lin)
state = builder.build()
# Assert
self.assertTrue(state.adjustment_files[DetectorType.to_string(
DetectorType.HAB)].pixel_adjustment_file == "test")
self.assertTrue(state.adjustment_files[DetectorType.to_string(
DetectorType.HAB)].wavelength_adjustment_file == "test2")
self.assertTrue(state.wavelength_low == [1.5])
self.assertTrue(state.wavelength_high == [2.7])
self.assertTrue(state.wavelength_step == 0.5)
self.assertTrue(state.wavelength_step_type is RangeStepType.Lin)
示例5: test_that_missing_beam_centre_is_taken_from_lab_move_state_when_no_component_is_specified
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def test_that_missing_beam_centre_is_taken_from_lab_move_state_when_no_component_is_specified(self):
# Arrange
file_name = "SANS2D00028784"
lab_z_translation_correction = 123.
workspace = load_workspace(file_name)
state = SANSMoveTest._get_simple_state(sample_scatter=file_name,
lab_z_translation_correction=lab_z_translation_correction)
# These values should be used instead of an explicitly specified beam centre
state.move.detectors[DetectorType.to_string(DetectorType.LAB)].sample_centre_pos1 = 26.
state.move.detectors[DetectorType.to_string(DetectorType.LAB)].sample_centre_pos2 = 98.
# Act
# The component input is not relevant for SANS2D's initial move. All detectors are moved
component = None
self._run_move(state, workspace=workspace, move_type="InitialMove", component=component)
# Assert for initial move for low angle bank
# These values are on the workspace and in the sample logs,
component_to_investigate = DetectorType.to_string(DetectorType.LAB)
initial_z_position = 23.281
rear_det_z = 11.9989755859
offset = 4.
total_x = 0.
total_y = 0.
total_z = initial_z_position + rear_det_z - offset + lab_z_translation_correction
expected_position = V3D(total_x - 26., total_y - 98., total_z)
expected_rotation = Quat(1., 0., 0., 0.)
self.compare_expected_position(expected_position, expected_rotation,
component_to_investigate, state.move, workspace)
示例6: set_components_to_original_for_isis
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def set_components_to_original_for_isis(move_info, workspace, component):
"""
This function resets the components for ISIS instruments. These are normally HAB, LAB, the monitors and
the sample holder
:param move_info: a StateMove object.
:param workspace: the workspace which is being reset.
:param component: the component which is being reset on the workspace. If this is not specified, then
everything is being reset.
"""
def _reset_detector(_key, _move_info, _component_names):
if _key in _move_info.detectors:
_detector_name = _move_info.detectors[_key].detector_name
if _detector_name:
_component_names.append(_detector_name)
# We reset the HAB, the LAB, the sample holder and monitor 4
if not component:
component_names = list(move_info.monitor_names.values())
hab_key = DetectorType.to_string(DetectorType.HAB)
_reset_detector(hab_key, move_info, component_names)
lab_key = DetectorType.to_string(DetectorType.LAB)
_reset_detector(lab_key, move_info, component_names)
component_names.append("some-sample-holder")
else:
component_names = [component]
# We also want to check the sample holder
set_selected_components_to_original_position(workspace, component_names)
示例7: do_move_initial
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def do_move_initial(self, move_info, workspace, coordinates, component, is_transmission_workspace):
# For LOQ we only have to coordinates
assert len(coordinates) == 2
if not is_transmission_workspace:
# First move the sample holder
move_sample_holder(workspace, move_info.sample_offset, move_info.sample_offset_direction)
x = coordinates[0]
y = coordinates[1]
center_position = move_info.center_position
x_shift = center_position - x
y_shift = center_position - y
detectors = [DetectorType.to_string(DetectorType.LAB), DetectorType.to_string(DetectorType.HAB)]
for detector in detectors:
# Get the detector name
component_name = move_info.detectors[detector].detector_name
# Shift the detector by the the input amount
offset = {CanonicalCoordinates.X: x_shift,
CanonicalCoordinates.Y: y_shift}
move_component(workspace, offset, component_name)
# Shift the detector according to the corrections of the detector under investigation
offset_from_corrections = {CanonicalCoordinates.X: move_info.detectors[detector].x_translation_correction,
CanonicalCoordinates.Y: move_info.detectors[detector].y_translation_correction,
CanonicalCoordinates.Z: move_info.detectors[detector].z_translation_correction}
move_component(workspace, offset_from_corrections, component_name)
示例8: validate
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def validate(self):
is_invalid = {}
if one_is_none([self.wavelength_low, self.wavelength_high, self.wavelength_step, self.wavelength_step_type]):
entry = validation_message("A wavelength entry has not been set.",
"Make sure that all entries are set.",
{"wavelength_low": self.wavelength_low,
"wavelength_high": self.wavelength_high,
"wavelength_step": self.wavelength_step,
"wavelength_step_type": self.wavelength_step_type})
is_invalid.update(entry)
if is_not_none_and_first_larger_than_second([self.wavelength_low, self.wavelength_high]):
entry = validation_message("Incorrect wavelength bounds.",
"Make sure that lower wavelength bound is smaller then upper bound.",
{"wavelength_low": self.wavelength_low,
"wavelength_high": self.wavelength_high})
is_invalid.update(entry)
try:
self.adjustment_files[DetectorType.to_string(DetectorType.LAB)].validate()
self.adjustment_files[DetectorType.to_string(DetectorType.HAB)].validate()
except ValueError as e:
is_invalid.update({"adjustment_files": str(e)})
if is_invalid:
raise ValueError("StateWavelengthAndPixelAdjustment: The provided inputs are illegal. "
"Please see: {0}".format(json.dumps(is_invalid)))
示例9: PyInit
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def PyInit(self):
# ----------
# INPUT
# ----------
# Workspace which is to be cropped
self.declareProperty(PropertyManagerProperty('SANSState'),
doc='A property manager which fulfills the SANSState contract.')
self.declareProperty(MatrixWorkspaceProperty("SampleScatterWorkspace", '',
optional=PropertyMode.Mandatory, direction=Direction.Input),
doc='The sample scatter data')
self.declareProperty(MatrixWorkspaceProperty('SampleScatterMonitorWorkspace', '',
optional=PropertyMode.Mandatory, direction=Direction.Input),
doc='The scatter monitor workspace. This workspace only condtains monitors.')
self.declareProperty("Centre1", 0.0, direction=Direction.InOut)
self.declareProperty("Centre2", 0.0, direction=Direction.InOut)
self.declareProperty("RMin", 0.06, direction=Direction.Input)
self.declareProperty('Tolerance', 0.0001251, direction=Direction.Input)
self.declareProperty('Iterations', 10, direction=Direction.Input)
allowed_detectors = StringListValidator([DetectorType.to_string(DetectorType.LAB),
DetectorType.to_string(DetectorType.HAB)])
self.declareProperty("Component", DetectorType.to_string(DetectorType.LAB),
validator=allowed_detectors, direction=Direction.Input,
doc="The component of the instrument which is to be reduced.")
示例10: _run_test
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def _run_test(state, sample_data, sample_monitor_data, transmission_data, direct_data, is_lab=True, is_sample=True):
adjustment_name = "SANSCreateAdjustmentWorkspaces"
adjustment_options = {"SANSState": state,
"SampleData": sample_data,
"MonitorWorkspace": sample_monitor_data,
"TransmissionWorkspace": transmission_data,
"DirectWorkspace": direct_data,
"OutputWorkspaceWavelengthAdjustment": EMPTY_NAME,
"OutputWorkspacePixelAdjustment": EMPTY_NAME,
"OutputWorkspaceWavelengthAndPixelAdjustment": EMPTY_NAME}
if is_sample:
adjustment_options.update({"DataType": DataType.to_string(DataType.Sample)})
else:
adjustment_options.update({"DataType": DataType.to_string(DataType.Can)})
if is_lab:
adjustment_options.update({"Component": DetectorType.to_string(DetectorType.LAB)})
else:
adjustment_options.update({"Component": DetectorType.to_string(DetectorType.HAB)})
adjustment_alg = create_unmanaged_algorithm(adjustment_name, **adjustment_options)
adjustment_alg.execute()
wavelength_adjustment = adjustment_alg.getProperty("OutputWorkspaceWavelengthAdjustment").value
pixel_adjustment = adjustment_alg.getProperty("OutputWorkspacePixelAdjustment").value
wavelength_and_pixel_adjustment = adjustment_alg.getProperty(
"OutputWorkspaceWavelengthAndPixelAdjustment").value
calculated_transmission = adjustment_alg.getProperty("CalculatedTransmissionWorkspace").value
unfitted_transmission = adjustment_alg.getProperty("UnfittedTransmissionWorkspace").value
return wavelength_adjustment, pixel_adjustment, wavelength_and_pixel_adjustment,\
calculated_transmission, unfitted_transmission
示例11: test_that_converter_methods_work
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def test_that_converter_methods_work(self):
# Arrange
state = StateReductionMode()
state.reduction_mode = ISISReductionMode.Merged
state.dimensionality = ReductionDimensionality.TwoDim
state.merge_shift = 12.65
state.merge_scale = 34.6
state.merge_fit_mode = FitModeForMerge.ShiftOnly
state.detector_names[DetectorType.to_string(DetectorType.LAB)] = "Test1"
state.detector_names[DetectorType.to_string(DetectorType.HAB)] = "Test2"
state.merge_mask = True
state.merge_min = 78.89
state.merge_max = 56.4
# Assert
merge_strategy = state.get_merge_strategy()
self.assertTrue(merge_strategy[0] is ISISReductionMode.LAB)
self.assertTrue(merge_strategy[1] is ISISReductionMode.HAB)
all_reductions = state.get_all_reduction_modes()
self.assertTrue(len(all_reductions) == 2)
self.assertTrue(all_reductions[0] is ISISReductionMode.LAB)
self.assertTrue(all_reductions[1] is ISISReductionMode.HAB)
result_lab = state.get_detector_name_for_reduction_mode(ISISReductionMode.LAB)
self.assertTrue(result_lab == "Test1")
result_hab = state.get_detector_name_for_reduction_mode(ISISReductionMode.HAB)
self.assertTrue(result_hab == "Test2")
self.assertRaises(RuntimeError, state.get_detector_name_for_reduction_mode, "non_sense")
示例12: set_spectrum_range_on_detector
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def set_spectrum_range_on_detector(self, spectrum_range_start, spectrum_range_stop):
"""
An unusual setter in the state framework. We cannot just call an automatic setter, since we have to decide
on which detector the spectrum range lives.
:param spectrum_range_start: a list of start spectra which we need to set on the right detector
:param spectrum_range_stop: a list of stop spectra which we need to set on the right detector
"""
instrument = self._data.instrument
for start, stop in zip(spectrum_range_start, spectrum_range_stop):
detector_bank_start = get_bank_for_spectrum_number(start, instrument)
detector_bank_stop = get_bank_for_spectrum_number(stop, instrument)
if detector_bank_start != detector_bank_stop:
raise ValueError("The specified spectrum mask range S{0}{1} has spectra on more than one detector. "
"Make sure that all spectra in the range are on a single detector".format(start, stop))
else:
detector_mask_state = self.state.detectors[DetectorType.to_string(detector_bank_start)]
spec_range_start = detector_mask_state.spectrum_range_start
spec_range_stop = detector_mask_state.spectrum_range_stop
# Set the start spectrum range
if spec_range_start is not None:
spec_range_start.append(start)
else:
self.state.detectors[DetectorType.to_string(detector_bank_start)].spectrum_range_start = [start]
# Set the stop spectrum range
if spec_range_stop is not None:
spec_range_stop.append(stop)
else:
self.state.detectors[DetectorType.to_string(detector_bank_start)].spectrum_range_stop = [stop]
示例13: PyInit
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def PyInit(self):
# ----------
# INPUT
# ----------
self.declareProperty(PropertyManagerProperty('SANSState'),
doc='A property manager which fulfills the SANSState contract.')
# WORKSPACES
# Scatter Workspaces
self.declareProperty(MatrixWorkspaceProperty('ScatterWorkspace', '',
optional=PropertyMode.Optional, direction=Direction.Input),
doc='The scatter workspace. This workspace does not contain monitors.')
self.declareProperty(MatrixWorkspaceProperty('ScatterMonitorWorkspace', '',
optional=PropertyMode.Optional, direction=Direction.Input),
doc='The scatter monitor workspace. This workspace only contains monitors.')
# Transmission Workspace
self.declareProperty(MatrixWorkspaceProperty('TransmissionWorkspace', '',
optional=PropertyMode.Optional, direction=Direction.Input),
doc='The transmission workspace.')
# Direct Workspace
self.declareProperty(MatrixWorkspaceProperty('DirectWorkspace', '',
optional=PropertyMode.Optional, direction=Direction.Input),
doc='The direct workspace.')
self.setPropertyGroup("ScatterWorkspace", 'Data')
self.setPropertyGroup("ScatterMonitorWorkspace", 'Data')
self.setPropertyGroup("TransmissionWorkspace", 'Data')
self.setPropertyGroup("DirectWorkspace", 'Data')
# The component
allowed_detectors = StringListValidator([DetectorType.to_string(DetectorType.LAB),
DetectorType.to_string(DetectorType.HAB)])
self.declareProperty("Component", DetectorType.to_string(DetectorType.LAB),
validator=allowed_detectors, direction=Direction.Input,
doc="The component of the instrument which is to be reduced.")
# The data type
allowed_data = StringListValidator([DataType.to_string(DataType.Sample),
DataType.to_string(DataType.Can)])
self.declareProperty("DataType", DataType.to_string(DataType.Sample),
validator=allowed_data, direction=Direction.Input,
doc="The component of the instrument which is to be reduced.")
# ----------
# OUTPUT
# ----------
self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", '', direction=Direction.Output),
doc='The output workspace.')
self.declareProperty(MatrixWorkspaceProperty('SumOfCounts', '', optional=PropertyMode.Optional,
direction=Direction.Output),
doc='The sum of the counts of the output workspace.')
self.declareProperty(MatrixWorkspaceProperty('SumOfNormFactors', '', optional=PropertyMode.Optional,
direction=Direction.Output),
doc='The sum of the counts of the output workspace.')
示例14: get_detector_name_for_reduction_mode
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def get_detector_name_for_reduction_mode(self, reduction_mode):
if reduction_mode is ISISReductionMode.LAB:
bank_type = DetectorType.to_string(DetectorType.LAB)
elif reduction_mode is ISISReductionMode.HAB:
bank_type = DetectorType.to_string(DetectorType.HAB)
else:
raise RuntimeError("SANStateReductionISIS: There is no detector available for the"
" reduction mode {0}.".format(reduction_mode))
return self.detector_names[bank_type]
示例15: test_that_SANS2D_can_move
# 需要导入模块: from sans.common.enums import DetectorType [as 别名]
# 或者: from sans.common.enums.DetectorType import to_string [as 别名]
def test_that_SANS2D_can_move(self):
# Arrange
file_name = "SANS2D00028784"
lab_z_translation_correction = 123.
workspace = load_workspace(file_name)
state = SANSMoveTest._get_simple_state(sample_scatter=file_name,
lab_z_translation_correction=lab_z_translation_correction)
beam_coordinates = [0.1076, -0.0835]
# Act
# The component input is not relevant for SANS2D's initial move. All detectors are moved
component = None
move_alg = self._run_move(state, workspace=workspace, move_type="InitialMove",
beam_coordinates=beam_coordinates, component=component)
# Assert for initial move for low angle bank
# These values are on the workspace and in the sample logs,
component_to_investigate = DetectorType.to_string(DetectorType.LAB)
initial_z_position = 23.281
rear_det_z = 11.9989755859
offset = 4.
total_x = 0.
total_y = 0.
total_z = initial_z_position + rear_det_z - offset + lab_z_translation_correction
expected_position = V3D(total_x - beam_coordinates[0], total_y - beam_coordinates[1], total_z)
expected_rotation = Quat(1., 0., 0., 0.)
self.compare_expected_position(expected_position, expected_rotation,
component_to_investigate, state.move, workspace)
# Assert for initial move for high angle bank
# These values are on the workspace and in the sample logs
component_to_investigate = DetectorType.to_string(DetectorType.HAB)
initial_x_position = 1.1
x_correction = -0.187987540973
initial_z_position = 23.281
z_correction = 1.00575649188
total_x = initial_x_position + x_correction
total_y = 0.
total_z = initial_z_position + z_correction
expected_position = V3D(total_x - beam_coordinates[0], total_y - beam_coordinates[1], total_z)
expected_rotation = Quat(0.9968998362876025, 0., 0.07868110579898738, 0.)
self.compare_expected_position(expected_position, expected_rotation,
component_to_investigate, state.move, workspace)
# Act + Assert for elementary move
component_elementary_move = "rear-detector"
component_elementary_move_key = DetectorType.to_string(DetectorType.LAB)
beam_coordinates_elementary_move = [120, 135]
self.check_that_elementary_displacement_with_only_translation_is_correct(workspace, move_alg, state.move,
beam_coordinates_elementary_move,
component_elementary_move,
component_elementary_move_key)
# # Act + Assert for setting to zero position for all
self.check_that_sets_to_zero(workspace, move_alg, state.move, comp_name=None)