From edd8ccb76fcd8566dde29af1b1f1061b7d9a4360 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 9 Jan 2018 16:34:29 +0100 Subject: [PATCH] Add ctools::time_reference constant and remove ctools::time_reference() method (#2295) --- ChangeLog | 1 + NEWS | 6 ++++++ cscripts/cslightcrv.py | 14 +++++++------- cscripts/csobsdef.py | 8 ++++---- cscripts/csobsinfo.py | 6 +++--- cscripts/csviscube.py | 6 +++--- cscripts/obsutils.py | 5 +++-- doc/source/admin/release_history/1.5.rst | 3 +++ pyext/ctool.i | 11 +++++++---- src/ctbin/ctbin.cpp | 2 +- src/ctobssim/ctobssim.cpp | 8 ++++---- src/support/ctool.cpp | 12 ++++++------ src/support/ctool.hpp | 22 +++++++--------------- 13 files changed, 55 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index fb95ce9..fa6aac4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Version 1.5.0 released ======================== + Add ctools::time_reference constant and remove ctools::time_reference() method (#2295) Correctly strip .gz suffix from output filenames (#2287) Support On/Off analysis in cslightcrv and csphasecrv (#2273) Add tutorial for classical analysis (#2267) diff --git a/NEWS b/NEWS index 6cc5cd4..33d45bb 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,12 @@ Support model None +Base classes +------------ +Add ctools::time_reference constant and remove ctools::time_reference() method +(#2295). + + ctbin - CTA event binning ------------------------- None diff --git a/cscripts/cslightcrv.py b/cscripts/cslightcrv.py index bf99296..590b079 100755 --- a/cscripts/cslightcrv.py +++ b/cscripts/cslightcrv.py @@ -2,7 +2,7 @@ # ========================================================================== # Generates a lightcurve. # -# Copyright (C) 2014-2017 Michael Mayer +# Copyright (C) 2014-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -174,8 +174,8 @@ class cslightcrv(ctools.csobservation): elif algorithm == 'LIN': # Get start and stop time and number of time bins - time_min = self['tmin'].time(self._time_reference()) - time_max = self['tmax'].time(self._time_reference()) + time_min = self['tmin'].time(ctools.time_reference) + time_max = self['tmax'].time(ctools.time_reference) nbins = self['tbins'].integer() # Compute time step in seconds and setup the GTIs @@ -386,8 +386,8 @@ class cslightcrv(ctools.csobservation): select = ctools.ctselect(self.obs()) select['emin'] = self['emin'].real() select['emax'] = self['emax'].real() - select['tmin'] = tmin.convert(self._time_reference()) - select['tmax'] = tmax.convert(self._time_reference()) + select['tmin'] = tmin.convert(ctools.time_reference) + select['tmax'] = tmax.convert(ctools.time_reference) select['rad'] = 'UNDEFINED' select['ra'] = 'UNDEFINED' select['dec'] = 'UNDEFINED' @@ -445,8 +445,8 @@ class cslightcrv(ctools.csobservation): select = ctools.ctselect(self.obs()) select['emin'] = self['emin'].real() select['emax'] = self['emax'].real() - select['tmin'] = tmin.convert(self._time_reference()) - select['tmax'] = tmax.convert(self._time_reference()) + select['tmin'] = tmin.convert(ctools.time_reference) + select['tmax'] = tmax.convert(ctools.time_reference) select['rad'] = 'UNDEFINED' select['ra'] = 'UNDEFINED' select['dec'] = 'UNDEFINED' diff --git a/cscripts/csobsdef.py b/cscripts/csobsdef.py index 279ffd3..3e7c4b0 100755 --- a/cscripts/csobsdef.py +++ b/cscripts/csobsdef.py @@ -2,7 +2,7 @@ # ========================================================================== # Generation of an observation definition file # -# Copyright (C) 2015-2017 Juergen Knoedlseder +# Copyright (C) 2015-2018 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -274,9 +274,9 @@ class csobsdef(ctools.cscript): duration = self['duration'].real() tmin = self._tmin tmax = self._tmin + duration - gti = gammalib.GGti(self._time_reference()) - tstart = gammalib.GTime(tmin, self._time_reference()) - tstop = gammalib.GTime(tmax, self._time_reference()) + gti = gammalib.GGti(ctools.time_reference) + tstart = gammalib.GTime(tmin, ctools.time_reference) + tstop = gammalib.GTime(tmax, ctools.time_reference) self._tmin = tmax gti.append(tstart, tstop) obs.ontime(gti.ontime()) diff --git a/cscripts/csobsinfo.py b/cscripts/csobsinfo.py index 2d4458e..36d3c39 100755 --- a/cscripts/csobsinfo.py +++ b/cscripts/csobsinfo.py @@ -2,7 +2,7 @@ # ========================================================================== # Dump information about observation into log file # -# Copyright (C) 2015-2017 Michael Mayer +# Copyright (C) 2015-2018 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -291,8 +291,8 @@ class csobsinfo(ctools.csobservation): # Log time range mjd = '%.3f - %.3f' % (self._gti.tstart().mjd(), self._gti.tstop().mjd()) utc = '%s - %s' % (self._gti.tstart().utc(), self._gti.tstop().utc()) - met = '%.3f - %.3f' % (self._gti.tstart().convert(self._time_reference()), - self._gti.tstop().convert(self._time_reference())) + met = '%.3f - %.3f' % (self._gti.tstart().convert(ctools.time_reference), + self._gti.tstop().convert(ctools.time_reference)) self._log_header3(gammalib.NORMAL, 'Time range') self._log_value(gammalib.NORMAL, 'MJD (days)', mjd) self._log_value(gammalib.NORMAL, 'UTC', utc) diff --git a/cscripts/csviscube.py b/cscripts/csviscube.py index 5e08194..17a52ff 100755 --- a/cscripts/csviscube.py +++ b/cscripts/csviscube.py @@ -2,7 +2,7 @@ # ========================================================================== # Compute a visibility cube # -# Copyright (C) 2016-2017 Juergen Knoedlseder +# Copyright (C) 2016-2018 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -260,8 +260,8 @@ class csviscube(ctools.cscript): #geolon = self['geolon'].real() # Get time interval - tmin = self['tmin'].time(self._time_reference()) - tmax = self['tmax'].time(self._time_reference()) + tmin = self['tmin'].time(ctools.time_reference) + tmax = self['tmax'].time(ctools.time_reference) # Initialise hour angle list hour_angles = [] diff --git a/cscripts/obsutils.py b/cscripts/obsutils.py index 10af62c..f7018a2 100755 --- a/cscripts/obsutils.py +++ b/cscripts/obsutils.py @@ -280,8 +280,9 @@ def set_obs(pntdir, tstart=0.0, duration=1800.0, deadc=0.98, \ roi.radius(rad) # Set GTI - gti = gammalib.GGti() - gti.append(gammalib.GTime(tstart), gammalib.GTime(tstart+duration)) + gti = gammalib.GGti(ctools.time_reference) + gti.append(gammalib.GTime(tstart, ctools.time_reference), + gammalib.GTime(tstart+duration, ctools.time_reference)) # Set energy boundaries ebounds = gammalib.GEbounds(gammalib.GEnergy(emin, 'TeV'), diff --git a/doc/source/admin/release_history/1.5.rst b/doc/source/admin/release_history/1.5.rst index b23d1f9..46e85a1 100644 --- a/doc/source/admin/release_history/1.5.rst +++ b/doc/source/admin/release_history/1.5.rst @@ -26,6 +26,9 @@ Bug fixes Improvements ------------ +* [`2295 `_] - + Add ``ctools::time_reference`` constant and remove ``ctools::time_reference()`` + method * [`2273 `_] - Support On/Off analysis in :ref:`cslightcrv` and :ref:`csphasecrv` * [`2267 `_] - diff --git a/pyext/ctool.i b/pyext/ctool.i index 0e53f5b..489ceac 100644 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -1,7 +1,7 @@ /*************************************************************************** * ctool - ctool base class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2017 by Juergen Knoedlseder * + * copyright (C) 2014-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -28,7 +28,6 @@ #define SWIG #include "ctool.hpp" - /***********************************************************************//** * @class cscript * @@ -57,6 +56,12 @@ public: // arguments to GApplication constructor %include "argcargv.i" +/* __ Constants __________________________________________________________ */ +namespace ctools { + const GTimeReference time_reference = + GTimeReference(G_CTA_MJDREF, "s", "TT", "LOCAL"); +} + /***********************************************************************//** * @class ctool @@ -83,7 +88,6 @@ public: // Make methods private in Python by prepending an underscore %rename(_read_ahead) read_ahead; - %rename(_time_reference) time_reference; %rename(_get_observations) get_observations; %rename(_setup_observations) setup_observations; %rename(_setup_models) setup_models; @@ -119,7 +123,6 @@ public: // Protected methods const bool& read_ahead(void) const; - const GTimeReference& time_reference(void) const; // Protected high-level setup methods void setup_observations(GObservations& obs, const bool& response = true, diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index fc008c3..0b1c967 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -386,7 +386,7 @@ void ctbin::init_members(void) m_dirs.clear(); // Set CTA reference time - m_gti.reference(m_cta_ref); + m_gti.reference(ctools::time_reference); // Return return; diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index 3172d74..2e8c2f9 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -790,9 +790,9 @@ void ctobssim::simulate_source(GCTAObservation* obs, wrklog->indent(indent); } *wrklog << gammalib::parformat("Time interval", indent); - *wrklog << tmin.convert(m_cta_ref); + *wrklog << tmin.convert(ctools::time_reference); *wrklog << " - "; - *wrklog << tmax.convert(m_cta_ref); + *wrklog << tmax.convert(ctools::time_reference); *wrklog << " s" << std::endl; } @@ -1057,8 +1057,8 @@ void ctobssim::simulate_interval(GCTAObservation* obs, wrklog->indent(indent); } *wrklog << gammalib::parformat("Time slice", indent); - *wrklog << tstart.convert(m_cta_ref) << " - "; - *wrklog << tstop.convert(m_cta_ref) << " s"; + *wrklog << tstart.convert(ctools::time_reference) << " - "; + *wrklog << tstop.convert(ctools::time_reference) << " s"; if (model->name().length() > 0) { *wrklog << " [" << model->name() << "]"; } diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index 027d386..119bead 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctool - ctool base class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2017 by Juergen Knoedlseder * + * copyright (C) 2014-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -253,7 +253,7 @@ void ctool::init_members(void) // Set CTA time reference. G_CTA_MJDREF is the CTA reference MJD, // which is defined in GCTALib.hpp. This is somehow a kluge. We need // a better mechanism to implement the CTA reference MJD. - m_cta_ref.set(G_CTA_MJDREF, "s", "TT", "LOCAL"); + //m_cta_ref.set(G_CTA_MJDREF, "s", "TT", "LOCAL"); // Set logger properties log.date(true); @@ -276,7 +276,7 @@ void ctool::copy_members(const ctool& app) // Copy members m_read_ahead = app.m_read_ahead; m_use_xml = app.m_use_xml; - m_cta_ref = app.m_cta_ref; + //m_cta_ref = app.m_cta_ref; // Return return; @@ -1059,14 +1059,14 @@ GEbounds ctool::get_ebounds(void) GGti ctool::get_gti(void) { // Initialise Good Time Intervals with CTA reference time - GGti gti(m_cta_ref); + GGti gti(ctools::time_reference); // Continue only if "tmin" has a valid time value if ((*this)["tmin"].is_valid() && (*this)["tmax"].is_valid()) { // Get minimum and maximum time for CTA time reference - GTime tmin = (*this)["tmin"].time(m_cta_ref); - GTime tmax = (*this)["tmax"].time(m_cta_ref); + GTime tmin = (*this)["tmin"].time(ctools::time_reference); + GTime tmax = (*this)["tmax"].time(ctools::time_reference); // Append GTI gti.append(tmin, tmax); diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index 97c66e9..054ae6a 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctool - ctool base class * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2017 by Juergen Knoedlseder * + * copyright (C) 2014-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,6 +33,12 @@ /* __Definitions _________________________________________________________ */ +/* __ Constants __________________________________________________________ */ +namespace ctools { + const GTimeReference time_reference = + GTimeReference(G_CTA_MJDREF, "s", "TT", "LOCAL"); +} + /***********************************************************************//** * @class ctool @@ -75,7 +81,6 @@ protected: void copy_members(const ctool& app); void free_members(void); const bool& read_ahead(void) const; - const GTimeReference& time_reference(void) const; // Protected high-level setup methods void setup_observations(GObservations& obs, const bool& response = true, @@ -151,7 +156,6 @@ protected: // Protected members bool m_use_xml; //!< Use XML file instead of FITS file for observations - GTimeReference m_cta_ref; //!< CTA time reference }; @@ -173,18 +177,6 @@ const bool& ctool::read_ahead(void) const /***********************************************************************//** - * @brief Return time reference - * - * @return Reference to time reference - ***************************************************************************/ -inline -const GTimeReference& ctool::time_reference(void) const -{ - return (m_cta_ref); -} - - -/***********************************************************************//** * @brief Check of a filename is valid * * @return True if filename is valid -- libgit2 0.21.4