Commit edd8ccb76fcd8566dde29af1b1f1061b7d9a4360

Authored by Jürgen Knödlseder
1 parent 376dca09

Add ctools::time_reference constant and remove ctools::time_reference() method (#2295)

ChangeLog
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 * Version 1.5.0 released 3 * Version 1.5.0 released
4 ======================== 4 ========================
5 5
  6 + Add ctools::time_reference constant and remove ctools::time_reference() method (#2295)
6 Correctly strip .gz suffix from output filenames (#2287) 7 Correctly strip .gz suffix from output filenames (#2287)
7 Support On/Off analysis in cslightcrv and csphasecrv (#2273) 8 Support On/Off analysis in cslightcrv and csphasecrv (#2273)
8 Add tutorial for classical analysis (#2267) 9 Add tutorial for classical analysis (#2267)
@@ -24,6 +24,12 @@ Support model @@ -24,6 +24,12 @@ Support model
24 None 24 None
25 25
26 26
  27 +Base classes
  28 +------------
  29 +Add ctools::time_reference constant and remove ctools::time_reference() method
  30 +(#2295).
  31 +
  32 +
27 ctbin - CTA event binning 33 ctbin - CTA event binning
28 ------------------------- 34 -------------------------
29 None 35 None
cscripts/cslightcrv.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Generates a lightcurve. 3 # Generates a lightcurve.
4 # 4 #
5 -# Copyright (C) 2014-2017 Michael Mayer 5 +# Copyright (C) 2014-2018 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 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 8 # it under the terms of the GNU General Public License as published by
@@ -174,8 +174,8 @@ class cslightcrv(ctools.csobservation): @@ -174,8 +174,8 @@ class cslightcrv(ctools.csobservation):
174 elif algorithm == 'LIN': 174 elif algorithm == 'LIN':
175 175
176 # Get start and stop time and number of time bins 176 # Get start and stop time and number of time bins
177 - time_min = self['tmin'].time(self._time_reference())  
178 - time_max = self['tmax'].time(self._time_reference()) 177 + time_min = self['tmin'].time(ctools.time_reference)
  178 + time_max = self['tmax'].time(ctools.time_reference)
179 nbins = self['tbins'].integer() 179 nbins = self['tbins'].integer()
180 180
181 # Compute time step in seconds and setup the GTIs 181 # Compute time step in seconds and setup the GTIs
@@ -386,8 +386,8 @@ class cslightcrv(ctools.csobservation): @@ -386,8 +386,8 @@ class cslightcrv(ctools.csobservation):
386 select = ctools.ctselect(self.obs()) 386 select = ctools.ctselect(self.obs())
387 select['emin'] = self['emin'].real() 387 select['emin'] = self['emin'].real()
388 select['emax'] = self['emax'].real() 388 select['emax'] = self['emax'].real()
389 - select['tmin'] = tmin.convert(self._time_reference())  
390 - select['tmax'] = tmax.convert(self._time_reference()) 389 + select['tmin'] = tmin.convert(ctools.time_reference)
  390 + select['tmax'] = tmax.convert(ctools.time_reference)
391 select['rad'] = 'UNDEFINED' 391 select['rad'] = 'UNDEFINED'
392 select['ra'] = 'UNDEFINED' 392 select['ra'] = 'UNDEFINED'
393 select['dec'] = 'UNDEFINED' 393 select['dec'] = 'UNDEFINED'
@@ -445,8 +445,8 @@ class cslightcrv(ctools.csobservation): @@ -445,8 +445,8 @@ class cslightcrv(ctools.csobservation):
445 select = ctools.ctselect(self.obs()) 445 select = ctools.ctselect(self.obs())
446 select['emin'] = self['emin'].real() 446 select['emin'] = self['emin'].real()
447 select['emax'] = self['emax'].real() 447 select['emax'] = self['emax'].real()
448 - select['tmin'] = tmin.convert(self._time_reference())  
449 - select['tmax'] = tmax.convert(self._time_reference()) 448 + select['tmin'] = tmin.convert(ctools.time_reference)
  449 + select['tmax'] = tmax.convert(ctools.time_reference)
450 select['rad'] = 'UNDEFINED' 450 select['rad'] = 'UNDEFINED'
451 select['ra'] = 'UNDEFINED' 451 select['ra'] = 'UNDEFINED'
452 select['dec'] = 'UNDEFINED' 452 select['dec'] = 'UNDEFINED'
cscripts/csobsdef.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Generation of an observation definition file 3 # Generation of an observation definition file
4 # 4 #
5 -# Copyright (C) 2015-2017 Juergen Knoedlseder 5 +# Copyright (C) 2015-2018 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 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 8 # it under the terms of the GNU General Public License as published by
@@ -274,9 +274,9 @@ class csobsdef(ctools.cscript): @@ -274,9 +274,9 @@ class csobsdef(ctools.cscript):
274 duration = self['duration'].real() 274 duration = self['duration'].real()
275 tmin = self._tmin 275 tmin = self._tmin
276 tmax = self._tmin + duration 276 tmax = self._tmin + duration
277 - gti = gammalib.GGti(self._time_reference())  
278 - tstart = gammalib.GTime(tmin, self._time_reference())  
279 - tstop = gammalib.GTime(tmax, self._time_reference()) 277 + gti = gammalib.GGti(ctools.time_reference)
  278 + tstart = gammalib.GTime(tmin, ctools.time_reference)
  279 + tstop = gammalib.GTime(tmax, ctools.time_reference)
280 self._tmin = tmax 280 self._tmin = tmax
281 gti.append(tstart, tstop) 281 gti.append(tstart, tstop)
282 obs.ontime(gti.ontime()) 282 obs.ontime(gti.ontime())
cscripts/csobsinfo.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Dump information about observation into log file 3 # Dump information about observation into log file
4 # 4 #
5 -# Copyright (C) 2015-2017 Michael Mayer 5 +# Copyright (C) 2015-2018 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 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 8 # it under the terms of the GNU General Public License as published by
@@ -291,8 +291,8 @@ class csobsinfo(ctools.csobservation): @@ -291,8 +291,8 @@ class csobsinfo(ctools.csobservation):
291 # Log time range 291 # Log time range
292 mjd = '%.3f - %.3f' % (self._gti.tstart().mjd(), self._gti.tstop().mjd()) 292 mjd = '%.3f - %.3f' % (self._gti.tstart().mjd(), self._gti.tstop().mjd())
293 utc = '%s - %s' % (self._gti.tstart().utc(), self._gti.tstop().utc()) 293 utc = '%s - %s' % (self._gti.tstart().utc(), self._gti.tstop().utc())
294 - met = '%.3f - %.3f' % (self._gti.tstart().convert(self._time_reference()),  
295 - self._gti.tstop().convert(self._time_reference())) 294 + met = '%.3f - %.3f' % (self._gti.tstart().convert(ctools.time_reference),
  295 + self._gti.tstop().convert(ctools.time_reference))
296 self._log_header3(gammalib.NORMAL, 'Time range') 296 self._log_header3(gammalib.NORMAL, 'Time range')
297 self._log_value(gammalib.NORMAL, 'MJD (days)', mjd) 297 self._log_value(gammalib.NORMAL, 'MJD (days)', mjd)
298 self._log_value(gammalib.NORMAL, 'UTC', utc) 298 self._log_value(gammalib.NORMAL, 'UTC', utc)
cscripts/csviscube.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Compute a visibility cube 3 # Compute a visibility cube
4 # 4 #
5 -# Copyright (C) 2016-2017 Juergen Knoedlseder 5 +# Copyright (C) 2016-2018 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 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 8 # it under the terms of the GNU General Public License as published by
@@ -260,8 +260,8 @@ class csviscube(ctools.cscript): @@ -260,8 +260,8 @@ class csviscube(ctools.cscript):
260 #geolon = self['geolon'].real() 260 #geolon = self['geolon'].real()
261 261
262 # Get time interval 262 # Get time interval
263 - tmin = self['tmin'].time(self._time_reference())  
264 - tmax = self['tmax'].time(self._time_reference()) 263 + tmin = self['tmin'].time(ctools.time_reference)
  264 + tmax = self['tmax'].time(ctools.time_reference)
265 265
266 # Initialise hour angle list 266 # Initialise hour angle list
267 hour_angles = [] 267 hour_angles = []
cscripts/obsutils.py
@@ -280,8 +280,9 @@ def set_obs(pntdir, tstart=0.0, duration=1800.0, deadc=0.98, \ @@ -280,8 +280,9 @@ def set_obs(pntdir, tstart=0.0, duration=1800.0, deadc=0.98, \
280 roi.radius(rad) 280 roi.radius(rad)
281 281
282 # Set GTI 282 # Set GTI
283 - gti = gammalib.GGti()  
284 - gti.append(gammalib.GTime(tstart), gammalib.GTime(tstart+duration)) 283 + gti = gammalib.GGti(ctools.time_reference)
  284 + gti.append(gammalib.GTime(tstart, ctools.time_reference),
  285 + gammalib.GTime(tstart+duration, ctools.time_reference))
285 286
286 # Set energy boundaries 287 # Set energy boundaries
287 ebounds = gammalib.GEbounds(gammalib.GEnergy(emin, 'TeV'), 288 ebounds = gammalib.GEbounds(gammalib.GEnergy(emin, 'TeV'),
doc/source/admin/release_history/1.5.rst
@@ -26,6 +26,9 @@ Bug fixes @@ -26,6 +26,9 @@ Bug fixes
26 Improvements 26 Improvements
27 ------------ 27 ------------
28 28
  29 +* [`2295 <https://cta-redmine.irap.omp.eu/issues/2295>`_] -
  30 + Add ``ctools::time_reference`` constant and remove ``ctools::time_reference()``
  31 + method
29 * [`2273 <https://cta-redmine.irap.omp.eu/issues/2273>`_] - 32 * [`2273 <https://cta-redmine.irap.omp.eu/issues/2273>`_] -
30 Support On/Off analysis in :ref:`cslightcrv` and :ref:`csphasecrv` 33 Support On/Off analysis in :ref:`cslightcrv` and :ref:`csphasecrv`
31 * [`2267 <https://cta-redmine.irap.omp.eu/issues/2267>`_] - 34 * [`2267 <https://cta-redmine.irap.omp.eu/issues/2267>`_] -
pyext/ctool.i
1 /*************************************************************************** 1 /***************************************************************************
2 * ctool - ctool base class * 2 * ctool - ctool base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2014-2017 by Juergen Knoedlseder * 4 + * copyright (C) 2014-2018 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -28,7 +28,6 @@ @@ -28,7 +28,6 @@
28 #define SWIG 28 #define SWIG
29 #include "ctool.hpp" 29 #include "ctool.hpp"
30 30
31 -  
32 /***********************************************************************//** 31 /***********************************************************************//**
33 * @class cscript 32 * @class cscript
34 * 33 *
@@ -57,6 +56,12 @@ public: @@ -57,6 +56,12 @@ public:
57 // arguments to GApplication constructor 56 // arguments to GApplication constructor
58 %include "argcargv.i" 57 %include "argcargv.i"
59 58
  59 +/* __ Constants __________________________________________________________ */
  60 +namespace ctools {
  61 + const GTimeReference time_reference =
  62 + GTimeReference(G_CTA_MJDREF, "s", "TT", "LOCAL");
  63 +}
  64 +
60 65
61 /***********************************************************************//** 66 /***********************************************************************//**
62 * @class ctool 67 * @class ctool
@@ -83,7 +88,6 @@ public: @@ -83,7 +88,6 @@ public:
83 88
84 // Make methods private in Python by prepending an underscore 89 // Make methods private in Python by prepending an underscore
85 %rename(_read_ahead) read_ahead; 90 %rename(_read_ahead) read_ahead;
86 - %rename(_time_reference) time_reference;  
87 %rename(_get_observations) get_observations; 91 %rename(_get_observations) get_observations;
88 %rename(_setup_observations) setup_observations; 92 %rename(_setup_observations) setup_observations;
89 %rename(_setup_models) setup_models; 93 %rename(_setup_models) setup_models;
@@ -119,7 +123,6 @@ public: @@ -119,7 +123,6 @@ public:
119 123
120 // Protected methods 124 // Protected methods
121 const bool& read_ahead(void) const; 125 const bool& read_ahead(void) const;
122 - const GTimeReference& time_reference(void) const;  
123 126
124 // Protected high-level setup methods 127 // Protected high-level setup methods
125 void setup_observations(GObservations& obs, const bool& response = true, 128 void setup_observations(GObservations& obs, const bool& response = true,
src/ctbin/ctbin.cpp
@@ -386,7 +386,7 @@ void ctbin::init_members(void) @@ -386,7 +386,7 @@ void ctbin::init_members(void)
386 m_dirs.clear(); 386 m_dirs.clear();
387 387
388 // Set CTA reference time 388 // Set CTA reference time
389 - m_gti.reference(m_cta_ref); 389 + m_gti.reference(ctools::time_reference);
390 390
391 // Return 391 // Return
392 return; 392 return;
src/ctobssim/ctobssim.cpp
@@ -790,9 +790,9 @@ void ctobssim::simulate_source(GCTAObservation* obs, @@ -790,9 +790,9 @@ void ctobssim::simulate_source(GCTAObservation* obs,
790 wrklog->indent(indent); 790 wrklog->indent(indent);
791 } 791 }
792 *wrklog << gammalib::parformat("Time interval", indent); 792 *wrklog << gammalib::parformat("Time interval", indent);
793 - *wrklog << tmin.convert(m_cta_ref); 793 + *wrklog << tmin.convert(ctools::time_reference);
794 *wrklog << " - "; 794 *wrklog << " - ";
795 - *wrklog << tmax.convert(m_cta_ref); 795 + *wrklog << tmax.convert(ctools::time_reference);
796 *wrklog << " s" << std::endl; 796 *wrklog << " s" << std::endl;
797 } 797 }
798 798
@@ -1057,8 +1057,8 @@ void ctobssim::simulate_interval(GCTAObservation* obs, @@ -1057,8 +1057,8 @@ void ctobssim::simulate_interval(GCTAObservation* obs,
1057 wrklog->indent(indent); 1057 wrklog->indent(indent);
1058 } 1058 }
1059 *wrklog << gammalib::parformat("Time slice", indent); 1059 *wrklog << gammalib::parformat("Time slice", indent);
1060 - *wrklog << tstart.convert(m_cta_ref) << " - ";  
1061 - *wrklog << tstop.convert(m_cta_ref) << " s"; 1060 + *wrklog << tstart.convert(ctools::time_reference) << " - ";
  1061 + *wrklog << tstop.convert(ctools::time_reference) << " s";
1062 if (model->name().length() > 0) { 1062 if (model->name().length() > 0) {
1063 *wrklog << " [" << model->name() << "]"; 1063 *wrklog << " [" << model->name() << "]";
1064 } 1064 }
src/support/ctool.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctool - ctool base class * 2 * ctool - ctool base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2014-2017 by Juergen Knoedlseder * 4 + * copyright (C) 2014-2018 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -253,7 +253,7 @@ void ctool::init_members(void) @@ -253,7 +253,7 @@ void ctool::init_members(void)
253 // Set CTA time reference. G_CTA_MJDREF is the CTA reference MJD, 253 // Set CTA time reference. G_CTA_MJDREF is the CTA reference MJD,
254 // which is defined in GCTALib.hpp. This is somehow a kluge. We need 254 // which is defined in GCTALib.hpp. This is somehow a kluge. We need
255 // a better mechanism to implement the CTA reference MJD. 255 // a better mechanism to implement the CTA reference MJD.
256 - m_cta_ref.set(G_CTA_MJDREF, "s", "TT", "LOCAL"); 256 + //m_cta_ref.set(G_CTA_MJDREF, "s", "TT", "LOCAL");
257 257
258 // Set logger properties 258 // Set logger properties
259 log.date(true); 259 log.date(true);
@@ -276,7 +276,7 @@ void ctool::copy_members(const ctool&amp; app) @@ -276,7 +276,7 @@ void ctool::copy_members(const ctool&amp; app)
276 // Copy members 276 // Copy members
277 m_read_ahead = app.m_read_ahead; 277 m_read_ahead = app.m_read_ahead;
278 m_use_xml = app.m_use_xml; 278 m_use_xml = app.m_use_xml;
279 - m_cta_ref = app.m_cta_ref; 279 + //m_cta_ref = app.m_cta_ref;
280 280
281 // Return 281 // Return
282 return; 282 return;
@@ -1059,14 +1059,14 @@ GEbounds ctool::get_ebounds(void) @@ -1059,14 +1059,14 @@ GEbounds ctool::get_ebounds(void)
1059 GGti ctool::get_gti(void) 1059 GGti ctool::get_gti(void)
1060 { 1060 {
1061 // Initialise Good Time Intervals with CTA reference time 1061 // Initialise Good Time Intervals with CTA reference time
1062 - GGti gti(m_cta_ref); 1062 + GGti gti(ctools::time_reference);
1063 1063
1064 // Continue only if "tmin" has a valid time value 1064 // Continue only if "tmin" has a valid time value
1065 if ((*this)["tmin"].is_valid() && (*this)["tmax"].is_valid()) { 1065 if ((*this)["tmin"].is_valid() && (*this)["tmax"].is_valid()) {
1066 1066
1067 // Get minimum and maximum time for CTA time reference 1067 // Get minimum and maximum time for CTA time reference
1068 - GTime tmin = (*this)["tmin"].time(m_cta_ref);  
1069 - GTime tmax = (*this)["tmax"].time(m_cta_ref); 1068 + GTime tmin = (*this)["tmin"].time(ctools::time_reference);
  1069 + GTime tmax = (*this)["tmax"].time(ctools::time_reference);
1070 1070
1071 // Append GTI 1071 // Append GTI
1072 gti.append(tmin, tmax); 1072 gti.append(tmin, tmax);
src/support/ctool.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctool - ctool base class * 2 * ctool - ctool base class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2014-2017 by Juergen Knoedlseder * 4 + * copyright (C) 2014-2018 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -33,6 +33,12 @@ @@ -33,6 +33,12 @@
33 33
34 /* __Definitions _________________________________________________________ */ 34 /* __Definitions _________________________________________________________ */
35 35
  36 +/* __ Constants __________________________________________________________ */
  37 +namespace ctools {
  38 + const GTimeReference time_reference =
  39 + GTimeReference(G_CTA_MJDREF, "s", "TT", "LOCAL");
  40 +}
  41 +
36 42
37 /***********************************************************************//** 43 /***********************************************************************//**
38 * @class ctool 44 * @class ctool
@@ -75,7 +81,6 @@ protected: @@ -75,7 +81,6 @@ protected:
75 void copy_members(const ctool& app); 81 void copy_members(const ctool& app);
76 void free_members(void); 82 void free_members(void);
77 const bool& read_ahead(void) const; 83 const bool& read_ahead(void) const;
78 - const GTimeReference& time_reference(void) const;  
79 84
80 // Protected high-level setup methods 85 // Protected high-level setup methods
81 void setup_observations(GObservations& obs, const bool& response = true, 86 void setup_observations(GObservations& obs, const bool& response = true,
@@ -151,7 +156,6 @@ protected: @@ -151,7 +156,6 @@ protected:
151 156
152 // Protected members 157 // Protected members
153 bool m_use_xml; //!< Use XML file instead of FITS file for observations 158 bool m_use_xml; //!< Use XML file instead of FITS file for observations
154 - GTimeReference m_cta_ref; //!< CTA time reference  
155 }; 159 };
156 160
157 161
@@ -173,18 +177,6 @@ const bool&amp; ctool::read_ahead(void) const @@ -173,18 +177,6 @@ const bool&amp; ctool::read_ahead(void) const
173 177
174 178
175 /***********************************************************************//** 179 /***********************************************************************//**
176 - * @brief Return time reference  
177 - *  
178 - * @return Reference to time reference  
179 - ***************************************************************************/  
180 -inline  
181 -const GTimeReference& ctool::time_reference(void) const  
182 -{  
183 - return (m_cta_ref);  
184 -}  
185 -  
186 -  
187 -/***********************************************************************//**  
188 * @brief Check of a filename is valid 180 * @brief Check of a filename is valid
189 * 181 *
190 * @return True if filename is valid 182 * @return True if filename is valid