diff --git a/cscripts/cstsmapmerge.py b/cscripts/cstsmapmerge.py index 9322e43..10ef14a 100755 --- a/cscripts/cstsmapmerge.py +++ b/cscripts/cstsmapmerge.py @@ -30,17 +30,17 @@ import ctools # ================== # class cstsmapmerge(ctools.cscript): """ - Merge Test Statistic maps + Merge Test Statistic maps. """ # Constructor def __init__(self, *argv): """ - Constructor + Constructor. """ # Set name self._name = 'cstsmapmerge' - self._version = '1.2.0' + self._version = '1.1.0' # Initialise class members self._files = None @@ -64,7 +64,7 @@ class cstsmapmerge(ctools.cscript): # Private methods def _get_parameters(self): """ - Get parameters from parfile + Get parameters from parfile. """ # Get input maps string inmaps = self['inmaps'].string() @@ -118,11 +118,7 @@ class cstsmapmerge(ctools.cscript): if self._read_ahead(): self['outmap'].filename() -<<<<<<< HEAD - # Write input parameters into logger -======= # Write input parameters into logger ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 self._log_parameters(gammalib.TERSE) # Return @@ -130,12 +126,7 @@ class cstsmapmerge(ctools.cscript): def _init_ts_map(self, fitsfile): """ - Initialise Test Statistic map - - Parameters - ---------- - fitsfile : str - FITS file to be merged + Initialise Test Statistic map. """ # Set filename self._in_filename = fitsfile @@ -157,11 +148,7 @@ class cstsmapmerge(ctools.cscript): for hdu in fits: # Leave out primary and status extension -<<<<<<< HEAD - if hdu.extname() != 'IMAGE' and hdu.extname() != 'STATUS MAP': -======= if hdu.extname() != "IMAGE" and hdu.extname() != 'STATUS MAP': ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # Add present maps skymap = gammalib.GSkyMap() @@ -177,12 +164,10 @@ class cstsmapmerge(ctools.cscript): def _merge_ts_map(self, fitsfile): """ - Merge TS map from FITS file into output TS map + Merge TS map from FITS file into output TS map. - Parameters - ---------- - fitsfile : str - FITS file to be merged + Args: + fitsfile: FITS file to be merged. """ # Open FITS file fits = gammalib.GFits(fitsfile) @@ -200,11 +185,7 @@ class cstsmapmerge(ctools.cscript): for hdu in fits: # Leave out primary and status extension -<<<<<<< HEAD - if hdu.extname() != 'IMAGE' and hdu.extname() != 'STATUS MAP': -======= if hdu.extname() != "IMAGE" and hdu.extname() != 'STATUS MAP': ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # Add present maps skymap = gammalib.GSkyMap() @@ -216,9 +197,9 @@ class cstsmapmerge(ctools.cscript): # Compare size of maps if not len(add_maps) == len(self._maps): - msg = ('Cannot merge map "%s" into map "%s" since the number of ' - 'parameters between both maps is different.' % - (fitsfile, self._in_filename)) + msg = "Cannot merge map \""+fitsfile+"\" into map \""+\ + self._in_filename+"\" since the number of parameters "\ + "between both maps is different." raise RuntimeError(msg) # Loop over bins @@ -228,19 +209,11 @@ class cstsmapmerge(ctools.cscript): if add_statusmap[i] > -0.5: # Raise exception if this bin has already been computed -<<<<<<< HEAD - if self._statusmap[i] > 0.5 and not self._overwrite: - msg = ('Attempt to merge bin which apparently has already ' - 'been merged. File "%s" contains already merged ' - 'bins. Set hidden parameter "overwrite=yes" to ' - 'avoid this error.' % fitsfile) -======= if self._statusmap[i] > -0.5 and not self._overwrite: msg = "Attempt to merge bin which apparently has "+\ "already been merged. File \""+fitsfile+"\" "+\ "contains already merged bins. Set hidden "+\ "parameter \"overwrite=yes\" to avoid this error." ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 raise RuntimeError(msg) # Copy TS values @@ -258,20 +231,16 @@ class cstsmapmerge(ctools.cscript): def _get_number_of_ts_pixels(self, fitsfile): """ - Return number of pixels with TS values + Return number of pixels with TS values. - Parameters - ---------- - fitsfile : str - FITS file to be merged + Args: + fitsfile: FITS file to be merged. - Returns - ------- - counts : int - Number of pixels for which TS has been computed + Returns: + Number of pixels for which TS has been computed. """ # Get status map for this file - status = gammalib.GSkyMap(fitsfile+'[STATUS MAP]') + status = gammalib.GSkyMap(fitsfile+"[STATUS MAP]") # Count number of pixels with TS status set count = 0 @@ -286,7 +255,7 @@ class cstsmapmerge(ctools.cscript): # Public methods def run(self): """ - Run the script + Run the script. """ # Switch screen logging on in debug mode if self._logDebug(): @@ -296,12 +265,10 @@ class cstsmapmerge(ctools.cscript): self._get_parameters() # Write header into logger - if self._logTerse(): - self._log('\n') - self._log.header1('Merge TS maps') + self._log_header1(gammalib.TERSE, "Merge TS maps") # Initialise file to start with - file0 = '' + file0 = "" self._merged_files = [] # Test files for the entry status map. Use the first one to appear @@ -310,16 +277,11 @@ class cstsmapmerge(ctools.cscript): # Skip file if it's not a FITS file if not gammalib.GFilename(fitsfile).is_fits(): -<<<<<<< HEAD - self._log_value(gammalib.EXPLICIT, 'Skip file', - '%s (not a FITS file)' % fitsfile) -======= # Log message self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (not a FITS file)") # Continue ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 continue # Open FITS file @@ -327,47 +289,22 @@ class cstsmapmerge(ctools.cscript): # If file contains a status map then use it if fits.contains('STATUS MAP'): -<<<<<<< HEAD -======= # Close FITS file ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 fits.close() # Set filename to initial filename file0 = fitsfile -<<<<<<< HEAD - if self._logTerse(): - self._log(gammalib.parformat('Initial TS map file')) - self._log(fitsfile) - count = self._get_number_of_ts_pixels(fitsfile) - self._log(' (%d TS pixels computed)' % count) - self._log('\n') -======= # Log message pix_info = " (%d TS pixels computed)" % self._get_number_of_ts_pixels(fitsfile) self._log_value(gammalib.TERSE, "Initial TS map file", fitsfile + pix_info) # Leave loop ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 break # ... otherwise signal that file is useless else: -<<<<<<< HEAD - fits.close() - self._log_value(gammalib.EXPLICIT, 'Skip file', - '%s (no "STATUS MAP" extension)' % fitsfile) - continue - - # Signal if no suitable file was found - if file0 == '': - if self._logTerse(): - self._log('None of the provided files seems to be a sliced ' - 'TS map file (none has a "STATUS MAP" extension).\n') - -======= # Close fits file fits.close() @@ -384,7 +321,6 @@ class cstsmapmerge(ctools.cscript): "TS map file (none has a \"STATUS MAP\" " "extension).\n") ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # ... otherwise merge files else: @@ -405,14 +341,8 @@ class cstsmapmerge(ctools.cscript): # Skip if file is not FITS if not gammalib.GFilename(fitsfile).is_fits(): -<<<<<<< HEAD - self._log_value(gammalib.EXPLICIT, 'Skip file', - '%s (not a FITS file)' % fitsfile) - continue -======= self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (not a FITS file)") continue ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # Open FITS file fits = gammalib.GFits(fitsfile) @@ -420,29 +350,15 @@ class cstsmapmerge(ctools.cscript): # Skip if file does not contain status map if not fits.contains('STATUS MAP'): fits.close() -<<<<<<< HEAD - self._log_value(gammalib.EXPLICIT, 'Skip file', - '%s (no "STATUS MAP" extension)' % fitsfile) -======= self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (no \"STATUS MAP\" extension)") ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 continue # Close FITS file fits.close() # Logging -<<<<<<< HEAD - if self._logTerse(): - self._log(gammalib.parformat('Merge TS map file')) - self._log(fitsfile) - count = self._get_number_of_ts_pixels(fitsfile) - self._log(' (%d TS pixels computed)' % count) - self._log('\n') -======= pix_info = " (%d TS pixels computed)" % self._get_number_of_ts_pixels(fitsfile) self._log_value(gammalib.TERSE, "Merge TS map file", fitsfile + pix_info) ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # Merge TS map self._merge_ts_map(fitsfile) @@ -455,22 +371,11 @@ class cstsmapmerge(ctools.cscript): def save(self): """ - Save TS map and remove slices if requested + Save TS map and remove slices if requested. """ -<<<<<<< HEAD - # Write header - self._log_header1(gammalib.TERSE, 'Save TS map') - - # Get output filename in case it was not read ahead - outmap = self['outmap'].filename() - - # Log filename - self._log_value(gammalib.TERSE, 'TS map file', outmap.url()) -======= # Get output filename in case it was not read ahead outmap = self["outmap"].filename() ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # Create FITS file fits = gammalib.GFits() @@ -504,10 +409,6 @@ class cstsmapmerge(ctools.cscript): # Write status map if we are not done yet if not done: -<<<<<<< HEAD - self._statusmap.write(fits) - fits[fits.size()-1].extname('STATUS MAP') -======= # Log bins that were computed and those that were missing self._log_value(gammalib.TERSE, "TS map bins", self._tsmap.npix()) @@ -524,7 +425,6 @@ class cstsmapmerge(ctools.cscript): # Log filename self._log_value(gammalib.TERSE, "TS map file", outmap.url()) ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # Save FITS file fits.saveto(outmap, self._clobber()) @@ -540,20 +440,16 @@ class cstsmapmerge(ctools.cscript): # Remove file os.remove(filename) -<<<<<<< HEAD - self._log_value(gammalib.TERSE, 'Deleted input file', filename) -======= # Log message about file self._log_value(gammalib.TERSE,"Deleted input file", filename) ->>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 # Return return def execute(self): """ - Execute the script + Execute the script. """ # Open logfile self.logFileOpen()