def testindex_delimited_detectors(self): d1, d2 = index_delimited_detectors(self.detectors) self.assertEqual(0, d1['det1']) self.assertEqual(2, d1['det2']) self.assertEqual(3, d1['det3']) self.assertEqual(0, d1['det4']) self.assertEqual(1, d1['det5']) self.assertEqual(['det1', 'det4'], sorted(d2[0])) self.assertEqual(['det5'], d2[1]) self.assertEqual(['det2'], d2[2]) self.assertEqual(['det3'], d2[3]) d1, d2 = index_delimited_detectors({}) self.assertEqual(0, len(d1)) self.assertEqual(0, len(d2))
def _import(self, options, dirpath, *args, **kwargs): # Find index for each delimited detector # The same method (index_delimited_detectors) is called when exporting # the result. It ensures that the same index is used for all detectors dets = dict(options.detectors.iterclass(_PhotonDelimitedDetector)) phdets_key_index, phdets_index_keys = index_delimited_detectors(dets) return self._run_importers(options, dirpath, phdets_key_index, phdets_index_keys, *args, **kwargs)
def _create_input_file(self, options, outputdir, geoinfo, matinfos, *args): """ Creates .in file for the specific PENELOPE main program and returns its location. :arg options: options to be exported :arg outputdir: directory where all the simulation files are saved :arg geoinfo: class:`tuple` containing :class:`PenelopeGeometry` object used to create the *geo* file and the full path of this *geo* file. :arg matinfos: :class:`list` of :class:`tuple` where each :class:`tuple` contains :class:`PenelopeMaterial` object and its associated *mat* filepath. The order of the materials is the same as they appear in the geometry file. :return: path to the .in file """ # Find index for each delimited detector # The same method (index_delimited_detectors) is called when importing # the result. It ensures that the same index is used for all detectors dets = dict(options.detectors.iterclass(_PhotonDelimitedDetector)) phdets_key_index, phdets_index_keys = index_delimited_detectors(dets) # Create lines lines = [] args = (lines, options, geoinfo, matinfos, phdets_key_index, phdets_index_keys) + args self._append_title(*args) self._append_electron_beam(*args) self._append_material_data(*args) self._append_geometry(*args) self._append_interaction_forcing(*args) self._append_emerging_particles_distribution(*args) self._append_photon_detectors(*args) self._append_spatial_distribution(*args) # self._append_phirhoz_distribution(*args) self._append_job_properties(*args) lines.append(self._KEYWORD_END()) # Create .in file filepath = os.path.join(outputdir, options.name + '.in') with open(filepath, 'w') as fp: for line in lines: fp.write(line + os.linesep) return filepath