def setUp(self): beam = mo.get_beam() det = mo.get_detector() self.rec_file = Path(tempfile.gettempdir(), "rec") self.erd_file = Path(tempfile.gettempdir(), "erd") self.espe = GetEspe( beam.ion.get_prefix(), beam.energy, det.detector_theta, mo.get_target().target_theta, det.calculate_tof_length(), det.calculate_solid(), self.rec_file, self.erd_file)
def test_serialization(self): with tempfile.TemporaryDirectory() as tmp_dir: fp = Path(tmp_dir, "test.simu") sim = Simulation(Path(tmp_dir, "foo.simulation"), mo.get_request(), name="foo", description="bar", save_on_creation=False, run=mo.get_run(), detector=mo.get_detector(), target=mo.get_target(), enable_logging=False, use_request_settings=False) sim.to_file(fp) sim2 = Simulation.from_file(mo.get_request(), fp, detector=mo.get_detector(), target=mo.get_target(), run=mo.get_run(), enable_logging=False, save_on_creation=False) self.assertEqual(sim.name, sim2.name) self.assertEqual(sim.description, sim2.description) self.assertEqual(sim.measurement_setting_file_description, sim2.measurement_setting_file_description) self.assertEqual(sim.measurement_setting_file_name, sim2.measurement_setting_file_name) self.assertEqual(sim.use_request_settings, sim2.use_request_settings) self.assertEqual(sim.detector.name, sim2.detector.name) self.assertEqual(sim.detector.angle_offset, sim2.detector.angle_offset) self.assertEqual(sim.target.scattering_element, sim2.target.scattering_element) self.assertEqual(sim.target.target_type, sim2.target.target_type) self.assertEqual(sim.run.fluence, sim2.run.fluence)
def test_copy_layers(self): """Tests that copied layers have the same attributes as the original ones. """ target = mo.get_target() target.layers = [mo.get_layer(1)] copied_layers = target.copy_layers() self.assertEqual(len(target.layers), len(copied_layers)) for l1, l2 in zip(target.layers, copied_layers): self.assertIsNot(l1, l2) self.assertEqual(l1.get_mcerd_params(), l2.get_mcerd_params()) for e1, e2 in zip(l1.elements, l2.elements): self.assertIsNot(e1, e2) self.assertEqual(e1, e2)
def test_adjustable_settings(self): target = mo.get_target() kwargs = { "name": "test", "description": "Some description.", "modification_time": 1601838503.492942, "target_type": "AFM", "scattering_element": Element("H", 2), "image_size": [1024, 1024], "image_file": "", "layers": [], "target_theta": 30 } self.assertNotEqual(kwargs, target.get_settings()) target.set_settings(**kwargs) self.assertEqual(kwargs, target.get_settings())
def setUp(self): self.beam = mo.get_beam() self.detector = mo.get_detector() self.target = mo.get_target() self.default_kwargs = { "beam_ion": self.beam.ion.get_prefix(), "energy": self.beam.energy, "theta": self.detector.detector_theta, "toflen": self.detector.calculate_tof_length(), "tangle": self.target.target_theta, "solid": self.detector.calculate_solid(), "recoil_file": _RECOIL_FILE, "erd_file": _ERD_FILE, "reference_density": 4.98e22, "ch": 0.025, "fluence": 5.00e+11, "timeres": self.detector.timeres, }
def test_initialization(self): tab = Mock() sim = mo.get_simulation() target = mo.get_target() icons = IconManager() settings = mo.get_global_settings() widget = TargetWidget(tab, sim, target, icons, settings, auto_save=False) rec_dist = widget.recoil_distribution_widget self.assertFalse(rec_dist.main_recoil_selected()) self.assertIsNone(rec_dist.get_current_main_recoil()) widget.close()