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)
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)
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)
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)
def test_that_cylinder_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) # 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)
def test_that_mask_can_be_built(self): # Arrange facility = SANSFacility.ISIS file_information = SANSFileInformationMock(run_number=74044) data_builder = get_data_builder(facility, file_information) data_builder.set_sample_scatter("LOQ74044") data_builder.set_sample_scatter_period(3) data_info = data_builder.build() # Act builder = get_mask_builder(data_info) self.assertTrue(builder) start_time = [0.1, 1.3] end_time = [0.2, 1.6] builder.set_bin_mask_general_start(start_time) builder.set_bin_mask_general_stop(end_time) builder.set_LAB_single_vertical_strip_mask([1, 2, 3]) # Assert state = builder.build() self.assertTrue(len(state.bin_mask_general_start) == 2) self.assertTrue(state.bin_mask_general_start[0] == start_time[0]) self.assertTrue(state.bin_mask_general_start[1] == start_time[1]) self.assertTrue(len(state.bin_mask_general_stop) == 2) self.assertTrue(state.bin_mask_general_stop[0] == end_time[0]) self.assertTrue(state.bin_mask_general_stop[1] == end_time[1]) strip_mask = state.detectors[DetectorType.to_string( DetectorType.LAB)].single_vertical_strip_mask self.assertTrue(len(strip_mask) == 3) self.assertTrue(strip_mask[2] == 3)
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)
def test_that_mask_can_be_built(self): # Arrange facility = SANSFacility.ISIS data_builder = get_data_builder(facility) data_builder.set_sample_scatter("LOQ74044") data_builder.set_sample_scatter_period(3) data_info = data_builder.build() # Act builder = get_mask_builder(data_info) self.assertTrue(builder) start_time = [0.1, 1.3] end_time = [0.2, 1.6] builder.set_bin_mask_general_start(start_time) builder.set_bin_mask_general_stop(end_time) builder.set_LAB_single_vertical_strip_mask([1, 2, 3]) # Assert state = builder.build() self.assertTrue(len(state.bin_mask_general_start) == 2) self.assertTrue(state.bin_mask_general_start[0] == start_time[0]) self.assertTrue(state.bin_mask_general_start[1] == start_time[1]) self.assertTrue(len(state.bin_mask_general_stop) == 2) self.assertTrue(state.bin_mask_general_stop[0] == end_time[0]) self.assertTrue(state.bin_mask_general_stop[1] == end_time[1]) strip_mask = state.detectors[DetectorType.to_string(DetectorType.LAB)].single_vertical_strip_mask self.assertTrue(len(strip_mask) == 3) self.assertTrue(strip_mask[2] == 3)
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)
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)
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)))
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)
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)
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)))
def test_that_block_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 expected_spectra = [] # Block # Detector-specific block # The block will be evaluated for SANS2D on the LAB as: block_horizontal_start = [12, 17] block_horizontal_stop = [14, 21] block_vertical_start = [45, 87] block_vertical_stop = [48, 91] for h_start, h_stop, v_start, v_stop in zip(block_horizontal_start, block_horizontal_stop, block_vertical_start, block_vertical_stop): expected_spectra.extend(((h_start * 512 + 9) + y * 512 + x for y in range(0, h_stop - h_start + 1) for x in range(v_start, v_stop + 1))) mask_builder.set_LAB_block_horizontal_start(block_horizontal_start) mask_builder.set_LAB_block_horizontal_stop(block_horizontal_stop) mask_builder.set_LAB_block_vertical_start(block_vertical_start) mask_builder.set_LAB_block_vertical_stop(block_vertical_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) # Act workspace = self._run_mask(state, workspace, "LAB") # Assert self._do_assert(workspace, expected_spectra)
def test_that_detector_specific_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_start = [27000., 58000.] bin_mask_stop = [45000., 61000.] mask_builder.set_LAB_bin_mask_start(bin_mask_start) mask_builder.set_LAB_bin_mask_stop(bin_mask_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) # Is part of LAB tof_spectra_23813_original = workspace.getSpectrum(23813).getTofs() # Act workspace = self._run_mask(state, workspace, "LAB") # Assert # Confirm that everything in the ranges 27000-45000 and 58000-61000 is removed from the event list tof_spectra_23813_masked = workspace.getSpectrum(23813).getTofs() # Spectrum 23813 # Five events should have been removed self.assertTrue( len(tof_spectra_23813_masked) == len(tof_spectra_23813_original) - 5) # Make sure that there are no elements for start, stop in zip(bin_mask_start, bin_mask_stop): self.assertFalse( any(elements_in_range(start, stop, tof_spectra_23813_masked)))
def test_that_beam_stop_masking_is_applied_for_LOQ(self): # Arrange file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "LOQ74044") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("LOQ74044") 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((7811 + x for x in range(0, 63))) expected_spectra.extend((7939 + x for x in range(0, 63))) 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() move_builder = get_move_builder(data_info) move_builder.set_center_position(0.) move_info = move_builder.build() test_director = TestDirector() test_director.set_states(data_state=data_info, mask_state=mask_info, move_state=move_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)
def test_that_block_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 expected_spectra = [] # Block # Detector-specific block # The block will be evaluated for SANS2D on the LAB as: block_horizontal_start = [12, 17] block_horizontal_stop = [14, 21] block_vertical_start = [45, 87] block_vertical_stop = [48, 91] for h_start, h_stop, v_start, v_stop in zip(block_horizontal_start, block_horizontal_stop, block_vertical_start, block_vertical_stop): expected_spectra.extend(((h_start*512 + 9) + y*512 + x for y in range(0, h_stop - h_start + 1) for x in range(v_start, v_stop + 1))) mask_builder.set_LAB_block_horizontal_start(block_horizontal_start) mask_builder.set_LAB_block_horizontal_stop(block_horizontal_stop) mask_builder.set_LAB_block_vertical_start(block_vertical_start) mask_builder.set_LAB_block_vertical_stop(block_vertical_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) # Act workspace = self._run_mask(state, workspace, "LAB") # Assert self._do_assert(workspace, expected_spectra)
def test_that_detector_specific_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_start = [27000., 58000.] bin_mask_stop = [45000., 61000.] mask_builder.set_LAB_bin_mask_start(bin_mask_start) mask_builder.set_LAB_bin_mask_stop(bin_mask_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) # Is part of LAB tof_spectra_23813_original = workspace.getSpectrum(23813).getTofs() # Act workspace = self._run_mask(state, workspace, "LAB") # Assert # Confirm that everything in the ranges 27000-45000 and 58000-61000 is removed from the event list tof_spectra_23813_masked = workspace.getSpectrum(23813).getTofs() # Spectrum 23813 # Five events should have been removed self.assertTrue(len(tof_spectra_23813_masked) == len(tof_spectra_23813_original) - 5) # Make sure that there are no elements for start, stop in zip(bin_mask_start, bin_mask_stop): self.assertFalse(any(elements_in_range(start, stop, tof_spectra_23813_masked)))
def test_that_beam_stop_masking_is_applied_for_LOQ(self): # Arrange file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information("LOQ74044") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("LOQ74044") 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((7811 + x for x in range(0, 63))) expected_spectra.extend((7939 + x for x in range(0, 63))) 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() move_builder = get_move_builder(data_info) move_builder.set_center_position(0.) move_info = move_builder.build() test_director = TestDirector() test_director.set_states(data_state=data_info, mask_state=mask_info, move_state=move_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)
def test_that_spectra_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 = [] # Standard spectra single_spectra = [13, 14, 17] expected_spectra.extend(single_spectra) spectrum_range_start = [20, 30] spectrum_range_stop = [25, 35] expected_spectra.extend(list(range(20, 25 + 1))) expected_spectra.extend(list(range(30, 35 + 1))) # Detector-specific single horizontal strip mask # The horizontal strip will be evaluated for SANS2D on the LAB as: # e.g. [(50*512 + 9(monitors)] + x in range(0, 512) single_horizontal_strip_masks = [50, 53] for single_horizontal_strip_mask in single_horizontal_strip_masks: expected_spectra.extend(((single_horizontal_strip_mask*512 + 9) + x for x in range(0, 512))) # Detector-specific range horizontal strip mask # The horizontal range will be evaluated for SANS2D on the LAB as: # e.g. [(62*512 + 9(monitors)] + x in range(0, 512) + (63*512 + 9(monitors)] + x in range(0, 512) + ...] range_horizontal_strip_start = [62, 67] range_horizontal_strip_stop = [64, 70] for start, stop in zip(range_horizontal_strip_start, range_horizontal_strip_stop): expected_spectra.extend(((start*512 + 9) + y*512 + x for y in range(0, stop - start + 1) for x in range(0, 512))) # Detector-specific single vertical strip mask # The vertical strip will be evaluated for SANS2D on the LAB as: # e.g. [(45 + 9(monitors)] + y*512 for y in range(0, 120)] single_vertical_strip_masks = [45, 89] for single_vertical_strip_mask in single_vertical_strip_masks: expected_spectra.extend(((single_vertical_strip_mask + 9) + y*512 for y in range(0, 120))) # Detector-specific range vertical strip mask # The vertical range will be evaluated for SANS2D on the LAB as: range_vertical_strip_start = [99] range_vertical_strip_stop = [102] for start, stop in zip(range_vertical_strip_start, range_vertical_strip_stop): expected_spectra.extend(((start_elem + 9) + y * 512 for start_elem in range(start, stop + 1) for y in range(0, 120))) mask_builder.set_single_spectra_on_detector(single_spectra) mask_builder.set_spectrum_range_on_detector(spectrum_range_start, spectrum_range_stop) mask_builder.set_LAB_single_horizontal_strip_mask(single_horizontal_strip_masks) mask_builder.set_LAB_range_horizontal_strip_start(range_horizontal_strip_start) mask_builder.set_LAB_range_horizontal_strip_stop(range_horizontal_strip_stop) mask_builder.set_LAB_single_vertical_strip_mask(single_vertical_strip_masks) mask_builder.set_LAB_range_vertical_strip_start(range_vertical_strip_start) mask_builder.set_LAB_range_vertical_strip_stop(range_vertical_strip_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) # Act workspace = self._run_mask(state, workspace, "LAB") # Assert self._do_assert(workspace, expected_spectra)
def test_that_spectra_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 expected_spectra = [] # Standard spectra single_spectra = [13, 14, 17] expected_spectra.extend(single_spectra) spectrum_range_start = [20, 30] spectrum_range_stop = [25, 35] expected_spectra.extend(list(range(20, 25 + 1))) expected_spectra.extend(list(range(30, 35 + 1))) # Detector-specific single horizontal strip mask # The horizontal strip will be evaluated for SANS2D on the LAB as: # e.g. [(50*512 + 9(monitors)] + x in range(0, 512) single_horizontal_strip_masks = [50, 53] for single_horizontal_strip_mask in single_horizontal_strip_masks: expected_spectra.extend( ((single_horizontal_strip_mask * 512 + 9) + x for x in range(0, 512))) # Detector-specific range horizontal strip mask # The horizontal range will be evaluated for SANS2D on the LAB as: # e.g. [(62*512 + 9(monitors)] + x in range(0, 512) + (63*512 + 9(monitors)] + x in range(0, 512) + ...] range_horizontal_strip_start = [62, 67] range_horizontal_strip_stop = [64, 70] for start, stop in zip(range_horizontal_strip_start, range_horizontal_strip_stop): expected_spectra.extend(((start * 512 + 9) + y * 512 + x for y in range(0, stop - start + 1) for x in range(0, 512))) # Detector-specific single vertical strip mask # The vertical strip will be evaluated for SANS2D on the LAB as: # e.g. [(45 + 9(monitors)] + y*512 for y in range(0, 120)] single_vertical_strip_masks = [45, 89] for single_vertical_strip_mask in single_vertical_strip_masks: expected_spectra.extend(((single_vertical_strip_mask + 9) + y * 512 for y in range(0, 120))) # Detector-specific range vertical strip mask # The vertical range will be evaluated for SANS2D on the LAB as: range_vertical_strip_start = [99] range_vertical_strip_stop = [102] for start, stop in zip(range_vertical_strip_start, range_vertical_strip_stop): expected_spectra.extend(((start_elem + 9) + y * 512 for start_elem in range(start, stop + 1) for y in range(0, 120))) mask_builder.set_single_spectra_on_detector(single_spectra) mask_builder.set_spectrum_range_on_detector(spectrum_range_start, spectrum_range_stop) mask_builder.set_LAB_single_horizontal_strip_mask( single_horizontal_strip_masks) mask_builder.set_LAB_range_horizontal_strip_start( range_horizontal_strip_start) mask_builder.set_LAB_range_horizontal_strip_stop( range_horizontal_strip_stop) mask_builder.set_LAB_single_vertical_strip_mask( single_vertical_strip_masks) mask_builder.set_LAB_range_vertical_strip_start( range_vertical_strip_start) mask_builder.set_LAB_range_vertical_strip_stop( range_vertical_strip_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) # Act workspace = self._run_mask(state, workspace, "LAB") # Assert self._do_assert(workspace, expected_spectra)
def construct(self): facility = SANSFacility.ISIS # Build the SANSStateData if self.data_state is None: data_builder = get_data_builder(facility) data_builder.set_sample_scatter("SANS2D00022024") data_builder.set_can_scatter("SANS2D00022024") self.data_state = data_builder.build() # Build the SANSStateMove if self.move_state is None: move_builder = get_move_builder(self.data_state) if hasattr(move_builder, "set_HAB_x_translation_correction"): move_builder.set_HAB_x_translation_correction(21.2) move_builder.set_LAB_x_translation_correction(12.1) self.move_state = move_builder.build() # Build the SANSStateReduction if self.reduction_state is None: reduction_builder = get_reduction_mode_builder(self.data_state) reduction_builder.set_reduction_mode(ISISReductionMode.Merged) reduction_builder.set_reduction_dimensionality(ReductionDimensionality.OneDim) reduction_builder.set_merge_fit_mode(FitModeForMerge.Both) reduction_builder.set_merge_shift(324.2) reduction_builder.set_merge_scale(3420.98) self.reduction_state = reduction_builder.build() # Build the SANSStateSliceEvent if self.slice_state is None: slice_builder = get_slice_event_builder(self.data_state) slice_builder.set_start_time([0.1, 1.3]) slice_builder.set_end_time([0.2, 1.6]) self.slice_state = slice_builder.build() # Build the SANSStateMask if self.mask_state is None: mask_builder = get_mask_builder(self.data_state) mask_builder.set_radius_min(10.0) mask_builder.set_radius_max(20.0) self.mask_state = mask_builder.build() # Build the SANSStateWavelength if self.wavelength_state is None: wavelength_builder = get_wavelength_builder(self.data_state) wavelength_builder.set_wavelength_low(1.0) wavelength_builder.set_wavelength_high(10.0) wavelength_builder.set_wavelength_step(2.0) wavelength_builder.set_wavelength_step_type(RangeStepType.Lin) wavelength_builder.set_rebin_type(RebinType.Rebin) self.wavelength_state = wavelength_builder.build() # Build the SANSStateSave if self.save_state is None: save_builder = get_save_builder(self.data_state) save_builder.set_user_specified_output_name("test_file_name") save_builder.set_file_format([SaveType.Nexus]) self.save_state = save_builder.build() # Build the SANSStateScale if self.scale_state is None: scale_builder = get_scale_builder(self.data_state) scale_builder.set_shape(SampleShape.Cuboid) scale_builder.set_width(1.0) scale_builder.set_height(2.0) scale_builder.set_thickness(3.0) scale_builder.set_scale(4.0) self.scale_state = scale_builder.build() # Build the SANSAdjustmentState if self.adjustment_state is None: # NormalizeToMonitor normalize_to_monitor_builder = get_normalize_to_monitor_builder(self.data_state) normalize_to_monitor_builder.set_wavelength_low(1.0) normalize_to_monitor_builder.set_wavelength_high(10.0) normalize_to_monitor_builder.set_wavelength_step(2.0) normalize_to_monitor_builder.set_wavelength_step_type(RangeStepType.Lin) normalize_to_monitor_builder.set_rebin_type(RebinType.Rebin) normalize_to_monitor_builder.set_background_TOF_general_start(1000.) normalize_to_monitor_builder.set_background_TOF_general_stop(2000.) normalize_to_monitor_builder.set_incident_monitor(1) normalize_to_monitor = normalize_to_monitor_builder.build() # CalculateTransmission calculate_transmission_builder = get_calculate_transmission_builder(self.data_state) calculate_transmission_builder.set_transmission_monitor(3) calculate_transmission_builder.set_incident_monitor(2) calculate_transmission_builder.set_wavelength_low(1.0) calculate_transmission_builder.set_wavelength_high(10.0) calculate_transmission_builder.set_wavelength_step(2.0) calculate_transmission_builder.set_wavelength_step_type(RangeStepType.Lin) calculate_transmission_builder.set_rebin_type(RebinType.Rebin) calculate_transmission_builder.set_background_TOF_general_start(1000.) calculate_transmission_builder.set_background_TOF_general_stop(2000.) calculate_transmission_builder.set_Sample_fit_type(FitType.Linear) calculate_transmission_builder.set_Sample_polynomial_order(0) calculate_transmission_builder.set_Sample_wavelength_low(1.0) calculate_transmission_builder.set_Sample_wavelength_high(10.0) calculate_transmission_builder.set_Can_fit_type(FitType.Polynomial) calculate_transmission_builder.set_Can_polynomial_order(3) calculate_transmission_builder.set_Can_wavelength_low(10.0) calculate_transmission_builder.set_Can_wavelength_high(20.0) calculate_transmission = calculate_transmission_builder.build() # Wavelength and pixel adjustment wavelength_and_pixel_builder = get_wavelength_and_pixel_adjustment_builder(self.data_state) wavelength_and_pixel_builder.set_wavelength_low(1.0) wavelength_and_pixel_builder.set_wavelength_high(10.0) wavelength_and_pixel_builder.set_wavelength_step(2.0) wavelength_and_pixel_builder.set_wavelength_step_type(RangeStepType.Lin) wavelength_and_pixel = wavelength_and_pixel_builder.build() # Adjustment adjustment_builder = get_adjustment_builder(self.data_state) adjustment_builder.set_normalize_to_monitor(normalize_to_monitor) adjustment_builder.set_calculate_transmission(calculate_transmission) adjustment_builder.set_wavelength_and_pixel_adjustment(wavelength_and_pixel) self.adjustment_state = adjustment_builder.build() # SANSStateConvertToQ if self.convert_to_q_state is None: convert_to_q_builder = get_convert_to_q_builder(self.data_state) convert_to_q_builder.set_reduction_dimensionality(ReductionDimensionality.OneDim) convert_to_q_builder.set_use_gravity(False) convert_to_q_builder.set_radius_cutoff(0.002) convert_to_q_builder.set_wavelength_cutoff(12.) convert_to_q_builder.set_q_min(0.1) convert_to_q_builder.set_q_max(0.8) convert_to_q_builder.set_q_1d_rebin_string("0.1,0.01,0.8") convert_to_q_builder.set_use_q_resolution(False) self.convert_to_q_state = convert_to_q_builder.build() # Set the sub states on the SANSState state_builder = get_state_builder(self.data_state) state_builder.set_data(self.data_state) state_builder.set_move(self.move_state) state_builder.set_reduction(self.reduction_state) state_builder.set_slice(self.slice_state) state_builder.set_mask(self.mask_state) state_builder.set_wavelength(self.wavelength_state) state_builder.set_save(self.save_state) state_builder.set_scale(self.scale_state) state_builder.set_adjustment(self.adjustment_state) state_builder.set_convert_to_q(self.convert_to_q_state) return state_builder.build()