24 from cscripts
import obsutils
32 Generates a residual map
41 self._init_csobservation(self.__class__.__name__, ctools.__version__, argv)
55 Get parameters from parfile and setup the observation
65 if self.obs().size() == 0
and self[
'inobs'].filename() !=
'NONE':
66 filename = gammalib.GFilename(self[
'inobs'].filename())
67 if filename.is_fits():
68 cta = gammalib.GCTAObservation()
70 if cta.eventtype() ==
'CountsCube':
76 self.
_use_maps = self[
'modcube'].is_valid()
82 if self.obs().size() == 0:
83 self._require_inobs(
'csresmap.get_parameters()')
84 self.obs(self._get_observations())
88 if self.obs().size() == 1
and \
89 self.obs()[0].classname() ==
'GCTAObservation' and \
90 self.obs()[0].eventtype() ==
'CountsCube':
94 if self.obs().
models().size() == 0:
95 self.obs().
models(self[
'inmodel'].filename())
102 self[
'coordsys'].string()
103 self[
'proj'].string()
104 self[
'nxpix'].integer()
105 self[
'nypix'].integer()
107 self[
'ebinalg'].string()
108 if self[
'ebinalg'].string() ==
'FILE':
109 self[
'ebinfile'].filename()
113 self[
'enumbins'].integer()
114 if self[
'ebinalg'].string() ==
'POW':
115 self[
'ebingamma'].real()
118 self[
'edisp'].boolean()
119 self[
'algorithm'].string()
120 self[
'publish'].boolean()
121 self[
'chatter'].integer()
122 self[
'clobber'].boolean()
123 self[
'debug'].boolean()
126 if (self._read_ahead()):
127 self[
'outmap'].filename()
130 self._log_parameters(gammalib.TERSE)
145 self._log_observations(gammalib.NORMAL, self.obs(),
'Observation')
149 countmap = gammalib.GSkyMap(self[
'inobs'].filename())
150 modelmap = gammalib.GSkyMap(self[
'modcube'].filename())
158 cta_counts_cube = gammalib.GCTAEventCube(self.obs()[0].events())
164 self._log_header1(gammalib.TERSE,
'Generate binned map (ctbin)')
167 cta_counts_cube = obsutils.create_counts_cube(self, self.obs())
170 countmap = cta_counts_cube.counts()
173 self._log_header1(gammalib.TERSE,
'Generate model map (ctmodel)')
176 model = ctools.ctmodel(self.obs())
177 model.cube(cta_counts_cube)
178 model[
'chatter'] = self[
'chatter'].integer()
179 model[
'clobber'] = self[
'clobber'].boolean()
180 model[
'debug'] = self[
'debug'].boolean()
181 model[
'edisp'] = self[
'edisp'].boolean()
185 modelmap = model.cube().counts().copy()
191 countmap1 = countmap.copy()
192 countmap1.stack_maps()
193 modelmap.stack_maps()
194 self.
_resmap = obsutils.residuals(self,countmap1,modelmap)
197 if self[
'publish'].boolean():
208 self._log_header1(gammalib.TERSE,
'Save residual map')
211 outmap = self[
'outmap'].filename()
217 self._log_value(gammalib.TERSE,
'Residual map file', outmap.url())
220 self._resmap.save(outmap, self[
'clobber'].boolean())
238 self._log_header1(gammalib.TERSE,
'Publish residual map')
245 user_name = self._name()
250 self._log_value(gammalib.TERSE,
'Residual map name', user_name)
253 self._resmap.publish(user_name)
274 map : `~gammalib.GSkyMap'
284 if __name__ ==
'__main__':