24 from cscripts
import modutils
32 Shows the content of a model container
34 The script is useful to show, e.g., the number of sources in a model
35 container, the background models, free and fixed parameters etc.
36 The script can also dump the models into a region file to for display
46 self._init_cscript(self.__class__.__name__, ctools.__version__, argv)
58 Get parameters from parfile and setup the observation
61 self.
_models = gammalib.GModels(self[
'inmodel'].filename())
64 self[
'pnt_type'].string()
65 self[
'pnt_mark_size'].integer()
66 self[
'show_labels'].boolean()
67 self[
'width'].integer()
68 self[
'fontfamily'].string()
69 self[
'fontsize'].integer()
70 self[
'fontweight'].string()
71 self[
'fontslant'].string()
72 self[
'show_ext_type'].boolean()
73 self[
'free_color'].string()
74 self[
'fixed_color'].string()
77 if self._read_ahead():
78 self[
'outds9file'].query()
81 self._log_parameters(gammalib.TERSE)
96 if self._logVerbose():
98 self._log.header1(
'Models')
121 types[model.type()] = 0
122 instruments[model.instruments()] = 0
123 pars_at_limit[model.name()] = []
129 types[model.type()] += 1
132 instruments[model.instruments()] += 1
136 ts[model.name()] = model.ts()
139 skymodel = (model.classname() ==
'GModelSky')
141 free_src_pars[model.name()] = []
151 if par.value() == par.min()
or par.value() == par.max():
152 pars_at_limit[model.name()].append(par.name())
160 free_src_pars[model.name()].append(par)
170 for par
in model.spectral():
173 for par
in model.spatial():
176 for par
in model.temporal():
184 self._log_header1(gammalib.TERSE,
'Summary')
187 self._log.header3(
'Instrument specific models')
188 for inst, n_inst
in instruments.items():
191 self._log_value(gammalib.TERSE, inst, n_inst)
194 self._log_header3(gammalib.TERSE,
'Model types')
195 for modeltype, n_types
in types.items():
196 self._log_value(gammalib.TERSE, modeltype, n_types)
199 self._log_header1(gammalib.TERSE,
'Parameter information')
200 self._log_value(gammalib.TERSE,
'All parameters', n_par_total)
201 self._log_value(gammalib.TERSE,
'Fixed parameters', n_par_fixed)
202 self._log_value(gammalib.TERSE,
'Free parameters (total)', n_par_free)
203 self._log_value(gammalib.TERSE,
'Free background parameters', n_par_free_bkg)
204 self._log_value(gammalib.TERSE,
'Free source parameters', n_par_free_src)
205 if n_par_free_spec > 0:
206 self._log_value(gammalib.TERSE,
'Free spectral parameters', n_par_free_spec)
207 if n_par_free_spat > 0:
208 self._log_value(gammalib.TERSE,
'Free spatial parameters', n_par_free_spat)
209 if n_par_free_temp > 0:
210 self._log_value(gammalib.TERSE,
'Free temporal parameters', n_par_free_temp)
211 self._log_value(gammalib.TERSE,
'Parameters at limit', n_par_at_limit)
214 if n_par_at_limit > 0:
215 self._log_header3(gammalib.TERSE,
'Parameters at limit')
216 for source, parameter
in pars_at_limit.items():
218 for par
in parameter:
219 self._log_value(gammalib.TERSE, source, par)
222 if len(free_src_pars):
223 self._log_header2(gammalib.EXPLICIT,
'Free source parameters')
224 for source, parameter
in free_src_pars.items():
226 self._log.header3(source)
227 for par
in parameter:
228 self._log_string(gammalib.EXPLICIT, str(par)+
'\n')
232 self._log_header3(gammalib.TERSE,
'Test statistics')
233 for source, tsvalue
in ts.items():
234 self._log_value(gammalib.TERSE, source, tsvalue)
241 Save models to ds9 region file
244 if self[
'outds9file'].is_valid():
247 ds9file = self[
'outds9file'].filename()
250 self._log_header1(gammalib.TERSE,
'Save models in DS9 file')
253 self._log_value(gammalib.NORMAL,
'DS9 filename', ds9file.url())
256 pnt_type = self[
'pnt_type'].string()
257 pnt_mark_size = self[
'pnt_mark_size'].integer()
258 show_labels = self[
'show_labels'].boolean()
259 free_color = self[
'free_color'].string()
260 fixed_color = self[
'fixed_color'].string()
261 width = self[
'width'].integer()
262 fontfamily = self[
'fontfamily'].string()
263 fontsize = self[
'fontsize'].integer()
264 fontweight = self[
'fontweight'].string()
265 fontslant = self[
'fontslant'].string()
268 errors = modutils.models2ds9file(self.
_models, ds9file.url(),
270 pnt_mark_size=pnt_mark_size,
271 show_labels=show_labels,
272 free_color=free_color,
273 fixed_color=fixed_color,
275 fontfamily=fontfamily,
277 fontweight=fontweight,
291 if __name__ ==
'__main__':