31 Puts subset of sources in diffuse model cube
33 The csmodelsois class puts a subset of sources in a model definition
34 XML file into a model cube and generates a new model definition XML file
35 in which the subset of sources is replaced by a model of type
46 argv : list of parameters
51 An invalid number of command line arguments was provided.
54 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
68 Get parameters from parfile
71 self[
'inmodel'].filename()
72 self[
'soilist'].string()
75 ptsrcsig = self[
'ptsrcsig'].real()
78 self.
_cubegen[
'coordsys'].string(self[
'coordsys'].string())
79 if self[
'coordsys'].string() ==
'CEL':
80 self.
_cubegen[
'xref'].real(self[
'ra'].real())
81 self.
_cubegen[
'yref'].real(self[
'dec'].real())
83 self.
_cubegen[
'xref'].real(self[
'glon'].real())
84 self.
_cubegen[
'yref'].real(self[
'glat'].real())
87 self.
_cubegen[
'binsz'].real(self[
'binsz'].real())
88 self.
_cubegen[
'nxpix'].integer(self[
'nxpix'].integer())
89 self.
_cubegen[
'nypix'].integer(self[
'nypix'].integer())
90 self.
_cubegen[
'proj'].string(self[
'proj'].string())
93 self.
_cubegen[
'ebinalg'].string(self[
'ebinalg'].string())
94 if self[
'ebinalg'].string() ==
'FILE':
95 self.
_cubegen[
'ebinfile'].filename(self[
'ebinfile'].filename())
97 self.
_cubegen[
'emin'].real(self[
'emin'].real())
98 self.
_cubegen[
'emax'].real(self[
'emax'].real())
99 self.
_cubegen[
'enumbins'].integer(self[
'enumbins'].integer())
102 self.
_cubegen[
'ptsrcsig'].real(ptsrcsig)
105 if self._read_ahead():
106 self.
_cubegen[
'outcube'].filename(self[
'outcube'].filename())
107 self[
'outmodel'].query()
110 self._log_parameters(gammalib.TERSE)
116 Generates a binned model from the model file using ctmapcube
119 sources = self[
'soilist'].string().split(
',')
122 if (self._models.size() == 0):
123 self.
_models = gammalib.GModels(self[
'inmodel'].filename())
132 if model.classname() !=
'GModelSky':
133 self._cubemodels.remove(model.name())
137 elif model.name()
in sources:
138 self._cubemodels.remove(model.name())
141 self._log_value(self[
'chatter'].integer(),
'Numner of cube models',
142 self._cubemodels.size())
151 Implements the actual bulk of the script's tasks
160 if not self._cubemodels.is_empty():
163 self._log_string(gammalib.NORMAL,
'Generating model cube')
172 self._log_string(gammalib.NORMAL,
173 'List of models is empty, nothing will be done')
180 Save the cube and optionally the updated XML model file
183 if ((
not self._cubegen.mapcube().cube().is_empty())
and
184 self[
'outcube'].is_valid()):
187 self._cubegen.mapcube().
save(self[
'outcube'].filename(),
188 self[
'clobber'].boolean())
191 self._stamp(self[
'outcube'].filename())
194 if self[
'outmodel'].is_valid():
197 outmodels = gammalib.GModels(self.
_models)
201 outmodels.remove(model.name())
204 spat = gammalib.GModelSpatialDiffuseCube(self[
'outcube'].filename())
205 spec = gammalib.GModelSpectralConst()
206 newmodel = gammalib.GModelSky(spat, spec)
212 outmodels.append(newmodel)
215 outmodels.save(self[
'outmodel'].filename())
222 Return the mapcube generated by the underlying 'ctmapcube' object
225 return self._cubegen.mapcube()
229 Return the name to be given to the cube model in the output XML file
232 return 'FixedSourcesCube'
240 models : `~gammalib.GModels`
253 if __name__ ==
'__main__':