33 Merge model definition XML files
35 An arbitrary number of model definition XML files will be merged into
36 a single model definition XML file.
45 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
58 Get parameters from parfile
61 inmodels = self[
'inmodels'].string()
66 if '@' == inmodels[0]:
67 filename = inmodels.replace(
'@',
'')
68 self.
_files = open(filename).read().splitlines()
69 dirname = os.path.dirname(filename)
73 fname = dirname +
'/' + f
81 self.
_files = glob.glob(inmodels)
85 self.
_files = inmodels.split(
' ')
89 self.
_files = inmodels.split(
';')
93 msg =
'Parameter "inmodels" must contain either an @ASCII '\
94 'file, a semi-colon-separated or whitespace-separated '\
95 'list of files or a wildcard string.'
96 raise RuntimeError(msg)
99 if self._read_ahead():
100 self[
'outmodel'].filename()
106 self._log_parameters(gammalib.TERSE)
123 self._log.header1(
'Merge models')
126 self.
_models = gammalib.GModels()
132 models = gammalib.GModels(f)
135 nmodels = models.size()
137 name =
'Add no model from file'
139 name =
'Add 1 model from file'
141 name =
'Add %d models from file' % nmodels
142 self._log_value(gammalib.TERSE, name, f)
145 self._models.extend(models)
148 self._log_value(gammalib.TERSE,
'Models after merging',
156 Save model definition XML file
159 self._log_header1(gammalib.TERSE,
'Save models')
162 outmodel = self[
'outmodel'].filename()
165 if outmodel.exists()
and not self.
_clobber:
166 msg = (
'Cannot save "'+outmodel.url()+
'": File already exists. '
167 'Use parameter clobber=yes to allow overwriting of files.')
168 raise RuntimeError(msg)
173 self._log_value(gammalib.NORMAL,
'Model definition XML file',
177 self._models.save(outmodel)
186 if __name__ ==
'__main__':