Commit ff0d52ee4d08814f6fe78005fba1c656c94f3dac

Authored by Jürgen Knödlseder
1 parent b3540bee

Adapt to new GApplication logging interface (#1828)

The new GApplication logger support function take the chattiness level as the first argument.
cscripts/csfindobs.py
@@ -174,9 +174,7 @@ class csfindobs(ctools.cscript): @@ -174,9 +174,7 @@ class csfindobs(ctools.cscript):
174 self._get_parameters() 174 self._get_parameters()
175 175
176 # Write header into logger 176 # Write header into logger
177 - if self._logTerse():  
178 - self._log('\n')  
179 - self._log.header1('Find observations') 177 + self._log_header1(gammalib.TERSE, 'Find observations')
180 178
181 # Initialise run list 179 # Initialise run list
182 self._runs = [] 180 self._runs = []
@@ -204,9 +202,7 @@ class csfindobs(ctools.cscript): @@ -204,9 +202,7 @@ class csfindobs(ctools.cscript):
204 expr += '&&' + expression 202 expr += '&&' + expression
205 203
206 # Write the expression into the logger 204 # Write the expression into the logger
207 - if self._logNormal():  
208 - self._log(gammalib.parformat('Expression'))  
209 - self._log(expr+'\n') 205 + self._log_value(gammalib.NORMAL, 'Expression', expr)
210 206
211 # Set filename including the selection expression 207 # Set filename including the selection expression
212 filename = self._obs_index+'[OBS_INDEX]['+expr+']' 208 filename = self._obs_index+'[OBS_INDEX]['+expr+']'
@@ -222,13 +218,12 @@ class csfindobs(ctools.cscript): @@ -222,13 +218,12 @@ class csfindobs(ctools.cscript):
222 self._runs.append(obs_index['OBS_ID'][i]) 218 self._runs.append(obs_index['OBS_ID'][i])
223 219
224 # Write the number of observations into the logger 220 # Write the number of observations into the logger
225 - if self._logTerse():  
226 - self._log_value('Observations', len(self._runs)) 221 + self._log_value(gammalib.TERSE, 'Observations', len(self._runs))
227 222
228 # Write the observation identifiers into the logger 223 # Write the observation identifiers into the logger
229 - if self._logNormal() and len(self._runs) > 0: 224 + if len(self._runs) > 0:
230 for i, run in enumerate(self._runs): 225 for i, run in enumerate(self._runs):
231 - self._log_value('Observation %d' % (i+1), run) 226 + self._log_value(gammalib.NORMAL, 'Observation %d' % (i+1), run)
232 227
233 # Close FITS file 228 # Close FITS file
234 fits.close() 229 fits.close()
@@ -260,9 +255,7 @@ class csfindobs(ctools.cscript): @@ -260,9 +255,7 @@ class csfindobs(ctools.cscript):
260 Save runlist 255 Save runlist
261 """ 256 """
262 # Write header 257 # Write header
263 - if self._logTerse():  
264 - self._log('\n')  
265 - self._log.header1('Save runlist') 258 + self._log_header1(gammalib.TERSE, 'Save runlist')
266 259
267 # Get filename 260 # Get filename
268 outfile = self['outfile'].filename() 261 outfile = self['outfile'].filename()
@@ -270,18 +263,15 @@ class csfindobs(ctools.cscript): @@ -270,18 +263,15 @@ class csfindobs(ctools.cscript):
270 # If the runlist file exists but the clobber flag is not set then signal 263 # If the runlist file exists but the clobber flag is not set then signal
271 # that runlist file exists already 264 # that runlist file exists already
272 if outfile.exists() and not self._clobber(): 265 if outfile.exists() and not self._clobber():
273 - if self._logTerse():  
274 - self._log('File "'+outfile+'" exists already, runlist not ')  
275 - self._log('saved. Set clobber=yes to overwrite the file.\n') 266 + msg = ('File "'+outfile+'" exists already, runlist not saved. '
  267 + 'Set clobber=yes to overwrite the file.\n')
  268 + self._log_string(gammalib.TERSE, msg)
276 269
277 # ... otherwise save the runlist into a file 270 # ... otherwise save the runlist into a file
278 else: 271 else:
279 272
280 # Log file name 273 # Log file name
281 - if self._logTerse():  
282 - self._log(gammalib.parformat('Runlist file'))  
283 - self._log(outfile.url())  
284 - self._log('\n') 274 + self._log_value(gammalib.NORMAL, 'Runlist file', outfile.url())
285 275
286 # Write all runs to file 276 # Write all runs to file
287 f = open(outfile.url(),'w') 277 f = open(outfile.url(),'w')
cscripts/csiactcopy.py
@@ -107,32 +107,25 @@ class csiactcopy(ctools.cscript): @@ -107,32 +107,25 @@ class csiactcopy(ctools.cscript):
107 107
108 # Initialise return value 108 # Initialise return value
109 filesize = 0.0 109 filesize = 0.0
  110 +
  111 + # Flag if file destination is already available
  112 + is_file = os.path.isfile(destination)
110 113
111 # Logging 114 # Logging
112 - if self._logVerbose():  
113 - self._log('\n')  
114 - self._log.header3('Copy file')  
115 - self._log_value('Source', source)  
116 - self._log_value('Destination', destination)  
117 - self._log_value('Already exists', str(os.path.isfile(destination)))  
118 - self._log_value('Overwrite', clobber)  
119 - self._log.parformat('Copying') 115 + self._log_header3(gammalib.VERBOSE, 'Copy file')
  116 + self._log_value(gammalib.VERBOSE, 'Source', source)
  117 + self._log_value(gammalib.VERBOSE, 'Destination', destination)
  118 + self._log_value(gammalib.VERBOSE, 'Already exists', is_file)
  119 + self._log_value(gammalib.VERBOSE, 'Overwrite', clobber)
120 120
121 - # Flag if file destination is already available  
122 - is_file = os.path.isfile(destination)  
123 -  
124 # check if file could be skipped because clobber=no 121 # check if file could be skipped because clobber=no
125 if is_file and clobber == False: 122 if is_file and clobber == False:
126 - if self._logVerbose():  
127 - self._log('Skip (clobber=no)')  
128 - self._log('\n') 123 + self._log_value(gammalib.VERBOSE, 'Copying', 'Skip (clobber=no)')
129 124
130 # check if file could be skipped because it is the same file 125 # check if file could be skipped because it is the same file
131 elif is_file and os.path.samefile(destination, source): 126 elif is_file and os.path.samefile(destination, source):
132 - if self._logVerbose():  
133 - self._log('Skip (same file)')  
134 - self._log('\n')  
135 - 127 + self._log_value(gammalib.VERBOSE, 'Copying', 'Skip (same file)')
  128 +
136 else: 129 else:
137 # Create directory if not existent 130 # Create directory if not existent
138 dest_dir = os.path.dirname(destination) 131 dest_dir = os.path.dirname(destination)
@@ -146,10 +139,8 @@ class csiactcopy(ctools.cscript): @@ -146,10 +139,8 @@ class csiactcopy(ctools.cscript):
146 filesize = os.stat(destination).st_size 139 filesize = os.stat(destination).st_size
147 140
148 # Logging 141 # Logging
149 - if self._logVerbose():  
150 - self._log('Done!')  
151 - self._log('\n')  
152 - 142 + self._log_value(gammalib.VERBOSE, 'Copying', 'Done!')
  143 +
153 # Return 144 # Return
154 return filesize 145 return filesize
155 146
@@ -171,15 +162,14 @@ class csiactcopy(ctools.cscript): @@ -171,15 +162,14 @@ class csiactcopy(ctools.cscript):
171 """ 162 """
172 163
173 # Logging 164 # Logging
174 - if self._logTerse():  
175 - self._log_value('Local file', localfits)  
176 - self._log_value('Remote file', remotefits)  
177 - self._log_value('HDU name', hduname)  
178 - if clobber:  
179 - preference = 'Remote'  
180 - else:  
181 - preference = 'Local'  
182 - self._log_value('Conflict preference', preference) 165 + self._log_value(gammalib.TERSE, 'Local file', localfits)
  166 + self._log_value(gammalib.TERSE, 'Remote file', remotefits)
  167 + self._log_value(gammalib.TERSE, 'HDU name', hduname)
  168 + if clobber:
  169 + preference = 'Remote'
  170 + else:
  171 + preference = 'Local'
  172 + self._log_value(gammalib.TERSE, 'Conflict preference', preference)
183 173
184 # Check if local fits file is available 174 # Check if local fits file is available
185 if os.path.isfile(localfits): 175 if os.path.isfile(localfits):
@@ -251,9 +241,8 @@ class csiactcopy(ctools.cscript): @@ -251,9 +241,8 @@ class csiactcopy(ctools.cscript):
251 remote_obs.append(obs_id) 241 remote_obs.append(obs_id)
252 242
253 # Log entries of index files 243 # Log entries of index files
254 - if self._logTerse():  
255 - self._log_value('Remote entries', len(remote_obs))  
256 - self._log_value('Local entries', len(local_obs)) 244 + self._log_value(gammalib.TERSE, 'Remote entries', len(remote_obs))
  245 + self._log_value(gammalib.TERSE, 'Local entries', len(local_obs))
257 246
258 # initialise counter for logging 247 # initialise counter for logging
259 removed_rows = 0 248 removed_rows = 0
@@ -318,12 +307,11 @@ class csiactcopy(ctools.cscript): @@ -318,12 +307,11 @@ class csiactcopy(ctools.cscript):
318 local_hdu.insert_rows(old_local_rows, remote_hdu.nrows()) 307 local_hdu.insert_rows(old_local_rows, remote_hdu.nrows())
319 308
320 # Log actions 309 # Log actions
321 - if self._logTerse():  
322 - if clobber:  
323 - what = 'Removed local rows'  
324 - else:  
325 - what = 'Skipped remote rows'  
326 - self._log_value(what, removed_rows) 310 + if clobber:
  311 + what = 'Removed local rows'
  312 + else:
  313 + what = 'Skipped remote rows'
  314 + self._log_value(gammalib.TERSE, what, removed_rows)
327 315
328 # Loop over columns 316 # Loop over columns
329 for i in range(local_hdu.ncols()): 317 for i in range(local_hdu.ncols()):
@@ -384,8 +372,8 @@ class csiactcopy(ctools.cscript): @@ -384,8 +372,8 @@ class csiactcopy(ctools.cscript):
384 runfile.close() 372 runfile.close()
385 373
386 # Logging 374 # Logging
387 - if self._logTerse():  
388 - self._log_value('Number of observations', len(self._runs)) 375 + self._log_value(gammalib.TERSE, 'Number of observations',
  376 + len(self._runs))
389 377
390 # Copy all data if runlist file is 'NONE' 378 # Copy all data if runlist file is 'NONE'
391 elif self._runlist == 'NONE': 379 elif self._runlist == 'NONE':
@@ -446,10 +434,10 @@ class csiactcopy(ctools.cscript): @@ -446,10 +434,10 @@ class csiactcopy(ctools.cscript):
446 remote_obs = os.path.join(self._remote_base, config['obsindx']) 434 remote_obs = os.path.join(self._remote_base, config['obsindx'])
447 435
448 # Log information 436 # Log information
449 - if self._logTerse():  
450 - self._log.header3('Remote config "'+self._prodname+'"')  
451 - self._log_value('HDU index', remote_hdu)  
452 - self._log_value('Observation index', remote_obs) 437 + self._log_header3(gammalib.TERSE, 'Remote config "'+
  438 + self._prodname+'"')
  439 + self._log_value(gammalib.TERSE, 'HDU index', remote_hdu)
  440 + self._log_value(gammalib.TERSE, 'Observation index', remote_obs)
453 441
454 # Open remote HDU index file 442 # Open remote HDU index file
455 fits = gammalib.GFits(str(remote_hdu)) 443 fits = gammalib.GFits(str(remote_hdu))
@@ -524,29 +512,22 @@ class csiactcopy(ctools.cscript): @@ -524,29 +512,22 @@ class csiactcopy(ctools.cscript):
524 cp_size += table['SIZE'][row] 512 cp_size += table['SIZE'][row]
525 513
526 # Log file information 514 # Log file information
527 - if self._logTerse():  
528 - self._log('\n')  
529 - self._log.header2('File information')  
530 - self._log_value('Number of files', len(files))  
531 - if has_size:  
532 - size = float(cp_size) * 1.0e-6  
533 - self._log_value('Size', '%.2f MB' % size)  
534 - if self._logVerbose():  
535 - self._log('\n')  
536 - self._log.header3('File names')  
537 - for filename in files:  
538 - self._log(str(filename)+'\n') 515 + self._log_header2(gammalib.TERSE, 'File information')
  516 + self._log_value(gammalib.TERSE, 'Number of files', len(files))
  517 + if has_size:
  518 + size = float(cp_size) * 1.0e-6
  519 + self._log_value(gammalib.TERSE, 'Size', '%.2f MB' % size)
  520 + self._log_header3(gammalib.VERBOSE, 'File names')
  521 + for filename in files:
  522 + self._log_string(gammalib.VERBOSE, str(filename)+'\n')
539 523
540 # Close HDU index file 524 # Close HDU index file
541 fits.close() 525 fits.close()
542 526
543 # If prodname is not found just log that we skip the config 527 # If prodname is not found just log that we skip the config
544 else: 528 else:
545 - if self._logExplicit():  
546 - self._log('\n')  
547 - self._log.header3('Skipping config "'+  
548 - str(config['name'])+'"')  
549 - self._log('\n') 529 + self._log_header3(gammalib.EXPLICIT, 'Skipping config "'+
  530 + str(config['name'])+'"')
550 531
551 # Raise Exception if prodname was not found 532 # Raise Exception if prodname was not found
552 if not has_prod: 533 if not has_prod:
@@ -556,10 +537,8 @@ class csiactcopy(ctools.cscript): @@ -556,10 +537,8 @@ class csiactcopy(ctools.cscript):
556 msg += ' - '+config['name']+'\n' 537 msg += ' - '+config['name']+'\n'
557 raise RuntimeError(msg) 538 raise RuntimeError(msg)
558 539
559 - # Logging  
560 - if self._logNormal():  
561 - self._log('\n')  
562 - self._log.header1('Copying files') 540 + # Write header
  541 + self._log_header1(gammalib.NORMAL, 'Copying files')
563 542
564 # Intialise counter 543 # Intialise counter
565 k = 0 544 k = 0
@@ -592,8 +571,8 @@ class csiactcopy(ctools.cscript): @@ -592,8 +571,8 @@ class csiactcopy(ctools.cscript):
592 while fraction > last_fraction: 571 while fraction > last_fraction:
593 572
594 # Print status of copying procedure 573 # Print status of copying procedure
595 - if self._logNormal() and not self._logVerbose():  
596 - self._log_value('Status', '%d %%' % int(last_fraction)) 574 + self._log_value(gammalib.NORMAL, 'Status', '%d %%' %
  575 + int(last_fraction))
597 last_fraction += fraction_increment 576 last_fraction += fraction_increment
598 577
599 # Copy file 578 # Copy file
@@ -632,17 +611,13 @@ class csiactcopy(ctools.cscript): @@ -632,17 +611,13 @@ class csiactcopy(ctools.cscript):
632 if len(self._runs): 611 if len(self._runs):
633 612
634 # Logging 613 # Logging
635 - if self._logTerse():  
636 - self._log('\n')  
637 - self._log.header3('HDU index') 614 + self._log_header3(gammalib.TERSE, 'HDU index')
638 615
639 # Merge remote index files with local files 616 # Merge remote index files with local files
640 self._merge(local_hdu, remote_hdu, 'HDU_INDEX', self._clobber()) 617 self._merge(local_hdu, remote_hdu, 'HDU_INDEX', self._clobber())
641 618
642 # Logging 619 # Logging
643 - if self._logTerse():  
644 - self._log('\n')  
645 - self._log.header3('OBS index') 620 + self._log_header3(gammalib.TERSE, 'OBS index')
646 621
647 # Merge remote index files with local files 622 # Merge remote index files with local files
648 self._merge(local_obs, remote_obs, 'OBS_INDEX', self._clobber()) 623 self._merge(local_obs, remote_obs, 'OBS_INDEX', self._clobber())
@@ -653,9 +628,7 @@ class csiactcopy(ctools.cscript): @@ -653,9 +628,7 @@ class csiactcopy(ctools.cscript):
653 self._copy(remote_obs, self._clobber()) 628 self._copy(remote_obs, self._clobber())
654 629
655 # Logging 630 # Logging
656 - if self._logTerse():  
657 - self._log('\n')  
658 - self._log.header3('Master index file') 631 + self._log_header3(gammalib.TERSE, 'Master index file')
659 632
660 # Adding prodname to local master 633 # Adding prodname to local master
661 localmaster = os.path.join(self._outpath, 'master.json') 634 localmaster = os.path.join(self._outpath, 'master.json')
@@ -722,20 +695,18 @@ class csiactcopy(ctools.cscript): @@ -722,20 +695,18 @@ class csiactcopy(ctools.cscript):
722 json.dump(data, f, indent=2) 695 json.dump(data, f, indent=2)
723 f.close() 696 f.close()
724 697
  698 + # Compute total size in MB
  699 + size_MB = float(total_size) * 1.0e-6
  700 +
725 # Log summary 701 # Log summary
726 - if self._logNormal():  
727 - self._log('\n')  
728 - self._log.header1('Summary')  
729 - self._log_value('Data files found', len(files))  
730 - self._log_value('Data files copied', n_copied)  
731 - self._log_value('Size', '%.2f MB' % (float(total_size)*1.0e-6))  
732 - self._log_value('Local configs', len(newconfigs))  
733 - if self._logTerse():  
734 - self._log('\n')  
735 - self._log.header3('Content of master index')  
736 - for config in newconfigs:  
737 - self._log(str(config['name']))  
738 - self._log('\n') 702 + self._log_header1(gammalib.NORMAL, 'Summary')
  703 + self._log_value(gammalib.NORMAL, 'Data files found', len(files))
  704 + self._log_value(gammalib.NORMAL, 'Data files copied', n_copied)
  705 + self._log_value(gammalib.NORMAL, 'Size', '%.2f MB' % size_MB)
  706 + self._log_value(gammalib.NORMAL, 'Local configs', len(newconfigs))
  707 + self._log_header3(gammalib.TERSE, 'Content of master index')
  708 + for config in newconfigs:
  709 + self._log_string(gammalib.TERSE, str(config['name'])+'\n')
739 710
740 # Return 711 # Return
741 return 712 return
cscripts/csiactdata.py
@@ -98,24 +98,20 @@ class csiactdata(ctools.cscript): @@ -98,24 +98,20 @@ class csiactdata(ctools.cscript):
98 ---------- 98 ----------
99 config : dict 99 config : dict
100 Dictionary containing data configuration 100 Dictionary containing data configuration
101 -  
102 """ 101 """
103 - # Log only if the level is at least "Terse"  
104 - if self._logTerse():  
105 -  
106 - # Log configuration information  
107 - self._log.header3(str(config['name']))  
108 - self._log_value('Name', config['name'])  
109 - self._log_value('Observation index', config['obsindx'])  
110 - self._log_value('HDU index', config['hduindx']) 102 + # Log configuration information
  103 + self._log_header3(gammalib.TERSE, str(config['name']))
  104 + self._log_value(gammalib.TERSE, 'Name', config['name'])
  105 + self._log_value(gammalib.TERSE, 'Observation index', config['obsindx'])
  106 + self._log_value(gammalib.TERSE, 'HDU index', config['hduindx'])
111 107
112 - # Print additional information  
113 - for key in config: 108 + # Print additional information
  109 + for key in config:
114 110
115 - # Skip keys that were treated above  
116 - if key in ['name','hduindx','obsindx']:  
117 - continue  
118 - self._log_value(key, config[key]) 111 + # Skip keys that were treated above
  112 + if key in ['name','hduindx','obsindx']:
  113 + continue
  114 + self._log_value(gammalib.TERSE, key, config[key])
119 115
120 # Return 116 # Return
121 return 117 return
cscripts/csiactobs.py
@@ -401,11 +401,9 @@ class csiactobs(ctools.cscript): @@ -401,11 +401,9 @@ class csiactobs(ctools.cscript):
401 filename = self['inmodel'].filename().url() 401 filename = self['inmodel'].filename().url()
402 if filename != '' and filename != 'NONE': 402 if filename != '' and filename != 'NONE':
403 403
404 - # Write header  
405 - if self._logTerse():  
406 - self._log('\n')  
407 - self._log.header1('Append input models')  
408 - self._log_value('Input model file', filename) 404 + # Log header and input model file
  405 + self._log_header1(gammalib.TERSE, 'Append input models')
  406 + self._log_value(gammalib.NORMAL, 'Input model file', filename)
409 407
410 # Load input models 408 # Load input models
411 models = gammalib.GModels(filename) 409 models = gammalib.GModels(filename)
@@ -413,8 +411,8 @@ class csiactobs(ctools.cscript): @@ -413,8 +411,8 @@ class csiactobs(ctools.cscript):
413 # Loop over input models and append them to the model container 411 # Loop over input models and append them to the model container
414 for model in models: 412 for model in models:
415 self._models.append(model) 413 self._models.append(model)
416 - if self._logTerse():  
417 - self._log_value('Append model', '"'+model.name()+'"') 414 + self._log_value(gammalib.NORMAL, 'Append model',
  415 + '"'+model.name()+'"')
418 416
419 # Return 417 # Return
420 return 418 return
@@ -423,23 +421,19 @@ class csiactobs(ctools.cscript): @@ -423,23 +421,19 @@ class csiactobs(ctools.cscript):
423 """ 421 """
424 Write observation summary 422 Write observation summary
425 """ 423 """
426 - # Write observation summary  
427 - if self._logTerse(): 424 + # Log header
  425 + self._log_header1(gammalib.TERSE, 'Observation summary')
  426 +
  427 + # Set energy range dependent on whether boundaries exist or
  428 + # not
  429 + if self._ebounds.size() > 0:
  430 + erange = '%s - %s' % (str(self._ebounds.emin()),
  431 + str(self._ebounds.emax()))
  432 + else:
  433 + erange = 'not available'
428 434
429 - # Log header  
430 - self._log('\n')  
431 - self._log.header1('Observation summary')  
432 -  
433 - # Set energy range dependent on whether boundaries exist or  
434 - # not  
435 - if self._ebounds.size() > 0:  
436 - erange = '%s - %s' % (str(self._ebounds.emin()),  
437 - str(self._ebounds.emax()))  
438 - else:  
439 - erange = 'not available'  
440 -  
441 - # Log energy range  
442 - self._log_value('Energy range', erange) 435 + # Log energy range
  436 + self._log_value(gammalib.NORMAL, 'Energy range', erange)
443 437
444 # Return 438 # Return
445 return 439 return
@@ -712,19 +706,17 @@ class csiactobs(ctools.cscript): @@ -712,19 +706,17 @@ class csiactobs(ctools.cscript):
712 obs.append(bck) 706 obs.append(bck)
713 707
714 # Log the observation ID and object name that has been appended 708 # Log the observation ID and object name that has been appended
715 - if self._logTerse():  
716 - self._log_value('Append observation', '%s ("%s")' %  
717 - (obs_id, object_name)) 709 + self._log_value(gammalib.TERSE, 'Append observation', '%s ("%s")' %
  710 + (obs_id, object_name))
718 711
719 # Log the file names of the event and response files 712 # Log the file names of the event and response files
720 - if self._logExplicit():  
721 - self._log_value(' Event file', eventfile)  
722 - self._log_value(' Effective area file', aefffile)  
723 - self._log_value(' Point spread function file', psffile)  
724 - self._log_value(' Energy dispersion file', edispfile)  
725 - self._log_value(' Background file', bkgfile)  
726 - if self._use_bkg_scale:  
727 - self._log_value(' Background scale', bkg_scale) 713 + self._log_value(gammalib.EXPLICIT, ' Event file', eventfile)
  714 + self._log_value(gammalib.EXPLICIT, ' Effective area file', aefffile)
  715 + self._log_value(gammalib.EXPLICIT, ' Point spread function file', psffile)
  716 + self._log_value(gammalib.EXPLICIT, ' Energy dispersion file', edispfile)
  717 + self._log_value(gammalib.EXPLICIT, ' Background file', bkgfile)
  718 + if self._use_bkg_scale:
  719 + self._log_value(gammalib.EXPLICIT, ' Background scale', bkg_scale)
728 720
729 # Append models provided by "inmodel" to the model container 721 # Append models provided by "inmodel" to the model container
730 self._append_inmodels() 722 self._append_inmodels()
cscripts/cslightcrv.py
@@ -558,9 +558,8 @@ class cslightcrv(ctools.cscript): @@ -558,9 +558,8 @@ class cslightcrv(ctools.cscript):
558 if like.obs().logL() == 0.0: 558 if like.obs().logL() == 0.0:
559 559
560 # Signal skipping of bin 560 # Signal skipping of bin
561 - if self._logTerse():  
562 - self._log_value('Warning', 'No event in this time bin, '  
563 - 'skip bin.') 561 + self._log_value(gammalib.TERSE, 'Warning',
  562 + 'No event in this time bin, skip bin.')
564 563
565 # Set all results to 0 564 # Set all results to 0
566 for par in pars: 565 for par in pars:
@@ -594,19 +593,19 @@ class cslightcrv(ctools.cscript): @@ -594,19 +593,19 @@ class cslightcrv(ctools.cscript):
594 results.append(result) 593 results.append(result)
595 594
596 # Log results for this time bin 595 # Log results for this time bin
597 - if self._logNormal():  
598 - self._log.header3('Results')  
599 - pars = self._get_free_par_names()  
600 - for par in pars:  
601 - value = source.spectral()[par].value()  
602 - error = source.spectral()[par].error()  
603 - unit = source.spectral()[par].unit()  
604 - self._log_value(par, str(value)+' +/- '+str(error)+' '+unit)  
605 - if result['ulimit'] > 0.0:  
606 - self._log_value('Upper flux limit', str(result['ulimit'])+  
607 - ' ph/cm2/s')  
608 - if self['calc_ts'].boolean():  
609 - self._log_value('Test Statistic', result['ts']) 596 + self._log.header3('Results')
  597 + pars = self._get_free_par_names()
  598 + for par in pars:
  599 + value = source.spectral()[par].value()
  600 + error = source.spectral()[par].error()
  601 + unit = source.spectral()[par].unit()
  602 + self._log_value(gammalib.NORMAL, par,
  603 + str(value)+' +/- '+str(error)+' '+unit)
  604 + if result['ulimit'] > 0.0:
  605 + self._log_value(gammalib.NORMAL, 'Upper flux limit',
  606 + str(result['ulimit'])+' ph/cm2/s')
  607 + if self['calc_ts'].boolean():
  608 + self._log_value(gammalib.NORMAL, 'Test Statistic', result['ts'])
610 609
611 # Create FITS table from results 610 # Create FITS table from results
612 table = self._create_fits_table(results) 611 table = self._create_fits_table(results)
@@ -642,9 +641,7 @@ class cslightcrv(ctools.cscript): @@ -642,9 +641,7 @@ class cslightcrv(ctools.cscript):
642 Save light curve 641 Save light curve
643 """ 642 """
644 # Write header 643 # Write header
645 - if self._logTerse():  
646 - self._log('\n')  
647 - self._log.header1('Save light curve') 644 + self._log_header1(gammalib.TERSE, 'Save light curve')
648 645
649 # Get light curve filename 646 # Get light curve filename
650 outfile = self['outfile'].filename() 647 outfile = self['outfile'].filename()
@@ -653,8 +650,7 @@ class cslightcrv(ctools.cscript): @@ -653,8 +650,7 @@ class cslightcrv(ctools.cscript):
653 if self._fits != None: 650 if self._fits != None:
654 651
655 # Log file name 652 # Log file name
656 - if self._logTerse():  
657 - self._log_value('Light curve file', outfile.url()) 653 + self._log_value(gammalib.NORMAL, 'Light curve file', outfile.url())
658 654
659 # Save spectrum 655 # Save spectrum
660 self._fits.saveto(outfile, self._clobber()) 656 self._fits.saveto(outfile, self._clobber())
cscripts/csmodelinfo.py
@@ -337,62 +337,57 @@ class csmodelinfo(ctools.cscript): @@ -337,62 +337,57 @@ class csmodelinfo(ctools.cscript):
337 if self._logTerse(): 337 if self._logTerse():
338 338
339 # Log summary 339 # Log summary
340 - self._log('\n')  
341 - self._log.header1('Summary') 340 + self._log_header1(gammalib.TERSE, 'Summary')
342 341
343 # Log instruments 342 # Log instruments
344 self._log.header3('Instrument specific models') 343 self._log.header3('Instrument specific models')
345 for inst, n_inst in instruments.items(): 344 for inst, n_inst in instruments.items():
346 if inst == '': 345 if inst == '':
347 inst = 'All' 346 inst = 'All'
348 - self._log_value(inst, n_inst) 347 + self._log_value(gammalib.TERSE, inst, n_inst)
349 348
350 # Log model types 349 # Log model types
351 - self._log.header3('Model types') 350 + self._log_header3(gammalib.TERSE, 'Model types')
352 for modeltype, n_types in types.items(): 351 for modeltype, n_types in types.items():
353 - self._log_value(modeltype, n_types) 352 + self._log_value(gammalib.TERSE, modeltype, n_types)
354 353
355 # Log model parameter information 354 # Log model parameter information
356 - self._log('\n')  
357 - self._log.header1('Parameter information')  
358 - self._log_value('All parameters', n_par_total)  
359 - self._log_value('Fixed parameters', n_par_fixed)  
360 - self._log_value('Free parameters (total)', n_par_free)  
361 - self._log_value('Free background parameters', n_par_free_bkg)  
362 - self._log_value('Free source parameters', n_par_free_src) 355 + self._log_header1(gammalib.TERSE,'Parameter information')
  356 + self._log_value(gammalib.TERSE,'All parameters', n_par_total)
  357 + self._log_value(gammalib.TERSE,'Fixed parameters', n_par_fixed)
  358 + self._log_value(gammalib.TERSE,'Free parameters (total)', n_par_free)
  359 + self._log_value(gammalib.TERSE,'Free background parameters', n_par_free_bkg)
  360 + self._log_value(gammalib.TERSE,'Free source parameters', n_par_free_src)
363 if n_par_free_spec > 0: 361 if n_par_free_spec > 0:
364 - self._log_value('Free spectral parameters', n_par_free_spec) 362 + self._log_value(gammalib.TERSE,'Free spectral parameters', n_par_free_spec)
365 if n_par_free_spat > 0: 363 if n_par_free_spat > 0:
366 - self._log_value('Free spatial parameters', n_par_free_spat) 364 + self._log_value(gammalib.TERSE,'Free spatial parameters', n_par_free_spat)
367 if n_par_free_temp > 0: 365 if n_par_free_temp > 0:
368 - self._log_value('Free temporal parameters', n_par_free_temp)  
369 - self._log_value('Parameters at limit', n_par_at_limit) 366 + self._log_value(gammalib.TERSE,'Free temporal parameters', n_par_free_temp)
  367 + self._log_value(gammalib.TERSE,'Parameters at limit', n_par_at_limit)
370 368
371 # Log parameters at limit (if any) 369 # Log parameters at limit (if any)
372 if n_par_at_limit > 0: 370 if n_par_at_limit > 0:
373 - self._log.header3('Parameters at limit') 371 + self._log_header3(gammalib.TERSE, 'Parameters at limit')
374 for source, parameter in pars_at_limit.items(): 372 for source, parameter in pars_at_limit.items():
375 if len(parameter): 373 if len(parameter):
376 for par in parameter: 374 for par in parameter:
377 self._log_value(source, par) 375 self._log_value(source, par)
378 376
379 # Optionally log free parameters 377 # Optionally log free parameters
380 - if self._logExplicit() and len(free_src_pars):  
381 - self._log('\n')  
382 - self._log.header2('Free source parameters') 378 + if len(free_src_pars):
  379 + self._log_header2(gammalib.EXPLICIT, 'Free source parameters')
383 for source, parameter in free_src_pars.items(): 380 for source, parameter in free_src_pars.items():
384 if len(parameter): 381 if len(parameter):
385 self._log.header3(source) 382 self._log.header3(source)
386 for par in parameter: 383 for par in parameter:
387 - self._log(str(par))  
388 - self._log('\n')  
389 - self._log('\n') 384 + self._log_string(gammalib.EXPLICIT, str(par)+'\n')
390 385
391 # Log TS values if available 386 # Log TS values if available
392 if len(ts): 387 if len(ts):
393 - self._log.header3('Test statistics') 388 + self._log_header3(gammalib.TERSE, 'Test statistics')
394 for source, tsvalue in ts.items(): 389 for source, tsvalue in ts.items():
395 - self._log_value(source, tsvalue) 390 + self._log_value(gammalib.TERSE, source, tsvalue)
396 391
397 # Return 392 # Return
398 return 393 return
@@ -408,13 +403,10 @@ class csmodelinfo(ctools.cscript): @@ -408,13 +403,10 @@ class csmodelinfo(ctools.cscript):
408 if ds9file != '' and ds9file != 'NONE': 403 if ds9file != '' and ds9file != 'NONE':
409 404
410 # Write header 405 # Write header
411 - if self._logTerse():  
412 - self._log('\n')  
413 - self._log.header1('Save models in DS9 file') 406 + self._log_header1(gammalib.TERSE, 'Save models in DS9 file')
414 407
415 # Log filename 408 # Log filename
416 - if self._logTerse():  
417 - self._log_value('DS9 filename', ds9file.url()) 409 + self._log_value(gammalib.NORMAL, 'DS9 filename', ds9file.url())
418 410
419 # Open file 411 # Open file
420 f = open(ds9file.url(), 'w') 412 f = open(ds9file.url(), 'w')
cscripts/csmodelmerge.py
@@ -141,22 +141,21 @@ class csmodelmerge(ctools.cscript): @@ -141,22 +141,21 @@ class csmodelmerge(ctools.cscript):
141 models = gammalib.GModels(f) 141 models = gammalib.GModels(f)
142 142
143 # Log number of models to add 143 # Log number of models to add
144 - if self._logTerse():  
145 - nmodels = models.size()  
146 - if nmodels == 0:  
147 - name = 'Add no model from file'  
148 - elif nmodels == 1:  
149 - name = 'Add 1 model from file'  
150 - else:  
151 - name = 'Add %d models from file' % nmodels  
152 - self._log_value(name, f) 144 + nmodels = models.size()
  145 + if nmodels == 0:
  146 + name = 'Add no model from file'
  147 + elif nmodels == 1:
  148 + name = 'Add 1 model from file'
  149 + else:
  150 + name = 'Add %d models from file' % nmodels
  151 + self._log_value(gammalib.TERSE, name, f)
153 152
154 # Extend model container by adding all models in the model file 153 # Extend model container by adding all models in the model file
155 self._models.extend(models) 154 self._models.extend(models)
156 155
157 # Log total number of models 156 # Log total number of models
158 - if self._logTerse():  
159 - self._log_value('Models after merging', self._models.size()) 157 + self._log_value(gammalib.TERSE, 'Models after merging',
  158 + self._models.size())
160 159
161 # Return 160 # Return
162 return 161 return
@@ -166,24 +165,22 @@ class csmodelmerge(ctools.cscript): @@ -166,24 +165,22 @@ class csmodelmerge(ctools.cscript):
166 Save model definition XML file 165 Save model definition XML file
167 """ 166 """
168 # Write header 167 # Write header
169 - if self._logTerse():  
170 - self._log('\n')  
171 - self._log.header1('Save models') 168 + self._log_header1(gammalib.TERSE, 'Save models')
172 169
173 # Get output filename in case it was not read ahead 170 # Get output filename in case it was not read ahead
174 outmodel = self['outmodel'].filename() 171 outmodel = self['outmodel'].filename()
175 172
176 # If file exists and clobber flag is false then raise an exception 173 # If file exists and clobber flag is false then raise an exception
177 if outmodel.exists() and not self._clobber: 174 if outmodel.exists() and not self._clobber:
178 - msg = 'Cannot save ""+outmodel.url()+"": File already exists. '\  
179 - 'Use parameter clobber=yes to allow overwriting of files.' 175 + msg = ('Cannot save "'+outmodel.url()+'": File already exists. '
  176 + 'Use parameter clobber=yes to allow overwriting of files.')
180 raise RuntimeError(msg) 177 raise RuntimeError(msg)
181 178
182 else: 179 else:
183 180
184 # Log filename 181 # Log filename
185 - if self._logTerse():  
186 - self._log_value('Model definition XML file', outmodel.url()) 182 + self._log_value(gammalib.NORMAL, 'Model definition XML file',
  183 + outmodel.url())
187 184
188 # Save models 185 # Save models
189 self._models.save(outmodel) 186 self._models.save(outmodel)
cscripts/csobs2caldb.py
@@ -153,12 +153,11 @@ class csobs2caldb(ctools.cscript): @@ -153,12 +153,11 @@ class csobs2caldb(ctools.cscript):
153 fname_bkg = rsp.background().filename() 153 fname_bkg = rsp.background().filename()
154 154
155 # Log filenames 155 # Log filenames
156 - if self._logNormal():  
157 - self._log.header3('IRF input files')  
158 - self._log_value('Effective area', fname_aeff.url())  
159 - self._log_value('Point spread function', fname_psf.url())  
160 - self._log_value('Energy dispersion', fname_edisp.url())  
161 - self._log_value('Background rate', fname_bkg.url()) 156 + self._log_header3(gammalib.NORMAL, 'IRF input files')
  157 + self._log_value(gammalib.NORMAL, 'Effective area', fname_aeff.url())
  158 + self._log_value(gammalib.NORMAL, 'Point spread function', fname_psf.url())
  159 + self._log_value(gammalib.NORMAL, 'Energy dispersion', fname_edisp.url())
  160 + self._log_value(gammalib.NORMAL, 'Background rate', fname_bkg.url())
162 161
163 # Open FITS files of response components 162 # Open FITS files of response components
164 fits_aeff = gammalib.GFits(fname_aeff) 163 fits_aeff = gammalib.GFits(fname_aeff)
@@ -325,14 +324,13 @@ class csobs2caldb(ctools.cscript): @@ -325,14 +324,13 @@ class csobs2caldb(ctools.cscript):
325 self._rsp_dir = caldb.rootdir() + "/" + self._cal_dir 324 self._rsp_dir = caldb.rootdir() + "/" + self._cal_dir
326 325
327 # Log resulting FITS table 326 # Log resulting FITS table
328 - if self._logNormal():  
329 - self._log_value('Calibration directory', self._cal_dir)  
330 - self._log_value('Base directory', self._base_dir)  
331 - if not os.path.isdir(self._rsp_dir):  
332 - name = 'IRF directory'  
333 - else:  
334 - name = 'IRF directory (existing)'  
335 - self._log_value(name, self._rsp_dir) 327 + self._log_value(gammalib.NORMAL, 'Calibration directory', self._cal_dir)
  328 + self._log_value(gammalib.NORMAL, 'Base directory', self._base_dir)
  329 + if not os.path.isdir(self._rsp_dir):
  330 + name = 'IRF directory'
  331 + else:
  332 + name = 'IRF directory (existing)'
  333 + self._log_value(gammalib.NORMAL, name, self._rsp_dir)
336 334
337 # Create IRF directory is it does not yet exist 335 # Create IRF directory is it does not yet exist
338 if not os.path.isdir(self._rsp_dir): 336 if not os.path.isdir(self._rsp_dir):
@@ -376,17 +374,15 @@ class csobs2caldb(ctools.cscript): @@ -376,17 +374,15 @@ class csobs2caldb(ctools.cscript):
376 Save calibration database FITS file 374 Save calibration database FITS file
377 """ 375 """
378 # Write header into logger 376 # Write header into logger
379 - if self._logTerse():  
380 - self._log('\n')  
381 - self._log.header1('Save calibration database') 377 + self._log_header1(gammalib.TERSE, 'Save calibration database')
382 378
383 # Set response filename 379 # Set response filename
384 filename = self._rsp_dir + '/' + self._outfile 380 filename = self._rsp_dir + '/' + self._outfile
385 381
386 # Write filenames into logger 382 # Write filenames into logger
387 - if self._logNormal():  
388 - self._log_value('CALDB index file', self._caldb_inx.filename().url())  
389 - self._log_value('Response file', filename) 383 + self._log_value(gammalib.NORMAL, 'CALDB index file',
  384 + self._caldb_inx.filename().url())
  385 + self._log_value(gammalib.NORMAL, 'Response file', filename)
390 386
391 # Save caldb index file 387 # Save caldb index file
392 self._caldb_inx.save(self._clobber()) 388 self._caldb_inx.save(self._clobber())
cscripts/csobsdef.py
@@ -177,9 +177,8 @@ class csobsdef(ctools.cscript): @@ -177,9 +177,8 @@ class csobsdef(ctools.cscript):
177 self._get_parameters() 177 self._get_parameters()
178 178
179 # Write header into logger 179 # Write header into logger
180 - if self._logTerse():  
181 - self._log('\n')  
182 - self._log.header1('Creating observation definition XML file') 180 + self._log_header1(gammalib.TERSE,
  181 + 'Creating observation definition XML file')
183 182
184 # Load pointing definition file if it is not already set. Extract 183 # Load pointing definition file if it is not already set. Extract
185 # the number of columns and pointings 184 # the number of columns and pointings
@@ -335,13 +334,10 @@ class csobsdef(ctools.cscript): @@ -335,13 +334,10 @@ class csobsdef(ctools.cscript):
335 obs.events(event_list) 334 obs.events(event_list)
336 335
337 # Write observation into logger 336 # Write observation into logger
338 - if self._logExplicit():  
339 - self._log(str(obs))  
340 - self._log('\n')  
341 - elif self._logTerse():  
342 - name = obs.instrument()+' observation'  
343 - value = 'Name="%s" ID="%s"' % (obs.name(), obs.id())  
344 - self._log_value(name, value) 337 + name = obs.instrument()+' observation'
  338 + value = 'Name="%s" ID="%s"' % (obs.name(), obs.id())
  339 + self._log_value(gammalib.TERSE, name, value)
  340 + self._log_string(gammalib.EXPLICIT, str(obs)+'\n')
345 341
346 # Append observation 342 # Append observation
347 self._obs.append(obs) 343 self._obs.append(obs)
@@ -354,9 +350,7 @@ class csobsdef(ctools.cscript): @@ -354,9 +350,7 @@ class csobsdef(ctools.cscript):
354 Save observation definition XML file. 350 Save observation definition XML file.
355 """ 351 """
356 # Write header and filename into logger 352 # Write header and filename into logger
357 - if self._logTerse():  
358 - self._log('\n')  
359 - self._log.header1('Save observation definition XML file') 353 + self._log_header1(gammalib.TERSE, 'Save observation definition XML file')
360 354
361 # Get output filename in case it was not read ahead 355 # Get output filename in case it was not read ahead
362 outobs = self['outobs'].filename() 356 outobs = self['outobs'].filename()
@@ -365,8 +359,7 @@ class csobsdef(ctools.cscript): @@ -365,8 +359,7 @@ class csobsdef(ctools.cscript):
365 if outobs.url() != 'NONE': 359 if outobs.url() != 'NONE':
366 360
367 # Log filename 361 # Log filename
368 - if self._logTerse():  
369 - self._log_value('Observation XML file', outobs.url()) 362 + self._log_value(gammalib.NORMAL, 'Observation XML file', outobs.url())
370 363
371 # Save observation definition XML file 364 # Save observation definition XML file
372 self._obs.save(outobs) 365 self._obs.save(outobs)
cscripts/csobsinfo.py
@@ -178,15 +178,15 @@ class csobsinfo(ctools.cscript): @@ -178,15 +178,15 @@ class csobsinfo(ctools.cscript):
178 if obs.eventtype() == 'CountsCube': 178 if obs.eventtype() == 'CountsCube':
179 n_eventbins += obs.events().size() 179 n_eventbins += obs.events().size()
180 n_obs_binned += 1 180 n_obs_binned += 1
181 - if self._logTerse():  
182 - self._log_value('Binned', 'yes')  
183 - self._log_value('Number of bins', obs.events().size()) 181 + is_binned = 'yes'
  182 + is_what = 'Number of bins'
184 else: 183 else:
185 n_events += obs.events().size() 184 n_events += obs.events().size()
186 n_obs_unbinned += 1 185 n_obs_unbinned += 1
187 - if self._logTerse():  
188 - self._log_value('Binned', 'no')  
189 - self._log_value('Number of events', obs.events().size()) 186 + is_binned = 'no'
  187 + is_what = 'Number of events'
  188 + self._log_value(gammalib.TERSE, 'Binned', is_binned)
  189 + self._log_value(gammalib.TERSE, is_what, obs.events().size())
190 190
191 # Retrieve zenith and azimuth and store for later use 191 # Retrieve zenith and azimuth and store for later use
192 zenith = obs.pointing().zenith() 192 zenith = obs.pointing().zenith()
@@ -224,86 +224,100 @@ class csobsinfo(ctools.cscript): @@ -224,86 +224,100 @@ class csobsinfo(ctools.cscript):
224 self._log(str(obs_gti.tstop().mjd())) 224 self._log(str(obs_gti.tstop().mjd()))
225 self._log('\n') 225 self._log('\n')
226 226
227 - # Log observation information  
228 - self._log_value('Ontime', '%.3f s' % obs.ontime())  
229 - self._log_value('Livetime', '%.3f s' % obs.livetime())  
230 - self._log_value('Deadtime fraction', '%.3f %%' % deadfrac)  
231 - self._log_value('Pointing', pnt_dir)  
232 -  
233 - # Optionally log offset with respect to target direction  
234 - if self._compute_offset:  
235 - self._log_value('Offset from target', '%.2f deg' % offset)  
236 -  
237 - # Log Zenith and Azimuth angles  
238 - self._log_value('Zenith angle', '%.2f deg' % zenith)  
239 - self._log_value('Azimuth angle', '%.2f deg' % azimuth)  
240 -  
241 - # Log summary  
242 - if self._logTerse():  
243 -  
244 - # Write header  
245 - self._log('\n')  
246 - self._log.header1('Summary')  
247 -  
248 - # Log general summary  
249 - self._log.header3('Observations')  
250 - self._log_value('Unbinned observations', n_obs_unbinned)  
251 - self._log_value('Binned observations', n_obs_binned)  
252 - self._log_value('Binned observations', n_obs_binned)  
253 - self._log.header3('Events')  
254 - self._log_value('Number of events', n_events)  
255 - self._log_value('Number of bins', n_eventbins)  
256 -  
257 - # Log pointing summary  
258 - self._log.header3('Pointings')  
259 -  
260 - # Log mean offset if possible 227 + # Log observation information
  228 + self._log_value(gammalib.TERSE, 'Ontime', '%.3f s' %
  229 + obs.ontime())
  230 + self._log_value(gammalib.TERSE, 'Livetime', '%.3f s' %
  231 + obs.livetime())
  232 + self._log_value(gammalib.TERSE, 'Deadtime fraction', '%.3f %%' %
  233 + deadfrac)
  234 + self._log_value(gammalib.TERSE, 'Pointing', pnt_dir)
  235 +
  236 + # Optionally log offset with respect to target direction
261 if self._compute_offset: 237 if self._compute_offset:
262 - self._log_value('Mean offset angle', '%.2f deg' %  
263 - (sum(self._offsets)/len(self._offsets)))  
264 -  
265 - # Log mean azimuth and zenith angle  
266 - self._log_value('Mean zenith angle', '%.2f deg' %  
267 - (sum(self._zeniths)/len(self._zeniths)))  
268 - self._log_value('Mean azimuth angle', '%.2f deg' %  
269 - (sum(self._azimuths)/len(self._azimuths))) 238 + self._log_value(gammalib.TERSE,
  239 + 'Offset from target', '%.2f deg' % offset)
  240 +
  241 + # Log Zenith and Azimuth angles
  242 + self._log_value(gammalib.TERSE, 'Zenith angle', '%.2f deg' %
  243 + zenith)
  244 + self._log_value(gammalib.TERSE, 'Azimuth angle', '%.2f deg' %
  245 + azimuth)
  246 +
  247 + # Write summary header
  248 + self._log_string(gammalib.TERSE, '\n')
  249 + self._log_header1(gammalib.TERSE, 'Summary')
  250 +
  251 + # Log general summary
  252 + self._log_header3(gammalib.TERSE, 'Observations')
  253 + self._log_value(gammalib.TERSE, 'Unbinned observations', n_obs_unbinned)
  254 + self._log_value(gammalib.TERSE, 'Binned observations', n_obs_binned)
  255 + self._log_value(gammalib.TERSE, 'Binned observations', n_obs_binned)
  256 + self._log_header3(gammalib.TERSE, 'Events')
  257 + self._log_value(gammalib.TERSE, 'Number of events', n_events)
  258 + self._log_value(gammalib.TERSE, 'Number of bins', n_eventbins)
  259 +
  260 +
  261 + # Compute mean offset, azimuth and zenith angle
  262 + if len(self._offsets) > 0:
  263 + mean_offset = sum(self._offsets) / len(self._offsets)
  264 + else:
  265 + mean_offset = 'Unknown'
  266 + if len(self._zeniths) > 0:
  267 + mean_zenith = sum(self._zeniths) / len(self._zeniths)
  268 + else:
  269 + mean_zenith = 'Unknown'
  270 + if len(self._azimuths) > 0:
  271 + mean_azimuth = sum(self._azimuths) / len(self._azimuths)
  272 + else:
  273 + mean_azimuth = 'Unknown'
270 274
271 - # Optionally log names of observations. Note that the set class  
272 - # is used to extract all different observation names from the  
273 - # list of observation names, and the set class is only available  
274 - # from Python 2.4 on.  
275 - if self._logExplicit() and sys.version_info >= (2,4):  
276 - obs_set = set(obs_names)  
277 - for name in obs_set:  
278 - self._log_value('"'+name+'"', obs_names.count(name))  
279 - self._log('\n') 275 + # Log mean offset, azimuth and zenith angle
  276 + self._log_header3(gammalib.TERSE, 'Pointings')
  277 + self._log_value(gammalib.TERSE, 'Mean offset angle', '%.2f deg' %
  278 + mean_offset)
  279 + self._log_value(gammalib.TERSE, 'Mean zenith angle', '%.2f deg' %
  280 + mean_zenith)
  281 + self._log_value(gammalib.TERSE, 'Mean azimuth angle', '%.2f deg' %
  282 + mean_azimuth)
  283 +
  284 + # Optionally log names of observations. Note that the set class is
  285 + # used to extract all different observation names from the list of
  286 + # observation names, and the set class is only available from
  287 + # Python 2.4 on.
  288 + if sys.version_info >= (2,4):
  289 + obs_set = set(obs_names)
  290 + for name in obs_set:
  291 + self._log_value(gammalib.EXPLICIT,'"'+name+'"',
  292 + obs_names.count(name))
  293 + self._log('\n')
280 294
281 - # Get energy boundary information  
282 - if self._ebounds.size() == 0:  
283 - min_value = 'undefined'  
284 - max_value = 'undefined'  
285 - else:  
286 - min_value = str(self._ebounds.emin())  
287 - max_value = str(self._ebounds.emax())  
288 -  
289 - # Log energy range  
290 - self._log.header3('Energy range')  
291 - self._log_value('Minimum energy', min_value)  
292 - self._log_value('Maximum energy', max_value)  
293 -  
294 - # Log time range  
295 - self._log.header3('Time range')  
296 - self._log_value('Start (MJD)', self._gti.tstart().mjd())  
297 - self._log_value('Stop (MJD)', self._gti.tstop().mjd())  
298 -  
299 - # Log ontime and livetime in different units  
300 - on_time = '%.2f s = %.2f min = %.2f h' % \  
301 - (ontime, ontime/60., ontime/3600.)  
302 - live_time = '%.2f s = %.2f min = %.2f h' % \  
303 - (livetime, livetime/60., livetime/3600.)  
304 - self._log_value('Total ontime', on_time)  
305 - self._log_value('Total livetime', live_time)  
306 - 295 + # Get energy boundary information
  296 + if self._ebounds.size() == 0:
  297 + min_value = 'undefined'
  298 + max_value = 'undefined'
  299 + else:
  300 + min_value = str(self._ebounds.emin())
  301 + max_value = str(self._ebounds.emax())
  302 +
  303 + # Log energy range
  304 + self._log_header3(gammalib.TERSE, 'Energy range')
  305 + self._log_value(gammalib.TERSE, 'Minimum energy', min_value)
  306 + self._log_value(gammalib.TERSE, 'Maximum energy', max_value)
  307 +
  308 + # Log time range
  309 + self._log_header3(gammalib.TERSE, 'Time range')
  310 + self._log_value(gammalib.TERSE, 'Start (MJD)', self._gti.tstart().mjd())
  311 + self._log_value(gammalib.TERSE, 'Stop (MJD)', self._gti.tstop().mjd())
  312 +
  313 + # Log ontime and livetime in different units
  314 + on_time = '%.2f s = %.2f min = %.2f h' % \
  315 + (ontime, ontime/60., ontime/3600.)
  316 + live_time = '%.2f s = %.2f min = %.2f h' % \
  317 + (livetime, livetime/60., livetime/3600.)
  318 + self._log_value(gammalib.TERSE, 'Total ontime', on_time)
  319 + self._log_value(gammalib.TERSE, 'Total livetime', live_time)
  320 +
307 # Return 321 # Return
308 return 322 return
309 323
@@ -323,13 +337,10 @@ class csobsinfo(ctools.cscript): @@ -323,13 +337,10 @@ class csobsinfo(ctools.cscript):
323 if ds9file.url() != 'NONE': 337 if ds9file.url() != 'NONE':
324 338
325 # Write header 339 # Write header
326 - if self._logTerse():  
327 - self._log('\n')  
328 - self._log.header1('Save pointings in DS9 file') 340 + self._log_header1(gammalib.TERSE, 'Save pointings in DS9 file')
329 341
330 # Log filename 342 # Log filename
331 - if self._logTerse():  
332 - self._log_value('DS9 filename', ds9file.url()) 343 + self._log_value(gammalib.TERSE, 'DS9 filename', ds9file.url())
333 344
334 # Open file 345 # Open file
335 f = open(ds9file.url(),'w') 346 f = open(ds9file.url(),'w')
cscripts/cspull.py
@@ -209,15 +209,14 @@ class cspull(ctools.cscript): @@ -209,15 +209,14 @@ class cspull(ctools.cscript):
209 nevents += run.events().number() 209 nevents += run.events().number()
210 210
211 # Write simulation results 211 # Write simulation results
212 - if self._logNormal():  
213 - self._log.header3('Simulation')  
214 - for run in self._obs:  
215 - self._log_value('Input observation %s' % run.id(),  
216 - self._obs_string(run))  
217 - for run in obs:  
218 - self._log_value('Output observation %s' % run.id(),  
219 - self._obs_string(run))  
220 - self._log_value('Number of simulated events', nevents) 212 + self._log_header3(gammalib.NORMAL, 'Simulation')
  213 + for run in self._obs:
  214 + self._log_value(gammalib.NORMAL, 'Input observation %s' % run.id(),
  215 + self._obs_string(run))
  216 + for run in obs:
  217 + self._log_value(gammalib.NORMAL, 'Output observation %s' % run.id(),
  218 + self._obs_string(run))
  219 + self._log_value(gammalib.NORMAL, 'Number of simulated events', nevents)
221 220
222 # Fit model 221 # Fit model
223 if self['profile'].boolean(): 222 if self['profile'].boolean():
@@ -284,9 +283,8 @@ class cspull(ctools.cscript): @@ -284,9 +283,8 @@ class cspull(ctools.cscript):
284 values['e_'+name] = error 283 values['e_'+name] = error
285 284
286 # Write result 285 # Write result
287 - if self._logNormal():  
288 - value = '%.4f (%e +/- %e)' % (pull, fitted_value, error)  
289 - self._log_value(name, value) 286 + value = '%.4f (%e +/- %e)' % (pull, fitted_value, error)
  287 + self._log_value(gammalib.NORMAL, name, value)
290 288
291 # Bundle together results 289 # Bundle together results
292 result = {'colnames': colnames, 'values': values} 290 result = {'colnames': colnames, 'values': values}
cscripts/csresmap.py
@@ -276,9 +276,7 @@ class csresmap(ctools.cscript): @@ -276,9 +276,7 @@ class csresmap(ctools.cscript):
276 Save residual map 276 Save residual map
277 """ 277 """
278 # Write header 278 # Write header
279 - if self._logTerse():  
280 - self._log('\n')  
281 - self._log.header1('Save residual map') 279 + self._log_header1(gammalib.TERSE, 'Save residual map')
282 280
283 # Get outmap parameter 281 # Get outmap parameter
284 outmap = self['outmap'].filename() 282 outmap = self['outmap'].filename()
@@ -287,8 +285,7 @@ class csresmap(ctools.cscript): @@ -287,8 +285,7 @@ class csresmap(ctools.cscript):
287 if self._resmap != None: 285 if self._resmap != None:
288 286
289 # Log file name 287 # Log file name
290 - if self._logTerse():  
291 - self._log_value('Residual map file', outmap.url()) 288 + self._log_value(gammalib.TERSE, 'Residual map file', outmap.url())
292 289
293 # Save residual map 290 # Save residual map
294 self._resmap.save(outmap, self['clobber'].boolean()) 291 self._resmap.save(outmap, self['clobber'].boolean())
@@ -306,9 +303,7 @@ class csresmap(ctools.cscript): @@ -306,9 +303,7 @@ class csresmap(ctools.cscript):
306 Name of residual map 303 Name of residual map
307 """ 304 """
308 # Write header 305 # Write header
309 - if self._logTerse():  
310 - self._log('\n')  
311 - self._log.header1('Publish residual map') 306 + self._log_header1(gammalib.TERSE, 'Publish residual map')
312 307
313 # Continue only if residual map is valid 308 # Continue only if residual map is valid
314 if self._resmap != None: 309 if self._resmap != None:
@@ -320,8 +315,7 @@ class csresmap(ctools.cscript): @@ -320,8 +315,7 @@ class csresmap(ctools.cscript):
320 user_name = name 315 user_name = name
321 316
322 # Log map name 317 # Log map name
323 - if self._logTerse():  
324 - self._log_value('Residual map name', user_name) 318 + self._log_value(gammalib.TERSE, 'Residual map name', user_name)
325 319
326 # Publish map 320 # Publish map
327 self._resmap.publish(user_name) 321 self._resmap.publish(user_name)
cscripts/cssens.py
@@ -301,12 +301,11 @@ class cssens(ctools.cscript): @@ -301,12 +301,11 @@ class cssens(ctools.cscript):
301 crab_unit = crab_flux/src_flux 301 crab_unit = crab_flux/src_flux
302 302
303 # Write header 303 # Write header
304 - if self._logTerse():  
305 - self._log('\n')  
306 - self._log.header2('Energies: '+str(emin)+' - '+str(emax))  
307 - self._log_value('Crab flux', str(crab_flux)+' ph/cm2/s')  
308 - self._log_value('Source model flux', str(src_flux)+' ph/cm2/s')  
309 - self._log_value('Crab unit factor', crab_unit) 304 + self._log_header2(gammalib.TERSE, 'Energies: '+str(emin)+' - '+str(emax))
  305 + self._log_value(gammalib.TERSE, 'Crab flux', str(crab_flux)+' ph/cm2/s')
  306 + self._log_value(gammalib.TERSE, 'Source model flux', str(src_flux)+
  307 + ' ph/cm2/s')
  308 + self._log_value(gammalib.TERSE, 'Crab unit factor', crab_unit)
310 309
311 # Initialise loop 310 # Initialise loop
312 crab_flux_value = [] 311 crab_flux_value = []
@@ -348,9 +347,9 @@ class cssens(ctools.cscript): @@ -348,9 +347,9 @@ class cssens(ctools.cscript):
348 nevents += run.events().number() 347 nevents += run.events().number()
349 348
350 # Write simulation results 349 # Write simulation results
351 - if self._logExplicit():  
352 - self._log.header3('Simulation')  
353 - self._log_value('Number of simulated events', nevents) 350 + self._log_header3(gammalib.EXPLICIT, 'Simulation')
  351 + self._log_value(gammalib.EXPLICIT, 'Number of simulated events',
  352 + nevents)
354 353
355 # Fit test source 354 # Fit test source
356 fit = ctools.ctlike(sim) 355 fit = ctools.ctlike(sim)
@@ -379,16 +378,16 @@ class cssens(ctools.cscript): @@ -379,16 +378,16 @@ class cssens(ctools.cscript):
379 quality = npred - nevents 378 quality = npred - nevents
380 379
381 # Write test source fit results 380 # Write test source fit results
382 - if self._logExplicit():  
383 - self._log.header3('Test source model fit')  
384 - self._log_value('Test statistics', ts)  
385 - self._log_value('log likelihood', logL)  
386 - self._log_value('Number of predicted events', quality)  
387 - self._log_value('Fit quality', npred)  
388 - for model in models:  
389 - self._log_value('Model', model.name())  
390 - for par in model:  
391 - self._log(str(par)+'\n') 381 + self._log_header3(gammalib.EXPLICIT, 'Test source model fit')
  382 + self._log_value(gammalib.EXPLICIT, 'Test statistics', ts)
  383 + self._log_value(gammalib.EXPLICIT, 'log likelihood', logL)
  384 + self._log_value(gammalib.EXPLICIT, 'Number of predicted events',
  385 + quality)
  386 + self._log_value(gammalib.EXPLICIT, 'Fit quality', npred)
  387 + for model in models:
  388 + self._log_value(gammalib.EXPLICIT, 'Model', model.name())
  389 + for par in model:
  390 + self._log(str(par)+'\n')
392 391
393 # If TS was non-positive then increase the test flux and start 392 # If TS was non-positive then increase the test flux and start
394 # over 393 # over
@@ -427,13 +426,16 @@ class cssens(ctools.cscript): @@ -427,13 +426,16 @@ class cssens(ctools.cscript):
427 426
428 # Write fit results 427 # Write fit results
429 if self._logExplicit(): 428 if self._logExplicit():
430 - self._log_value('Photon flux', str(photon_flux)+' ph/cm2/s')  
431 - self._log_value('Energy flux', str(energy_flux)+' erg/cm2/s')  
432 - self._log_value('Crab flux', str(crab_flux*1000.0)+' mCrab')  
433 - self._log_value('Differential sensitivity', str(sensitivity)+  
434 - ' erg/cm2/s') 429 + self._log_value(gammalib.EXPLICIT, 'Photon flux',
  430 + str(photon_flux)+' ph/cm2/s')
  431 + self._log_value(gammalib.EXPLICIT, 'Energy flux',
  432 + str(energy_flux)+' erg/cm2/s')
  433 + self._log_value(gammalib.EXPLICIT, 'Crab flux',
  434 + str(crab_flux*1000.0)+' mCrab')
  435 + self._log_value(gammalib.EXPLICIT, 'Differential sensitivity',
  436 + str(sensitivity)+' erg/cm2/s')
435 for model in models: 437 for model in models:
436 - self._log_value('Model', model.name()) 438 + self._log_value(gammalib.EXPLICIT, 'Model', model.name())
437 for par in model: 439 for par in model:
438 self._log(str(par)+'\n') 440 self._log(str(par)+'\n')
439 elif self._logTerse(): 441 elif self._logTerse():
@@ -441,7 +443,7 @@ class cssens(ctools.cscript): @@ -441,7 +443,7 @@ class cssens(ctools.cscript):
441 value = ('TS=%.4f corr=%e %e ph/cm2/s = %e erg/cm2/s = %.2f ' 443 value = ('TS=%.4f corr=%e %e ph/cm2/s = %e erg/cm2/s = %.2f '
442 'mCrab = %e erg/cm2/s' % (ts, correct, photon_flux, 444 'mCrab = %e erg/cm2/s' % (ts, correct, photon_flux,
443 energy_flux, crab_flux*1000.0, sensitivity)) 445 energy_flux, crab_flux*1000.0, sensitivity))
444 - self._log_value(name, value) 446 + self._log_value(gammalib.TERSE, name, value)
445 447
446 # Compute sliding average of extrapolated fitted prefactor, 448 # Compute sliding average of extrapolated fitted prefactor,
447 # photon and energy flux. This damps out fluctuations and 449 # photon and energy flux. This damps out fluctuations and
@@ -493,21 +495,24 @@ class cssens(ctools.cscript): @@ -493,21 +495,24 @@ class cssens(ctools.cscript):
493 break 495 break
494 496
495 # Write fit results 497 # Write fit results
496 - if self._logTerse():  
497 - self._log.header3('Fit results')  
498 - self._log_value('Test statistics', ts)  
499 - self._log_value('Photon flux', str(photon_flux)+' ph/cm2/s')  
500 - self._log_value('Energy flux', str(energy_flux)+' erg/cm2/s')  
501 - self._log_value('Crab flux', str(crab_flux*1000.0)+' mCrab')  
502 - self._log_value('Differential sensitivity', str(sensitivity)+' erg/cm2/s')  
503 - self._log_value('Number of simulated events', nevents)  
504 - self._log.header3('Test source model fitting')  
505 - self._log_value('log likelihood', logL)  
506 - self._log_value('Number of predicted events', npred)  
507 - for model in models:  
508 - self._log_value('Model', model.name())  
509 - for par in model:  
510 - self._log(str(par)+'\n') 498 + self._log_header3(gammalib.TERSE, 'Fit results')
  499 + self._log_value(gammalib.TERSE, 'Test statistics', ts)
  500 + self._log_value(gammalib.TERSE, 'Photon flux',
  501 + str(photon_flux)+' ph/cm2/s')
  502 + self._log_value(gammalib.TERSE, 'Energy flux',
  503 + str(energy_flux)+' erg/cm2/s')
  504 + self._log_value(gammalib.TERSE, 'Crab flux',
  505 + str(crab_flux*1000.0)+' mCrab')
  506 + self._log_value(gammalib.TERSE, 'Differential sensitivity',
  507 + str(sensitivity)+' erg/cm2/s')
  508 + self._log_value(gammalib.TERSE, 'Number of simulated events', nevents)
  509 + self._log_header3(gammalib.TERSE, 'Test source model fitting')
  510 + self._log_value(gammalib.TERSE, 'log likelihood', logL)
  511 + self._log_value(gammalib.TERSE, 'Number of predicted events', npred)
  512 + for model in models:
  513 + self._log_value(gammalib.TERSE, 'Model', model.name())
  514 + for par in model:
  515 + self._log_string(gammalib.TERSE, str(par)+'\n')
511 516
512 # Restore energy boundaries of observation container 517 # Restore energy boundaries of observation container
513 for i, obs in enumerate(self._obs): 518 for i, obs in enumerate(self._obs):
cscripts/csspec.py
@@ -207,18 +207,17 @@ class csspec(ctools.cscript): @@ -207,18 +207,17 @@ class csspec(ctools.cscript):
207 self._get_parameters() 207 self._get_parameters()
208 208
209 # Write spectral binning into header 209 # Write spectral binning into header
210 - if self._logTerse():  
211 - self._log("\n")  
212 - self._log.header1("Spectral binning")  
213 - if self._binned_mode:  
214 - cube_ebounds = self._obs[0].events().ebounds()  
215 - value = '%s - %s' % (str(cube_ebounds.emin()),  
216 - str(cube_ebounds.emax()))  
217 - self._log_value('Counts cube energy range', value)  
218 - for i in range(self._ebounds.size()):  
219 - value = '%s - %s' % (str(self._ebounds.emin(i)),  
220 - str(self._ebounds.emax(i)))  
221 - self._log_value('Bin %d' % (i+1), value) 210 + self._log("\n")
  211 + self._log.header1("Spectral binning")
  212 + if self._binned_mode:
  213 + cube_ebounds = self._obs[0].events().ebounds()
  214 + value = '%s - %s' % (str(cube_ebounds.emin()),
  215 + str(cube_ebounds.emax()))
  216 + self._log_value(gammalib.TERSE, 'Counts cube energy range', value)
  217 + for i in range(self._ebounds.size()):
  218 + value = '%s - %s' % (str(self._ebounds.emin(i)),
  219 + str(self._ebounds.emax(i)))
  220 + self._log_value(gammalib.TERSE, 'Bin %d' % (i+1), value)
222 221
223 # Write observation into logger 222 # Write observation into logger
224 if self._logTerse(): 223 if self._logTerse():
cscripts/cstsdist.py
@@ -156,9 +156,8 @@ class cstsdist(ctools.cscript): @@ -156,9 +156,8 @@ class cstsdist(ctools.cscript):
156 nevents += run.events().number() 156 nevents += run.events().number()
157 157
158 # Write simulation results 158 # Write simulation results
159 - if self._logExplicit():  
160 - self._log.header3('Simulation')  
161 - self._log_value('Number of simulated events', nevents) 159 + self._log_header3(gammalib.EXPLICIT, 'Simulation')
  160 + self._log_value(gammalib.EXPLICIT, 'Number of simulated events', nevents)
162 161
163 # Fit model 162 # Fit model
164 fit = ctools.ctlike(sim) 163 fit = ctools.ctlike(sim)
@@ -175,19 +174,19 @@ class cstsdist(ctools.cscript): @@ -175,19 +174,19 @@ class cstsdist(ctools.cscript):
175 174
176 # Write fit results, either explicit or normal 175 # Write fit results, either explicit or normal
177 if self._logExplicit(): 176 if self._logExplicit():
178 - self._log.header3('Test source model fit')  
179 - self._log_value('Test statistics', ts)  
180 - self._log_value('log likelihood', logL)  
181 - self._log_value('Number of predicted events', npred) 177 + self._log_header3(gammalib.EXPLICIT, 'Test source model fit')
  178 + self._log_value(gammalib.EXPLICIT, 'Test statistics', ts)
  179 + self._log_value(gammalib.EXPLICIT, 'log likelihood', logL)
  180 + self._log_value(gammalib.EXPLICIT, 'Number of predicted events', npred)
182 for model in models: 181 for model in models:
183 - self._log_value('Model', model.name()) 182 + self._log_value(gammalib.EXPLICIT, 'Model', model.name())
184 for par in model: 183 for par in model:
185 - self._log(str(par)+'\n') 184 + self._log_string(gammalib.EXPLICIT, str(par)+'\n')
186 elif self._logNormal(): 185 elif self._logNormal():
187 name = 'Trial %d' % seed 186 name = 'Trial %d' % seed
188 value = 'TS=%.3f Prefactor=%e +/- %e' % \ 187 value = 'TS=%.3f Prefactor=%e +/- %e' % \
189 (ts, model['Prefactor'].value(), model['Prefactor'].error()) 188 (ts, model['Prefactor'].value(), model['Prefactor'].error())
190 - self._log_value(name, value) 189 + self._log_value(gammalib.TERSE, name, value)
191 190
192 # Initialise results 191 # Initialise results
193 colnames = [] 192 colnames = []
cscripts/cstsmapmerge.py
@@ -290,9 +290,8 @@ class cstsmapmerge(ctools.cscript): @@ -290,9 +290,8 @@ class cstsmapmerge(ctools.cscript):
290 290
291 # Skip file if it's not a FITS file 291 # Skip file if it's not a FITS file
292 if not gammalib.GFilename(fitsfile).is_fits(): 292 if not gammalib.GFilename(fitsfile).is_fits():
293 - if self._logExplicit():  
294 - self._log_value('Skip file',  
295 - '%s (not a FITS file)' % fitsfile) 293 + self._log_value(gammalib.EXPLICIT, 'Skip file',
  294 + '%s (not a FITS file)' % fitsfile)
296 continue 295 continue
297 296
298 # Open FITS file 297 # Open FITS file
@@ -313,9 +312,8 @@ class cstsmapmerge(ctools.cscript): @@ -313,9 +312,8 @@ class cstsmapmerge(ctools.cscript):
313 # ... otherwise signal that file is useless 312 # ... otherwise signal that file is useless
314 else: 313 else:
315 fits.close() 314 fits.close()
316 - if self._logExplicit():  
317 - self._log_value('Skip file',  
318 - '%s (no "STATUS MAP" extension)' % fitsfile) 315 + self._log_value(gammalib.EXPLICIT, 'Skip file',
  316 + '%s (no "STATUS MAP" extension)' % fitsfile)
319 continue 317 continue
320 318
321 # Signal if no suitable file was found 319 # Signal if no suitable file was found
@@ -344,9 +342,8 @@ class cstsmapmerge(ctools.cscript): @@ -344,9 +342,8 @@ class cstsmapmerge(ctools.cscript):
344 342
345 # Skip if file is not FITS 343 # Skip if file is not FITS
346 if not gammalib.GFilename(fitsfile).is_fits(): 344 if not gammalib.GFilename(fitsfile).is_fits():
347 - if self._logExplicit():  
348 - self._log_value('Skip file',  
349 - '%s (not a FITS file)' % fitsfile) 345 + self._log_value(gammalib.EXPLICIT, 'Skip file',
  346 + '%s (not a FITS file)' % fitsfile)
350 continue 347 continue
351 348
352 # Open FITS file 349 # Open FITS file
@@ -355,10 +352,8 @@ class cstsmapmerge(ctools.cscript): @@ -355,10 +352,8 @@ class cstsmapmerge(ctools.cscript):
355 # Skip if file does not contain status map 352 # Skip if file does not contain status map
356 if not fits.contains('STATUS MAP'): 353 if not fits.contains('STATUS MAP'):
357 fits.close() 354 fits.close()
358 - if self._logExplicit():  
359 - self._log_value('Skip file',  
360 - '%s (no "STATUS MAP" extension)' %  
361 - fitsfile) 355 + self._log_value(gammalib.EXPLICIT, 'Skip file',
  356 + '%s (no "STATUS MAP" extension)' % fitsfile)
362 continue 357 continue
363 358
364 # Close FITS file 359 # Close FITS file
@@ -386,16 +381,13 @@ class cstsmapmerge(ctools.cscript): @@ -386,16 +381,13 @@ class cstsmapmerge(ctools.cscript):
386 Save TS map and remove slices if requested 381 Save TS map and remove slices if requested
387 """ 382 """
388 # Write header 383 # Write header
389 - if self._logTerse():  
390 - self._log('\n')  
391 - self._log.header1('Save TS map') 384 + self._log_header1(gammalib.TERSE, 'Save TS map')
392 385
393 # Get output filename in case it was not read ahead 386 # Get output filename in case it was not read ahead
394 outmap = self['outmap'].filename() 387 outmap = self['outmap'].filename()
395 388
396 # Log filename 389 # Log filename
397 - if self._logTerse():  
398 - self._log_value('TS map file', outmap.url()) 390 + self._log_value(gammalib.TERSE, 'TS map file', outmap.url())
399 391
400 # Create FITS file 392 # Create FITS file
401 fits = gammalib.GFits() 393 fits = gammalib.GFits()
@@ -430,8 +422,7 @@ class cstsmapmerge(ctools.cscript): @@ -430,8 +422,7 @@ class cstsmapmerge(ctools.cscript):
430 if self._delete: 422 if self._delete:
431 for filename in self._merged_files: 423 for filename in self._merged_files:
432 os.remove(filename) 424 os.remove(filename)
433 - if self._logTerse():  
434 - self._log_value('Deleted input file', filename) 425 + self._log_value(gammalib.TERSE, 'Deleted input file', filename)
435 426
436 # Return 427 # Return
437 return 428 return
cscripts/cstsmapsplit.py
@@ -168,9 +168,8 @@ class cstsmapsplit(ctools.cscript): @@ -168,9 +168,8 @@ class cstsmapsplit(ctools.cscript):
168 logL0 = self._compute_null_hypothesis() 168 logL0 = self._compute_null_hypothesis()
169 169
170 # Write likelihood into logger 170 # Write likelihood into logger
171 - if self._logTerse():  
172 - self._log_value('Source removed', self._srcname)  
173 - self._log_value('Log-likelihood', repr(logL0)) 171 + self._log_value(gammalib.TERSE, 'Source removed', self._srcname)
  172 + self._log_value(gammalib.TERSE, 'Log-likelihood', repr(logL0))
174 173
175 # Get parameters of TS map ctool 174 # Get parameters of TS map ctool
176 pars = gammalib.GApplicationPars('cttsmap.par') 175 pars = gammalib.GApplicationPars('cttsmap.par')
@@ -186,10 +185,8 @@ class cstsmapsplit(ctools.cscript): @@ -186,10 +185,8 @@ class cstsmapsplit(ctools.cscript):
186 base_command = 'cttsmap' 185 base_command = 'cttsmap'
187 186
188 # Write information into logger 187 # Write information into logger
189 - if self._logTerse():  
190 - self._log('\n')  
191 - self._log.header1('Create commands')  
192 - self._log_value('Number of cttsmap calls', njobs) 188 + self._log_header1(gammalib.TERSE, 'Create commands')
  189 + self._log_value(gammalib.TERSE, 'Number of cttsmap calls', njobs)
193 190
194 # Loop over TS map parameters 191 # Loop over TS map parameters
195 for par in pars: 192 for par in pars:
cscripts/csworkflow.py
@@ -165,20 +165,22 @@ class csworkflow(ctools.cscript): @@ -165,20 +165,22 @@ class csworkflow(ctools.cscript):
165 self._actors.append(entry) 165 self._actors.append(entry)
166 166
167 # Log information about actors 167 # Log information about actors
168 - if self._logNormal():  
169 - self._log_value('Actor "%s"' % name, tool)  
170 - if num_inputs == 0:  
171 - self._log_value(' Predecessor', 'none')  
172 - else:  
173 - if num_inputs == 1:  
174 - self._log.parformat(' Predecessor')  
175 - else:  
176 - self._log.parformat(' Predecessors')  
177 - for k in range(num_inputs):  
178 - if k > 0:  
179 - self._log(', ')  
180 - self._log('"'+input_actors[k]+'"')  
181 - self._log('\n') 168 + self._log_value(gammalib.NORMAL, 'Actor "%s"' % name, tool)
  169 +
  170 + # Compute list of predecessors
  171 + if num_inputs == 0:
  172 + predecessors = 'none'
  173 + else:
  174 + predecessors = ''
  175 + for k in range(num_inputs):
  176 + if k > 0:
  177 + predecessors += ', '
  178 + predecessors += '"'+input_actors[k]+'"'
  179 +
  180 + # Log predecessors
  181 + self._log_value(gammalib.NORMAL,
  182 + gammalib.number(' Predecessor', num_inputs),
  183 + predecessors)
182 184
183 # Return 185 # Return
184 return 186 return
@@ -197,16 +199,15 @@ class csworkflow(ctools.cscript): @@ -197,16 +199,15 @@ class csworkflow(ctools.cscript):
197 if actor['status'] == 'ready': 199 if actor['status'] == 'ready':
198 200
199 # Log execution start 201 # Log execution start
200 - if self._logNormal():  
201 - self._log_value('Execute actor', '"%s"' % actor['name']) 202 + self._log_value(gammalib.NORMAL, 'Execute actor',
  203 + '"%s"' % actor['name'])
202 204
203 # Execute actor 205 # Execute actor
204 self._execute_actor(actor) 206 self._execute_actor(actor)
205 207
206 # Log execution finish 208 # Log execution finish
207 - if self._logNormal():  
208 - self._log_value('Finished actor execution',  
209 - '"%s"' % actor['name']) 209 + self._log_value(gammalib.NORMAL, 'Finished actor execution',
  210 + '"%s"' % actor['name'])
210 211
211 # Set actor status to finished 212 # Set actor status to finished
212 actor['status'] = 'finished' 213 actor['status'] = 'finished'
@@ -238,18 +239,16 @@ class csworkflow(ctools.cscript): @@ -238,18 +239,16 @@ class csworkflow(ctools.cscript):
238 def _execute_actor(self, actor): 239 def _execute_actor(self, actor):
239 240
240 # Log input parameters 241 # Log input parameters
241 - if self._logNormal():  
242 - pars = actor['input_parameters']  
243 - for par in pars:  
244 - self._log_value(' Input parameter', '%s=%s' %  
245 - (par['name'], self._get_parameter_value(par))) 242 + pars = actor['input_parameters']
  243 + for par in pars:
  244 + self._log_value(gammalib.NORMAL, ' Input parameter', '%s=%s' %
  245 + (par['name'], self._get_parameter_value(par)))
246 246
247 # Log output parameters 247 # Log output parameters
248 - if self._logNormal():  
249 - pars = actor['output_parameters']  
250 - for par in pars:  
251 - self._log_value(' Output parameter', '%s=%s' %  
252 - (par['name'], self._get_parameter_value(par))) 248 + pars = actor['output_parameters']
  249 + for par in pars:
  250 + self._log_value(gammalib.NORMAL, ' Output parameter', '%s=%s' %
  251 + (par['name'], self._get_parameter_value(par)))
253 252
254 # Set actor tool 253 # Set actor tool
255 if 'tool' in actor: 254 if 'tool' in actor:
pyext/ctool.i
@@ -195,11 +195,4 @@ def _init_cscript(self, argv): @@ -195,11 +195,4 @@ def _init_cscript(self, argv):
195 self._log_header() 195 self._log_header()
196 self._log.date(True) 196 self._log.date(True)
197 cscript._init_cscript = _init_cscript 197 cscript._init_cscript = _init_cscript
198 -  
199 -# Log the value of a parameter  
200 -def _log_value(self, name, value):  
201 - self._log.parformat(str(name))  
202 - self._log(str(value))  
203 - self._log('\n')  
204 -cscript._log_value = _log_value  
205 %} 198 %}