diff --git a/.gitignore b/.gitignore index e4ac738..6971cc5 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,7 @@ src/ctselect/ctselect src/ctskymap/ctskymap src/ctexpcube/ctexpcube src/ctpsfcube/ctpsfcube +src/ctbkgcube/ctbkgcube src/ctcubemask/ctcubemask test/pfiles/ test/*.fits diff --git a/ChangeLog b/ChangeLog index 8595f65..ec35376 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2014-07-20 Juergen Knoedlseder +2014-07-22 Juergen Knoedlseder * Version 0.8.0 released ======================== @@ -6,7 +6,8 @@ Adapt to GammaLib 0.9.0 interface ctbin now always merges event lists into a single counts cube Add ctexpcube tool (generates exposure cube) - Add ctpsfcube tool (generated PSF cube) + Add ctpsfcube tool (generates PSF cube) + Add ctbkgcube tool (generates background cube) Add ctcubemask tool (masks event bins in event cube) Support energy dispersion in ctobssim, ctlike and ctmodel Correct ctobssim for thread safety diff --git a/NEWS b/NEWS index 4da0e53..8c66f8a 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-08-00 Author(s) : Juergen Knoedlseder -20 July 2014 +22 July 2014 1. Introduction @@ -97,7 +97,15 @@ definition file. The cube definition may be taken from a counts cube or may be specified by user parameters. -12. ctcubemask - CTA cube filtering +12. ctbkgcube - CTA background cube generation +---------------------------------------------- +The first version of the ctbkgcube tool is included in the release. +ctbkgcube computes the background cube for an observation definition +file. The cube definition may be taken from a counts cube or may be +specified by user parameters. + + +13. ctcubemask - CTA cube filtering ----------------------------------- The first version of the ctcubemask tool is included in the release. ctcubemask allows filtering of bins in a counts cube by setting the @@ -105,12 +113,12 @@ bin content to -1. Filtering can be done by energy, for a circular Region of Interest (ROI) or using ds9 exclusion regions. -13. Examples +14. Examples ------------ None -14. Scripts +15. Scripts ----------- Add logL and event statistics to cspull output file. @@ -119,11 +127,11 @@ Convert all tabs into spaces. The obsutils script has now been moved into the ctools module namespace. -15. caldb +16. caldb --------- None -16. models +17. models ---------- None diff --git a/pyext/ctbkgcube.i b/pyext/ctbkgcube.i new file mode 100644 index 0000000..d93b533 --- /dev/null +++ b/pyext/ctbkgcube.i @@ -0,0 +1,68 @@ +/*************************************************************************** + * ctbkgcube - CTA background cube tool * + * ----------------------------------------------------------------------- * + * copyright (C) 2014 by Chia-Chun Lu * + * ----------------------------------------------------------------------- * + * * + * 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 * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + * * + ***************************************************************************/ +/** + * @file ctbkgcube.i + * @brief CTA background cube tool definition + * @author Chia-Chun Lu + */ + +%{ +/* Put headers and other declarations here that are needed for compilation */ +#include "ctbkgcube.hpp" +#include "GTools.hpp" +%} + +/***********************************************************************//** + * @class ctbkgcube + * + * @brief CTA background cube tool + ***************************************************************************/ +class ctbkgcube : public GApplication { + +public: + // Constructors and destructors + ctbkgcube(void); + explicit ctbkgcube(const GObservations& obs); + ctbkgcube(int argc, char *argv[]); + ctbkgcube(const ctbkgcube& app); + virtual ~ctbkgcube(void); + + // Methods + void clear(void); + void execute(void); + void run(void); + void save(void); + const GObservations& obs(void) const; + void get_parameters(void); + void get_obs(void); + void get_ebounds(void); + void set_from_cntmap(const std::string& filename); + void fill_cube(GCTAObservation* obs); +}; + +/***********************************************************************//** + * @brief CTA background cube tool Python extension + ***************************************************************************/ +%extend ctbkgcube { + ctbkgcube copy() { + return (*self); + } +} diff --git a/pyext/ctools/ctools.i b/pyext/ctools/ctools.i index a51c413..956fa6d 100755 --- a/pyext/ctools/ctools.i +++ b/pyext/ctools/ctools.i @@ -53,4 +53,5 @@ %include "ctskymap.i" %include "ctexpcube.i" %include "ctpsfcube.i" +%include "ctbkgcube.i" %include "ctcubemask.i" diff --git a/src/ctbkgcube/ctbkgcube.cpp b/src/ctbkgcube/ctbkgcube.cpp index 65a19f4..50ce350 100644 --- a/src/ctbkgcube/ctbkgcube.cpp +++ b/src/ctbkgcube/ctbkgcube.cpp @@ -31,11 +31,11 @@ #include #include "ctbkgcube.hpp" #include "GTools.hpp" -#include "GWcs.hpp" /* __ Method name definitions ____________________________________________ */ -#define G_GET_EBOUNDS "ctbkgcube::get_ebounds()" #define G_GET_PARAMETERS "ctbkgcube::get_parameters()" +#define G_GET_OBS "ctbkgcube::get_obs()" +#define G_GET_EBOUNDS "ctbkgcube::get_ebounds()" #define G_SET_FROM_CNTMAP "ctbkgcube::set_from_cntmap(std::string&)" /* __ Debug definitions __________________________________________________ */ @@ -230,7 +230,7 @@ void ctbkgcube::execute(void) * * This method reads the task parameters from the parfile, sets up the * observation container, loops over all CTA observations in the container - * and generates an background cube from the CTA observations. + * and generates a background cube from the CTA observations. ***************************************************************************/ void ctbkgcube::run(void) { @@ -248,18 +248,6 @@ void ctbkgcube::run(void) log << std::endl; } - // Set energy dispersion flag for all CTA observations and save old - // values in save_edisp vector - std::vector save_edisp; - save_edisp.assign(m_obs.size(), false); - for (int i = 0; i < m_obs.size(); ++i) { - GCTAObservation* obs = dynamic_cast(m_obs[i]); - if (obs != NULL) { - save_edisp[i] = obs->response()->apply_edisp(); - obs->response()->apply_edisp(m_apply_edisp); - } - } - // Write observation(s) into logger if (logTerse()) { log << std::endl; @@ -275,83 +263,149 @@ void ctbkgcube::run(void) // Write header if (logTerse()) { log << std::endl; - log.header1("Generate background cube"); + log.header1("Prepare model"); } - // If there are no models associated with the observations then - // load now the model definition from the XML file - if (m_obs.models().size() == 0) { - m_bgmdl = (*this)["bgmdl"].filename(); - m_obs.models(GModels(m_bgmdl)); - - // TODO: throw a message when no background definition file is given + // Copy models from observation container + m_bkgmdl = m_obs.models(); + + // Remove all model that are not CTA background models from the + // container + int num = m_bkgmdl.size(); + for (int i = num-1; i >= 0; --i) { + + // Flag removal + bool remove = true; + + // Do we have a CTA, HESS or VERITAS specific model? + if (m_bkgmdl[i]->is_valid("CTA", "") || + m_bkgmdl[i]->is_valid("HESS", "") || + m_bkgmdl[i]->is_valid("VERITAS", "")) { + + // Do we have a background model? + if (dynamic_cast(m_bkgmdl[i]) != NULL) { + + // ... then keep model + remove = false; + + } // endif: had a background model + } // endif: had a CTA, HESS or VERITAS model + + // Log results + if (logTerse()) { + if (remove) { + log << gammalib::parformat("Remove model"); + } + else { + log << gammalib::parformat("Keep model"); + } + log << m_bkgmdl[i]->name(); + log << " "; + log << m_bkgmdl[i]->type(); + log << "("; + log << m_bkgmdl[i]->instruments(); + log << ")"; + log << std::endl; + } + + // Remove model if requested + if (remove) { + m_bkgmdl.remove(i); + } + + } // endfor: looped over all background models + + // Write header + if (logTerse()) { + log << std::endl; + log.header1("Generate background cube"); } + // Initialise observation counter + int n_observations = 0; + // Loop over all observations in the container for (int i = 0; i < m_obs.size(); ++i) { // Get CTA observation GCTAObservation* obs = dynamic_cast(m_obs[i]); - - // Fill background cube - fill_cube(obs, m_obs.models()); - - } - // Restore energy dispersion flag for all CTA observations - for (int i = 0; i < m_obs.size(); ++i) { - GCTAObservation* obs = dynamic_cast(m_obs[i]); + // Continue only if observation is a CTA observation if (obs != NULL) { - obs->response()->apply_edisp(save_edisp[i]); - } + + // Write header for observation + if (logTerse()) { + if (obs->name().length() > 1) { + log.header3("Observation "+obs->name()); + } + else { + log.header3("Observation "+gammalib::str(i)); + } + } + + // Increment number of observations + n_observations++; + + // Fill the cube + fill_cube(obs); + + } // endif: CTA observation found + + } // endfor: looped over observations + + // Log results + if (logTerse()) { + log << gammalib::parformat("Number of observations"); + log << n_observations << std::endl; } // Return return; } + /***********************************************************************//** * @brief Generate background cube * - * @param[in] obs CTA observation pointer. - * @param[in] models Model container. - * + * @param[in] obs Pointer to CTA observation. * + * Fills ***************************************************************************/ -void ctbkgcube::fill_cube(GCTAObservation* obs, const GModels& models) +void ctbkgcube::fill_cube(GCTAObservation* obs) { // Continue only if observation pointer is valid if (obs != NULL) { - obs->events(m_bkgcube); - GCTAEventCube* cube = - const_cast(dynamic_cast(obs->events())); // Initialise statistics double sum = 0.0; - GCTAEventBin* bin = (*cube)[10000]; - std::cout << bin->counts() << std::endl; - // Loop over all events in counts map - for (int i = 0; i < cube->size(); ++i) { - + + // Set GTI of actual observations as the GTI of the event cube + m_bkgcube.gti(obs->events()->gti()); + + // Loop over all bins in background cube + for (int i = 0; i < m_bkgcube.size(); ++i) { + // Get event bin - GCTAEventBin* bin = (*cube)[i]; + GCTAEventBin* bin = m_bkgcube[i]; // Compute model value for event bin double model = - models.eval(*(const_cast(bin)), *obs) * + m_bkgmdl.eval(*(const_cast(bin)), *obs) * bin->size(); - - // Store value - bin->counts( bin->counts() + model ); - - // Sum all events - sum += model; + // Add existing number of counts + model += bin->counts(); + + // Store cumulated value + bin->counts(model); + + // Sum all events + sum += model; } - + // Log results if (logTerse()) { - log << gammalib::parformat("Model events in cube"); + log << gammalib::parformat("Background events in cube"); log << sum << std::endl; } @@ -361,9 +415,11 @@ void ctbkgcube::fill_cube(GCTAObservation* obs, const GModels& models) return; } + /***********************************************************************//** * @brief Save background cube * + * Save the background cube into the file specified by the outfile parameter. ***************************************************************************/ void ctbkgcube::save(void) { @@ -373,11 +429,26 @@ void ctbkgcube::save(void) log.header1("Save background cube"); } + // Create energies container from energy boundaries + GEnergies energies; + for (int i = 0; i < m_ebounds.size(); ++i) { + energies.append(m_ebounds.elogmean(i)); + } + // Get output filename - m_outfile = (*this)["outfile"].filename(); + std::string filename = (*this)["outfile"].filename(); + + // Create empty FITS file + GFits fits; - // Save background cube - m_map.save(m_outfile, clobber()); + // Write background cube + m_bkgcube.map().write(fits); + + // Write energies + energies.write(fits); + + // Save FITS file + fits.saveto(filename, clobber()); // Return return; @@ -387,32 +458,43 @@ void ctbkgcube::save(void) /***********************************************************************//** * @brief Get application parameters * + * @exception GException::invalid_value + * No background model definition XML file specified. + * * Get all task parameters from parameter file or (if required) by querying * the user. The parameters are read in the correct order. - * - * @todo Setup background cube from counts map ***************************************************************************/ void ctbkgcube::get_parameters(void) { - // If we do not have any observations in the container then get an - // input file name or observation descriptor file + // If we do not have any observations in the container then load them + // using the "infile" parameter if (m_obs.size() == 0) { get_obs(); } - // Make sure that response is set - set_response(); - - // Read energy dispersion flag - m_apply_edisp = (*this)["edisp"].boolean(); + // If there are no models associated with the observations then load now + // the model definition from the XML file + if (m_obs.models().size() == 0) { + if ((*this)["bkgmdl"].is_undefined()) { + std::string msg = "No background model definition XML file " + "specified. Please set the \"bkgmdl\" parameter " + "to the background model definition XML " + "filename."; + throw GException::invalid_value(G_GET_PARAMETERS, msg); + } + std::string bkgmdl = (*this)["bkgmdl"].filename(); + GModels models(bkgmdl); + m_obs.models(models); + } // If no counts map is specified then setup the background cube from // the user parameters std::string cntmap = (*this)["cntmap"].filename(); - if ((cntmap == "NONE") || (gammalib::strip_whitespace(cntmap) == "")) { + if ((gammalib::toupper(cntmap) == "NONE") || + (gammalib::strip_whitespace(cntmap) == "")) { // Get user parameters for counts map definition - std::string wcs = (*this)["proj"].string(); + std::string proj = (*this)["proj"].string(); std::string coordsys = (*this)["coordsys"].string(); double xref = (*this)["xref"].real(); double yref = (*this)["yref"].real(); @@ -423,21 +505,16 @@ void ctbkgcube::get_parameters(void) // Get energy definition get_ebounds(); - // Define background cube - m_map = GSkymap(wcs, coordsys, xref, yref, - -binsz, binsz, nxpix, nypix, - m_ebounds.size()); - GGti gti = m_obs[0]->events()->gti(); - m_bkgcube = GCTAEventCube(m_map, m_ebounds, gti); - - // Loop over all events in background cube and - // set all pixels to 0 - for (int i = 0; i < m_bkgcube.size(); ++i) - { - // Get event bin - GCTAEventBin* bin = m_bkgcube[i]; - bin->counts(0); - } + // Define skymap for background cube + GSkymap map(proj, coordsys, xref, yref, + -binsz, binsz, nxpix, nypix, + m_ebounds.size()); + + // Allocate background cube using a dummy GTI + GGti gti; + gti.append(GTime(0.0), GTime(1.0)); // Dummy GTI + m_bkgcube = GCTAEventCube(map, m_ebounds, gti); + } // ... otherwise setup the background cube from the counts map @@ -450,7 +527,7 @@ void ctbkgcube::get_parameters(void) // Read output filename (if needed) if (m_read_ahead) { - m_outfile = (*this)["outfile"].filename(); + std::string filename = (*this)["outfile"].filename(); } // Return @@ -461,6 +538,10 @@ void ctbkgcube::get_parameters(void) /***********************************************************************//** * @brief Get observation definition * + * @exception GException::invalid_value + * No event list, counts cube or observation definition file + * specified. + * * Get observation definition from the user parameters. ***************************************************************************/ void ctbkgcube::get_obs(void) @@ -468,6 +549,15 @@ void ctbkgcube::get_obs(void) // Get input filename std::string filename = (*this)["infile"].filename(); + // Check whether infile parameter is undefined + if (gammalib::toupper(filename) == "NONE") { + std::string msg = "No event list, counts cube or observation definition " + "file specified. Please set the \"infile\" parameter " + "to either an event list filename, a counts cube " + "filename or an observation definition filename."; + throw GException::invalid_value(G_GET_OBS, msg); + } + // Try first to open as FITS file try { @@ -479,7 +569,6 @@ void ctbkgcube::get_obs(void) // Append CTA observation to container m_obs.append(obs); - } @@ -497,59 +586,11 @@ void ctbkgcube::get_obs(void) /***********************************************************************//** - * @brief Set observation response - * - * Set response for all observations that so have no response. - ***************************************************************************/ -void ctbkgcube::set_response(void) -{ - // Loop over all observations - for (int i = 0; i < m_obs.size(); ++i) { - - // Is this observation a CTA observation? - GCTAObservation* obs = dynamic_cast(m_obs[i]); - - // Yes ... - if (obs != NULL) { - - // Set response if we don't have one - if (!obs->hasresponse()) { - - // Load response information - std::string database = (*this)["caldb"].string(); - std::string irf = (*this)["irf"].string(); - - // Set calibration database. If specified parameter is a - // directory then use this as the pathname to the calibration - // database. Otherwise interpret this as the instrument name, - // the mission being "cta" - GCaldb caldb; - if (gammalib::dir_exists(database)) { - caldb.rootdir(database); - } - else { - caldb.open("cta", database); - } - - // Set reponse - obs->response(irf, caldb); - - } // endif: observation already has a response - - } // endif: observation was a CTA observation - - } // endfor: looped over all observations - - // Return - return; -} - - -/***********************************************************************//** * @brief Get energy boundaries from parameters * * @exception GException::invalid_value - * Invalid extension name encountered. + * Energy bin definition file not defined or invalid extension + * name encountered. * * Get the energy boundaries from the user parameters. ***************************************************************************/ @@ -561,10 +602,18 @@ void ctbkgcube::get_ebounds(void) // If we have the binning given by a file then try to get the boundaries // from that file if (ebinalg == "FILE") { - + // Get filename std::string filename = (*this)["ebinfile"].filename(); + // Check whether infile parameter is undefined + if (gammalib::toupper(filename) == "NONE") { + std::string msg = "No energy bin definition file specified. " + "Please set the \"ebinfile\" parameter to a " + "file containing the energy bin definition."; + throw GException::invalid_value(G_GET_EBOUNDS, msg); + } + // Open fits file to check which extension is given GFits file(filename); @@ -655,22 +704,14 @@ void ctbkgcube::set_from_cntmap(const std::string& filename) // Get energy definition m_ebounds = cube->ebounds(); - - - // Define background cube - m_map = GSkymap(proj, coordsys, xref, yref, - dx, dy, nx, ny, - m_ebounds.size()); - GGti gti = m_obs[0]->events()->gti(); - m_bkgcube = GCTAEventCube(m_map, m_ebounds, gti); - // Loop over all events in background cube and - // set all pixels to 0 - for (int i = 0; i < m_bkgcube.size(); ++i) - { - // Get event bin - GCTAEventBin* bin = m_bkgcube[i]; - bin->counts(0); - } + + // Define skymap for background cube + GSkymap map(proj, coordsys, xref, yref, + dx, dy, nx, ny, + m_ebounds.size()); + + // Allocate background cube + m_bkgcube = GCTAEventCube(map, m_ebounds, obs.events()->gti()); } // endif: WCS projection was valid @@ -706,14 +747,10 @@ void ctbkgcube::set_from_cntmap(const std::string& filename) void ctbkgcube::init_members(void) { // Initialise members - m_outfile.clear(); - m_apply_edisp = false; - - // Initialise protected members m_read_ahead = false; m_obs.clear(); m_bkgcube.clear(); - m_map.clear(); + m_bkgmdl.clear(); m_ebounds.clear(); // Set logger properties @@ -731,15 +768,11 @@ void ctbkgcube::init_members(void) ***************************************************************************/ void ctbkgcube::copy_members(const ctbkgcube& app) { - // Copy attributes - m_outfile = app.m_outfile; - m_apply_edisp = app.m_apply_edisp; - - // Copy protected members + // Copy members m_read_ahead = app.m_read_ahead; m_obs = app.m_obs; m_bkgcube = app.m_bkgcube; - m_map = app.m_map; + m_bkgmdl = app.m_bkgmdl; m_ebounds = app.m_ebounds; // Return diff --git a/src/ctbkgcube/ctbkgcube.hpp b/src/ctbkgcube/ctbkgcube.hpp index cb69e80..e488e19 100644 --- a/src/ctbkgcube/ctbkgcube.hpp +++ b/src/ctbkgcube/ctbkgcube.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbkgcube - CTA background cube tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Juergen Knoedlseder * + * copyright (C) 2014 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -55,36 +55,42 @@ public: ctbkgcube& operator=(const ctbkgcube& app); // Methods - void clear(void); - void execute(void); - void run(void); - void save(void); - GObservations& obs(void) { return m_obs; } - void get_parameters(void); - void get_obs(void); - void set_response(void); - void get_ebounds(void); - void set_from_cntmap(const std::string& filename); - void fill_cube(GCTAObservation* obs, const GModels& models); + void clear(void); + void execute(void); + void run(void); + void save(void); + const GObservations& obs(void) const; + void get_parameters(void); + void get_obs(void); + void get_ebounds(void); + void set_from_cntmap(const std::string& filename); + void fill_cube(GCTAObservation* obs); protected: // Protected methods - void init_members(void); - void copy_members(const ctbkgcube& app); - void free_members(void); - - // User parameters - std::string m_outfile; //!< Output background cube file - std::string m_bgmdl; //!< background model - bool m_apply_edisp; //!< Apply energy dispersion? + void init_members(void); + void copy_members(const ctbkgcube& app); + void free_members(void); // Protected members bool m_read_ahead; //!< Read ahead parameters GObservations m_obs; //!< Observation container GCTAEventCube m_bkgcube; //!< Background cube - GSkymap m_map; //!< Background map + GModels m_bkgmdl; //!< CTA background models GEbounds m_ebounds; //!< Energy boundaries - }; + +/***********************************************************************//** + * @brief Return observation container + * + * @return Observation container. + ***************************************************************************/ +inline +const GObservations& ctbkgcube::obs(void) const +{ + // Return observation container + return m_obs; +} + #endif /* CTBKGCUBE_HPP */ diff --git a/src/ctbkgcube/ctbkgcube.par b/src/ctbkgcube/ctbkgcube.par index e88d32e..1f89a76 100644 --- a/src/ctbkgcube/ctbkgcube.par +++ b/src/ctbkgcube/ctbkgcube.par @@ -4,26 +4,23 @@ # # # ------------------------------------------------------------------------- # # # -# File: ctexpcube.par # +# File: ctbkgcube.par # # Version: 00-01-00 # # # -# Author: Juergen Knoedlseder # -# Jurgen.Knodlseder@irap.omp.eu # -# IRAP # +# Author: Chia-Chun Lu # +# c.lu@mpi-hd.mpg.de # +# MPIK # # # -# Purpose: Parameter file for the ctexpcube application # +# Purpose: Parameter file for the ctbkgcube application # # # ############################################################################# # # General parameters #=================== -infile, f, a, "NONE",,, "Observation definition file" -bgmdl, f, a, "NONE",,, "Background definition file" -cntmap, f, a, "NONE",,, "Counts map for background cube definition" +infile, f, a, "NONE",,, "Event list, counts cube or observation definition file" +bkgmdl, f, a, "NONE",,, "Background model XML file" +cntmap, f, a, "NONE",,, "Counts cube for background cube definition" outfile, f, a, "bkgcube.fits",,, "Output background cube file" -caldb, s, a, "dummy",,, "Calibration database" -irf, s, a, "cta_dummy_irf",,, "Instrument response function" -edisp, b, h, no,,, "Apply energy dispersion?" # # Energy binning parameters #========================== @@ -50,4 +47,4 @@ chatter, i, h, 2,0,4, "Chattiness of output" clobber, b, h, yes,,, "Overwrite existing output files with new output files?" debug, b, h, no,,, "Debugging mode activated" mode, s, h, "ql",,, "Mode of automatic parameters" -logfile, f, h, "ctexpcube.log",,, "Log filename" +logfile, f, h, "ctbkgcube.log",,, "Log filename" diff --git a/src/ctbkgcube/main.cpp b/src/ctbkgcube/main.cpp index ea447b7..93c4277 100644 --- a/src/ctbkgcube/main.cpp +++ b/src/ctbkgcube/main.cpp @@ -1,7 +1,7 @@ /*************************************************************************** - * ctbkgcube - CTA exposure cube tool * + * ctbkgcube - CTA background cube tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Juergen Knoedlseder * + * copyright (C) 2014 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * diff --git a/src/ctexpcube/ctexpcube.par b/src/ctexpcube/ctexpcube.par index 4560351..76fd8a6 100644 --- a/src/ctexpcube/ctexpcube.par +++ b/src/ctexpcube/ctexpcube.par @@ -17,7 +17,7 @@ # # General parameters #=================== -infile, f, a, "NONE",,, "Observation definition file" +infile, f, a, "NONE",,, "Event list, counts cube or observation definition file" cntmap, f, a, "NONE",,, "Counts map for exposure cube definition" outfile, f, a, "expcube.fits",,, "Output exposure cube file" caldb, s, a, "dummy",,, "Calibration database" diff --git a/src/ctpsfcube/ctpsfcube.par b/src/ctpsfcube/ctpsfcube.par index 8a899f8..22cb4ef 100644 --- a/src/ctpsfcube/ctpsfcube.par +++ b/src/ctpsfcube/ctpsfcube.par @@ -17,7 +17,7 @@ # # General parameters #=================== -infile, f, a, "NONE",,, "Observation definition file" +infile, f, a, "NONE",,, "Event list, counts cube or observation definition file" cntmap, f, a, "NONE",,, "Counts map for exposure cube definition" outfile, f, a, "psfcube.fits",,, "Output exposure cube file" caldb, s, a, "dummy",,, "Calibration database" diff --git a/test/test_ctbin.py b/test/test_ctbin.py index e91d2dd..3027938 100755 --- a/test/test_ctbin.py +++ b/test/test_ctbin.py @@ -22,9 +22,9 @@ import gammalib import ctools -# ============================ # -# Test class for ctobssim tool # -# ============================ # +# ========================= # +# Test class for ctbin tool # +# ========================= # class Test(gammalib.GPythonTestSuite): """ Test class for ctbin tool. diff --git a/test/test_ctbkgcube.py b/test/test_ctbkgcube.py new file mode 100755 index 0000000..6c9b27d --- /dev/null +++ b/test/test_ctbkgcube.py @@ -0,0 +1,101 @@ +#! /usr/bin/env python +# ========================================================================== +# This scripts performs unit tests for the ctbkgcube tool. +# +# Copyright (C) 2014 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# ========================================================================== +import gammalib +import ctools + + +# ============================= # +# Test class for ctbkgcube tool # +# ============================= # +class Test(gammalib.GPythonTestSuite): + """ + Test class for ctbkgcube tool. + """ + # Constructor + def __init__(self): + """ + Constructor. + """ + # Call base class constructor + gammalib.GPythonTestSuite.__init__(self) + + # Set members + self.events_name = "data/crab_events.fits" + self.bkg_model = "data/crab.xml" + + # Return + return + + # Set test functions + def set(self): + """ + Set all test functions. + """ + # Set test name + self.name("ctbkgcube") + + # Append tests + self.append(self.test_functional, "Test ctbkgcube functionality") + + # Return + return + + # Test ctbkgcube functionnality + def test_functional(self): + """ + Test ctbkgcube functionnality. + """ + # Set-up ctbkgcube + bkgcube = ctools.ctbkgcube() + bkgcube["infile"].filename(self.events_name) + bkgcube["bkgmdl"].filename(self.bkg_model) + bkgcube["cntmap"].filename("NONE") + bkgcube["outfile"].filename("psfcube.fits") + bkgcube["ebinalg"].string("LOG") + bkgcube["emin"].real(0.1) + bkgcube["emax"].real(100.0) + bkgcube["enumbins"].integer(20) + bkgcube["nxpix"].integer(10) + bkgcube["nypix"].integer(10) + bkgcube["binsz"].real(0.4) + bkgcube["coordsys"].string("CEL") + bkgcube["proj"].string("CAR") + bkgcube["xref"].real(83.63) + bkgcube["yref"].real(22.01) + + # Run tool + self.test_try("Run ctbkgcube") + try: + bkgcube.run() + self.test_try_success() + except: + self.test_try_failure("Exception occured in ctbkgcube.") + + # Save background cube + self.test_try("Save background cube") + try: + bkgcube.save() + self.test_try_success() + except: + self.test_try_failure("Exception occured in saving background cube.") + + # Return + return diff --git a/test/test_ctcubemask.py b/test/test_ctcubemask.py index fdcea06..300ab5b 100755 --- a/test/test_ctcubemask.py +++ b/test/test_ctcubemask.py @@ -22,9 +22,9 @@ import gammalib import ctools -# ============================ # -# Test class for ctobssim tool # -# ============================ # +# ============================== # +# Test class for ctcubemask tool # +# ============================== # class Test(gammalib.GPythonTestSuite): """ Test class for ctcubemask tool. diff --git a/test/test_ctexpcube.py b/test/test_ctexpcube.py index 9a43fab..d2a55b1 100755 --- a/test/test_ctexpcube.py +++ b/test/test_ctexpcube.py @@ -22,9 +22,9 @@ import gammalib import ctools -# ============================ # -# Test class for ctobssim tool # -# ============================ # +# ============================= # +# Test class for ctexpcube tool # +# ============================= # class Test(gammalib.GPythonTestSuite): """ Test class for ctexpcube tool. diff --git a/test/test_ctlike.py b/test/test_ctlike.py index 0e48c3b..1f743fa 100755 --- a/test/test_ctlike.py +++ b/test/test_ctlike.py @@ -22,9 +22,9 @@ import gammalib import ctools -# ============================ # -# Test class for ctobssim tool # -# ============================ # +# ========================== # +# Test class for ctlike tool # +# ========================== # class Test(gammalib.GPythonTestSuite): """ Test class for ctlike tool. diff --git a/test/test_ctmodel.py b/test/test_ctmodel.py index 17d43c4..996226c 100755 --- a/test/test_ctmodel.py +++ b/test/test_ctmodel.py @@ -22,9 +22,9 @@ import gammalib import ctools -# ============================ # -# Test class for ctobssim tool # -# ============================ # +# =========================== # +# Test class for ctmodel tool # +# =========================== # class Test(gammalib.GPythonTestSuite): """ Test class for ctmodel tool. diff --git a/test/test_ctools.sh b/test/test_ctools.sh index 8ea3d16..ed940f1 100755 --- a/test/test_ctools.sh +++ b/test/test_ctools.sh @@ -42,6 +42,7 @@ ctselect=../src/ctselect/ctselect ctskymap=../src/ctskymap/ctskymap ctexpcube=../src/ctexpcube/ctexpcube ctpsfcube=../src/ctpsfcube/ctpsfcube +ctbkgcube=../src/ctbkgcube/ctbkgcube ctcubemask=../src/ctcubemask/ctcubemask @@ -444,6 +445,51 @@ $ECHO " ok" # +# Test ctbkgcube +# ============== +$ECHO -n "Test ctbkgcube: " +# +# Run 1 +$ctbkgcube infile="data/crab_events.fits" \ + bkgmdl="data/crab.xml" \ + cntmap="NONE" \ + outfile="bkgcube1.fits" \ + emin=0.1 \ + emax=100.0 \ + enumbins=20 \ + nxpix=10 \ + nypix=10 \ + binsz=0.4 \ + coordsys="CEL" \ + xref=83.63 \ + yref=22.01 \ + proj="CAR" +$ECHO -n "." +if [ -s "bkgcube1.fits" ] +then + $ECHO -n "." +else + $ECHO " bkgcube1.fits file is not valid" + exit 1 +fi +# +# Run 2 +$ctbkgcube infile="data/crab_events.fits" \ + bkgmdl="data/crab.xml" \ + cntmap="data/crab_cntmap.fits" \ + outfile="bkgcube2.fits" +$ECHO -n "." +if [ -s "bkgcube2.fits" ] +then + $ECHO -n "." +else + $ECHO " bkgcube2.fits file is not valid" + exit 1 +fi +$ECHO " ok" + + +# # Test ctcubemask # =============== $ECHO -n "Test ctcubemask: " diff --git a/test/test_ctpsfcube.py b/test/test_ctpsfcube.py index fa71a04..5870619 100755 --- a/test/test_ctpsfcube.py +++ b/test/test_ctpsfcube.py @@ -22,9 +22,9 @@ import gammalib import ctools -# ============================ # -# Test class for ctobssim tool # -# ============================ # +# ============================= # +# Test class for ctpsfcube tool # +# ============================= # class Test(gammalib.GPythonTestSuite): """ Test class for ctpsfcube tool. diff --git a/test/test_ctselect.py b/test/test_ctselect.py index ad3033e..3fbd776 100755 --- a/test/test_ctselect.py +++ b/test/test_ctselect.py @@ -23,7 +23,7 @@ import ctools # ============================ # -# Test class for ctobssim tool # +# Test class for ctselect tool # # ============================ # class Test(gammalib.GPythonTestSuite): """ diff --git a/test/test_ctskymap.py b/test/test_ctskymap.py index c4236ed..5dee2cd 100755 --- a/test/test_ctskymap.py +++ b/test/test_ctskymap.py @@ -23,7 +23,7 @@ import ctools # ============================ # -# Test class for ctobssim tool # +# Test class for ctskymap tool # # ============================ # class Test(gammalib.GPythonTestSuite): """ diff --git a/test/test_python.py b/test/test_python.py index 4d1de1c..8ab4a76 100755 --- a/test/test_python.py +++ b/test/test_python.py @@ -28,9 +28,10 @@ import test_ctbin import test_ctlike import test_ctmodel import test_ctskymap -import test_ctcubemask import test_ctexpcube import test_ctpsfcube +import test_ctbkgcube +import test_ctcubemask import test_pipelines @@ -51,9 +52,10 @@ if __name__ == '__main__': suite_ctlike = test_ctlike.Test() suite_ctmodel = test_ctmodel.Test() suite_ctskymap = test_ctskymap.Test() - suite_ctcubemask = test_ctcubemask.Test() suite_ctexpcube = test_ctexpcube.Test() suite_ctpsfcube = test_ctpsfcube.Test() + suite_ctbkgcube = test_ctbkgcube.Test() + suite_ctcubemask = test_ctcubemask.Test() suite_pipelines = test_pipelines.Test() # Setup unit tests @@ -63,9 +65,10 @@ if __name__ == '__main__': suite_ctlike.set() suite_ctmodel.set() suite_ctskymap.set() - suite_ctcubemask.set() suite_ctexpcube.set() suite_ctpsfcube.set() + suite_ctbkgcube.set() + suite_ctcubemask.set() suite_pipelines.set() # Append tests to container @@ -75,9 +78,10 @@ if __name__ == '__main__': suites.append(suite_ctlike) suites.append(suite_ctmodel) suites.append(suite_ctskymap) - suites.append(suite_ctcubemask) suites.append(suite_ctexpcube) suites.append(suite_ctpsfcube) + suites.append(suite_ctbkgcube) + suites.append(suite_ctcubemask) suites.append(suite_pipelines) # Set PFILES environment variable