From c5a2d15fdefdbcf8b6f158ab01f4ffdad2b96716 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 16 Feb 2016 02:49:56 +0100 Subject: [PATCH] Adapt to new GFilename class interface. --- cscripts/csfindobs.py | 3 ++- cscripts/csiactcopy.py | 3 ++- cscripts/csiactobs.py | 30 ++++++++++++++++-------------- cscripts/csobs2caldb.py | 10 +++++----- cscripts/csresmap.py | 7 ++++--- cscripts/cstsmapmerge.py | 6 +++--- src/ctmodel/ctmodel.cpp | 7 +++---- src/ctselect/ctselect.cpp | 8 ++++---- src/support/ctool.cpp | 12 ++++++------ 9 files changed, 45 insertions(+), 41 deletions(-) diff --git a/cscripts/csfindobs.py b/cscripts/csfindobs.py index de7c52d..ffd8481 100755 --- a/cscripts/csfindobs.py +++ b/cscripts/csfindobs.py @@ -178,7 +178,8 @@ class csfindobs(ctools.cscript): # Check HDUs if self.m_obs_index == "": raise RuntimeError("FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names") - if not gammalib.is_fits(self.m_obs_index+"[OBS_INDEX]"): + filename = gammalib.GFilename(self.m_obs_index+"[OBS_INDEX]") + if not filename.is_fits(): 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.") # Set other members diff --git a/cscripts/csiactcopy.py b/cscripts/csiactcopy.py index e8961aa..6177b3f 100755 --- a/cscripts/csiactcopy.py +++ b/cscripts/csiactcopy.py @@ -447,7 +447,8 @@ class csiactcopy(ctools.cscript): obs = os.path.join(self.m_outpath, config["obsindx"]) # Check if index files are available - if not (gammalib.is_fits(str(hdu)) and gammalib.is_fits(str(obs))): + if not (gammalib.GFilename(str(hdu)).is_fits() and + gammalib.GFilename(str(obs)).is_fits()): if self.logTerse(): self.log("Removing \""+str(config["name"])+"\" (not available)") self.log("\n") diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index 50c60cc..86683ed 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -196,12 +196,14 @@ class csiactobs(ctools.cscript): # Check HDUs if self.m_hdu_index == "" or self.m_obs_index == "": raise RuntimeError("*** ERROR: FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names") - if not gammalib.is_fits(self.m_hdu_index+"[HDU_INDEX]"): + filename = gammalib.GFilename(self.m_hdu_index+"[HDU_INDEX]") + if not filename.is_fits(): 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.") # Check for existence of "BKG_SCALE" in the observation index file if required if self.m_use_bkg_scale: - if gammalib.is_fits(self.m_obs_index+"[OBS_INDEX]"): + filename = gammalib.GFilename(self.m_obs_index+"[OBS_INDEX]") + if filename.is_fits(): fits = gammalib.GFits(self.m_obs_index) if not fits["OBS_INDEX"].contains("BKG_SCALE"): self.m_use_bkg_scale = False @@ -439,10 +441,10 @@ class csiactobs(ctools.cscript): index = formats.index(version) break if index >= 0: - eventfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) - eventhdu = hduindx_hdu["HDU_NAME"][index] + eventfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) + eventhdu = hduindx_hdu["HDU_NAME"][index] eventfile += "["+eventhdu+"]" - if not gammalib.is_fits(eventfile): + if not gammalib.GFilename(eventfile).is_fits(): if self.logTerse(): self.log("Skipping observation "+str(obs_id)+": eventfile \""+eventfile+"\" not found\n") continue @@ -455,10 +457,10 @@ class csiactobs(ctools.cscript): index = formats.index(version) break if index >= 0: - aefffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) - aeffhdu = hduindx_hdu["HDU_NAME"][index] + aefffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) + aeffhdu = hduindx_hdu["HDU_NAME"][index] aefffile += "["+aeffhdu+"]" - if not gammalib.is_fits(aefffile): + if not gammalib.GFilename(aefffile).is_fits(): if self.logTerse(): self.log("Skipping observation "+str(obs_id)+": effective area \""+aefffile+"\" not found\n") continue @@ -471,9 +473,9 @@ class csiactobs(ctools.cscript): index = formats.index(version) break if index >= 0: - psffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) + psffile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) psffile += "["+hduindx_hdu["HDU_NAME"][index]+"]" - if not gammalib.is_fits(psffile): + if not gammalib.GFilename(psffile).is_fits(): if self.logTerse(): self.log("Skipping observation "+str(obs_id)+": point spread function \""+psffile+"\" not found\n") continue @@ -486,9 +488,9 @@ class csiactobs(ctools.cscript): index = formats.index(version) break if index >= 0: - edispfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) + edispfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) edispfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" - if not gammalib.is_fits(edispfile): + if not gammalib.GFilename(edispfile).is_fits(): if self.logTerse(): self.log("Warning: observation "+str(obs_id)+" has no energy dispersion \""+edispfile+"\" information\n") edispfile = "" @@ -502,9 +504,9 @@ class csiactobs(ctools.cscript): index = formats.index(version) break if index >= 0: - bkgfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) + bkgfile = os.path.join(self.subdir, hduindx_hdu["FILE_DIR"][index], hduindx_hdu["FILE_NAME"][index]) bkgfile += "["+hduindx_hdu["HDU_NAME"][index]+"]" - if not gammalib.is_fits(bkgfile): + if not gammalib.GFilename(bkgfile).is_fits(): if self.logTerse(): self.log("Warning: observation "+str(obs_id)+" has no background information (file=\""+bkgfile+"\"). IRF background cannot be used\n") bkgfile = "" diff --git a/cscripts/csobs2caldb.py b/cscripts/csobs2caldb.py index c68226c..62ef217 100755 --- a/cscripts/csobs2caldb.py +++ b/cscripts/csobs2caldb.py @@ -2,7 +2,7 @@ # ========================================================================== # Generation of an caldb entry from general IACT observation. # -# Copyright (C) 2015 Michael Mayer +# Copyright (C) 2015-2016 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -152,10 +152,10 @@ class csobs2caldb(ctools.cscript): fname_bkg = gammalib.GFilename(rsp.background().filename()) # Open FITS files of response components - fits_aeff = gammalib.GFits(fname_aeff.filename()) - fits_psf = gammalib.GFits(fname_psf.filename()) - fits_edisp = gammalib.GFits(fname_edisp.filename()) - fits_bkg = gammalib.GFits(fname_bkg.filename()) + fits_aeff = gammalib.GFits(fname_aeff) + fits_psf = gammalib.GFits(fname_psf) + fits_edisp = gammalib.GFits(fname_edisp) + fits_bkg = gammalib.GFits(fname_bkg) # Bundle IRFs into one file fits.append(fits_aeff[fname_aeff.extname("EFFECTIVE AREA")]) diff --git a/cscripts/csresmap.py b/cscripts/csresmap.py index a3d8e44..f63cc93 100755 --- a/cscripts/csresmap.py +++ b/cscripts/csresmap.py @@ -2,7 +2,7 @@ # ========================================================================== # Residual map generation script. # -# Copyright (C) 2014-2015 Michael Mayer +# Copyright (C) 2014-2016 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -143,9 +143,10 @@ class csresmap(ctools.cscript): # First check if the inobs parameter is a counts cube if self.obs.size() == 0 and self["inobs"].filename() != "NONE": - if gammalib.is_fits(self["inobs"].filename()): + filename = gammalib.GFilename(self["inobs"].filename()) + if filename.is_fits(): cta = gammalib.GCTAObservation() - cta.load(self["inobs"].filename()) + cta.load(filename) if cta.eventtype() == "CountsCube": self.m_skip_binning = True diff --git a/cscripts/cstsmapmerge.py b/cscripts/cstsmapmerge.py index 5ab465e..2ef812f 100755 --- a/cscripts/cstsmapmerge.py +++ b/cscripts/cstsmapmerge.py @@ -2,7 +2,7 @@ # ========================================================================== # Merges sliced TS map files into one map # -# Copyright (C) 2015 Michael Mayer +# Copyright (C) 2015-2016 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -261,7 +261,7 @@ class cstsmapmerge(ctools.cscript): # Test files for the entry status map # use the first one to appear useful for fitsfile in self.files: - if not gammalib.is_fits(fitsfile): + if not gammalib.GFilename(fitsfile).is_fits(): self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") fits = gammalib.GFits(fitsfile) @@ -297,7 +297,7 @@ class cstsmapmerge(ctools.cscript): for fitsfile in workfiles: # Skip if file is not FITS - if not gammalib.is_fits(fitsfile): + if not gammalib.GFilename(fitsfile).is_fits(): if self.logTerse(): self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") continue diff --git a/src/ctmodel/ctmodel.cpp b/src/ctmodel/ctmodel.cpp index fa0ae9d..e7280ea 100644 --- a/src/ctmodel/ctmodel.cpp +++ b/src/ctmodel/ctmodel.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctmodel - Model cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2015 by Juergen Knoedlseder * + * copyright (C) 2012-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -303,8 +303,7 @@ void ctmodel::run(void) fill_cube(obs); // Dispose events to free memory if event file exists on disk - if (obs->eventfile().length() > 0 && - gammalib::file_exists(obs->eventfile())) { + if (obs->eventfile().length() > 0 && obs->eventfile().exists()) { obs->dispose_events(); } @@ -673,7 +672,7 @@ void ctmodel::get_obs(void) // If file is a FITS file then create an empty CTA observation // and load file into observation - if (gammalib::is_fits(filename)) { + if (GFilename(filename).is_fits()) { // Allocate empty CTA observation GCTAObservation cta; diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index f23e80d..d73c24c 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -295,7 +295,7 @@ void ctselect::run(void) if (fname.has_extname()) { m_evtname[i] = fname.extname(); } - m_gtiname[i] = get_gtiname(fname.filename(), m_evtname[i]); + m_gtiname[i] = get_gtiname(fname.url(), m_evtname[i]); // Log input file information if (logTerse()) { @@ -1184,7 +1184,7 @@ std::string ctselect::set_outfile_name(const std::string& filename) const GFilename fname(filename); // Split input filename without any extensions into path elements - std::vector elements = gammalib::split(fname.filename(), "/"); + std::vector elements = gammalib::split(fname.url(), "/"); // The last path element is the filename std::string outname = m_prefix + elements[elements.size()-1]; @@ -1254,7 +1254,7 @@ void ctselect::save_fits(void) GFilename fname(m_outobs); // Extract filename and event extension name - std::string outfile = fname.filename(); + std::string outfile = fname.url(); // Append event extension name. We handle here the possibility // to write the events into a different extension. @@ -1458,7 +1458,7 @@ void ctselect::save_event_list(const GCTAObservation* obs, infits.close(); // Save file to disk and close it (we need both operations) - outfits.saveto(outname.filename(), clobber()); + outfits.saveto(outname.url(), clobber()); outfits.close(); } // endif: observation was unbinned diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index fc6e872..ee6f9fe 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctool - ctool base class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Juergen Knoedlseder * + * copyright (C) 2014-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -327,7 +327,7 @@ GObservations ctool::get_observations(const bool& get_response) // If file is a FITS file then create an empty CTA observation // and load file into observation - if (gammalib::is_fits(filename)) { + if (GFilename(filename).is_fits()) { // Allocate empty CTA observation GCTAObservation cta_obs; @@ -705,10 +705,10 @@ void ctool::require_inobs(const std::string& method) void ctool::require_inobs_nolist(const std::string& method) { // Get inobs filename - std::string filename = (*this)["inobs"].filename(); + GFilename filename = (*this)["inobs"].filename(); // Continue only if we have a FITS file - if (gammalib::is_fits(filename)) { + if (filename.is_fits()) { // Signal no list bool is_list = false; @@ -757,10 +757,10 @@ void ctool::require_inobs_nolist(const std::string& method) void ctool::require_inobs_nocube(const std::string& method) { // Get inobs filename - std::string filename = (*this)["inobs"].filename(); + GFilename filename = (*this)["inobs"].filename(); // Continue only if we have a FITS file - if (gammalib::is_fits(filename)) { + if (filename.is_fits()) { // Signal no cube bool is_cube = false; -- libgit2 0.21.4