Commit c5a2d15fdefdbcf8b6f158ab01f4ffdad2b96716

Authored by Jürgen Knödlseder
1 parent 94494155

Adapt to new GFilename class interface.

cscripts/csfindobs.py
@@ -178,7 +178,8 @@ class csfindobs(ctools.cscript): @@ -178,7 +178,8 @@ class csfindobs(ctools.cscript):
178 # Check HDUs 178 # Check HDUs
179 if self.m_obs_index == "": 179 if self.m_obs_index == "":
180 raise RuntimeError("FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names") 180 raise RuntimeError("FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names")
181 - if not gammalib.is_fits(self.m_obs_index+"[OBS_INDEX]"): 181 + filename = gammalib.GFilename(self.m_obs_index+"[OBS_INDEX]")
  182 + if not filename.is_fits():
182 raise RuntimeError("Observation index file \""+self.m_obs_index+"[OBS_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csiactdata to get a list of available storage names.") 183 raise RuntimeError("Observation index file \""+self.m_obs_index+"[OBS_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csiactdata to get a list of available storage names.")
183 184
184 # Set other members 185 # Set other members
cscripts/csiactcopy.py
@@ -447,7 +447,8 @@ class csiactcopy(ctools.cscript): @@ -447,7 +447,8 @@ class csiactcopy(ctools.cscript):
447 obs = os.path.join(self.m_outpath, config["obsindx"]) 447 obs = os.path.join(self.m_outpath, config["obsindx"])
448 448
449 # Check if index files are available 449 # Check if index files are available
450 - if not (gammalib.is_fits(str(hdu)) and gammalib.is_fits(str(obs))): 450 + if not (gammalib.GFilename(str(hdu)).is_fits() and
  451 + gammalib.GFilename(str(obs)).is_fits()):
451 if self.logTerse(): 452 if self.logTerse():
452 self.log("Removing \""+str(config["name"])+"\" (not available)") 453 self.log("Removing \""+str(config["name"])+"\" (not available)")
453 self.log("\n") 454 self.log("\n")
cscripts/csiactobs.py
@@ -196,12 +196,14 @@ class csiactobs(ctools.cscript): @@ -196,12 +196,14 @@ class csiactobs(ctools.cscript):
196 # Check HDUs 196 # Check HDUs
197 if self.m_hdu_index == "" or self.m_obs_index == "": 197 if self.m_hdu_index == "" or self.m_obs_index == "":
198 raise RuntimeError("*** ERROR: FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names") 198 raise RuntimeError("*** ERROR: FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names")
199 - if not gammalib.is_fits(self.m_hdu_index+"[HDU_INDEX]"): 199 + filename = gammalib.GFilename(self.m_hdu_index+"[HDU_INDEX]")
  200 + if not filename.is_fits():
200 raise RuntimeError("*** ERROR: HDU index file \""+self.m_hdu_index+"[HDU_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csiactdata to get a list of available storage names.") 201 raise RuntimeError("*** ERROR: HDU index file \""+self.m_hdu_index+"[HDU_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csiactdata to get a list of available storage names.")
201 202
202 # Check for existence of "BKG_SCALE" in the observation index file if required 203 # Check for existence of "BKG_SCALE" in the observation index file if required
203 if self.m_use_bkg_scale: 204 if self.m_use_bkg_scale:
204 - if gammalib.is_fits(self.m_obs_index+"[OBS_INDEX]"): 205 + filename = gammalib.GFilename(self.m_obs_index+"[OBS_INDEX]")
  206 + if filename.is_fits():
205 fits = gammalib.GFits(self.m_obs_index) 207 fits = gammalib.GFits(self.m_obs_index)
206 if not fits["OBS_INDEX"].contains("BKG_SCALE"): 208 if not fits["OBS_INDEX"].contains("BKG_SCALE"):
207 self.m_use_bkg_scale = False 209 self.m_use_bkg_scale = False
@@ -439,10 +441,10 @@ class csiactobs(ctools.cscript): @@ -439,10 +441,10 @@ class csiactobs(ctools.cscript):
439 index = formats.index(version) 441 index = formats.index(version)
440 break 442 break
441 if index >= 0: 443 if index >= 0:
442 - eventfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index])  
443 - eventhdu = hduindx_hdu["HDU_NAME"][index] 444 + eventfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index])
  445 + eventhdu = hduindx_hdu["HDU_NAME"][index]
444 eventfile += "["+eventhdu+"]" 446 eventfile += "["+eventhdu+"]"
445 - if not gammalib.is_fits(eventfile): 447 + if not gammalib.GFilename(eventfile).is_fits():
446 if self.logTerse(): 448 if self.logTerse():
447 self.log("Skipping observation "+str(obs_id)+": eventfile \""+eventfile+"\" not found\n") 449 self.log("Skipping observation "+str(obs_id)+": eventfile \""+eventfile+"\" not found\n")
448 continue 450 continue
@@ -455,10 +457,10 @@ class csiactobs(ctools.cscript): @@ -455,10 +457,10 @@ class csiactobs(ctools.cscript):
455 index = formats.index(version) 457 index = formats.index(version)
456 break 458 break
457 if index >= 0: 459 if index >= 0:
458 - aefffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index])  
459 - aeffhdu = hduindx_hdu["HDU_NAME"][index] 460 + aefffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index])
  461 + aeffhdu = hduindx_hdu["HDU_NAME"][index]
460 aefffile += "["+aeffhdu+"]" 462 aefffile += "["+aeffhdu+"]"
461 - if not gammalib.is_fits(aefffile): 463 + if not gammalib.GFilename(aefffile).is_fits():
462 if self.logTerse(): 464 if self.logTerse():
463 self.log("Skipping observation "+str(obs_id)+": effective area \""+aefffile+"\" not found\n") 465 self.log("Skipping observation "+str(obs_id)+": effective area \""+aefffile+"\" not found\n")
464 continue 466 continue
@@ -471,9 +473,9 @@ class csiactobs(ctools.cscript): @@ -471,9 +473,9 @@ class csiactobs(ctools.cscript):
471 index = formats.index(version) 473 index = formats.index(version)
472 break 474 break
473 if index >= 0: 475 if index >= 0:
474 - psffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) 476 + psffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index])
475 psffile += "["+hduindx_hdu["HDU_NAME"][index]+"]" 477 psffile += "["+hduindx_hdu["HDU_NAME"][index]+"]"
476 - if not gammalib.is_fits(psffile): 478 + if not gammalib.GFilename(psffile).is_fits():
477 if self.logTerse(): 479 if self.logTerse():
478 self.log("Skipping observation "+str(obs_id)+": point spread function \""+psffile+"\" not found\n") 480 self.log("Skipping observation "+str(obs_id)+": point spread function \""+psffile+"\" not found\n")
479 continue 481 continue
@@ -486,9 +488,9 @@ class csiactobs(ctools.cscript): @@ -486,9 +488,9 @@ class csiactobs(ctools.cscript):
486 index = formats.index(version) 488 index = formats.index(version)
487 break 489 break
488 if index >= 0: 490 if index >= 0:
489 - edispfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) 491 + edispfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index])
490 edispfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" 492 edispfile += "["+hduindx_hdu["HDU_NAME"][index]+"]"
491 - if not gammalib.is_fits(edispfile): 493 + if not gammalib.GFilename(edispfile).is_fits():
492 if self.logTerse(): 494 if self.logTerse():
493 self.log("Warning: observation "+str(obs_id)+" has no energy dispersion \""+edispfile+"\" information\n") 495 self.log("Warning: observation "+str(obs_id)+" has no energy dispersion \""+edispfile+"\" information\n")
494 edispfile = "" 496 edispfile = ""
@@ -502,9 +504,9 @@ class csiactobs(ctools.cscript): @@ -502,9 +504,9 @@ class csiactobs(ctools.cscript):
502 index = formats.index(version) 504 index = formats.index(version)
503 break 505 break
504 if index >= 0: 506 if index >= 0:
505 - bkgfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) 507 + bkgfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index])
506 bkgfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" 508 bkgfile += "["+hduindx_hdu["HDU_NAME"][index]+"]"
507 - if not gammalib.is_fits(bkgfile): 509 + if not gammalib.GFilename(bkgfile).is_fits():
508 if self.logTerse(): 510 if self.logTerse():
509 self.log("Warning: observation "+str(obs_id)+" has no background information (file=\""+bkgfile+"\"). IRF background cannot be used\n") 511 self.log("Warning: observation "+str(obs_id)+" has no background information (file=\""+bkgfile+"\"). IRF background cannot be used\n")
510 bkgfile = "" 512 bkgfile = ""
cscripts/csobs2caldb.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Generation of an caldb entry from general IACT observation. 3 # Generation of an caldb entry from general IACT observation.
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
@@ -152,10 +152,10 @@ class csobs2caldb(ctools.cscript): @@ -152,10 +152,10 @@ class csobs2caldb(ctools.cscript):
152 fname_bkg = gammalib.GFilename(rsp.background().filename()) 152 fname_bkg = gammalib.GFilename(rsp.background().filename())
153 153
154 # Open FITS files of response components 154 # Open FITS files of response components
155 - fits_aeff = gammalib.GFits(fname_aeff.filename())  
156 - fits_psf = gammalib.GFits(fname_psf.filename())  
157 - fits_edisp = gammalib.GFits(fname_edisp.filename())  
158 - fits_bkg = gammalib.GFits(fname_bkg.filename()) 155 + fits_aeff = gammalib.GFits(fname_aeff)
  156 + fits_psf = gammalib.GFits(fname_psf)
  157 + fits_edisp = gammalib.GFits(fname_edisp)
  158 + fits_bkg = gammalib.GFits(fname_bkg)
159 159
160 # Bundle IRFs into one file 160 # Bundle IRFs into one file
161 fits.append(fits_aeff[fname_aeff.extname("EFFECTIVE AREA")]) 161 fits.append(fits_aeff[fname_aeff.extname("EFFECTIVE AREA")])
cscripts/csresmap.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Residual map generation script. 3 # Residual map generation script.
4 # 4 #
5 -# Copyright (C) 2014-2015 Michael Mayer 5 +# Copyright (C) 2014-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
@@ -143,9 +143,10 @@ class csresmap(ctools.cscript): @@ -143,9 +143,10 @@ class csresmap(ctools.cscript):
143 143
144 # First check if the inobs parameter is a counts cube 144 # First check if the inobs parameter is a counts cube
145 if self.obs.size() == 0 and self["inobs"].filename() != "NONE": 145 if self.obs.size() == 0 and self["inobs"].filename() != "NONE":
146 - if gammalib.is_fits(self["inobs"].filename()): 146 + filename = gammalib.GFilename(self["inobs"].filename())
  147 + if filename.is_fits():
147 cta = gammalib.GCTAObservation() 148 cta = gammalib.GCTAObservation()
148 - cta.load(self["inobs"].filename()) 149 + cta.load(filename)
149 if cta.eventtype() == "CountsCube": 150 if cta.eventtype() == "CountsCube":
150 self.m_skip_binning = True 151 self.m_skip_binning = True
151 152
cscripts/cstsmapmerge.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Merges sliced TS map files into one map 3 # Merges sliced TS map files into one map
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
@@ -261,7 +261,7 @@ class cstsmapmerge(ctools.cscript): @@ -261,7 +261,7 @@ class cstsmapmerge(ctools.cscript):
261 # Test files for the entry status map 261 # Test files for the entry status map
262 # use the first one to appear useful 262 # use the first one to appear useful
263 for fitsfile in self.files: 263 for fitsfile in self.files:
264 - if not gammalib.is_fits(fitsfile): 264 + if not gammalib.GFilename(fitsfile).is_fits():
265 self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") 265 self.log("Skipping file \""+fitsfile+" (not a FITS file)\n")
266 fits = gammalib.GFits(fitsfile) 266 fits = gammalib.GFits(fitsfile)
267 267
@@ -297,7 +297,7 @@ class cstsmapmerge(ctools.cscript): @@ -297,7 +297,7 @@ class cstsmapmerge(ctools.cscript):
297 for fitsfile in workfiles: 297 for fitsfile in workfiles:
298 298
299 # Skip if file is not FITS 299 # Skip if file is not FITS
300 - if not gammalib.is_fits(fitsfile): 300 + if not gammalib.GFilename(fitsfile).is_fits():
301 if self.logTerse(): 301 if self.logTerse():
302 self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") 302 self.log("Skipping file \""+fitsfile+" (not a FITS file)\n")
303 continue 303 continue
src/ctmodel/ctmodel.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctmodel - Model cube generation tool * 2 * ctmodel - Model cube generation tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2012-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2012-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
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 *
@@ -303,8 +303,7 @@ void ctmodel::run(void) @@ -303,8 +303,7 @@ void ctmodel::run(void)
303 fill_cube(obs); 303 fill_cube(obs);
304 304
305 // Dispose events to free memory if event file exists on disk 305 // Dispose events to free memory if event file exists on disk
306 - if (obs->eventfile().length() > 0 &&  
307 - gammalib::file_exists(obs->eventfile())) { 306 + if (obs->eventfile().length() > 0 && obs->eventfile().exists()) {
308 obs->dispose_events(); 307 obs->dispose_events();
309 } 308 }
310 309
@@ -673,7 +672,7 @@ void ctmodel::get_obs(void) @@ -673,7 +672,7 @@ void ctmodel::get_obs(void)
673 672
674 // If file is a FITS file then create an empty CTA observation 673 // If file is a FITS file then create an empty CTA observation
675 // and load file into observation 674 // and load file into observation
676 - if (gammalib::is_fits(filename)) { 675 + if (GFilename(filename).is_fits()) {
677 676
678 // Allocate empty CTA observation 677 // Allocate empty CTA observation
679 GCTAObservation cta; 678 GCTAObservation cta;
src/ctselect/ctselect.cpp
@@ -295,7 +295,7 @@ void ctselect::run(void) @@ -295,7 +295,7 @@ void ctselect::run(void)
295 if (fname.has_extname()) { 295 if (fname.has_extname()) {
296 m_evtname[i] = fname.extname(); 296 m_evtname[i] = fname.extname();
297 } 297 }
298 - m_gtiname[i] = get_gtiname(fname.filename(), m_evtname[i]); 298 + m_gtiname[i] = get_gtiname(fname.url(), m_evtname[i]);
299 299
300 // Log input file information 300 // Log input file information
301 if (logTerse()) { 301 if (logTerse()) {
@@ -1184,7 +1184,7 @@ std::string ctselect::set_outfile_name(const std::string& filename) const @@ -1184,7 +1184,7 @@ std::string ctselect::set_outfile_name(const std::string& filename) const
1184 GFilename fname(filename); 1184 GFilename fname(filename);
1185 1185
1186 // Split input filename without any extensions into path elements 1186 // Split input filename without any extensions into path elements
1187 - std::vector<std::string> elements = gammalib::split(fname.filename(), "/"); 1187 + std::vector<std::string> elements = gammalib::split(fname.url(), "/");
1188 1188
1189 // The last path element is the filename 1189 // The last path element is the filename
1190 std::string outname = m_prefix + elements[elements.size()-1]; 1190 std::string outname = m_prefix + elements[elements.size()-1];
@@ -1254,7 +1254,7 @@ void ctselect::save_fits(void) @@ -1254,7 +1254,7 @@ void ctselect::save_fits(void)
1254 GFilename fname(m_outobs); 1254 GFilename fname(m_outobs);
1255 1255
1256 // Extract filename and event extension name 1256 // Extract filename and event extension name
1257 - std::string outfile = fname.filename(); 1257 + std::string outfile = fname.url();
1258 1258
1259 // Append event extension name. We handle here the possibility 1259 // Append event extension name. We handle here the possibility
1260 // to write the events into a different extension. 1260 // to write the events into a different extension.
@@ -1458,7 +1458,7 @@ void ctselect::save_event_list(const GCTAObservation* obs, @@ -1458,7 +1458,7 @@ void ctselect::save_event_list(const GCTAObservation* obs,
1458 infits.close(); 1458 infits.close();
1459 1459
1460 // Save file to disk and close it (we need both operations) 1460 // Save file to disk and close it (we need both operations)
1461 - outfits.saveto(outname.filename(), clobber()); 1461 + outfits.saveto(outname.url(), clobber());
1462 outfits.close(); 1462 outfits.close();
1463 1463
1464 } // endif: observation was unbinned 1464 } // endif: observation was unbinned
src/support/ctool.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctool - ctool base class * 2 * ctool - ctool base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2014-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2014-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
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 *
@@ -327,7 +327,7 @@ GObservations ctool::get_observations(const bool&amp; get_response) @@ -327,7 +327,7 @@ GObservations ctool::get_observations(const bool&amp; get_response)
327 327
328 // If file is a FITS file then create an empty CTA observation 328 // If file is a FITS file then create an empty CTA observation
329 // and load file into observation 329 // and load file into observation
330 - if (gammalib::is_fits(filename)) { 330 + if (GFilename(filename).is_fits()) {
331 331
332 // Allocate empty CTA observation 332 // Allocate empty CTA observation
333 GCTAObservation cta_obs; 333 GCTAObservation cta_obs;
@@ -705,10 +705,10 @@ void ctool::require_inobs(const std::string&amp; method) @@ -705,10 +705,10 @@ void ctool::require_inobs(const std::string&amp; method)
705 void ctool::require_inobs_nolist(const std::string& method) 705 void ctool::require_inobs_nolist(const std::string& method)
706 { 706 {
707 // Get inobs filename 707 // Get inobs filename
708 - std::string filename = (*this)["inobs"].filename(); 708 + GFilename filename = (*this)["inobs"].filename();
709 709
710 // Continue only if we have a FITS file 710 // Continue only if we have a FITS file
711 - if (gammalib::is_fits(filename)) { 711 + if (filename.is_fits()) {
712 712
713 // Signal no list 713 // Signal no list
714 bool is_list = false; 714 bool is_list = false;
@@ -757,10 +757,10 @@ void ctool::require_inobs_nolist(const std::string&amp; method) @@ -757,10 +757,10 @@ void ctool::require_inobs_nolist(const std::string&amp; method)
757 void ctool::require_inobs_nocube(const std::string& method) 757 void ctool::require_inobs_nocube(const std::string& method)
758 { 758 {
759 // Get inobs filename 759 // Get inobs filename
760 - std::string filename = (*this)["inobs"].filename(); 760 + GFilename filename = (*this)["inobs"].filename();
761 761
762 // Continue only if we have a FITS file 762 // Continue only if we have a FITS file
763 - if (gammalib::is_fits(filename)) { 763 + if (filename.is_fits()) {
764 764
765 // Signal no cube 765 // Signal no cube
766 bool is_cube = false; 766 bool is_cube = false;