def _set_adjustment_file_setting(self, element_id, detector_type, file_path): # Check if we already have items for the particular detector type settings_with_correct_detector = [] settings = [] if element_id in self._user_file_items: settings = self._user_file_items[element_id] settings_with_correct_detector = [ setting for setting in settings if setting.detector_type is detector_type ] if not (settings and settings_with_correct_detector): settings.append( monitor_file(file_path="", detector_type=detector_type)) # At this point we have settings with the desired detector type new_settings = [] for setting in settings: if setting.detector_type is detector_type: new_settings.append( monitor_file(file_path=file_path, detector_type=setting.detector_type)) else: new_settings.append(setting) self._user_file_items.update({element_id: new_settings})
def _process_wavelength_correction_file(self, command): file_path = command.values[0] detector_type = command.values[1] new_state_entries = { MonId.DIRECT: monitor_file(file_path=file_path, detector_type=detector_type) } self.add_to_processed_state_settings(new_state_entries)
def _process_flood_file(self, command): file_path = command.values[0] detector_type = command.values[1] new_state_entries = { MonId.FLAT: monitor_file(file_path=file_path, detector_type=detector_type) } self.add_to_processed_state_settings(new_state_entries)
def _set_adjustment_file_setting(self, element_id, detector_type, file_path): # Check if we already have items for the particular detector type settings_with_correct_detector = [] settings = [] if element_id in self._user_file_items: settings = self._user_file_items[element_id] settings_with_correct_detector = [setting for setting in settings if setting.detector_type is detector_type] if not (settings and settings_with_correct_detector): settings.append(monitor_file(file_path="", detector_type=detector_type)) # At this point we have settings with the desired detector type new_settings = [] for setting in settings: if setting.detector_type is detector_type: new_settings.append(monitor_file(file_path=file_path, detector_type=setting.detector_type)) else: new_settings.append(setting) self._user_file_items.update({element_id: new_settings})
def test_that_can_read_user_file(self): # Arrange user_file_path = create_user_file(sample_user_file) reader = UserFileReader(user_file_path) # Act output = reader.read_user_file() # Assert expected_values = {LimitsId.wavelength: [simple_range(start=1.5, stop=12.5, step=0.125, step_type=RangeStepType.Lin)], LimitsId.q: [q_rebin_values(min=.001, max=.2, rebin_string="0.001,0.001,0.0126,-0.08,0.2")], LimitsId.qxy: [simple_range(0, 0.05, 0.001, RangeStepType.Lin)], BackId.single_monitors: [back_single_monitor_entry(1, 35000, 65000), back_single_monitor_entry(2, 85000, 98000)], DetectorId.reduction_mode: [ISISReductionMode.LAB], GravityId.on_off: [True], FitId.general: [fit_general(start=1.5, stop=12.5, fit_type=FitType.Logarithmic, data_type=None, polynomial_order=0)], MaskId.vertical_single_strip_mask: [single_entry_with_detector(191, DetectorType.LAB), single_entry_with_detector(191, DetectorType.HAB), single_entry_with_detector(0, DetectorType.LAB), single_entry_with_detector(0, DetectorType.HAB)], MaskId.horizontal_single_strip_mask: [single_entry_with_detector(0, DetectorType.LAB), single_entry_with_detector(0, DetectorType.HAB)], MaskId.horizontal_range_strip_mask: [range_entry_with_detector(190, 191, DetectorType.LAB), range_entry_with_detector(167, 172, DetectorType.LAB), range_entry_with_detector(190, 191, DetectorType.HAB), range_entry_with_detector(156, 159, DetectorType.HAB) ], MaskId.time: [range_entry_with_detector(17500, 22000, None)], MonId.direct: [monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.LAB), monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.HAB)], MonId.spectrum: [monitor_spectrum(1, True, True), monitor_spectrum(1, False, True)], SetId.centre: [position_entry(155.45, -169.6, DetectorType.LAB)], SetId.scales: [set_scales_entry(0.074, 1.0, 1.0, 1.0, 1.0)], SampleId.offset: [53.0], DetectorId.correction_x: [single_entry_with_detector(-16.0, DetectorType.LAB), single_entry_with_detector(-44.0, DetectorType.HAB)], DetectorId.correction_y: [single_entry_with_detector(-20.0, DetectorType.HAB)], DetectorId.correction_z: [single_entry_with_detector(47.0, DetectorType.LAB), single_entry_with_detector(47.0, DetectorType.HAB)], DetectorId.correction_rotation: [single_entry_with_detector(0.0, DetectorType.HAB)], LimitsId.events_binning: ["7000.0,500.0,60000.0"], MaskId.clear_detector_mask: [True], MaskId.clear_time_mask: [True], LimitsId.radius: [range_entry(12, 15)], TransId.spec_shift: [-70.], PrintId.print_line: ["for changer"], BackId.all_monitors: [range_entry(start=3500, stop=4500)], FitId.monitor_times: [range_entry(start=1000, stop=2000)], TransId.spec: [4], BackId.trans: [range_entry(start=123, stop=466)], TransId.radius: [7.0], TransId.roi: ["test.xml", "test2.xml"], TransId.mask: ["test3.xml", "test4.xml"], SampleId.path: [True], LimitsId.radius_cut: [200.0], LimitsId.wavelength_cut: [8.0], QResolutionId.on: [True], QResolutionId.delta_r: [11.], QResolutionId.collimation_length: [12.], QResolutionId.a1: [13.], QResolutionId.a2: [14.], QResolutionId.moderator: ["moderator_rkh_file.txt"], TubeCalibrationFileId.file: ["TUBE_SANS2D_BOTH_31681_25Sept15.nxs"]} self.assertEqual(len(expected_values), len(output)) for key, value in list(expected_values.items()): self.assertTrue(key in output) self.assertEqual(len(output[key]), len(value)) elements = output[key] # Make sure that the different entries are sorted UserFileReaderTest._sort_list(elements) UserFileReaderTest._sort_list(value) self.assertEqual(elements, value, "{} is not {}".format(elements, value)) # clean up if os.path.exists(user_file_path): os.remove(user_file_path)
def test_that_can_read_user_file(self): # Arrange user_file_path = create_user_file(sample_user_file) reader = UserFileReader(user_file_path) # Act output = reader.read_user_file() # Assert expected_values = { LimitsId.wavelength: [ simple_range(start=1.5, stop=12.5, step=0.125, step_type=RangeStepType.Lin) ], LimitsId.q: [ q_rebin_values(min=.001, max=.2, rebin_string="0.001,0.001,0.0126,-0.08,0.2") ], LimitsId.qxy: [simple_range(0, 0.05, 0.001, RangeStepType.Lin)], BackId.single_monitors: [ back_single_monitor_entry(1, 35000, 65000), back_single_monitor_entry(2, 85000, 98000) ], DetectorId.reduction_mode: [ISISReductionMode.LAB], GravityId.on_off: [True], FitId.general: [ fit_general(start=1.5, stop=12.5, fit_type=FitType.Logarithmic, data_type=None, polynomial_order=0) ], MaskId.vertical_single_strip_mask: [ single_entry_with_detector(191, DetectorType.LAB), single_entry_with_detector(191, DetectorType.HAB), single_entry_with_detector(0, DetectorType.LAB), single_entry_with_detector(0, DetectorType.HAB) ], MaskId.horizontal_single_strip_mask: [ single_entry_with_detector(0, DetectorType.LAB), single_entry_with_detector(0, DetectorType.HAB) ], MaskId.horizontal_range_strip_mask: [ range_entry_with_detector(190, 191, DetectorType.LAB), range_entry_with_detector(167, 172, DetectorType.LAB), range_entry_with_detector(190, 191, DetectorType.HAB), range_entry_with_detector(156, 159, DetectorType.HAB) ], MaskId.time: [range_entry_with_detector(17500, 22000, None)], MonId.direct: [ monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.LAB), monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.HAB) ], MonId.spectrum: [ monitor_spectrum(1, True, True), monitor_spectrum(1, False, True) ], SetId.centre: [position_entry(155.45, -169.6, DetectorType.LAB)], SetId.scales: [set_scales_entry(0.074, 1.0, 1.0, 1.0, 1.0)], SampleId.offset: [53.0], DetectorId.correction_x: [ single_entry_with_detector(-16.0, DetectorType.LAB), single_entry_with_detector(-44.0, DetectorType.HAB) ], DetectorId.correction_y: [single_entry_with_detector(-20.0, DetectorType.HAB)], DetectorId.correction_z: [ single_entry_with_detector(47.0, DetectorType.LAB), single_entry_with_detector(47.0, DetectorType.HAB) ], DetectorId.correction_rotation: [single_entry_with_detector(0.0, DetectorType.HAB)], LimitsId.events_binning: ["7000.0,500.0,60000.0"], MaskId.clear_detector_mask: [True], MaskId.clear_time_mask: [True], LimitsId.radius: [range_entry(12, 15)], TransId.spec_shift: [-70.], PrintId.print_line: ["for changer"], BackId.all_monitors: [range_entry(start=3500, stop=4500)], FitId.monitor_times: [range_entry(start=1000, stop=2000)], TransId.spec: [4], BackId.trans: [range_entry(start=123, stop=466)], TransId.radius: [7.0], TransId.roi: ["test.xml", "test2.xml"], TransId.mask: ["test3.xml", "test4.xml"], SampleId.path: [True], LimitsId.radius_cut: [200.0], LimitsId.wavelength_cut: [8.0], QResolutionId.on: [True], QResolutionId.delta_r: [11.], QResolutionId.collimation_length: [12.], QResolutionId.a1: [13.], QResolutionId.a2: [14.], QResolutionId.moderator: ["moderator_rkh_file.txt"], TubeCalibrationFileId.file: ["TUBE_SANS2D_BOTH_31681_25Sept15.nxs"] } self.assertTrue(len(expected_values) == len(output)) for key, value in list(expected_values.items()): self.assertTrue(key in output) self.assertTrue(len(output[key]) == len(value)) elements = output[key] # Make sure that the different entries are sorted UserFileReaderTest._sort_list(elements) UserFileReaderTest._sort_list(value) self.assertTrue(elements == value) # clean up if os.path.exists(user_file_path): os.remove(user_file_path)
def _process_wavelength_correction_file(self, command): file_path = command.values[0] detector_type = command.values[1] new_state_entries = {MonId.direct: monitor_file(file_path=file_path, detector_type=detector_type)} self.add_to_processed_state_settings(new_state_entries)
def _process_flood_file(self, command): file_path = command.values[0] detector_type = command.values[1] new_state_entries = {MonId.flat: monitor_file(file_path=file_path, detector_type=detector_type)} self.add_to_processed_state_settings(new_state_entries)
def test_that_can_read_user_file(self): # Arrange user_file_path = create_user_file(sample_user_file) reader = UserFileReader(user_file_path) # Act output = reader.read_user_file() # Assert expected_values = { LimitsId.WAVELENGTH: [ simple_range(start=1.5, stop=12.5, step=0.125, step_type=RangeStepType.LIN) ], LimitsId.Q: [ q_rebin_values(min=.001, max=.2, rebin_string="0.001,0.001,0.0126,-0.08,0.2") ], LimitsId.QXY: [simple_range(0, 0.05, 0.001, RangeStepType.LIN)], BackId.SINGLE_MONITORS: [ back_single_monitor_entry(1, 35000, 65000), back_single_monitor_entry(2, 85000, 98000) ], DetectorId.REDUCTION_MODE: [ReductionMode.LAB], GravityId.ON_OFF: [True], FitId.GENERAL: [ fit_general(start=1.5, stop=12.5, fit_type=FitType.LOGARITHMIC, data_type=None, polynomial_order=0) ], MaskId.VERTICAL_SINGLE_STRIP_MASK: [ single_entry_with_detector(191, DetectorType.LAB), single_entry_with_detector(191, DetectorType.HAB), single_entry_with_detector(0, DetectorType.LAB), single_entry_with_detector(0, DetectorType.HAB) ], MaskId.HORIZONTAL_SINGLE_STRIP_MASK: [ single_entry_with_detector(0, DetectorType.LAB), single_entry_with_detector(0, DetectorType.HAB) ], MaskId.HORIZONTAL_RANGE_STRIP_MASK: [ range_entry_with_detector(190, 191, DetectorType.LAB), range_entry_with_detector(167, 172, DetectorType.LAB), range_entry_with_detector(190, 191, DetectorType.HAB), range_entry_with_detector(156, 159, DetectorType.HAB) ], MaskId.TIME: [range_entry_with_detector(17500, 22000, None)], MonId.DIRECT: [ monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.LAB), monitor_file("DIRECTM1_15785_12m_31Oct12_v12.dat", DetectorType.HAB) ], MonId.SPECTRUM: [ monitor_spectrum(1, True, True), monitor_spectrum(1, False, True) ], SetId.CENTRE: [position_entry(155.45, -169.6, DetectorType.LAB)], SetId.SCALES: [set_scales_entry(0.074, 1.0, 1.0, 1.0, 1.0)], SampleId.OFFSET: [53.0], DetectorId.CORRECTION_X: [ single_entry_with_detector(-16.0, DetectorType.LAB), single_entry_with_detector(-44.0, DetectorType.HAB) ], DetectorId.CORRECTION_Y: [single_entry_with_detector(-20.0, DetectorType.HAB)], DetectorId.CORRECTION_Z: [ single_entry_with_detector(47.0, DetectorType.LAB), single_entry_with_detector(47.0, DetectorType.HAB) ], DetectorId.CORRECTION_ROTATION: [single_entry_with_detector(0.0, DetectorType.HAB)], LimitsId.EVENTS_BINNING: ["7000.0,500.0,60000.0"], MaskId.CLEAR_DETECTOR_MASK: [True], MaskId.CLEAR_TIME_MASK: [True], LimitsId.RADIUS: [range_entry(12, 15)], TransId.SPEC_4_SHIFT: [-70.], PrintId.PRINT_LINE: ["for changer"], BackId.ALL_MONITORS: [range_entry(start=3500, stop=4500)], FitId.MONITOR_TIMES: [range_entry(start=1000, stop=2000)], TransId.SPEC: [4], BackId.TRANS: [range_entry(start=123, stop=466)], TransId.RADIUS: [7.0], TransId.ROI: ["test.xml", "test2.xml"], TransId.MASK: ["test3.xml", "test4.xml"], SampleId.PATH: [True], LimitsId.RADIUS_CUT: [200.0], LimitsId.WAVELENGTH_CUT: [8.0], QResolutionId.ON: [True], QResolutionId.DELTA_R: [11.], QResolutionId.COLLIMATION_LENGTH: [12.], QResolutionId.A1: [13.], QResolutionId.A2: [14.], QResolutionId.MODERATOR: ["moderator_rkh_file.txt"], TubeCalibrationFileId.FILE: ["TUBE_SANS2D_BOTH_31681_25Sept15.nxs"] } self.assertEqual(len(expected_values), len(output)) for key, value in list(expected_values.items()): self.assertTrue(key in output) self.assertEqual(len(output[key]), len(value)) elements = output[key] # Make sure that the different entries are sorted UserFileReaderTest._sort_list(elements) UserFileReaderTest._sort_list(value) self.assertEqual(elements, value, "{} is not {}".format(elements, value)) # clean up if os.path.exists(user_file_path): os.remove(user_file_path)