From 155cf0c2bbb3f37e3152bce020289dd2d864d2f7 Mon Sep 17 00:00:00 2001 From: Simon Bonnefoy Date: Mon, 5 Nov 2018 16:46:15 +0100 Subject: [PATCH] creation of the new time variability tool --- doc/source/users/reference_manual/ctfindvar.rst | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ pyext/ctfindvar.i | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctfindvar/Makefile.am | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctfindvar/ctfindvar.cpp | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctfindvar/ctfindvar.hpp | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ctfindvar/ctfindvar.par | 28 ++++++++++++++++++++++++++++ src/ctfindvar/main.cpp | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/test_ctfindvar.py | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 797 insertions(+), 0 deletions(-) create mode 100644 doc/source/users/reference_manual/ctfindvar.rst create mode 100644 pyext/ctfindvar.i create mode 100644 src/ctfindvar/Makefile.am create mode 100644 src/ctfindvar/ctfindvar.cpp create mode 100644 src/ctfindvar/ctfindvar.hpp create mode 100644 src/ctfindvar/ctfindvar.par create mode 100644 src/ctfindvar/main.cpp create mode 100644 test/test_ctfindvar.py diff --git a/doc/source/users/reference_manual/ctfindvar.rst b/doc/source/users/reference_manual/ctfindvar.rst new file mode 100644 index 0000000..cc29dc1 --- /dev/null +++ b/doc/source/users/reference_manual/ctfindvar.rst @@ -0,0 +1,54 @@ +.. _ctfindvar: + +ctfindvar +============================== + +ToDo: Describe in a one liner what the tool is doing. + + +Synopsis +-------- + +ToDo: Desribe in detail what the tool is doing, what it takes on input and +what it produces on output. Please do not write more than 80 characters per +line since this file is also used to produce a help text for the terminal. + + +General parameters +------------------ + +ToDo: Add here your parameters. + + +Standard parameters +------------------- + +``(chatter = 2) [integer]`` + Verbosity of the executable: + ``chatter = 0``: no information will be logged + + ``chatter = 1``: only errors will be logged + + ``chatter = 2``: errors and actions will be logged + + ``chatter = 3``: report about the task execution + + ``chatter = 4``: detailed report about the task execution + +``(clobber = yes) [boolean]`` + Specifies whether an existing output file should be overwritten. + +``(debug = no) [boolean]`` + Enables debug mode. In debug mode the executable will dump any log file output to the console. + +``(mode = ql) [string]`` + Mode of automatic parameters (default is ``ql``, i.e. "query and learn"). + +``(logfile = ctfindvar.log) [string]`` + Name of log file. + + +Related tools or scripts +------------------------ + +None diff --git a/pyext/ctfindvar.i b/pyext/ctfindvar.i new file mode 100644 index 0000000..03dbd00 --- /dev/null +++ b/pyext/ctfindvar.i @@ -0,0 +1,60 @@ +/*************************************************************************** + * ctfindvar - search time variability tool * + * ----------------------------------------------------------------------- * + * copyright (C) 2018 by Simon Bonnefoy * + * ----------------------------------------------------------------------- * + * * + * 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 ctfindvar.i + * @brief search time variability tool definition + * @author Simon Bonnefoy + */ +%{ +/* Put headers and other declarations here that are needed for compilation */ +#include "ctfindvar.hpp" +%} + + +/***********************************************************************//** + * @class ctfindvar + * + * @brief search time variability tool + ***************************************************************************/ +class ctfindvar : public ctobservation { +public: + // Constructors and destructors + ctfindvar(void); + explicit ctfindvar(const GObservations& obs); + ctfindvar(int argc, char *argv[]); + ctfindvar(const ctfindvar& app); + virtual ~ctfindvar(void); + + // Methods + void clear(void); + void run(void); + void save(void); +}; + + +/***********************************************************************//** + * @brief search time variability tool Python extension + ***************************************************************************/ +%extend ctfindvar { + ctfindvar copy() { + return (*self); + } +} diff --git a/src/ctfindvar/Makefile.am b/src/ctfindvar/Makefile.am new file mode 100644 index 0000000..7b67c15 --- /dev/null +++ b/src/ctfindvar/Makefile.am @@ -0,0 +1,50 @@ +############################################################################# +# Makefile.am for ctfindvar tool # +# ------------------------------------------------------------------------- # +# Copyright (C) 2018 by Simon Bonnefoy # +# ------------------------------------------------------------------------- # +# # +# 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 . # +# # +############################################################################# + +# Set include directories +INCLUDES = -I$(top_srcdir)/src/support + +# Program name +bin_PROGRAMS = ctfindvar + +# Sources +sources = ctfindvar.cpp ctfindvar.hpp + +# Headers +pkginclude_HEADERS = ctfindvar.hpp + +# Libtool library +noinst_LTLIBRARIES = libctfindvar.la +libctfindvar_la_SOURCES = $(sources) +libctfindvar_la_LDFLAGS = @OPENMP_LIB_LDFLAGS@ + +# Program definition +ctfindvar_SOURCES = main.cpp +ctfindvar_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ +ctfindvar_CPPFLAGS = @CPPFLAGS@ +ctfindvar_LDADD = libctfindvar.la $(top_builddir)/src/support/libsupport.la + +# Parameter files +pfilesdir = $(prefix)/syspfiles +pfiles_DATA = $(srcdir)/ctfindvar.par + +# Extra files to be distributed in the tar file +EXTRA_DIST = $(pfiles_DATA) diff --git a/src/ctfindvar/ctfindvar.cpp b/src/ctfindvar/ctfindvar.cpp new file mode 100644 index 0000000..9327f2f --- /dev/null +++ b/src/ctfindvar/ctfindvar.cpp @@ -0,0 +1,311 @@ +/*************************************************************************** + * ctfindvar - search time variability tool * + * ----------------------------------------------------------------------- * + * copyright (C) 2018 by Simon Bonnefoy * + * ----------------------------------------------------------------------- * + * * + * 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 ctfindvar.cpp + * @brief search time variability tool implementation + * @author Simon Bonnefoy + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include "ctfindvar.hpp" +#include "GammaLib.hpp" +#include "GCTALib.hpp" + +/* __ OpenMP section _____________________________________________________ */ +//#ifdef _OPENMP +//#include +//#endif + +/* __ Method name definitions ____________________________________________ */ + +/* __ Debug definitions __________________________________________________ */ + +/* __ Coding definitions _________________________________________________ */ + +/* __ Constants __________________________________________________________ */ + + +/*========================================================================== + = = + = Constructors/destructors = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Void constructor + * + * Constructs empty search time variability tool. + ***************************************************************************/ +ctfindvar::ctfindvar(void) : ctobservation(CTFINDVAR_NAME, VERSION) +{ + // Initialise members + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Observations constructor + * + * param[in] obs Observation container. + * + * Constructs search time variability tool from an observation container. + ***************************************************************************/ +ctfindvar::ctfindvar(const GObservations& obs) : ctobservation(CTFINDVAR_NAME, VERSION, obs) +{ + // Initialise members + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Command line constructor + * + * @param[in] argc Number of arguments in command line. + * @param[in] argv Array of command line arguments. + * + * Constructs search time variability tool using command line arguments for user + * parameter setting. + ***************************************************************************/ +ctfindvar::ctfindvar(int argc, char *argv[]) : ctobservation(CTFINDVAR_NAME, VERSION, argc, argv) +{ + // Initialise members + init_members(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy constructor + * + * @param[in] app search time variability tool. + * + * Constructs search time variability tool from another search time variability tool. + ***************************************************************************/ +ctfindvar::ctfindvar(const ctfindvar& app) : ctobservation(app) +{ + // Initialise members + init_members(); + + // Copy members + copy_members(app); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Destructor + * + * Destructs search time variability tool. + ***************************************************************************/ +ctfindvar::~ctfindvar(void) +{ + // Free members + free_members(); + + // Return + return; +} + + +/*========================================================================== + = = + = Operators = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Assignment operator + * + * @param[in] app search time variability tool. + * @return search time variability tool. + * + * Assigns search time variability tool. + ***************************************************************************/ +ctfindvar& ctfindvar::operator=(const ctfindvar& app) +{ + // Execute only if object is not identical + if (this != &app) { + + // Copy base class members + this->ctobservation::operator=(app); + + // Free members + free_members(); + + // Initialise members + init_members(); + + // Copy members + copy_members(app); + + } // endif: object was not identical + + // Return this object + return *this; +} + + +/*========================================================================== + = = + = Public methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Clear search time variability tool + * + * Clears search time variability tool. + ***************************************************************************/ +void ctfindvar::clear(void) +{ + // Free members + free_members(); + this->ctobservation::free_members(); + this->ctool::free_members(); + + // Clear base class (needed to conserve tool name and version) + this->GApplication::clear(); + + // Initialise members + this->ctool::init_members(); + this->ctobservation::init_members(); + init_members(); + + // Write header into logger + log_header(); + + // Return + return; +} + + +/***********************************************************************//** + * @brief Run search time variability tool + ***************************************************************************/ +void ctfindvar::run(void) +{ + // If we're in debug mode then all output is also dumped on the screen + if (logDebug()) { + log.cout(true); + } + + // Get task parameters + get_parameters(); + + // Write input observation container into logger + log_observations(NORMAL, m_obs, "Input observation"); + + // TODO: Your code goes here + + // Return + return; +} + + +/***********************************************************************//** + * @brief Save something + * + * Saves something. + ***************************************************************************/ +void ctfindvar::save(void) +{ + // Write header + log_header1(TERSE, "Save something"); + + // TODO: Your code goes here + + // Return + return; +} + + +/*========================================================================== + = = + = Private methods = + = = + ==========================================================================*/ + +/***********************************************************************//** + * @brief Initialise class members + ***************************************************************************/ +void ctfindvar::init_members(void) +{ + // Initialise members + // TODO: Your code goes here + + // Return + return; +} + + +/***********************************************************************//** + * @brief Copy class members + * + * @param[in] app search time variability tool. + ***************************************************************************/ +void ctfindvar::copy_members(const ctfindvar& app) +{ + // Copy attributes + // TODO: Your code goes here + + // Return + return; +} + + +/***********************************************************************//** + * @brief Delete class members + ***************************************************************************/ +void ctfindvar::free_members(void) +{ + // Return + return; +} + + +/***********************************************************************//** + * @brief Get application parameters + * + * @todo Implement method + ***************************************************************************/ +void ctfindvar::get_parameters(void) +{ + // TODO: Your code goes here + + // Write parameters into logger + log_parameters(TERSE); + + // Return + return; +} diff --git a/src/ctfindvar/ctfindvar.hpp b/src/ctfindvar/ctfindvar.hpp new file mode 100644 index 0000000..37f7c74 --- /dev/null +++ b/src/ctfindvar/ctfindvar.hpp @@ -0,0 +1,72 @@ +/*************************************************************************** + * ctfindvar - search time variability tool * + * ----------------------------------------------------------------------- * + * copyright (C) 2018 by Simon Bonnefoy * + * ----------------------------------------------------------------------- * + * * + * 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 ctfindvar.hpp + * @brief search time variability tool definition + * @author Simon Bonnefoy + */ + +#ifndef CTFINDVAR_HPP +#define CTFINDVAR_HPP + +/* __ Includes ___________________________________________________________ */ +#include "ctobservation.hpp" + +/* __Definitions _________________________________________________________ */ +#define CTFINDVAR_NAME "ctfindvar" + + +/***********************************************************************//** + * @class ctfindvar + * + * @brief search time variability tool + * + * @todo Add tool description. + ***************************************************************************/ +class ctfindvar : public ctobservation { +public: + // Constructors and destructors + ctfindvar(void); + explicit ctfindvar(const GObservations& obs); + ctfindvar(int argc, char *argv[]); + ctfindvar(const ctfindvar& app); + virtual ~ctfindvar(void); + + // Operators + ctfindvar& operator=(const ctfindvar& app); + + // Methods + void clear(void); + void run(void); + void save(void); + +protected: + // Protected methods + void init_members(void); + void copy_members(const ctfindvar& app); + void free_members(void); + void get_parameters(void); + + // Protected members + // TODO: Add any data members that are necessary +}; + +#endif /* CTFINDVAR_HPP */ diff --git a/src/ctfindvar/ctfindvar.par b/src/ctfindvar/ctfindvar.par new file mode 100644 index 0000000..5ff7a36 --- /dev/null +++ b/src/ctfindvar/ctfindvar.par @@ -0,0 +1,28 @@ +############################################################################# +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: ctfindvar.par # +# # +# Author: Simon Bonnefoy # +# simon.bonnefoy@desy.de # +# DESY # +# # +# Purpose: Parameter file for the ctfindvar tool # +# # +############################################################################# +# +# General parameters +#=================== +# Your parameters go here + +# +# Standard parameters +#==================== +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,,, "Activate debugging mode?" +mode, s, h, ql,,, "Mode of automatic parameters" +logfile, f, h, ctfindvar.log,,, "Log filename" diff --git a/src/ctfindvar/main.cpp b/src/ctfindvar/main.cpp new file mode 100644 index 0000000..6b95384 --- /dev/null +++ b/src/ctfindvar/main.cpp @@ -0,0 +1,77 @@ +/*************************************************************************** + *ctfindvar - search time variability tool main code * + * ----------------------------------------------------------------------- * + * copyright (C) 2018 by Simon Bonnefoy * + * ----------------------------------------------------------------------- * + * * + * 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 ctfindvar/main.cpp + * @brief search time variability tool main code + * @author Simon Bonnefoy + */ + +/* __ Includes ___________________________________________________________ */ +#ifdef HAVE_CONFIG_H +#include +#endif +#include "support.hpp" +#include "ctfindvar.hpp" + + +/***********************************************************************//** + * @brief Main entry point of application + * + * @param[in] argc Number of command line arguments. + * @param[in] argv Command line arguments. + * + * This is the main entry point of the ctfindvar application. It allocates a + * ctfindvar object and executes the application. Any exceptions that occur + * will be catched and corresponding error messages written in the + * application logger and into the standard output. + ***************************************************************************/ +int main (int argc, char *argv[]) +{ + // Initialise return code + int rc = 1; + + // Initialise pointer on application + ctfindvar* application = NULL; + + // Try creating an instance of the application and executing the instance + try { + + // Create instance of application + application = new ctfindvar(argc, argv); + + // Execute ctool + rc = execute_ctool(application); + + } + + catch (std::exception &e) { + + // Report exception + report_ctool_failure("ctfindvar", e.what()); + + } + + // Delete application + delete application; + + // Return + return rc; +} diff --git a/test/test_ctfindvar.py b/test/test_ctfindvar.py new file mode 100644 index 0000000..17c70ce --- /dev/null +++ b/test/test_ctfindvar.py @@ -0,0 +1,145 @@ +#! /usr/bin/env python +# ========================================================================== +# This scripts performs unit tests for the ctfindvar tool. +# +# Copyright (C) 2018 Simon Bonnefoy +# +# 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 os +import gammalib +import ctools +from testing import test + + +# ======================= # +# Test class for ctfindvar tool # +# ======================= # +class Test(test): + """ + Test class for ctfindvar tool + + This test class makes unit tests for the ctfindvar tool by using it from + the command line and from Python. + """ + + # Constructor + def __init__(self): + """ + Constructor + """ + # Call base class constructor + test.__init__(self) + + # Return + return + + # Set test functions + def set(self): + """ + Set all test functions + """ + # Set test name + self.name('ctfindvar') + + # Append tests + self.append(self._test_cmd, 'Test ctfindvar on command line') + self.append(self._test_python, 'Test ctfindvar from Python') + + # Return + return + + # Test ctfindvar on command line + def _test_cmd(self): + """ + Test ctfindvar on the command line + """ + # Set tool name + ctfindvar = self._tool('ctfindvar') + + # Setup ctfindvar command + cmd = ctfindvar+' logfile="ctfindvar_cmd1.log" chatter=1' + + # Check if execution was successful + self.test_value(self._execute(cmd), 0, + 'Check successful execution from command line') + + # Check ctfindvar --help + self._check_help(ctfindvar) + + # Return + return + + # Test ctfindvar from Python + def _test_python(self): + """ + Test ctfindvar from Python + """ + # Allocate ctfindvar + tool = ctools.ctfindvar() + + # Check that saving does not nothing + tool['logfile'] = 'ctfindvar_py0.log' + tool.logFileOpen() + tool.save() + self.test_assert(not os.path.isfile('ctfindvar_py0.fits'), + 'Check that no FITS file has been created') + + # Check that clearing does not lead to an exception or segfault + tool.clear() + + # Now set ctfindvar parameters + tool['logfile'] = 'ctfindvar_py1.log' + tool['chatter'] = 2 + + # Run ctfindvar tool + tool.logFileOpen() + tool.run() + + # Check result + self._check_result(tool) + + # Copy ctfindvar tool + cpy_tool = tool.copy() + + # Check result + self._check_result(cpy_tool) + + # Run copy of ctfindvar tool again + cpy_tool['logfile'] = 'ctfindvar_py2.log' + cpy_tool['chatter'] = 3 + cpy_tool.logFileOpen() + cpy_tool.run() + + # Check result + self._check_result(cpy_tool) + + # Return + return + + # Check ctfindvar result + def _check_result(self, tool): + """ + Check content of tool + + Parameters + ---------- + tool : `~ctools.ctfindvar` + ctfindvar instance + """ + # TODO: Implement test on tool result + + # Return + return -- libgit2 0.21.4