162 Merge TS map from FITS file into output TS map.
165 fitsfile: FITS file to be merged.
168 fits = gammalib.GFits(fitsfile)
171 add_tsmap = gammalib.GSkyMap()
172 add_tsmap.read(fits[0])
173 add_statusmap = gammalib.GSkyMap()
174 add_statusmap.read(fits[
'STATUS MAP'])
183 if hdu.extname() !=
'IMAGE' and hdu.extname() !=
'STATUS MAP':
186 skymap = gammalib.GSkyMap()
188 add_maps.append(skymap)
194 if not len(add_maps) == len(self.
_maps):
195 msg =
'Cannot merge map "'+fitsfile+
'" into map "'+\
196 self.
_in_filename+
'" since the number of parameters ' +\
197 'between both maps is different.'
198 raise RuntimeError(msg)
201 for i
in range(self.
_tsmap.npix()):
204 if add_statusmap[i] > -0.5:
208 msg =
'Attempt to merge bin which apparently has '+\
209 'already been merged. File "'+fitsfile+
'" '+\
210 'contains already merged bins. Set hidden '+\
211 'parameter "overwrite=yes" to avoid this error.'
212 raise RuntimeError(msg)
215 self.
_tsmap[i] = add_tsmap[i]
221 for j
in range(len(self.
_maps)):
222 self.
_maps[j][i] = add_maps[j][i]
259 self._log_header1(gammalib.TERSE,
'Merge TS maps')
267 for fitsfile
in self.
_files:
270 if not gammalib.GFilename(fitsfile).is_fits():
273 self._log_value(gammalib.EXPLICIT,
'Skip file', fitsfile +
274 ' (not a FITS file)')
280 fits = gammalib.GFits(fitsfile)
283 if fits.contains(
'STATUS MAP'):
292 pix_info =
' (%d TS pixels computed)' % \
294 self._log_value(gammalib.TERSE,
'Initial TS map file',
307 self._log_value(gammalib.EXPLICIT,
'Skip file', fitsfile +
308 ' (no "STATUS MAP" extension)')
315 msg =
'None of the provided files seems to be a sliced ' + \
316 'TS map file (none has a "STATUS MAP" ' + \
318 raise RuntimeError(msg)
327 workfiles.remove(file0)
336 for fitsfile
in workfiles:
339 if not gammalib.GFilename(fitsfile).is_fits():
340 self._log_value(gammalib.EXPLICIT,
'Skip file', fitsfile +
341 ' (not a FITS file)')
345 fits = gammalib.GFits(fitsfile)
348 if not fits.contains(
'STATUS MAP'):
350 self._log_value(gammalib.EXPLICIT,
'Skip file', fitsfile +
351 ' (no "STATUS MAP" extension)')
358 pix_info =
' (%d TS pixels computed)' % \
360 self._log_value(gammalib.TERSE,
'Merge TS map file',
374 Save TS map and remove slices if requested.
378 outmap = self[
'outmap'].filename()
381 fits = gammalib.GFits()
387 for i
in range(len(self.
_maps)):
388 self.
_maps[i].write(fits)
396 fits[fits.size()-1].extname(
'STATUS MAP')
408 done = (bins_merged == self.
_tsmap.npix())
411 self._log_header2(gammalib.TERSE,
'Merging Summary')
417 self._log_value(gammalib.TERSE,
'TS map bins', self.
_tsmap.npix())
418 self._log_value(gammalib.TERSE,
'Bins computed and merged', bins_merged )
419 self._log_value(gammalib.TERSE,
'Bins missing', self.
_tsmap.npix() - bins_merged)
424 self._log_string(gammalib.TERSE,
'TS map was fully computed and successfully merged')
427 self._log_header1(gammalib.TERSE,
'Save TS map')
430 self._log_value(gammalib.TERSE,
'TS map file', outmap.url())
433 fits.saveto(outmap, self._clobber())
439 self._log_header2(gammalib.TERSE,
'Delete slices TS map files')
448 self._log_value(gammalib.TERSE,
'Deleted input file', filename)