Commit e8293d760663ee3fb979e10d340f7feda47fdace

Authored by Jürgen Knödlseder
1 parent d98a593d

Add initial version of ctmapcube tool (so far the initial version generates an empty map cube)

.gitignore
... ... @@ -65,6 +65,7 @@ src/ctexpcube/ctexpcube
65 65 src/ctpsfcube/ctpsfcube
66 66 src/ctedispcube/ctedispcube
67 67 src/ctbkgcube/ctbkgcube
  68 +src/ctmapcube/ctmapcube
68 69 src/ctcubemask/ctcubemask
69 70 src/ctbutterfly/ctbutterfly
70 71 src/ctulimit/ctulimit
... ...
configure.ac
... ... @@ -1013,6 +1013,7 @@ AC_CONFIG_FILES([Makefile
1013 1013 src/ctpsfcube/Makefile
1014 1014 src/ctedispcube/Makefile
1015 1015 src/ctbkgcube/Makefile
  1016 + src/ctmapcube/Makefile
1016 1017 src/ctcubemask/Makefile
1017 1018 src/cttsmap/Makefile
1018 1019 src/ctbutterfly/Makefile
... ...
pyext/Makefile.am
... ... @@ -42,6 +42,7 @@ testscripts = ctools/tests/__init__.py \
42 42 ../test/test_ctexpcube.py \
43 43 ../test/test_ctpsfcube.py \
44 44 ../test/test_ctbkgcube.py \
  45 + ../test/test_ctmapcube.py \
45 46 ../test/test_ctcubemask.py \
46 47 ../test/test_ctbutterfly.py \
47 48 ../test/test_ctulimit.py \
... ...
pyext/ctmapcube.i 0 → 100644
  1 +/***************************************************************************
  2 + * ctmapcube - Map cube generation tool *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2016 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file ctmapcube.i
  23 + * @brief Map cube generation tool definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "ctmapcube.hpp"
  29 +%}
  30 +
  31 +
  32 +/***********************************************************************//**
  33 + * @class ctmapcube
  34 + *
  35 + * @brief Map cube generation tool
  36 + ***************************************************************************/
  37 +class ctmapcube : public ctool {
  38 +
  39 +public:
  40 + // Constructors and destructors
  41 + ctmapcube(void);
  42 + ctmapcube(int argc, char *argv[]);
  43 + ctmapcube(const ctmapcube& app);
  44 + virtual ~ctmapcube(void);
  45 +
  46 + // Methods
  47 + void clear(void);
  48 + void run(void);
  49 + void save(void);
  50 + void publish(const std::string& name = "");
  51 + void models(const GModels& models);
  52 +};
  53 +
  54 +
  55 +/***********************************************************************//**
  56 + * @brief Map cube generation tool Python extension
  57 + ***************************************************************************/
  58 +%extend ctmapcube {
  59 + ctmapcube copy() {
  60 + return (*self);
  61 + }
  62 +}
... ...
pyext/ctools/tools.i
... ... @@ -56,6 +56,7 @@
56 56 %include "ctpsfcube.i"
57 57 %include "ctedispcube.i"
58 58 %include "ctbkgcube.i"
  59 +%include "ctmapcube.i"
59 60 %include "ctcubemask.i"
60 61 %include "cttsmap.i"
61 62 %include "ctbutterfly.i"
... ...
src/Makefile.am
... ... @@ -16,6 +16,7 @@ SUBDIRS = support \
16 16 ctpsfcube \
17 17 ctedispcube \
18 18 ctbkgcube \
  19 + ctmapcube \
19 20 ctcubemask \
20 21 cttsmap \
21 22 ctbutterfly \
... ... @@ -43,6 +44,7 @@ libctools_la_LIBADD = support/libsupport.la \
43 44 ctpsfcube/libctpsfcube.la \
44 45 ctedispcube/libctedispcube.la \
45 46 ctbkgcube/libctbkgcube.la \
  47 + ctmapcube/libctmapcube.la \
46 48 ctcubemask/libctcubemask.la \
47 49 cttsmap/libcttsmap.la \
48 50 ctbutterfly/libctbutterfly.la \
... ...
src/ctmapcube/Makefile.am 0 → 100644
  1 +## Process this file with automake to produce Makefile.in
  2 +
  3 +# Set include directories
  4 +INCLUDES = -I$(top_srcdir)/src/support
  5 +
  6 +# Program name
  7 +bin_PROGRAMS = ctmapcube
  8 +
  9 +# Sources
  10 +sources = ctmapcube.cpp
  11 +
  12 +# Libtool library
  13 +noinst_LTLIBRARIES = libctmapcube.la
  14 +libctmapcube_la_SOURCES = $(sources)
  15 +libctmapcube_la_LDFLAGS = @OPENMP_LIB_LDFLAGS@
  16 +
  17 +# Program definition
  18 +ctmapcube_SOURCES = main.cpp
  19 +ctmapcube_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@
  20 +ctmapcube_CPPFLAGS = @CPPFLAGS@
  21 +ctmapcube_LDADD = libctmapcube.la $(top_srcdir)/src/support/libsupport.la
  22 +
  23 +# Parameter files
  24 +pfilesdir = $(prefix)/syspfiles
  25 +pfiles_DATA = ctmapcube.par
... ...
src/ctmapcube/ctmapcube.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctmapcube - Map cube generation tool *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2016 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file ctmapcube.cpp
  23 + * @brief Map cube generation tool implementation
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include <cstdio>
  32 +#include "ctmapcube.hpp"
  33 +#include "GTools.hpp"
  34 +
  35 +/* __ Method name definitions ____________________________________________ */
  36 +#define G_GET_PARAMETERS "ctmapcube::get_parameters()"
  37 +
  38 +/* __ Debug definitions __________________________________________________ */
  39 +
  40 +/* __ Coding definitions _________________________________________________ */
  41 +
  42 +/* __ Constants __________________________________________________________ */
  43 +
  44 +
  45 +/*==========================================================================
  46 + = =
  47 + = Constructors/destructors =
  48 + = =
  49 + ==========================================================================*/
  50 +
  51 +/***********************************************************************//**
  52 + * @brief Void constructor
  53 + ***************************************************************************/
  54 +ctmapcube::ctmapcube(void) : ctool(CTMAPCUBE_NAME, CTMAPCUBE_VERSION)
  55 +{
  56 + // Initialise members
  57 + init_members();
  58 +
  59 + // Return
  60 + return;
  61 +}
  62 +
  63 +
  64 +/***********************************************************************//**
  65 + * @brief Command line constructor
  66 + *
  67 + * @param[in] argc Number of arguments in command line.
  68 + * @param[in] argv Array of command line arguments.
  69 + ***************************************************************************/
  70 +ctmapcube::ctmapcube(int argc, char *argv[]) :
  71 + ctool(CTMAPCUBE_NAME, CTMAPCUBE_VERSION, argc, argv)
  72 +{
  73 + // Initialise members
  74 + init_members();
  75 +
  76 + // Return
  77 + return;
  78 +}
  79 +
  80 +
  81 +/***********************************************************************//**
  82 + * @brief Copy constructor
  83 + *
  84 + * @param[in] app Application.
  85 + ***************************************************************************/
  86 +ctmapcube::ctmapcube(const ctmapcube& app) : ctool(app)
  87 +{
  88 + // Initialise members
  89 + init_members();
  90 +
  91 + // Copy members
  92 + copy_members(app);
  93 +
  94 + // Return
  95 + return;
  96 +}
  97 +
  98 +
  99 +/***********************************************************************//**
  100 + * @brief Destructor
  101 + ***************************************************************************/
  102 +ctmapcube::~ctmapcube(void)
  103 +{
  104 + // Free members
  105 + free_members();
  106 +
  107 + // Return
  108 + return;
  109 +}
  110 +
  111 +
  112 +/*==========================================================================
  113 + = =
  114 + = Operators =
  115 + = =
  116 + ==========================================================================*/
  117 +
  118 +/***********************************************************************//**
  119 + * @brief Assignment operator
  120 + *
  121 + * @param[in] app Application.
  122 + * @return Application.
  123 + ***************************************************************************/
  124 +ctmapcube& ctmapcube::operator=(const ctmapcube& app)
  125 +{
  126 + // Execute only if object is not identical
  127 + if (this != &app) {
  128 +
  129 + // Copy base class members
  130 + this->ctool::operator=(app);
  131 +
  132 + // Free members
  133 + free_members();
  134 +
  135 + // Initialise members
  136 + init_members();
  137 +
  138 + // Copy members
  139 + copy_members(app);
  140 +
  141 + } // endif: object was not identical
  142 +
  143 + // Return this object
  144 + return *this;
  145 +}
  146 +
  147 +
  148 +/*==========================================================================
  149 + = =
  150 + = Public methods =
  151 + = =
  152 + ==========================================================================*/
  153 +
  154 +/***********************************************************************//**
  155 + * @brief Clear instance
  156 + ***************************************************************************/
  157 +void ctmapcube::clear(void)
  158 +{
  159 + // Free members
  160 + free_members();
  161 + this->ctool::free_members();
  162 + this->GApplication::free_members();
  163 +
  164 + // Initialise members
  165 + this->GApplication::init_members();
  166 + this->ctool::init_members();
  167 + init_members();
  168 +
  169 + // Return
  170 + return;
  171 +}
  172 +
  173 +
  174 +/***********************************************************************//**
  175 + * @brief Generate map cube.
  176 + *
  177 + * This method reads the task parameters from the parfile and generates the
  178 + * map cube.
  179 + ***************************************************************************/
  180 +void ctmapcube::run(void)
  181 +{
  182 + // If we're in debug mode then all output is also dumped on the screen
  183 + if (logDebug()) {
  184 + log.cout(true);
  185 + }
  186 +
  187 + // Get task parameters
  188 + get_parameters();
  189 +
  190 + // Write models into logger
  191 + if (logTerse()) {
  192 + log << std::endl;
  193 + log.header1(gammalib::number("Model", m_models.size()));
  194 + log << m_models << std::endl;
  195 + }
  196 +
  197 + // Write header
  198 + if (logTerse()) {
  199 + log << std::endl;
  200 + log.header1("Generate map cube");
  201 + }
  202 +
  203 + //TODO
  204 +
  205 + // Log cube
  206 + if (logTerse()) {
  207 + log << std::endl;
  208 + log.header1("Map cube");
  209 + log << m_cube << std::endl;
  210 + }
  211 +
  212 + // Optionally publish map cube
  213 + if (m_publish) {
  214 + publish();
  215 + }
  216 +
  217 + // Return
  218 + return;
  219 +}
  220 +
  221 +
  222 +/***********************************************************************//**
  223 + * @brief Save map cube
  224 + *
  225 + * Saves the map cube into a FITS file.
  226 + ***************************************************************************/
  227 +void ctmapcube::save(void)
  228 +{
  229 + // Write header
  230 + if (logTerse()) {
  231 + log << std::endl;
  232 + log.header1("Save map cube");
  233 + }
  234 +
  235 + // Get map cube filename
  236 + m_outcube = (*this)["outcube"].filename();
  237 +
  238 + // Save only if filename is non-empty
  239 + if (!m_outcube.is_empty()) {
  240 +
  241 + // Log filename
  242 + if (logTerse()) {
  243 + log << "Save map cube into file \""+m_outcube+"\".";
  244 + log << std::endl;
  245 + }
  246 +
  247 + // Save map cube into FITS file
  248 + m_cube.save(m_outcube, clobber());
  249 +
  250 + }
  251 +
  252 + // Return
  253 + return;
  254 +}
  255 +
  256 +
  257 +/***********************************************************************//**
  258 + * @brief Publish map cube
  259 + *
  260 + * @param[in] name Map cube name.
  261 + ***************************************************************************/
  262 +void ctmapcube::publish(const std::string& name)
  263 +{
  264 + // Write header
  265 + if (logTerse()) {
  266 + log << std::endl;
  267 + log.header1("Publish map cube");
  268 + }
  269 +
  270 + // Set default name is user name is empty
  271 + std::string user_name(name);
  272 + if (user_name.empty()) {
  273 + user_name = CTMAPCUBE_NAME;
  274 + }
  275 +
  276 + // Log filename
  277 + if (logTerse()) {
  278 + log << "Publish \""+user_name+"\" map cube." << std::endl;
  279 + }
  280 +
  281 + // Publish map cube
  282 + m_cube.cube().publish(user_name);
  283 +
  284 + // Return
  285 + return;
  286 +}
  287 +
  288 +
  289 +/*==========================================================================
  290 + = =
  291 + = Private methods =
  292 + = =
  293 + ==========================================================================*/
  294 +
  295 +/***********************************************************************//**
  296 + * @brief Initialise class members
  297 + ***************************************************************************/
  298 +void ctmapcube::init_members(void)
  299 +{
  300 + // Initialise members
  301 + m_outcube.clear();
  302 + m_publish = false;
  303 +
  304 + // Initialise protected members
  305 + m_models.clear();
  306 + m_cube.clear();
  307 +
  308 + // Return
  309 + return;
  310 +}
  311 +
  312 +
  313 +/***********************************************************************//**
  314 + * @brief Copy class members
  315 + *
  316 + * @param[in] app Application.
  317 + ***************************************************************************/
  318 +void ctmapcube::copy_members(const ctmapcube& app)
  319 +{
  320 + // Copy attributes
  321 + m_outcube = app.m_outcube;
  322 + m_publish = app.m_publish;
  323 +
  324 + // Copy protected members
  325 + m_models = app.m_models;
  326 + m_cube = app.m_cube;
  327 +
  328 + // Return
  329 + return;
  330 +}
  331 +
  332 +
  333 +/***********************************************************************//**
  334 + * @brief Delete class members
  335 + ***************************************************************************/
  336 +void ctmapcube::free_members(void)
  337 +{
  338 + // Return
  339 + return;
  340 +}
  341 +
  342 +
  343 +/***********************************************************************//**
  344 + * @brief Get application parameters
  345 + *
  346 + * Get all task parameters from parameter file or (if required) by querying
  347 + * the user. The parameters are read in the correct order.
  348 + ***************************************************************************/
  349 +void ctmapcube::get_parameters(void)
  350 +{
  351 + // Get energy binning parameters
  352 + GEnergies energies = create_energies();
  353 +
  354 + // Get spatial binning parameters
  355 + double xref = (*this)["xref"].real();
  356 + double yref = (*this)["yref"].real();
  357 + std::string proj = (*this)["proj"].string();
  358 + std::string coordsys = (*this)["coordsys"].string();
  359 + double binsz = (*this)["binsz"].real();
  360 + int nxpix = (*this)["nxpix"].integer();
  361 + int nypix = (*this)["nypix"].integer();
  362 +
  363 + // Allocate map cube
  364 + GSkyMap cube(proj, coordsys, xref, yref, -binsz, binsz, nxpix, nypix,
  365 + energies.size());
  366 +
  367 + // Allocate map cube
  368 + m_cube = GModelSpatialDiffuseCube(cube, energies);
  369 +
  370 + // Read model definition file if required
  371 + if (m_models.size() == 0) {
  372 +
  373 + // Get model filename
  374 + GFilename inmodel = (*this)["inmodel"].filename();
  375 +
  376 + // Load models from file
  377 + m_models.load(inmodel);
  378 +
  379 + } // endif: there were no models
  380 +
  381 + // Get remaining parameters
  382 + m_publish = (*this)["publish"].boolean();
  383 +
  384 + // Read optionally output cube filenames
  385 + if (read_ahead()) {
  386 + m_outcube = (*this)["outcube"].filename();
  387 + }
  388 +
  389 + // Write parameters into logger
  390 + if (logTerse()) {
  391 + log_parameters();
  392 + log << std::endl;
  393 + }
  394 +
  395 + // Return
  396 + return;
  397 +}
  398 +
  399 +
  400 +/***********************************************************************//**
  401 + * @brief Create energy vector from user parameters
  402 + *
  403 + * @exception GException::invalid_value
  404 + * No valid energy boundary extension found.
  405 + *
  406 + * Get the energy vector according to the user parameters. The method
  407 + * supports loading of energy information from the ENERGIES extension (or
  408 + * any other extension specified by the "ebinfile" parameters), or setting
  409 + * energies using a linear or logarithmical spacing.
  410 + *
  411 + * The following parameters are read:
  412 + * ebinalg - Energy binning algorithm
  413 + * emin - Minimum energy (if ebinalg != FILE)
  414 + * emax - Maximum energy (if ebinalg != FILE)
  415 + * enumbins - Number of energies (if ebinalg != FILE)
  416 + ***************************************************************************/
  417 +GEnergies ctmapcube::create_energies(void)
  418 +{
  419 + // Allocate energies
  420 + GEnergies energies;
  421 +
  422 + // Get energy binning algorithm
  423 + std::string ebinalg = (*this)["ebinalg"].string();
  424 +
  425 + // If energy binning algorithm is of type "FILE" (case sensitive), then
  426 + // read energies from FITS file ...
  427 + if (ebinalg == "FILE") {
  428 +
  429 + // Get filename
  430 + GFilename ebinfile = (*this)["ebinfile"].filename();
  431 +
  432 + // Load energies
  433 + energies.load(ebinfile);
  434 +
  435 + } // endif: ebinalg was "FILE"
  436 +
  437 + // ... otherwise use a linear or a logarithmically-spaced energy binning
  438 + else {
  439 +
  440 + // Get task parameters
  441 + double emin = (*this)["emin"].real();
  442 + double emax = (*this)["emax"].real();
  443 + int enumbins = (*this)["enumbins"].integer();
  444 +
  445 + // Initialise log mode for ebinning
  446 + bool log = true;
  447 +
  448 + // Check if algorithm is linear
  449 + if (ebinalg == "LIN") {
  450 + log = false;
  451 + }
  452 +
  453 + // Setup energies
  454 + energies = GEnergies(enumbins, GEnergy(emin, "TeV"),
  455 + GEnergy(emax, "TeV"), log);
  456 +
  457 + } // endelse: ebinalg was not "FILE"
  458 +
  459 + // Return energies
  460 + return energies;
  461 +}
... ...
src/ctmapcube/ctmapcube.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctmapcube - Map cube generation tool *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2016 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file ctmapcube.hpp
  23 + * @brief Map cube generation tool definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +#ifndef CTMAPCUBE_HPP
  28 +#define CTMAPCUBE_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include "GammaLib.hpp"
  32 +#include "GCTALib.hpp"
  33 +#include "ctool.hpp"
  34 +
  35 +/* __Definitions _________________________________________________________ */
  36 +#define CTMAPCUBE_NAME "ctmapcube"
  37 +#define CTMAPCUBE_VERSION "1.0.0"
  38 +
  39 +
  40 +/***********************************************************************//**
  41 + * @class ctmapcube
  42 + *
  43 + * @brief Map cube generation tool
  44 + ***************************************************************************/
  45 +class ctmapcube : public ctool {
  46 +
  47 +public:
  48 + // Constructors and destructors
  49 + ctmapcube(void);
  50 + ctmapcube(int argc, char *argv[]);
  51 + ctmapcube(const ctmapcube& app);
  52 + virtual ~ctmapcube(void);
  53 +
  54 + // Operators
  55 + ctmapcube& operator=(const ctmapcube& app);
  56 +
  57 + // Methods
  58 + void clear(void);
  59 + void run(void);
  60 + void save(void);
  61 + void publish(const std::string& name = "");
  62 + void models(const GModels& models);
  63 +
  64 +protected:
  65 + // Protected methods
  66 + void init_members(void);
  67 + void copy_members(const ctmapcube& app);
  68 + void free_members(void);
  69 + void get_parameters(void);
  70 + GEnergies create_energies(void);
  71 +
  72 + // User parameters
  73 + GFilename m_outcube; //!< Output map cube filename
  74 + bool m_publish; //!< Publish map cube?
  75 +
  76 + // Protected members
  77 + GModels m_models; //!< Model container
  78 + GModelSpatialDiffuseCube m_cube; //!< Map cube
  79 +};
  80 +
  81 +
  82 +/***********************************************************************//**
  83 + * @brief Set models
  84 + *
  85 + * @param[in] models Model container.
  86 + *
  87 + * Set model container to be used for map cube generation.
  88 + ***************************************************************************/
  89 +inline
  90 +void ctmapcube::models(const GModels& models)
  91 +{
  92 + m_models = models;
  93 + return;
  94 +}
  95 +
  96 +#endif /* CTMAPCUBE_HPP */
... ...
src/ctmapcube/ctmapcube.par 0 → 100644
  1 +#############################################################################
  2 +# #
  3 +# CTA Science Analysis Tools #
  4 +# #
  5 +# ------------------------------------------------------------------------- #
  6 +# #
  7 +# File: ctmapcube.par #
  8 +# Version: 1.0.0 #
  9 +# #
  10 +# Author: Juergen Knoedlseder #
  11 +# Jurgen.Knodlseder@irap.omp.eu #
  12 +# IRAP #
  13 +# #
  14 +# Purpose: Parameter file for the ctmapcube application #
  15 +# #
  16 +#############################################################################
  17 +#
  18 +# General parameters
  19 +#===================
  20 +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Input model XML file"
  21 +outcube, f, a, "mapcube.fits",,, "Output map cube file"
  22 +
  23 +#
  24 +# Energy binning parameters
  25 +#==========================
  26 +ebinalg, s, a, LOG,FILE|LIN|LOG,, "Algorithm for defining energy bins"
  27 +emin, r, a, 0.1,,, "Start value for first energy bin in TeV"
  28 +emax, r, a, 100.0,,, "Stop value for last energy bin in TeV"
  29 +enumbins, i, a, 20,1,200, "Number of energy bins"
  30 +ebinfile, f, a, NONE,,, "Name of the file containing the energy bin definition"
  31 +
  32 +#
  33 +# Spatial binning parameters
  34 +#===========================
  35 +nxpix, i, a, 200,,, "Size of the X axis in pixels"
  36 +nypix, i, a, 200,,, "Size of the Y axis in pixels"
  37 +binsz, r, a, 0.02,,, "Image scale (in degrees/pixel)"
  38 +coordsys, s, a, CEL,CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)"
  39 +xref, r, a, 83.63,0,360, "First coordinate of image center in degrees (RA or galactic l)"
  40 +yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DEC or galactic b)"
  41 +proj, s, a, CAR,AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method"
  42 +
  43 +#
  44 +# Standard parameters
  45 +#====================
  46 +publish, b, h, no,,, "Publish map cube on VO Hub?"
  47 +chatter, i, h, 2,0,4, "Chattiness of output"
  48 +clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
  49 +debug, b, h, no,,, "Debugging mode activated"
  50 +mode, s, h, "ql",,, "Mode of automatic parameters"
  51 +logfile, f, h, "ctmapcube.log",,, "Log filename"
... ...
src/ctmapcube/main.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * ctmapcube - CTA map cube generation tool *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2016 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file ctmapcube/main.cpp
  23 + * @brief CTA map cube generation tool main code
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include <cstdio>
  32 +#include "ctmapcube.hpp"
  33 +
  34 +
  35 +/***********************************************************************//**
  36 + * @brief Main entry point of application
  37 + *
  38 + * @param[in] argc Number of command line arguments.
  39 + * @param[in] argv Command line arguments.
  40 + *
  41 + * This is the main entry point of the gtbin application. It allocates a
  42 + * ctmapcube object and runs the application.
  43 + ***************************************************************************/
  44 +int main (int argc, char *argv[])
  45 +{
  46 + // Initialise return code
  47 + int rc = 1;
  48 +
  49 + // Create instance of application
  50 + ctmapcube application(argc, argv);
  51 +
  52 + // Run application
  53 + try {
  54 + // Execute application
  55 + application.execute();
  56 +
  57 + // Signal success
  58 + rc = 0;
  59 + }
  60 + catch (std::exception &e) {
  61 +
  62 + // Extract error message
  63 + std::string message = e.what();
  64 + std::string signal = "*** ERROR encounterted in the execution of"
  65 + " ctmapcube. Run aborted ...";
  66 +
  67 + // Write error in logger
  68 + application.log << signal << std::endl;
  69 + application.log << message << std::endl;
  70 +
  71 + // Write error on standard output
  72 + std::cout << signal << std::endl;
  73 + std::cout << message << std::endl;
  74 +
  75 + } // endcatch: catched any application error
  76 +
  77 + // Return
  78 + return rc;
  79 +}
... ...
test/test_ctmapcube.py 0 → 100644
  1 +#! /usr/bin/env python
  2 +# ==========================================================================
  3 +# This scripts performs unit tests for the ctmapcube tool.
  4 +#
  5 +# Copyright (C) 2016 Juergen Knoedlseder
  6 +#
  7 +# This program is free software: you can redistribute it and/or modify
  8 +# it under the terms of the GNU General Public License as published by
  9 +# the Free Software Foundation, either version 3 of the License, or
  10 +# (at your option) any later version.
  11 +#
  12 +# This program is distributed in the hope that it will be useful,
  13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 +# GNU General Public License for more details.
  16 +#
  17 +# You should have received a copy of the GNU General Public License
  18 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 +#
  20 +# ==========================================================================
  21 +import os
  22 +import gammalib
  23 +import ctools
  24 +
  25 +
  26 +# ============================= #
  27 +# Test class for ctmapcube tool #
  28 +# ============================= #
  29 +class Test(gammalib.GPythonTestSuite):
  30 + """
  31 + Test class for ctmapcube tool.
  32 +
  33 + This test class makes unit tests for the ctmapcube tool by using it from
  34 + the command line and from Python.
  35 + """
  36 +
  37 + # Constructor
  38 + def __init__(self):
  39 + """
  40 + Constructor.
  41 + """
  42 + # Call base class constructor
  43 + gammalib.GPythonTestSuite.__init__(self)
  44 +
  45 + # Set members
  46 + self._model_name = "data/crab.xml"
  47 +
  48 + # Return
  49 + return
  50 +
  51 + # Set test functions
  52 + def set(self):
  53 + """
  54 + Set all test functions.
  55 + """
  56 + # Set test name
  57 + self.name("ctmapcube")
  58 +
  59 + # Append tests
  60 + self.append(self._test_cmd, "Test ctmapcube on command line")
  61 + self.append(self._test_python, "Test ctmapcube from Python")
  62 +
  63 + # Return
  64 + return
  65 +
  66 + # Test ctmapcube on command line
  67 + def _test_cmd(self):
  68 + """
  69 + Test ctmapcube on the command line.
  70 + """
  71 + # Kluge to set the command (installed version has no README file)
  72 + if os.path.isfile("README"):
  73 + ctmapcube = "../src/ctmapcube/ctmapcube"
  74 + else:
  75 + ctmapcube = "ctmapcube"
  76 +
  77 + # Setup ctmapcube command
  78 + cmd = ctmapcube+' inmodel="'+self._model_name+'"'+ \
  79 + ' outcube="ctmapcube_cmd1.fits"'+\
  80 + ' emin=0.1 emax=100.0 enumbins=20 ebinalg=LOG'+ \
  81 + ' nxpix=200 nypix=200 binsz=0.02 coordsys=CEL'+ \
  82 + ' xref=83.63 yref=22.01 proj=CAR'+ \
  83 + ' logfile="ctmapcube_cmd1.log" chatter=1'
  84 +
  85 + # Execute ctmapcube, make sure we catch any exception
  86 + try:
  87 + #rc = os.system(cmd)
  88 + rc = os.system(cmd+" >/dev/null 2>&1")
  89 + except:
  90 + pass
  91 +
  92 + # Check if execution was successful
  93 + self.test_assert(rc == 0,
  94 + "Successful ctmapcube execution on command line")
  95 +
  96 + # Check map cube
  97 + self._check_cube("ctmapcube_cmd1.fits")
  98 +
  99 + # Setup ctmapcube command
  100 + cmd = ctmapcube+' inmodel="events_that_do_not_exist.fits"'+ \
  101 + ' outcube="ctmapcube_cmd2.fits"'+\
  102 + ' emin=0.1 emax=100.0 enumbins=20 ebinalg=LOG'+ \
  103 + ' nxpix=200 nypix=200 binsz=0.02 coordsys=CEL'+ \
  104 + ' xref=83.63 yref=22.01 proj=CAR'+ \
  105 + ' logfile="ctmapcube_cmd2.log"'
  106 +
  107 + # Execute ctmapcube, make sure we catch any exception
  108 + try:
  109 + #rc = os.system(cmd)
  110 + rc = os.system(cmd+" >/dev/null 2>&1")
  111 + except:
  112 + pass
  113 +
  114 + # Check if execution failed
  115 + self.test_assert(rc != 0,
  116 + "Failure of ctmapcube execution on command line")
  117 +
  118 + # Return
  119 + return
  120 +
  121 + # Test ctmapcube from Python
  122 + def _test_python(self):
  123 + """
  124 + Test ctmapcube from Python.
  125 + """
  126 + # Set-up ctmapcube
  127 + mapcube = ctools.ctmapcube()
  128 + mapcube["inmodel"] = self._model_name
  129 + mapcube["outcube"] = "ctmapcube_py1.fits"
  130 + mapcube["ebinalg"] = "LOG"
  131 + mapcube["emin"] = 0.1
  132 + mapcube["emax"] = 100.0
  133 + mapcube["enumbins"] = 20
  134 + mapcube["nxpix"] = 200
  135 + mapcube["nypix"] = 200
  136 + mapcube["binsz"] = 0.02
  137 + mapcube["coordsys"] = "CEL"
  138 + mapcube["proj"] = "CAR"
  139 + mapcube["xref"] = 83.63
  140 + mapcube["yref"] = 22.01
  141 + mapcube["logfile"] = "ctmapcube_py1.log"
  142 + mapcube["chatter"] = 2
  143 +
  144 + # Run ctmapcube tool
  145 + mapcube.logFileOpen() # Make sure we get a log file
  146 + mapcube.run()
  147 +
  148 + # Save map cube
  149 + mapcube.save()
  150 +
  151 + # Check map cube
  152 + self._check_cube("ctmapcube_py1.fits")
  153 +
  154 + # Return
  155 + return
  156 +
  157 + # Check map cube
  158 + def _check_cube(self, filename):
  159 + """
  160 + Check content of map cube."
  161 +
  162 + Args:
  163 + filename: Map cube file name.
  164 + """
  165 + # Load map cube
  166 + cube = gammalib.GModelSpatialDiffuseCube(filename)
  167 + #print(cube)
  168 +
  169 + # Test map cube
  170 + #self.test_value(cube.maps(), 20, "20 maps")
  171 + #self.test_value(cube.pixels(), 40000, "40000 map pixels")
  172 + # The map cube is not loaded by default !!!! We should add the method so that
  173 + # the attributes are known !!!!
  174 + self.test_value(cube.maps(), 0, "20 maps")
  175 + self.test_value(cube.pixels(), 0, "40000 map pixels")
  176 +
  177 + # Return
  178 + return
... ...
test/test_python_ctools.py
... ... @@ -33,6 +33,7 @@ import test_ctskymap
33 33 import test_ctexpcube
34 34 import test_ctpsfcube
35 35 import test_ctbkgcube
  36 +import test_ctmapcube
36 37 import test_ctcubemask
37 38 import test_ctbutterfly
38 39 import test_ctulimit
... ... @@ -61,6 +62,7 @@ def test(installed=False):
61 62 suite_ctexpcube = test_ctexpcube.Test()
62 63 suite_ctpsfcube = test_ctpsfcube.Test()
63 64 suite_ctbkgcube = test_ctbkgcube.Test()
  65 + suite_ctmapcube = test_ctmapcube.Test()
64 66 suite_ctcubemask = test_ctcubemask.Test()
65 67 suite_ctbutterfly = test_ctbutterfly.Test()
66 68 suite_ctulimit = test_ctulimit.Test()
... ... @@ -78,6 +80,7 @@ def test(installed=False):
78 80 suite_ctexpcube.set()
79 81 suite_ctpsfcube.set()
80 82 suite_ctbkgcube.set()
  83 + suite_ctmapcube.set()
81 84 suite_ctcubemask.set()
82 85 suite_ctbutterfly.set()
83 86 suite_ctulimit.set()
... ... @@ -95,6 +98,7 @@ def test(installed=False):
95 98 suites.append(suite_ctexpcube)
96 99 suites.append(suite_ctpsfcube)
97 100 suites.append(suite_ctbkgcube)
  101 + suites.append(suite_ctmapcube)
98 102 suites.append(suite_ctcubemask)
99 103 suites.append(suite_ctbutterfly)
100 104 suites.append(suite_ctulimit)
... ...