Commit 19dd9c214fc798626fd50156a4ca296dabfae5d1

Authored by Jürgen Knödlseder
1 parent 72de0cfb

Use t-type parameters for all "tmin" and "tmax" parameters (#1864)

ChangeLog
1   -2017-08-01
  1 +2017-08-08
2 2  
3 3 * Version 1.5.0 released
4 4 ========================
5 5  
  6 + Use t-type parameters for all "tmin" and "tmax" parameters (#1864)
  7 +
6 8  
7 9 2017-07-28
8 10  
... ...
1 1 New Features and Important Changes in ctools 1.5.0
2 2  
3   -1 August 2017
  3 +8 August 2017
4 4  
5 5  
6 6 Introduction
... ... @@ -26,12 +26,14 @@ None
26 26  
27 27 ctobssim - CTA observation simulation
28 28 -------------------------------------
29   -None
  29 +Use t-type parameters for "tmin" and "tmax" to all specifying times in various
  30 +formats (#1864).
30 31  
31 32  
32 33 ctselect - CTA event selection
33 34 ------------------------------
34   -None
  35 +Use t-type parameters for "tmin" and "tmax" to all specifying times in various
  36 +formats (#1864).
35 37  
36 38  
37 39 ctbin - CTA event binning
... ... @@ -56,7 +58,8 @@ None
56 58  
57 59 ctmodel - CTA counts cube modelling
58 60 -----------------------------------
59   -None
  61 +Use t-type parameters for "tmin" and "tmax" to all specifying times in various
  62 +formats (#1864).
60 63  
61 64  
62 65 ctexpcube - CTA exposure cube generation
... ... @@ -116,7 +119,8 @@ None
116 119  
117 120 cscripts
118 121 --------
119   -None
  122 +Use t-type parameters for "tmin" and "tmax" to all specifying times in various
  123 +formats (#1864).
120 124  
121 125  
122 126 Examples
... ...
cscripts/csebins.py
... ... @@ -22,7 +22,6 @@ import sys
22 22 import math
23 23 import gammalib
24 24 import ctools
25   -#from cscripts import obsutils
26 25  
27 26  
28 27 # ============= #
... ... @@ -175,7 +174,7 @@ class csebins(ctools.cscript):
175 174  
176 175 # Build list of response dictionaries
177 176 responses = []
178   -
  177 +
179 178 # Loop over all observations
180 179 for run in obs:
181 180  
... ...
cscripts/cslightcrv.par
... ... @@ -28,8 +28,8 @@ outfile, f, a, lightcurve.fits,,, "Output light curve file"
28 28 # Script parameters
29 29 #==================
30 30 tbinalg, s, a, GTI,FILE|LIN|GTI,, "Algorithm for defining time bins"
31   -tmin, r, a, 51544.5,,,"Lightcurve start time (MJD)"
32   -tmax, r, a, 51544.6,,,"Lightcurve stop time (MJD)"
  31 +tmin, t, a, MJD 51544.5,,,"Lightcurve start time (UTC string, JD, MJD or time in seconds)"
  32 +tmax, t, a, MJD 51544.6,,,"Lightcurve stop time (UTC string, JD, MJD or time in seconds)"
33 33 tbins, i, a, 5,1,10000, "Number of time bins"
34 34 tbinfile, f, a, NONE,,, "File defining the time binning"
35 35 emin, r, a, 0.1,,, "Lower energy limit of events (TeV)"
... ...
cscripts/cslightcrv.py
... ... @@ -191,17 +191,15 @@ class cslightcrv(ctools.cscript):
191 191 elif algorithm == 'LIN':
192 192  
193 193 # Get start and stop time and number of time bins
194   - time_min = self['tmin'].real()
195   - time_max = self['tmax'].real()
  194 + time_min = self['tmin'].time(self._time_reference())
  195 + time_max = self['tmax'].time(self._time_reference())
196 196 nbins = self['tbins'].integer()
197 197  
198   - # Compute time step and setup the GTIs
  198 + # Compute time step in seconds and setup the GTIs
199 199 time_step = (time_max - time_min) / float(nbins)
200 200 for i in range(nbins):
201   - tmin = gammalib.GTime()
202   - tmax = gammalib.GTime()
203   - tmin.mjd(time_min + i *time_step)
204   - tmax.mjd(time_min + (i+1)*time_step)
  201 + tmin = time_min + i *time_step
  202 + tmax = time_min + (i+1)*time_step
205 203 gti.append(tmin,tmax)
206 204  
207 205 # If the algorithm is "GTI" then extract the GTIs from the observations
... ...
cscripts/cspull.par
... ... @@ -28,20 +28,20 @@ outfile, f, a, pull.dat,,, "Output pull distribution file"
28 28 # Script parameters
29 29 #==================
30 30 ntrials, i, a, 10,,, "Number of trials"
31   -ra, r, a, 83.6331,0,360, "RA of pointing (deg)"
32   -dec, r, a, 22.0145,-90,90, "Dec of pointing (deg)"
  31 +ra, r, a, 83.6331,0,360, "RA of pointing (degrees)"
  32 +dec, r, a, 22.0145,-90,90, "Dec of pointing (degrees)"
33 33 coordsys, s, a, CEL,CEL|GAL,, "Coordinate system (CEL - celestial, GAL - galactic)"
34 34 proj, s, a, TAN,AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN,, "Projection method"
35 35 emin, r, a, 0.1,,, "Lower energy limit (TeV)"
36 36 emax, r, a, 100.0,,, "Upper energy limit (TeV)"
37 37 enumbins, i, a, 0,,, "Number of energy bins (0=unbinned)"
38   -tmin, r, h, 0.0,,, "Start time (MET in s)"
39   -tmax, r, a, 1800.0,,, "Duration (s)"
  38 +tmin, t, a, 2020-01-01T00:00:00,,, "Start time (UTC string, JD, MJD or time in seconds)"
  39 +tmax, t, a, 2020-01-01T00:30:00,,, "Stop time (UTC string, JD, MJD or time in seconds)"
40 40 npix, i, a, 200,,, "Number of pixels for binned"
41   -binsz, r, a, 0.05,,, "Pixel size for binned (deg/pixel)"
42   -rad, r, h, 5.0,0,180, "Radius of ROI (deg)"
  41 +binsz, r, a, 0.05,,, "Pixel size for binned (degrees/pixel)"
  42 +rad, r, h, 5.0,0,180, "Radius of ROI (degrees)"
43 43 pattern, s, h, single,single|four,, "Observation pattern"
44   -offset, r, h, 1.5,,, "Observation pattern offset (deg)"
  44 +offset, r, h, 1.5,,, "Observation pattern offset (degrees)"
45 45 profile, b, h, no,,, "Use likelihood profile method for errors?"
46 46 seed, i, h, 1,,, "Initial random number generator seed"
47 47  
... ...
cscripts/cspull.py
... ... @@ -76,8 +76,10 @@ class cspull(ctools.cscript):
76 76  
77 77 # Check for requested pattern and set wobble pattern
78 78 if self['pattern'].string() == 'four':
  79 + tmin = self['tmin'].time(self._time_reference()).secs()
  80 + duration = self['tmax'].time(self._time_reference()).secs() - tmin
79 81 self._obs = obsutils.set_observations(self['ra'].real(), self['dec'].real(), self['rad'].real(),
80   - self['tmin'].real(), self['tmax'].real(),
  82 + tmin, duration,
81 83 self['emin'].real(), self['emax'].real(),
82 84 self['irf'].string(), self['caldb'].string(),
83 85 deadc=self['deadc'].real(),
... ...
cscripts/cstsdist.par
... ... @@ -33,20 +33,20 @@ outfile, f, a, ts.dat,,, "Output Test Statistic distribution file"
33 33 # Script parameters
34 34 #==================
35 35 ntrials, i, a, 10,,, "Number of trials"
36   -ra, r, a, 83.63,0,360, "RA of pointing (deg)"
37   -dec, r, a, 22.01,-90,90, "Dec of pointing (deg)"
  36 +ra, r, a, 83.63,0,360, "RA of pointing (degrees)"
  37 +dec, r, a, 22.01,-90,90, "Dec of pointing (degrees)"
38 38 coordsys, s, a, CEL,CEL|GAL,, "Coordinate system (CEL - celestial, GAL - galactic)"
39 39 proj, s, a, TAN,AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN,, "Projection method"
40 40 emin, r, a, 0.1,,, "Lower energy limit (TeV)"
41 41 emax, r, a, 100.0,,, "Upper energy limit (TeV)"
42 42 enumbins, i, a, 0,,, "Number of energy bins (0=unbinned)"
43   -tmin, r, h, 0.0,,, "Start time (MET in s)"
44   -tmax, r, a, 1800.0,,, "Duration (s)"
  43 +tmin, t, a, 2020-01-01T00:00:00,,, "Start time (UTC string, JD, MJD or time in seconds)"
  44 +tmax, t, a, 2020-01-01T00:30:00,,, "Stop time (UTC string, JD, MJD or time in seconds)"
45 45 npix, i, a, 200,,, "Number of pixels for binned"
46   -binsz, r, a, 0.05,,, "Pixel size for binned (deg/pixel)"
47   -rad, r, h, 5.0,0,180, "Radius of ROI (deg)"
  46 +binsz, r, a, 0.05,,, "Pixel size for binned (degrees/pixel)"
  47 +rad, r, h, 5.0,0,180, "Radius of ROI (degrees)"
48 48 pattern, s, h, single,single|four,, "Observation pattern"
49   -offset, r, h, 1.5,,, "Observation pattern offset (deg)"
  49 +offset, r, h, 1.5,,, "Observation pattern offset (degrees)"
50 50  
51 51 #
52 52 # Standard parameters
... ...
cscripts/cstsdist.py
... ... @@ -68,8 +68,10 @@ class cstsdist(ctools.cscript):
68 68  
69 69 # Check for requested pattern and set wobble pattern
70 70 if self['pattern'].string() == 'four':
  71 + tmin = self['tmin'].time(self._time_reference()).secs()
  72 + duration = self['tmax'].time(self._time_reference()).secs() - tmin
71 73 self._obs = obsutils.set_observations(self['ra'].real(), self['dec'].real(), self['rad'].real(),
72   - self['tmin'].real(), self['tmax'].real(),
  74 + tmin, duration,
73 75 self['emin'].real(), self['emax'].real(),
74 76 self['irf'].string(), self['caldb'].string(),
75 77 deadc=self['deadc'].real(),
... ...
cscripts/csviscube.par
... ... @@ -16,8 +16,8 @@
16 16 #
17 17 # General parameters
18 18 #===================
19   -tmin, r, a, 0.0,,, "Start time (CTA MET in seconds)"
20   -tmax, r, a, 31557600.0,,, "End time (CTA MET in seconds)"
  19 +tmin, t, a, 2020-01-01T00:00:00,,, "Start time of observation (UTC string, JD, MJD or time in seconds)"
  20 +tmax, t, a, 2021-01-01T00:00:00,,, "Stop time of observation (UTC string, JD, MJD or time in seconds)"
21 21 geolon, r, a, 79.4041,,, "Geographic longitude of array (deg)"
22 22 geolat, r, a, -24.6272,,, "Geographic latitude of array (deg)"
23 23 sunzenith, r, h, 105.0,,, "Minimum Sun zenith angle for observations (deg)"
... ...
cscripts/csviscube.py
... ... @@ -36,7 +36,7 @@ class csviscube(ctools.cscript):
36 36 def __init__(self, *argv):
37 37 """
38 38 Constructor
39   -
  39 +
40 40 Parameters
41 41 ----------
42 42 argv : list of str
... ... @@ -68,8 +68,8 @@ class csviscube(ctools.cscript):
68 68 Get all parameters
69 69 """
70 70 # Query parameters
71   - self['tmin'].real()
72   - self['tmax'].real()
  71 + self['tmin'].time()
  72 + self['tmax'].time()
73 73 self['geolon'].real()
74 74 self['geolat'].real()
75 75 self['outfile'].filename()
... ... @@ -107,7 +107,7 @@ class csviscube(ctools.cscript):
107 107  
108 108 The hour angle h (or local hour angle, LHA) is defined as the difference
109 109 between local siderial time (LST) and the Right Ascension
110   -
  110 +
111 111 h = LST - ra
112 112  
113 113 The map is computed for h=-ra which is equivalent to GST=lon (or LST=0).
... ... @@ -234,7 +234,7 @@ class csviscube(ctools.cscript):
234 234 cos_geolat = math.cos(geolat)
235 235 sin_sundec = math.sin(sundec)
236 236 cos_sundec = math.cos(sundec)
237   -
  237 +
238 238 # Compute Right Ascension difference when Sun is below the mimimum
239 239 # zenith angle in degrees
240 240 dra = math.acos((cos_sunzenith - sin_geolat * sin_sundec) /
... ... @@ -264,17 +264,17 @@ class csviscube(ctools.cscript):
264 264 #geolon = self['geolon'].real()
265 265  
266 266 # Get time interval
267   - tmin = gammalib.GTime(self['tmin'].real(), 's')
268   - tmax = gammalib.GTime(self['tmax'].real(), 's')
  267 + tmin = self['tmin'].time(self._time_reference())
  268 + tmax = self['tmax'].time(self._time_reference())
269 269  
270 270 # Initialise hour angle list
271 271 hour_angles = []
272   -
  272 +
273 273 # Set number of hour angle bins and compute conversion factor and weight
274 274 nsteps = 1000
275 275 ra2inx = float(nsteps)/360.0 # Conversion from RA (deg) to index
276 276 weight = 24.0/float(nsteps) # Weight per hour angle step
277   -
  277 +
278 278 # Initialise hour angle array and weight
279 279 hours = [0.0 for i in range(nsteps)]
280 280  
... ... @@ -298,11 +298,11 @@ class csviscube(ctools.cscript):
298 298 # Compute the time from now when the Sun will culminate. The time
299 299 # is here expressed in degrees
300 300 dra_sun = self._sun_ra_exclusion(time)
301   -
  301 +
302 302 # Set [0,ra_start] and [ra_stop,360.0]
303 303 ra_start = sunra - dra_sun
304 304 ra_stop = sunra + dra_sun
305   -
  305 +
306 306 # Case 1: The RA interval during which the Sun is above the zenith
307 307 # angle constraint is fully comprised within the [0,360] interval.
308 308 # In that case the dark time is comprised of two intervals:
... ... @@ -378,7 +378,7 @@ class csviscube(ctools.cscript):
378 378 def _visibility_cube(self):
379 379 """
380 380 Compute visibility cube
381   -
  381 +
382 382 Compute visibility cube by displacing the zenith angle map for all
383 383 hour angles. The visibility cube contains the number of hours a given
384 384 celestial position is visible under a given zenith angle interval.
... ... @@ -475,7 +475,7 @@ class csviscube(ctools.cscript):
475 475  
476 476 # Get outfile parameter
477 477 outfile = self['outfile'].filename()
478   -
  478 +
479 479 # Log file name
480 480 self._log_value(gammalib.NORMAL, 'Visibility cube file', outfile.url())
481 481  
... ...
doc/source/users/reference_manual/cslightcrv.rst
... ... @@ -51,11 +51,11 @@ General parameters
51 51 ``(tbinalg = GTI) <FILE|LIN|GTI> [string]``
52 52 Algorithm for defining time bins.
53 53  
54   -``tmin [real]``
55   - Lightcurve start time (in MJD).
  54 +``tmin [time]``
  55 + Lightcurve start time (UTC string, JD, MJD or time in seconds).
56 56  
57   -``tmax [real]``
58   - Lightcurve stop time (in MJD).
  57 +``tmax [time]``
  58 + Lightcurve stop time (UTC string, JD, MJD or time in seconds).
59 59  
60 60 ``tbins [integer]``
61 61 Number of time bins.
... ...
doc/source/users/reference_manual/cspull.rst
... ... @@ -83,11 +83,11 @@ General parameters
83 83 ``enumbins [integer]``
84 84 Number of energy bins (0=unbinned).
85 85  
86   -``(tmin = 0.0) [real]``
87   - Start time (in seconds).
  86 +``tmin [time]``
  87 + Start time (UTC string, JD, MJD or time in seconds).
88 88  
89   -``tmax [real]``
90   - Stop time (in seconds).
  89 +``tmax [time]``
  90 + Stop time (UTC string, JD, MJD or time in seconds).
91 91  
92 92 ``npix [integer]``
93 93 Number of pixels for binned analysis.
... ...
doc/source/users/reference_manual/cstsdist.rst
... ... @@ -90,11 +90,11 @@ General parameters
90 90 ``enumbins [integer]``
91 91 Number of energy bins (0=unbinned).
92 92  
93   -``(tmin = 0.0) [real]``
94   - Start time (in seconds).
  93 +``tmin [time]``
  94 + Start time (UTC string, JD, MJD or time in seconds).
95 95  
96   -``tmax [real]``
97   - Stop time (in seconds).
  96 +``tmax [time]``
  97 + Stop time (UTC string, JD, MJD or time in seconds).
98 98  
99 99 ``npix [integer]``
100 100 Number of pixels for binned analysis.
... ...
doc/source/users/reference_manual/csviscube.rst
... ... @@ -24,11 +24,11 @@ On output, the script will provide a FITS file containing the visibility cube.
24 24 General parameters
25 25 ------------------
26 26  
27   -``tmin [real]``
28   - Start time of the observation.
  27 +``tmin [time]``
  28 + Start time of observation (UTC string, JD, MJD or time in seconds).
29 29  
30   -``tmax [real]``
31   - Stop time of the observation.
  30 +``tmax [time]``
  31 + Stop time of observation (UTC string, JD, MJD or time in seconds).
32 32  
33 33 ``geolon [real]``
34 34 Geographic longitude of the IACT array in degrees.
... ...
doc/source/users/reference_manual/ctmodel.rst
... ... @@ -86,11 +86,11 @@ General parameters
86 86 ``rad [real]``
87 87 Radius of field of view (in degrees).
88 88  
89   -``tmin [real]``
90   - CTA mission elapsed start time (in seconds).
  89 +``tmin [time]``
  90 + Start time (UTC string, JD, MJD or time in seconds).
91 91  
92   -``tmax [real]``
93   - CTA mission elapsed stop time (in seconds).
  92 +``tmax [time]``
  93 + Stop time (UTC string, JD, MJD or time in seconds).
94 94  
95 95 ``(deadc = 0.95) [real]``
96 96 Average deadtime correction factor.
... ...
doc/source/users/reference_manual/ctobssim.rst
... ... @@ -83,12 +83,12 @@ General parameters
83 83 ``rad [real]``
84 84 Radius of CTA field of view (simulation cone radius) (in degrees).
85 85  
86   -``tmin [real]``
87   - Mission elapsed start time of observation (in seconds).
88   -
89   -``tmax [real]``
90   - Mission elapsed stop time of observation (in seconds).
  86 +``tmin [time]``
  87 + Start time (UTC string, JD, MJD or time in seconds).
91 88  
  89 +``tmax [time]``
  90 + Stop time (UTC string, JD, MJD or time in seconds).
  91 +
92 92 ``emin [real]``
93 93 Lower energy limit of simulated events (in TeV).
94 94  
... ...
doc/source/users/reference_manual/ctselect.rst
... ... @@ -65,13 +65,13 @@ General parameters
65 65 If INDEF, NONE, UNDEF or UNDEFINED is passed as value, no ROI
66 66 selection will be performed.
67 67  
68   -``tmin [real]``
69   - CTA mission elapsed start time defining the earliest event (in seconds).
  68 +``tmin [time]``
  69 + Start time (UTC string, JD, MJD or time in seconds).
70 70 If INDEF, NONE, UNDEF or UNDEFINED is passed as value, no time
71 71 selection will be performed.
72 72  
73   -``tmax [real]``
74   - CTA mission elapsed stop time defining the latest event (in seconds).
  73 +``tmax [time]``
  74 + Stop time (UTC string, JD, MJD or time in seconds).
75 75 If INDEF, NONE, UNDEF or UNDEFINED is passed as value, no time
76 76 selection will be performed.
77 77  
... ...
pyext/ctool.i
... ... @@ -94,6 +94,11 @@ public:
94 94 %rename(_require_inobs) require_inobs;
95 95 %rename(_require_inobs_nocube) require_inobs_nocube;
96 96 %rename(_get_roi) get_roi;
  97 + %rename(_get_ebounds) get_ebounds;
  98 + %rename(_get_gti) get_gti;
  99 + %rename(_get_pointing) get_pointing;
  100 + %rename(_get_skydir) get_skydir;
  101 + %rename(_set_outfile_name) set_outfile_name;
97 102 %rename(_set_response) set_response;
98 103 %rename(_set_edisp) set_edisp;
99 104 %rename(_restore_edisp) restore_edisp;
... ... @@ -121,17 +126,22 @@ public:
121 126 void setup_models(GObservations& obs, const std::string& name = "");
122 127  
123 128 // Protected methods that create objects from user parameters
124   - GEbounds create_ebounds(void);
125   - GSkyMap create_map(const GObservations& obs);
126   - GCTAEventCube create_cube(const GObservations& obs);
127   - GCTAObservation create_cta_obs(void);
  129 + GEbounds create_ebounds(void);
  130 + GSkyMap create_map(const GObservations& obs);
  131 + GCTAEventCube create_cube(const GObservations& obs);
  132 + GCTAObservation create_cta_obs(void);
128 133  
129 134 // Protected methods that check user parameters
130   - void require_inobs(const std::string& method);
131   - void require_inobs_nocube(const std::string& method);
  135 + void require_inobs(const std::string& method);
  136 + void require_inobs_nocube(const std::string& method);
132 137  
133 138 // Protected methods that extract user parameters
134   - GCTARoi get_roi(void);
  139 + GCTARoi get_roi(const GCTAPointing& pnt = GCTAPointing());
  140 + GEbounds get_ebounds(void);
  141 + GGti get_gti(void);
  142 + GCTAPointing get_pointing(void);
  143 + GSkyDir get_skydir(void);
  144 + std::string set_outfile_name(const std::string& filename);
135 145  
136 146 // Protected support methods
137 147 void set_response(GObservations& obs);
... ...
src/ctcubemask/ctcubemask.cpp
... ... @@ -375,8 +375,6 @@ void ctcubemask::init_members(void)
375 375 m_regfile.clear();
376 376 m_outcube.clear();
377 377 m_prefix.clear();
378   - m_usepnt = false;
379   - m_roi.clear();
380 378 m_emin = 0.0;
381 379 m_emax = 0.0;
382 380 m_publish = false;
... ... @@ -384,7 +382,6 @@ void ctcubemask::init_members(void)
384 382 // Initialise protected members
385 383 m_infiles.clear();
386 384 m_select_energy = true;
387   - m_select_roi = true;
388 385  
389 386 // Return
390 387 return;
... ... @@ -402,8 +399,6 @@ void ctcubemask::copy_members(const ctcubemask&amp; app)
402 399 m_regfile = app.m_regfile;
403 400 m_outcube = app.m_outcube;
404 401 m_prefix = app.m_prefix;
405   - m_usepnt = app.m_usepnt;
406   - m_roi = app.m_roi;
407 402 m_emin = app.m_emin;
408 403 m_emax = app.m_emax;
409 404 m_publish = app.m_publish;
... ... @@ -411,7 +406,6 @@ void ctcubemask::copy_members(const ctcubemask&amp; app)
411 406 // Copy protected members
412 407 m_infiles = app.m_infiles;
413 408 m_select_energy = app.m_select_energy;
414   - m_select_roi = app.m_select_roi;
415 409  
416 410 // Return
417 411 return;
... ... @@ -442,7 +436,6 @@ void ctcubemask::get_parameters(void)
442 436 {
443 437 // Initialise selection flags
444 438 m_select_energy = true;
445   - m_select_roi = true;
446 439  
447 440 // Setup observations from "inobs" parameter. Do not request response
448 441 // information and do not accept event lists.
... ... @@ -450,11 +443,9 @@ void ctcubemask::get_parameters(void)
450 443  
451 444 // Get parameters
452 445 m_regfile = (*this)["regfile"].filename();
453   - m_usepnt = (*this)["usepnt"].boolean();
454 446  
455   - // Get the RoI and enable RoI selection if the RoI is valid
456   - m_roi = get_roi();
457   - m_select_roi = m_roi.is_valid();
  447 + // Query the RoI
  448 + GCTARoi roi = get_roi();
458 449  
459 450 // Check for sanity of energy selection parameters
460 451 if ((*this)["emin"].is_valid() && (*this)["emax"].is_valid()) {
... ... @@ -563,12 +554,13 @@ void ctcubemask::apply_mask(GCTAObservation* obs)
563 554  
564 555 // Set all pixels inside selected energy bands but outside RoI
565 556 // to -1.0 if requested
566   - if (m_select_roi) {
567   - GSkyRegionCircle roi(m_roi.centre().dir(), m_roi.radius());
  557 + GCTARoi roi = get_roi(obs->pointing());
  558 + if (roi.is_valid()) {
  559 + GSkyRegionCircle circle(roi.centre().dir(), roi.radius());
568 560 for (int i = e_idx1; i <= e_idx2; ++i) {
569 561 for (int pixel = 0; pixel < npix; ++pixel) {
570 562 GSkyDir dir = map.inx2dir(pixel);
571   - if (!roi.contains(dir)) {
  563 + if (!circle.contains(dir)) {
572 564 map(pixel,i) = -1.0;
573 565 }
574 566 }
... ... @@ -576,9 +568,9 @@ void ctcubemask::apply_mask(GCTAObservation* obs)
576 568  
577 569 // Log selected RoI
578 570 log_value(NORMAL, "Selected RoI",
579   - "RA="+gammalib::str(roi.centre().ra_deg())+" deg, "+
580   - "DEC="+gammalib::str(roi.centre().dec_deg())+" deg, "+
581   - "Radius="+gammalib::str(roi.radius())+" deg");
  571 + "RA="+gammalib::str(circle.centre().ra_deg())+" deg, "+
  572 + "DEC="+gammalib::str(circle.centre().dec_deg())+" deg, "+
  573 + "Radius="+gammalib::str(circle.radius())+" deg");
582 574  
583 575 } // endif: applied RoI selection
584 576  
... ...
src/ctcubemask/ctcubemask.hpp
1 1 /***************************************************************************
2 2 * ctcubemask - Cube filter tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2016 by Chia-Chun Lu *
  4 + * copyright (C) 2014-2017 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -78,8 +78,6 @@ protected:
78 78 GFilename m_regfile; //!< ds9 region file
79 79 GFilename m_outcube; //!< Output event list or XML file
80 80 std::string m_prefix; //!< Prefix for multiple counts maps
81   - bool m_usepnt; //!< Use pointing instead of RA/DEC parameters
82   - GCTARoi m_roi; //!< RoI selection
83 81 double m_emin; //!< Lower energy
84 82 double m_emax; //!< Upper energy
85 83 bool m_publish; //!< Publish counts cube?
... ... @@ -87,7 +85,6 @@ protected:
87 85 // Protected members
88 86 std::vector<std::string> m_infiles; //!< Input event filenames
89 87 bool m_select_energy; //!< Perform energy selection
90   - bool m_select_roi; //!< Perform ROI selection
91 88 };
92 89  
93 90  
... ...
src/ctmodel/ctmodel.par
... ... @@ -34,8 +34,8 @@ outcube, f, a, &quot;modcube.fits&quot;,,, &quot;Output model cube file&quot;
34 34 ra, r, a, 83.63,0,360, "RA of pointing (degrees)"
35 35 dec, r, a, 22.01,-90,90, "Dec of pointing (degrees)"
36 36 rad, r, a, 5.0,0,180, "Radius of FOV (degrees)"
37   -tmin, r, a, 0.0,,, "Start time (MET in s)"
38   -tmax, r, a, 1800.0,,, "End time (MET in s)"
  37 +tmin, t, a, 2020-01-01T00:00:00,,, "Start time (UTC string, JD, MJD or time in seconds)"
  38 +tmax, t, a, 2020-01-01T00:30:00,,, "Stop time (UTC string, JD, MJD or time in seconds)"
39 39 deadc, r, h, 0.98,0,1, "Average deadtime correction factor"
40 40  
41 41 #
... ...
src/ctobssim/ctobssim.par
... ... @@ -32,8 +32,8 @@ seed, i, h, 1,,, &quot;Random number generator seed&quot;
32 32 ra, r, a, 83.63,0,360, "RA of pointing (degrees)"
33 33 dec, r, a, 22.01,-90,90, "Dec of pointing (degrees)"
34 34 rad, r, a, 5.0,0,180, "Radius of FOV (degrees)"
35   -tmin, r, a, 0.0,,, "Start time (MET in s)"
36   -tmax, r, a, 1800.0,,, "End time (MET in s)"
  35 +tmin, t, a, 2020-01-01T00:00:00,,, "Start time (UTC string, JD, MJD or time in seconds)"
  36 +tmax, t, a, 2020-01-01T00:30:00,,, "Stop time (UTC string, JD, MJD or time in seconds)"
37 37 emin, r, a, 0.1,,, "Lower energy limit (TeV)"
38 38 emax, r, a, 100.0,,, "Upper energy limit (TeV)"
39 39 deadc, r, h, 0.98,0,1, "Average deadtime correction factor"
... ...
src/ctselect/ctselect.cpp
... ... @@ -466,10 +466,7 @@ void ctselect::init_members(void)
466 466 // Initialise parameters
467 467 m_outobs.clear();
468 468 m_prefix.clear();
469   - m_usepnt = false;
470   - m_roi.clear();
471   - m_tmin = 0.0;
472   - m_tmax = 0.0;
  469 + m_gti.clear();
473 470 m_emin = 0.0;
474 471 m_emax = 0.0;
475 472 m_expr.clear();
... ... @@ -484,8 +481,6 @@ void ctselect::init_members(void)
484 481 m_timemax.clear();
485 482 m_phases.clear();
486 483 m_select_energy = false;
487   - m_select_roi = false;
488   - m_select_time = false;
489 484 m_select_phase = false;
490 485  
491 486 // Return
... ... @@ -503,10 +498,7 @@ void ctselect::copy_members(const ctselect&amp; app)
503 498 // Copy parameters
504 499 m_outobs = app.m_outobs;
505 500 m_prefix = app.m_prefix;
506   - m_usepnt = app.m_usepnt;
507   - m_roi = app.m_roi;
508   - m_tmin = app.m_tmin;
509   - m_tmax = app.m_tmax;
  501 + m_gti = app.m_gti;
510 502 m_emin = app.m_emin;
511 503 m_emax = app.m_emax;
512 504 m_expr = app.m_expr;
... ... @@ -521,8 +513,6 @@ void ctselect::copy_members(const ctselect&amp; app)
521 513 m_timemax = app.m_timemax;
522 514 m_phases = app.m_phases;
523 515 m_select_energy = app.m_select_energy;
524   - m_select_roi = app.m_select_roi;
525   - m_select_time = app.m_select_time;
526 516 m_select_phase = app.m_select_phase;
527 517  
528 518 // Return
... ... @@ -557,36 +547,18 @@ void ctselect::get_parameters(void)
557 547  
558 548 // Initialise selection flags
559 549 m_select_energy = false;
560   - m_select_roi = false;
561   - m_select_time = false;
562 550 m_select_phase = false;
563 551  
564 552 // Setup observations from "inobs" parameter. Do not request response
565 553 // information and do not accept counts cubes.
566 554 setup_observations(m_obs, false, true, false);
567 555  
568   - // Get some parameters
569   - m_usepnt = (*this)["usepnt"].boolean();
  556 + // Query the RoI
  557 + GCTAPointing pnt;
  558 + GCTARoi roi = get_roi(pnt);
570 559  
571   - // Get the RoI and enable RoI selection if the RoI is valid
572   - m_roi = get_roi();
573   - m_select_roi = m_roi.is_valid();
574   -
575   - // Get time selection parameters
576   - if ((*this)["tmin"].is_valid() && (*this)["tmax"].is_valid()) {
577   -
578   - // Get User parameters
579   - m_tmin = (*this)["tmin"].real();
580   - m_tmax = (*this)["tmax"].real();
581   -
582   - // Additional check for time values
583   - if (m_tmin >= m_tmax) {
584   - m_select_time = false;
585   - }
586   - else {
587   - m_select_time = true;
588   - }
589   - }
  560 + // Get Good Time Intervals (empty if no selection is done)
  561 + m_gti = get_gti();
590 562  
591 563 // Get energy selection parameters
592 564 if ((*this)["emin"].is_valid() && (*this)["emax"].is_valid()) {
... ... @@ -686,8 +658,8 @@ void ctselect::get_parameters(void)
686 658  
687 659 // Set time interval with input times given in CTA reference
688 660 // time (in seconds)
689   - m_timemin.set(m_tmin, m_cta_ref);
690   - m_timemax.set(m_tmax, m_cta_ref);
  661 + m_timemin = m_gti.tstart();
  662 + m_timemax = m_gti.tstop();
691 663  
692 664 // Write parameters into logger
693 665 log_parameters(TERSE);
... ... @@ -716,8 +688,7 @@ void ctselect::get_parameters(void)
716 688 * observation is replaced by selected event list read from the FITS file.
717 689 *
718 690 * Good Time Intervals of the observation will be limited to the time
719   - * interval [m_tmin, m_tmax]. If m_tmin=m_tmax=0, no time selection is
720   - * performed.
  691 + * interval [m_timemin, m_timemax].
721 692 ***************************************************************************/
722 693 void ctselect::select_events(GCTAObservation* obs,
723 694 const std::string& filename,
... ... @@ -756,21 +727,19 @@ void ctselect::select_events(GCTAObservation* obs,
756 727 // Analyse expression to see if a selection is required
757 728 bool select_expr = (gammalib::strip_whitespace(m_expr).length() > 0);
758 729  
759   - // Set RoI selection. If the "usepnt" parameter is set to true then
760   - // use the pointing direction as the RoI centre.
761   - double ra = m_roi.centre().dir().ra_deg();
762   - double dec = m_roi.centre().dir().dec_deg();
763   - double rad = m_roi.radius();
764   - if (m_usepnt) {
765   - const GCTAPointing &pnt = obs->pointing();
766   - ra = pnt.dir().ra_deg();
767   - dec = pnt.dir().dec_deg();
768   - }
769   -
  730 + // Set RoI selection
  731 + GCTARoi roi = get_roi(obs->pointing());
  732 + double ra = roi.centre().dir().ra_deg();
  733 + double dec = roi.centre().dir().dec_deg();
  734 + double rad = roi.radius();
  735 +
  736 + // Signal that RoI selection should be performed
  737 + bool select_roi = roi.is_valid();
  738 +
770 739 // Set time selection interval. We make sure here that the time selection
771 740 // interval cannot be wider than the GTIs covering the data. This is done
772 741 // using GGti's reduce() method.
773   - if (m_select_time) {
  742 + if (!m_gti.is_empty()) {
774 743  
775 744 // Reduce GTIs to specified time interval. The complicated cast is
776 745 // necessary here because the gti() method is declared const, so
... ... @@ -783,8 +752,8 @@ void ctselect::select_events(GCTAObservation* obs,
783 752 GGti gti = list->gti();
784 753  
785 754 // Make time selection
786   - if (m_select_time) {
787   -
  755 + if (!m_gti.is_empty()) {
  756 +
788 757 // Extract effective time interval in the reference time of the
789 758 // event list. We get this reference time from gti.reference().
790 759 double tmin = gti.tstart().convert(gti.reference());
... ... @@ -910,7 +879,7 @@ void ctselect::select_events(GCTAObservation* obs,
910 879 } // endif: made energy selection
911 880  
912 881 // Make RoI selection
913   - if (m_select_roi) {
  882 + if (select_roi) {
914 883  
915 884 // Store the original radius
916 885 double original_rad = rad;
... ... @@ -1032,7 +1001,7 @@ void ctselect::select_events(GCTAObservation* obs,
1032 1001 list->fetch();
1033 1002  
1034 1003 // If RoI selection has been applied then set the event list RoI
1035   - if (m_select_roi) {
  1004 + if (select_roi) {
1036 1005 GCTAInstDir instdir;
1037 1006 instdir.dir().radec_deg(ra, dec);
1038 1007 list->roi(GCTARoi(instdir, rad));
... ... @@ -1326,7 +1295,7 @@ void ctselect::save_fits(void)
1326 1295  
1327 1296 // Save only if it's a CTA observation
1328 1297 if (obs != NULL) {
1329   -
  1298 +
1330 1299 // Save only if file name is non-empty
1331 1300 if (m_infiles[0].length() > 0) {
1332 1301  
... ...
src/ctselect/ctselect.hpp
... ... @@ -83,10 +83,7 @@ protected:
83 83 // User parameters
84 84 std::string m_outobs; //!< Output event list or XML file
85 85 std::string m_prefix; //!< Prefix for multiple event lists
86   - bool m_usepnt; //!< Use pointing instead of RA/DEC parameters
87   - GCTARoi m_roi; //!< RoI selection
88   - double m_tmin; //!< Start time
89   - double m_tmax; //!< Stop time
  86 + GGti m_gti; //!< Time selection
90 87 double m_emin; //!< Lower energy
91 88 double m_emax; //!< Upper energy
92 89 std::string m_expr; //!< Selection expression
... ... @@ -101,8 +98,6 @@ protected:
101 98 GTime m_timemax; //!< Latest time
102 99 GPhases m_phases; //!< Phase intervals
103 100 bool m_select_energy; //!< Perform energy selection
104   - bool m_select_roi; //!< Perform RoI selection
105   - bool m_select_time; //!< Perform time selection
106 101 bool m_select_phase; //!< Perform phase selection
107 102 };
108 103  
... ...
src/ctselect/ctselect.par
... ... @@ -27,8 +27,8 @@ usepnt, b, h, no,,, &quot;Use pointing instead of RA/DEC parameters?&quot;
27 27 ra, r, a, 83.63,0,360, "RA for ROI centre (degrees)"
28 28 dec, r, a, 22.01,-90,90, "Dec for ROI centre (degrees)"
29 29 rad, r, a, 3.0,0,180, "Radius of ROI (degrees)"
30   -tmin, r, a, 0.0,,, "Start time (CTA MET in seconds)"
31   -tmax, r, a, 0.0,,, "End time (CTA MET in seconds)"
  30 +tmin, t, a, NONE,,, "Start time (UTC string, JD, MJD or time in seconds)"
  31 +tmax, t, a, NONE,,, "End time (UTC string, JD, MJD or time in seconds)"
32 32 emin, r, a, 0.1,,, "Lower energy limit (TeV)"
33 33 emax, r, a, 100.0,,, "Upper energy limit (TeV)"
34 34 phase, s, h, NONE,,, "Phase expression in the format phasemin0:phasemax0,phasemin1:phasemax1,..."
... ...
src/support/ctool.cpp
... ... @@ -737,9 +737,9 @@ GCTAEventCube ctool::create_cube(const GObservations&amp; obs)
737 737  
738 738  
739 739 /***********************************************************************//**
740   - * @brief Create a CTA observation from user parameters
  740 + * @brief Create a CTA observation from User parameters
741 741 *
742   - * Creates an empty CTA observation from user parameters. An empty event list
  742 + * Creates an empty CTA observation from User parameters. An empty event list
743 743 * including RoI, GTI and energy boundary information is attached to the
744 744 * observation. The method also sets the pointing direction using the ra and
745 745 * dec parameter, the ROI based on ra, dec and rad, a single GTI based on
... ... @@ -760,45 +760,24 @@ GCTAEventCube ctool::create_cube(const GObservations&amp; obs)
760 760 ***************************************************************************/
761 761 GCTAObservation ctool::create_cta_obs(void)
762 762 {
763   - // Get CTA observation parameters
764   - double ra = (*this)["ra"].real();
765   - double dec = (*this)["dec"].real();
766   - double rad = (*this)["rad"].real();
  763 + // Get deadtime correction User parameter
767 764 double deadc = (*this)["deadc"].real();
768   - double t_min = (*this)["tmin"].real();
769   - double t_max = (*this)["tmax"].real();
770   - double e_min = (*this)["emin"].real();
771   - double e_max = (*this)["emax"].real();
772 765  
773 766 // Allocate CTA observation and empty event list
774 767 GCTAObservation obs;
775 768 GCTAEventList list;
776 769  
777 770 // Set pointing direction
778   - GCTAPointing pnt;
779   - GSkyDir skydir;
780   - skydir.radec_deg(ra, dec);
781   - pnt.dir(skydir);
  771 + GCTAPointing pnt = get_pointing();
782 772  
783   - // Set ROI
784   - GCTAInstDir instdir(skydir);
785   - GCTARoi roi(instdir, rad);
  773 + // Set RoI
  774 + GCTARoi roi = get_roi(pnt);
786 775  
787 776 // Set GTI
788   - GGti gti(m_cta_ref);
789   - GTime tstart;
790   - GTime tstop;
791   - tstart.set(t_min, m_cta_ref);
792   - tstop.set(t_max, m_cta_ref);
793   - gti.append(tstart, tstop);
  777 + GGti gti = get_gti();
794 778  
795 779 // Set energy boundaries
796   - GEbounds ebounds;
797   - GEnergy emin;
798   - GEnergy emax;
799   - emin.TeV(e_min);
800   - emax.TeV(e_max);
801   - ebounds.append(emin, emax);
  780 + GEbounds ebounds = get_ebounds();
802 781  
803 782 // Set CTA event list attributes
804 783 list.roi(roi);
... ... @@ -870,7 +849,7 @@ void ctool::require_inobs_nocube(const std::string&amp; method)
870 849  
871 850 // Signal no cube
872 851 bool is_cube = false;
873   -
  852 +
874 853 // Try loading file as counts cube. If this is successful then
875 854 // throw an exception
876 855 try {
... ... @@ -897,9 +876,9 @@ void ctool::require_inobs_nocube(const std::string&amp; method)
897 876 "observation definition file.";
898 877 throw GException::invalid_value(method, msg);
899 878 }
900   -
  879 +
901 880 } // endif: we had a FITS file
902   -
  881 +
903 882 // Return
904 883 return;
905 884 }
... ... @@ -974,17 +953,21 @@ void ctool::log_models(const GChatter&amp; chatter,
974 953  
975 954  
976 955 /***********************************************************************//**
977   - * @brief Return RoI from user parameters
  956 + * @brief Return RoI from User parameters
978 957 *
979   - * @param[in] obs Observation container.
980   - * @return Region of interest.
  958 + * @param[in] pnt Pointing direction.
  959 + * @return Region of Interest.
981 960 *
982   - * Returns region of interest from the user parameters "ra", "dec" and "rad".
983   - * If the "usepnt" parameter exists and is "yes" then postpone then assume
984   - * that the Right Ascension and Declination of the RoI centre will be set
985   - * from the pointing direction somewhere else.
  961 + * Returns Region of Interest (RoI) from the User parameters "ra", "dec" and
  962 + * "rad". If any of the parameters "ra", "dec" or "rad" is not valid an
  963 + * invalid RoI is returned.
  964 + *
  965 + * If the "usepnt" parameter exists and is set to "yes", the RoI centre will
  966 + * be taken from the specified pointing direction instead of the "ra" and
  967 + * "dec" parameters. Make sure to provide a valid pointing direction in case
  968 + * that you want to use the "usepnt" User parameter.
986 969 ***************************************************************************/
987   -GCTARoi ctool::get_roi(void)
  970 +GCTARoi ctool::get_roi(const GCTAPointing& pnt)
988 971 {
989 972 // Initialise an empty RoI
990 973 GCTARoi roi;
... ... @@ -993,31 +976,32 @@ GCTARoi ctool::get_roi(void)
993 976 // use for the RoI centre
994 977 bool usepnt = (has_par("usepnt") && (*this)["usepnt"].boolean());
995 978  
996   - // If pointing should not bet used the extract the RoI centre from the
997   - // "ra" and "dec" parameters
998   - if (!usepnt) {
  979 + // If the pointing direction should be used then extract the RoI centre
  980 + // from the pointing direction
  981 + if (usepnt) {
  982 + roi.centre(GCTAInstDir(pnt.dir()));
  983 + }
999 984  
1000   - // Read "ra" and "dec" parameters only if both are valid
1001   - if ((*this)["ra"].is_valid() && (*this)["dec"].is_valid()) {
  985 + // ... otherwise extract the RoI centre from "ra" and "dec" User
  986 + // parameters if they are valid
  987 + else if ((*this)["ra"].is_valid() && (*this)["dec"].is_valid()) {
1002 988  
1003   - // Read parameters
1004   - double ra = (*this)["ra"].real();
1005   - double dec = (*this)["dec"].real();
  989 + // Get Sky direction
  990 + GSkyDir skydir = get_skydir();
1006 991  
1007   - // Set RoI
1008   - GCTAInstDir instdir;
1009   - instdir.dir().radec_deg(ra, dec);
1010   - roi.centre(instdir);
  992 + // Convert into CTA instrument direction
  993 + GCTAInstDir instdir(skydir);
1011 994  
1012   - // Signal that we have a pointing direction
1013   - usepnt = true;
  995 + // Set RoI centre
  996 + roi.centre(instdir);
1014 997  
1015   - } // endif: "ra" and "dec" were valid
  998 + // Signal that we have a centre
  999 + usepnt = true;
1016 1000  
1017   - } // endif: pointing was not used for RoI centre
  1001 + } // endelse: set RoI centre from User parameters
1018 1002  
1019   - // If we have a RoI centre and if the "rad" parameter is valid then
1020   - // extract the RoI radius from the parameter
  1003 + // Extract the RoI radius from the "rad" parameter if we have a centre
  1004 + // and the "rad" parameter is valid
1021 1005 if (usepnt && (*this)["rad"].is_valid()) {
1022 1006 roi.radius((*this)["rad"].real());
1023 1007 }
... ... @@ -1028,6 +1012,137 @@ GCTARoi ctool::get_roi(void)
1028 1012  
1029 1013  
1030 1014 /***********************************************************************//**
  1015 + * @brief Return energy boundaries from User parameters
  1016 + *
  1017 + * @return Energy boundaries.
  1018 + *
  1019 + * Returns energy boundaries from the User parameters "emin" and "emax". If
  1020 + * one of "emin" or "emax" is not valid, an empty energy boundaries object
  1021 + * is returned. If "emin" is not valid, "emax" is not queried.
  1022 + ***************************************************************************/
  1023 +GEbounds ctool::get_ebounds(void)
  1024 +{
  1025 + // Initialise energy boundaries
  1026 + GEbounds ebounds;
  1027 +
  1028 + // Get minimum energy from "emin" User parameter
  1029 + GApplicationPar parmin = (*this)["emin"];
  1030 +
  1031 + // Continue only if "emin" has a valid energy value
  1032 + if (parmin.is_valid()) {
  1033 +
  1034 + // Get maximum energy from "emax" User parameter
  1035 + GApplicationPar parmax = (*this)["emax"];
  1036 +
  1037 + // Continue only if "emax" has a valid energy value
  1038 + if (parmax.is_valid()) {
  1039 +
  1040 + // Read minimum and maximum energy parameters in TeV
  1041 + double e_min = parmin.real();
  1042 + double e_max = parmax.real();
  1043 +
  1044 + // Set energy boundaries
  1045 + GEnergy emin;
  1046 + GEnergy emax;
  1047 + emin.TeV(e_min);
  1048 + emax.TeV(e_max);
  1049 + ebounds.append(emin, emax);
  1050 +
  1051 + } // endif: "emax" parameter was valid
  1052 +
  1053 + } // endif: "emin" parameter was valid
  1054 +
  1055 + // Return energy boundaries
  1056 + return ebounds;
  1057 +}
  1058 +
  1059 +
  1060 +/***********************************************************************//**
  1061 + * @brief Return Good Time Intervals from User parameter
  1062 + *
  1063 + * @return Good Time Intervals.
  1064 + *
  1065 + * Returns Good Time Intervals from the User parameters "tmin" and "tmax",
  1066 + * taking into account the transformation into the CTA reference time system.
  1067 + * If one of "tmin" or "tmax" is not valid, an empty Good Time Interval
  1068 + * object is returned. If "tmin" is not valid, "tmax" is not queried.
  1069 + ***************************************************************************/
  1070 +GGti ctool::get_gti(void)
  1071 +{
  1072 + // Initialise Good Time Intervals with CTA reference time
  1073 + GGti gti(m_cta_ref);
  1074 +
  1075 + // Get minimum time from "tmin" User parameter
  1076 + GApplicationPar parmin = (*this)["tmin"];
  1077 +
  1078 + // Continue only if "tmin" has a valid time value
  1079 + if (parmin.is_valid()) {
  1080 +
  1081 + // Get maximum time from "tmax" User parameter
  1082 + GApplicationPar parmax = (*this)["tmax"];
  1083 +
  1084 + // Continue only if "tmax" has a valid time value
  1085 + if (parmax.is_valid()) {
  1086 +
  1087 + // Get minimum and maximum time for CTA time reference
  1088 + GTime tmin = parmin.time(m_cta_ref);
  1089 + GTime tmax = parmax.time(m_cta_ref);
  1090 +
  1091 + // Append GTI
  1092 + gti.append(tmin, tmax);
  1093 +
  1094 + } // endif: "tmax" parameter was valid
  1095 +
  1096 + } // endif: "tmin" parameter was valid
  1097 +
  1098 + // Return GTI
  1099 + return gti;
  1100 +}
  1101 +
  1102 +
  1103 +/***********************************************************************//**
  1104 + * @brief Return CTA pointing from User parameters
  1105 + *
  1106 + * @return CTA pointing.
  1107 + *
  1108 + * Returns CTA pointing from the User parameters "ra" and "dec".
  1109 + ***************************************************************************/
  1110 +GCTAPointing ctool::get_pointing(void)
  1111 +{
  1112 + // Get sky direction
  1113 + GSkyDir skydir = get_skydir();
  1114 +
  1115 + // Set CTA pointing
  1116 + GCTAPointing pnt(skydir);
  1117 +
  1118 + // Return pointing
  1119 + return pnt;
  1120 +}
  1121 +
  1122 +
  1123 +/***********************************************************************//**
  1124 + * @brief Return sky direction from User parameters
  1125 + *
  1126 + * @return Sky direction.
  1127 + *
  1128 + * Returns sky direction from the User parameters "ra" and "dec".
  1129 + ***************************************************************************/
  1130 +GSkyDir ctool::get_skydir(void)
  1131 +{
  1132 + // Read Right Ascension and Declination parameters
  1133 + double ra = (*this)["ra"].real();
  1134 + double dec = (*this)["dec"].real();
  1135 +
  1136 + // Set sky direction
  1137 + GSkyDir skydir;
  1138 + skydir.radec_deg(ra, dec);
  1139 +
  1140 + // Return sky direction
  1141 + return skydir;
  1142 +}
  1143 +
  1144 +
  1145 +/***********************************************************************//**
1031 1146 * @brief Set output file name.
1032 1147 *
1033 1148 * @param[in] filename Input file name.
... ... @@ -1056,7 +1171,7 @@ std::string ctool::set_outfile_name(const std::string&amp; filename)
1056 1171  
1057 1172 // Strip any ".gz"
1058 1173 outname = gammalib::strip_chars(outname, ".gz");
1059   -
  1174 +
1060 1175 // Return output filename
1061 1176 return outname;
1062 1177 }
... ... @@ -1120,7 +1235,7 @@ std::vector&lt;bool&gt; ctool::set_edisp(GObservations&amp; obs, const bool&amp; edisp) const
1120 1235  
1121 1236 // Yes, then set the energy dispersion flag
1122 1237 if (cta != NULL) {
1123   -
  1238 +
1124 1239 // Save old energy dispersion flag
1125 1240 old_edisp[i] = cta->response()->apply_edisp();
1126 1241  
... ... @@ -1280,7 +1395,7 @@ void ctool::set_obs_response(GCTAObservation* obs)
1280 1395  
1281 1396 // Set response without energy dispersion
1282 1397 obs->response(exposure, psf, background);
1283   -
  1398 +
1284 1399 } // endelse: no energy dispersion was available
1285 1400  
1286 1401 } // endif: energy dispersion needed
... ... @@ -1322,7 +1437,7 @@ void ctool::set_obs_response(GCTAObservation* obs)
1322 1437  
1323 1438 // Attach response to observation
1324 1439 obs->response(response);
1325   -
  1440 +
1326 1441 // Signal response availability
1327 1442 has_response = true;
1328 1443  
... ... @@ -1398,7 +1513,7 @@ void ctool::set_obs_bounds(GObservations&amp; obs)
1398 1513 list->roi(roi);
1399 1514 }
1400 1515 }
1401   -
  1516 +
1402 1517 } // endfor: looped over observations
1403 1518  
1404 1519 // Return
... ... @@ -1682,14 +1797,14 @@ GEnergies ctool::insert_energy_boundaries(const GEnergies&amp; energies,
1682 1797 bool insert = true;
1683 1798 int index = -1;
1684 1799 for (int k = 0; k < engs.size(); ++k) {
1685   -
  1800 +
1686 1801 // If energy exists already then skip the boundary and examine the
1687 1802 // next one. We consider here 1 MeV as being sufficiently close.
1688 1803 if (std::abs(engs[k].MeV()-energy.MeV()) < 1.0) {
1689 1804 insert = false;
1690 1805 break;
1691 1806 }
1692   -
  1807 +
1693 1808 // If energy is above the boundary energy we found the index
1694 1809 if (engs[k] > energy) {
1695 1810 index = k;
... ... @@ -1927,7 +2042,7 @@ std::string ctool::warn_too_few_energies(const GEnergies&amp; energies) const
1927 2042 double logEmin = std::log10(energies[0].TeV());
1928 2043 double logEmax = std::log10(energies[n-1].TeV());
1929 2044 int nrequired = int((logEmax - logEmin) * 25.0);
1930   -
  2045 +
1931 2046 // Warn if there are not enough energy bins
1932 2047 if (n < nrequired) {
1933 2048 warning.append("\nWARNING: Only "+gammalib::str(n-1)+" energy bins "
... ... @@ -1961,7 +2076,7 @@ std::string ctool::warn_xml_suffix(const GFilename&amp; filename) const
1961 2076 // Get filename suffix
1962 2077 std::string fname = std::string(filename);
1963 2078 std::string suffix = gammalib::tolower(fname.substr(fname.length()-4,4));
1964   -
  2079 +
1965 2080 // Warn if there are not enough energy bins
1966 2081 if (suffix != ".xml") {
1967 2082 warning.append("WARNING: Name of observation definition output file "
... ...
src/support/ctool.hpp
... ... @@ -84,28 +84,32 @@ protected:
84 84 void setup_models(GObservations& obs, const std::string& name = "");
85 85  
86 86 // Protected methods that create objects from user parameters
87   - GEbounds create_ebounds(void);
88   - GSkyMap create_map(const GObservations& obs);
89   - GCTAEventCube create_cube(const GObservations& obs);
90   - GCTAObservation create_cta_obs(void);
  87 + GEbounds create_ebounds(void);
  88 + GSkyMap create_map(const GObservations& obs);
  89 + GCTAEventCube create_cube(const GObservations& obs);
  90 + GCTAObservation create_cta_obs(void);
91 91  
92 92 // Protected methods that check user parameters
93   - void require_inobs(const std::string& method);
94   - void require_inobs_nolist(const std::string& method);
95   - void require_inobs_nocube(const std::string& method);
96   -
97   - // Protected methods for logging
98   - void log_observations(const GChatter& chatter,
99   - const GObservations& obs,
100   - const std::string& what = "Observation");
101   - void log_models(const GChatter& chatter,
102   - const GModels& models,
103   - const std::string& what = "Model");
  93 + void require_inobs(const std::string& method);
  94 + void require_inobs_nolist(const std::string& method);
  95 + void require_inobs_nocube(const std::string& method);
104 96  
105 97 // Protected methods that extract user parameters
106   - GCTARoi get_roi(void);
  98 + GCTARoi get_roi(const GCTAPointing& pnt = GCTAPointing());
  99 + GEbounds get_ebounds(void);
  100 + GGti get_gti(void);
  101 + GCTAPointing get_pointing(void);
  102 + GSkyDir get_skydir(void);
107 103 std::string set_outfile_name(const std::string& filename);
108 104  
  105 + // Protected methods for logging
  106 + void log_observations(const GChatter& chatter,
  107 + const GObservations& obs,
  108 + const std::string& what = "Observation");
  109 + void log_models(const GChatter& chatter,
  110 + const GModels& models,
  111 + const std::string& what = "Model");
  112 +
109 113 // Protected support methods
110 114 void set_response(GObservations& obs);
111 115 std::vector<bool> set_edisp(GObservations& obs, const bool& edisp) const;
... ...
test/test_cscript.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This scripts performs unit tests for the cspull script.
4 4 #
5   -# Copyright (C) 2016 Juergen Knoedlseder
  5 +# Copyright (C) 2016-2017 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -37,7 +37,7 @@ class cscript_test(ctools.cscript):
37 37 """
38 38 # Set name
39 39 self._name = 'cscript_test'
40   - self._version = '1.2.0'
  40 + self._version = ctools.__version__
41 41  
42 42 # Initialise observation container from constructor arguments
43 43 self._obs, argv = self._set_input_obs(argv)
... ... @@ -84,7 +84,8 @@ class cscript_test(ctools.cscript):
84 84  
85 85 # Check get_roi() method
86 86 def check_get_roi(self):
87   - return self._get_roi()
  87 + pnt = gammalib.GCTAPointing()
  88 + return self._get_roi(pnt)
88 89  
89 90 # Check restore_edisp() method
90 91 def check_restore_edisp(self):
... ... @@ -140,7 +141,7 @@ class ctobservation_test(ctools.csobservation):
140 141 """
141 142 # Set name
142 143 self._name = 'ctobservation_test'
143   - self._version = '1.2.0'
  144 + self._version = ctools.__version__
144 145  
145 146 # Initialise application by calling the appropriate class constructor
146 147 self._init_csobservation(argv)
... ... @@ -171,7 +172,7 @@ class ctlikelihood_test(ctools.cslikelihood):
171 172 """
172 173 # Set name
173 174 self._name = 'ctlikelihood_test'
174   - self._version = '1.2.0'
  175 + self._version = ctools.__version__
175 176  
176 177 # Initialise application by calling the appropriate class constructor
177 178 self._init_cslikelihood(argv)
... ... @@ -213,6 +214,8 @@ class Test(test):
213 214 pars.append(gammalib.GApplicationPar('rad','r','h','1.0','','',''))
214 215 pars.append(gammalib.GApplicationPar('emin','r','h','1.0','','',''))
215 216 pars.append(gammalib.GApplicationPar('emax','r','h','10.0','','',''))
  217 + pars.append(gammalib.GApplicationPar('tmin','t','h','2005-10-08T14:30:25','','',''))
  218 + pars.append(gammalib.GApplicationPar('tmax','t','h','2005-10-08T14:58:26','','',''))
216 219 pars.append(gammalib.GApplicationPar('expcube','f','h','NONE','','',''))
217 220 pars.append(gammalib.GApplicationPar('psfcube','f','h','NONE','','',''))
218 221 pars.append(gammalib.GApplicationPar('bkgcube','f','h','NONE','','',''))
... ...
test/test_cslightcrv.py
... ... @@ -72,7 +72,7 @@ class Test(test):
72 72 cmd = cslightcrv+' inobs="'+self._events+'"'+ \
73 73 ' inmodel="'+self._model+'" srcname="Crab"'+ \
74 74 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
75   - ' tbinalg="LIN" tmin=51544.50 tmax=51544.53'+ \
  75 + ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \
76 76 ' tbins=3 enumbins=0 emin=0.1 emax=100.0'+ \
77 77 ' outfile="lightcurve_cmd1.fits"'+ \
78 78 ' logfile="cslightcrv_cmd1.log" chatter=1'
... ... @@ -92,7 +92,7 @@ class Test(test):
92 92 cmd = cslightcrv+' inobs="events_that_do_not_exist.fits"'+ \
93 93 ' inmodel="'+self._model+'" srcname="Crab"'+ \
94 94 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
95   - ' tbinalg="LIN" tmin=51544.50 tmax=51544.53'+ \
  95 + ' tbinalg="LIN" tmin="MJD 51544.50" tmax="MJD 51544.53"'+ \
96 96 ' tbins=3 enumbins=0 emin=0.1 emax=100.0'+ \
97 97 ' outfile="lightcurve_cmd1.fits"'+ \
98 98 ' logfile="cslightcrv_cmd2.log"'
... ... @@ -117,8 +117,8 @@ class Test(test):
117 117 lcrv['caldb'] = self._caldb
118 118 lcrv['irf'] = self._irf
119 119 lcrv['tbinalg'] = 'LIN'
120   - lcrv['tmin'] = 51544.50
121   - lcrv['tmax'] = 51544.53
  120 + lcrv['tmin'] = 'MJD 51544.50'
  121 + lcrv['tmax'] = 'MJD 51544.53'
122 122 lcrv['tbins'] = 3
123 123 lcrv['enumbins'] = 0
124 124 lcrv['emin'] = 0.1
... ... @@ -206,8 +206,8 @@ class Test(test):
206 206 lcrv['caldb'] = self._caldb
207 207 lcrv['irf'] = self._irf
208 208 lcrv['tbinalg'] = 'LIN'
209   - lcrv['tmin'] = 51544.50
210   - lcrv['tmax'] = 51544.53
  209 + lcrv['tmin'] = 'MJD 51544.50'
  210 + lcrv['tmax'] = 'MJD 51544.53'
211 211 lcrv['tbins'] = 2
212 212 lcrv['emin'] = 0.1
213 213 lcrv['emax'] = 100.0
... ...
test/test_cspull.py
... ... @@ -79,7 +79,7 @@ class Test(test):
79 79 ' ntrials=2'+ \
80 80 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
81 81 ' ra=83.6331 dec=22.0145 emin=0.1 emax=100.0'+ \
82   - ' enumbins=0 tmax=100.0 deadc=0.98 rad=5.0'+ \
  82 + ' enumbins=0 tmin=0.0 tmax=100.0 deadc=0.98 rad=5.0'+ \
83 83 ' npix=200 binsz=0.05'+ \
84 84 ' logfile="cspull_cmd1.log" chatter=1'
85 85  
... ... @@ -100,7 +100,7 @@ class Test(test):
100 100 ' ntrials=2'+ \
101 101 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
102 102 ' ra=83.6331 dec=22.0145 emin=0.1 emax=100.0'+ \
103   - ' enumbins=0 tmax=100.0 deadc=0.98 rad=5.0'+ \
  103 + ' enumbins=0 tmin=0.0 tmax=100.0 deadc=0.98 rad=5.0'+ \
104 104 ' npix=200 binsz=0.05'+ \
105 105 ' logfile="cspull_cmd2.log"'
106 106  
... ... @@ -128,6 +128,7 @@ class Test(test):
128 128 pull['emin'] = 0.1
129 129 pull['emax'] = 100.0
130 130 pull['enumbins'] = 0
  131 + pull['tmin'] = 0.0
131 132 pull['tmax'] = 100.0
132 133 pull['deadc'] = 0.98
133 134 pull['rad'] = 5.0
... ... @@ -154,6 +155,7 @@ class Test(test):
154 155 pull['emin'] = 0.1
155 156 pull['emax'] = 100.0
156 157 pull['enumbins'] = 10
  158 + pull['tmin'] = 0.0
157 159 pull['tmax'] = 100.0
158 160 pull['deadc'] = 0.98
159 161 pull['rad'] = 5.0
... ...
test/test_cstsdist.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This scripts performs unit tests for the cstsdist script.
4 4 #
5   -# Copyright (C) 2016 Juergen Knoedlseder
  5 +# Copyright (C) 2016-2017 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -73,7 +73,7 @@ class Test(test):
73 73 ' srcname="Crab"'+ \
74 74 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
75 75 ' ntrials=1 ra=83.63 dec=22.01 emin=0.1 emax=100.0'+ \
76   - ' enumbins=0 tmax=1800.0 rad=5.0 npix=200 npix=200'+ \
  76 + ' enumbins=0 tmin=0.0 tmax=1800.0 rad=5.0 npix=200 npix=200'+ \
77 77 ' binsz=0.05'+ \
78 78 ' outfile="cstsdist_cmd1.dat"'+ \
79 79 ' logfile="cstsdist_cmd1.log" chatter=2'
... ... @@ -94,7 +94,7 @@ class Test(test):
94 94 ' srcname="Crab"'+ \
95 95 ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \
96 96 ' ntrials=1 ra=83.63 dec=22.01 emin=0.1 emax=100.0'+ \
97   - ' enumbins=0 tmax=1800.0 rad=5.0 npix=200 npix=200'+ \
  97 + ' enumbins=0 tmin=0.0 tmax=1800.0 rad=5.0 npix=200 npix=200'+ \
98 98 ' binsz=0.05'+ \
99 99 ' outfile="cstsdist_cmd2.dat"'+ \
100 100 ' logfile="cstsdist_cmd2.log" chatter=2'
... ... @@ -123,6 +123,7 @@ class Test(test):
123 123 tsdist['emin'] = 0.1
124 124 tsdist['emax'] = 100.0
125 125 tsdist['enumbins'] = 0
  126 + tsdist['tmin'] = 0.0
126 127 tsdist['tmax'] = 1800.0
127 128 tsdist['rad'] = 5.0
128 129 tsdist['outfile'] = 'cstsdist_py1.dat'
... ... @@ -151,6 +152,7 @@ class Test(test):
151 152 tsdist['emin'] = 0.1
152 153 tsdist['emax'] = 100.0
153 154 tsdist['enumbins'] = 10
  155 + tsdist['tmin'] = 0.0
154 156 tsdist['tmax'] = 1800.0
155 157 tsdist['rad'] = 5.0
156 158 tsdist['npix'] = 50
... ...
test/test_ctobssim.py
... ... @@ -75,7 +75,9 @@ class Test(test):
75 75 ' outevents="ctobssim_cmd1.fits"'+ \
76 76 ' caldb="'+self._caldb+'" irf="'+self._irf+'" '+ \
77 77 ' ra=83.63 dec=22.01 rad=10.0'+ \
78   - ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0'+ \
  78 + ' tmin="2020-01-01T00:00:00"'+ \
  79 + ' tmax="2020-01-01T00:30:00"'+ \
  80 + ' emin=0.1 emax=100.0'+ \
79 81 ' logfile="ctobssim_cmd1.log" chatter=1'
80 82  
81 83 # Check if execution of wrong command fails
... ... @@ -95,7 +97,9 @@ class Test(test):
95 97 ' outevents="ctobssim_cmd2.fits"'+ \
96 98 ' caldb="'+self._caldb+'" irf="'+self._irf+'" '+ \
97 99 ' ra=83.63 dec=22.01 rad=10.0'+ \
98   - ' tmin=0.0 tmax=1800.0 emin=0.1 emax=100.0'+ \
  100 + ' tmin="2020-01-01T00:00:00"'+ \
  101 + ' tmax="2020-01-01T00:30:00"'+ \
  102 + ' emin=0.1 emax=100.0'+ \
99 103 ' logfile="ctobssim_cmd2.log" chatter=1'
100 104  
101 105 # Check if execution failed
... ... @@ -147,8 +151,8 @@ class Test(test):
147 151 sim['ra'] = 83.63
148 152 sim['dec'] = 22.01
149 153 sim['rad'] = 10.0
150   - sim['tmin'] = 0.0
151   - sim['tmax'] = 1800.0
  154 + sim['tmin'] = '2020-01-01T00:00:00'
  155 + sim['tmax'] = '2020-01-01T00:30:00'
152 156 sim['emin'] = 0.1
153 157 sim['emax'] = 100.0
154 158 sim['outevents'] = 'ctobssim_py1.fits'
... ...