def delete_by_range(start, end): # Init returnValue = True # Execution PressureModel.delte_by_range(start, end) HumidityModel.delte_by_range(start, end) CO2Model.delete_by_range(start, end) TemperatureModel.delete_by_range(start, end) # Clean and return return returnValue
def delete_all(): # Init returnValue = True # Execution PressureModel.delete_all() HumidityModel.delete_all() CO2Model.delete_all() TemperatureModel.delete_all() # Clean and return return returnValue
def test_saving_and_loading_a_complete_setting(self): setting_filename = os.path.join(unittest_files_path, 'complete.trs') temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement.spe')) self.model.load_us_calibration_image( os.path.join(temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image( os.path.join(temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.load_ds_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.set_ds_calibration_temperature(2500) self.model.set_us_calibration_temperature(2300) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from( x_limits_wavelength) ds_roi_limits = [x_limits_ind[0], x_limits_ind[1], 152, 163] us_roi_limits = [x_limits_ind[0], x_limits_ind[1], 99, 110] self.model.set_rois(ds_roi_limits, us_roi_limits) self.model.save_setting(setting_filename) self.model2 = TemperatureModel() self.model2.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement.spe')) self.model2.load_setting(setting_filename) print self.model.ds_roi.as_list() print self.model2.ds_roi.as_list() self.assertEqual(self.model.ds_temperature, self.model2.ds_temperature) self.assertEqual(self.model.us_temperature, self.model2.us_temperature)
def test_saving_and_loading_a_complete_setting(self): setting_filename = os.path.join(unittest_files_path, 'complete.trs') temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement.spe')) self.model.load_us_calibration_image(os.path.join( temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image(os.path.join( temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.load_ds_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.set_ds_calibration_temperature(2500) self.model.set_us_calibration_temperature(2300) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from(x_limits_wavelength) ds_roi_limits = [x_limits_ind[0], x_limits_ind[1], 152, 163] us_roi_limits = [x_limits_ind[0], x_limits_ind[1], 99, 110] self.model.set_rois(ds_roi_limits, us_roi_limits) self.model.save_setting(setting_filename) self.model2 = TemperatureModel() self.model2.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement.spe')) self.model2.load_setting(setting_filename) print self.model.ds_roi.as_list() print self.model2.ds_roi.as_list() self.assertEqual(self.model.ds_temperature, self.model2.ds_temperature) self.assertEqual(self.model.us_temperature, self.model2.us_temperature)
def to_average_json(self): logging.debug("Formatting SensorModel to average json") json = { 'type': 'All sensor average', 'attributes': { 'pressure': PressureModel.average_json(self.pressures), 'humidity': HumidityModel.average_json(self.humidities), 'co2': CO2Model.average_json(self.co2), 'temperature': TemperatureModel.average_json(self.temperatures) } } return json
def get_all(): # init foundPressure = [] foundHumidities = [] foundCo2 = [] foundTemperatures = [] # Execution (4 connection, could be more effecient but query time is hardly an issue) foundPressure = PressureModel.get_all() foundHumidities = HumidityModel.get_all() foundCo2 = CO2Model.get_all() foundTemperatures = TemperatureModel.get_all() # Build object returnObj = SensorModel(foundPressure, foundHumidities, foundCo2, foundTemperatures) # Clean and return return returnObj
def get_average_by_range(start, end): # init foundPressure = None foundHumidities = None foundCo2 = None foundTemperatures = None # Execution (4 connection, could be more effecient but query time is hardly an issue) foundPressure = PressureModel.get_average_by_range(start, end) foundHumidities = HumidityModel.get_average_by_range(start, end) foundCo2 = CO2Model.get_average_by_range(start, end) foundTemperatures = TemperatureModel.get_average_by_range(start, end) # Build object returnObj = SensorModel(foundPressure, foundHumidities, foundCo2, foundTemperatures) # Clean and return return returnObj
def setUp(self): self.app = QtGui.QApplication([]) self.model = TemperatureModel()
class TestTemperatureModel(unittest.TestCase): def setUp(self): self.app = QtGui.QApplication([]) self.model = TemperatureModel() def tearDown(self): del self.app def array_almost_equal(self, array1, array2): self.assertAlmostEqual(np.sum(array1 - array2), 0) def array_not_almost_equal(self, array1, array2): self.assertNotAlmostEqual(np.sum(array1 - array2), 0) def spectrum_almost_equal(self, spectrum1, spectrum2): x1, y1 = spectrum1.data x2, y2 = spectrum2.data self.array_almost_equal(x1, x2) self.array_almost_equal(y1, y2) def spectrum_not_almost_equal(self, spectrum1, spectrum2): x1, y1 = spectrum1.data x2, y2 = spectrum2.data self.array_almost_equal(x1, x2) self.array_not_almost_equal(y1, y2) def test_file_browsing(self): self.model.load_data_image(os.path.join(unittest_files_path, 'temper_009.spe')) us_data_x_1, us_data_y_1 = self.model.us_data_spectrum.data ds_data_x_1, ds_data_y_1 = self.model.ds_data_spectrum.data self.model.load_next_data_image() us_data_x_2, us_data_y_2 = self.model.us_data_spectrum.data ds_data_x_2, ds_data_y_2 = self.model.ds_data_spectrum.data self.array_almost_equal(us_data_x_1, us_data_x_2) self.array_almost_equal(ds_data_x_1, ds_data_x_2) self.array_not_almost_equal(ds_data_y_1, ds_data_y_2) self.array_not_almost_equal(us_data_y_1, us_data_y_2) self.model.load_previous_data_image() us_data_x_3, us_data_y_3 = self.model.us_data_spectrum.data ds_data_x_3, ds_data_y_3 = self.model.ds_data_spectrum.data self.array_almost_equal(us_data_x_1, us_data_x_3) self.array_almost_equal(ds_data_x_1, ds_data_x_3) self.array_almost_equal(ds_data_y_1, ds_data_y_3) self.array_almost_equal(us_data_y_1, us_data_y_3) def test_loading_data_img_and_retrieve_upstream_and_down_stream_spectrum(self): self.model.load_data_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.assertGreater(len(self.model.us_data_spectrum._x), 0) self.assertGreater(len(self.model.ds_data_spectrum._x), 0) def test_loading_upstream_img_and_retrieve_upstream_spectrum(self): self.model.load_us_calibration_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.assertGreater(len(self.model.us_calibration_spectrum._x), 0) def test_loading_downstream_img_and_retrieve_downstream_spectrum(self): self.model.load_ds_calibration_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.assertGreater(len(self.model.ds_calibration_spectrum._x), 0) def test_loading_images_for_data_downstream_and_upstream_all_should_be_different(self): self.model.load_data_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image(os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image(os.path.join(unittest_files_path, 'temper_010.spe')) us_data_x, us_data_y = self.model.us_data_spectrum.data ds_data_x, ds_data_y = self.model.ds_data_spectrum.data us_calibration_x, us_calibration_y = self.model.us_calibration_spectrum.data ds_calibration_x, ds_calibration_y = self.model.ds_calibration_spectrum.data self.array_not_almost_equal(us_data_y, ds_data_y) self.array_not_almost_equal(us_data_y, us_calibration_y) self.array_not_almost_equal(us_data_y, ds_calibration_y) self.array_not_almost_equal(ds_data_y, us_calibration_y) self.array_not_almost_equal(ds_data_y, ds_calibration_y) self.array_not_almost_equal(us_calibration_y, ds_calibration_y) def test_changing_us_roi_values(self): self.model.load_data_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image(os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image(os.path.join(unittest_files_path, 'temper_010.spe')) _, us_data_y = self.model.us_data_spectrum.data _, us_calibration_y = self.model.us_calibration_spectrum.data self.model.us_roi = [123, 900, 30, 50] _, after_us_data_y = self.model.us_data_spectrum.data _, after_us_calibration_y = self.model.us_calibration_spectrum.data self.assertNotEqual(len(us_data_y), len(after_us_data_y)) self.assertNotEqual(len(us_calibration_y), len(after_us_calibration_y)) self.assertEqual(len(after_us_data_y), len(after_us_calibration_y)) def test_changing_ds_roi_values(self): self.model.load_data_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image(os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image(os.path.join(unittest_files_path, 'temper_010.spe')) _, ds_data_y = self.model.ds_data_spectrum.data _, ds_calibration_y = self.model.ds_calibration_spectrum.data self.model.ds_roi = [123, 900, 30, 50] _, after_ds_data_y = self.model.ds_data_spectrum.data _, after_ds_calibration_y = self.model.ds_calibration_spectrum.data self.assertNotEqual(len(ds_data_y), len(after_ds_data_y)) self.assertNotEqual(len(ds_calibration_y), len(after_ds_calibration_y)) def test_changing_aggregate_roi_values(self): self.model.load_data_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image(os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image(os.path.join(unittest_files_path, 'temper_010.spe')) _, us_data_y = self.model.us_data_spectrum.data _, ds_data_y = self.model.ds_data_spectrum.data _, us_calibration_y = self.model.us_calibration_spectrum.data _, ds_calibration_y = self.model.ds_calibration_spectrum.data self.model.set_rois([123, 500, 30, 40], [123, 500, 60, 90]) _, after_us_data_y = self.model.us_data_spectrum.data _, after_ds_data_y = self.model.ds_data_spectrum.data _, after_us_calibration_y = self.model.us_calibration_spectrum.data _, after_ds_calibration_y = self.model.ds_calibration_spectrum.data self.assertNotEqual(len(us_data_y), len(after_us_data_y)) self.assertNotEqual(len(ds_data_y), len(after_ds_data_y)) self.assertNotEqual(len(us_calibration_y), len(after_us_calibration_y)) self.assertNotEqual(len(ds_calibration_y), len(after_ds_calibration_y)) self.assertEqual(len(after_us_data_y), len(after_ds_data_y)) self.assertEqual(len(after_us_data_y), len(after_ds_calibration_y)) self.assertEqual(len(after_us_data_y), len(after_us_calibration_y)) def test_changing_the_sum_with_roi_settings(self): self.model.load_data_image(os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image(os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image(os.path.join(unittest_files_path, 'temper_010.spe')) self.model.set_rois([123, 500, 30, 40], [123, 500, 60, 90]) _, us_data_y = self.model.us_data_spectrum.data _, ds_data_y = self.model.ds_data_spectrum.data _, us_calibration_y = self.model.us_calibration_spectrum.data _, ds_calibration_y = self.model.ds_calibration_spectrum.data _, us_corrected_y = self.model.us_corrected_spectrum.data _, ds_corrected_y = self.model.ds_corrected_spectrum.data self.model.set_rois([123, 500, 30, 50], [123, 500, 55, 120]) _, after_us_data_y = self.model.us_data_spectrum.data _, after_ds_data_y = self.model.ds_data_spectrum.data _, after_us_calibration_y = self.model.us_calibration_spectrum.data _, after_ds_calibration_y = self.model.ds_calibration_spectrum.data _, after_us_corrected_y = self.model.us_corrected_spectrum.data _, after_ds_corrected_y = self.model.ds_corrected_spectrum.data self.array_not_almost_equal(us_data_y, after_us_data_y) self.array_not_almost_equal(ds_data_y, after_ds_data_y) self.array_not_almost_equal(us_calibration_y, after_us_calibration_y) self.array_not_almost_equal(ds_calibration_y, after_ds_calibration_y) self.array_not_almost_equal(us_corrected_y, after_us_corrected_y) self.array_not_almost_equal(ds_corrected_y, after_ds_corrected_y) def test_fitting_temperature(self): # loading files self.load_single_frame_file_and_calibration() self.assertEqual(np.round(self.model.ds_temperature), 1047) self.assertEqual(np.round(self.model.us_temperature), 1414) def test_multiple_frame_spe_file(self): temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement_multiple.spe')) self.assertGreater(len(self.model.us_data_spectrum), 0) self.assertGreater(len(self.model.ds_data_spectrum), 0) _, us_y = self.model.us_data_spectrum.data _, ds_y = self.model.ds_data_spectrum.data self.model.load_next_img_frame() _, us_y_1 = self.model.us_data_spectrum.data _, ds_y_1 = self.model.ds_data_spectrum.data self.array_not_almost_equal(us_y, us_y_1) self.array_not_almost_equal(ds_y, ds_y_1) self.model.load_previous_img_frame() _, us_y_2 = self.model.us_data_spectrum.data _, ds_y_2 = self.model.ds_data_spectrum.data self.array_almost_equal(us_y, us_y_2) self.array_almost_equal(ds_y, ds_y_2) def test_multiple_frame_spe_file_on_limits(self): temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement_multiple.spe')) _, us_y = self.model.us_data_spectrum.data _, ds_y = self.model.ds_data_spectrum.data self.model.load_previous_img_frame() _, us_y_1 = self.model.us_data_spectrum.data _, ds_y_1 = self.model.ds_data_spectrum.data self.array_almost_equal(us_y, us_y_1) self.array_almost_equal(ds_y, ds_y_1) self.assertEqual(self.model.current_frame, 0) self.model.set_img_frame_number_to(9) _, us_y = self.model.us_data_spectrum.data _, ds_y = self.model.ds_data_spectrum.data self.model.load_next_img_frame() _, us_y_1 = self.model.us_data_spectrum.data _, ds_y_1 = self.model.ds_data_spectrum.data self.array_almost_equal(us_y, us_y_1) self.array_almost_equal(ds_y, ds_y_1) self.assertEqual(self.model.current_frame, 9) def test_temperature_fitting_of_multiple_frame_spe_file(self): temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement_multiple.spe')) self.model.load_us_calibration_image(os.path.join( temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image(os.path.join( temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.load_ds_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.set_us_calibration_modus(1) self.model.set_ds_calibration_modus(1) us_temperature1 = self.model.us_temperature ds_temperature1 = self.model.ds_temperature self.model.load_next_img_frame() us_temperature2 = self.model.us_temperature ds_temperature2 = self.model.ds_temperature self.assertNotAlmostEqual(us_temperature1, us_temperature2) self.assertNotAlmostEqual(ds_temperature1, ds_temperature2) def test_batch_fitting_of_multiple_frame_spe_file(self): temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement_multiple.spe')) self.model.load_us_calibration_image(os.path.join( temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image(os.path.join( temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.load_ds_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from(x_limits_wavelength) self.model.set_rois([x_limits_ind[0], x_limits_ind[1], 152, 163], [x_limits_ind[0], x_limits_ind[1], 99, 110]) us_temperature, us_temperature_error, ds_temperature, ds_temperature_error = self.model.fit_all_frames() self.assertEqual(len(us_temperature), 10) self.assertEqual(len(ds_temperature), 10) self.assertEqual(len(us_temperature_error), 10) self.assertEqual(len(ds_temperature_error), 10) self.array_not_almost_equal(np.array(us_temperature), np.array(ds_temperature)) self.array_not_almost_equal(np.array(us_temperature_error), np.array(ds_temperature_error)) def test_saving_and_loading_empty_settings(self): filename = os.path.join(unittest_files_path, 'empty.trs') self.model.save_setting(filename) temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement_multiple.spe')) self.model.load_us_calibration_image(os.path.join( temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image(os.path.join( temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.load_ds_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.set_ds_calibration_temperature(2500) self.model.set_us_calibration_temperature(2300) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) self.model.load_setting(filename) self.assertEqual(self.model.ds_calibration_filename, None) self.assertEqual(self.model.us_calibration_filename, None) self.assertEqual(self.model.ds_temperature_model.calibration_parameter.temperature, 2000) self.assertEqual(self.model.us_temperature_model.calibration_parameter.temperature, 2000) self.assertEqual(self.model.ds_temperature_model.calibration_parameter.modus, 0) self.assertEqual(self.model.us_temperature_model.calibration_parameter.modus, 0) self.assertTrue(self.model.ds_temperature is np.NaN) self.assertTrue(self.model.ds_temperature_error is np.NaN) self.assertTrue(self.model.us_temperature is np.NaN) self.assertTrue(self.model.us_temperature_error is np.NaN) self.assertEqual(self.model.ds_roi.as_list(), [0, 0, 0, 0]) self.assertEqual(self.model.us_roi.as_list(), [0, 0, 0, 0]) def test_saving_and_loading_a_complete_setting(self): setting_filename = os.path.join(unittest_files_path, 'complete.trs') temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement.spe')) self.model.load_us_calibration_image(os.path.join( temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image(os.path.join( temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.load_ds_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.set_ds_calibration_temperature(2500) self.model.set_us_calibration_temperature(2300) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from(x_limits_wavelength) ds_roi_limits = [x_limits_ind[0], x_limits_ind[1], 152, 163] us_roi_limits = [x_limits_ind[0], x_limits_ind[1], 99, 110] self.model.set_rois(ds_roi_limits, us_roi_limits) self.model.save_setting(setting_filename) self.model2 = TemperatureModel() self.model2.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement.spe')) self.model2.load_setting(setting_filename) print self.model.ds_roi.as_list() print self.model2.ds_roi.as_list() self.assertEqual(self.model.ds_temperature, self.model2.ds_temperature) self.assertEqual(self.model.us_temperature, self.model2.us_temperature) def load_single_frame_file_and_calibration(self): temperature_fitting_path = os.path.join( unittest_files_path, 'temperature_fitting') self.model.load_data_image(os.path.join( temperature_fitting_path, 'test_measurement.spe')) self.model.load_us_calibration_image(os.path.join( temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image(os.path.join( temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.load_ds_etalon_spectrum(os.path.join( temperature_fitting_path, '15A_lamp.txt' )) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from(x_limits_wavelength) self.model.set_rois([x_limits_ind[0], x_limits_ind[1], 152, 163], [x_limits_ind[0], x_limits_ind[1], 99, 110]) def test_saving_data_as_text_from_a_single_frame(self): self.load_single_frame_file_and_calibration() out_path = os.path.join(unittest_files_path, 'data.txt') self.model.save_txt(out_path) file = open(out_path) lines = file.readlines() self.assertEqual(lines[0], "# Fitted Temperatures:\n") self.assertEqual(lines[1], "# Downstream (K): 1046.9 14.7\n") self.assertEqual(lines[2], "# Upstream (K): 1413.6 2.1\n") self.assertEqual(lines[3], "# \n") self.assertEqual(lines[4], "# Datacolumns:\n") self.assertEqual(lines[5], "# lambda(nm) DS_data DS_fit US_data US_fit\n") file.close() os.remove(out_path)
def setUp(self): self.app = QtGui.QApplication(sys.argv) self.widget = TemperatureWidget() self.model = TemperatureModel() self.controller = TemperatureController(self.widget, self.model)
class TestTemperatureController(unittest.TestCase): def setUp(self): self.app = QtGui.QApplication(sys.argv) self.widget = TemperatureWidget() self.model = TemperatureModel() self.controller = TemperatureController(self.widget, self.model) def tearDown(self): self.app.closeAllWindows() self.app.quit() del self.app def array_almost_equal(self, array1, array2): self.assertAlmostEqual(np.sum(array1 - array2), 0) def array_not_almost_equal(self, array1, array2): self.assertNotAlmostEqual(np.sum(array1 - array2), 0) def test_gui_to_model_connection(self): self.controller.load_data_file( os.path.join(unittest_files_path, 'temper_009.spe')) self.assertGreater(len(self.model.ds_data_spectrum), 0) self.assertGreater(len(self.model.us_data_spectrum), 0) ds_x, ds_y = self.model.ds_data_spectrum.data us_x, us_y = self.model.us_data_spectrum.data QTest.mouseClick(self.widget.load_next_data_file_btn, QtCore.Qt.LeftButton) ds_x_1, ds_y_1 = self.model.ds_data_spectrum.data us_x_1, us_y_1 = self.model.us_data_spectrum.data self.array_almost_equal(ds_x, ds_x_1) self.array_not_almost_equal(ds_y, ds_y_1) self.array_almost_equal(us_x, us_x_1) self.array_not_almost_equal(us_y, us_y_1) QTest.mouseClick(self.widget.load_previous_data_file_btn, QtCore.Qt.LeftButton) ds_x_2, ds_y_2 = self.model.ds_data_spectrum.data us_x_2, us_y_2 = self.model.us_data_spectrum.data self.array_almost_equal(ds_x, ds_x_2) self.array_almost_equal(ds_y, ds_y_2) self.array_almost_equal(us_x, us_x_2) self.array_almost_equal(us_y, us_y_2) def test_updating_gui_after_loading_single_frame_data(self): filename = os.path.join(temperature_fitting_path, 'test_measurement.spe') self.controller.load_data_file(filename) self.array_almost_equal(self.widget.roi_img_item.image, np.rot90(self.model.data_img)) self.assertEqual(self.widget.roi_widget.get_rois(), self.model.get_roi_data_list()) self.assertEqual(os.path.basename(filename), str(self.widget.filename_lbl.text())) dirname = os.path.sep.join( os.path.dirname(filename).split(os.path.sep)[-2:]) self.assertEqual(dirname, str(self.widget.dirname_lbl.text())) self.assertFalse(self.widget.frame_widget.isVisible()) def test_updating_gui_after_loading_multi_frame_data(self): filename = os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe') self.controller.load_data_file(filename) self.array_almost_equal(self.widget.roi_img_item.image, np.rot90(self.model.data_img)) self.assertEqual(self.widget.roi_widget.get_rois(), self.model.get_roi_data_list()) self.assertEqual(os.path.basename(filename), str(self.widget.filename_lbl.text())) dirname = os.path.sep.join( os.path.dirname(filename).split(os.path.sep)[-2:]) self.assertEqual(dirname, str(self.widget.dirname_lbl.text())) self.assertEqual(1, int(str(self.widget.frame_num_txt.text()))) # browsing frames changes the frame_num_txt QTest.mouseClick(self.widget.load_next_frame_btn, QtCore.Qt.LeftButton) self.assertEqual(2, int(str(self.widget.frame_num_txt.text()))) def test_loading_downstream_calibration_img(self): filename = os.path.join(temperature_fitting_path, 'ds_calibration.spe') self.controller.load_ds_calibration_file(filename) self.assertGreater(len(self.model.ds_calibration_spectrum), 0) self.assertEqual(os.path.basename(filename), str(self.widget.ds_calibration_filename_lbl.text())) def test_loading_upstream_calibration_img(self): filename = os.path.join(temperature_fitting_path, 'us_calibration.spe') self.controller.load_us_calibration_file(filename) self.assertGreater(len(self.model.us_calibration_spectrum), 0) self.assertEqual(os.path.basename(filename), str(self.widget.us_calibration_filename_lbl.text())) def test_downstream_calibration_controls(self): QTest.mouseClick(self.widget.ds_etalon_rb, QtCore.Qt.LeftButton, pos=QtCore.QPoint( 2, self.widget.ds_etalon_rb.height() / 2)) self.assertTrue(self.widget.ds_etalon_rb.isChecked()) self.assertEqual( self.model.ds_temperature_model.calibration_parameter.modus, 1) QTest.mouseClick(self.widget.ds_temperature_rb, QtCore.Qt.LeftButton, pos=QtCore.QPoint( 2, self.widget.ds_etalon_rb.height() / 2)) self.assertEqual( self.model.ds_temperature_model.calibration_parameter.modus, 0) self.widget.ds_temperature_txt.setText('') QTest.keyClicks(self.widget.ds_temperature_txt, '1800') QTest.keyPress(self.widget.ds_temperature_txt, QtCore.Qt.Key_Enter) self.assertEqual( self.model.ds_temperature_model.calibration_parameter.temperature, 1800) filename = os.path.join(temperature_fitting_path, '15A_lamp.txt') self.controller.load_ds_etalon_file(filename) self.assertEqual( self.model.ds_temperature_model.calibration_parameter. etalon_file_name, filename) self.assertEqual(str(self.widget.ds_etalon_filename_lbl.text()), os.path.basename(filename)) def test_upstream_calibration_controls(self): QTest.mouseClick(self.widget.us_etalon_rb, QtCore.Qt.LeftButton, pos=QtCore.QPoint( 2, self.widget.us_etalon_rb.height() / 2)) self.assertTrue(self.widget.us_etalon_rb.isChecked()) self.assertEqual( self.model.us_temperature_model.calibration_parameter.modus, 1) QTest.mouseClick(self.widget.us_temperature_rb, QtCore.Qt.LeftButton, pos=QtCore.QPoint( 2, self.widget.us_etalon_rb.height() / 2)) self.assertEqual( self.model.us_temperature_model.calibration_parameter.modus, 0) self.widget.us_temperature_txt.setText('') QTest.keyClicks(self.widget.us_temperature_txt, '1800') QTest.keyPress(self.widget.us_temperature_txt, QtCore.Qt.Key_Enter) self.assertEqual( self.model.us_temperature_model.calibration_parameter.temperature, 1800) filename = os.path.join(temperature_fitting_path, '15A_lamp.txt') self.controller.load_us_etalon_file(filename) self.assertEqual( self.model.us_temperature_model.calibration_parameter. etalon_file_name, filename) self.assertEqual(str(self.widget.us_etalon_filename_lbl.text()), os.path.basename(filename)) def test_ds_temperature_fitting_is_shown_in_graph(self): data_filename = os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe') calibration_filename = os.path.join(temperature_fitting_path, 'ds_calibration.spe') self.controller.load_data_file(data_filename) self.controller.load_ds_calibration_file(calibration_filename) self.assertNotEqual( self.widget.graph_widget._us_temperature_txt_item.text, u'') self.array_almost_equal( np.array(self.widget.graph_widget._ds_fit_item.getData()), np.array(self.model.ds_fit_spectrum.data)) def test_us_temperature_fitting_is_shown_in_graph(self): data_filename = os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe') calibration_filename = os.path.join(temperature_fitting_path, 'us_calibration.spe') self.controller.load_data_file(data_filename) self.controller.load_us_calibration_file(calibration_filename) self.assertNotEqual( self.widget.graph_widget._us_temperature_txt_item.text, u'') self.array_almost_equal( np.array(self.widget.graph_widget._us_fit_item.getData()), np.array(self.model.us_fit_spectrum.data)) def test_loading_settings(self): self.load_pimax_example_and_setting() self.assertEqual( self.widget.graph_widget._ds_temperature_txt_item.text, '1047 K ± 15') self.assertEqual( self.widget.graph_widget._us_temperature_txt_item.text, '1414 K ± 2') self.assertEqual(self.widget.ds_calibration_filename_lbl.text(), 'ds_calibration.spe') self.assertEqual(self.widget.us_calibration_filename_lbl.text(), 'us_calibration.spe') self.assertEqual(self.widget.ds_etalon_filename_lbl.text(), '15A_lamp.txt') self.assertEqual(self.widget.us_etalon_filename_lbl.text(), '15A_lamp.txt') self.assertEqual(self.widget.ds_temperature_txt.text(), '2500') self.assertEqual(self.widget.us_temperature_txt.text(), '2300') self.assertEqual(self.widget.settings_cb.count(), 1) def load_single_frame_file_and_calibration(self): temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement.spe')) self.model.load_us_calibration_image( os.path.join(temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image( os.path.join(temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.load_ds_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from( x_limits_wavelength) self.model.set_rois([x_limits_ind[0], x_limits_ind[1], 152, 163], [x_limits_ind[0], x_limits_ind[1], 99, 110]) def load_pimax_example_and_setting(self): filename = os.path.join(temperature_fitting_path, 'test_measurement.spe') self.controller.load_data_file(filename) setting_filename = os.path.join(temperature_fitting_path, 'PiMax.trs') self.controller.load_setting_file(setting_filename) @patch('PyQt4.QtGui.QFileDialog.getSaveFileName') def test_saving_data_as_txt(self, filedialog): self.load_single_frame_file_and_calibration() out_path = os.path.join(unittest_files_path, 'data.txt') filedialog.return_value = out_path QTest.mouseClick(self.widget.save_data_btn, QtCore.Qt.LeftButton) self.assertTrue(os.path.exists(out_path)) os.remove(out_path) @patch('PyQt4.QtGui.QFileDialog.getSaveFileName') def test_saving_graph_image(self, filedialog): self.load_single_frame_file_and_calibration() out_path = os.path.join(unittest_files_path, 'data.png') filedialog.return_value = out_path QTest.mouseClick(self.widget.save_graph_btn, QtCore.Qt.LeftButton) self.assertTrue(os.path.exists(out_path)) os.remove(out_path) out_path = os.path.join(unittest_files_path, 'data.svg') filedialog.return_value = out_path QTest.mouseClick(self.widget.save_graph_btn, QtCore.Qt.LeftButton) self.assertTrue(os.path.exists(out_path)) os.remove(out_path) def test_graph_status_bar_shows_file_info(self): self.controller.load_data_file( os.path.join(unittest_files_path, 'temper_009.spe')) self.assertEqual(str(self.widget.graph_info_lbl.text()), self.model.file_info) def test_graph_status_bar_shows_mouse_position(self): self.widget.graph_widget._ds_plot.mouse_moved.emit(102, 104) self.assertIn("102", str(self.widget.graph_mouse_pos_lbl.text())) self.assertIn("104", str(self.widget.graph_mouse_pos_lbl.text())) self.widget.graph_widget._us_plot.mouse_moved.emit(106, 154) self.assertIn("106", str(self.widget.graph_mouse_pos_lbl.text())) self.assertIn("154", str(self.widget.graph_mouse_pos_lbl.text())) self.widget.graph_widget._time_lapse_plot.mouse_moved.emit(200, 300) self.assertIn("200", str(self.widget.graph_mouse_pos_lbl.text())) self.assertIn("300", str(self.widget.graph_mouse_pos_lbl.text())) def test_roi_status_bar_shows_mouse_position_intensity_and_wavelength( self): self.controller.load_data_file( os.path.join(unittest_files_path, 'temper_009.spe')) self.widget.roi_widget.img_widget.mouse_moved.emit(130, 20) self.assertIn("20", self.widget.roi_widget.pos_lbl.text()) self.assertIn("130", self.widget.roi_widget.pos_lbl.text()) self.assertIn("{:.0f}".format(self.model.data_img[20, 130]), self.widget.roi_widget.pos_lbl.text()) self.assertIn( "{:.2f}".format(self.model.data_img_file.x_calibration[130]), self.widget.roi_widget.pos_lbl.text()) def test_pyepics_connection_is_working(self): try: import epics except ImportError: return QTest.mouseClick(self.widget.connect_to_epics_cb, QtCore.Qt.LeftButton, pos=QtCore.QPoint( self.widget.connect_to_epics_cb.width() - 2, self.widget.connect_to_epics_cb.height() / 2)) self.load_pimax_example_and_setting() self.assertAlmostEqual(self.model.ds_temperature, epics.caget('13IDD:ds_las_temp.VAL')) self.assertAlmostEqual(self.model.us_temperature, epics.caget('13IDD:us_las_temp.VAL')) self.assertAlmostEqual(self.model.ds_roi_max, float(epics.caget('13IDD:dn_t_int.VAL'))) self.assertAlmostEqual(self.model.us_roi_max, float(epics.caget('13IDD:up_t_int.VAL'))) self.load_single_frame_file_and_calibration() self.assertAlmostEqual(self.model.ds_temperature, epics.caget('13IDD:ds_las_temp.VAL')) self.assertAlmostEqual(self.model.us_temperature, epics.caget('13IDD:us_las_temp.VAL')) self.assertAlmostEqual(self.model.ds_roi_max, float(epics.caget('13IDD:dn_t_int.VAL'))) self.assertAlmostEqual(self.model.us_roi_max, float(epics.caget('13IDD:up_t_int.VAL')))
def create_data_models(self): self.temperature_model = TemperatureModel() self.ruby_model = RubyModel() self.diamond_model = DiamondModel() self.raman_model = RamanModel()
class TestTemperatureModel(unittest.TestCase): def setUp(self): self.app = QtGui.QApplication([]) self.model = TemperatureModel() def tearDown(self): del self.app def array_almost_equal(self, array1, array2): self.assertAlmostEqual(np.sum(array1 - array2), 0) def array_not_almost_equal(self, array1, array2): self.assertNotAlmostEqual(np.sum(array1 - array2), 0) def spectrum_almost_equal(self, spectrum1, spectrum2): x1, y1 = spectrum1.data x2, y2 = spectrum2.data self.array_almost_equal(x1, x2) self.array_almost_equal(y1, y2) def spectrum_not_almost_equal(self, spectrum1, spectrum2): x1, y1 = spectrum1.data x2, y2 = spectrum2.data self.array_almost_equal(x1, x2) self.array_not_almost_equal(y1, y2) def test_file_browsing(self): self.model.load_data_image( os.path.join(unittest_files_path, 'temper_009.spe')) us_data_x_1, us_data_y_1 = self.model.us_data_spectrum.data ds_data_x_1, ds_data_y_1 = self.model.ds_data_spectrum.data self.model.load_next_data_image() us_data_x_2, us_data_y_2 = self.model.us_data_spectrum.data ds_data_x_2, ds_data_y_2 = self.model.ds_data_spectrum.data self.array_almost_equal(us_data_x_1, us_data_x_2) self.array_almost_equal(ds_data_x_1, ds_data_x_2) self.array_not_almost_equal(ds_data_y_1, ds_data_y_2) self.array_not_almost_equal(us_data_y_1, us_data_y_2) self.model.load_previous_data_image() us_data_x_3, us_data_y_3 = self.model.us_data_spectrum.data ds_data_x_3, ds_data_y_3 = self.model.ds_data_spectrum.data self.array_almost_equal(us_data_x_1, us_data_x_3) self.array_almost_equal(ds_data_x_1, ds_data_x_3) self.array_almost_equal(ds_data_y_1, ds_data_y_3) self.array_almost_equal(us_data_y_1, us_data_y_3) def test_loading_data_img_and_retrieve_upstream_and_down_stream_spectrum( self): self.model.load_data_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.assertGreater(len(self.model.us_data_spectrum._x), 0) self.assertGreater(len(self.model.ds_data_spectrum._x), 0) def test_loading_upstream_img_and_retrieve_upstream_spectrum(self): self.model.load_us_calibration_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.assertGreater(len(self.model.us_calibration_spectrum._x), 0) def test_loading_downstream_img_and_retrieve_downstream_spectrum(self): self.model.load_ds_calibration_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.assertGreater(len(self.model.ds_calibration_spectrum._x), 0) def test_loading_images_for_data_downstream_and_upstream_all_should_be_different( self): self.model.load_data_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image( os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image( os.path.join(unittest_files_path, 'temper_010.spe')) us_data_x, us_data_y = self.model.us_data_spectrum.data ds_data_x, ds_data_y = self.model.ds_data_spectrum.data us_calibration_x, us_calibration_y = self.model.us_calibration_spectrum.data ds_calibration_x, ds_calibration_y = self.model.ds_calibration_spectrum.data self.array_not_almost_equal(us_data_y, ds_data_y) self.array_not_almost_equal(us_data_y, us_calibration_y) self.array_not_almost_equal(us_data_y, ds_calibration_y) self.array_not_almost_equal(ds_data_y, us_calibration_y) self.array_not_almost_equal(ds_data_y, ds_calibration_y) self.array_not_almost_equal(us_calibration_y, ds_calibration_y) def test_changing_us_roi_values(self): self.model.load_data_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image( os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image( os.path.join(unittest_files_path, 'temper_010.spe')) _, us_data_y = self.model.us_data_spectrum.data _, us_calibration_y = self.model.us_calibration_spectrum.data self.model.us_roi = [123, 900, 30, 50] _, after_us_data_y = self.model.us_data_spectrum.data _, after_us_calibration_y = self.model.us_calibration_spectrum.data self.assertNotEqual(len(us_data_y), len(after_us_data_y)) self.assertNotEqual(len(us_calibration_y), len(after_us_calibration_y)) self.assertEqual(len(after_us_data_y), len(after_us_calibration_y)) def test_changing_ds_roi_values(self): self.model.load_data_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image( os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image( os.path.join(unittest_files_path, 'temper_010.spe')) _, ds_data_y = self.model.ds_data_spectrum.data _, ds_calibration_y = self.model.ds_calibration_spectrum.data self.model.ds_roi = [123, 900, 30, 50] _, after_ds_data_y = self.model.ds_data_spectrum.data _, after_ds_calibration_y = self.model.ds_calibration_spectrum.data self.assertNotEqual(len(ds_data_y), len(after_ds_data_y)) self.assertNotEqual(len(ds_calibration_y), len(after_ds_calibration_y)) def test_changing_aggregate_roi_values(self): self.model.load_data_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image( os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image( os.path.join(unittest_files_path, 'temper_010.spe')) _, us_data_y = self.model.us_data_spectrum.data _, ds_data_y = self.model.ds_data_spectrum.data _, us_calibration_y = self.model.us_calibration_spectrum.data _, ds_calibration_y = self.model.ds_calibration_spectrum.data self.model.set_rois([123, 500, 30, 40], [123, 500, 60, 90]) _, after_us_data_y = self.model.us_data_spectrum.data _, after_ds_data_y = self.model.ds_data_spectrum.data _, after_us_calibration_y = self.model.us_calibration_spectrum.data _, after_ds_calibration_y = self.model.ds_calibration_spectrum.data self.assertNotEqual(len(us_data_y), len(after_us_data_y)) self.assertNotEqual(len(ds_data_y), len(after_ds_data_y)) self.assertNotEqual(len(us_calibration_y), len(after_us_calibration_y)) self.assertNotEqual(len(ds_calibration_y), len(after_ds_calibration_y)) self.assertEqual(len(after_us_data_y), len(after_ds_data_y)) self.assertEqual(len(after_us_data_y), len(after_ds_calibration_y)) self.assertEqual(len(after_us_data_y), len(after_us_calibration_y)) def test_changing_the_sum_with_roi_settings(self): self.model.load_data_image( os.path.join(unittest_files_path, 'temper_009.spe')) self.model.load_us_calibration_image( os.path.join(unittest_files_path, 'temper_011.spe')) self.model.load_ds_calibration_image( os.path.join(unittest_files_path, 'temper_010.spe')) self.model.set_rois([123, 500, 30, 40], [123, 500, 60, 90]) _, us_data_y = self.model.us_data_spectrum.data _, ds_data_y = self.model.ds_data_spectrum.data _, us_calibration_y = self.model.us_calibration_spectrum.data _, ds_calibration_y = self.model.ds_calibration_spectrum.data _, us_corrected_y = self.model.us_corrected_spectrum.data _, ds_corrected_y = self.model.ds_corrected_spectrum.data self.model.set_rois([123, 500, 30, 50], [123, 500, 55, 120]) _, after_us_data_y = self.model.us_data_spectrum.data _, after_ds_data_y = self.model.ds_data_spectrum.data _, after_us_calibration_y = self.model.us_calibration_spectrum.data _, after_ds_calibration_y = self.model.ds_calibration_spectrum.data _, after_us_corrected_y = self.model.us_corrected_spectrum.data _, after_ds_corrected_y = self.model.ds_corrected_spectrum.data self.array_not_almost_equal(us_data_y, after_us_data_y) self.array_not_almost_equal(ds_data_y, after_ds_data_y) self.array_not_almost_equal(us_calibration_y, after_us_calibration_y) self.array_not_almost_equal(ds_calibration_y, after_ds_calibration_y) self.array_not_almost_equal(us_corrected_y, after_us_corrected_y) self.array_not_almost_equal(ds_corrected_y, after_ds_corrected_y) def test_fitting_temperature(self): # loading files self.load_single_frame_file_and_calibration() self.assertEqual(np.round(self.model.ds_temperature), 1047) self.assertEqual(np.round(self.model.us_temperature), 1414) def test_multiple_frame_spe_file(self): temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe')) self.assertGreater(len(self.model.us_data_spectrum), 0) self.assertGreater(len(self.model.ds_data_spectrum), 0) _, us_y = self.model.us_data_spectrum.data _, ds_y = self.model.ds_data_spectrum.data self.model.load_next_img_frame() _, us_y_1 = self.model.us_data_spectrum.data _, ds_y_1 = self.model.ds_data_spectrum.data self.array_not_almost_equal(us_y, us_y_1) self.array_not_almost_equal(ds_y, ds_y_1) self.model.load_previous_img_frame() _, us_y_2 = self.model.us_data_spectrum.data _, ds_y_2 = self.model.ds_data_spectrum.data self.array_almost_equal(us_y, us_y_2) self.array_almost_equal(ds_y, ds_y_2) def test_multiple_frame_spe_file_on_limits(self): temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe')) _, us_y = self.model.us_data_spectrum.data _, ds_y = self.model.ds_data_spectrum.data self.model.load_previous_img_frame() _, us_y_1 = self.model.us_data_spectrum.data _, ds_y_1 = self.model.ds_data_spectrum.data self.array_almost_equal(us_y, us_y_1) self.array_almost_equal(ds_y, ds_y_1) self.assertEqual(self.model.current_frame, 0) self.model.set_img_frame_number_to(9) _, us_y = self.model.us_data_spectrum.data _, ds_y = self.model.ds_data_spectrum.data self.model.load_next_img_frame() _, us_y_1 = self.model.us_data_spectrum.data _, ds_y_1 = self.model.ds_data_spectrum.data self.array_almost_equal(us_y, us_y_1) self.array_almost_equal(ds_y, ds_y_1) self.assertEqual(self.model.current_frame, 9) def test_temperature_fitting_of_multiple_frame_spe_file(self): temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe')) self.model.load_us_calibration_image( os.path.join(temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image( os.path.join(temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.load_ds_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.set_us_calibration_modus(1) self.model.set_ds_calibration_modus(1) us_temperature1 = self.model.us_temperature ds_temperature1 = self.model.ds_temperature self.model.load_next_img_frame() us_temperature2 = self.model.us_temperature ds_temperature2 = self.model.ds_temperature self.assertNotAlmostEqual(us_temperature1, us_temperature2) self.assertNotAlmostEqual(ds_temperature1, ds_temperature2) def test_batch_fitting_of_multiple_frame_spe_file(self): temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe')) self.model.load_us_calibration_image( os.path.join(temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image( os.path.join(temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.load_ds_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from( x_limits_wavelength) self.model.set_rois([x_limits_ind[0], x_limits_ind[1], 152, 163], [x_limits_ind[0], x_limits_ind[1], 99, 110]) us_temperature, us_temperature_error, ds_temperature, ds_temperature_error = self.model.fit_all_frames( ) self.assertEqual(len(us_temperature), 10) self.assertEqual(len(ds_temperature), 10) self.assertEqual(len(us_temperature_error), 10) self.assertEqual(len(ds_temperature_error), 10) self.array_not_almost_equal(np.array(us_temperature), np.array(ds_temperature)) self.array_not_almost_equal(np.array(us_temperature_error), np.array(ds_temperature_error)) def test_saving_and_loading_empty_settings(self): filename = os.path.join(unittest_files_path, 'empty.trs') self.model.save_setting(filename) temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement_multiple.spe')) self.model.load_us_calibration_image( os.path.join(temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image( os.path.join(temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.load_ds_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.set_ds_calibration_temperature(2500) self.model.set_us_calibration_temperature(2300) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) self.model.load_setting(filename) self.assertEqual(self.model.ds_calibration_filename, None) self.assertEqual(self.model.us_calibration_filename, None) self.assertEqual( self.model.ds_temperature_model.calibration_parameter.temperature, 2000) self.assertEqual( self.model.us_temperature_model.calibration_parameter.temperature, 2000) self.assertEqual( self.model.ds_temperature_model.calibration_parameter.modus, 0) self.assertEqual( self.model.us_temperature_model.calibration_parameter.modus, 0) self.assertTrue(self.model.ds_temperature is np.NaN) self.assertTrue(self.model.ds_temperature_error is np.NaN) self.assertTrue(self.model.us_temperature is np.NaN) self.assertTrue(self.model.us_temperature_error is np.NaN) self.assertEqual(self.model.ds_roi.as_list(), [0, 0, 0, 0]) self.assertEqual(self.model.us_roi.as_list(), [0, 0, 0, 0]) def test_saving_and_loading_a_complete_setting(self): setting_filename = os.path.join(unittest_files_path, 'complete.trs') temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement.spe')) self.model.load_us_calibration_image( os.path.join(temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image( os.path.join(temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.load_ds_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.set_ds_calibration_temperature(2500) self.model.set_us_calibration_temperature(2300) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from( x_limits_wavelength) ds_roi_limits = [x_limits_ind[0], x_limits_ind[1], 152, 163] us_roi_limits = [x_limits_ind[0], x_limits_ind[1], 99, 110] self.model.set_rois(ds_roi_limits, us_roi_limits) self.model.save_setting(setting_filename) self.model2 = TemperatureModel() self.model2.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement.spe')) self.model2.load_setting(setting_filename) print self.model.ds_roi.as_list() print self.model2.ds_roi.as_list() self.assertEqual(self.model.ds_temperature, self.model2.ds_temperature) self.assertEqual(self.model.us_temperature, self.model2.us_temperature) def load_single_frame_file_and_calibration(self): temperature_fitting_path = os.path.join(unittest_files_path, 'temperature_fitting') self.model.load_data_image( os.path.join(temperature_fitting_path, 'test_measurement.spe')) self.model.load_us_calibration_image( os.path.join(temperature_fitting_path, 'us_calibration.spe')) self.model.load_ds_calibration_image( os.path.join(temperature_fitting_path, 'ds_calibration.spe')) # load correct etalon files: self.model.load_us_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.load_ds_etalon_spectrum( os.path.join(temperature_fitting_path, '15A_lamp.txt')) self.model.set_ds_calibration_modus(1) self.model.set_us_calibration_modus(1) # set the correct roi x_limits_wavelength = [666, 836] x_limits_ind = self.model.data_img_file.get_index_from( x_limits_wavelength) self.model.set_rois([x_limits_ind[0], x_limits_ind[1], 152, 163], [x_limits_ind[0], x_limits_ind[1], 99, 110]) def test_saving_data_as_text_from_a_single_frame(self): self.load_single_frame_file_and_calibration() out_path = os.path.join(unittest_files_path, 'data.txt') self.model.save_txt(out_path) file = open(out_path) lines = file.readlines() self.assertEqual(lines[0], "# Fitted Temperatures:\n") self.assertEqual(lines[1], "# Downstream (K): 1046.9 14.7\n") self.assertEqual(lines[2], "# Upstream (K): 1413.6 2.1\n") self.assertEqual(lines[3], "# \n") self.assertEqual(lines[4], "# Datacolumns:\n") self.assertEqual(lines[5], "# lambda(nm) DS_data DS_fit US_data US_fit\n") file.close() os.remove(out_path)