本文整理汇总了Python中sans.test_helper.test_director.TestDirector.set_states方法的典型用法代码示例。如果您正苦于以下问题:Python TestDirector.set_states方法的具体用法?Python TestDirector.set_states怎么用?Python TestDirector.set_states使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sans.test_helper.test_director.TestDirector
的用法示例。
在下文中一共展示了TestDirector.set_states方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_that_divide_uses_settings_from_workspace
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_divide_uses_settings_from_workspace(self):
# Arrange
facility = SANSFacility.ISIS
data_builder = get_data_builder(facility)
data_builder.set_sample_scatter("SANS2D00022024")
data_state = data_builder.build()
scale_builder = get_scale_builder(data_state)
scale_state = scale_builder.build()
test_director = TestDirector()
test_director.set_states(scale_state=scale_state, data_state=data_state)
state = test_director.construct()
divide_factory = DivideByVolumeFactory()
divider = divide_factory.create_divide_by_volume(state)
# Apply the settings from the SANS2D00022024 workspace
width = 8.
height = 8.
thickness = 1.
shape = 3
workspace = ScaleHelperTest._get_workspace(width, height, thickness, shape)
# Act
output_workspace = divider.divide_by_volume(workspace, scale_state)
# Assert
expected_volume = thickness * math.pi * math.pow(width, 2) / 4.0
expected_value = 0.3 / expected_volume
data_y = output_workspace.dataY(0)
self.assertEqual(data_y[0], expected_value)
示例2: test_that_divide_uses_settings_from_state_if_they_are_set
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_divide_uses_settings_from_state_if_they_are_set(self):
# Arrange
facility = SANSFacility.ISIS
data_builder = get_data_builder(facility)
data_builder.set_sample_scatter("SANS2D00022024")
data_state = data_builder.build()
scale_builder = get_scale_builder(data_state)
width = 10.
height = 5.
thickness = 2.
scale_builder.set_shape(SampleShape.CylinderAxisAlong)
scale_builder.set_thickness(thickness)
scale_builder.set_width(width)
scale_builder.set_height(height)
scale_state = scale_builder.build()
test_director = TestDirector()
test_director.set_states(scale_state=scale_state, data_state=data_state)
state = test_director.construct()
divide_factory = DivideByVolumeFactory()
divider = divide_factory.create_divide_by_volume(state)
workspace = ScaleHelperTest._get_workspace()
# Act
output_workspace = divider.divide_by_volume(workspace, scale_state)
# Assert
expected_volume = thickness * math.pi * math.pow(width, 2) / 4.0
expected_value = 0.3 / expected_volume
data_y = output_workspace.dataY(0)
self.assertEqual(data_y[0], expected_value)
示例3: test_that_beam_stop_masking_is_applied
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_beam_stop_masking_is_applied(self):
# Arrange
data_builder = get_data_builder(SANSFacility.ISIS)
data_builder.set_sample_scatter("SANS2D00028827")
data_info = data_builder.build()
mask_builder = get_mask_builder(data_info)
beam_stop_arm_width = .01
beam_stop_arm_angle = 180.0
beam_stop_arm_pos1 = 0.0
beam_stop_arm_pos2 = 0.0
# Expected_spectra, again the tubes are shifted and that will produce the slightly strange masking
expected_spectra = []
expected_spectra.extend((512*59 + 9 + x for x in range(0, 257)))
expected_spectra.extend((512*60 + 9 + x for x in range(0, 255)))
mask_builder.set_beam_stop_arm_width(beam_stop_arm_width)
mask_builder.set_beam_stop_arm_angle(beam_stop_arm_angle)
mask_builder.set_beam_stop_arm_pos1(beam_stop_arm_pos1)
mask_builder.set_beam_stop_arm_pos2(beam_stop_arm_pos2)
mask_info = mask_builder.build()
test_director = TestDirector()
test_director.set_states(data_state=data_info, mask_state=mask_info)
state = test_director.construct()
workspace = self._load_workspace(state, move_workspace=False)
# Act
workspace = self._run_mask(state, workspace, "LAB")
# Assert
self._do_assert(workspace, expected_spectra)
示例4: test_that_correct_scale_strategy_is_selected_for_loq_2
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_correct_scale_strategy_is_selected_for_loq_2(self):
# Arrange
facility = SANSFacility.ISIS
data_builder = get_data_builder(facility)
data_builder.set_sample_scatter("LOQ74044")
data_state = data_builder.build()
scale_builder = get_scale_builder(data_state)
scale_builder.set_scale(2.4)
scale_state = scale_builder.build()
test_director = TestDirector()
test_director.set_states(scale_state=scale_state, data_state=data_state)
state_loq = test_director.construct()
absolute_multiply_factory = MultiplyByAbsoluteScaleFactory()
multiplier = absolute_multiply_factory.create_multiply_by_absolute(state_loq)
workspace = self._get_workspace()
# Act
output_workspace = multiplier.multiply_by_absolute_scale(workspace, state_loq.scale)
# Assert
expected_value = 0.3 * 2.4 / math.pi * 100.
data_y = output_workspace.dataY(0)
self.assertEqual(data_y[0], expected_value)
示例5: test_that_cylinder_masking_is_applied
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_cylinder_masking_is_applied(self):
# Arrange
data_builder = get_data_builder(SANSFacility.ISIS)
data_builder.set_sample_scatter("SANS2D00028827")
data_info = data_builder.build()
mask_builder = get_mask_builder(data_info)
# Radius Mask
radius_min = 0.01
radius_max = 10.
expected_spectra = []
expected_spectra.extend([30469, 30470, 30471, 30472, 30473, 30474, 30475, 30476, 30477, 30980,
30981, 30982, 30983, 30984, 30985, 30986, 30987, 30988])
mask_builder.set_radius_min(radius_min)
mask_builder.set_radius_max(radius_max)
mask_info = mask_builder.build()
test_director = TestDirector()
test_director.set_states(data_state=data_info, mask_state=mask_info)
state = test_director.construct()
workspace = self._load_workspace(state, move_workspace=False)
# Act
workspace = self._run_mask(state, workspace, "LAB")
# Assert
self._do_assert(workspace, expected_spectra)
示例6: _get_sample_state
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def _get_sample_state(q_min=1., q_max=2., q_step=0.1, q_step_type=RangeStepType.Lin,
q_xy_max=None, q_xy_step=None, q_xy_step_type=None,
use_gravity=False, dim=ReductionDimensionality.OneDim):
# Arrange
facility = SANSFacility.ISIS
data_builder = get_data_builder(facility)
data_builder.set_sample_scatter("LOQ74044")
data_state = data_builder.build()
convert_to_q_builder = get_convert_to_q_builder(data_state)
convert_to_q_builder.set_reduction_dimensionality(dim)
convert_to_q_builder.set_use_gravity(use_gravity)
convert_to_q_builder.set_radius_cutoff(0.002)
convert_to_q_builder.set_wavelength_cutoff(2.)
convert_to_q_builder.set_q_min(q_min)
convert_to_q_builder.set_q_max(q_max)
prefix = 1. if q_step_type is RangeStepType.Lin else -1.
q_step *= prefix
rebin_string = str(q_min) + "," + str(q_step) + "," + str(q_max)
convert_to_q_builder.set_q_1d_rebin_string(rebin_string)
if q_xy_max is not None:
convert_to_q_builder.set_q_xy_max(q_xy_max)
if q_xy_step is not None:
convert_to_q_builder.set_q_xy_step(q_xy_step)
if q_xy_step_type is not None:
convert_to_q_builder.set_q_xy_step_type(q_xy_step_type)
convert_to_q_state = convert_to_q_builder.build()
test_director = TestDirector()
test_director.set_states(convert_to_q_state=convert_to_q_state, data_state=data_state)
return test_director.construct().property_manager
示例7: test_that_cross_block_masking_is_applied
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_cross_block_masking_is_applied(self):
# Arrange
data_builder = get_data_builder(SANSFacility.ISIS)
data_builder.set_sample_scatter("SANS2D00028827")
data_info = data_builder.build()
mask_builder = get_mask_builder(data_info)
# Expected_spectra
expected_spectra = []
# Block
# Detector-specific cross block
# The block will be evaluated for SANS2D on the LAB as:
block_cross_horizontal = [12, 17]
block_cross_vertical = [49, 67]
for h, v in zip(block_cross_horizontal, block_cross_vertical):
expected_spectra.extend([h*512 + 9 + v])
mask_builder.set_LAB_block_cross_horizontal(block_cross_horizontal)
mask_builder.set_LAB_block_cross_vertical(block_cross_vertical)
mask_info = mask_builder.build()
test_director = TestDirector()
test_director.set_states(data_state=data_info, mask_state=mask_info)
state = test_director.construct()
workspace = self._load_workspace(state)
# Act
workspace = self._run_mask(state, workspace, "LAB")
# Assert
self._do_assert(workspace, expected_spectra)
示例8: _get_simple_state
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def _get_simple_state(sample_scatter, sample_trans=None, sample_direct=None,
can_scatter=None, can_trans=None, can_direct=None, calibration=None,
sample_scatter_period=None, sample_trans_period=None, sample_direct_period=None,
can_scatter_period=None, can_trans_period=None, can_direct_period=None):
file_information_factory = SANSFileInformationFactory()
file_information = file_information_factory.create_sans_file_information(sample_scatter)
data_builder = get_data_builder(SANSFacility.ISIS, file_information)
data_builder.set_sample_scatter(sample_scatter)
# Set the file names
if sample_trans is not None:
data_builder.set_sample_transmission(sample_trans)
if sample_direct is not None:
data_builder.set_sample_direct(sample_direct)
if can_scatter is not None:
data_builder.set_can_scatter(can_scatter)
if can_trans is not None:
data_builder.set_can_transmission(can_trans)
if can_direct is not None:
data_builder.set_can_direct(can_direct)
# Set the periods
if sample_scatter_period is not None:
data_builder.set_sample_scatter_period(sample_scatter_period)
if sample_trans_period is not None:
data_builder.set_sample_transmission_period(sample_trans_period)
if sample_direct_period is not None:
data_builder.set_sample_direct_period(sample_direct_period)
if can_scatter_period is not None:
data_builder.set_can_scatter_period(can_scatter_period)
if can_trans_period is not None:
data_builder.set_can_transmission_period(can_trans_period)
if can_direct_period is not None:
data_builder.set_can_direct_period(can_direct_period)
# Add the calibration
if calibration is not None:
data_builder.set_calibration(calibration)
data_info = data_builder.build()
# Get the sample state
test_director = TestDirector()
test_director.set_states(data_state=data_info)
return test_director.construct()
示例9: get_example_state
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def get_example_state():
ws_name_sample = "SANS2D00022024"
data_builder = get_data_builder(SANSFacility.ISIS)
data_builder.set_sample_scatter(ws_name_sample)
data = data_builder.build()
# Get the sample state
test_director = TestDirector()
test_director.set_states(data_state=data)
return test_director.construct()
示例10: get_example_state
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def get_example_state():
ws_name_sample = "SANS2D00022024"
file_information = SANSFileInformationMock(instrument=SANSInstrument.SANS2D, run_number=22024)
data_builder = get_data_builder(SANSFacility.ISIS, file_information)
data_builder.set_sample_scatter(ws_name_sample)
data = data_builder.build()
# Get the sample state
test_director = TestDirector()
test_director.set_states(data_state=data)
return test_director.construct()
示例11: _get_simple_state
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def _get_simple_state(fit_type=FitModeForMerge.NoFit, scale=1.0, shift=0.0):
# Set the reduction parameters
reduction_info = StateReductionMode()
reduction_info.reduction_mode = ISISReductionMode.Merged
reduction_info.dimensionality = ReductionDimensionality.TwoDim
reduction_info.merge_shift = shift
reduction_info.merge_scale = scale
reduction_info.merge_fit_mode = fit_type
# Get the sample state
test_director = TestDirector()
test_director.set_states(reduction_state=reduction_info)
return test_director.construct()
示例12: test_that_angle_masking_is_applied
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_angle_masking_is_applied(self):
# Arrange
file_information_factory = SANSFileInformationFactory()
file_information = file_information_factory.create_sans_file_information("SANS2D00028827")
data_builder = get_data_builder(SANSFacility.ISIS, file_information)
data_builder.set_sample_scatter("SANS2D00028827")
data_info = data_builder.build()
mask_builder = get_mask_builder(data_info)
# Expected_spectra
phi_mirror = False
phi_min = 0.
phi_max = 90.
# This should mask everything except for the upper right quadrant
# | 120 |-------------------|
# | |---------------------|
# | 60 |-------------------|
# | |----------------------|
# |
# |
# |-------------------|------------------|
# 512 256 0
expected_spectra = []
# The strange double pattern arises from the offset of the SANS2D tube geometry (see InstrumentView)
for y in range(60, 120):
if y % 2 == 0:
expected_spectra.extend(((y * 512) + 9 + x for x in range(0, 255)))
else:
expected_spectra.extend(((y * 512) + 9 + x for x in range(0, 257)))
expected_spectra.extend((x for x in range(92169, 122889))) # HAB
mask_builder.set_use_mask_phi_mirror(phi_mirror)
mask_builder.set_phi_min(phi_min)
mask_builder.set_phi_max(phi_max)
mask_info = mask_builder.build()
test_director = TestDirector()
test_director.set_states(data_state=data_info, mask_state=mask_info)
state = test_director.construct()
workspace = self._load_workspace(state)
# Act
workspace = self._run_mask(state, workspace, "LAB")
# Assert
self._do_assert_non_masked(workspace, expected_spectra)
示例13: test_that_mask_files_are_applied
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_mask_files_are_applied(self):
def create_shape_xml_file(xml_string):
f_name = os.path.join(mantid.config.getString('defaultsave.directory'), 'sample_mask_file.xml')
if os.path.exists(f_name):
os.remove(f_name)
with open(f_name, 'w') as f:
f.write(xml_string)
return f_name
# Arrange
shape_xml = "<?xml version=\"1.0\"?>\n"\
"<detector-masking>\n" \
"<group>\n" \
"<detids>\n" \
"1313191-1313256\n" \
"</detids>\n" \
"</group>\n" \
"</detector-masking >"
file_name = create_shape_xml_file(shape_xml)
# Arrange
file_information_factory = SANSFileInformationFactory()
file_information = file_information_factory.create_sans_file_information("SANS2D00028827")
data_builder = get_data_builder(SANSFacility.ISIS, file_information)
data_builder.set_sample_scatter("SANS2D00028827")
data_info = data_builder.build()
mask_builder = get_mask_builder(data_info)
# Mask file
# Got the spectra from the detector view
expected_spectra = [x for x in range(31432, 31498)]
mask_builder.set_mask_files([file_name])
mask_info = mask_builder.build()
test_director = TestDirector()
test_director.set_states(data_state=data_info, mask_state=mask_info)
state = test_director.construct()
workspace = self._load_workspace(state, move_workspace=False)
# Act
workspace = self._run_mask(state, workspace, "LAB")
# Assert
self._do_assert(workspace, expected_spectra)
# Remove
if os.path.exists(file_name):
os.remove(file_name)
示例14: test_that_general_time_masking_is_applied
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def test_that_general_time_masking_is_applied(self):
# Arrange
file_information_factory = SANSFileInformationFactory()
file_information = file_information_factory.create_sans_file_information("SANS2D00028827")
data_builder = get_data_builder(SANSFacility.ISIS, file_information)
data_builder.set_sample_scatter("SANS2D00028827")
data_info = data_builder.build()
mask_builder = get_mask_builder(data_info)
# Expected_spectra
bin_mask_general_start = [30000., 67000.]
bin_mask_general_stop = [35000., 75000.]
# bin_mask_start = [14000]
# bin_mask_stop = FloatListParameter()
mask_builder.set_bin_mask_general_start(bin_mask_general_start)
mask_builder.set_bin_mask_general_stop(bin_mask_general_stop)
mask_info = mask_builder.build()
test_director = TestDirector()
test_director.set_states(data_state=data_info, mask_state=mask_info)
state = test_director.construct()
workspace = self._load_workspace(state, move_workspace=False)
tof_spectra_10_original = workspace.getSpectrum(10).getTofs()
tof_spectra_11_original = workspace.getSpectrum(11).getTofs()
# Act
workspace = self._run_mask(state, workspace, "LAB")
# Assert
# Confirm that everything in the ranges 30000-35000 and 67000-75000 is removed from the event list
tof_spectra_10_masked = workspace.getSpectrum(10).getTofs()
tof_spectra_11_masked = workspace.getSpectrum(11).getTofs()
# Spectrum 10
# Three events should have been removed
self.assertTrue(len(tof_spectra_10_masked) == len(tof_spectra_10_original) - 3)
# One event should have been removed
self.assertTrue(len(tof_spectra_11_masked) == len(tof_spectra_11_original) - 1)
# Make sure that there are no elements
for start, stop in zip(bin_mask_general_start, bin_mask_general_stop):
self.assertFalse(any(elements_in_range(start, stop, tof_spectra_10_masked)))
self.assertFalse(any(elements_in_range(start, stop, tof_spectra_11_masked)))
示例15: _get_simple_state
# 需要导入模块: from sans.test_helper.test_director import TestDirector [as 别名]
# 或者: from sans.test_helper.test_director.TestDirector import set_states [as 别名]
def _get_simple_state(sample_scatter, lab_x_translation_correction=None, lab_z_translation_correction=None):
# Set the data
data_builder = get_data_builder(SANSFacility.ISIS)
data_builder.set_sample_scatter(sample_scatter)
data_info = data_builder.build()
# Set the move parameters
builder = get_move_builder(data_info)
if lab_x_translation_correction is not None:
builder.set_LAB_x_translation_correction(lab_x_translation_correction)
if lab_z_translation_correction is not None:
builder.set_LAB_z_translation_correction(lab_z_translation_correction)
move_info = builder.build()
# Get the sample state
test_director = TestDirector()
test_director.set_states(data_state=data_info, move_state=move_info)
return test_director.construct()