diff --git a/NEWS b/NEWS index 200cd0b..e996b80 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 1.6.0 -25 June 2018 +28 June 2018 1. Introduction @@ -24,12 +24,16 @@ The following methods have been added: - gammalib::atan2() - gammalib::plaw_integral() - gammalib::gauss_integral() -- GSkyDir::cos_dist() +- GApplication(std::string&, std::string&, std::vector&) +- GApplicationPar::pickle() - GApplicationPar::query() - GApplicationPar::was_queried() +- GApplicationPars::pickle() - GApplicationPars::syspfiles() - operator==(GSkyPixel&, GSkyPixel&) - operator!=(GSkyPixel&, GSkyPixel&) +- GArf::read(GFits&) +- GPha::read(GFits&) - GPha::operator(int&, int&) - GPha::operator[](std::string&) - GPha::columns() @@ -47,20 +51,27 @@ The following methods have been added: - GPha::respfile() - GPha::ancrfile(std::string&) - GPha::ancrfile() +- GRmf::read(GFits&) - GFitsHDU::header(GFitsHeader&) - GFitsHDU::card(std::string&, bool&, std::string&) -- GFitsHeaderCard general card constructor -- GFitsHeaderCard boolean constructor +- GFitsHeaderCard(std::string&, std::string&, std::string&, std::string&) +- GFitsHeaderCard(std::string&, bool&, std::string&) - GObservation::has_events() - GModelSpatialPointSource::type(std::string&) - GModelSpectralPlaw::type(std::string&) - GModelSpatialRadialProfileGauss(GSkyDir&, double&) - GModelSpatialRadialProfileGauss::sigma() +- GSkyDir::cos_dist() +- GSkyRegions::filename(GFilename&) - GXml::GXml(GXmlDocument&) - GXml::root() - GXmlElement::attributes() - GXmlElement::attribute(int&) - GXmlDocument::GXmlDocument(GFilename&, std::string&, std::string&, std::string&) +- GCTAObservation::instrument(std::string&) +- GCTAObservation::lo_user_thres(double&) +- GCTAObservation::hi_user_thres(double&) +- GCTAOnOffObservation::has_response() - GCTAInstDir::theta() - GCTAInstDir::phi() - GCTAEventAtom(GCTAInstDir&, GEnergy&, GTime&) @@ -72,6 +83,9 @@ The following methods have been added: - GCTAEdispPerfTable::prob_erecobin() - GCTAEdispRmf::prob_erecobin() - GCTAEdisp2D::prob_erecobin() +- GCTAModelAeffBackground(GModelSpectral&, GModelTemporal&) +- GCTAModelCubeBackground(GModelSpectral&, GModelTemporal&) +- GCTAModelRadialAcceptance(GCTAModelRadial&, GModelSpectral&, GModelTemporal&) - GCTAModelRadialAcceptance::radial(GCTAModelRadial*) - GCTAModelRadialAcceptance::spectral(GModelSpectral*) - GCTAModelRadialAcceptance::temporal(GModelTemporal*) @@ -79,13 +93,13 @@ The following methods have been added: - GCTAModelIrfBackground::temporal(GModelTemporal*) The following methods have been removed: -- none +- GSkyRegionMap::filename() The following methods have been renamed: - GPhoton::mc_id() from GPhoton::mcid() The arguments for the following methods have been changed: -- GCTAOnOffObservation CTA observation constructor now takes a spatial model component +- GCTAOnOffObservation(GCTAObservation&, GModelSpatial&, GEbounds&, GEbounds&, GSkyRegions&, GSkyRegions&) The return value of the following methods has been changed: - none diff --git a/include/GApplication.hpp b/include/GApplication.hpp index 78f4d07..a716163 100644 --- a/include/GApplication.hpp +++ b/include/GApplication.hpp @@ -53,6 +53,8 @@ public: GApplication(void); GApplication(const std::string& name, const std::string& version); GApplication(const std::string& name, const std::string& version, + const std::vector& args); + GApplication(const std::string& name, const std::string& version, int argc, char* argv[]); GApplication(const GApplication& app); ~GApplication(void); @@ -65,49 +67,50 @@ public: const GApplicationPar& operator[](const std::string& name) const; // Methods - void clear(void); - GApplication* clone(void) const; - std::string classname(void) const; - const std::string& name(void) const; - const std::string& version(void) const; - double telapse(void) const; - double celapse(void) const; - void logFileOpen(const bool& clobber = true); - void logFileClose(void); - bool logTerse(void) const; - bool logNormal(void) const; - bool logExplicit(void) const; - bool logVerbose(void) const; - bool logDebug(void) const; - bool clobber(void) const; - bool has_par(const std::string& name) const; - const std::string& par_filename(void) const; - const std::string& log_filename(void) const; - void log_header(void); - void log_trailer(void); - void log_string(const GChatter& chatter, - const std::string& string, - const bool& linefeed = true); - void log_value(const GChatter& chatter, - const std::string& name, - const std::string& value); - void log_value(const GChatter& chatter, - const std::string& name, - const int& value); - void log_value(const GChatter& chatter, - const std::string& name, - const double& value); - void log_header1(const GChatter& chatter, - const std::string& header); - void log_header2(const GChatter& chatter, - const std::string& header); - void log_header3(const GChatter& chatter, - const std::string& header); - void log_parameters(const GChatter& chatter); - const bool& need_help(void) const; - const GApplicationPars& pars(void) const; - void pars(const GApplicationPars& pars); - std::string print(const GChatter& chatter = NORMAL) const; + void clear(void); + GApplication* clone(void) const; + std::string classname(void) const; + const std::string& name(void) const; + const std::string& version(void) const; + double telapse(void) const; + double celapse(void) const; + void logFileOpen(const bool& clobber = true); + void logFileClose(void); + bool logTerse(void) const; + bool logNormal(void) const; + bool logExplicit(void) const; + bool logVerbose(void) const; + bool logDebug(void) const; + bool clobber(void) const; + bool has_par(const std::string& name) const; + const std::string& par_filename(void) const; + const std::string& log_filename(void) const; + void log_header(void); + void log_trailer(void); + void log_string(const GChatter& chatter, + const std::string& string, + const bool& linefeed = true); + void log_value(const GChatter& chatter, + const std::string& name, + const std::string& value); + void log_value(const GChatter& chatter, + const std::string& name, + const int& value); + void log_value(const GChatter& chatter, + const std::string& name, + const double& value); + void log_header1(const GChatter& chatter, + const std::string& header); + void log_header2(const GChatter& chatter, + const std::string& header); + void log_header3(const GChatter& chatter, + const std::string& header); + void log_parameters(const GChatter& chatter); + const bool& need_help(void) const; + const GApplicationPars& pars(void) const; + void pars(const GApplicationPars& pars); + const std::vector& args(void) const; + std::string print(const GChatter& chatter = NORMAL) const; // Public members GLog log; //!< Application logger @@ -117,6 +120,9 @@ protected: void init_members(void); void copy_members(const GApplication& app); void free_members(void); + void set_members(const std::string& name, + const std::string& version, + const std::vector& args); void set_log_chatter(void); void set_log_filename(void); @@ -312,4 +318,16 @@ void GApplication::pars(const GApplicationPars& pars) return; } + +/***********************************************************************//** + * @brief Return command line arguments + * + * @return Command line arguments. + ***************************************************************************/ +inline +const std::vector& GApplication::args(void) const +{ + return m_args; +} + #endif /* GAPPLICATION_HPP */ diff --git a/include/GApplicationPar.hpp b/include/GApplicationPar.hpp index 6ba0458..538f893 100644 --- a/include/GApplicationPar.hpp +++ b/include/GApplicationPar.hpp @@ -29,6 +29,7 @@ /* __ Includes ___________________________________________________________ */ #include +#include #include "GBase.hpp" #include "GTime.hpp" @@ -62,42 +63,44 @@ public: GApplicationPar& operator=(const GApplicationPar& par); // Methods - void clear(void); - GApplicationPar* clone(void) const; - std::string classname(void) const; - void type(const std::string& type); - void mode(const std::string& mode); - void value(const std::string& value); - void string(const std::string& value); - void filename(const GFilename& value); - void time(const GTime& value); - void boolean(const bool& value); - void integer(const int& value); - void real(const double& value); - const std::string& name(void) const; - const std::string& type(void) const; - const std::string& mode(void) const; - void query(void); - std::string value(void); - std::string string(void); - GFilename filename(void); - GTime time(void); - GTime time(const GTimeReference& ref); - bool boolean(void); - int integer(void); - double real(void); - const std::string& current_value(void) const; - const std::string& min(void) const; - const std::string& max(void) const; - const std::string& prompt(void) const; - bool is_learn(void) const; - bool is_query(void) const; - bool is_filename(void) const; - bool is_valid(void); - bool is_undefined(void); - bool is_notanumber(void); - bool was_queried(void) const; - std::string print(const GChatter& chatter = NORMAL) const; + void clear(void); + GApplicationPar* clone(void) const; + std::string classname(void) const; + void type(const std::string& type); + void mode(const std::string& mode); + void value(const std::string& value); + void string(const std::string& value); + void filename(const GFilename& value); + void time(const GTime& value); + void boolean(const bool& value); + void integer(const int& value); + void real(const double& value); + const std::string& name(void) const; + const std::string& type(void) const; + const std::string& mode(void) const; + void query(void); + std::string value(void); + std::string string(void); + GFilename filename(void); + GTime time(void); + GTime time(const GTimeReference& ref); + bool boolean(void); + int integer(void); + double real(void); + const std::string& current_value(void) const; + const std::string& min(void) const; + const std::string& max(void) const; + const std::string& prompt(void) const; + bool is_learn(void) const; + bool is_query(void) const; + bool is_filename(void) const; + bool is_valid(void); + bool is_undefined(void); + bool is_notanumber(void); + bool was_queried(void) const; + void pickle(const std::vector& string); + std::vector pickle(void) const; + std::string print(const GChatter& chatter = NORMAL) const; protected: // Protected enumerators diff --git a/include/GApplicationPars.hpp b/include/GApplicationPars.hpp index db1e91c..14a4d78 100644 --- a/include/GApplicationPars.hpp +++ b/include/GApplicationPars.hpp @@ -66,30 +66,32 @@ public: const GApplicationPar& operator[](const std::string& name) const; // Methods - void clear(void); - GApplicationPars* clone(void) const; - std::string classname(void) const; - GApplicationPar& at(const int& index); - const GApplicationPar& at(const int& index) const; - int size(void) const; - bool is_empty(void) const; - GApplicationPar& append(const GApplicationPar& par); - void append_standard(void); - GApplicationPar& insert(const int& index, const GApplicationPar& par); - GApplicationPar& insert(const std::string& name, - const GApplicationPar& par); - void remove(const int& index); - void remove(const std::string& name); - void reserve(const int& num); - void extend(const GApplicationPars& pars); - bool contains(const std::string& name) const; - void syspfiles(const std::string& syspfiles); - const std::string& syspfiles(void) const; - void load(const GFilename& filename); - void load(const GFilename& filename, - const std::vector& args); - void save(const GFilename& filename); - std::string print(const GChatter& chatter = NORMAL) const; + void clear(void); + GApplicationPars* clone(void) const; + std::string classname(void) const; + GApplicationPar& at(const int& index); + const GApplicationPar& at(const int& index) const; + int size(void) const; + bool is_empty(void) const; + GApplicationPar& append(const GApplicationPar& par); + void append_standard(void); + GApplicationPar& insert(const int& index, const GApplicationPar& par); + GApplicationPar& insert(const std::string& name, + const GApplicationPar& par); + void remove(const int& index); + void remove(const std::string& name); + void reserve(const int& num); + void extend(const GApplicationPars& pars); + bool contains(const std::string& name) const; + void syspfiles(const std::string& syspfiles); + const std::string& syspfiles(void) const; + void load(const GFilename& filename); + void load(const GFilename& filename, + const std::vector& args); + void save(const GFilename& filename); + void pickle(const std::vector& string); + std::vector pickle(void) const; + std::string print(const GChatter& chatter = NORMAL) const; protected: // Protected methods diff --git a/include/GArf.hpp b/include/GArf.hpp index 96a5e28..19b35d9 100644 --- a/include/GArf.hpp +++ b/include/GArf.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GArf.hpp - XSPEC Auxiliary Response File class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2017 by Juergen Knoedlseder * + * copyright (C) 2013-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -100,6 +100,7 @@ public: void load(const GFilename& filename); void save(const GFilename& filename, const bool& clobber = false) const; + void read(const GFits& fits); void read(const GFitsTable& table); void write(GFits& fits) const; const GFilename& filename(void) const; diff --git a/include/GFitsAsciiTable.hpp b/include/GFitsAsciiTable.hpp index 4f1b5a5..69d00ca 100644 --- a/include/GFitsAsciiTable.hpp +++ b/include/GFitsAsciiTable.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsAsciiTable.hpp - FITS ASCII table class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2014 by Juergen Knoedlseder * + * copyright (C) 2008-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -65,6 +65,7 @@ private: void init_members(void); void copy_members(const GFitsAsciiTable& table); void free_members(void); + void init_table_header(void); }; diff --git a/include/GFitsBinTable.hpp b/include/GFitsBinTable.hpp index 18b94d5..ba83366 100644 --- a/include/GFitsBinTable.hpp +++ b/include/GFitsBinTable.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsBinTable.hpp - FITS binary table class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2015 by Juergen Knoedlseder * + * copyright (C) 2008-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -59,6 +59,7 @@ private: void init_members(void); void copy_members(const GFitsBinTable& table); void free_members(void); + void init_table_header(void); }; diff --git a/include/GModelSpatialDiffuseCube.hpp b/include/GModelSpatialDiffuseCube.hpp index b81f012..7df68dd 100644 --- a/include/GModelSpatialDiffuseCube.hpp +++ b/include/GModelSpatialDiffuseCube.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialDiffuseCube.hpp - Spatial map cube model class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -110,7 +110,8 @@ public: void load(const GFilename& filename); void save(const GFilename& filename, const bool& clobber = false) const; - void write(GFits& file) const; + void read(const GFits& fits); + void write(GFits& fits) const; protected: // Protected methods diff --git a/include/GPha.hpp b/include/GPha.hpp index 8dc955f..2c4281c 100644 --- a/include/GPha.hpp +++ b/include/GPha.hpp @@ -134,6 +134,7 @@ public: void load(const GFilename& filename); void save(const GFilename& filename, const bool& clobber = false) const; + void read(const GFits& fits); void read(const GFitsTable& table); void write(GFits& fits) const; const GFilename& filename(void) const; diff --git a/include/GRmf.hpp b/include/GRmf.hpp index 09bedb2..fdbafdb 100644 --- a/include/GRmf.hpp +++ b/include/GRmf.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GRmf.hpp - XSPEC Redistribution Matrix File class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2017 by Juergen Knoedlseder * + * copyright (C) 2013-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -97,6 +97,7 @@ public: void save(const GFilename& filename, const bool& clobber = false, const std::string& unit = "keV") const; + void read(const GFits& fits); void read(const GFitsTable& table); void write(GFits& fits, const std::string& unit = "keV") const; diff --git a/include/GSkyRegionMap.hpp b/include/GSkyRegionMap.hpp index 8815d72..f207a35 100644 --- a/include/GSkyRegionMap.hpp +++ b/include/GSkyRegionMap.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyRegionMap.hpp - Sky region map class * * ----------------------------------------------------------------------- * - * copyright (C) 2017 by Pierrick Martin * + * copyright (C) 2017-2018 by Pierrick Martin * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -45,17 +45,17 @@ class GSkyRegionMap; * @brief Interface for a sky region map * * This class provides an implementation for a sky region defined by a - * sky map. The map is provided as a FITS file filled with 0 and non-zero - * values. + * sky map. The map is provided as a FITS file. Pixels with non-zero values + * are within the region, pixels with zero values outside the region. ***************************************************************************/ class GSkyRegionMap : public GSkyRegion { public: // Constructors and destructors GSkyRegionMap(void); - GSkyRegionMap(const GFilename& filename); - GSkyRegionMap(const GSkyMap& map); - GSkyRegionMap(const GSkyRegion* region); + explicit GSkyRegionMap(const GFilename& filename); + explicit GSkyRegionMap(const GSkyMap& map); + explicit GSkyRegionMap(const GSkyRegion* region); GSkyRegionMap(const GSkyRegionMap& region); virtual ~GSkyRegionMap(void); @@ -77,7 +77,6 @@ public: void load(const GFilename& filename); void map(const GSkyMap& map); const GSkyMap& map(void) const; - const GFilename& filename(void) const; const std::vector& nonzero_indices(void) const; protected: @@ -92,7 +91,6 @@ protected: // Protected members GSkyMap m_map; //!< The region map std::vector m_nonzero_indices; //!< Vector of non-zero pixel indices - mutable GFilename m_filename; //!< Filename of origin (if any) }; @@ -142,10 +140,12 @@ const std::vector& GSkyRegionMap::nonzero_indices(void) const * which the region was saved. The returned string will be empty if * no load() or save() method has been called before. ***************************************************************************/ +/* inline const GFilename& GSkyRegionMap::filename(void) const { return (m_filename); } +*/ #endif /* GSKYREGIONMAP_HPP */ diff --git a/include/GSkyRegions.hpp b/include/GSkyRegions.hpp index 60c8af1..39a93f6 100644 --- a/include/GSkyRegions.hpp +++ b/include/GSkyRegions.hpp @@ -87,6 +87,7 @@ public: void load(const GFilename& filename); void save(const GFilename& filename) const; const GFilename& filename(void) const; + void filename(const GFilename& filename); std::string print(const GChatter& chatter = NORMAL) const; protected: @@ -185,14 +186,14 @@ void GSkyRegions::reserve(const int& num) /***********************************************************************//** - * @brief Return file name + * @brief Return regions file name * * @return File name from which the regions have been loaded or into which * the regions have been saved. * * Returns the file name from which the regions have been loaded or into - * which the regions have been saved. The returned string will be empty if - * no load() or save() method has been called before. + * which the regions have been saved. The returned string will be set if + * the load(), save() or filename() setter methods were called. ***************************************************************************/ inline const GFilename& GSkyRegions::filename(void) const @@ -200,4 +201,19 @@ const GFilename& GSkyRegions::filename(void) const return (m_filename); } + +/***********************************************************************//** + * @brief Set regions file name + * + * @param[in] filename Regions file name. + * + * Set the regions file name. + ***************************************************************************/ +inline +void GSkyRegions::filename(const GFilename& filename) +{ + m_filename = filename; + return; +} + #endif /* GSKYREGIONS_HPP */ diff --git a/inst/cta/include/GCTAModelAeffBackground.hpp b/inst/cta/include/GCTAModelAeffBackground.hpp index 05ca443..adac974 100644 --- a/inst/cta/include/GCTAModelAeffBackground.hpp +++ b/inst/cta/include/GCTAModelAeffBackground.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelAeffBackground.hpp - CTA Aeff background model class * * ----------------------------------------------------------------------- * - * copyright (C) 2015-2016 by Michael Mayer * + * copyright (C) 2015-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -51,6 +51,8 @@ public: GCTAModelAeffBackground(void); explicit GCTAModelAeffBackground(const GXmlElement& xml); explicit GCTAModelAeffBackground(const GModelSpectral& spectral); + GCTAModelAeffBackground(const GModelSpectral& spectral, + const GModelTemporal& temporal); GCTAModelAeffBackground(const GCTAModelAeffBackground& bgd); virtual ~GCTAModelAeffBackground(void); diff --git a/inst/cta/include/GCTAModelCubeBackground.hpp b/inst/cta/include/GCTAModelCubeBackground.hpp index 7da5052..c6c5b14 100644 --- a/inst/cta/include/GCTAModelCubeBackground.hpp +++ b/inst/cta/include/GCTAModelCubeBackground.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelCubeBackground.hpp - CTA cube background model class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2016 by Michael Mayer * + * copyright (C) 2013-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -56,6 +56,8 @@ public: GCTAModelCubeBackground(void); explicit GCTAModelCubeBackground(const GXmlElement& xml); explicit GCTAModelCubeBackground(const GModelSpectral& spectral); + GCTAModelCubeBackground(const GModelSpectral& spectral, + const GModelTemporal& temporal); GCTAModelCubeBackground(const GCTAModelCubeBackground& bgd); virtual ~GCTAModelCubeBackground(void); diff --git a/inst/cta/include/GCTAModelRadial.hpp b/inst/cta/include/GCTAModelRadial.hpp index f881b28..214f827 100644 --- a/inst/cta/include/GCTAModelRadial.hpp +++ b/inst/cta/include/GCTAModelRadial.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelRadial.hpp - Radial model abstract base class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -21,7 +21,7 @@ /** * @file GCTAModelRadial.hpp * @brief Abstract radial acceptance model class interface definition - * @author J. Knodlseder + * @author Juergen Knoedlseder */ #ifndef GCTAMODELRADIAL_HPP @@ -73,7 +73,7 @@ public: virtual std::string print(const GChatter& chatter = NORMAL) const = 0; // Methods - int size(void) const { return (int)m_pars.size(); } + int size(void) const; protected: // Protected methods @@ -85,4 +85,16 @@ protected: std::vector m_pars; //!< Parameter pointers }; + +/***********************************************************************//** + * @brief Return number of model parameters + * + * @return Number of model parameters. + ***************************************************************************/ +inline +int GCTAModelRadial::size(void) const +{ + return ((int)m_pars.size()); +} + #endif /* GCTAMODELRADIAL_HPP */ diff --git a/inst/cta/include/GCTAModelRadialAcceptance.hpp b/inst/cta/include/GCTAModelRadialAcceptance.hpp index 4c3a148..883850c 100644 --- a/inst/cta/include/GCTAModelRadialAcceptance.hpp +++ b/inst/cta/include/GCTAModelRadialAcceptance.hpp @@ -55,8 +55,11 @@ public: // Constructors and destructors GCTAModelRadialAcceptance(void); explicit GCTAModelRadialAcceptance(const GXmlElement& xml); - explicit GCTAModelRadialAcceptance(const GCTAModelRadial& radial, - const GModelSpectral& spectral); + GCTAModelRadialAcceptance(const GCTAModelRadial& radial, + const GModelSpectral& spectral); + GCTAModelRadialAcceptance(const GCTAModelRadial& radial, + const GModelSpectral& spectral, + const GModelTemporal& temporal); GCTAModelRadialAcceptance(const GCTAModelRadialAcceptance& model); virtual ~GCTAModelRadialAcceptance(void); diff --git a/inst/cta/include/GCTAModelRadialPolynom.hpp b/inst/cta/include/GCTAModelRadialPolynom.hpp index b3111f4..52d2bbe 100644 --- a/inst/cta/include/GCTAModelRadialPolynom.hpp +++ b/inst/cta/include/GCTAModelRadialPolynom.hpp @@ -63,7 +63,7 @@ public: virtual ~GCTAModelRadialPolynom(void); // Operators - virtual GCTAModelRadialPolynom& operator= (const GCTAModelRadialPolynom& model); + virtual GCTAModelRadialPolynom& operator=(const GCTAModelRadialPolynom& model); // Implemented pure virtual methods virtual void clear(void); @@ -79,7 +79,6 @@ public: virtual std::string print(const GChatter& chatter = NORMAL) const; // Other methods - int size(void) const; //double coeff(void) const; //void coeff(const double& value); @@ -130,16 +129,4 @@ std::string GCTAModelRadialPolynom::type(void) const return ("Polynom"); } - -/***********************************************************************//** - * @brief Return number of coefficients in polynomial - * - * @return Number of coefficients in polynomial. - ***************************************************************************/ -inline -int GCTAModelRadialPolynom::size(void) const -{ - return (int)m_coeffs.size(); -} - #endif /* GCTAMODELRADIALPOLYNOM_HPP */ diff --git a/inst/cta/include/GCTAObservation.hpp b/inst/cta/include/GCTAObservation.hpp index 4d1214b..f520d05 100644 --- a/inst/cta/include/GCTAObservation.hpp +++ b/inst/cta/include/GCTAObservation.hpp @@ -98,6 +98,7 @@ public: virtual std::string print(const GChatter& chatter = NORMAL) const; // Other methods + void instrument(const std::string& instrument); bool has_response(void) const; bool has_events(void) const; void read(const GFits& fits); @@ -145,7 +146,9 @@ public: const GFilename& eventfile(void) const; std::string eventtype(void) const; void dispose_events(void); + void lo_user_thres(const double& lo_user_thres); const double& lo_user_thres(void) const; + void hi_user_thres(const double& hi_user_thres); const double& hi_user_thres(void) const; void n_tels(const int& tels); const int& n_tels(void) const; @@ -193,6 +196,19 @@ std::string GCTAObservation::classname(void) const /***********************************************************************//** + * @brief Set instrument name + * + * @param[in] instrument Instrument name. + ***************************************************************************/ +inline +void GCTAObservation::instrument(const std::string& instrument) +{ + m_instrument = instrument; + return; +} + + +/***********************************************************************//** * @brief Return instrument name * * @return Instrument name. @@ -462,6 +478,19 @@ const GFilename& GCTAObservation::eventfile(void) const /***********************************************************************//** + * @brief Set user low energy threshold + * + * @param[in] lo_user_thres User low energy threshold. + ***************************************************************************/ +inline +void GCTAObservation::lo_user_thres(const double& lo_user_thres) +{ + m_lo_user_thres = lo_user_thres; + return; +} + + +/***********************************************************************//** * @brief Return user low energy threshold * * @return User low energy threshold. @@ -472,6 +501,20 @@ const double& GCTAObservation::lo_user_thres(void) const return m_lo_user_thres; } + +/***********************************************************************//** + * @brief Set user high energy threshold + * + * @param[in] hi_user_thres User high energy threshold. + ***************************************************************************/ +inline +void GCTAObservation::hi_user_thres(const double& hi_user_thres) +{ + m_hi_user_thres = hi_user_thres; + return; +} + + /***********************************************************************//** * @brief Return user high energy threshold * diff --git a/inst/cta/include/GCTAOnOffObservation.hpp b/inst/cta/include/GCTAOnOffObservation.hpp index bd8a006..76ca453 100644 --- a/inst/cta/include/GCTAOnOffObservation.hpp +++ b/inst/cta/include/GCTAOnOffObservation.hpp @@ -109,6 +109,7 @@ public: // Other methods void instrument(const std::string& instrument); + bool has_response(void) const; const GPha& on_spec(void) const; const GPha& off_spec(void) const; const GArf& arf(void) const; @@ -243,6 +244,18 @@ double GCTAOnOffObservation::deadc(const GTime& time) const /***********************************************************************//** + * @brief Signal if observation contains response information + * + * @return True if observation contains response information. + ***************************************************************************/ +inline +bool GCTAOnOffObservation::has_response(void) const +{ + return (m_response != NULL); +} + + +/***********************************************************************//** * @brief Set instrument * * @param[in] instrument Instrument. diff --git a/inst/cta/pyext/GCTAAeff2D.i b/inst/cta/pyext/GCTAAeff2D.i index 29e2a23..aea6232 100644 --- a/inst/cta/pyext/GCTAAeff2D.i +++ b/inst/cta/pyext/GCTAAeff2D.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAAeff2D.i - CTA 2D effective area class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2017 by Juergen Knoedlseder * + * copyright (C) 2012-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -80,4 +80,21 @@ public: GCTAAeff2D copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (self.filename(), hdu) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + if state[1].nrows() > 0: + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTABackground3D.i b/inst/cta/pyext/GCTABackground3D.i index e2c6d47..05a2c0a 100644 --- a/inst/cta/pyext/GCTABackground3D.i +++ b/inst/cta/pyext/GCTABackground3D.i @@ -80,4 +80,21 @@ public: GCTABackground3D copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (self.filename(), hdu) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + if state[1].nrows() > 0: + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTACubeBackground.i b/inst/cta/pyext/GCTACubeBackground.i index 9662b64..27d7412 100644 --- a/inst/cta/pyext/GCTACubeBackground.i +++ b/inst/cta/pyext/GCTACubeBackground.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTACubeBackground.i - CTA cube background class * * ----------------------------------------------------------------------- * - * copyright (C) 2015-2016 by Michael Mayer * + * copyright (C) 2015-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -81,4 +81,20 @@ public: GCTACubeBackground copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + fits = gammalib.GFits() + self.write(fits) + state = (self.filename(), fits) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTACubeEdisp.i b/inst/cta/pyext/GCTACubeEdisp.i index 1e65d78..e524b52 100644 --- a/inst/cta/pyext/GCTACubeEdisp.i +++ b/inst/cta/pyext/GCTACubeEdisp.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTACubeEdisp.i - CTA cube analysis energy dispersion class * * ----------------------------------------------------------------------- * - * copyright (C) 2016 by Michael Mayer * + * copyright (C) 2016-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -96,4 +96,20 @@ public: GCTACubeEdisp copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + fits = gammalib.GFits() + self.write(fits) + state = (self.filename(), fits) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTACubeExposure.i b/inst/cta/pyext/GCTACubeExposure.i index 1ea29e4..2936faa 100644 --- a/inst/cta/pyext/GCTACubeExposure.i +++ b/inst/cta/pyext/GCTACubeExposure.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTACubeExposure.i - CTA cube analysis exposure class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2016 by Chia-Chun Lu * + * copyright (C) 2014-2018 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -87,4 +87,20 @@ public: GCTACubeExposure copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + fits = gammalib.GFits() + self.write(fits) + state = (self.filename(), fits) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTACubePsf.i b/inst/cta/pyext/GCTACubePsf.i index 45c3fbf..38bc455 100644 --- a/inst/cta/pyext/GCTACubePsf.i +++ b/inst/cta/pyext/GCTACubePsf.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTACubePsf.i - CTA cube analysis point spread function class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2016 by Chia-Chun Lu * + * copyright (C) 2014-2018 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -95,4 +95,20 @@ public: GCTACubePsf copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + fits = gammalib.GFits() + self.write(fits) + state = (self.filename(), fits) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTAEdisp2D.i b/inst/cta/pyext/GCTAEdisp2D.i index bba069c..b882616 100644 --- a/inst/cta/pyext/GCTAEdisp2D.i +++ b/inst/cta/pyext/GCTAEdisp2D.i @@ -96,4 +96,21 @@ public: GCTAEdisp2D copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (self.filename(), hdu) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + if state[1].nrows() > 0: + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTAEventBin.i b/inst/cta/pyext/GCTAEventBin.i index 59e18b4..b577e19 100644 --- a/inst/cta/pyext/GCTAEventBin.i +++ b/inst/cta/pyext/GCTAEventBin.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAEventBin.i - CTA event bin class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -83,4 +83,22 @@ public: GCTAEventBin copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.ipix(), self.dir(), self.energy(), self.time(), + self.counts(), self.solidangle(), self.ewidth(), + self.ontime(), self.weight()) + return state + def __setstate__(self, state): + self.__init__() + if state[0] == -1: + self.dir(state[1]) + self.energy(state[2]) + self.time(state[3]) + self.counts(state[4]) + self.solidangle(state[5]) + self.ewidth(state[6]) + self.ontime(state[7]) + self.weight(state[8]) +} }; diff --git a/inst/cta/pyext/GCTAEventCube.i b/inst/cta/pyext/GCTAEventCube.i index 8d0a836..199925c 100644 --- a/inst/cta/pyext/GCTAEventCube.i +++ b/inst/cta/pyext/GCTAEventCube.i @@ -92,10 +92,13 @@ public: } %pythoncode { def __getstate__(self): - args = gammalib.GEventCube.__getstate__(self) - return args + fits = gammalib.GFits() + self.write(fits) + state = (fits,) + return state def __setstate__(self, state): self.__init__() - gammalib.GEventCube.__setstate__(self, state) + if state[0][0].has_card('NAXIS') and state[0][0].integer('NAXIS') >= 2: + self.read(state[0]) } }; diff --git a/inst/cta/pyext/GCTAEventList.i b/inst/cta/pyext/GCTAEventList.i index a555727..5c305e0 100644 --- a/inst/cta/pyext/GCTAEventList.i +++ b/inst/cta/pyext/GCTAEventList.i @@ -152,10 +152,12 @@ public: } %pythoncode { def __getstate__(self): - args = gammalib.GEventList.__getstate__(self) - return args + fits = gammalib.GFits() + self.write(fits) + state = (fits,) + return state def __setstate__(self, state): self.__init__() - gammalib.GEventList.__setstate__(self, state) + self.read(state[0]) } }; diff --git a/inst/cta/pyext/GCTAModelAeffBackground.i b/inst/cta/pyext/GCTAModelAeffBackground.i index 13b5fbe..bc0949f 100644 --- a/inst/cta/pyext/GCTAModelAeffBackground.i +++ b/inst/cta/pyext/GCTAModelAeffBackground.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelAeffBackground.i - CTA Aeff background model class * * ----------------------------------------------------------------------- * - * copyright (C) 2015-2016 by Michael Mayer * + * copyright (C) 2015-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -40,6 +40,8 @@ public: GCTAModelAeffBackground(void); explicit GCTAModelAeffBackground(const GXmlElement& xml); explicit GCTAModelAeffBackground(const GModelSpectral& spectral); + GCTAModelAeffBackground(const GModelSpectral& spectral, + const GModelTemporal& temporal); GCTAModelAeffBackground(const GCTAModelAeffBackground& bgd); virtual ~GCTAModelAeffBackground(void); @@ -71,4 +73,18 @@ public: GCTAModelAeffBackground copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.spectral(), self.temporal(), + gammalib.GModelData.__getstate__(self)) + return state + def __setstate__(self, state): + if state[0] == None and state[1] == None: + self.__init__() + elif state[1] == None: + self.__init__(state[0]) + else: + self.__init__(state[0], state[1]) + gammalib.GModelData.__setstate__(self, state[2]) +} }; diff --git a/inst/cta/pyext/GCTAModelCubeBackground.i b/inst/cta/pyext/GCTAModelCubeBackground.i index ce1cdf1..9d047ad 100644 --- a/inst/cta/pyext/GCTAModelCubeBackground.i +++ b/inst/cta/pyext/GCTAModelCubeBackground.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelCubeBackground.i - CTA cube background model class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2016 by Michael Mayer * + * copyright (C) 2013-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -41,6 +41,8 @@ public: GCTAModelCubeBackground(void); explicit GCTAModelCubeBackground(const GXmlElement& xml); explicit GCTAModelCubeBackground(const GModelSpectral& spectral); + GCTAModelCubeBackground(const GModelSpectral& spectral, + const GModelTemporal& temporal); GCTAModelCubeBackground(const GCTAModelCubeBackground& model); virtual ~GCTAModelCubeBackground(void); @@ -72,4 +74,18 @@ public: GCTAModelCubeBackground copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.spectral(), self.temporal(), + gammalib.GModelData.__getstate__(self)) + return state + def __setstate__(self, state): + if state[0] == None and state[1] == None: + self.__init__() + elif state[1] == None: + self.__init__(state[0]) + else: + self.__init__(state[0], state[1]) + gammalib.GModelData.__setstate__(self, state[2]) +} }; diff --git a/inst/cta/pyext/GCTAModelRadial.i b/inst/cta/pyext/GCTAModelRadial.i index ec8a7b7..e83b139 100644 --- a/inst/cta/pyext/GCTAModelRadial.i +++ b/inst/cta/pyext/GCTAModelRadial.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelRadial.i - Abstract radial model base class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -26,7 +26,6 @@ %{ /* Put headers and other declarations here that are needed for compilation */ #include "GCTAModelRadial.hpp" -#include "GTools.hpp" %} @@ -56,7 +55,7 @@ public: virtual void write(GXmlElement& xml) const = 0; // Methods - int size(void) const { return m_pars.size(); } + int size(void) const; }; diff --git a/inst/cta/pyext/GCTAModelRadialAcceptance.i b/inst/cta/pyext/GCTAModelRadialAcceptance.i index 38ffaf7..9041b30 100644 --- a/inst/cta/pyext/GCTAModelRadialAcceptance.i +++ b/inst/cta/pyext/GCTAModelRadialAcceptance.i @@ -26,7 +26,6 @@ %{ /* Put headers and other declarations here that are needed for compilation */ #include "GCTAModelRadialAcceptance.hpp" -#include "GTools.hpp" %} @@ -41,8 +40,11 @@ public: // Constructors and destructors GCTAModelRadialAcceptance(void); explicit GCTAModelRadialAcceptance(const GXmlElement& xml); - explicit GCTAModelRadialAcceptance(const GCTAModelRadial& radial, - const GModelSpectral& spectral); + GCTAModelRadialAcceptance(const GCTAModelRadial& radial, + const GModelSpectral& spectral); + GCTAModelRadialAcceptance(const GCTAModelRadial& radial, + const GModelSpectral& spectral, + const GModelTemporal& temporal); GCTAModelRadialAcceptance(const GCTAModelRadialAcceptance& model); virtual ~GCTAModelRadialAcceptance(void); @@ -72,7 +74,24 @@ public: /***********************************************************************//** - * @brief GCTAModelRadial class extension + * @brief GCTAModelRadialAcceptance class extension ***************************************************************************/ -%extend GCTAModelRadial { +%extend GCTAModelRadialAcceptance { + GCTAModelRadialAcceptance copy() { + return (*self); + } +%pythoncode { + def __getstate__(self): + state = (self.radial(), self.spectral(), self.temporal(), + gammalib.GModelData.__getstate__(self)) + return state + def __setstate__(self, state): + if state[0] != None and state[1] != None and state[2] != None: + self.__init__(state[0], state[1], state[2]) + elif state[0] != None and state[1] != None: + self.__init__(state[0], state[1]) + else: + self.__init__() + gammalib.GModelData.__setstate__(self, state[3]) +} }; diff --git a/inst/cta/pyext/GCTAModelRadialGauss.i b/inst/cta/pyext/GCTAModelRadialGauss.i index 8f195db..dde2174 100644 --- a/inst/cta/pyext/GCTAModelRadialGauss.i +++ b/inst/cta/pyext/GCTAModelRadialGauss.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelRadialGauss.i - Radial Gaussian model class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -26,7 +26,6 @@ %{ /* Put headers and other declarations here that are needed for compilation */ #include "GCTAModelRadialGauss.hpp" -#include "GTools.hpp" %} @@ -66,4 +65,15 @@ public: * @brief GCTAModelRadialGauss class extension ***************************************************************************/ %extend GCTAModelRadialGauss { + GCTAModelRadialGauss copy() { + return (*self); + } +%pythoncode { + def __getstate__(self): + state = (self[0],) + return state + def __setstate__(self, state): + self.__init__() + self[0] = state[0] +} }; diff --git a/inst/cta/pyext/GCTAModelRadialPolynom.i b/inst/cta/pyext/GCTAModelRadialPolynom.i index 90d89bd..fabbc67 100644 --- a/inst/cta/pyext/GCTAModelRadialPolynom.i +++ b/inst/cta/pyext/GCTAModelRadialPolynom.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelRadialPolynom.i - Radial Polynom model class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -26,7 +26,6 @@ %{ /* Put headers and other declarations here that are needed for compilation */ #include "GCTAModelRadialPolynom.hpp" -#include "GTools.hpp" %} @@ -57,7 +56,6 @@ public: virtual void write(GXmlElement& xml) const; // Other methods - int size(void) const { return m_coeffs.size(); } //double coeff(void) const; //void coeff(const double& value); }; @@ -67,4 +65,19 @@ public: * @brief GCTAModelRadialPolynom class extension ***************************************************************************/ %extend GCTAModelRadialPolynom { + GCTAModelRadialPolynom copy() { + return (*self); + } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + if state[0].elements('parameter') == 0: + self.__init__() + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTAModelRadialProfile.i b/inst/cta/pyext/GCTAModelRadialProfile.i index 44f9dba..1350e4a 100644 --- a/inst/cta/pyext/GCTAModelRadialProfile.i +++ b/inst/cta/pyext/GCTAModelRadialProfile.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelRadialProfile.i - Radial Profile model class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -71,4 +71,17 @@ public: * @brief GCTAModelRadialProfile class extension ***************************************************************************/ %extend GCTAModelRadialProfile { + GCTAModelRadialProfile copy() { + return (*self); + } +%pythoncode { + def __getstate__(self): + state = (self[0], self[1], self[2]) + return state + def __setstate__(self, state): + self.__init__() + self[0] = state[0] + self[1] = state[1] + self[2] = state[2] +} }; diff --git a/inst/cta/pyext/GCTAObservation.i b/inst/cta/pyext/GCTAObservation.i index 3f93114..2c8b2a1 100644 --- a/inst/cta/pyext/GCTAObservation.i +++ b/inst/cta/pyext/GCTAObservation.i @@ -65,6 +65,7 @@ public: virtual void write(GXmlElement& xml) const; // Other methods + void instrument(const std::string& instrument); bool has_response(void) const; bool has_events(void) const; void read(const GFits& fits); @@ -112,7 +113,9 @@ public: const GFilename& eventfile(void) const; std::string eventtype(void) const; void dispose_events(void); + void lo_user_thres(const double& lo_user_thres); const double& lo_user_thres(void) const; + void hi_user_thres(const double& hi_user_thres); const double& hi_user_thres(void) const; void n_tels(const int& tels); const int& n_tels(void) const; @@ -128,10 +131,32 @@ public: } %pythoncode { def __getstate__(self): - args = gammalib.GObservation.__getstate__(self) + () - return args + if self.has_response(): + response = self.response() + else: + response = None + state = (gammalib.GObservation.__getstate__(self), + self.instrument(), self.eventfile(), response, + self.pointing(), self.off_regions(), self.ontime(), + self.livetime(), self.deadc(), self.ra_obj(), self.dec_obj(), + self.lo_user_thres(), self.hi_user_thres(), self.n_tels()) + return state def __setstate__(self, state): self.__init__() - gammalib.GObservation.__setstate__(self, state) + gammalib.GObservation.__setstate__(self, state[0]) + self.instrument(state[1]) + self.eventfile(state[2]) + if state[3] != None: + self.response(state[3]) + self.pointing(state[4]) + self.off_regions(state[5]) + self.ontime(state[6]) + self.livetime(state[7]) + self.deadc(state[8]) + self.ra_obj(state[9]) + self.dec_obj(state[10]) + self.lo_user_thres(state[11]) + self.hi_user_thres(state[12]) + self.n_tels(state[13]) } }; diff --git a/inst/cta/pyext/GCTAOnOffObservation.i b/inst/cta/pyext/GCTAOnOffObservation.i index 086fabd..05d27fb 100644 --- a/inst/cta/pyext/GCTAOnOffObservation.i +++ b/inst/cta/pyext/GCTAOnOffObservation.i @@ -112,6 +112,7 @@ public: // Other methods void instrument(const std::string& instrument); + bool has_response(void) const; const GPha& on_spec(void) const; const GPha& off_spec(void) const; const GArf& arf(void) const; @@ -128,4 +129,21 @@ public: GCTAOnOffObservation copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.has_response(): + response = self.response() + else: + response = None + state = (gammalib.GObservation.__getstate__(self), + self.instrument(), response, self.on_spec(), self.off_spec(), + self.arf(), self.rmf()) + return state + def __setstate__(self, state): + self.__init__(state[3], state[4], state[5], state[6]) + gammalib.GObservation.__setstate__(self, state[0]) + self.instrument(state[1]) + if state[2] != None: + self.response(state[2]) +} } diff --git a/inst/cta/pyext/GCTAPointing.i b/inst/cta/pyext/GCTAPointing.i index f8ad35f..7e5ebf8 100644 --- a/inst/cta/pyext/GCTAPointing.i +++ b/inst/cta/pyext/GCTAPointing.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAPointing.i - CTA pointing class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Jurgen Knodlseder * + * copyright (C) 2010-2018 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -73,4 +73,13 @@ public: GCTAPointing copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.dir(), self.zenith(), self.azimuth()) + return state + def __setstate__(self, state): + self.__init__(state[0]) + self.zenith(state[1]) + self.azimuth(state[2]) +} }; diff --git a/inst/cta/pyext/GCTAPsf2D.i b/inst/cta/pyext/GCTAPsf2D.i index fb2372c..302045e 100644 --- a/inst/cta/pyext/GCTAPsf2D.i +++ b/inst/cta/pyext/GCTAPsf2D.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAPsf2D.i - CTA 2D point spread function class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2016 by Juergen Knoedlseder * + * copyright (C) 2012-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -96,4 +96,21 @@ public: GCTAPsf2D copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (self.filename(), hdu) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + if state[1].nrows() > 0: + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTAPsfKing.i b/inst/cta/pyext/GCTAPsfKing.i index 6eeaa70..bef27a1 100644 --- a/inst/cta/pyext/GCTAPsfKing.i +++ b/inst/cta/pyext/GCTAPsfKing.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAPsfKing.i - King profile CTA point spread function class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2016 by Michael Mayer * + * copyright (C) 2013-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -98,4 +98,21 @@ public: GCTAPsfKing copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (self.filename(), hdu) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + if state[1].nrows() > 0: + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTAPsfTable.i b/inst/cta/pyext/GCTAPsfTable.i index 99731dd..75b78e9 100644 --- a/inst/cta/pyext/GCTAPsfTable.i +++ b/inst/cta/pyext/GCTAPsfTable.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAPsfTable.i - CTA point spread function table class * * ----------------------------------------------------------------------- * - * copyright (C) 2016 by Juergen Knoedlseder * + * copyright (C) 2016-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -95,4 +95,21 @@ public: GCTAPsfTable copy() { return (*self); } +%pythoncode { + def __getstate__(self): + if self.filename().is_empty(): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (self.filename(), hdu) + else: + state = (self.filename(),) + return state + def __setstate__(self, state): + if state[0].is_empty(): + self.__init__() + if state[1].nrows() > 0: + self.read(state[1]) + else: + self.__init__(state[0]) +} }; diff --git a/inst/cta/pyext/GCTAResponseCube.i b/inst/cta/pyext/GCTAResponseCube.i index 5a7743b..6b99e33 100644 --- a/inst/cta/pyext/GCTAResponseCube.i +++ b/inst/cta/pyext/GCTAResponseCube.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAResponseCube.i - CTA cube analysis response function class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2016 by Juergen Knoedlseder * + * copyright (C) 2014-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -90,4 +90,16 @@ public: GCTAResponseCube copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.exposure(), self.psf(), self.edisp(), self.background(), + self.apply_edisp()) + return state + def __setstate__(self, state): + if state[2].energies().is_empty(): + self.__init__(state[0], state[1], state[3]) + else: + self.__init__(state[0], state[1], state[2], state[3]) + self.apply_edisp(state[4]) +} }; diff --git a/inst/cta/pyext/GCTAResponseIrf.i b/inst/cta/pyext/GCTAResponseIrf.i index 3c41a11..8e0bf3a 100644 --- a/inst/cta/pyext/GCTAResponseIrf.i +++ b/inst/cta/pyext/GCTAResponseIrf.i @@ -129,4 +129,14 @@ public: GCTAResponseIrf copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.rspname(), self.caldb()) + return state + def __setstate__(self, state): + if state[0]: + self.__init__(state[0], state[1]) + else: + self.__init__() +} }; diff --git a/inst/cta/pyext/GCTAResponseTable.i b/inst/cta/pyext/GCTAResponseTable.i index 536a3ca..379edb3 100644 --- a/inst/cta/pyext/GCTAResponseTable.i +++ b/inst/cta/pyext/GCTAResponseTable.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAResponseTable.i - CTA response table class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2016 by Juergen Knoedlseder * + * copyright (C) 2012-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -169,9 +169,6 @@ public: * @brief GCTAResponse class extension ***************************************************************************/ %extend GCTAResponseTable { - GCTAResponseTable copy() { - return (*self); - } double __getitem__(int GCTAResponseTableInx[]) { if (GCTAResponseTableInx[0] == 1) { return (*self)(GCTAResponseTableInx[1]); @@ -188,4 +185,17 @@ public: (*self)(GCTAResponseTableInx[1], GCTAResponseTableInx[2]) = value; } } + GCTAResponseTable copy() { + return (*self); + } +%pythoncode { + def __getstate__(self): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (hdu,) + return state + def __setstate__(self, state): + self.__init__() + self.read(state[0]) +} }; diff --git a/inst/cta/pyext/GCTARoi.i b/inst/cta/pyext/GCTARoi.i index 61848be..f641986 100644 --- a/inst/cta/pyext/GCTARoi.i +++ b/inst/cta/pyext/GCTARoi.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTARoi.i - CTA region of interest class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Jurgen Knodlseder * + * copyright (C) 2010-2018 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -69,4 +69,14 @@ public: GCTARoi copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.centre(), self.radius()) + return state + def __setstate__(self, state): + if state[1] > 0.0: + self.__init__(state[0], state[1]) + else: + self.__init__() +} }; diff --git a/inst/cta/pyext/cta.i b/inst/cta/pyext/cta.i index 70e2a46..9e56ebf 100644 --- a/inst/cta/pyext/cta.i +++ b/inst/cta/pyext/cta.i @@ -1,7 +1,7 @@ /*************************************************************************** * cta.i - Cherenkov Telescope Array module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -178,6 +178,28 @@ } $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); } +%typemap(out) GCTAModelRadial* { + if ($1 == NULL) { + $result = Py_None; + Py_INCREF(Py_None); // Py_None is a singleton so increment its reference + } + else { + char classname[80]; + strcpy(classname, "_p_"); + strcat(classname, result->classname().c_str()); + swig_type_info *myinfo = SWIGTYPE_p_GCTAModelRadial; + swig_cast_info *mycast = 0; + mycast = myinfo->cast; + while (mycast != 0) { + if (strcmp(classname, mycast->type->name) == 0) { + myinfo = mycast->type; + break; + } + mycast = mycast->next; + } + $result = SWIG_NewPointerObj(SWIG_as_voidptr($1), myinfo, 0 | 0); + } +} %typemap(out) GModelSpectral* { if ($1 == NULL) { $result = Py_None; diff --git a/inst/cta/src/GCTAAeff2D.cpp b/inst/cta/src/GCTAAeff2D.cpp index 625cf33..c07b20f 100644 --- a/inst/cta/src/GCTAAeff2D.cpp +++ b/inst/cta/src/GCTAAeff2D.cpp @@ -548,25 +548,33 @@ std::string GCTAAeff2D::print(const GChatter& chatter) const // Continue only if chatter is not silent if (chatter != SILENT) { - // Compute energy boundaries in TeV - double emin = m_aeff.axis_lo(m_inx_energy,0); - double emax = m_aeff.axis_hi(m_inx_energy, - m_aeff.axis_bins(m_inx_energy)-1); - - // Compute offset angle boundaries in deg - double omin = m_aeff.axis_lo(m_inx_theta,0); - double omax = m_aeff.axis_hi(m_inx_theta, - m_aeff.axis_bins(m_inx_theta)-1); - // Append header result.append("=== GCTAAeff2D ==="); + result.append("\n"+gammalib::parformat("Filename")+m_filename); + + // Initialise information + int nebins = 0; + int nthetabins = 0; + double emin = 0.0; + double emax = 0.0; + double omin = 0.0; + double omax = 0.0; + + // Extract information if there are axes in the response table + if (m_aeff.axes() > 0) { + nebins = m_aeff.axis_bins(m_inx_energy); + nthetabins = m_aeff.axis_bins(m_inx_theta); + emin = m_aeff.axis_lo(m_inx_energy,0); + emax = m_aeff.axis_hi(m_inx_energy,nebins-1); + omin = m_aeff.axis_lo(m_inx_theta,0); + omax = m_aeff.axis_hi(m_inx_theta,nthetabins-1); + } // Append information - result.append("\n"+gammalib::parformat("Filename")+m_filename); result.append("\n"+gammalib::parformat("Number of energy bins") + - gammalib::str(m_aeff.axis_bins(m_inx_energy))); + gammalib::str(nebins)); result.append("\n"+gammalib::parformat("Number of offset bins") + - gammalib::str(m_aeff.axis_bins(m_inx_theta))); + gammalib::str(nthetabins)); result.append("\n"+gammalib::parformat("Log10(Energy) range")); result.append(gammalib::str(emin)+" - "+gammalib::str(emax)+" TeV"); result.append("\n"+gammalib::parformat("Offset angle range")); diff --git a/inst/cta/src/GCTACubeExposure.cpp b/inst/cta/src/GCTACubeExposure.cpp index 38e1de2..73198f4 100644 --- a/inst/cta/src/GCTACubeExposure.cpp +++ b/inst/cta/src/GCTACubeExposure.cpp @@ -420,8 +420,10 @@ void GCTACubeExposure::write(GFits& fits) const m_cube.write(fits); // Get last HDU and write attributes - GFitsHDU& hdu = *fits[fits.size()-1]; - write_attributes(hdu); + if (fits.size() > 0) { + GFitsHDU& hdu = *fits[fits.size()-1]; + write_attributes(hdu); + } // Write energies m_energies.write(fits); diff --git a/inst/cta/src/GCTAEdisp2D.cpp b/inst/cta/src/GCTAEdisp2D.cpp index d280d01..f01f4e9 100644 --- a/inst/cta/src/GCTAEdisp2D.cpp +++ b/inst/cta/src/GCTAEdisp2D.cpp @@ -691,8 +691,6 @@ GEbounds GCTAEdisp2D::ebounds_src(const double& logEobs, * @exception GException::file_error * File not found. * Unable to load energy dispersion. - * @exception GException::invalid_value - * No file name has been specified. * * Fetches the energy dispersion by reading it from a FITS file. This method * does nothing if the energy dispersion is already loaded, if there is @@ -763,13 +761,6 @@ void GCTAEdisp2D::fetch(void) const } } // endif: filename was not empty - - // Throw an exception if the FITS file name is not known - else { - std::string msg = "Unable to fetch energy dispersion since no " - "filename is specified."; - throw GException::invalid_value(G_FETCH, msg); - } } // endif: energy dispersion had not yet been fetched @@ -932,35 +923,44 @@ std::string GCTAEdisp2D::print(const GChatter& chatter) const // Continue only if chatter is not silent if (chatter != SILENT) { + // Append header + result.append("=== GCTAEdisp2D ==="); + result.append("\n"+gammalib::parformat("Filename")+m_filename); + // Make sure that energy dispersion is online fetch(); - // Compute energy boundaries in TeV - double emin = m_edisp.axis_lo(m_inx_etrue,0); - double emax = m_edisp.axis_hi(m_inx_etrue, - m_edisp.axis_bins(m_inx_etrue)-1); - - // Compute mingration - double mmin = m_edisp.axis_lo(m_inx_migra,0); - double mmax = m_edisp.axis_hi(m_inx_migra, - m_edisp.axis_bins(m_inx_migra)-1); - - // Compute offset angle boundaries in deg - double omin = m_edisp.axis_lo(m_inx_theta,0); - double omax = m_edisp.axis_hi(m_inx_theta, - m_edisp.axis_bins(m_inx_theta)-1); - - // Append header - result.append("=== GCTAEdisp2D ==="); + // Initialise information + int nebins = 0; + int nmigrabins = 0; + int nthetabins = 0; + double emin = 0.0; + double emax = 0.0; + double mmin = 0.0; + double mmax = 0.0; + double omin = 0.0; + double omax = 0.0; + + // Extract information if there are axes in the response table + if (m_edisp.axes() > 0) { + nebins = m_edisp.axis_bins(m_inx_etrue); + nmigrabins = m_edisp.axis_bins(m_inx_migra); + nthetabins = m_edisp.axis_bins(m_inx_theta); + emin = m_edisp.axis_lo(m_inx_etrue,0); + emax = m_edisp.axis_hi(m_inx_etrue,nebins-1); + mmin = m_edisp.axis_lo(m_inx_migra,0); + mmax = m_edisp.axis_hi(m_inx_migra,nmigrabins-1); + omin = m_edisp.axis_lo(m_inx_theta,0); + omax = m_edisp.axis_hi(m_inx_theta,nthetabins-1); + } // Append information - result.append("\n"+gammalib::parformat("Filename")+m_filename); result.append("\n"+gammalib::parformat("Number of energy bins") + - gammalib::str(m_edisp.axis_bins(m_inx_etrue))); + gammalib::str(nebins)); result.append("\n"+gammalib::parformat("Number of migration bins") + - gammalib::str(m_edisp.axis_bins(m_inx_migra))); + gammalib::str(nmigrabins)); result.append("\n"+gammalib::parformat("Number of offset bins") + - gammalib::str(m_edisp.axis_bins(m_inx_theta))); + gammalib::str(nthetabins)); result.append("\n"+gammalib::parformat("Log10(Energy) range")); result.append(gammalib::str(emin)+" - "+gammalib::str(emax)+" TeV"); result.append("\n"+gammalib::parformat("Migration range")); diff --git a/inst/cta/src/GCTAEventList.cpp b/inst/cta/src/GCTAEventList.cpp index 6b232f6..2ad5be8 100644 --- a/inst/cta/src/GCTAEventList.cpp +++ b/inst/cta/src/GCTAEventList.cpp @@ -444,9 +444,10 @@ void GCTAEventList::read(const GFits& fits) // Read phase intervals from data sub-space keyword m_phases = gammalib::read_ds_phase(events); - // If the file name contains an expression then load the events now. - // We do this at the end to make sure that the GTI has been set before. - if (m_filename.has_expression()) { + // If the file name contains an expression or the filename is empty then + // load the events now. We do this at the end to make sure that the GTI + // has been set before. + if (m_filename.has_expression() || m_filename.is_empty()) { read_events(events); } diff --git a/inst/cta/src/GCTAModelAeffBackground.cpp b/inst/cta/src/GCTAModelAeffBackground.cpp index 0a01d7d..9581ab2 100644 --- a/inst/cta/src/GCTAModelAeffBackground.cpp +++ b/inst/cta/src/GCTAModelAeffBackground.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelAeffBackground.cpp - CTA Aeff background model class * * ----------------------------------------------------------------------- * - * copyright (C) 2015-2017 by Michael Mayer * + * copyright (C) 2015-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -85,7 +85,7 @@ GCTAModelAeffBackground::GCTAModelAeffBackground(void) : GModelData() /***********************************************************************//** - * @brief Constructor + * @brief XML constructor * * @param[in] xml XML element. * @@ -135,10 +135,8 @@ GCTAModelAeffBackground::GCTAModelAeffBackground(const GXmlElement& xml) : * * @param[in] spectral Spectral model component. * - * Constructs a CTA effective area background model from a spectral + * Constructs a CTA effective area background model from a @p spectral * model component. The temporal component is assumed to be constant. - * Please refer to the class GModelSpectral to learn more about the - * definition of the spectral components. ***************************************************************************/ GCTAModelAeffBackground::GCTAModelAeffBackground(const GModelSpectral& spectral) : GModelData() @@ -162,6 +160,34 @@ GCTAModelAeffBackground::GCTAModelAeffBackground(const GModelSpectral& spectral) /***********************************************************************//** + * @brief Construct from model components + * + * @param[in] spectral Spectral model component. + * @param[in] temporal Temporal model component. + * + * Constructs a CTA effective area background model from a @p spectral and a + * @p temporal component. + ***************************************************************************/ +GCTAModelAeffBackground::GCTAModelAeffBackground(const GModelSpectral& spectral, + const GModelTemporal& temporal) : + GModelData() +{ + // Initialise members + init_members(); + + // Clone model components + m_spectral = spectral.clone(); + m_temporal = temporal.clone(); + + // Set parameter pointers + set_pointers(); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] aeff CTA instrument background model. diff --git a/inst/cta/src/GCTAModelCubeBackground.cpp b/inst/cta/src/GCTAModelCubeBackground.cpp index 4051716..8c13d42 100644 --- a/inst/cta/src/GCTAModelCubeBackground.cpp +++ b/inst/cta/src/GCTAModelCubeBackground.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAModelCubeBackground.cpp - CTA cube background model class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2016 by Michael Mayer * + * copyright (C) 2013-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -112,10 +112,8 @@ GCTAModelCubeBackground::GCTAModelCubeBackground(const GXmlElement& xml) : * * @param[in] spectral Spectral model component. * - * Constructs a CTA cube background model from a spectral model component. - * The temporal component is assumed to be constant. Please refer to the - * class GModelSpectral to learn more about the definition of the spectral - * components. + * Constructs a CTA cube background model from a @p spectral model component. + * The temporal component is assumed to be constant. ***************************************************************************/ GCTAModelCubeBackground::GCTAModelCubeBackground(const GModelSpectral& spectral) : GModelData() @@ -139,6 +137,34 @@ GCTAModelCubeBackground::GCTAModelCubeBackground(const GModelSpectral& spectral) /***********************************************************************//** + * @brief Construct from model components + * + * @param[in] spectral Spectral model component. + * @param[in] temporal Temporal model component. + * + * Constructs a CTA cube background model from a @p spectral and a + * @p temporal component. + ***************************************************************************/ +GCTAModelCubeBackground::GCTAModelCubeBackground(const GModelSpectral& spectral, + const GModelTemporal& temporal) : + GModelData() +{ + // Initialise members + init_members(); + + // Clone model components + m_spectral = spectral.clone(); + m_temporal = temporal.clone(); + + // Set parameter pointers + set_pointers(); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] bgd CTA cube background model. diff --git a/inst/cta/src/GCTAModelRadialAcceptance.cpp b/inst/cta/src/GCTAModelRadialAcceptance.cpp index b26188a..a7106a8 100644 --- a/inst/cta/src/GCTAModelRadialAcceptance.cpp +++ b/inst/cta/src/GCTAModelRadialAcceptance.cpp @@ -92,14 +92,13 @@ GCTAModelRadialAcceptance::GCTAModelRadialAcceptance(void) : GModelData() /***********************************************************************//** - * @brief Constructor + * @brief XML constructor * * @param[in] xml XML element. * * Constructs a CTA radial acceptance model from the information that is - * found in a XML element. Please refer to the method - * GCTAModelRadialAcceptance::read - * to learn more about the information that is expected in the XML element. + * found in a XML element. Please refer to the read() method to learn about + * the expected structure of the XML element. ***************************************************************************/ GCTAModelRadialAcceptance::GCTAModelRadialAcceptance(const GXmlElement& xml) : GModelData(xml) @@ -124,10 +123,9 @@ GCTAModelRadialAcceptance::GCTAModelRadialAcceptance(const GXmlElement& xml) : * @param[in] radial Radial CTA model component. * @param[in] spectral Spectral model component. * - * Constructs a CTA radial acceptance model from a radial and a spectral - * model component. The temporal component is assumed to be constant. - * Please refer to the classes GCTAModelRadial and GModelSpectral to learn - * more about the definition of the radial and spectral components. + * Constructs a CTA radial acceptance model from a @p radial and a + * @p spectral model component. The temporal component is assumed to be + * constant. ***************************************************************************/ GCTAModelRadialAcceptance::GCTAModelRadialAcceptance(const GCTAModelRadial& radial, const GModelSpectral& spectral) : @@ -153,6 +151,37 @@ GCTAModelRadialAcceptance::GCTAModelRadialAcceptance(const GCTAModelRadial& radi /***********************************************************************//** + * @brief Construct from model components + * + * @param[in] radial Radial CTA model component. + * @param[in] spectral Spectral model component. + * @param[in] temporal Temporal model component. + * + * Constructs a CTA radial acceptance model from a @p radial, a @p spectral + * and a @p temporal model component. + ***************************************************************************/ +GCTAModelRadialAcceptance::GCTAModelRadialAcceptance(const GCTAModelRadial& radial, + const GModelSpectral& spectral, + const GModelTemporal& temporal) : + GModelData() +{ + // Initialise members + init_members(); + + // Clone model components + m_radial = radial.clone(); + m_spectral = spectral.clone(); + m_temporal = temporal.clone(); + + // Set parameter pointers + set_pointers(); + + // Return + return; +} + + +/***********************************************************************//** * @brief Copy constructor * * @param[in] model Radial acceptance model. diff --git a/inst/cta/src/GCTAModelRadialPolynom.cpp b/inst/cta/src/GCTAModelRadialPolynom.cpp index 8fabeec..f305647 100644 --- a/inst/cta/src/GCTAModelRadialPolynom.cpp +++ b/inst/cta/src/GCTAModelRadialPolynom.cpp @@ -79,8 +79,8 @@ GCTAModelRadialPolynom::GCTAModelRadialPolynom(void) : GCTAModelRadial() * * @param[in] coeffs Vector of polynomial coefficients. ***************************************************************************/ -GCTAModelRadialPolynom::GCTAModelRadialPolynom(const std::vector& coeffs) - : GCTAModelRadial() +GCTAModelRadialPolynom::GCTAModelRadialPolynom(const std::vector& coeffs) : + GCTAModelRadial() { // Initialise members init_members(); @@ -95,7 +95,7 @@ GCTAModelRadialPolynom::GCTAModelRadialPolynom(const std::vector& coeffs par.value(coeffs[i]); // Set other attributes - std::string name = "coeff" + gammalib::str(i); + std::string name = "Coeff" + gammalib::str(i); par.name(name); par.unit(""); par.free(); diff --git a/inst/cta/src/GCTAPsf2D.cpp b/inst/cta/src/GCTAPsf2D.cpp index 7ee02a0..5ced293 100644 --- a/inst/cta/src/GCTAPsf2D.cpp +++ b/inst/cta/src/GCTAPsf2D.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAPsf2D.cpp - CTA 2D point spread function class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2016 by Juergen Knoedlseder * + * copyright (C) 2012-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -364,10 +364,12 @@ void GCTAPsf2D::write(GFitsBinTable& table) const // Create a copy of the response table GCTAResponseTable psf(m_psf); - // Convert sigma parameters back to degrees - psf.scale(m_inx_sigma1, gammalib::rad2deg); - psf.scale(m_inx_sigma2, gammalib::rad2deg); - psf.scale(m_inx_sigma3, gammalib::rad2deg); + // Convert sigma parameters back to degrees (only if there are tables) + if (psf.tables() > 0) { + psf.scale(m_inx_sigma1, gammalib::rad2deg); + psf.scale(m_inx_sigma2, gammalib::rad2deg); + psf.scale(m_inx_sigma3, gammalib::rad2deg); + } // Write response table psf.write(table); @@ -670,7 +672,7 @@ double GCTAPsf2D::containment_radius(const double& fraction, /***********************************************************************//** * @brief Print point spread function information * - * @param[in] chatter Chattiness (defaults to NORMAL). + * @param[in] chatter Chattiness. * @return String containing point spread function information. ***************************************************************************/ std::string GCTAPsf2D::print(const GChatter& chatter) const @@ -681,25 +683,33 @@ std::string GCTAPsf2D::print(const GChatter& chatter) const // Continue only if chatter is not silent if (chatter != SILENT) { - // Compute energy boundaries in TeV - double emin = m_psf.axis_lo(m_inx_energy,0); - double emax = m_psf.axis_hi(m_inx_energy, - m_psf.axis_bins(m_inx_energy)-1); - - // Compute offset angle boundaries in deg - double omin = m_psf.axis_lo(m_inx_theta,0); - double omax = m_psf.axis_hi(m_inx_theta, - m_psf.axis_bins(m_inx_theta)-1); - // Append header result.append("=== GCTAPsf2D ==="); + result.append("\n"+gammalib::parformat("Filename")+m_filename); + + // Initialise information + int nebins = 0; + int nthetabins = 0; + double emin = 0.0; + double emax = 0.0; + double omin = 0.0; + double omax = 0.0; + + // Extract information if there are axes in the response table + if (m_psf.axes() > 0) { + nebins = m_psf.axis_bins(m_inx_energy); + nthetabins = m_psf.axis_bins(m_inx_theta); + emin = m_psf.axis_lo(m_inx_energy,0); + emax = m_psf.axis_hi(m_inx_energy,nebins-1); + omin = m_psf.axis_lo(m_inx_theta,0); + omax = m_psf.axis_hi(m_inx_theta,nthetabins-1); + } // Append information - result.append("\n"+gammalib::parformat("Filename")+m_filename); result.append("\n"+gammalib::parformat("Number of energy bins") + - gammalib::str(m_psf.axis_bins(m_inx_energy))); + gammalib::str(nebins)); result.append("\n"+gammalib::parformat("Number of offset bins") + - gammalib::str(m_psf.axis_bins(m_inx_theta))); + gammalib::str(nthetabins)); result.append("\n"+gammalib::parformat("Log10(Energy) range")); result.append(gammalib::str(emin)+" - "+gammalib::str(emax)+" TeV"); result.append("\n"+gammalib::parformat("Offset angle range")); diff --git a/inst/cta/src/GCTAPsfKing.cpp b/inst/cta/src/GCTAPsfKing.cpp index b2990ae..090f5ac 100644 --- a/inst/cta/src/GCTAPsfKing.cpp +++ b/inst/cta/src/GCTAPsfKing.cpp @@ -341,8 +341,10 @@ void GCTAPsfKing::write(GFitsBinTable& table) const // Create a copy of the response table GCTAResponseTable psf(m_psf); - // Convert sigma parameters back to degrees - psf.scale(m_inx_sigma, gammalib::rad2deg); + // Convert sigma parameters back to degrees (only if there are tables) + if (psf.tables() > 0) { + psf.scale(m_inx_sigma, gammalib::rad2deg); + } // Write response table psf.write(table); @@ -583,7 +585,7 @@ double GCTAPsfKing::containment_radius(const double& fraction, /***********************************************************************//** * @brief Print point spread function information * - * @return Content of point spread function instance. + * @param[in] chatter Chattiness. * @return String containing point spread function information. ***************************************************************************/ std::string GCTAPsfKing::print(const GChatter& chatter) const @@ -594,25 +596,33 @@ std::string GCTAPsfKing::print(const GChatter& chatter) const // Continue only if chatter is not silent if (chatter != SILENT) { - // Compute energy boundaries in TeV - double emin = m_psf.axis_lo(m_inx_energy,0); - double emax = m_psf.axis_hi(m_inx_energy, - m_psf.axis_bins(m_inx_energy)-1); - - // Compute offset angle boundaries in deg - double omin = m_psf.axis_lo(m_inx_theta,0); - double omax = m_psf.axis_hi(m_inx_theta, - m_psf.axis_bins(m_inx_theta)-1); - // Append header result.append("=== GCTAPsfKing ==="); + result.append("\n"+gammalib::parformat("Filename")+m_filename); + + // Initialise information + int nebins = 0; + int nthetabins = 0; + double emin = 0.0; + double emax = 0.0; + double omin = 0.0; + double omax = 0.0; + + // Extract information if there are axes in the response table + if (m_psf.axes() > 0) { + nebins = m_psf.axis_bins(m_inx_energy); + nthetabins = m_psf.axis_bins(m_inx_theta); + emin = m_psf.axis_lo(m_inx_energy,0); + emax = m_psf.axis_hi(m_inx_energy,nebins-1); + omin = m_psf.axis_lo(m_inx_theta,0); + omax = m_psf.axis_hi(m_inx_theta,nthetabins-1); + } // Append information - result.append("\n"+gammalib::parformat("Filename")+m_filename); result.append("\n"+gammalib::parformat("Number of energy bins") + - gammalib::str(m_psf.axis_bins(m_inx_energy))); + gammalib::str(nebins)); result.append("\n"+gammalib::parformat("Number of offset bins") + - gammalib::str(m_psf.axis_bins(m_inx_theta))); + gammalib::str(nthetabins)); result.append("\n"+gammalib::parformat("Log10(Energy) range")); result.append(gammalib::str(emin)+" - "+gammalib::str(emax)+" TeV"); result.append("\n"+gammalib::parformat("Offset angle range")); diff --git a/inst/cta/src/GCTAPsfTable.cpp b/inst/cta/src/GCTAPsfTable.cpp index cf5cd23..a182da9 100644 --- a/inst/cta/src/GCTAPsfTable.cpp +++ b/inst/cta/src/GCTAPsfTable.cpp @@ -583,7 +583,7 @@ double GCTAPsfTable::containment_radius(const double& fraction, /***********************************************************************//** * @brief Print point spread function information * - * @return Content of point spread function instance. + * @param[in] chatter Chattiness. * @return String containing point spread function information. ***************************************************************************/ std::string GCTAPsfTable::print(const GChatter& chatter) const @@ -594,32 +594,42 @@ std::string GCTAPsfTable::print(const GChatter& chatter) const // Continue only if chatter is not silent if (chatter != SILENT) { - // Compute energy boundaries in TeV - double emin = m_psf.axis_lo(m_inx_energy,0); - double emax = m_psf.axis_hi(m_inx_energy, - m_psf.axis_bins(m_inx_energy)-1); - - // Compute offset angle boundaries in deg - double omin = m_psf.axis_lo(m_inx_theta,0); - double omax = m_psf.axis_hi(m_inx_theta, - m_psf.axis_bins(m_inx_theta)-1); - - // Compute delta angle boundaries in deg - double dmin = m_psf.axis_lo(m_inx_delta,0); - double dmax = m_psf.axis_hi(m_inx_delta, - m_psf.axis_bins(m_inx_delta)-1); - // Append header result.append("=== GCTAPsfTable ==="); + result.append("\n"+gammalib::parformat("Filename")+m_filename); + + // Initialise information + int nebins = 0; + int nthetabins = 0; + int ndeltabins = 0; + double emin = 0.0; + double emax = 0.0; + double omin = 0.0; + double omax = 0.0; + double dmin = 0.0; + double dmax = 0.0; + + // Extract information if there are axes in the response table + if (m_psf.axes() > 0) { + nebins = m_psf.axis_bins(m_inx_energy); + nthetabins = m_psf.axis_bins(m_inx_theta); + ndeltabins = m_psf.axis_bins(m_inx_delta); + emin = m_psf.axis_lo(m_inx_energy,0); + emax = m_psf.axis_hi(m_inx_energy,nebins-1); + omin = m_psf.axis_lo(m_inx_theta,0); + omax = m_psf.axis_hi(m_inx_theta,nthetabins-1); + dmin = m_psf.axis_lo(m_inx_delta,0); + dmax = m_psf.axis_hi(m_inx_delta,ndeltabins-1); + } + // Append information - result.append("\n"+gammalib::parformat("Filename")+m_filename); result.append("\n"+gammalib::parformat("Number of energy bins") + - gammalib::str(m_psf.axis_bins(m_inx_energy))); + gammalib::str(nebins)); result.append("\n"+gammalib::parformat("Number of offset bins") + - gammalib::str(m_psf.axis_bins(m_inx_theta))); + gammalib::str(nthetabins)); result.append("\n"+gammalib::parformat("Number of delta bins") + - gammalib::str(m_psf.axis_bins(m_inx_delta))); + gammalib::str(ndeltabins)); result.append("\n"+gammalib::parformat("Log10(Energy) range")); result.append(gammalib::str(emin)+" - "+gammalib::str(emax)+" TeV"); result.append("\n"+gammalib::parformat("Offset angle range")); diff --git a/inst/cta/src/GCTAResponseTable.cpp b/inst/cta/src/GCTAResponseTable.cpp index a1da7fb..204b451 100644 --- a/inst/cta/src/GCTAResponseTable.cpp +++ b/inst/cta/src/GCTAResponseTable.cpp @@ -1836,7 +1836,7 @@ void GCTAResponseTable::read_tables(const GFitsTable& hdu) m_tables.clear(); // Compute expected cube size - m_nelements = axis_bins(0); + m_nelements = (axes() > 0) ? axis_bins(0) : 0; for (int i = 1; i < axes(); ++i) { m_nelements *= axis_bins(i); } diff --git a/inst/cta/test/test_CTA.py b/inst/cta/test/test_CTA.py index 0b90ed4..0a2bd3b 100755 --- a/inst/cta/test/test_CTA.py +++ b/inst/cta/test/test_CTA.py @@ -65,6 +65,31 @@ class Test(gammalib.GPythonTestSuite): # Return event list container return list + # Setup GCTAEventCube + def _setup_eventcube(self): + """ + Setup GCTAEventCube + + Returns + ------- + cube : `~gammalib.GCTAEventCube` + GCTAEventCube + """ + # Setup event cube + map = gammalib.GSkyMap('CAR','CEL',0.0,0.0,1.0,1.0,5,5,2) + ebds = gammalib.GEbounds(2, gammalib.GEnergy(1.0, 'TeV'), + gammalib.GEnergy(10.0, 'TeV')) + gti = gammalib.GGti(gammalib.GTime(0.0,'sec'), + gammalib.GTime(1.0,'sec')) + cube = gammalib.GCTAEventCube(map, ebds, gti) + counts = 0.0 + for bin in cube: + counts += 1.0 + bin.counts(1.0) + + # Return event cube + return cube + # Test GCTAEventList class access operators def _test_eventlist_access(self): """ @@ -347,48 +372,52 @@ class Test(gammalib.GPythonTestSuite): """ Test class pickeling """ + # Set CALDB + os.environ['CALDB'] = os.environ['TEST_DATA']+'/caldb' + # Perform pickeling tests of empty classes - #test_support._pickeling(self, gammalib.GCTAAeff2D()) + test_support._pickeling(self, gammalib.GCTAAeff2D()) #test_support._pickeling(self, gammalib.GCTAAeffArf()) #test_support._pickeling(self, gammalib.GCTAAeffPerfTable()) - #test_support._pickeling(self, gammalib.GCTABackground3D()) + test_support._pickeling(self, gammalib.GCTABackground3D()) #test_support._pickeling(self, gammalib.GCTABackgroundPerfTable()) - #test_support._pickeling(self, gammalib.GCTACubeBackground()) - #test_support._pickeling(self, gammalib.GCTACubeEdisp()) - #test_support._pickeling(self, gammalib.GCTACubeExposure()) - #test_support._pickeling(self, gammalib.GCTACubePsf()) + test_support._pickeling(self, gammalib.GCTACubeBackground()) + test_support._pickeling(self, gammalib.GCTACubeEdisp()) + test_support._pickeling(self, gammalib.GCTACubeExposure()) + test_support._pickeling(self, gammalib.GCTACubePsf()) #test_support._pickeling(self, gammalib.GCTACubeSourceDiffuse()) #test_support._pickeling(self, gammalib.GCTACubeSourcePoint()) - #test_support._pickeling(self, gammalib.GCTAEdisp2D()) + test_support._pickeling(self, gammalib.GCTAEdisp2D()) #test_support._pickeling(self, gammalib.GCTAEdispPerfTable()) #test_support._pickeling(self, gammalib.GCTAEdispRmf()) test_support._pickeling(self, gammalib.GCTAEventAtom()) - #test_support._pickeling(self, gammalib.GCTAEventBin()) - #test_support._pickeling(self, gammalib.GCTAEventCube()) - #test_support._pickeling(self, gammalib.GCTAEventList()) + test_support._pickeling(self, gammalib.GCTAEventBin()) + test_support._pickeling(self, gammalib.GCTAEventCube()) + test_support._pickeling(self, gammalib.GCTAEventList()) test_support._pickeling(self, gammalib.GCTAInstDir()) - #test_support._pickeling(self, gammalib.GCTAModelAeffBackground()) - #test_support._pickeling(self, gammalib.GCTAModelCubeBackground()) + test_support._pickeling(self, gammalib.GCTAModelAeffBackground()) + test_support._pickeling(self, gammalib.GCTAModelCubeBackground()) test_support._pickeling(self, gammalib.GCTAModelIrfBackground()) - #test_support._pickeling(self, gammalib.GCTAModelRadialAcceptance()) - #test_support._pickeling(self, gammalib.GCTAModelRadialGauss()) - #test_support._pickeling(self, gammalib.GCTAModelRadialPolynom()) - #test_support._pickeling(self, gammalib.GCTAModelRadialProfile()) - #test_support._pickeling(self, gammalib.GCTAObservation()) - #test_support._pickeling(self, gammalib.GCTAOnOffObservation()) - #test_support._pickeling(self, gammalib.GCTAPointing()) - #test_support._pickeling(self, gammalib.GCTAPsf2D()) - #test_support._pickeling(self, gammalib.GCTAPsfKing()) + test_support._pickeling(self, gammalib.GCTAModelRadialAcceptance()) + test_support._pickeling(self, gammalib.GCTAModelRadialGauss()) + test_support._pickeling(self, gammalib.GCTAModelRadialPolynom()) + test_support._pickeling(self, gammalib.GCTAModelRadialProfile()) + test_support._pickeling(self, gammalib.GCTAObservation()) + test_support._pickeling(self, gammalib.GCTAOnOffObservation()) + test_support._pickeling(self, gammalib.GCTAPointing()) + test_support._pickeling(self, gammalib.GCTAPsf2D()) + test_support._pickeling(self, gammalib.GCTAPsfKing()) #test_support._pickeling(self, gammalib.GCTAPsfPerfTable()) - #test_support._pickeling(self, gammalib.GCTAPsfTable()) + test_support._pickeling(self, gammalib.GCTAPsfTable()) #test_support._pickeling(self, gammalib.GCTAPsfVector()) - #test_support._pickeling(self, gammalib.GCTAResponseCube()) - #test_support._pickeling(self, gammalib.GCTAResponseIrf()) - #test_support._pickeling(self, gammalib.GCTAResponseTable()) - #test_support._pickeling(self, gammalib.GCTARoi()) + test_support._pickeling(self, gammalib.GCTAResponseCube()) + test_support._pickeling(self, gammalib.GCTAResponseIrf()) + test_support._pickeling(self, gammalib.GCTAResponseTable()) + test_support._pickeling(self, gammalib.GCTARoi()) # Setup test list = self._setup_eventlist() + cube = self._setup_eventcube() atom = list[0] dir = gammalib.GSkyDir() instdir = gammalib.GCTAInstDir(dir) @@ -396,46 +425,92 @@ class Test(gammalib.GPythonTestSuite): plaw = gammalib.GModelSpectralPlaw(1.0,-2.0,pivot) instdir.detx(2.0) instdir.dety(-3.0) + irfname = os.environ['TEST_DATA']+'/caldb/data/cta/prod2/bcf/North_0.5h/irf_file.fits.gz' + bin = gammalib.GCTAEventBin() + bin.dir(instdir) + bin.energy(pivot) + bin.time(gammalib.GTime(1.0,'sec')) + bin.counts(1.0) + bin.solidangle(0.1) + bin.ewidth(pivot) + bin.ontime(100.0) + bin.weight(1.0) + emin = gammalib.GEnergy(1.0,'TeV') + emax = gammalib.GEnergy(10.0,'TeV') + engs = gammalib.GEnergies(10,emin,emax) + ebds = gammalib.GEbounds(2,emin,emax) + region = gammalib.GSkyRegionCircle(dir, 0.2) + regs = gammalib.GSkyRegions() + regs.append(region) + ptsrc = gammalib.GModelSpatialPointSource() + expcube = gammalib.GCTACubeExposure('CAR','CEL',0.,0.,0.1,0.1,10,10,engs) + psfcube = gammalib.GCTACubePsf('CAR','CEL',0.,0.,0.1,0.1,10,10,engs,1.0,10) + bgdcube = gammalib.GCTACubeBackground('CAR','CEL',0.,0.,0.1,0.1,10,10,engs) + edispcube = gammalib.GCTACubeEdisp('CAR','CEL',0.,0.,0.1,0.1,10,10,engs,1.0,10) + caldb = gammalib.GCaldb('cta','prod2') + rspirf = gammalib.GCTAResponseIrf('North_0.5h', caldb) + rspcube1 = gammalib.GCTAResponseCube(expcube, psfcube, bgdcube) + rspcube2 = gammalib.GCTAResponseCube(expcube, psfcube, edispcube, bgdcube) + obs1 = gammalib.GCTAObservation() + obs1.events(list) + obs1.response(rspirf) + obs2 = gammalib.GCTAObservation() + obs2.events(cube) + obs2.response(rspirf) + obs3 = gammalib.GCTAObservation() + obs3.events(cube) + obs3.response(rspcube1) + obs4 = gammalib.GCTAObservation() + obs4.events(cube) + obs4.response(rspcube2) + obs5 = gammalib.GCTAOnOffObservation(obs1, ptsrc, ebds, ebds, regs, regs) + radgauss = gammalib.GCTAModelRadialGauss(1.0) + radacc = gammalib.GCTAModelRadialAcceptance(radgauss, plaw) + kingname = self._caldb + '/prod1_king.fits' # Perform pickeling tests of filled classes - #test_support._pickeling(self, gammalib.GCTAAeff2D()) + test_support._pickeling(self, gammalib.GCTAAeff2D(irfname)) #test_support._pickeling(self, gammalib.GCTAAeffArf()) #test_support._pickeling(self, gammalib.GCTAAeffPerfTable()) - #test_support._pickeling(self, gammalib.GCTABackground3D()) + test_support._pickeling(self, gammalib.GCTABackground3D(irfname)) #test_support._pickeling(self, gammalib.GCTABackgroundPerfTable()) - #test_support._pickeling(self, gammalib.GCTACubeBackground()) - #test_support._pickeling(self, gammalib.GCTACubeEdisp()) - #test_support._pickeling(self, gammalib.GCTACubeExposure()) - #test_support._pickeling(self, gammalib.GCTACubePsf()) + test_support._pickeling(self, gammalib.GCTACubeBackground(bgdcube)) + test_support._pickeling(self, gammalib.GCTACubeEdisp(edispcube)) + test_support._pickeling(self, gammalib.GCTACubeExposure(expcube)) + test_support._pickeling(self, gammalib.GCTACubePsf(psfcube)) #test_support._pickeling(self, gammalib.GCTACubeSourceDiffuse()) #test_support._pickeling(self, gammalib.GCTACubeSourcePoint()) - #test_support._pickeling(self, gammalib.GCTAEdisp2D()) + test_support._pickeling(self, gammalib.GCTAEdisp2D(irfname)) #test_support._pickeling(self, gammalib.GCTAEdispPerfTable()) #test_support._pickeling(self, gammalib.GCTAEdispRmf()) test_support._pickeling(self, gammalib.GCTAEventAtom(atom)) - #test_support._pickeling(self, gammalib.GCTAEventBin()) - #test_support._pickeling(self, gammalib.GCTAEventCube()) - #test_support._pickeling(self, gammalib.GCTAEventList()) + test_support._pickeling(self, gammalib.GCTAEventBin(bin)) + test_support._pickeling(self, gammalib.GCTAEventCube(cube)) + test_support._pickeling(self, gammalib.GCTAEventList(list)) test_support._pickeling(self, gammalib.GCTAInstDir(instdir)) - #test_support._pickeling(self, gammalib.GCTAModelAeffBackground()) - #test_support._pickeling(self, gammalib.GCTAModelCubeBackground()) + test_support._pickeling(self, gammalib.GCTAModelAeffBackground(plaw)) + test_support._pickeling(self, gammalib.GCTAModelCubeBackground(plaw)) test_support._pickeling(self, gammalib.GCTAModelIrfBackground(plaw)) - #test_support._pickeling(self, gammalib.GCTAModelRadialAcceptance()) - #test_support._pickeling(self, gammalib.GCTAModelRadialGauss()) - #test_support._pickeling(self, gammalib.GCTAModelRadialPolynom()) - #test_support._pickeling(self, gammalib.GCTAModelRadialProfile()) - #test_support._pickeling(self, gammalib.GCTAObservation()) - #test_support._pickeling(self, gammalib.GCTAOnOffObservation()) - #test_support._pickeling(self, gammalib.GCTAPointing()) - #test_support._pickeling(self, gammalib.GCTAPsf2D()) - #test_support._pickeling(self, gammalib.GCTAPsfKing()) + test_support._pickeling(self, gammalib.GCTAModelRadialAcceptance(radacc)) + test_support._pickeling(self, gammalib.GCTAModelRadialGauss(1.0)) + test_support._pickeling(self, gammalib.GCTAModelRadialPolynom([1.0,2.0])) + test_support._pickeling(self, gammalib.GCTAModelRadialProfile(1.0,2.0,3.0)) + test_support._pickeling(self, gammalib.GCTAObservation(obs1)) + test_support._pickeling(self, gammalib.GCTAObservation(obs2)) + test_support._pickeling(self, gammalib.GCTAObservation(obs3)) + test_support._pickeling(self, gammalib.GCTAObservation(obs4)) + test_support._pickeling(self, gammalib.GCTAOnOffObservation(obs5)) + test_support._pickeling(self, gammalib.GCTAPointing(dir)) + test_support._pickeling(self, gammalib.GCTAPsf2D(irfname)) + test_support._pickeling(self, gammalib.GCTAPsfKing(kingname)) #test_support._pickeling(self, gammalib.GCTAPsfPerfTable()) - #test_support._pickeling(self, gammalib.GCTAPsfTable()) + #test_support._pickeling(self, gammalib.GCTAPsfTable()) # No test data #test_support._pickeling(self, gammalib.GCTAPsfVector()) - #test_support._pickeling(self, gammalib.GCTAResponseCube()) - #test_support._pickeling(self, gammalib.GCTAResponseIrf()) - #test_support._pickeling(self, gammalib.GCTAResponseTable()) - #test_support._pickeling(self, gammalib.GCTARoi()) + test_support._pickeling(self, gammalib.GCTAResponseCube(rspcube1)) + test_support._pickeling(self, gammalib.GCTAResponseCube(rspcube2)) + test_support._pickeling(self, gammalib.GCTAResponseIrf(rspirf)) + #test_support._pickeling(self, gammalib.GCTAResponseTable()) # No constructor + test_support._pickeling(self, gammalib.GCTARoi(instdir,2.0)) # Return return @@ -456,7 +531,7 @@ class Test(gammalib.GPythonTestSuite): self.append(self._test_edisp, 'Test CTA energy dispersion classes') self.append(self._test_response, 'Test CTA response classes') self.append(self._test_onoff, 'Test CTA On/Off analysis') - self.append(self._test_pickeling, 'Test pickeling of "cta" classes') + self.append(self._test_pickeling, 'Test CTA class pickeling') # Return return diff --git a/pyext/GApplication.i b/pyext/GApplication.i index 924e05a..09f091e 100644 --- a/pyext/GApplication.i +++ b/pyext/GApplication.i @@ -1,7 +1,7 @@ /*************************************************************************** * GApplication.i - GammaLib application base class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -48,6 +48,8 @@ public: GApplication(void); GApplication(const std::string& name, const std::string& version); GApplication(const std::string& name, const std::string& version, + const std::vector& args); + GApplication(const std::string& name, const std::string& version, int ARGC, char **ARGV); GApplication(const GApplication& app); ~GApplication(void); @@ -76,28 +78,34 @@ public: %rename(_log_header) log_header; %rename(_log_trailer) log_trailer; %rename(_need_help) need_help; + %rename(_args) args; %rename(_log) log; // Methods - void clear(void); - GApplication* clone(void) const; - std::string classname(void) const; - const std::string& name(void) const; - const std::string& version(void) const; - bool logTerse(void) const; - bool logNormal(void) const; - bool logExplicit(void) const; - bool logVerbose(void) const; - bool logDebug(void) const; - bool clobber(void) const; - bool has_par(const std::string& name) const; - const std::string& par_filename(void) const; - const std::string& log_filename(void) const; - void log_header(void); - void log_trailer(void); - const bool& need_help(void) const; - const GApplicationPars& pars(void) const; - void pars(const GApplicationPars& pars); + void clear(void); + GApplication* clone(void) const; + std::string classname(void) const; + const std::string& name(void) const; + const std::string& version(void) const; + double telapse(void) const; + double celapse(void) const; + void logFileOpen(const bool& clobber = true); + void logFileClose(void); + bool logTerse(void) const; + bool logNormal(void) const; + bool logExplicit(void) const; + bool logVerbose(void) const; + bool logDebug(void) const; + bool clobber(void) const; + bool has_par(const std::string& name) const; + const std::string& par_filename(void) const; + const std::string& log_filename(void) const; + void log_header(void); + void log_trailer(void); + const bool& need_help(void) const; + const GApplicationPars& pars(void) const; + void pars(const GApplicationPars& pars); + const std::vector& args(void) const; // Public members GLog log; //!< Application logger @@ -276,4 +284,15 @@ GApplication._log_value = _log_value GApplication copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self._name(), self._version(), self._args(), self.pars()) + return state + def __setstate__(self, state): + if state[0] and state[1]: + self.__init__(state[0], state[1], state[2]) + else: + self.__init__() + self.pars(state[3]) +} }; diff --git a/pyext/GApplicationPar.i b/pyext/GApplicationPar.i index b0be67f..de7f294 100644 --- a/pyext/GApplicationPar.i +++ b/pyext/GApplicationPar.i @@ -46,41 +46,43 @@ public: virtual ~GApplicationPar(void); // Methods - void clear(void); - GApplicationPar* clone(void) const; - std::string classname(void) const; - void type(const std::string& type); - void mode(const std::string& mode); - void value(const std::string& value); - void string(const std::string& value); - void filename(const GFilename& value); - void time(const GTime& value); - void boolean(const bool& value); - void integer(const int& value); - void real(const double& value); - const std::string& name(void) const; - const std::string& type(void) const; - const std::string& mode(void) const; - void query(void); - std::string value(void); - std::string string(void); - GFilename filename(void); - GTime time(void); - GTime time(const GTimeReference& ref); - bool boolean(void); - int integer(void); - double real(void); - const std::string& current_value(void) const; - const std::string& min(void) const; - const std::string& max(void) const; - const std::string& prompt(void) const; - bool is_learn(void) const; - bool is_query(void) const; - bool is_filename(void) const; - bool is_valid(void); - bool is_undefined(void); - bool is_notanumber(void); - bool was_queried(void) const; + void clear(void); + GApplicationPar* clone(void) const; + std::string classname(void) const; + void type(const std::string& type); + void mode(const std::string& mode); + void value(const std::string& value); + void string(const std::string& value); + void filename(const GFilename& value); + void time(const GTime& value); + void boolean(const bool& value); + void integer(const int& value); + void real(const double& value); + const std::string& name(void) const; + const std::string& type(void) const; + const std::string& mode(void) const; + void query(void); + std::string value(void); + std::string string(void); + GFilename filename(void); + GTime time(void); + GTime time(const GTimeReference& ref); + bool boolean(void); + int integer(void); + double real(void); + const std::string& current_value(void) const; + const std::string& min(void) const; + const std::string& max(void) const; + const std::string& prompt(void) const; + bool is_learn(void) const; + bool is_query(void) const; + bool is_filename(void) const; + bool is_valid(void); + bool is_undefined(void); + bool is_notanumber(void); + bool was_queried(void) const; + void pickle(const std::vector& string); + std::vector pickle(void) const; }; @@ -91,4 +93,12 @@ public: GApplicationPar copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.pickle(),) + return state + def __setstate__(self, state): + self.__init__() + self.pickle(state[0]) +} } diff --git a/pyext/GApplicationPars.i b/pyext/GApplicationPars.i index d6b2ffa..57145b2 100644 --- a/pyext/GApplicationPars.i +++ b/pyext/GApplicationPars.i @@ -26,7 +26,6 @@ %{ /* Put headers and other declarations here that are needed for compilation */ #include "GApplicationPars.hpp" -#include "GException.hpp" #include "GFilename.hpp" %} @@ -48,27 +47,29 @@ public: virtual ~GApplicationPars(void); // Methods - void clear(void); - GApplicationPars* clone(void) const; - std::string classname(void) const; - int size(void) const; - bool is_empty(void) const; - GApplicationPar& append(const GApplicationPar& par); - void append_standard(void); - GApplicationPar& insert(const int& index, const GApplicationPar& par); - GApplicationPar& insert(const std::string& name, - const GApplicationPar& par); - void remove(const int& index); - void remove(const std::string& name); - void reserve(const int& num); - void extend(const GApplicationPars& pars); - bool contains(const std::string& name) const; - void syspfiles(const std::string& syspfiles); - const std::string& syspfiles(void) const; - void load(const GFilename& filename); - void load(const GFilename& filename, - const std::vector& args); - void save(const GFilename& filename); + void clear(void); + GApplicationPars* clone(void) const; + std::string classname(void) const; + int size(void) const; + bool is_empty(void) const; + GApplicationPar& append(const GApplicationPar& par); + void append_standard(void); + GApplicationPar& insert(const int& index, const GApplicationPar& par); + GApplicationPar& insert(const std::string& name, + const GApplicationPar& par); + void remove(const int& index); + void remove(const std::string& name); + void reserve(const int& num); + void extend(const GApplicationPars& pars); + bool contains(const std::string& name) const; + void syspfiles(const std::string& syspfiles); + const std::string& syspfiles(void) const; + void load(const GFilename& filename); + void load(const GFilename& filename, + const std::vector& args); + void save(const GFilename& filename); + void pickle(const std::vector& string); + std::vector pickle(void) const; }; @@ -142,4 +143,12 @@ public: GApplicationPars copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.pickle(),) + return state + def __setstate__(self, state): + self.__init__() + self.pickle(state[0]) } +}; diff --git a/pyext/GArf.i b/pyext/GArf.i index 1590064..70c0506 100644 --- a/pyext/GArf.i +++ b/pyext/GArf.i @@ -29,6 +29,11 @@ #include "GTools.hpp" %} +/* __ Constants __________________________________________________________ */ +namespace gammalib { + const std::string extname_arf = "SPECRESP"; +} + /***********************************************************************//** * @class GArf @@ -64,6 +69,7 @@ public: void load(const GFilename& filename); void save(const GFilename& filename, const bool& clobber = false) const; + void read(const GFits& fits); void read(const GFitsTable& table); void write(GFits& fits) const; const GFilename& filename(void) const; @@ -125,4 +131,15 @@ public: GArf copy() { return (*self); } +%pythoncode { + def __getstate__(self): + fits = gammalib.GFits() + self.write(fits) + state = (fits,) + return state + def __setstate__(self, state): + self.__init__() + if not state[0].is_empty(): + self.read(state[0]) +} }; diff --git a/pyext/GCaldb.i b/pyext/GCaldb.i index 7a5fe88..9885109 100644 --- a/pyext/GCaldb.i +++ b/pyext/GCaldb.i @@ -80,6 +80,9 @@ public: state = (self.mission(), self.instrument()) return state def __setstate__(self, state): - self.__init__(state[0], state[1]) + if state[0] and state[1]: + self.__init__(state[0], state[1]) + else: + self.__init__() } }; diff --git a/pyext/GEbounds.i b/pyext/GEbounds.i index ecaaec1..3e66710 100644 --- a/pyext/GEbounds.i +++ b/pyext/GEbounds.i @@ -29,6 +29,11 @@ #include "GTools.hpp" %} +/* __ Constants __________________________________________________________ */ +namespace gammalib { + const std::string extname_ebounds = "EBOUNDS"; +} + /***********************************************************************//** * @class GEbounds diff --git a/pyext/GFitsTable.i b/pyext/GFitsTable.i index 1c4dd2c..9d7cd59 100644 --- a/pyext/GFitsTable.i +++ b/pyext/GFitsTable.i @@ -154,11 +154,12 @@ public: } %pythoncode { def __getstate__(self): - state = (tuple([self[i] for i in range(self.ncols())]),) + state = (gammalib.GFitsHDU.__getstate__(self), tuple([self[i] for i in range(self.ncols())])) return state def __setstate__(self, state): self.__init__() - for x in state[0]: + gammalib.GFitsHDU.__setstate__(self, state[0]) + for x in state[1]: self.append(x) } }; diff --git a/pyext/GFitsTableBitCol.i b/pyext/GFitsTableBitCol.i index def118e..827e021 100644 --- a/pyext/GFitsTableBitCol.i +++ b/pyext/GFitsTableBitCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableBoolCol.i b/pyext/GFitsTableBoolCol.i index 3bb6998..84f14bd 100644 --- a/pyext/GFitsTableBoolCol.i +++ b/pyext/GFitsTableBoolCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableByteCol.i b/pyext/GFitsTableByteCol.i index 714d2f2..6a99a4c 100644 --- a/pyext/GFitsTableByteCol.i +++ b/pyext/GFitsTableByteCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableDoubleCol.i b/pyext/GFitsTableDoubleCol.i index 12b6b6e..0b73dbe 100644 --- a/pyext/GFitsTableDoubleCol.i +++ b/pyext/GFitsTableDoubleCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableFloatCol.i b/pyext/GFitsTableFloatCol.i index 660d98f..f7de789 100644 --- a/pyext/GFitsTableFloatCol.i +++ b/pyext/GFitsTableFloatCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableLongCol.i b/pyext/GFitsTableLongCol.i index 9ccce10..517737a 100644 --- a/pyext/GFitsTableLongCol.i +++ b/pyext/GFitsTableLongCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableLongLongCol.i b/pyext/GFitsTableLongLongCol.i index 9202ed3..d34ebea 100644 --- a/pyext/GFitsTableLongLongCol.i +++ b/pyext/GFitsTableLongLongCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableShortCol.i b/pyext/GFitsTableShortCol.i index 6772afe..9cc8613 100644 --- a/pyext/GFitsTableShortCol.i +++ b/pyext/GFitsTableShortCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableStringCol.i b/pyext/GFitsTableStringCol.i index cc71411..c18741e 100644 --- a/pyext/GFitsTableStringCol.i +++ b/pyext/GFitsTableStringCol.i @@ -136,13 +136,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.width(), self.number(), + state = (self.name(), self.nrows(), self.width(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2], state[3]) - for row in range(len(state[4])): - for inx in range(len(state[4][row])): - self[row,inx] = state[4][row][inx] + self.unit(state[4]) + for row in range(len(state[5])): + for inx in range(len(state[5][row])): + self[row,inx] = state[5][row][inx] } }; diff --git a/pyext/GFitsTableULongCol.i b/pyext/GFitsTableULongCol.i index 831b3fc..4759b50 100644 --- a/pyext/GFitsTableULongCol.i +++ b/pyext/GFitsTableULongCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GFitsTableUShortCol.i b/pyext/GFitsTableUShortCol.i index 8bd56d4..7ee1f75 100644 --- a/pyext/GFitsTableUShortCol.i +++ b/pyext/GFitsTableUShortCol.i @@ -115,13 +115,14 @@ public: } %pythoncode { def __getstate__(self): - state = (self.name(), self.nrows(), self.number(), + state = (self.name(), self.nrows(), self.number(), self.unit(), [[self[row,inx] for inx in range(self.elements(row))] for row in range(self.nrows())]) return state def __setstate__(self, state): self.__init__(state[0], state[1], state[2]) - for row in range(len(state[3])): - for inx in range(len(state[3][row])): - self[row,inx] = state[3][row][inx] + self.unit(state[3]) + for row in range(len(state[4])): + for inx in range(len(state[4][row])): + self[row,inx] = state[4][row][inx] } }; diff --git a/pyext/GHealpix.i b/pyext/GHealpix.i index 949f189..b020035 100644 --- a/pyext/GHealpix.i +++ b/pyext/GHealpix.i @@ -1,7 +1,7 @@ /*************************************************************************** * GHealpix.i - Healpix projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Jurgen Knodlseder * + * copyright (C) 2010-2018 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -77,4 +77,14 @@ public: GHealpix copy() { return (*self); } +%pythoncode { + def __getstate__(self): + hdu = gammalib.GFitsBinTable() + self.write(hdu) + state = (hdu,) + return state + def __setstate__(self, state): + self.__init__() + self.read(state[0]) +} }; diff --git a/pyext/GHorizDir.i b/pyext/GHorizDir.i index b29f929..29022c3 100644 --- a/pyext/GHorizDir.i +++ b/pyext/GHorizDir.i @@ -1,7 +1,7 @@ /*************************************************************************** * GHorizDir.i - Horizontal direction class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Karl Kosack * + * copyright (C) 2014-2018 by Karl Kosack * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -74,4 +74,12 @@ public: GHorizDir copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.alt(), self.az()) + return state + def __setstate__(self, state): + self.__init__() + self.altaz(state[0], state[1]) +} }; diff --git a/pyext/GModel.i b/pyext/GModel.i index 9188111..13dd1b2 100644 --- a/pyext/GModel.i +++ b/pyext/GModel.i @@ -110,8 +110,8 @@ public: } %pythoncode { def __getstate__(self): - state = self.name(), self.instruments(), self.ids(), self.tscalc(), \ - self.has_ts(), self.ts() + state = (self.name(), self.instruments(), self.ids(), self.tscalc(), + self.has_ts(), self.ts()) return state def __setstate__(self, state): self.__init__() diff --git a/pyext/GModelData.i b/pyext/GModelData.i index 6d2fbe9..48a5396 100644 --- a/pyext/GModelData.i +++ b/pyext/GModelData.i @@ -66,9 +66,9 @@ public: %extend GModelData { %pythoncode { def __getstate__(self): - state = gammalib.GModel.__getstate__(self) + state = (gammalib.GModel.__getstate__(self),) return state def __setstate__(self, state): - gammalib.GModel.__setstate__(self, state) + gammalib.GModel.__setstate__(self, state[0]) } }; diff --git a/pyext/GModelSpatialDiffuseCube.i b/pyext/GModelSpatialDiffuseCube.i index b43f1ed..cc0be0b 100644 --- a/pyext/GModelSpatialDiffuseCube.i +++ b/pyext/GModelSpatialDiffuseCube.i @@ -83,7 +83,8 @@ public: void load(const GFilename& filename); void save(const GFilename& filename, const bool& clobber = false) const; - void write(GFits& file) const; + void read(const GFits& fits); + void write(GFits& fits) const; }; @@ -94,4 +95,16 @@ public: GModelSpatialDiffuseCube copy() { return (*self); } +%pythoncode { + def __getstate__(self): + fits = gammalib.GFits() + self.write(fits) + state = (fits, self.filename(), self[0]) + return state + def __setstate__(self, state): + self.__init__() + self.read(state[0]) + self.filename(state[1]) + self[0] = state[2] +} }; diff --git a/pyext/GModelSpatialDiffuseMap.i b/pyext/GModelSpatialDiffuseMap.i index 502290d..ef6a704 100644 --- a/pyext/GModelSpatialDiffuseMap.i +++ b/pyext/GModelSpatialDiffuseMap.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialDiffuseMap.i - Spatial map model class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2016 by Juergen Knoedlseder * + * copyright (C) 2012-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -86,4 +86,13 @@ public: GModelSpatialDiffuseMap copy() { return (*self); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialEllipticalDisk.i b/pyext/GModelSpatialEllipticalDisk.i index a6406e0..04ce267 100644 --- a/pyext/GModelSpatialEllipticalDisk.i +++ b/pyext/GModelSpatialEllipticalDisk.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialEllipticalDisk.i - Elliptical disk source model class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2016 by Michael Mayer * + * copyright (C) 2013-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -79,4 +79,13 @@ public: double eval(const GPhoton& photon, const bool& gradients) const { return self->GModelSpatialElliptical::eval(photon, gradients); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialEllipticalGauss.i b/pyext/GModelSpatialEllipticalGauss.i index d5995d2..c49ef70 100644 --- a/pyext/GModelSpatialEllipticalGauss.i +++ b/pyext/GModelSpatialEllipticalGauss.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialEllipticalGauss.i - Elliptical gauss source model class * * ----------------------------------------------------------------------- * - * copyright (C) 2015-2016 by Michael Mayer * + * copyright (C) 2015-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -79,4 +79,13 @@ public: double eval(const GPhoton& photon, const bool& gradients) const { return self->GModelSpatialElliptical::eval(photon, gradients); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialRadialDisk.i b/pyext/GModelSpatialRadialDisk.i index 54ca40a..90543d9 100644 --- a/pyext/GModelSpatialRadialDisk.i +++ b/pyext/GModelSpatialRadialDisk.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialRadialDisk.i - Radial disk source model class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Christoph Deil * + * copyright (C) 2011-2018 by Christoph Deil * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -88,4 +88,13 @@ public: double eval(const GPhoton& photon, const bool& gradients) const { return self->GModelSpatialRadial::eval(photon, gradients); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialRadialGauss.i b/pyext/GModelSpatialRadialGauss.i index b9a959d..520c6d1 100644 --- a/pyext/GModelSpatialRadialGauss.i +++ b/pyext/GModelSpatialRadialGauss.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialRadialGauss.i - Radial Gaussian source model class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -85,4 +85,13 @@ public: double eval(const GPhoton& photon, const bool& gradients) const { return self->GModelSpatialRadial::eval(photon, gradients); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialRadialProfileDMBurkert.i b/pyext/GModelSpatialRadialProfileDMBurkert.i index b4cec3a..230106f 100644 --- a/pyext/GModelSpatialRadialProfileDMBurkert.i +++ b/pyext/GModelSpatialRadialProfileDMBurkert.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialRadialProfileDMBurkert.i - Burkert radial profile class * * ----------------------------------------------------------------------- * - * copyright (C) 2016 by Nathan Kelley-Hoskins * + * copyright (C) 2016-2018 by Nathan Kelley-Hoskins * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -75,4 +75,13 @@ public: GModelSpatialRadialProfileDMBurkert copy() { return (*self); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialRadialProfileDMEinasto.i b/pyext/GModelSpatialRadialProfileDMEinasto.i index e18a961..bff28e9 100644 --- a/pyext/GModelSpatialRadialProfileDMEinasto.i +++ b/pyext/GModelSpatialRadialProfileDMEinasto.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialRadialProfileDMEinasto.i - Einasto radial profile class * * ----------------------------------------------------------------------- * - * copyright (C) 2016 by Nathan Kelley-Hoskins * + * copyright (C) 2016-2018 by Nathan Kelley-Hoskins * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -77,4 +77,13 @@ public: GModelSpatialRadialProfileDMEinasto copy() { return (*self); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialRadialProfileDMZhao.i b/pyext/GModelSpatialRadialProfileDMZhao.i index 4b81cdb..3bc074f 100644 --- a/pyext/GModelSpatialRadialProfileDMZhao.i +++ b/pyext/GModelSpatialRadialProfileDMZhao.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialRadialProfileDMZhao.i - Zhao radial profile class * * ----------------------------------------------------------------------- * - * copyright (C) 2016 by Nathan Kelley-Hoskins * + * copyright (C) 2016-2018 by Nathan Kelley-Hoskins * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -81,4 +81,13 @@ public: GModelSpatialRadialProfileDMZhao copy() { return (*self); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialRadialProfileGauss.i b/pyext/GModelSpatialRadialProfileGauss.i index b89efed..4cda2d1 100644 --- a/pyext/GModelSpatialRadialProfileGauss.i +++ b/pyext/GModelSpatialRadialProfileGauss.i @@ -70,4 +70,13 @@ public: GModelSpatialRadialProfileGauss copy() { return (*self); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GModelSpatialRadialShell.i b/pyext/GModelSpatialRadialShell.i index 74f57e4..6ec320c 100644 --- a/pyext/GModelSpatialRadialShell.i +++ b/pyext/GModelSpatialRadialShell.i @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialRadialShell.i - Radial spatial shell source model class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Christoph Deil * + * copyright (C) 2011-2018 by Christoph Deil * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -88,4 +88,13 @@ public: double eval(const GPhoton& photon, const bool& gradients) const { return self->GModelSpatialRadial::eval(photon, gradients); } +%pythoncode { + def __getstate__(self): + xml = gammalib.GXmlElement() + self.write(xml) + state = (xml,) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GPha.i b/pyext/GPha.i index e7454df..732c016 100644 --- a/pyext/GPha.i +++ b/pyext/GPha.i @@ -28,6 +28,11 @@ #include "GPha.hpp" %} +/* __ Constants __________________________________________________________ */ +namespace gammalib { + const std::string extname_pha = "SPECTRUM"; +} + /***********************************************************************//** * @class GPha @@ -87,6 +92,7 @@ public: void load(const GFilename& filename); void save(const GFilename& filename, const bool& clobber = false) const; + void read(const GFits& fits); void read(const GFitsTable& table); void write(GFits& fits) const; const GFilename& filename(void) const; @@ -148,4 +154,15 @@ public: GPha copy() { return (*self); } +%pythoncode { + def __getstate__(self): + fits = gammalib.GFits() + self.write(fits) + state = (fits,) + return state + def __setstate__(self, state): + self.__init__() + if not state[0].is_empty(): + self.read(state[0]) +} }; diff --git a/pyext/GRmf.i b/pyext/GRmf.i index 883af73..2a495fc 100644 --- a/pyext/GRmf.i +++ b/pyext/GRmf.i @@ -31,6 +31,11 @@ /* __ Includes ___________________________________________________________ */ %include "GTypemaps.i" +/* __ Constants __________________________________________________________ */ +namespace gammalib { + const std::string extname_rmf = "MATRIX"; +} + /***********************************************************************//** * @class GRmf @@ -67,6 +72,7 @@ public: void save(const GFilename& filename, const bool& clobber = false, const std::string& unit = "keV") const; + void read(const GFits& fits); void read(const GFitsTable& table); void write(GFits& fits, const std::string& unit = "keV") const; @@ -115,4 +121,15 @@ public: GRmf copy() { return (*self); } +%pythoncode { + def __getstate__(self): + fits = gammalib.GFits() + self.write(fits) + state = (fits,) + return state + def __setstate__(self, state): + self.__init__() + if not state[0].is_empty(): + self.read(state[0]) +} }; diff --git a/pyext/GSkyMap.i b/pyext/GSkyMap.i index 860e660..00800ac 100644 --- a/pyext/GSkyMap.i +++ b/pyext/GSkyMap.i @@ -312,4 +312,23 @@ public: } return array; } +// Pickeling +%pythoncode { + def __getstate__(self): + fits = gammalib.GFits() + self.write(fits) + state = (fits,) + return state + def __setstate__(self, state): + self.__init__() + for hdu in state[0]: + if ((hdu.exttype() == 0 and + hdu.has_card('NAXIS') and + hdu.integer('NAXIS') >= 2) or + (hdu.exttype() == 0 and + hdu.has_card('PIXTYPE') and + hdu.string('PIXTYPE') == 'HEALPIX')): + self.read(hdu) + break +} }; diff --git a/pyext/GSkyPixel.i b/pyext/GSkyPixel.i index 18ac87f..a060cbc 100644 --- a/pyext/GSkyPixel.i +++ b/pyext/GSkyPixel.i @@ -76,4 +76,16 @@ public: GSkyPixel copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.is_1D(), self.is_2D(), self.x(), self.y(), self.index()) + return state + def __setstate__(self, state): + if state[0]: + self.__init__(state[4]) + elif state[1]: + self.__init__(state[2], state[3]) + else: + self.__init__() +} }; diff --git a/pyext/GSkyRegionCircle.i b/pyext/GSkyRegionCircle.i index 55f5496..87d7145 100644 --- a/pyext/GSkyRegionCircle.i +++ b/pyext/GSkyRegionCircle.i @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyRegionCircle.i - Sky region class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2015 by Michael Mayer * + * copyright (C) 2013-2018 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,4 +70,11 @@ public: GSkyRegionCircle copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.centre(), self.radius()) + return state + def __setstate__(self, state): + self.__init__(state[0], state[1]) +} }; diff --git a/pyext/GSkyRegionMap.i b/pyext/GSkyRegionMap.i index 6c74adb..e3281b4 100644 --- a/pyext/GSkyRegionMap.i +++ b/pyext/GSkyRegionMap.i @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyRegionMap.i - Sky region map class * * ----------------------------------------------------------------------- * - * copyright (C) 2017 by Pierrick Martin * + * copyright (C) 2017-2018 by Pierrick Martin * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -38,9 +38,9 @@ class GSkyRegionMap : public GSkyRegion { public: // Constructors and destructors GSkyRegionMap(void); - GSkyRegionMap(const GFilename& filename); - GSkyRegionMap(const GSkyMap& map); - GSkyRegionMap(const GSkyRegion* region); + explicit GSkyRegionMap(const GFilename& filename); + explicit GSkyRegionMap(const GSkyMap& map); + explicit GSkyRegionMap(const GSkyRegion* region); GSkyRegionMap(const GSkyRegionMap& region); virtual ~GSkyRegionMap(void); @@ -58,7 +58,6 @@ public: void load(const GFilename& filename); void map(const GSkyMap& map); const GSkyMap& map(void) const; - const GFilename& filename(void) const; const std::vector& nonzero_indices(void) const; }; @@ -70,4 +69,11 @@ public: GSkyRegionMap copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (self.map(),) + return state + def __setstate__(self, state): + self.__init__(state[0]) +} }; diff --git a/pyext/GSkyRegions.i b/pyext/GSkyRegions.i index f0018a2..f477d4f 100644 --- a/pyext/GSkyRegions.i +++ b/pyext/GSkyRegions.i @@ -60,6 +60,7 @@ public: void load(const GFilename& filename); void save(const GFilename& filename) const; const GFilename& filename(void) const; + void filename(const GFilename& filename); }; /***********************************************************************//** @@ -124,4 +125,16 @@ public: GSkyRegions copy() { return (*self); } +%pythoncode { + def __getstate__(self): + state = (tuple([x for x in self]), self.filename()) + return state + def __setstate__(self, state): + self.__init__() + size = len(state[0]) + self.reserve(size) + for x in state[0]: + self.append(x) + self.filename(state[1]) +} }; diff --git a/pyext/GWcs.i b/pyext/GWcs.i index 4632f62..444f23b 100644 --- a/pyext/GWcs.i +++ b/pyext/GWcs.i @@ -1,7 +1,7 @@ /*************************************************************************** * GWcs.i - Abstract world coordinate system base class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2015 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -75,3 +75,15 @@ public: /***********************************************************************//** * @brief GWcs class extension ***************************************************************************/ +%extend GWcs { +%pythoncode { + def __getstate__(self): + hdu = gammalib.GFitsImageDouble() + self.write(hdu) + state = (hdu,) + return state + def __setstate__(self, state): + self.__init__() + self.read(state[0]) +} +}; diff --git a/pyext/Makefile.am b/pyext/Makefile.am index 50e8dfc..6b76866 100755 --- a/pyext/Makefile.am +++ b/pyext/Makefile.am @@ -1,7 +1,7 @@ ############################################################################# # Makefile for gammalib Python extension module # # ------------------------------------------------------------------------- # -# Copyright (C) 2011-2017 Juergen Knoedlseder # +# Copyright (C) 2011-2018 Juergen Knoedlseder # # ------------------------------------------------------------------------- # # # # This program is free software: you can redistribute it and/or modify # @@ -120,7 +120,11 @@ testdata = $(top_srcdir)/test/data/initial_coords.txt \ $(top_srcdir)/test/data/fk5_to_galactic.txt \ $(top_srcdir)/test/data/file.fits.gz \ $(top_srcdir)/test/data/test_GApplication.par \ - $(top_srcdir)/test/data/model_point_plaw.xml + $(top_srcdir)/test/data/model_point_plaw.xml \ + $(top_srcdir)/test/data/test_cube.fits \ + $(top_srcdir)/test/data/filefunction.txt \ + $(top_srcdir)/test/data/model_temporal_lightcurve.fits \ + $(top_srcdir)/test/data/model_temporal_phasecurve.fits # Test data to be distributed in $(pyexecdir)/gammalib/tests/data/caldb/data/cta/prod2 testcaldbidx = $(top_srcdir)/test/data/caldb/data/cta/prod2/caldb.indx diff --git a/pyext/gammalib/app.i b/pyext/gammalib/app.i index 90f8b42..3cb7efe 100644 --- a/pyext/gammalib/app.i +++ b/pyext/gammalib/app.i @@ -1,7 +1,7 @@ /*************************************************************************** * app.i - Application module * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -38,6 +38,11 @@ /* __ Include standard typemaps for vectors and strings __________________ */ %include stl.i +%include std_string.i +%include std_vector.i +namespace std { + %template(vectors) vector; +}; /* __ Include GammaLib typemaps __________________________________________ */ %include typemap_GFilename.i diff --git a/src/app/GApplication.cpp b/src/app/GApplication.cpp index f5613ac..b784237 100644 --- a/src/app/GApplication.cpp +++ b/src/app/GApplication.cpp @@ -104,7 +104,32 @@ GApplication::GApplication(const std::string& name, const std::string& version) // Return return; } - + + +/***********************************************************************//** + * @brief Application constructor + * + * @param[in] name Application name. + * @param[in] version Application version. + * @param[in] args Command line arguments + * + * Constructs an application from an application @p name, @p version and a + * number of command line arguments @p args. + ***************************************************************************/ +GApplication::GApplication(const std::string& name, + const std::string& version, + const std::vector& args) +{ + // Initialise members + init_members(); + + // Set members + set_members(name, version, args); + + // Return + return; +} + /***********************************************************************//** * @brief Application constructor @@ -115,12 +140,7 @@ GApplication::GApplication(const std::string& name, const std::string& version) * @param[in] argv Command line arguments * * Constructs an application from an application @p name, @p version and a - * number @p argc of command line arguments @p argv. The constructor will - * set the parameter filename to ".par" and the log filename to - * "".log. The parameters will be loaded from the parameter file. - * - * No log file will be opened. To open the log file an explicit call to the - * logFileOpen() method is required. + * number @p argc of command line arguments @p argv. * * This constructor should be used for C++ applications. ***************************************************************************/ @@ -130,45 +150,14 @@ GApplication::GApplication(const std::string& name, const std::string& version, // Initialise members init_members(); - // Set application name and version - m_name = name; - m_version = version; - - // Set default parfile and logfile name - m_parfile = name+".par"; - m_logfile = name+".log"; - - // Save arguments as vector of strings + // Put arguments in vector string + std::vector args; for (int i = 0; i < argc; ++i) { - m_args.push_back(gammalib::strip_whitespace(argv[i])); - } - - // Catch --help option before doing anything else. The actual action - // needs to be done by the client, but we skip the loading of the - // parameter file and the opening of the logger if the help option - // was specified. - m_need_help = false; - if (m_args.size() >= 2) { - if (m_args[1] == "--help") { - m_need_help = true; - } + args.push_back(gammalib::strip_whitespace(argv[i])); } - // If no --help option has been specified then proceed with loading - // the parameter file and opening the logger - if (!m_need_help) { - - // Initialise application parameters - m_pars.load(par_filename(), m_args); - - // Signal that application parameters have been loaded - m_pars_loaded = true; - - // Set log filename and chattiness - set_log_filename(); - set_log_chatter(); - - } // endif: no --help option specified + // Set members + set_members(name, version, args); // Return return; @@ -919,6 +908,68 @@ void GApplication::free_members(void) /***********************************************************************//** + * @brief Set application members + * + * @param[in] name Application name. + * @param[in] version Application version. + * @param[in] args Command line arguments + * + * Sets the application members from an application @p name, @p version and + * a number of command line arguments @p args. The method will set the + * parameter filename to ".par" and the log filename to "".log. + * The parameters will be loaded from the parameter file. + * + * No log file will be opened. To open the log file an explicit call to the + * logFileOpen() method is required. + ***************************************************************************/ +void GApplication::set_members(const std::string& name, + const std::string& version, + const std::vector& args) +{ + // Set application name and version + m_name = name; + m_version = version; + + // Set default parfile and logfile name + m_parfile = name+".par"; + m_logfile = name+".log"; + + // Save arguments + m_args = args; + + // Catch --help option before doing anything else. The actual action + // needs to be done by the client, but we skip the loading of the + // parameter file and the opening of the logger if the help option + // was specified. + m_need_help = false; + if (m_args.size() >= 2) { + if (m_args[1] == "--help") { + m_need_help = true; + } + } + + // If no --help option has been specified then proceed with loading + // the parameter file and opening the logger + if (!m_need_help) { + + // Initialise application parameters + m_pars.load(par_filename(), m_args); + + // Signal that application parameters have been loaded + m_pars_loaded = true; + + // Set log filename and chattiness + set_log_filename(); + set_log_chatter(); + + } // endif: no --help option specified + + // Return + return; +} + + +/***********************************************************************//** * @brief Set chattiness of logger ***************************************************************************/ void GApplication::set_log_chatter(void) diff --git a/src/app/GApplicationPar.cpp b/src/app/GApplicationPar.cpp index 8c7c2ea..8742a43 100644 --- a/src/app/GApplicationPar.cpp +++ b/src/app/GApplicationPar.cpp @@ -855,6 +855,60 @@ bool GApplicationPar::is_notanumber(void) /***********************************************************************//** + * @brief Set class from pickled string vector + * + * @param[in] string String vector containing class information. + ***************************************************************************/ +void GApplicationPar::pickle(const std::vector& string) +{ + // Clear object + clear(); + + // Extract members + m_update = (bool)gammalib::toint(string[0]); + m_queried = (bool)gammalib::toint(string[1]); + m_name = string[2]; + m_type = string[3]; + m_mode = string[4]; + m_value = string[5]; + m_min = string[6]; + m_max = string[7]; + m_prompt = string[8]; + m_status = (Status)gammalib::toint(string[9]); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Return pickled string vector + * + * @return String vector containing class information. + ***************************************************************************/ +std::vector GApplicationPar::pickle(void) const +{ + // Allocate vector of strings with 10 elements + std::vector string(10); + + // Set vector elements from class members + string[0] = gammalib::str(m_update); + string[1] = gammalib::str(m_queried); + string[2] = m_name; + string[3] = m_type; + string[4] = m_mode; + string[5] = m_value; + string[6] = m_min; + string[7] = m_max; + string[8] = m_prompt; + string[9] = gammalib::str((int)m_status); + + // Return string vector + return (string); +} + + +/***********************************************************************//** * @brief Print parameter * * @param[in] chatter Chattiness. diff --git a/src/app/GApplicationPars.cpp b/src/app/GApplicationPars.cpp index a9840b4..850832e 100644 --- a/src/app/GApplicationPars.cpp +++ b/src/app/GApplicationPars.cpp @@ -34,6 +34,7 @@ #include // mkdir() function #include // std::getenv() function #include // std::fopen(), etc. functions +#include #include "GTools.hpp" #include "GException.hpp" #include "GFilename.hpp" @@ -784,6 +785,124 @@ void GApplicationPars::save(const GFilename& filename) /***********************************************************************//** + * @brief Set class from pickled string vector + * + * @param[in] string String vector containing class information. + ***************************************************************************/ +void GApplicationPars::pickle(const std::vector& string) +{ + // Clear object + clear(); + + // Extract vector sizes + int n_parfile = gammalib::toint(string[0]); + int n_pars = gammalib::toint(string[1]); + int n_line = gammalib::toint(string[2]); + int n_vstart = gammalib::toint(string[3]); + int n_vstop = gammalib::toint(string[4]); + + // Initialise string pointer + int istring = 5; + + // Extract parameter file lines + for (int i = 0; i < n_parfile; ++i, ++istring) { + m_parfile.push_back(string[istring]); + } + + // Extract application parameters + for (int i = 0; i < n_pars; ++i) { + int n_par = gammalib::toint(string[istring]); + int i_start = istring + 1; + int i_end = i_start + n_par; + //std::vector sub(string.begin()+i_start, + // string.begin()+i_end); + GApplicationPar par; + par.pickle(std::vector(string.begin()+i_start, + string.begin()+i_end)); + m_pars.push_back(par); + istring = i_end; + } + + // Extract line numbers + for (int i = 0; i < n_line; ++i, ++istring) { + m_line.push_back(gammalib::toint(string[istring])); + } + + // Extract columns of start values + for (int i = 0; i < n_vstart; ++i, ++istring) { + m_vstart.push_back((size_t)gammalib::toint(string[istring])); + } + + // Extract columns of stop values + for (int i = 0; i < n_vstop; ++i, ++istring) { + m_vstop.push_back((size_t)gammalib::toint(string[istring])); + } + + // Extract effective mode and location of syspfiles + m_mode = string[istring++]; + m_syspfiles = string[istring++]; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Return pickled string vector + * + * @return String vector containing class information. + ***************************************************************************/ +std::vector GApplicationPars::pickle(void) const +{ + // Allocate vector of strings + std::vector string; + + // Store vector lengths + string.push_back(gammalib::str(m_parfile.size())); + string.push_back(gammalib::str(m_pars.size())); + string.push_back(gammalib::str(m_line.size())); + string.push_back(gammalib::str(m_vstart.size())); + string.push_back(gammalib::str(m_vstop.size())); + + // Store parfile lines + for (int i = 0; i < m_parfile.size(); ++i) { + string.push_back(m_parfile[i]); + } + + // Store application parameters + for (int i = 0; i < m_pars.size(); ++i) { + std::vector par = m_pars[i].pickle(); + string.push_back(gammalib::str(par.size())); + for (int k = 0; k < par.size(); ++k) { + string.push_back(par[k]); + } + } + + // Store line numbers + for (int i = 0; i < m_line.size(); ++i) { + string.push_back(gammalib::str(m_line[i])); + } + + // Store columns of start values + for (int i = 0; i < m_vstart.size(); ++i) { + string.push_back(gammalib::str(m_vstart[i])); + } + + // Store columns of stop values + for (int i = 0; i < m_vstop.size(); ++i) { + string.push_back(gammalib::str(m_vstop[i])); + } + + // Store effective mode and location of syspfiles + string.push_back(m_mode); + string.push_back(m_syspfiles); + + // Return string vector + return string; +} + + +/***********************************************************************//** * @brief Print parameters * * @param[in] chatter Chattiness. diff --git a/src/fits/GFitsAsciiTable.cpp b/src/fits/GFitsAsciiTable.cpp index ed562d7..b18aa00 100644 --- a/src/fits/GFitsAsciiTable.cpp +++ b/src/fits/GFitsAsciiTable.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsAsciiTable.cpp - FITS ASCII table class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2013 by Juergen Knoedlseder * + * copyright (C) 2008-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -66,6 +66,9 @@ GFitsAsciiTable::GFitsAsciiTable(const int& nrows) : GFitsTable(nrows) // Initialise class members for clean destruction init_members(); + // Initialise header + init_table_header(); + // Return return; } @@ -216,3 +219,39 @@ void GFitsAsciiTable::free_members(void) // Return return; } + + + + +/***********************************************************************//** + * @brief Initialise ASCII table header + * + * Initialises the table header by setting the default header cards. + ***************************************************************************/ +void GFitsAsciiTable::init_table_header(void) +{ + // Compute total width in Bytes + int width = 0; + for (int i = 0; i < ncols(); ++i) { + width += m_columns[i]->width(); + } + + // Set image header keywords + m_header.append(GFitsHeaderCard("XTENSION", "TABLE", + "ASCII table extension")); + m_header.append(GFitsHeaderCard("BITPIX", 8, + "8-bit ASCII characters")); + m_header.append(GFitsHeaderCard("NAXIS", 2, + "2-dimensional ASCII table")); + m_header.append(GFitsHeaderCard("NAXIS1", width, + "width of table in characters")); + m_header.append(GFitsHeaderCard("NAXIS2", nrows(), + "number of rows in table")); + m_header.append(GFitsHeaderCard("PCOUNT", 0, + "no group parameters (required keyword)")); + m_header.append(GFitsHeaderCard("GCOUNT", 1, + "one data group (required keyword)")); + + // Return + return; +} diff --git a/src/fits/GFitsBinTable.cpp b/src/fits/GFitsBinTable.cpp index 4284068..c23c7cf 100644 --- a/src/fits/GFitsBinTable.cpp +++ b/src/fits/GFitsBinTable.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GFitsBinTable.cpp - FITS binary table class * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2013 by Juergen Knoedlseder * + * copyright (C) 2008-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,6 +70,9 @@ GFitsBinTable::GFitsBinTable(const int& nrows) : GFitsTable(nrows) // Initialise class members for clean destruction init_members(); + // Initialise header + init_table_header(); + // Return return; } @@ -220,3 +223,37 @@ void GFitsBinTable::free_members(void) // Return return; } + + +/***********************************************************************//** + * @brief Initialise binary table header + * + * Initialises the table header by setting the default header cards. + ***************************************************************************/ +void GFitsBinTable::init_table_header(void) +{ + // Compute total width in Bytes + int width = 0; + for (int i = 0; i < ncols(); ++i) { + width += m_columns[i]->width(); + } + + // Set image header keywords + m_header.append(GFitsHeaderCard("XTENSION", "BINTABLE", + "binary table extension")); + m_header.append(GFitsHeaderCard("BITPIX", 8, + "8-bit bytes")); + m_header.append(GFitsHeaderCard("NAXIS", 2, + "2-dimensional binary table")); + m_header.append(GFitsHeaderCard("NAXIS1", width, + "width of table in bytes")); + m_header.append(GFitsHeaderCard("NAXIS2", nrows(), + "number of rows in table")); + m_header.append(GFitsHeaderCard("PCOUNT", 0, + "size of special data area")); + m_header.append(GFitsHeaderCard("GCOUNT", 1, + "one data group (required keyword)")); + + // Return + return; +} diff --git a/src/fits/GFitsTable.cpp b/src/fits/GFitsTable.cpp index 1d4dff2..846f07f 100644 --- a/src/fits/GFitsTable.cpp +++ b/src/fits/GFitsTable.cpp @@ -621,7 +621,7 @@ bool GFitsTable::contains(const std::string& colname) const /***********************************************************************//** * @brief Print table information * - * @param[in] chatter Chattiness (defaults to NORMAL). + * @param[in] chatter Chattiness. * @return String containing table information. ***************************************************************************/ std::string GFitsTable::print(const GChatter& chatter) const @@ -695,6 +695,75 @@ std::string GFitsTable::print(const GChatter& chatter) const ==========================================================================*/ /***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void GFitsTable::init_members(void) +{ + // Initialise members + m_type = -1; + m_rows = 0; + m_cols = 0; + m_columns = NULL; + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] table Table to copy + ***************************************************************************/ +void GFitsTable::copy_members(const GFitsTable& table) +{ + // Copy attributes + m_type = table.m_type; + m_rows = table.m_rows; + m_cols = table.m_cols; + + // Copy column definition + if (table.m_columns != NULL && m_cols > 0) { + m_columns = new GFitsTableCol*[m_cols]; + for (int i = 0; i < m_cols; ++i) { + if (table.m_columns[i] != NULL) { + m_columns[i] = table.m_columns[i]->clone(); + } + else { + m_columns[i] = NULL; + } + } + } + + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + * + * De-allocates all column pointers + ***************************************************************************/ +void GFitsTable::free_members(void) +{ + // Free memory + if (m_columns != NULL) { + for (int i = 0; i < m_cols; ++i) { + if (m_columns[i] != NULL) delete m_columns[i]; + } + delete [] m_columns; + } + + // Mark memory as freed + m_columns = NULL; + + // Return + return; +} + + +/***********************************************************************//** * @brief Open Table * * @param[in] vptr FITS file pointer. @@ -1451,75 +1520,6 @@ char* GFitsTable::get_tunit(const int& colnum) const ==========================================================================*/ /***********************************************************************//** - * @brief Initialise class members - ***************************************************************************/ -void GFitsTable::init_members(void) -{ - // Initialise members - m_type = -1; - m_rows = 0; - m_cols = 0; - m_columns = NULL; - - // Return - return; -} - - -/***********************************************************************//** - * @brief Copy class members - * - * @param[in] table Table to copy - ***************************************************************************/ -void GFitsTable::copy_members(const GFitsTable& table) -{ - // Copy attributes - m_type = table.m_type; - m_rows = table.m_rows; - m_cols = table.m_cols; - - // Copy column definition - if (table.m_columns != NULL && m_cols > 0) { - m_columns = new GFitsTableCol*[m_cols]; - for (int i = 0; i < m_cols; ++i) { - if (table.m_columns[i] != NULL) { - m_columns[i] = table.m_columns[i]->clone(); - } - else { - m_columns[i] = NULL; - } - } - } - - // Return - return; -} - - -/***********************************************************************//** - * @brief Delete class members - * - * De-allocates all column pointers - ***************************************************************************/ -void GFitsTable::free_members(void) -{ - // Free memory - if (m_columns != NULL) { - for (int i = 0; i < m_cols; ++i) { - if (m_columns[i] != NULL) delete m_columns[i]; - } - delete [] m_columns; - } - - // Mark memory as freed - m_columns = NULL; - - // Return - return; -} - - -/***********************************************************************//** * @brief Allocates column * * @param[in] typecode cfitsio type code diff --git a/src/model/GModelSpatialDiffuseCube.cpp b/src/model/GModelSpatialDiffuseCube.cpp index d370dd6..942cd4d 100644 --- a/src/model/GModelSpatialDiffuseCube.cpp +++ b/src/model/GModelSpatialDiffuseCube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GModelSpatialDiffuseCube.cpp - Spatial map cube model class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -56,6 +56,7 @@ const GModelSpatialRegistry g_spatial_cube_legacy_registry(&g_spatial_cube_le #define G_WRITE "GModelSpatialDiffuseCube::write(GXmlElement&)" #define G_ENERGIES "GModelSpatialDiffuseCube::energies(GEnergies&)" #define G_LOAD_CUBE "GModelSpatialDiffuseCube::load_cube(GFilename&)" +#define G_READ_FITS "GModelSpatialDiffuseCube::read(GFits&)" /* __ Macros _____________________________________________________________ */ @@ -930,14 +931,80 @@ void GModelSpatialDiffuseCube::save(const GFilename& filename, /***********************************************************************//** - * @brief Write skymap into FITS file + * @brief Read diffuse cube from FITS file * - * @param[in] file FITS file pointer. + * @param[in] fits FITS file. + * + * @exception GException::invalid_value + * ENERGIES extension incompatible with map cube. + * + * Reads the diffuse cube sky map from the first extension in the @p fits + * file and the energy extension from the "ENERGIES" extension. ***************************************************************************/ -void GModelSpatialDiffuseCube::write(GFits& file) const +void GModelSpatialDiffuseCube::read(const GFits& fits) { + // Initialise skymap + m_cube.clear(); + m_logE.clear(); + + // Read cube from the first valid WCS image + for (int extno = 0; extno < fits.size(); ++extno) { + const GFitsHDU& hdu = *fits.at(extno); + if ((hdu.exttype() == GFitsHDU::HT_IMAGE) && + (hdu.has_card("NAXIS") && (hdu.integer("NAXIS") >= 2))) { + m_cube.read(hdu); + break; + } + } + + // Read energies + GEnergies energies; + energies.read(*(fits.table(gammalib::extname_energies))); + + // Extract number of energy bins + int num = energies.size(); + + // Check if energy binning is consistent with primary image hdu + if (num != m_cube.nmaps() ) { + std::string msg = "Number of energies in \"ENERGIES\" extension ("+ + gammalib::str(num)+") does not match the number of " + "maps ("+gammalib::str(m_cube.nmaps())+" in the " + "map cube. The \"ENERGIES\" extension table shall " + "provide one enegy value for each map in the cube."; + throw GException::invalid_value(G_READ_FITS, msg); + } + + // Set log10(energy) nodes, where energy is in units of MeV + for (int i = 0; i < num; ++i) { + m_logE.append(energies[i].log10MeV()); + } + + // Signal that cube has been loaded + m_loaded = true; + + // Set energy boundaries + set_energy_boundaries(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Write diffuse cube into FITS file + * + * @param[in] fits FITS file. + * + * Writes the diffuse cube sky map and the energy intervals into @p fits + * file. + ***************************************************************************/ +void GModelSpatialDiffuseCube::write(GFits& fits) const +{ + // Make sure that cube is fetched + fetch_cube(); + // Write cube - m_cube.write(file); + m_cube.write(fits); // Create energy intervals GEnergies energies; @@ -947,7 +1014,7 @@ void GModelSpatialDiffuseCube::write(GFits& file) const } // Write energy intervals - energies.write(file); + energies.write(fits); // Return return; @@ -957,7 +1024,7 @@ void GModelSpatialDiffuseCube::write(GFits& file) const /***********************************************************************//** * @brief Print map cube information * - * @param[in] chatter Chattiness (defaults to NORMAL). + * @param[in] chatter Chattiness. * @return String containing model information. ***************************************************************************/ std::string GModelSpatialDiffuseCube::print(const GChatter& chatter) const @@ -1153,14 +1220,14 @@ void GModelSpatialDiffuseCube::fetch_cube(void) const /***********************************************************************//** - * @brief Load cube + * @brief Load map cube * - * @param[in] filename Cube file. + * @param[in] filename Map cube file. * * @exception GException::invalid_value * Number of maps in cube mismatches number of energy bins. * - * Load diffuse cube. + * Load diffuse map cube. ***************************************************************************/ void GModelSpatialDiffuseCube::load_cube(const GFilename& filename) { @@ -1185,14 +1252,11 @@ void GModelSpatialDiffuseCube::load_cube(const GFilename& filename) // Check if energy binning is consistent with primary image hdu if (num != m_cube.nmaps() ) { - std::string msg = "Number of energies in \"ENERGIES\"" - " extension ("+gammalib::str(num)+")" - " does not match the number of maps ("+ - gammalib::str(m_cube.nmaps())+" in the" - " map cube.\n" - "The \"ENERGIES\" extension table shall" - " provide one enegy value for each map" - " in the cube."; + std::string msg = "Number of energies in \"ENERGIES\" extension ("+ + gammalib::str(num)+") does not match the number of " + "maps ("+gammalib::str(m_cube.nmaps())+" in the " + "map cube. The \"ENERGIES\" extension table shall " + "provide one enegy value for each map in the cube."; throw GException::invalid_value(G_LOAD_CUBE, msg); } diff --git a/src/model/GModelSpatialDiffuseMap.cpp b/src/model/GModelSpatialDiffuseMap.cpp index 7b56286..141f112 100644 --- a/src/model/GModelSpatialDiffuseMap.cpp +++ b/src/model/GModelSpatialDiffuseMap.cpp @@ -797,23 +797,30 @@ std::string GModelSpatialDiffuseMap::print(const GChatter& chatter) const * * Loads skymap into the model class. The method calls the protected method * prepare_map() that prepares the map for usage by the class. + * + * If the @p filename is empty, no map will be loaded. ***************************************************************************/ void GModelSpatialDiffuseMap::load(const GFilename& filename) { // Initialise skymap m_map.clear(); - // Store filename of skymap (for XML writing). Note that we do not - // expand any environment variable at this level, so that if we write - // back the XML element we write the filepath with the environment - // variables - m_filename = filename; + // Continue only if filename is not empty + if (!filename.is_empty()) { - // Load sky map - m_map.load(m_filename); + // Store filename of skymap (for XML writing). Note that we do not + // expand any environment variable at this level, so that if we + // write back the XML element we write the filepath with the + // environment variables + m_filename = filename; - // Prepare sky map - prepare_map(); + // Load sky map + m_map.load(m_filename); + + // Prepare sky map + prepare_map(); + + } // endif: filename was not empty // Return return; diff --git a/src/model/GModelSpatialRadialProfileDMBurkert.cpp b/src/model/GModelSpatialRadialProfileDMBurkert.cpp index 3c8ecc2..9eb69f9 100644 --- a/src/model/GModelSpatialRadialProfileDMBurkert.cpp +++ b/src/model/GModelSpatialRadialProfileDMBurkert.cpp @@ -421,6 +421,17 @@ void GModelSpatialRadialProfileDMBurkert::init_members(void) m_scale_radius.gradient(0.0); m_scale_radius.has_grad(false); // Radial components never have gradients + // Initialise scale density + m_scale_density.clear(); + m_scale_density.name("ScaleDensity"); + m_scale_density.unit("GeV/cm^3"); + m_scale_density.value(0.2); // GeV/cm3, default to GC scale density + m_scale_density.min(1.0e-6); + m_scale_density.fix(); + m_scale_density.scale(1.0); + m_scale_density.gradient(0.0); + m_scale_density.has_grad(false); // Radial components never have gradients + // Initialise halo distance m_halo_distance.clear(); m_halo_distance.name("HaloDistance"); @@ -497,6 +508,7 @@ void GModelSpatialRadialProfileDMBurkert::copy_members(const GModelSpatialRadial // stack as this should have been done by init_members() that was called // before. Otherwise we would have sigma twice on the stack. m_scale_radius = model.m_scale_radius; + m_scale_density = model.m_scale_density; m_halo_distance = model.m_halo_distance; m_theta_min = model.m_theta_min; m_theta_max = model.m_theta_max; diff --git a/src/sky/GSkyMap.cpp b/src/sky/GSkyMap.cpp index ea00f74..5b78cf1 100644 --- a/src/sky/GSkyMap.cpp +++ b/src/sky/GSkyMap.cpp @@ -2184,25 +2184,15 @@ void GSkyMap::read(const GFitsHDU& hdu) free_members(); init_members(); - // Initialize load flag - bool loaded = false; - - // If PIXTYPE keyword equals "HEALPIX" then load map - if (hdu.has_card("PIXTYPE") && hdu.string("PIXTYPE") == "HEALPIX") { + // If HDU is a Healpix HDU then load a Healpix map + if (is_healpix(hdu)) { read_healpix(static_cast(hdu)); - loaded = true; } - // ... otherwise try loading as non HEALPix map - if (!loaded) { - - // Load only if HDU contains an image - if (hdu.exttype() == 0) { - read_wcs(static_cast(hdu)); - //loaded = true; - } - - } // endif + // ... otherwise try loading as WCS map + else if (is_wcs(hdu)) { + read_wcs(static_cast(hdu)); + } // Return return; @@ -3140,6 +3130,9 @@ bool GSkyMap::overlaps_circle(const GSkyRegionCircle& region) const * * @param[in] hdu FITS Header Data Unit. * @return True is HDU contains HEALPix data. + * + * Returns true if the HDU is not an image and the HDU has the "PIXTYPE" + * keyword set to "HEALPIX". ***************************************************************************/ bool GSkyMap::is_healpix(const GFitsHDU& hdu) const { @@ -3149,8 +3142,7 @@ bool GSkyMap::is_healpix(const GFitsHDU& hdu) const // If PIXTYPE keyword equals "HEALPIX" then signal that we have // HEALPix data if ((hdu.exttype() != GFitsHDU::HT_IMAGE) && - (hdu.has_card("PIXTYPE")) && - (hdu.string("PIXTYPE") == "HEALPIX")) { + (hdu.has_card("PIXTYPE") && (hdu.string("PIXTYPE") == "HEALPIX"))) { flag = true; } @@ -3164,6 +3156,9 @@ bool GSkyMap::is_healpix(const GFitsHDU& hdu) const * * @param[in] hdu FITS Header Data Unit. * @return True is HDU contains WCS data. + * + * Returns true if the HDU is an image and the HDU has the "NAXIS" keyword + * set to a value >= 2. ***************************************************************************/ bool GSkyMap::is_wcs(const GFitsHDU& hdu) const { @@ -3171,7 +3166,8 @@ bool GSkyMap::is_wcs(const GFitsHDU& hdu) const bool flag(false); // If extension is an image thn signal that we have WCS data - if (hdu.exttype() == GFitsHDU::HT_IMAGE) { + if ((hdu.exttype() == GFitsHDU::HT_IMAGE) && + (hdu.has_card("NAXIS") && (hdu.integer("NAXIS") >= 2))) { flag = true; } diff --git a/src/sky/GSkyRegionMap.cpp b/src/sky/GSkyRegionMap.cpp index acfc5f4..84f3414 100644 --- a/src/sky/GSkyRegionMap.cpp +++ b/src/sky/GSkyRegionMap.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyRegionMap.cpp - Sky region map class * * ----------------------------------------------------------------------- * - * copyright (C) 2017 by Pierrick Martin * + * copyright (C) 2017-2018 by Pierrick Martin * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -261,7 +261,7 @@ void GSkyRegionMap::map(const GSkyMap& map) /***********************************************************************//** - * @brief Load region map from FITS file name + * @brief Load region map from FITS file * * @param[in] filename FITS file name. ***************************************************************************/ @@ -276,9 +276,6 @@ void GSkyRegionMap::load(const GFilename& filename) // Load map m_map.load(filename); - // Store filename - m_filename = filename; - // Set non-zero indices set_nonzero_indices(); @@ -495,7 +492,6 @@ void GSkyRegionMap::init_members(void) // Initialise members m_map.clear(); m_nonzero_indices.clear(); - m_filename.clear(); //Return return; @@ -510,9 +506,8 @@ void GSkyRegionMap::init_members(void) void GSkyRegionMap::copy_members(const GSkyRegionMap& map) { // Copy members - m_map = map.m_map; - m_nonzero_indices = map.m_nonzero_indices; - m_filename = map.m_filename; + m_map = map.m_map; + m_nonzero_indices = map.m_nonzero_indices; // Compute solid angle compute_solid_angle(); diff --git a/src/sky/GWcs.cpp b/src/sky/GWcs.cpp index b132cb5..ff9128b 100644 --- a/src/sky/GWcs.cpp +++ b/src/sky/GWcs.cpp @@ -222,77 +222,87 @@ void GWcs::read(const GFitsHDU& hdu) // Clear object clear(); - // Get standard keywords. Get bin size either from CDELT1/CDELT2 or - // CD1_1/CD2_2 - std::string ctype1 = hdu.string("CTYPE1"); - std::string ctype2 = hdu.string("CTYPE2"); - double crval1 = hdu.real("CRVAL1"); - double crval2 = hdu.real("CRVAL2"); - double crpix1 = hdu.real("CRPIX1"); - double crpix2 = hdu.real("CRPIX2"); - double cdelt1 = (hdu.has_card("CDELT1")) ? hdu.real("CDELT1") : hdu.real("CD1_1"); - double cdelt2 = (hdu.has_card("CDELT2")) ? hdu.real("CDELT2") : hdu.real("CD2_2"); - - // Determine coordinate system - std::string coords; - std::string xcoord = ctype1.substr(0,4); - std::string ycoord = ctype2.substr(0,4); - if (xcoord == "RA--" && ycoord == "DEC-") { - m_lng = 0; - m_lat = 1; - coords = "EQU"; - } - else if (xcoord == "DEC-" && ycoord == "RA--") { - m_lng = 1; - m_lat = 0; - coords = "EQU"; - } - else if (xcoord == "GLON" && ycoord == "GLAT") { - m_lng = 0; - m_lat = 1; - coords = "GAL"; - } - else if (xcoord == "GLAT" && ycoord == "GLON") { - m_lng = 1; - m_lat = 0; - coords = "GAL"; - } - else if (xcoord == "ELON" && ycoord == "ELAT") { - m_lng = 0; - m_lat = 1; - coords = "ECL"; - } - else if (xcoord == "ELAT" && ycoord == "ELON") { - m_lng = 1; - m_lat = 0; - coords = "ECL"; - } - else if (xcoord == "HLON" && ycoord == "HLAT") { - m_lng = 0; - m_lat = 1; - coords = "HEL"; - } - else if (xcoord == "HLAT" && ycoord == "HLON") { - m_lng = 1; - m_lat = 0; - coords = "HEL"; - } - else if (xcoord == "SLON" && ycoord == "SLAT") { - m_lng = 0; - m_lat = 1; - coords = "SGL"; - } - else if (xcoord == "SLAT" && ycoord == "SLON") { - m_lng = 1; - m_lat = 0; - coords = "SGL"; - } - else { - throw GException::wcs_bad_coords(G_READ, coordsys()); - } + // Continue only if there are standard keywords + if (hdu.has_card("CTYPE1") && hdu.has_card("CTYPE2") && + hdu.has_card("CRVAL1") && hdu.has_card("CRVAL2") && + hdu.has_card("CRPIX1") && hdu.has_card("CRPIX2")) { + + // Get standard keywords. Get bin size either from CDELT1/CDELT2 or + // CD1_1/CD2_2 + std::string ctype1 = hdu.string("CTYPE1"); + std::string ctype2 = hdu.string("CTYPE2"); + double crval1 = hdu.real("CRVAL1"); + double crval2 = hdu.real("CRVAL2"); + double crpix1 = hdu.real("CRPIX1"); + double crpix2 = hdu.real("CRPIX2"); + double cdelt1 = (hdu.has_card("CDELT1")) ? hdu.real("CDELT1") : hdu.real("CD1_1"); + double cdelt2 = (hdu.has_card("CDELT2")) ? hdu.real("CDELT2") : hdu.real("CD2_2"); + + // Determine coordinate system + std::string coords; + std::string xcoord = ctype1.substr(0,4); + std::string ycoord = ctype2.substr(0,4); + if (xcoord == "RA--" && ycoord == "DEC-") { + m_lng = 0; + m_lat = 1; + coords = "EQU"; + } + else if (xcoord == "DEC-" && ycoord == "RA--") { + m_lng = 1; + m_lat = 0; + coords = "EQU"; + } + else if (xcoord == "GLON" && ycoord == "GLAT") { + m_lng = 0; + m_lat = 1; + coords = "GAL"; + } + else if (xcoord == "GLAT" && ycoord == "GLON") { + m_lng = 1; + m_lat = 0; + coords = "GAL"; + } + else if (xcoord == "ELON" && ycoord == "ELAT") { + m_lng = 0; + m_lat = 1; + coords = "ECL"; + } + else if (xcoord == "ELAT" && ycoord == "ELON") { + m_lng = 1; + m_lat = 0; + coords = "ECL"; + } + else if (xcoord == "HLON" && ycoord == "HLAT") { + m_lng = 0; + m_lat = 1; + coords = "HEL"; + } + else if (xcoord == "HLAT" && ycoord == "HLON") { + m_lng = 1; + m_lat = 0; + coords = "HEL"; + } + else if (xcoord == "SLON" && ycoord == "SLAT") { + m_lng = 0; + m_lat = 1; + coords = "SGL"; + } + else if (xcoord == "SLAT" && ycoord == "SLON") { + m_lng = 1; + m_lat = 0; + coords = "SGL"; + } + else { + throw GException::wcs_bad_coords(G_READ, coordsys()); + } - // Set standard parameters - set_members(coords, crval1, crval2, crpix1, crpix2, cdelt1, cdelt2); + // Set standard parameters + set_members(coords, crval1, crval2, crpix1, crpix2, cdelt1, cdelt2); + + // Setup WCS derived parameters + wcs_set(); + + } // endif: there were standard keywords // Return return; @@ -311,111 +321,116 @@ void GWcs::read(const GFitsHDU& hdu) ***************************************************************************/ void GWcs::write(GFitsHDU& hdu) const { - // Write reference pixel coordinates - for (int i = 0; i < m_naxis; ++i) { - std::string keyname = "CRPIX"+gammalib::str(i+1); - std::string comment = "Pixel coordinate of reference point (starting from 1)"; - hdu.card(keyname, m_crpix.at(i), comment); - } - - //TODO: Write linear transformation matrix + // Continue only if there are axes + if (m_naxis > 0) { - // Write coordinate increment at reference point - for (int i = 0; i < m_naxis; ++i) { - std::string keyname = "CDELT"+gammalib::str(i+1); - std::string comment; - if (m_cunit.at(i).length() > 0) { - comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] "; + // Write reference pixel coordinates + for (int i = 0; i < m_naxis; ++i) { + std::string keyname = "CRPIX"+gammalib::str(i+1); + std::string comment = "Pixel coordinate of reference point (starting from 1)"; + hdu.card(keyname, m_crpix.at(i), comment); } - comment += "Coordinate increment at reference point"; - hdu.card(keyname, m_cdelt.at(i), comment); - } - // Write units of coordinate increment and reference value - for (int i = 0; i < m_naxis; ++i) { - if (m_cunit.at(i).length() > 0) { - std::string keyname = "CUNIT"+gammalib::str(i+1); - std::string comment = "Units of coordinate increment and value"; - hdu.card(keyname, m_cunit.at(0), comment); - } - } + //TODO: Write linear transformation matrix - // Write coordinate type - wcs_set_ctype(); - for (int i = 0; i < m_naxis; ++i) { - if (i == m_lng) { - std::string keyname = "CTYPE"+gammalib::str(i+1); - hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i)); + // Write coordinate increment at reference point + for (int i = 0; i < m_naxis; ++i) { + std::string keyname = "CDELT"+gammalib::str(i+1); + std::string comment; + if (m_cunit.at(i).length() > 0) { + comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] "; + } + comment += "Coordinate increment at reference point"; + hdu.card(keyname, m_cdelt.at(i), comment); } - if (i == m_lat) { - std::string keyname = "CTYPE"+gammalib::str(i+1); - hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i)); + + // Write units of coordinate increment and reference value + for (int i = 0; i < m_naxis; ++i) { + if (m_cunit.at(i).length() > 0) { + std::string keyname = "CUNIT"+gammalib::str(i+1); + std::string comment = "Units of coordinate increment and value"; + hdu.card(keyname, m_cunit.at(0), comment); + } } - if (i == m_spec) { - std::string keyname = "CTYPE"+gammalib::str(i+1); - hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i)); + + // Write coordinate type + wcs_set_ctype(); + for (int i = 0; i < m_naxis; ++i) { + if (i == m_lng) { + std::string keyname = "CTYPE"+gammalib::str(i+1); + hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i)); + } + if (i == m_lat) { + std::string keyname = "CTYPE"+gammalib::str(i+1); + hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i)); + } + if (i == m_spec) { + std::string keyname = "CTYPE"+gammalib::str(i+1); + hdu.card(keyname, m_ctype.at(i), m_ctype_c.at(i)); + } } - } - // Write coordinate value at reference point - for (int i = 0; i < m_naxis; ++i) { - std::string keyname = "CRVAL"+gammalib::str(i+1); - std::string comment; - if (m_cunit.at(i).length() > 0) { - comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] "; + // Write coordinate value at reference point + for (int i = 0; i < m_naxis; ++i) { + std::string keyname = "CRVAL"+gammalib::str(i+1); + std::string comment; + if (m_cunit.at(i).length() > 0) { + comment += "["+gammalib::strip_whitespace(m_cunit.at(i))+"] "; + } + comment += "Coordinate value at reference point"; + hdu.card(keyname, m_crval.at(i), comment); } - comment += "Coordinate value at reference point"; - hdu.card(keyname, m_crval.at(i), comment); - } - //TODO: Parameter values - hdu.card("CROTA2", 0.0, "[deg] Rotation Angle"); // Old style, use PV instead - //hdu.card("PV2_1", 0.0, "Projection parameter 1"); - //hdu.card("PV2_2", 0.0, "Projection parameter 2"); + //TODO: Parameter values + hdu.card("CROTA2", 0.0, "[deg] Rotation Angle"); // Old style, use PV instead + //hdu.card("PV2_1", 0.0, "Projection parameter 1"); + //hdu.card("PV2_2", 0.0, "Projection parameter 2"); - // Celestial and spectral transformation parameters - if (!undefined(m_lonpole)) { - hdu.card("LONPOLE", m_lonpole, "[deg] Native longitude of celestial pole"); - } - if (!undefined(m_latpole)) { - hdu.card("LATPOLE", m_latpole, "[deg] Native latitude of celestial pole"); - } - if (!undefined(m_restfrq)) { - hdu.card("RESTFRQ", m_restfrq, "[Hz] Line rest frequency"); - } - if (!undefined(m_restwav)) { - hdu.card("RESTWAV", m_restwav, "[Hz] Line rest wavelength"); - } + // Celestial and spectral transformation parameters + if (!undefined(m_lonpole)) { + hdu.card("LONPOLE", m_lonpole, "[deg] Native longitude of celestial pole"); + } + if (!undefined(m_latpole)) { + hdu.card("LATPOLE", m_latpole, "[deg] Native latitude of celestial pole"); + } + if (!undefined(m_restfrq)) { + hdu.card("RESTFRQ", m_restfrq, "[Hz] Line rest frequency"); + } + if (!undefined(m_restwav)) { + hdu.card("RESTWAV", m_restwav, "[Hz] Line rest wavelength"); + } - // Equatorial coordinate system type - if (m_radesys.length() > 0) { - hdu.card("RADESYS", m_radesys, "Equatorial coordinate system"); - } + // Equatorial coordinate system type + if (m_radesys.length() > 0) { + hdu.card("RADESYS", m_radesys, "Equatorial coordinate system"); + } - // Equinox of equatorial coordinate system - if (!undefined(m_equinox)) { - hdu.card("EQUINOX", m_equinox, "[yr] Equinox of equatorial coordinates"); - } + // Equinox of equatorial coordinate system + if (!undefined(m_equinox)) { + hdu.card("EQUINOX", m_equinox, "[yr] Equinox of equatorial coordinates"); + } - //TODO: Reference frame of spectral coordinates + //TODO: Reference frame of spectral coordinates - //TODO: Reference frame of spectral observation + //TODO: Reference frame of spectral observation - //TODO: Observer's velocity towards source + //TODO: Observer's velocity towards source - //TODO: Reference frame of source redshift + //TODO: Reference frame of source redshift - //TODO: Redshift of the source + //TODO: Redshift of the source - //TODO: Observatory coordinates + //TODO: Observatory coordinates - //TODO: MJD of observation + //TODO: MJD of observation - //TODO: MJD mid-observation time + //TODO: MJD mid-observation time - //TODO: ISO-8601 date corresponding to MJD-OBS + //TODO: ISO-8601 date corresponding to MJD-OBS - //TODO: ISO-8601 date corresponding to MJD-AVG + //TODO: ISO-8601 date corresponding to MJD-AVG + + } // endif: there were axes // Return return; @@ -1038,9 +1053,9 @@ void GWcs::free_members(void) * @todo Implement parameter validity check ***************************************************************************/ void GWcs::set_members(const std::string& coords, - const double& crval1, const double& crval2, - const double& crpix1, const double& crpix2, - const double& cdelt1, const double& cdelt2) + const double& crval1, const double& crval2, + const double& crpix1, const double& crpix2, + const double& cdelt1, const double& cdelt2) { //TODO: Check parameters diff --git a/src/sky/GWcsAIT.cpp b/src/sky/GWcsAIT.cpp index 7b2df8c..fffb7ff 100644 --- a/src/sky/GWcsAIT.cpp +++ b/src/sky/GWcsAIT.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsAIT.cpp - Aitoff (AIT) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2017 by Juergen Knoedlseder * + * copyright (C) 2013-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -96,6 +96,9 @@ GWcsAIT::GWcsAIT(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsAZP.cpp b/src/sky/GWcsAZP.cpp index d368597..daf0709 100644 --- a/src/sky/GWcsAZP.cpp +++ b/src/sky/GWcsAZP.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsAZP.cpp - Zenithal/azimuthal perspective (AZP) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -95,6 +95,9 @@ GWcsAZP::GWcsAZP(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsCAR.cpp b/src/sky/GWcsCAR.cpp index 18d4817..4681d5a 100644 --- a/src/sky/GWcsCAR.cpp +++ b/src/sky/GWcsCAR.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsCAR.cpp - Plate carree (CAR) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Jurgen Knodlseder * + * copyright (C) 2010-2018 by Jurgen Knodlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -90,6 +90,9 @@ GWcsCAR::GWcsCAR(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsGLS.cpp b/src/sky/GWcsGLS.cpp index a4a62cc..b55a3cc 100644 --- a/src/sky/GWcsGLS.cpp +++ b/src/sky/GWcsGLS.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsGLS.cpp - Global Sinusoidal (GLS) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2017 by Juergen Knoedlseder * + * copyright (C) 2017-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -89,6 +89,9 @@ GWcsGLS::GWcsGLS(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsMER.cpp b/src/sky/GWcsMER.cpp index bb9e8b0..e6fde11 100644 --- a/src/sky/GWcsMER.cpp +++ b/src/sky/GWcsMER.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsMER.cpp - Mercator's (MER) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2017 by Juergen Knoedlseder * + * copyright (C) 2012-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -90,6 +90,9 @@ GWcsMER::GWcsMER(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsMOL.cpp b/src/sky/GWcsMOL.cpp index 760ad64..8c63ec3 100644 --- a/src/sky/GWcsMOL.cpp +++ b/src/sky/GWcsMOL.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsMOL.cpp - Mollweide's projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2015-2017 by Juergen Knoedlseder * + * copyright (C) 2015-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -97,6 +97,9 @@ GWcsMOL::GWcsMOL(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsSFL.cpp b/src/sky/GWcsSFL.cpp index 614ebd8..6b4bee4 100644 --- a/src/sky/GWcsSFL.cpp +++ b/src/sky/GWcsSFL.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsSFL.cpp - Sanson-Flamsteed (SFL) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2017 by Juergen Knoedlseder * + * copyright (C) 2017-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -91,6 +91,9 @@ GWcsSFL::GWcsSFL(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsSIN.cpp b/src/sky/GWcsSIN.cpp index 61046e6..37953d4 100644 --- a/src/sky/GWcsSIN.cpp +++ b/src/sky/GWcsSIN.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsSIN.cpp - Orthographic/synthesis (SIN) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2016-2017 by Juergen Knoedlseder * + * copyright (C) 2016-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -94,6 +94,9 @@ GWcsSIN::GWcsSIN(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsSTG.cpp b/src/sky/GWcsSTG.cpp index 49f6cbe..63ecde6 100644 --- a/src/sky/GWcsSTG.cpp +++ b/src/sky/GWcsSTG.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsSTG.cpp - Stereographic (STG) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -92,6 +92,9 @@ GWcsSTG::GWcsSTG(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/sky/GWcsTAN.cpp b/src/sky/GWcsTAN.cpp index a959a02..1fad88d 100644 --- a/src/sky/GWcsTAN.cpp +++ b/src/sky/GWcsTAN.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GWcsTAN.cpp - Gnomonic (TAN) projection class * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2017 by Juergen Knoedlseder * + * copyright (C) 2011-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -92,6 +92,9 @@ GWcsTAN::GWcsTAN(const std::string& coords, // Initialise class members init_members(); + // Setup WCS derived parameters + wcs_set(); + // Return return; } diff --git a/src/xspec/GArf.cpp b/src/xspec/GArf.cpp index 44faaba..47606f8 100644 --- a/src/xspec/GArf.cpp +++ b/src/xspec/GArf.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GArf.cpp - XSPEC Auxiliary Response File class * * ----------------------------------------------------------------------- * - * copyright (C) 2013-2017 by Juergen Knoedlseder * + * copyright (C) 2013-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -556,11 +556,8 @@ void GArf::load(const GFilename& filename) // to modify the extension names) GFits fits(filename.url()); - // Get ARF table - const GFitsTable& table = *fits.table(gammalib::extname_arf); - // Read ARF data - read(table); + read(fits); // Close FITS file fits.close(); @@ -610,6 +607,30 @@ void GArf::save(const GFilename& filename, const bool& clobber) const /***********************************************************************//** * @brief Read Auxiliary Response File * + * @param[in] fits FITS file. + * + * Loads the Auxiliary Response File from the `SPECRESP` extension of the + * FITS file. + ***************************************************************************/ +void GArf::read(const GFits& fits) +{ + // Clear response + clear(); + + // Get ARF table + const GFitsTable& table = *fits.table(gammalib::extname_arf); + + // Read ARF data + read(table); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Read Auxiliary Response File + * * @param[in] table ARF FITS table. * * Reads the Auxiliary Response File from a FITS table. The true energy diff --git a/src/xspec/GPha.cpp b/src/xspec/GPha.cpp index 8f98dcb..b41c1a7 100644 --- a/src/xspec/GPha.cpp +++ b/src/xspec/GPha.cpp @@ -801,9 +801,7 @@ void GPha::fill(const GEnergy& energy, const double& value) * * @param[in] filename File name. * - * Loads the Pulse Height Analyzer spectrum from the `SPECTRUM` extension - * of the FITS file. If the file contains also an `EBOUNDS` extension the - * energy boundaries of all Pulse Height Analyzer channels are also loaded. + * Loads the Pulse Height Analyzer spectrum from a FITS file. ***************************************************************************/ void GPha::load(const GFilename& filename) { @@ -814,22 +812,8 @@ void GPha::load(const GFilename& filename) // to modify the extension names) GFits fits(filename.url()); - // Get PHA table - const GFitsTable& pha = *fits.table(gammalib::extname_pha); - // Read PHA data - read(pha); - - // Optionally read energy boundaries - if (fits.contains(gammalib::extname_ebounds)) { - - // Get energy boundary table - const GFitsTable& ebounds = *fits.table(gammalib::extname_ebounds); - - // Read energy boundaries - m_ebounds.read(ebounds); - - } // endif: had energy boundary table + read(fits); // Close FITS file fits.close(); @@ -881,6 +865,42 @@ void GPha::save(const GFilename& filename, const bool& clobber) const /***********************************************************************//** * @brief Read Pulse Height Analyzer spectrum * + * @param[in] fits File file. + * + * Reads the Pulse Height Analyzer spectrum from the `SPECTRUM` extension + * of the FITS file. If the file contains also an `EBOUNDS` extension the + * energy boundaries of all Pulse Height Analyzer channels are also loaded. + ***************************************************************************/ +void GPha::read(const GFits& fits) +{ + // Clear spectrum + clear(); + + // Get PHA table + const GFitsTable& pha = *fits.table(gammalib::extname_pha); + + // Read PHA data + read(pha); + + // Optionally read energy boundaries + if (fits.contains(gammalib::extname_ebounds)) { + + // Get energy boundary table + const GFitsTable& ebounds = *fits.table(gammalib::extname_ebounds); + + // Read energy boundaries + m_ebounds.read(ebounds); + + } // endif: had energy boundary table + + // Return + return; +} + + +/***********************************************************************//** + * @brief Read Pulse Height Analyzer spectrum + * * @param[in] table FITS table. * * @exception GException::invalid_value diff --git a/src/xspec/GRmf.cpp b/src/xspec/GRmf.cpp index f9f82f5..5bd1684 100644 --- a/src/xspec/GRmf.cpp +++ b/src/xspec/GRmf.cpp @@ -500,8 +500,8 @@ GEbounds GRmf::emeasured(const GEnergy& etrue) const * @param[in] filename File name. * * Loads the Redistribution Matrix File from the `MATRIX` extension of the - * FITS file. If the file contains also an `EBOUNDS` extension the energy - * boundaries of all measured energies are also loaded. + * FITS file and the reconstructed energy boundaries from the `EBOUNDS` + * extension. ***************************************************************************/ void GRmf::load(const GFilename& filename) { @@ -512,14 +512,8 @@ void GRmf::load(const GFilename& filename) // to modify the extension names) GFits fits(filename.url()); - // Read measured energy boundaries - m_ebds_measured.load(filename.url()); - - // Get RMF table - const GFitsTable& table = *fits.table(gammalib::extname_rmf); - - // Read RMF data - read(table); + // Read data + read(fits); // Close FITS file fits.close(); @@ -575,6 +569,37 @@ void GRmf::save(const GFilename& filename, /***********************************************************************//** * @brief Read Redistribution Matrix File * + * @param[in] fits File file. + * + * Reads the Redistribution Matrix File from the `MATRIX` extension of the + * FITS file and the reconstructed energy boundaries from the `EBOUNDS` + * extension. + ***************************************************************************/ +void GRmf::read(const GFits& fits) +{ + // Clear spectrum + clear(); + + // Get energy boundary table + const GFitsTable& ebounds = *fits.table(gammalib::extname_ebounds); + + // Read measured energy boundaries + m_ebds_measured.read(ebounds); + + // Get RMF table + const GFitsTable& rmf = *fits.table(gammalib::extname_rmf); + + // Read RMF data + read(rmf); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Read Redistribution Matrix File + * * @param[in] table RMF FITS table. * * Reads the Redistribution Matrix File from a FITS table. The true energy diff --git a/test/data/caldb/data/cta/prod2/caldb.indx b/test/data/caldb/data/cta/prod2/caldb.indx index 8171588..cd70aa0 100644 --- a/test/data/caldb/data/cta/prod2/caldb.indx +++ b/test/data/caldb/data/cta/prod2/caldb.indx @@ -1 +1 @@ -SIMPLE = T / file does conform to FITS standard BITPIX = 8 / number of bits per data pixel NAXIS = 0 / number of data axes EXTEND = T / FITS dataset may contain extensions COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H END XTENSION= 'BINTABLE' / binary table extension BITPIX = 8 / 8-bit bytes NAXIS = 2 / 2-dimensional binary table NAXIS1 = 945 / width of table in bytes NAXIS2 = 4 / number of rows in table PCOUNT = 0 / size of special data area GCOUNT = 1 / one data group (required keyword) TFIELDS = 18 / number of fields in each row TTYPE1 = 'TELESCOP' / label for field 1 TFORM1 = '10A ' / data format of field: ASCII Character TTYPE2 = 'INSTRUME' / label for field 2 TFORM2 = '10A ' / data format of field: ASCII Character TTYPE3 = 'DETNAM ' / label for field 3 TFORM3 = '20A ' / data format of field: ASCII Character TTYPE4 = 'FILTER ' / label for field 4 TFORM4 = '10A ' / data format of field: ASCII Character TTYPE5 = 'CAL_DEV ' / label for field 5 TFORM5 = '20A ' / data format of field: ASCII Character TTYPE6 = 'CAL_DIR ' / label for field 6 TFORM6 = '70A ' / data format of field: ASCII Character TTYPE7 = 'CAL_FILE' / label for field 7 TFORM7 = '40A ' / data format of field: ASCII Character TTYPE8 = 'CAL_CLAS' / label for field 8 TFORM8 = '3A ' / data format of field: ASCII Character TTYPE9 = 'CAL_DTYP' / label for field 9 TFORM9 = '4A ' / data format of field: ASCII Character TTYPE10 = 'CAL_CNAM' / label for field 10 TFORM10 = '20A ' / data format of field: ASCII Character TTYPE11 = 'CAL_CBD ' / label for field 11 TFORM11 = '630A70 ' / data format of field: ASCII Character TTYPE12 = 'CAL_XNO ' / label for field 12 TFORM12 = '1I ' / data format of field: 2-byte INTEGER TTYPE13 = 'CAL_VSD ' / label for field 13 TFORM13 = '10A ' / data format of field: ASCII Character TTYPE14 = 'CAL_VST ' / label for field 14 TFORM14 = '8A ' / data format of field: ASCII Character TTYPE15 = 'REF_TIME' / label for field 15 TFORM15 = '1D ' / data format of field: 8-byte DOUBLE TTYPE16 = 'CAL_QUAL' / label for field 16 TFORM16 = '1I ' / data format of field: 2-byte INTEGER TTYPE17 = 'CAL_DATE' / label for field 17 TFORM17 = '8A ' / data format of field: ASCII Character TTYPE18 = 'CAL_DESC' / label for field 18 TFORM18 = '70A ' / data format of field: ASCII Character EXTNAME = 'CIF ' / name of this extension CIFVERSN= '1992a ' / Version of CIF format HISTORY File modified by user 'jurgen' with fv on 2018-06-26T11:57:32 END CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/South_0.5h irf_file.fits BCFDATAEFF_AREA NAME(South_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) ENERG(0.0050-501.19)TeV THETA(0.00-4.50)deg PHI(0-360)deg NONE NONE 2015-05-1800:00:00@é+15/05/18CTA effective area CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/South_0.5h irf_file.fits BCFDATARPSF NAME(South_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) ENERG(0.0126-199.53)TeV THETA(0.00-9.00)deg PHI(0-360)deg PSF(GAUSS) NONE 2015-05-1800:00:00@é+15/05/18CTA point spread function CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/South_0.5h irf_file.fits BCFDATAEDISP NAME(South_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) ETRUE(0.0050-501.19)TeV MIGRA(0.0000-3.00) THETA(0.00-9.00)deg PHI(0-360)deg NONE 2015-05-1800:00:00@é+15/05/18CTA energy dispersion CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/South_0.5h irf_file.fits BCFDATABGD NAME(South_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) DETX(-4.50-4.50)deg DETY(-4.50-4.50)deg ENERG(0.0126-199.53)TeV NONE NONE 2015-05-1800:00:00@é+15/05/18CTA background \ No newline at end of file +SIMPLE = T / file does conform to FITS standard BITPIX = 8 / number of bits per data pixel NAXIS = 0 / number of data axes EXTEND = T / FITS dataset may contain extensions COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H COMMENT FITS (Flexible Image Transport System) format is defined in 'AstronomyCOMMENT and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H END XTENSION= 'BINTABLE' / binary table extension BITPIX = 8 / 8-bit bytes NAXIS = 2 / 2-dimensional binary table NAXIS1 = 945 / width of table in bytes NAXIS2 = 4 / number of rows in table PCOUNT = 0 / size of special data area GCOUNT = 1 / one data group (required keyword) TFIELDS = 18 / number of fields in each row TTYPE1 = 'TELESCOP' / label for field 1 TFORM1 = '10A ' / data format of field: ASCII Character TTYPE2 = 'INSTRUME' / label for field 2 TFORM2 = '10A ' / data format of field: ASCII Character TTYPE3 = 'DETNAM ' / label for field 3 TFORM3 = '20A ' / data format of field: ASCII Character TTYPE4 = 'FILTER ' / label for field 4 TFORM4 = '10A ' / data format of field: ASCII Character TTYPE5 = 'CAL_DEV ' / label for field 5 TFORM5 = '20A ' / data format of field: ASCII Character TTYPE6 = 'CAL_DIR ' / label for field 6 TFORM6 = '70A ' / data format of field: ASCII Character TTYPE7 = 'CAL_FILE' / label for field 7 TFORM7 = '40A ' / data format of field: ASCII Character TTYPE8 = 'CAL_CLAS' / label for field 8 TFORM8 = '3A ' / data format of field: ASCII Character TTYPE9 = 'CAL_DTYP' / label for field 9 TFORM9 = '4A ' / data format of field: ASCII Character TTYPE10 = 'CAL_CNAM' / label for field 10 TFORM10 = '20A ' / data format of field: ASCII Character TTYPE11 = 'CAL_CBD ' / label for field 11 TFORM11 = '630A70 ' / data format of field: ASCII Character TTYPE12 = 'CAL_XNO ' / label for field 12 TFORM12 = '1I ' / data format of field: 2-byte INTEGER TTYPE13 = 'CAL_VSD ' / label for field 13 TFORM13 = '10A ' / data format of field: ASCII Character TTYPE14 = 'CAL_VST ' / label for field 14 TFORM14 = '8A ' / data format of field: ASCII Character TTYPE15 = 'REF_TIME' / label for field 15 TFORM15 = '1D ' / data format of field: 8-byte DOUBLE TTYPE16 = 'CAL_QUAL' / label for field 16 TFORM16 = '1I ' / data format of field: 2-byte INTEGER TTYPE17 = 'CAL_DATE' / label for field 17 TFORM17 = '8A ' / data format of field: ASCII Character TTYPE18 = 'CAL_DESC' / label for field 18 TFORM18 = '70A ' / data format of field: ASCII Character EXTNAME = 'CIF ' / name of this extension CIFVERSN= '1992a ' / Version of CIF format HISTORY File modified by user 'jurgen' with fv on 2018-06-26T11:57:32 HISTORY File modified by user 'jurgen' with fv on 2018-06-27T21:19:16 END CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/North_0.5h irf_file.fits BCFDATAEFF_AREA NAME(North_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) ENERG(0.0050-501.19)TeV THETA(0.00-4.50)deg PHI(0-360)deg NONE NONE 2015-05-1800:00:00@é+15/05/18CTA effective area CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/North_0.5h irf_file.fits BCFDATARPSF NAME(North_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) ENERG(0.0126-199.53)TeV THETA(0.00-9.00)deg PHI(0-360)deg PSF(GAUSS) NONE 2015-05-1800:00:00@é+15/05/18CTA point spread function CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/North_0.5h irf_file.fits BCFDATAEDISP NAME(North_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) ETRUE(0.0050-501.19)TeV MIGRA(0.0000-3.00) THETA(0.00-9.00)deg PHI(0-360)deg NONE 2015-05-1800:00:00@é+15/05/18CTA energy dispersion CTA PROD2 NONE NONE ONLINE data/cta/prod2/bcf/North_0.5h irf_file.fits BCFDATABGD NAME(North_0.5h) VERSION(Prod2) CLASS(BEST) ANALYSIS(IFAE) DETX(-4.50-4.50)deg DETY(-4.50-4.50)deg ENERG(0.0126-199.53)TeV NONE NONE 2015-05-1800:00:00@é+15/05/18CTA background \ No newline at end of file diff --git a/test/test_GApplication.py b/test/test_GApplication.py index afd9e33..69c2462 100755 --- a/test/test_GApplication.py +++ b/test/test_GApplication.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib application module # -# Copyright (C) 2012-2017 Juergen Knoedlseder +# Copyright (C) 2012-2018 Juergen Knoedlseder # # 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 @@ -409,6 +409,33 @@ class Test(gammalib.GPythonTestSuite): # Return return + # Test class pickeling + def _test_pickeling(self): + """ + Test class pickeling + """ + # Set PFILES environment variable + os.environ['PFILES'] = os.environ['TEST_DATA'] + + # Perform pickeling tests of empty classes + test_support._pickeling(self, gammalib.GApplication()) + test_support._pickeling(self, gammalib.GApplicationPar()) + test_support._pickeling(self, gammalib.GApplicationPars()) + #test_support._pickeling(self, gammalib.GLog()) + + # Setup for tests + par = gammalib.GApplicationPar('Test','r','a','1.0','0.0','2.0','Dummy text') + app = gammalib.GApplication('test_GApplication', '1.1.0') + + # Perform pickeling tests of filled classes + test_support._pickeling(self, gammalib.GApplication(app)) + test_support._pickeling(self, gammalib.GApplicationPar(par)) + test_support._pickeling(self, gammalib.GApplicationPars('test_GApplication.par')) + #test_support._pickeling(self, gammalib.GLog()) + + # Return + return + # Set test functions def set(self): """ @@ -423,6 +450,7 @@ class Test(gammalib.GPythonTestSuite): self.append(self._test_pars, 'Test GApplicationPars') self.append(self._test_pars_access, 'Test GApplicationPars parameter access') self.append(self._test_pars_access, 'Test GApplicationPars slicing') + self.append(self._test_pickeling, 'Test application class pickeling') # Return return diff --git a/test/test_GFits.py b/test/test_GFits.py index 78761cd..3fd90f7 100755 --- a/test/test_GFits.py +++ b/test/test_GFits.py @@ -732,7 +732,7 @@ class Test(gammalib.GPythonTestSuite): self.append(self._test_fits_image, 'Test GFitsImage') self.append(self._test_fits_table, 'Test GFitsTable') self.append(self._test_fits_table_columns, 'Test GFitsTableCol') - self.append(self._test_pickeling, 'Test pickeling of "fits" classes') + self.append(self._test_pickeling, 'Test Fits class pickeling') # Return return diff --git a/test/test_GModel.py b/test/test_GModel.py index 222c4a3..799263e 100755 --- a/test/test_GModel.py +++ b/test/test_GModel.py @@ -118,18 +118,18 @@ class Test(gammalib.GPythonTestSuite): test_support._pickeling(self, gammalib.GModelSky()) test_support._pickeling(self, gammalib.GModelSpatialComposite()) test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst()) - #test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube()) - #test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap()) - #test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk()) - #test_support._pickeling(self, gammalib.GModelSpatialEllipticalGauss()) + test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube()) + test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap()) + test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk()) + test_support._pickeling(self, gammalib.GModelSpatialEllipticalGauss()) test_support._pickeling(self, gammalib.GModelSpatialPointSource()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialDisk()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialGauss()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMBurkert()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMEinasto()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMZhao()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileGauss()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialShell()) + test_support._pickeling(self, gammalib.GModelSpatialRadialDisk()) + test_support._pickeling(self, gammalib.GModelSpatialRadialGauss()) + test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMBurkert()) + test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMEinasto()) + test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMZhao()) + test_support._pickeling(self, gammalib.GModelSpatialRadialProfileGauss()) + test_support._pickeling(self, gammalib.GModelSpatialRadialShell()) test_support._pickeling(self, gammalib.GModelSpectralBrokenPlaw()) test_support._pickeling(self, gammalib.GModelSpectralComposite()) test_support._pickeling(self, gammalib.GModelSpectralConst()) @@ -170,6 +170,8 @@ class Test(gammalib.GPythonTestSuite): fct = gammalib.GFilename(os.environ['TEST_DATA']+'/filefunction.txt') lcrv = gammalib.GFilename(os.environ['TEST_DATA']+'/model_temporal_lightcurve.fits') pcrv = gammalib.GFilename(os.environ['TEST_DATA']+'/model_temporal_phasecurve.fits') + cube = gammalib.GFilename(os.environ['TEST_DATA']+'/test_cube.fits') + dir = gammalib.GSkyDir() # Perform pickeling tests of filled classes test_support._pickeling(self, gammalib.GModelPar('Par',2.0,5.0)) @@ -177,18 +179,18 @@ class Test(gammalib.GPythonTestSuite): test_support._pickeling(self, gammalib.GModelSky(sky)) test_support._pickeling(self, gammalib.GModelSpatialComposite(spacom)) test_support._pickeling(self, gammalib.GModelSpatialDiffuseConst(2.0)) - #test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube()) - #test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap()) - #test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk()) - #test_support._pickeling(self, gammalib.GModelSpatialEllipticalGauss()) + test_support._pickeling(self, gammalib.GModelSpatialDiffuseCube(cube, 2.0)) + test_support._pickeling(self, gammalib.GModelSpatialDiffuseMap(cube,2.0)) + test_support._pickeling(self, gammalib.GModelSpatialEllipticalDisk(dir,0.2,0.3,45.0)) + test_support._pickeling(self, gammalib.GModelSpatialEllipticalGauss(dir,0.2,0.3,45.0)) test_support._pickeling(self, gammalib.GModelSpatialPointSource(ptsrc)) - #test_support._pickeling(self, gammalib.GModelSpatialRadialDisk()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialGauss()) + test_support._pickeling(self, gammalib.GModelSpatialRadialDisk(dir,0.2)) + test_support._pickeling(self, gammalib.GModelSpatialRadialGauss(dir,0.2)) #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMBurkert()) #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMEinasto()) #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileDMZhao()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialProfileGauss()) - #test_support._pickeling(self, gammalib.GModelSpatialRadialShell()) + test_support._pickeling(self, gammalib.GModelSpatialRadialProfileGauss(dir,0.2)) + test_support._pickeling(self, gammalib.GModelSpatialRadialShell(dir,0.3,0.1)) test_support._pickeling(self, gammalib.GModelSpectralBrokenPlaw(1.0,-2.0,pivot,-2.1)) test_support._pickeling(self, gammalib.GModelSpectralComposite(specom)) test_support._pickeling(self, gammalib.GModelSpectralConst(3.0)) @@ -222,7 +224,7 @@ class Test(gammalib.GPythonTestSuite): # Append tests self.append(self._test_models_access, 'Test GModels model access') self.append(self._test_models_slicing, 'Test GModels slicing') - self.append(self._test_pickeling, 'Test pickeling of "model" classes') + self.append(self._test_pickeling, 'Test model class pickeling') # Return return diff --git a/test/test_GObservation.py b/test/test_GObservation.py index cc5adc4..72c70d5 100755 --- a/test/test_GObservation.py +++ b/test/test_GObservation.py @@ -739,7 +739,7 @@ class Test(gammalib.GPythonTestSuite): Test class pickeling """ # Perform pickeling tests of empty classes - #test_support._pickeling(self, gammalib.GCaldb()) + test_support._pickeling(self, gammalib.GCaldb()) test_support._pickeling(self, gammalib.GEbounds()) test_support._pickeling(self, gammalib.GEnergy()) test_support._pickeling(self, gammalib.GEnergies()) @@ -807,7 +807,7 @@ class Test(gammalib.GPythonTestSuite): self.append(self._test_times_slicing, 'Test GTimes slicing') self.append(self._test_photons_slicing, 'Test GPhotons slicing') self.append(self._test_observations_slicing, 'Test GObservations slicing') - self.append(self._test_pickeling, 'Test pickeling of "obs" classes') + self.append(self._test_pickeling, 'Test observation class pickeling') # Return return diff --git a/test/test_GOptimizer.py b/test/test_GOptimizer.py index 2672c9a..049d452 100755 --- a/test/test_GOptimizer.py +++ b/test/test_GOptimizer.py @@ -122,7 +122,7 @@ class Test(gammalib.GPythonTestSuite): # Append tests self.append(self._test_pars_access, 'Test GOptimizerPars parameter access') self.append(self._test_pars_slicing, 'Test GOptimizerPars slicing') - self.append(self._test_pickeling, 'Test pickeling of "opt" classes') + self.append(self._test_pickeling, 'Test optimizer class pickeling') # Return return diff --git a/test/test_GSky.py b/test/test_GSky.py index 8e55e41..1b5c735 100755 --- a/test/test_GSky.py +++ b/test/test_GSky.py @@ -556,14 +556,55 @@ class Test(gammalib.GPythonTestSuite): Test class pickeling """ # Perform pickeling tests of empty classes + test_support._pickeling(self, gammalib.GHealpix()) + test_support._pickeling(self, gammalib.GHorizDir()) test_support._pickeling(self, gammalib.GSkyDir()) + test_support._pickeling(self, gammalib.GSkyMap()) + test_support._pickeling(self, gammalib.GSkyPixel()) + test_support._pickeling(self, gammalib.GSkyRegionCircle()) + test_support._pickeling(self, gammalib.GSkyRegionMap()) + test_support._pickeling(self, gammalib.GSkyRegions()) + test_support._pickeling(self, gammalib.GWcsAIT()) + test_support._pickeling(self, gammalib.GWcsAZP()) + test_support._pickeling(self, gammalib.GWcsCAR()) + test_support._pickeling(self, gammalib.GWcsGLS()) + test_support._pickeling(self, gammalib.GWcsMER()) + test_support._pickeling(self, gammalib.GWcsMOL()) + test_support._pickeling(self, gammalib.GWcsSFL()) + test_support._pickeling(self, gammalib.GWcsSIN()) + test_support._pickeling(self, gammalib.GWcsSTG()) + test_support._pickeling(self, gammalib.GWcsTAN()) # Setup test - dir = gammalib.GSkyDir() + dir = gammalib.GSkyDir() dir.lb_deg(1.0, 2.0) + map = gammalib.GFilename(os.environ['TEST_DATA']+'/test_cube.fits') + regions = gammalib.GSkyRegions() + regions.append(gammalib.GSkyRegionCircle(dir,2.0)) + regions.append(gammalib.GSkyRegionMap(map)) + horizdir = gammalib.GHorizDir() + horizdir.altaz_deg(2.0, 3.0) # Perform pickeling tests of filled classes + test_support._pickeling(self, gammalib.GHealpix(4)) + test_support._pickeling(self, horizdir) test_support._pickeling(self, gammalib.GSkyDir(dir)) + test_support._pickeling(self, gammalib.GSkyMap(map)) + test_support._pickeling(self, gammalib.GSkyPixel(1.0)) + test_support._pickeling(self, gammalib.GSkyPixel(2.0,3.0)) + test_support._pickeling(self, gammalib.GSkyRegionCircle(dir,2.0)) + test_support._pickeling(self, gammalib.GSkyRegionMap(map)) + test_support._pickeling(self, gammalib.GSkyRegions(regions)) + test_support._pickeling(self, gammalib.GWcsAIT('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsAZP('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsCAR('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsGLS('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsMER('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsMOL('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsSFL('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsSIN('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsSTG('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) + test_support._pickeling(self, gammalib.GWcsTAN('GAL',1.0,2.0,1.0,1.0,0.1,0.1)) # Return return @@ -592,7 +633,7 @@ class Test(gammalib.GPythonTestSuite): self.append(self._test_skymap_tan, 'Test TAN projection map') self.append(self._test_regions_access, 'Test GSkyRegions region access') self.append(self._test_regions_slicing, 'Test GSkyRegions slicing') - self.append(self._test_pickeling, 'Test pickeling of "sky" classes') + self.append(self._test_pickeling, 'Test sky class pickeling') # Return return diff --git a/test/test_GSupport.py b/test/test_GSupport.py index b38c035..d179b3c 100755 --- a/test/test_GSupport.py +++ b/test/test_GSupport.py @@ -324,7 +324,7 @@ class Test(gammalib.GPythonTestSuite): self.append(self._test_url_string, 'Test GUrlString') self.append(self._test_filename, 'Test GFilename') self.append(self._test_csv, 'Test GCsv') - self.append(self._test_pickeling, 'Test pickeling of "support" classes') + self.append(self._test_pickeling, 'Test support class pickeling') # Return return diff --git a/test/test_GXml.py b/test/test_GXml.py index 9599fbf..69e52c1 100755 --- a/test/test_GXml.py +++ b/test/test_GXml.py @@ -196,7 +196,7 @@ class Test(gammalib.GPythonTestSuite): self.append(self._test_xml_slicing, 'Test GXml slicing') self.append(self._test_elements_access, 'Test GXmlElement parameter access') self.append(self._test_elements_slicing, 'Test GXmlElement slicing') - self.append(self._test_pickeling, 'Test pickeling of "xml" classes') + self.append(self._test_pickeling, 'Test Xml class pickeling') # Return return diff --git a/test/test_GXspec.py b/test/test_GXspec.py index e9c0878..245bd00 100755 --- a/test/test_GXspec.py +++ b/test/test_GXspec.py @@ -1,7 +1,7 @@ # ========================================================================== # This module performs unit tests for the GammaLib xspec module. # -# Copyright (C) 2013-2015 Juergen Knoedlseder +# Copyright (C) 2013-2018 Juergen Knoedlseder # # 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 @@ -18,6 +18,7 @@ # # ========================================================================== import gammalib +import test_support # ==================================== # @@ -38,31 +39,15 @@ class Test(gammalib.GPythonTestSuite): # Return return - # Set test functions - def set(self): - """ - Set all test functions. - """ - # Set test name - self.name("xspec") - - # Append tests - self.append(self.test_pha, "Test GPha") - self.append(self.test_arf, "Test GArf") - self.append(self.test_rmf, "Test GRmf") - - # Return - return - # Test GPha class - def test_pha(self): + def _test_pha(self): """ - Test GPha class. + Test GPha class """ # Allocate GPha object and check its size nmeasured = 10 - emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), - gammalib.GEnergy(10.0, "TeV")) + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, 'TeV'), + gammalib.GEnergy(10.0, 'TeV')) pha = gammalib.GPha(emeasured) self.test_value(pha.size(), nmeasured) @@ -75,14 +60,14 @@ class Test(gammalib.GPythonTestSuite): return # Test GArf class - def test_arf(self): + def _test_arf(self): """ - Test GArf class. + Test GArf class """ # Allocate GArf object and check its size nmeasured = 10 - emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), - gammalib.GEnergy(10.0, "TeV")) + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, 'TeV'), + gammalib.GEnergy(10.0, 'TeV')) arf = gammalib.GArf(emeasured) self.test_value(arf.size(), nmeasured) @@ -95,17 +80,17 @@ class Test(gammalib.GPythonTestSuite): return # Test GRmf class - def test_rmf(self): + def _test_rmf(self): """ - Test GRmf class. + Test GRmf class """ # Allocate GRmf object and check its size ntrue = 20 nmeasured = 10 - etrue = gammalib.GEbounds(ntrue, gammalib.GEnergy(1.0, "TeV"), - gammalib.GEnergy(10.0, "TeV")) - emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, "TeV"), - gammalib.GEnergy(10.0, "TeV")) + etrue = gammalib.GEbounds(ntrue, gammalib.GEnergy(1.0, 'TeV'), + gammalib.GEnergy(10.0, 'TeV')) + emeasured = gammalib.GEbounds(nmeasured, gammalib.GEnergy(1.0, 'TeV'), + gammalib.GEnergy(10.0, 'TeV')) rmf = gammalib.GRmf(etrue, emeasured) self.test_value(rmf.size(), ntrue*nmeasured) self.test_value(rmf.ntrue(), ntrue) @@ -118,3 +103,47 @@ class Test(gammalib.GPythonTestSuite): # Return return + + # Test class pickeling + def _test_pickeling(self): + """ + Test class pickeling + """ + # Perform pickeling tests of empty classes + test_support._pickeling(self, gammalib.GArf()) + test_support._pickeling(self, gammalib.GPha()) + test_support._pickeling(self, gammalib.GRmf()) + + # Setup test + emin = gammalib.GEnergy(1.0, 'TeV') + emax = gammalib.GEnergy(10.0, 'TeV') + etrue = gammalib.GEbounds(2, emin, emax) + ereco = gammalib.GEbounds(2, emin, emax) + arf = gammalib.GArf(etrue) + pha = gammalib.GPha(ereco) + rmf = gammalib.GRmf(etrue, ereco) + + # Perform pickeling tests of filled classes + test_support._pickeling(self, gammalib.GArf(arf)) + test_support._pickeling(self, gammalib.GPha(pha)) + test_support._pickeling(self, gammalib.GRmf(rmf)) + + # Return + return + + # Set test functions + def set(self): + """ + Set all test functions. + """ + # Set test name + self.name('xspec') + + # Append tests + self.append(self._test_pha, 'Test GPha') + self.append(self._test_arf, 'Test GArf') + self.append(self._test_rmf, 'Test GRmf') + self.append(self._test_pickeling, 'Test Xspec class pickeling') + + # Return + return diff --git a/test/test_support.py b/test/test_support.py index b6596c9..96397b1 100755 --- a/test/test_support.py +++ b/test/test_support.py @@ -17,6 +17,7 @@ # along with this program. If not, see . # # ========================================================================== +import sys import pickle @@ -267,7 +268,8 @@ def _pickeling(testsuite, object): 'Check pickled dump of "%s\n%s\n%s"' % (name, str(object), str(obj))) testsuite.test_try_success() - except Exception as e: + except: + _, e, _ = sys.exc_info() testsuite.test_try_failure('Error in pickeling "%s" (%s).' % (name, str(e)))