def test_ManagedMcrun_load_data_L_mon_direct(self): """ Use test_data_set to test load_data for L_mon with direct path """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", executable_path=executable_path, mcrun_path="path") load_path = os.path.join(THIS_DIR, "test_data_set") results = mcrun_obj.load_results(load_path) os.chdir(current_work_dir) # Reset work directory # Check properties of L_mon L_mon = results[2] self.assertEqual(L_mon.name, "L_mon") self.assertEqual(L_mon.metadata.dimension, 150) self.assertEqual(L_mon.metadata.limits, [0.7, 1.3]) self.assertEqual(L_mon.metadata.xlabel, "Wavelength [AA]") self.assertEqual(L_mon.metadata.ylabel, "Intensity") self.assertEqual(L_mon.metadata.title, "Wavelength monitor") self.assertEqual(L_mon.xaxis[53], 0.914) self.assertEqual(L_mon.Ncount[53], 37111) self.assertEqual(L_mon.Intensity[53], 6.990299315e-06) self.assertEqual(L_mon.Error[53], 6.215308587e-08)
def test_ManagedMcrun_load_data_PSD(self): """ Use test_data_set to test load_data for PSD """ mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", mcrun_path="path") THIS_DIR = os.path.dirname(os.path.abspath(__file__)) current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder results = mcrun_obj.load_results() os.chdir(current_work_dir) # Reset work directory # Check other properties PSD = results[1] self.assertEqual(PSD.name, "PSD") self.assertEqual(PSD.metadata.dimension, [200, 200]) self.assertEqual(PSD.metadata.limits, [-5, 5, -5, 5]) self.assertEqual(PSD.metadata.xlabel, "X position [cm]") self.assertEqual(PSD.metadata.ylabel, "Y position [cm]") self.assertEqual(PSD.metadata.title, "PSD monitor") self.assertEqual(PSD.Ncount[27][21], 9) self.assertEqual(PSD.Intensity[27][21], 2.623929371e-13) self.assertEqual(PSD.Error[27][21], 2.765467693e-13)
def test_ManagedMcrun_load_data_PSD(self): """ Use test_data_set to test load_data for PSD """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", executable_path=executable_path, mcrun_path="path") results = mcrun_obj.load_results() os.chdir(current_work_dir) # Reset work directory # Check three data objects are loaded self.assertEqual(len(results), 3) # Check properties of PSD data PSD = results[1] self.assertEqual(PSD.name, "PSD") self.assertEqual(PSD.metadata.dimension, [200, 200]) self.assertEqual(PSD.metadata.limits, [-5, 5, -5, 5]) self.assertEqual(PSD.metadata.xlabel, "X position [cm]") self.assertEqual(PSD.metadata.ylabel, "Y position [cm]") self.assertEqual(PSD.metadata.title, "PSD monitor") self.assertEqual(PSD.Ncount[27][21], 9) self.assertEqual(PSD.Intensity[27][21], 2.623929371e-13) self.assertEqual(PSD.Error[27][21], 2.765467693e-13)
def test_ManagedMcrun_load_data_PSD4PI(self): """ Use test_data_set to test load_data for PSD_4PI """ mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", mcrun_path="path") THIS_DIR = os.path.dirname(os.path.abspath(__file__)) current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder results = mcrun_obj.load_results() os.chdir(current_work_dir) # Reset work directory self.assertEqual(len(results), 3) PSD_4PI = results[0] self.assertEqual(PSD_4PI.name, "PSD_4PI") self.assertEqual(PSD_4PI.metadata.dimension, [300, 300]) self.assertEqual(PSD_4PI.metadata.limits, [-180, 180, -90, 90]) self.assertEqual(PSD_4PI.metadata.xlabel, "Longitude [deg]") self.assertEqual(PSD_4PI.metadata.ylabel, "Lattitude [deg]") self.assertEqual(PSD_4PI.metadata.title, "4PI PSD monitor") self.assertEqual(PSD_4PI.Ncount[4][1], 4) self.assertEqual(PSD_4PI.Intensity[4][1], 1.537334562E-10) self.assertEqual(PSD_4PI.Error[4][1], 1.139482296E-10)
def load_data(foldername): """ Loads data from a McStas data folder including mccode.sim Parameters ---------- foldername : string Name of the folder from which to load data """ managed_mcrun = ManagedMcrun("dummy", foldername=foldername) return managed_mcrun.load_results()
def test_ManagedMcrun_load_data_L_mon_empty_error(self): """ Check an error occurs when pointed to empty directory """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", executable_path=executable_path, mcrun_path="path") load_path = os.path.join(THIS_DIR, "/dummy_mcstas") with self.assertRaises(NameError): mcrun_obj.load_results(load_path) os.chdir(current_work_dir) # Reset work directory
def test_ManagedMcrun_load_data_Event(self): """ Use test_data_set to test load_data for event data """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", executable_path=executable_path, mcrun_path="path") load_path = os.path.join(THIS_DIR, "test_data_set") results = mcrun_obj.load_results(load_path) os.chdir(current_work_dir) # Reset work directory # Check properties of event data file mon = results[3] self.assertEqual(mon.name, "monitor") self.assertEqual(mon.metadata.dimension, [8, 12000]) self.assertEqual(mon.metadata.limits, [1.0, 12000.0, 1.0, 8.0]) self.assertEqual(mon.metadata.xlabel, "List of neutron events") self.assertEqual(mon.metadata.ylabel, "p x y z vx vy vz t") self.assertEqual( mon.metadata.title, "Intensity Position Position" + " Position Velocity Velocity Velocity" + " Time_Of_Flight Monitor (Square)") expected_parameters = {"wavelength": 1.0} self.assertEqual(mon.metadata.info["Parameters"], expected_parameters) self.assertEqual(mon.metadata.parameters, expected_parameters) self.assertEqual(mon.Intensity[12, 1], -0.006163896406) self.assertEqual(mon.Events[12, 1], -0.006163896406) self.assertEqual(mon.Events[43, 4], 22.06193582) self.assertFalse(hasattr(mon, 'xaxis')) self.assertFalse(hasattr(mon, 'Error')) self.assertFalse(hasattr(mon, 'Ncount'))
def test_ManagedMcrun_load_data_L_mon_direct_error(self): """ Check an error occurs when directory has no mccode.sim """ mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", mcrun_path="path") THIS_DIR = os.path.dirname(os.path.abspath(__file__)) current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder load_path = os.path.join(THIS_DIR, "non_exsistent_dataset") with self.assertRaises(NameError): results = mcrun_obj.load_results(load_path) os.chdir(current_work_dir) # Reset work directory
def test_ManagedMcrun_load_data_PSD4PI(self): """ Use test_data_set to test load_data for PSD_4PI test_data_set contains three data files and some junk, the mccode.sim file contains names of the data files so only these are loaded. """ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) executable_path = os.path.join(THIS_DIR, "dummy_mcstas") current_work_dir = os.getcwd() os.chdir(THIS_DIR) # Set work directory to test folder mcrun_obj = ManagedMcrun("test.instr", foldername="test_data_set", executable_path=executable_path, mcrun_path="path") results = mcrun_obj.load_results() os.chdir(current_work_dir) # Reset work directory # Check three data objects are loaded self.assertEqual(len(results), 4) # Check properties of PSD_4PI data PSD_4PI = results[0] self.assertEqual(PSD_4PI.name, "PSD_4PI") self.assertEqual(PSD_4PI.metadata.dimension, [300, 300]) self.assertEqual(PSD_4PI.metadata.limits, [-180, 180, -90, 90]) self.assertEqual(PSD_4PI.metadata.xlabel, "Longitude [deg]") self.assertEqual(PSD_4PI.metadata.ylabel, "Latitude [deg]") self.assertEqual(PSD_4PI.metadata.title, "4PI PSD monitor") expected_parameters = {"wavelength": 1.0} self.assertEqual(PSD_4PI.metadata.info["Parameters"], expected_parameters) self.assertEqual(PSD_4PI.metadata.parameters, expected_parameters) self.assertEqual(PSD_4PI.Ncount[4][1], 4) self.assertEqual(PSD_4PI.Intensity[4][1], 1.537334562E-10) self.assertEqual(PSD_4PI.Error[4][1], 1.139482296E-10)