def test_that_produces_correct_workspace_multiperiod_LARMOR(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "LARMOR00013065") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("LARMOR00013065") data_builder.set_calibration( "80tubeCalibration_1-05-2015_r3157-3160.nxs") data_state = data_builder.build() # Get the rest of the state from the user file user_file = "USER_LARMOR_151B_LarmorTeam_80tubes_BenchRot1p4_M4_r3699.txt" user_file_director = StateBuilder.new_instance( data_information=data_state, file_information=file_information, user_filename=user_file) # Construct the final state state = user_file_director.get_all_states() # Act output_workspaces = run_integral('', True, IntegralEnum.Horizontal, DetectorType.LAB, state) # Evaluate it up to a defined point reference_file_name = "LARMOR_ws_diagnostic_reference.nxs" self._compare_workspace(output_workspaces[0], reference_file_name)
def test_that_produces_correct_workspace_for_SANS2D(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_state = data_builder.build() # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_state, user_filename=user_file) state = user_file_director.get_all_states() state.compatibility.use_compatibility_mode = True # Act output_workspaces = run_integral('', True, IntegralEnum.Horizontal, DetectorType.LAB, state) self.assertEqual(len(output_workspaces), 1) # Evaluate it up to a defined point reference_file_name = "SANS2D_ws_centred_diagnostic_reference.nxs" self._compare_workspace(output_workspaces[0], reference_file_name)
def test_batch_reduction_on_period_time_sliced_wavelength_range_data(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D0005512") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D0005512") data_builder.set_sample_scatter_period(1) data_info = data_builder.build() # Get the rest of the state from the user file user_filename = "MASKSANS2Doptions.091A" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_filename) state = user_file_director.get_all_states() # Set the reduction mode to LAB state.reduction.reduction_mode = ReductionMode.LAB state.slice.start_time = [1.0, 3.0] state.slice.end_time = [3.0, 5.0] start = [1.0, 1.0] end = [3.0, 2.0] state.wavelength.wavelength_low = start state.wavelength.wavelength_high = end state.adjustment.normalize_to_monitor.wavelength_low = start state.adjustment.normalize_to_monitor.wavelength_high = end state.adjustment.calculate_transmission.wavelength_low = start state.adjustment.calculate_transmission.wavelength_high = end state.adjustment.wavelength_and_pixel_adjustment.wavelength_low = start state.adjustment.wavelength_and_pixel_adjustment.wavelength_high = end # Act states = [state] self._run_batch_reduction(states, use_optimizations=False) # Assert # We only assert that the expected workspaces exist on the ADS expected_workspaces = [ "5512_p1rear_1D_1.0_2.0Phi-45.0_45.0_t1.00_T3.00", "5512_p1rear_1D_1.0_2.0Phi-45.0_45.0_t3.00_T5.00", "5512_p1rear_1D_1.0_3.0Phi-45.0_45.0_t1.00_T3.00", "5512_p1rear_1D_1.0_3.0Phi-45.0_45.0_t3.00_T5.00" ] for element in expected_workspaces: self.assertTrue(AnalysisDataService.doesExist(element)) # Clean up for element in expected_workspaces: AnalysisDataService.remove(element)
def test_that_single_reduction_evaluates_LAB_for_2D_reduction(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_can_scatter("SANS2D00034481") data_builder.set_can_transmission("SANS2D00034502") data_builder.set_can_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_info = data_builder.build() # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_file) state = user_file_director.get_all_states() # Set the reduction mode to LAB state.reduction.reduction_mode = ReductionMode.LAB state.reduction.reduction_dimensionality = ReductionDimensionality.TWO_DIM state.convert_to_q.reduction_dimensionality = ReductionDimensionality.TWO_DIM state.compatibility.use_compatibility_mode = True # Load the sample workspaces sample, sample_monitor, transmission_workspace, direct_workspace, can, can_monitor, \ can_transmission, can_direct = self._load_workspace(state) # noqa # Act output_settings = {"OutputWorkspaceLAB": EMPTY_NAME} single_reduction_alg = self._run_single_reduction( state, sample_scatter=sample, sample_transmission=transmission_workspace, sample_direct=direct_workspace, sample_monitor=sample_monitor, can_scatter=can, can_monitor=can_monitor, can_transmission=can_transmission, can_direct=can_direct, output_settings=output_settings) output_workspace = single_reduction_alg.getProperty( "OutputWorkspaceLAB").value # Compare the output of the reduction with the reference reference_file_name = "SANS2D_ws_D20_reference_LAB_2D.nxs" self._compare_to_reference(output_workspace, reference_file_name)
def test_batch_reduction_on_time_sliced_file(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_can_scatter("SANS2D00034481") data_builder.set_can_transmission("SANS2D00034502") data_builder.set_can_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_info = data_builder.build() # Get the rest of the state from the user file user_filename = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_filename) state = user_file_director.get_all_states() # Set the reduction mode to LAB state.reduction.reduction_mode = ReductionMode.LAB state.compatibility.use_compatibility_mode = True # COMPATIBILITY BEGIN -- Remove when appropriate state.slice.start_time = [1.0, 3.0] state.slice.end_time = [3.0, 5.0] # Act states = [state] self._run_batch_reduction(states, use_optimizations=False) expected_workspaces = [ "34484_rear_1D_1.75_16.5_t1.00_T3.00", "34484_rear_1D_1.75_16.5_t3.00_T5.00" ] reference_file_names = [ "SANS2D_event_slice_referance_t1.00_T3.00.nxs", "SANS2D_event_slice_referance_t3.00_T5.00.nxs" ] for element, reference_file in zip(expected_workspaces, reference_file_names): self.assertTrue(AnalysisDataService.doesExist(element)) # Evaluate it up to a defined point self._compare_workspace(element, reference_file) # Clean up for element in expected_workspaces: AnalysisDataService.remove(element)
def test_that_beam_centre_core_produces_correct_workspaces(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_state = data_builder.build() # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( data_information=data_state, file_information=file_information, user_filename=user_file) state = user_file_director.get_all_states() state.compatibility.use_compatibility_mode = True # Load the sample workspaces workspace, workspace_monitor, transmission_workspace, direct_workspace = self._load_workspace( state) # Act reduction_core_alg = self._run_beam_centre_core( state, workspace, workspace_monitor, transmission_workspace, direct_workspace) output_workspace_left = reduction_core_alg.getProperty( "OutputWorkspaceLeft").value output_workspace_right = reduction_core_alg.getProperty( "OutputWorkspaceRight").value output_workspace_top = reduction_core_alg.getProperty( "OutputWorkspaceTop").value output_workspace_bottom = reduction_core_alg.getProperty( "OutputWorkspaceBottom").value # Evaluate it up to a defined point reference_file_name_left = "SANS2D_ws_D20_reference_left.nxs" reference_file_name_right = "SANS2D_ws_D20_reference_right.nxs" reference_file_name_top = "SANS2D_ws_D20_reference_top.nxs" reference_file_name_bottom = "SANS2D_ws_D20_reference_bottom.nxs" self._compare_workspace(output_workspace_left, reference_file_name_left) self._compare_workspace(output_workspace_right, reference_file_name_right) self._compare_workspace(output_workspace_top, reference_file_name_top) self._compare_workspace(output_workspace_bottom, reference_file_name_bottom)
def test_that_reduction_core_evaluates_LAB(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_state = data_builder.build() # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_state, user_filename=user_file) state = user_file_director.get_all_states() state.compatibility.use_compatibility_mode = True # Load the sample workspaces workspace, workspace_monitor, transmission_workspace, direct_workspace = self._load_workspace( state) # Act reduction_core_alg = self._run_reduction_core(state, workspace, workspace_monitor, transmission_workspace, direct_workspace) output_workspace = reduction_core_alg.getProperty( "OutputWorkspace").value calculated_transmission = reduction_core_alg.getProperty( "CalculatedTransmissionWorkspace").value unfitted_transmission = reduction_core_alg.getProperty( "UnfittedTransmissionWorkspace").value # Evaluate it up to a defined point reference_file_name = "SANS2D_ws_D20_reference.nxs" self._compare_workspace(output_workspace, reference_file_name) calculated_transmission_reference_file = "SANS2D_ws_D20_calculated_transmission_reference.nxs" unfitted_transmission_reference_file = "SANS2D_ws_D20_unfitted_transmission_reference.nxs" self._compare_workspace(calculated_transmission, calculated_transmission_reference_file) self._compare_workspace(unfitted_transmission, unfitted_transmission_reference_file)
def test_that_batch_reduction_evaluates_LAB(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_can_scatter("SANS2D00034481") data_builder.set_can_transmission("SANS2D00034502") data_builder.set_can_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_info = data_builder.build() user_filename = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_filename) # Get the rest of the state from the user file state = user_file_director.get_all_states() # Set the reduction mode to LAB state.reduction.reduction_mode = ReductionMode.LAB # Since we are dealing with event based data but we want to compare it with histogram data from the # old reduction system we need to enable the compatibility mode state.compatibility.use_compatibility_mode = True # COMPATIBILITY BEGIN -- Remove when appropriate # Act states = [state] self._run_batch_reduction(states, use_optimizations=False) workspace_name = "34484_rear_1D_1.75_16.5" output_workspace = AnalysisDataService.retrieve(workspace_name) # Evaluate it up to a defined point reference_file_name = "SANS2D_ws_D20_reference_LAB_1D.nxs" self._compare_workspace(output_workspace, reference_file_name) if AnalysisDataService.doesExist(workspace_name): AnalysisDataService.remove(workspace_name)
def test_batch_reduction_on_multiperiod_file(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D0005512") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D0005512") data_info = data_builder.build() # Get the rest of the state from the user file user_filename = "MASKSANS2Doptions.091A" user_file_parser = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_filename) state = user_file_parser.get_all_states() # Set the reduction mode to LAB state.reduction.reduction_mode = ReductionMode.LAB # Act states = [state] self._run_batch_reduction(states, use_optimizations=False) # Assert # We only assert that the expected workspaces exist on the ADS expected_workspaces = [ "5512_p{0}rear_1D_2.0_14.0Phi-45.0_45.0".format(i) for i in range(1, 14) ] for element in expected_workspaces: does_exist = AnalysisDataService.doesExist(element) self.assertTrue(does_exist, msg="{0} was not found".format(element)) # Clean up for element in expected_workspaces: AnalysisDataService.remove(element)
def test_similarity_between_results_in_compatibility_mode_and_non_compatibility_mode(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information("SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_state = data_builder.build() ################################################################################################################ # Compatibility mode ################################################################################################################ # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance(file_information=file_information, data_information=data_state, user_filename=user_file) state = user_file_director.get_all_states() state.compatibility.use_compatibility_mode = True # Load the sample workspaces workspace, workspace_monitor, transmission_workspace, direct_workspace = self._load_workspace(state) # Act reduction_core_alg = self._run_reduction_core(state, workspace, workspace_monitor, transmission_workspace, direct_workspace) compatibility_output_workspace = reduction_core_alg.getProperty("OutputWorkspace").value ################################################################################################################ # Non-compatibility mode ################################################################################################################ user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance(file_information=file_information, data_information=data_state, user_filename=user_file) state = user_file_director.get_all_states() state.compatibility.use_compatibility_mode = False # Load the sample workspaces workspace, workspace_monitor, transmission_workspace, direct_workspace = self._load_workspace(state) # Act reduction_core_alg = self._run_reduction_core(state, workspace, workspace_monitor, transmission_workspace, direct_workspace) non_compatibility_output_workspace = reduction_core_alg.getProperty("OutputWorkspace").value ################################################################################################################ # Compare workspaces ################################################################################################################ compare_name = "CompareWorkspaces" compare_options = {"Workspace1": non_compatibility_output_workspace, "Workspace2": compatibility_output_workspace, "Tolerance": 1, "CheckInstrument": False, "CheckSample": False, "ToleranceRelErr": True, "CheckAllData": True, "CheckMasking": True, "CheckType": True, "CheckAxes": True, "CheckSpectraMap": True} compare_alg = create_unmanaged_algorithm(compare_name, **compare_options) compare_alg.setChild(False) compare_alg.execute() result = compare_alg.getProperty("Result").value self.assertTrue(result)
def test_that_single_reduction_evaluates_LAB(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_can_scatter("SANS2D00034481") data_builder.set_can_transmission("SANS2D00034502") data_builder.set_can_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_info = data_builder.build() # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_file) # Set the reduction mode to LAB state = user_file_director.get_all_states() state.reduction.reduction_mode = ReductionMode.LAB state.compatibility.use_compatibility_mode = False # Add some event slices state.slice.start_time = [0.00, 300.00] state.slice.end_time = [300.00, 600.00] # Load the sample workspaces sample, sample_monitor, transmission_workspace, direct_workspace, can, can_monitor,\ can_transmission, can_direct = self._load_workspace(state) # noqa # Act output_settings = {"OutputWorkspaceLAB": EMPTY_NAME} single_reduction_v2_alg = self._run_single_reduction( state, sample_scatter=sample, sample_transmission=transmission_workspace, sample_direct=direct_workspace, sample_monitor=sample_monitor, can_scatter=can, can_monitor=can_monitor, can_transmission=can_transmission, can_direct=can_direct, output_settings=output_settings, event_slice_optimisation=True, save_can=True, use_optimizations=True) # Check output workspaces output_workspace = single_reduction_v2_alg.getProperty( "OutputWorkspaceLAB").value lab_can = single_reduction_v2_alg.getProperty( "OutputWorkspaceLABCan").value lab_sample = single_reduction_v2_alg.getProperty( "OutputWorkspaceLABSample").value lab_can_count = single_reduction_v2_alg.getProperty( "OutputWorkspaceLABCanCount").value lab_can_norm = single_reduction_v2_alg.getProperty( "OutputWorkspaceLABCanNorm").value self._assert_group_workspace(output_workspace) self._assert_group_workspace(lab_can) self._assert_group_workspace(lab_sample) self._assert_group_workspace(lab_can_count) self._assert_group_workspace(lab_can_norm) # --------------------------------------------------- # Comparison test with version 1 # This can be removed once version 2 has been adopted # --------------------------------------------------- # Run the first event slice state.slice.start_time = [0.00] state.slice.end_time = [300.00] single_reduction_alg_first_slice = self._run_single_reduction( state, sample_scatter=sample, sample_transmission=transmission_workspace, sample_direct=direct_workspace, sample_monitor=sample_monitor, can_scatter=can, can_monitor=can_monitor, can_transmission=can_transmission, can_direct=can_direct, output_settings=output_settings, event_slice_optimisation=False, save_can=True) # Run the second event slice state.slice.start_time = [300.00] state.slice.end_time = [600.00] single_reduction_alg_second_slice = self._run_single_reduction( state, sample_scatter=sample, sample_transmission=transmission_workspace, sample_direct=direct_workspace, sample_monitor=sample_monitor, can_scatter=can, can_monitor=can_monitor, can_transmission=can_transmission, can_direct=can_direct, output_settings=output_settings, event_slice_optimisation=False, save_can=True) # Now compare output workspaces from the two versions # Output LAB workspace event_slice_output_workspace = single_reduction_v2_alg.getProperty( "OutputWorkspaceLAB").value first_slice_output_workspace = single_reduction_alg_first_slice.getProperty( "OutputWorkspaceLAB").value second_slice_output_workspace = single_reduction_alg_second_slice.getProperty( "OutputWorkspaceLAB").value self._compare_workspace(event_slice_output_workspace[0], first_slice_output_workspace, tolerance=1e-6) self._compare_workspace(event_slice_output_workspace[1], second_slice_output_workspace, tolerance=1e-6) # LAB sample event_slice_output_sample = single_reduction_v2_alg.getProperty( "OutputWorkspaceLABSample").value first_slice_output_sample = single_reduction_alg_first_slice.getProperty( "OutputWorkspaceLABSample").value second_slice_output_sample = single_reduction_alg_second_slice.getProperty( "OutputWorkspaceLABSample").value self._compare_workspace(event_slice_output_sample[0], first_slice_output_sample, tolerance=1e-6) self._compare_workspace(event_slice_output_sample[1], second_slice_output_sample, tolerance=1e-6) # LAB can event_slice_output_can = single_reduction_v2_alg.getProperty( "OutputWorkspaceLABCan").value first_slice_output_can = single_reduction_alg_first_slice.getProperty( "OutputWorkspaceLABCan").value second_slice_output_can = single_reduction_alg_second_slice.getProperty( "OutputWorkspaceLABCan").value self._compare_workspace(event_slice_output_can[0], first_slice_output_can, tolerance=1e-6) self._compare_workspace(event_slice_output_can[1], second_slice_output_can, tolerance=1e-6)
def test_that_single_reduction_evaluates_merged(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_can_scatter("SANS2D00034481") data_builder.set_can_transmission("SANS2D00034502") data_builder.set_can_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_info = data_builder.build() # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_file) state = user_file_director.get_all_states() state.reduction.reduction_mode = ReductionMode.MERGED state.reduction.merge_fit_mode = FitModeForMerge.BOTH state.reduction.merge_scale = 1.0 state.reduction.merge_shift = 0.0 state.compatibility.use_compatibility_mode = True # Load the sample workspaces sample, sample_monitor, transmission_workspace, direct_workspace, \ can, can_monitor, can_transmission, can_direct = self._load_workspace(state) # noqa # Act output_settings = {"OutputWorkspaceMerged": EMPTY_NAME} single_reduction_alg = self._run_single_reduction( state, sample_scatter=sample, sample_transmission=transmission_workspace, sample_direct=direct_workspace, sample_monitor=sample_monitor, can_scatter=can, can_monitor=can_monitor, can_transmission=can_transmission, can_direct=can_direct, output_settings=output_settings) output_workspace = single_reduction_alg.getProperty( "OutputWorkspaceMerged").value output_scale_factor = single_reduction_alg.getProperty( "OutScaleFactor").value output_shift_factor = single_reduction_alg.getProperty( "OutShiftFactor").value tolerance = 1e-6 expected_shift = 0.00278452 expected_scale = 0.81439154 self.assertTrue(abs(expected_shift - output_shift_factor) < tolerance) self.assertTrue(abs(expected_scale - output_scale_factor) < tolerance) # Compare the output of the reduction with the reference reference_file_name = "SANS2D_ws_D20_reference_Merged_1D.nxs" self._compare_to_reference(output_workspace, reference_file_name)
def test_that_single_reduction_evaluates_LAB(self): # Arrange # Build the data information file_information_factory = SANSFileInformationFactory() file_information = file_information_factory.create_sans_file_information( "SANS2D00034484") data_builder = get_data_builder(SANSFacility.ISIS, file_information) data_builder.set_sample_scatter("SANS2D00034484") data_builder.set_sample_transmission("SANS2D00034505") data_builder.set_sample_direct("SANS2D00034461") data_builder.set_can_scatter("SANS2D00034481") data_builder.set_can_transmission("SANS2D00034502") data_builder.set_can_direct("SANS2D00034461") data_builder.set_calibration("TUBE_SANS2D_BOTH_31681_25Sept15.nxs") data_info = data_builder.build() # Get the rest of the state from the user file user_file = "USER_SANS2D_154E_2p4_4m_M3_Xpress_8mm_SampleChanger.txt" user_file_director = StateBuilder.new_instance( file_information=file_information, data_information=data_info, user_filename=user_file) state = user_file_director.get_all_states() # Set the reduction mode to LAB state.reduction.reduction_mode = ReductionMode.LAB # Since we are dealing with event based data but we want to compare it with histogram data from the # old reduction system we need to enable the compatibility mode state.compatibility.use_compatibility_mode = True # Load the sample workspaces sample, sample_monitor, transmission_workspace, direct_workspace, can, can_monitor, \ can_transmission, can_direct = self._load_workspace(state) # noqa # Act output_settings = {"OutputWorkspaceLAB": EMPTY_NAME} single_reduction_alg = self._run_single_reduction( state, sample_scatter=sample, sample_transmission=transmission_workspace, sample_direct=direct_workspace, sample_monitor=sample_monitor, can_scatter=can, can_monitor=can_monitor, can_transmission=can_transmission, can_direct=can_direct, output_settings=output_settings) output_workspace = single_reduction_alg.getProperty( "OutputWorkspaceLAB").value calculated_transmission = single_reduction_alg.getProperty( "OutputWorkspaceCalculatedTransmission").value unfitted_transmission = single_reduction_alg.getProperty( "OutputWorkspaceUnfittedTransmission").value calculated_transmission_can = single_reduction_alg.getProperty( "OutputWorkspaceCalculatedTransmissionCan").value unfitted_transmission_can = single_reduction_alg.getProperty( "OutputWorkspaceUnfittedTransmissionCan").value # Compare the output of the reduction with the reference reference_file_name = "SANS2D_ws_D20_reference_LAB_1D.nxs" self._compare_to_reference(output_workspace, reference_file_name) calculated_transmission_reference_file = "SANS2D_ws_D20_calculated_transmission_reference_LAB.nxs" unfitted_transmission_reference_file = "SANS2D_ws_D20_unfitted_transmission_reference_LAB.nxs" calculated_transmission_reference_file_can = "SANS2D_ws_D20_calculated_transmission_reference_LAB_can.nxs" unfitted_transmission_reference_file_can = "SANS2D_ws_D20_unfitted_transmission_reference_LAB_can.nxs" self._compare_to_reference(calculated_transmission, calculated_transmission_reference_file, check_spectra_map=False) self._compare_to_reference(unfitted_transmission, unfitted_transmission_reference_file) self._compare_to_reference(calculated_transmission_can, calculated_transmission_reference_file_can, check_spectra_map=False) self._compare_to_reference(unfitted_transmission_can, unfitted_transmission_reference_file_can)