Commit 71cb52641493fc4788cbe06a9c57d395cc4e53b8

Authored by Jürgen Knödlseder
1 parent c5a2d15f

GApplicationPar::filename() now returns GFilename instead of std::string.

cscripts/csfindobs.py
@@ -287,12 +287,12 @@ class csfindobs(ctools.cscript): @@ -287,12 +287,12 @@ class csfindobs(ctools.cscript):
287 def save(self, outfile): 287 def save(self, outfile):
288 288
289 # Check for clobber 289 # Check for clobber
290 - if os.path.isfile(outfile) and not self.clobber():  
291 - self.log("File "+outfile+" already exists. Set clobber=yes to overwrite file") 290 + if outfile.exists() and not self.clobber():
  291 + self.log("File "+outfile.url()+" already exists. Set clobber=yes to overwrite file")
292 self.log("\n") 292 self.log("\n")
293 else: 293 else:
294 # Write runs to file 294 # Write runs to file
295 - f = open(outfile,"w") 295 + f = open(outfile.url(),"w")
296 for run in self.runs: 296 for run in self.runs:
297 f.write(str(run)+" \n") 297 f.write(str(run)+" \n")
298 f.close() 298 f.close()
cscripts/csiactcopy.py
@@ -103,9 +103,10 @@ class csiactcopy(ctools.cscript): @@ -103,9 +103,10 @@ class csiactcopy(ctools.cscript):
103 """ 103 """
104 104
105 # Get Parameters 105 # Get Parameters
106 - self.m_remote_master = gammalib.expand_env(self["remote_master"].filename())  
107 - if not os.path.isfile(self.m_remote_master):  
108 - raise RuntimeError("*** ERROR: FITS data not available. No master index file found in \""+self.m_remote_master+"\". Make sure remote file system is properly mounted") 106 + self.m_remote_master = self["remote_master"].filename()
  107 + #if not os.path.isfile(self.m_remote_master):
  108 + if not self.m_remote_master.exists():
  109 + raise RuntimeError("*** ERROR: FITS data not available. No master index file found in \""+self.m_remote_master.url()+"\". Make sure remote file system is properly mounted")
109 110
110 # Get parameters 111 # Get parameters
111 self.m_prodname = self["prodname"].string() 112 self.m_prodname = self["prodname"].string()
@@ -153,7 +154,7 @@ class csiactcopy(ctools.cscript): @@ -153,7 +154,7 @@ class csiactcopy(ctools.cscript):
153 self.runlist = [] 154 self.runlist = []
154 155
155 # Check if runlist file is available 156 # Check if runlist file is available
156 - if os.path.isfile(self.m_runlist): 157 + if self.m_runlist.exists():
157 runfile = open(self.m_runlist) 158 runfile = open(self.m_runlist)
158 for line in runfile.readlines(): 159 for line in runfile.readlines():
159 if len(line) == 0: 160 if len(line) == 0:
cscripts/csiactobs.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Generation of an IACT observation definition file. 3 # Generation of an IACT observation definition file.
4 # 4 #
5 -# Copyright (C) 2015 Michael Mayer 5 +# Copyright (C) 2015-2016 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -138,7 +138,7 @@ class csiactobs(ctools.cscript): @@ -138,7 +138,7 @@ class csiactobs(ctools.cscript):
138 138
139 # Read user parameters 139 # Read user parameters
140 self.m_prodname = self["prodname"].string() 140 self.m_prodname = self["prodname"].string()
141 - self.m_runlistfile = gammalib.expand_env(self["infile"].filename()) 141 + self.m_runlistfile = self["infile"].filename()
142 self.m_bkgpars = self["bkgpars"].integer() 142 self.m_bkgpars = self["bkgpars"].integer()
143 143
144 # Output model file 144 # Output model file
@@ -288,16 +288,15 @@ class csiactobs(ctools.cscript): @@ -288,16 +288,15 @@ class csiactobs(ctools.cscript):
288 prefactor = 1.0 288 prefactor = 1.0
289 index = 0.0 289 index = 0.0
290 prefactor *= bkg_scale 290 prefactor *= bkg_scale
291 - spec = self.background_spectrum(obs_id, prefactor, index, emin, emax) 291 + spec = self.background_spectrum(obs_id, prefactor, index, emin, emax)
292 292
293 # Create background model instance 293 # Create background model instance
294 bck = gammalib.GCTAModelIrfBackground(spec) 294 bck = gammalib.GCTAModelIrfBackground(spec)
295 295
296 # Set AeffBackground 296 # Set AeffBackground
297 elif bkgtype == "aeff": 297 elif bkgtype == "aeff":
298 -  
299 prefactor = bkg_scale * self.m_bkg_aeff_norm 298 prefactor = bkg_scale * self.m_bkg_aeff_norm
300 - spec = self.background_spectrum(obs_id, prefactor, self.m_bkg_aeff_index, emin, emax) 299 + spec = self.background_spectrum(obs_id, prefactor, self.m_bkg_aeff_index, emin, emax)
301 300
302 # Create background model instance 301 # Create background model instance
303 bck = gammalib.GCTAModelAeffBackground(spec) 302 bck = gammalib.GCTAModelAeffBackground(spec)
@@ -393,7 +392,7 @@ class csiactobs(ctools.cscript): @@ -393,7 +392,7 @@ class csiactobs(ctools.cscript):
393 392
394 # Read runlist from file 393 # Read runlist from file
395 runlist = [] 394 runlist = []
396 - runfile = open(self.m_runlistfile) 395 + runfile = open(self.m_runlistfile.url())
397 for line in runfile.readlines(): 396 for line in runfile.readlines():
398 if len(line) == 0: 397 if len(line) == 0:
399 continue 398 continue
@@ -420,12 +419,12 @@ class csiactobs(ctools.cscript): @@ -420,12 +419,12 @@ class csiactobs(ctools.cscript):
420 obs_selection = "[OBS_ID=="+str(obs_id)+"]" 419 obs_selection = "[OBS_ID=="+str(obs_id)+"]"
421 420
422 # Open HDU index file 421 # Open HDU index file
423 - hduindx = gammalib.GFits(self.m_hdu_index+"[HDU_INDEX]"+obs_selection) 422 + hduindx = gammalib.GFits(self.m_hdu_index+"[HDU_INDEX]"+obs_selection)
424 hduindx_hdu = hduindx["HDU_INDEX"] 423 hduindx_hdu = hduindx["HDU_INDEX"]
425 424
426 # Initialise files and hdu names 425 # Initialise files and hdu names
427 eventfile = aefffile = psffile = edispfile = bkgfile = "" 426 eventfile = aefffile = psffile = edispfile = bkgfile = ""
428 - eventhdu = aeffhdu = "" 427 + eventhdu = aeffhdu = ""
429 428
430 types = [] 429 types = []
431 formats = [] 430 formats = []
@@ -533,7 +532,7 @@ class csiactobs(ctools.cscript): @@ -533,7 +532,7 @@ class csiactobs(ctools.cscript):
533 fits.close() 532 fits.close()
534 533
535 # Open effective area file to look for threshold 534 # Open effective area file to look for threshold
536 - aeff_fits = gammalib.GFits(aefffile) 535 + aeff_fits = gammalib.GFits(aefffile)
537 aeff_table = aeff_fits[aeffhdu] 536 aeff_table = aeff_fits[aeffhdu]
538 537
539 # Set energy range from header keyword if present 538 # Set energy range from header keyword if present
cscripts/csmodelinfo.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Dump information about models into log file 3 # Dump information about models into log file
4 # 4 #
5 -# Copyright (C) 2015 Michael Mayer 5 +# Copyright (C) 2015-2016 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -329,7 +329,7 @@ class csmodelinfo(ctools.cscript): @@ -329,7 +329,7 @@ class csmodelinfo(ctools.cscript):
329 self.log.header1("Save region file") 329 self.log.header1("Save region file")
330 330
331 # Open file 331 # Open file
332 - f = open(self.ds9file,"w") 332 + f = open(self.ds9file.url(),"w")
333 333
334 # Write coordinate system 334 # Write coordinate system
335 f.write("fk5\n") 335 f.write("fk5\n")
cscripts/csobsinfo.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Dump information about observation into log file 3 # Dump information about observation into log file
4 # 4 #
5 -# Copyright (C) 2015 Michael Mayer 5 +# Copyright (C) 2015-2016 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -381,7 +381,7 @@ class csobsinfo(ctools.cscript): @@ -381,7 +381,7 @@ class csobsinfo(ctools.cscript):
381 if not self.ds9file == "NONE": 381 if not self.ds9file == "NONE":
382 382
383 # Open file 383 # Open file
384 - f = open(self.ds9file,"w") 384 + f = open(self.ds9file.url(),"w")
385 385
386 # Write coordinate system 386 # Write coordinate system
387 f.write("fk5\n") 387 f.write("fk5\n")
cscripts/cspull.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # This script generates the pull distribution for all model parameters. 3 # This script generates the pull distribution for all model parameters.
4 # 4 #
5 -# Copyright (C) 2011-2015 Juergen Knoedlseder 5 +# Copyright (C) 2011-2016 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -319,11 +319,11 @@ class cspull(ctools.cscript): @@ -319,11 +319,11 @@ class cspull(ctools.cscript):
319 319
320 # Write out result immediately 320 # Write out result immediately
321 if seed == 0: 321 if seed == 0:
322 - file = open(self.m_outfile, 'w') 322 + file = open(self.m_outfile.url(), 'w')
323 writer = csv.DictWriter(file, result['colnames']) 323 writer = csv.DictWriter(file, result['colnames'])
324 writer.writerow(dict((_,_) for _ in result['colnames'])) 324 writer.writerow(dict((_,_) for _ in result['colnames']))
325 else: 325 else:
326 - file = open(self.m_outfile, 'a') 326 + file = open(self.m_outfile.url(), 'a')
327 writer = csv.DictWriter(file, result['colnames']) 327 writer = csv.DictWriter(file, result['colnames'])
328 writer.writerow(result['values']) 328 writer.writerow(result['values'])
329 file.close() 329 file.close()
cscripts/cssens.py
@@ -249,13 +249,13 @@ class cssens(ctools.cscript): @@ -249,13 +249,13 @@ class cssens(ctools.cscript):
249 249
250 # Write results 250 # Write results
251 if ieng == 0: 251 if ieng == 0:
252 - f = open(self.m_outfile, 'w') 252 + f = open(self.m_outfile.url(), 'w')
253 writer = csv.DictWriter(f, colnames) 253 writer = csv.DictWriter(f, colnames)
254 writer.writerow(dict((_,_) for _ in colnames)) 254 writer.writerow(dict((_,_) for _ in colnames))
255 writer.writerow(result) 255 writer.writerow(result)
256 f.close() 256 f.close()
257 else: 257 else:
258 - f = open(self.m_outfile, 'a') 258 + f = open(self.m_outfile.url(), 'a')
259 writer = csv.DictWriter(f, colnames) 259 writer = csv.DictWriter(f, colnames)
260 writer.writerow(result) 260 writer.writerow(result)
261 f.close() 261 f.close()
cscripts/cstsdist.py
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 # This script generates the TS distribution for a particular model based 3 # This script generates the TS distribution for a particular model based
4 # on Monte-Carlo simulations. 4 # on Monte-Carlo simulations.
5 # 5 #
6 -# Copyright (C) 2011-2015 Juergen Knoedlseder 6 +# Copyright (C) 2011-2016 Juergen Knoedlseder
7 # 7 #
8 # This program is free software: you can redistribute it and/or modify 8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by 9 # it under the terms of the GNU General Public License as published by
@@ -249,11 +249,11 @@ class cstsdist(ctools.cscript): @@ -249,11 +249,11 @@ class cstsdist(ctools.cscript):
249 249
250 # Write out result immediately 250 # Write out result immediately
251 if seed == 0: 251 if seed == 0:
252 - file = open(self.m_outfile, 'w') 252 + file = open(self.m_outfile.url(), 'w')
253 writer = csv.DictWriter(file, result['colnames']) 253 writer = csv.DictWriter(file, result['colnames'])
254 writer.writerow(dict((_,_) for _ in result['colnames'])) 254 writer.writerow(dict((_,_) for _ in result['colnames']))
255 else: 255 else:
256 - file = open(self.m_outfile, 'a') 256 + file = open(self.m_outfile.url(), 'a')
257 writer = csv.DictWriter(file, result['colnames']) 257 writer = csv.DictWriter(file, result['colnames'])
258 writer.writerow(result['values']) 258 writer.writerow(result['values'])
259 file.close() 259 file.close()