def load(self): if os.path.isfile(self.full_file_name): _tof_handler = TOF(filename=self.full_file_name) _tof_array_s = _tof_handler.tof_array #self.tof_array = _tof_array_s * 1e6 self.tof_array = _tof_array_s self.counts_array = _tof_handler.counts_array
def test_loading_manual_tof_in_ns_units(self): """Assert in TOF - TOF(ms) array is correctly manually loaded and units are converted""" _tof_array = np.array( [1.e9, 2.e9, 3.e9, 4.e9, 5.e9, 6.e9, 7.e9, 8.e9, 9.e9]) _tof_units = 'ns' _tof_handler = TOF(tof_array=_tof_array, units=_tof_units) self.assertTrue(all(_tof_array * 1.e-9 == _tof_handler.tof_array))
def test_loading_counts_column(self): """Assert in TOF - second column (counts) is correctly loaded""" _filename = self.get_full_path('tof.txt') _tof_handler = TOF(filename=_filename) _counts_expected = np.array([2137, 1988, 1979, 2078]) self.assertTrue( all(_counts_expected == _tof_handler.counts_array[0:4]))
def test_loading_manual_tof_in_micros_units(self): """Assert in TOF - TOF(micros) array is correctly manually loaded and units are converted""" _tof_array = np.array( [1.e6, 2.e6, 3.e6, 4.e6, 5.e6, 6.e6, 7.e6, 8.e6, 9.e6]) _tof_units = 'micros' _tof_handler = TOF(tof_array=_tof_array, units=_tof_units) self.assertTrue(all(_tof_array * 1.e-6 == _tof_handler.tof_array))
def test_create_csv_lambda_file_without_providing_name(self): """Assert in Experiment - no file is created if no filename is provided""" _tof_file = os.path.join(self.data_path, 'tof.txt') _tof_obj = TOF(filename=_tof_file) _distance_source_detector_m = 1.609 _detector_offset_micros = 4500 _output_file_name = os.path.join(self.data_path, 'no_file.txt') _exp_obj = Experiment( tof=_tof_obj.tof_array, distance_source_detector_m=_distance_source_detector_m, detector_offset_micros=_detector_offset_micros) self.assertRaises(ValueError, _exp_obj.export_lambda)
def test_experiment_calculate_main_coefficient(self): """Assert in experiment - the calculation of main coefficient is correct""" _tof_file = os.path.join(self.data_path, 'tof.txt') _tof_obj = TOF(filename=_tof_file) _distance_source_detector_m = 1.609 _detector_offset_s = 4500e-6 _exp_obj = Experiment( tof=_tof_obj.tof_array, distance_source_detector_m=_distance_source_detector_m, detector_offset_micros=_detector_offset_s) self.assertAlmostEqual(2.45869e-7, _exp_obj._h_over_MnLds, delta=0.0001)
def test_create_csv_lambda_file(self): """Assert in Experiment - the lambda file is correctly exported""" _tof_file = os.path.join(self.data_path, 'tof.txt') _tof_obj = TOF(filename=_tof_file) _distance_source_detector_m = 1.609 _detector_offset_micros = 4500 _exp_obj = Experiment( tof=_tof_obj.tof_array, distance_source_detector_m=_distance_source_detector_m, detector_offset_micros=_detector_offset_micros) _output_filename = os.path.join(self.data_path, 'remove_me.txt') _exp_obj.export_lambda(filename=_output_filename) self.assertTrue(os.path.isfile(_output_filename)) os.remove(_output_filename) # cleanup temp file
def test_calculate_detector_offset(self): """Assert in Experiment - the detector offset is correctly calculated""" _tof_file = os.path.join(self.data_path, 'tof.txt') _tof_obj = TOF(filename=_tof_file) _distance_source_detector_m = 1.609 _lambda_file = os.path.join(self.data_path, 'lambda.txt') _lambda_obj = LambdaWavelength(filename=_lambda_file) _tof_array = _tof_obj.tof_array[0:20] _lambda_array = _lambda_obj.lambda_array[0:20] _exp_handler = Experiment( tof=_tof_array, lambda_array=_lambda_array, distance_source_detector_m=_distance_source_detector_m) _offset_expected_micros = 4500 #micros _offset_calculated = _exp_handler.detector_offset_micros self.assertAlmostEqual(_offset_expected_micros, _offset_calculated, delta=1e-6)
def test_experiment_calculate_lambda(self): """Assert in experiment - the calculation of lambda is correct""" _tof_file = os.path.join(self.data_path, 'tof.txt') _tof_obj = TOF(filename=_tof_file) _distance_source_detector_m = 1.609 _detector_offset_micros = 4500 _exp_obj = Experiment( tof=_tof_obj.tof_array, distance_source_detector_m=_distance_source_detector_m, detector_offset_micros=_detector_offset_micros) _lambda_expected = np.array([ 1.10664704e-09, 1.10916474e-09, 1.11168244e-09, 1.11420014e-09, 1.11671784e-09, 1.11923554e-09, 1.12175324e-09, 1.12427094e-09, 1.12678864e-09, 1.12930634e-09, 1.13182403e-09, 1.13434173e-09, 1.13685943e-09, 1.13937713e-09, 1.14189483e-09, 1.14441253e-09, 1.14693023e-09, 1.14944793e-09, 1.15196563e-09, 1.15448333e-09 ]) _lambda_returned = _exp_obj.lambda_array self.assertTrue(_lambda_expected[0], _lambda_returned[0]) self.assertTrue(_lambda_expected[5], _lambda_returned[5]) self.assertTrue(_lambda_expected[-1], _lambda_returned[-1]) self.assertTrue(len(_lambda_expected), len(_lambda_returned))
def test_loading_real_tof_file(self): """Assert in TOF - that real tof file is correctly loaded""" _filename = self.get_full_path('tof.txt') _tof_handler = TOF(filename=_filename) _tof_expected = np.array([9.6e-7, 1.12e-5, 2.144e-5, 3.168e-5]) self.assertTrue(all(_tof_expected == _tof_handler.tof_array[0:4]))
def test_loading_good_tof_file(self): """Assert in TOF - that correctly formated tof file is correctly loaded""" _filename = self.get_full_path('good_tof.txt') _tof_handler = TOF(filename=_filename) _tof_expected = np.array([1.0, 2.0, 3.0, 4.0]) self.assertTrue(all(_tof_expected == _tof_handler.tof_array[0:4]))
def test_loading_manual_tof_in_s_units(self): """Assert in TOF - TOF(s) array is correctly manually loaded""" _tof_array = [1., 2., 3., 4., 5., 6., 7., 8., 9.] _tof_handler = TOF(tof_array=_tof_array) self.assertTrue(all(_tof_array == _tof_handler.tof_array))