31 Selects model from a model definition XML file
40 self._init_csobservation(self.__class__.__name__, ctools.__version__, argv)
53 Get parameters from parfile and setup the observation
56 self[
'inobs'].filename()
57 self[
'inmodel'].filename()
60 self[
'roilimit'].real()
61 self[
'roimargin'].real()
63 self[
'fluxlimit'].real()
64 self[
'tslimit'].real()
65 self[
'fit_pos'].boolean()
66 self[
'fit_shape'].boolean()
69 if self._read_ahead():
70 self[
'outmodel'].filename()
74 if self.obs().size() == 0:
75 self.obs(self._get_observations(
False))
78 self.
_models = gammalib.GModels(self[
'inmodel'].filename())
81 self._log_parameters(gammalib.TERSE)
92 model : `~gammalib.GModel`
94 obs : `~gammalib.GObservations`
103 roilimit = self[
'roilimit'].real()
104 roimargin = self[
'roimargin'].real()
105 ethres = self[
'ethres'].real()
106 fluxlimit = self[
'fluxlimit'].real()
107 tslimit = self[
'tslimit'].real()
111 msg =
'Select by default'
114 if hasattr(model,
'spatial'):
117 model_bounds = model.spatial().region()
121 msg =
'Exclude since outside any RoI'
133 obs_centre = obs_roi.centre().dir()
134 obs_radius = obs_roi.radius()
135 if obs_radius > roilimit:
136 obs_radius = roilimit
137 obs_radius += roimargin
140 obs_bounds = gammalib.GSkyRegionCircle(obs_centre, obs_radius)
143 if obs_bounds.overlaps(model_bounds):
145 msg =
'Select due to overlap with at least one RoI'
150 if select
and model.has_ts():
151 if model.ts() < tslimit:
153 msg =
'Exclude since below TS limit (TS=%.3f)' % model.ts()
157 if select
and model.classname() ==
'GModelSky':
158 emin = gammalib.GEnergy(ethres,
'TeV')
159 emax = gammalib.GEnergy(1000.0,
'TeV')
160 flux = model.spectral().flux(emin, emax)
163 msg =
'Exclude since below flux limit (Flux=%.3e ph/cm2/s)' % flux
166 self._log_value(gammalib.NORMAL, model.name(), msg)
177 model : `~gammalib.GModel`
182 model : `~gammalib.GModel`
183 Model with parameter set
186 fit_pos = self[
'fit_pos'].boolean()
187 fit_shape = self[
'fit_shape'].boolean()
190 if hasattr(model,
'spatial'):
196 if par.name() ==
'RA' or par.name() ==
'DEC':
203 elif par.name() ==
'Radius' or \
204 par.name() ==
'Sigma' or \
205 par.name() ==
'Width' or \
206 par.name() ==
'PA' or \
207 par.name() ==
'MajorRadius' or \
208 par.name() ==
'MinorRadius':
227 models = gammalib.GModels()
230 self._log_observations(gammalib.NORMAL, self.obs(),
'Input observation')
233 self._log_models(gammalib.NORMAL, self.
_models,
'Input model')
236 self._log_header1(gammalib.NORMAL,
'Model selection')
255 self._log_models(gammalib.NORMAL, self.
_models,
'Selected model')
262 Save model definition XML file
265 self._log_header1(gammalib.TERSE,
'Save models')
268 outmodel = self[
'outmodel'].filename()
271 if outmodel.exists()
and not self._clobber:
272 msg = (
'Cannot save "'+outmodel.url()+
'": File already exists. '
273 'Use parameter clobber=yes to allow overwriting of files.')
274 raise RuntimeError(msg)
279 self._log_value(gammalib.NORMAL,
'Model definition XML file',
283 self._models.save(outmodel)
292 if __name__ ==
'__main__':
def _set_model_parameters