Commit a62f95f90841f58818c14fef2ef51c9ea6d5528d

Authored by Jürgen Knödlseder
1 parent bac09f5e

Add publish parameter and methods to ctobssim, ctselect, cslightcrv and csspec (#1871)

ChangeLog
1   -2016-10-05
  1 +2016-10-07
2 2  
3 3 * Version 1.2.0 released
4 4 ========================
5 5  
  6 + Add publish parameter and methods to ctobssim, ctselect, cslightcrv and csspec (#1871)
6 7 Add csviscube script (#1853)
7 8 Add zenith and azimuth angle information to IRF caldb (#1853)
8 9 Fix ctbin segfault bug for varying energy thresholds (#1850)
... ...
1 1 New Features and Important Changes in ctools 1.2.0
2 2  
3   -5 October 2016
  3 +7 October 2016
4 4  
5 5  
6 6 Introduction
... ... @@ -63,6 +63,9 @@ ctobssim - CTA observation simulation
63 63 The clear() method now calls GApplication::clear() to conserve the properties
64 64 of the tool (#1835).
65 65  
  66 +A publish() method has been added that publishes the simulated event lists on
  67 +a VO hub (#1871).
  68 +
66 69  
67 70 ctselect - CTA event selection
68 71 ------------------------------
... ... @@ -72,6 +75,9 @@ of the tool (#1835).
72 75 The time_reference() method has been removed since the method is part of the
73 76 ctool base class, and exposed in Python as _time_reference().
74 77  
  78 +A publish() method has been added that publishes the simulated event lists on
  79 +a VO hub (#1871).
  80 +
75 81  
76 82 ctbin - CTA event binning
77 83 -------------------------
... ... @@ -200,6 +206,9 @@ of hours that a given position on the sky is observable under a given zenith
200 206 angle by an IACT array during a given time period. The tool implements so far
201 207 a Sun constraint, but no Moon constraint (#1835).
202 208  
  209 +A publish() method has been added to cslightcrv and csspec that publishes the
  210 +results on a VO hub (#1871).
  211 +
203 212  
204 213 Examples
205 214 --------
... ...
cscripts/cslightcrv.par
... ... @@ -5,7 +5,7 @@
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # File: cslightcrv.par #
8   -# Version: 1.1.0 #
  8 +# Version: 1.2.0 #
9 9 # #
10 10 # Author: Juergen Knoedlseder #
11 11 # Jurgen.Knodlseder@irap.omp.eu #
... ... @@ -55,6 +55,7 @@ fix_bkg, b, h, no,,, "Fix background model parameters?"
55 55 #
56 56 # Standard parameters
57 57 #====================
  58 +publish, b, h, no,,, "Publish light curve on VO Hub?"
58 59 chatter, i, h, 2,0,4, "Chattiness of output"
59 60 clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
60 61 debug, b, h, no,,, "Debugging mode activated"
... ...
cscripts/cslightcrv.py
... ... @@ -614,6 +614,10 @@ class cslightcrv(ctools.cscript):
614 614 self._fits = gammalib.GFits()
615 615 self._fits.append(table)
616 616  
  617 + # Optionally publish light curve
  618 + if self['publish'].boolean():
  619 + self.publish()
  620 +
617 621 # Return
618 622 return
619 623  
... ... @@ -658,6 +662,36 @@ class cslightcrv(ctools.cscript):
658 662 # Return
659 663 return
660 664  
  665 + def publish(self, name=''):
  666 + """
  667 + Publish light curve
  668 +
  669 + Parameters
  670 + ----------
  671 + name : str, optional
  672 + Name of light curve
  673 + """
  674 + # Write header
  675 + self._log_header1(gammalib.TERSE, 'Publish light curve')
  676 +
  677 + # Continue only if light curve is valid
  678 + if self._fits.contains('LIGHTCURVE'):
  679 +
  680 + # Set default name is user name is empty
  681 + if not name:
  682 + user_name = self._name
  683 + else:
  684 + user_name = name
  685 +
  686 + # Log file name
  687 + self._log_value(gammalib.NORMAL, 'Light curve name', user_name)
  688 +
  689 + # Publish light curve
  690 + self._fits.publish('LIGHTCURVE', user_name)
  691 +
  692 + # Return
  693 + return
  694 +
661 695 def lightcurve(self):
662 696 """
663 697 Return light curve FITS file
... ...
cscripts/csresmap.py
... ... @@ -295,7 +295,7 @@ class csresmap(ctools.cscript):
295 295  
296 296 def publish(self, name=''):
297 297 """
298   - Publish residual map.
  298 + Publish residual map
299 299  
300 300 Parameters
301 301 ----------
... ...
cscripts/csspec.par
... ... @@ -5,7 +5,7 @@
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # File: csspec.par #
8   -# Version: 1.1.0 #
  8 +# Version: 1.2.0 #
9 9 # #
10 10 # Author: Juergen Knoedlseder #
11 11 # Jurgen.Knodlseder@irap.omp.eu #
... ... @@ -45,6 +45,7 @@ fix_bkg, b, h, no,,, "Fix background parameters"
45 45 #
46 46 # Standard parameters
47 47 #====================
  48 +publish, b, h, no,,, "Publish spectrum on VO Hub?"
48 49 chatter, i, h, 2,0,4, "Chattiness of output"
49 50 clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
50 51 debug, b, h, no,,, "Debugging mode activated"
... ...
cscripts/csspec.py
... ... @@ -268,18 +268,17 @@ class csspec(ctools.cscript):
268 268 par.fix()
269 269  
270 270 # Write header
  271 + self._log_header1(gammalib.TERSE, 'Generate spectrum')
271 272 if self._logTerse():
272   - self._log("\n")
273   - self._log.header1("Generate spectrum")
274   - self._log(str(self._ebounds))
  273 + self._log(str(self._ebounds))
275 274  
276 275 # Initialise FITS Table with extension "SPECTRUM"
277 276 table = gammalib.GFitsBinTable(self._ebounds.size())
278   - table.extname("SPECTRUM")
  277 + table.extname('SPECTRUM')
279 278  
280 279 # Add Header for compatibility with gammalib.GMWLSpectrum
281   - table.card("INSTRUME", "CTA", "Name of Instrument")
282   - table.card("TELESCOP", "CTA", "Name of Telescope")
  280 + table.card('INSTRUME', 'CTA', 'Name of Instrument')
  281 + table.card('TELESCOP', 'CTA', 'Name of Telescope')
283 282  
284 283 # Create FITS table columns
285 284 nrows = self._ebounds.size()
... ... @@ -470,12 +469,16 @@ class csspec(ctools.cscript):
470 469 self._fits = gammalib.GFits()
471 470 self._fits.append(table)
472 471  
  472 + # Optionally publish light curve
  473 + if self['publish'].boolean():
  474 + self.publish()
  475 +
473 476 # Return
474 477 return
475 478  
476 479 def execute(self):
477 480 """
478   - Execute the script.
  481 + Execute the script
479 482 """
480 483 # Open logfile
481 484 self.logFileOpen()
... ... @@ -494,24 +497,19 @@ class csspec(ctools.cscript):
494 497  
495 498 def save(self):
496 499 """
497   - Save spectrum.
  500 + Save spectrum
498 501 """
499 502 # Write header
500   - if self._logTerse():
501   - self._log("\n")
502   - self._log.header1("Save spectrum")
  503 + self._log_header1(gammalib.TERSE, 'Save spectrum')
503 504  
504 505 # Get outmap parameter
505   - outfile = self["outfile"].filename()
  506 + outfile = self['outfile'].filename()
506 507  
507 508 # Continue only filename and residual map are valid
508 509 if self._fits != None:
509 510  
510 511 # Log file name
511   - if self._logTerse():
512   - self._log(gammalib.parformat("Spectrum file"))
513   - self._log(outfile.url())
514   - self._log("\n")
  512 + self._log_value(gammalib.NORMAL, 'Spectrum file', outfile.url())
515 513  
516 514 # Save spectrum
517 515 self._fits.saveto(outfile, self._clobber)
... ... @@ -519,6 +517,36 @@ class csspec(ctools.cscript):
519 517 # Return
520 518 return
521 519  
  520 + def publish(self, name=''):
  521 + """
  522 + Publish spectrum
  523 +
  524 + Parameters
  525 + ----------
  526 + name : str, optional
  527 + Name of spectrum
  528 + """
  529 + # Write header
  530 + self._log_header1(gammalib.TERSE, 'Publish spectrum')
  531 +
  532 + # Continue only if spectrum is valid
  533 + if self._fits.contains('SPECTRUM'):
  534 +
  535 + # Set default name is user name is empty
  536 + if not name:
  537 + user_name = self._name
  538 + else:
  539 + user_name = name
  540 +
  541 + # Log file name
  542 + self._log_value(gammalib.NORMAL, 'Spectrum name', user_name)
  543 +
  544 + # Publish spectrum
  545 + self._fits.publish('SPECTRUM', user_name)
  546 +
  547 + # Return
  548 + return
  549 +
522 550 def spectrum(self):
523 551 """
524 552 Return spectrum FITS file.
... ...
cscripts/csviscube.par
... ... @@ -35,6 +35,7 @@ zmax, r, h, 60.0,,, "Maximum zenith angle (deg)"
35 35 #
36 36 # Standard parameters
37 37 #====================
  38 +publish, b, h, no,,, "Publish visibility cube on VO Hub?"
38 39 chatter, i, h, 2,0,4, "Chattiness of output"
39 40 clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
40 41 debug, b, h, no,,, "Debugging mode activated"
... ...
cscripts/csviscube.py
... ... @@ -462,6 +462,10 @@ class csviscube(ctools.cscript):
462 462 # Compute visibility cube
463 463 self._visibility_cube()
464 464  
  465 + # Optionally publish map
  466 + if self['publish'].boolean():
  467 + self.publish()
  468 +
465 469 # Return
466 470 return
467 471  
... ... @@ -484,6 +488,33 @@ class csviscube(ctools.cscript):
484 488 # Return
485 489 return
486 490  
  491 + def publish(self, name=''):
  492 + """
  493 + Publish visibility cube
  494 +
  495 + Parameters
  496 + ----------
  497 + name : str, optional
  498 + Name of visibility cube
  499 + """
  500 + # Write header
  501 + self._log_header1(gammalib.TERSE, 'Publish visibility cube')
  502 +
  503 + # Set default name is user name is empty
  504 + if not name:
  505 + user_name = self._name
  506 + else:
  507 + user_name = name
  508 +
  509 + # Log cube name
  510 + self._log_value(gammalib.TERSE, 'Visibility cube name', user_name)
  511 +
  512 + # Publish cube
  513 + self._cube.publish(user_name)
  514 +
  515 + # Return
  516 + return
  517 +
487 518 def execute(self):
488 519 """
489 520 Execute the script
... ...
doc/source/users/reference_manual/cslightcrv.rst
... ... @@ -118,6 +118,9 @@ General parameters
118 118 Standard parameters
119 119 -------------------
120 120  
  121 +``(publish = no) [boolean]``
  122 + Specifies whether the light curve should be published on VO Hub.
  123 +
121 124 ``(chatter = 2) [integer]``
122 125 Verbosity of the executable:
123 126 chatter = 0: no information will be logged
... ...
doc/source/users/reference_manual/csspec.rst
... ... @@ -110,6 +110,9 @@ General parameters
110 110 Standard parameters
111 111 -------------------
112 112  
  113 +``(publish = no) [boolean]``
  114 + Specifies whether the spectrum should be published on VO Hub.
  115 +
113 116 ``(chatter = 2) [integer]``
114 117 Verbosity of the executable:
115 118 chatter = 0: no information will be logged
... ...
doc/source/users/reference_manual/csviscube.rst
... ... @@ -58,6 +58,9 @@ General parameters
58 58 Standard parameters
59 59 -------------------
60 60  
  61 +``(publish = no) [boolean]``
  62 + Specifies whether the visibility cube should be published on VO Hub.
  63 +
61 64 ``(chatter = 2) [integer]``
62 65 Verbosity of the executable:
63 66 chatter = 0: no information will be logged
... ...
doc/source/users/reference_manual/ctobssim.rst
... ... @@ -107,7 +107,7 @@ Standard parameters
107 107 -------------------
108 108  
109 109 ``(publish = no) [boolean]``
110   - Specifies whether the event list should be published on VO Hub.
  110 + Specifies whether the event list(s) should be published on VO Hub.
111 111  
112 112 ``(chatter = 2) [integer]``
113 113 Verbosity of the executable:
... ...
doc/source/users/reference_manual/ctselect.rst
... ... @@ -95,6 +95,9 @@ General parameters
95 95 Standard parameters
96 96 -------------------
97 97  
  98 +``(publish = no) [boolean]``
  99 + Specifies whether the event list(s) should be published on VO Hub.
  100 +
98 101 ``(chatter = 2) [integer]``
99 102 Verbosity of the executable:
100 103 chatter = 0: no information will be logged
... ...
pyext/ctselect.i
1 1 /***************************************************************************
2 2 * ctselect - Data selection tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2014 by Jurgen Knodlseder *
  4 + * copyright (C) 2010-2016 by Jurgen Knodlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -47,6 +47,7 @@ public:
47 47 void clear(void);
48 48 void run(void);
49 49 void save(void);
  50 + void publish(const std::string& name = "");
50 51 };
51 52  
52 53  
... ...
src/ctobssim/ctobssim.hpp
... ... @@ -34,7 +34,7 @@
34 34  
35 35 /* __Definitions _________________________________________________________ */
36 36 #define CTOBSSIM_NAME "ctobssim"
37   -#define CTOBSSIM_VERSION "1.1.0"
  37 +#define CTOBSSIM_VERSION "1.2.0"
38 38  
39 39  
40 40 /***********************************************************************//**
... ...
src/ctobssim/ctobssim.par
... ... @@ -2,6 +2,17 @@
2 2 # #
3 3 # CTA Science Analysis Tools #
4 4 # #
  5 +# ------------------------------------------------------------------------- #
  6 +# #
  7 +# File: ctobssim.par #
  8 +# Version: 1.2.0 #
  9 +# #
  10 +# Author: Juergen Knoedlseder #
  11 +# Jurgen.Knodlseder@irap.omp.eu #
  12 +# IRAP #
  13 +# #
  14 +# Purpose: Parameter file for the ctobssim application #
  15 +# #
5 16 #############################################################################
6 17 #
7 18 # General parameters
... ...
src/ctselect/ctselect.cpp
... ... @@ -348,6 +348,11 @@ void ctselect::run(void)
348 348 // Write observation(s) into logger
349 349 log_observations(NORMAL, m_obs, "Output observation");
350 350  
  351 + // Optionally publish event list(s)
  352 + if ((*this)["publish"].boolean()) {
  353 + publish();
  354 + }
  355 +
351 356 // Return
352 357 return;
353 358 }
... ... @@ -392,6 +397,60 @@ void ctselect::save(void)
392 397 }
393 398  
394 399  
  400 +/***********************************************************************//**
  401 + * @brief Publish event lists
  402 + *
  403 + * @param[in] name Event list name.
  404 + ***************************************************************************/
  405 +void ctselect::publish(const std::string& name)
  406 +{
  407 + // Write header into logger
  408 + log_header1(TERSE, gammalib::number("Publish event list", m_obs.size()));
  409 +
  410 + // Loop over all observation in the container
  411 + for (int i = 0; i < m_obs.size(); ++i) {
  412 +
  413 + // Get CTA observation
  414 + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);
  415 +
  416 + // Handle only CTA observations
  417 + if (obs != NULL) {
  418 +
  419 + // Continue only if there is an event list
  420 + if (obs->events()->size() != 0) {
  421 +
  422 + // Set default name if user name is empty
  423 + std::string user_name(name);
  424 + if (user_name.empty()) {
  425 + user_name = CTSELECT_NAME;
  426 + }
  427 +
  428 + // If there are several event lists then add an index
  429 + if (m_use_xml) {
  430 + user_name += gammalib::str(i);
  431 + }
  432 +
  433 + // Write event list name into logger
  434 + log_value(NORMAL, "Event list name", user_name);
  435 +
  436 + // Write events into in-memory FITS file
  437 + GFits fits;
  438 + obs->write(fits);
  439 +
  440 + // Publish
  441 + fits.publish("EVENTS", user_name);
  442 +
  443 + } // endif: there were events
  444 +
  445 + } // endif: observation was a CTA observation
  446 +
  447 + } // endfor: looped over observations
  448 +
  449 + // Return
  450 + return;
  451 +}
  452 +
  453 +
395 454 /*==========================================================================
396 455 = =
397 456 = Private methods =
... ...
src/ctselect/ctselect.hpp
... ... @@ -61,6 +61,7 @@ public:
61 61 void clear(void);
62 62 void run(void);
63 63 void save(void);
  64 + void publish(const std::string& name = "");
64 65  
65 66 protected:
66 67 // Protected methods
... ...
src/ctselect/ctselect.par
... ... @@ -5,7 +5,7 @@
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # File: ctselect.par #
8   -# Version: 1.0.0 #
  8 +# Version: 1.2.0 #
9 9 # #
10 10 # Author: Jurgen Knodlseder #
11 11 # Jurgen.Knodlseder@irap.omp.eu #
... ... @@ -38,6 +38,7 @@ usethres,s, h, &quot;NONE&quot;,NONE|DEFAULT|USER,, &quot;Energy threshold type&quot;
38 38 #
39 39 # Standard parameters
40 40 #====================
  41 +publish, b, h, no,,, "Publish event list on VO Hub?"
41 42 chatter, i, h, 2,0,4, "Chattiness of output"
42 43 clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
43 44 debug, b, h, no,,, "Debugging mode activated"
... ...
test/test_cslightcrv.py
... ... @@ -126,6 +126,7 @@ class Test(test):
126 126 lcrv['outfile'] = 'cslightcrv_py1.fits'
127 127 lcrv['logfile'] = 'cslightcrv_py1.log'
128 128 lcrv['chatter'] = 2
  129 + lcrv['publish'] = True
129 130  
130 131 # Run cslightcrv script and save light curve
131 132 lcrv.logFileOpen() # Make sure we get a log file
... ...
test/test_csspec.py
... ... @@ -130,6 +130,7 @@ class Test(test):
130 130 spec['emax'] = 100.0
131 131 spec['logfile'] = 'csspec_py1.log'
132 132 spec['chatter'] = 2
  133 + spec['publish'] = True
133 134  
134 135 # Run csspec script
135 136 spec.logFileOpen() # Make sure we get a log file
... ... @@ -155,6 +156,7 @@ class Test(test):
155 156 spec['emax'] = 100.0
156 157 spec['logfile'] = 'csspec_py2.log'
157 158 spec['chatter'] = 3
  159 + spec['publish'] = False
158 160  
159 161 # Execute csspec script
160 162 spec.execute()
... ...
test/test_csviscube.py
... ... @@ -34,7 +34,7 @@ class Test(test):
34 34 # Constructor
35 35 def __init__(self):
36 36 """
37   - Constructor.
  37 + Constructor
38 38 """
39 39 # Call base class constructor
40 40 test.__init__(self)
... ... @@ -45,7 +45,7 @@ class Test(test):
45 45 # Set test functions
46 46 def set(self):
47 47 """
48   - Set all test functions.
  48 + Set all test functions
49 49 """
50 50 # Set test name
51 51 self.name('csviscube')
... ... @@ -60,7 +60,7 @@ class Test(test):
60 60 # Test csviscube on command line
61 61 def _test_cmd(self):
62 62 """
63   - Test csviscube on the command line.
  63 + Test csviscube on the command line
64 64 """
65 65 # Set script name
66 66 csviscube = self._script('csviscube')
... ... @@ -84,7 +84,7 @@ class Test(test):
84 84 # Test csviscube from Python
85 85 def _test_python(self):
86 86 """
87   - Test csviscube from Python.
  87 + Test csviscube from Python
88 88 """
89 89 # Set-up csviscube
90 90 viscube = cscripts.csviscube()
... ... @@ -96,6 +96,7 @@ class Test(test):
96 96 viscube['outfile'] = 'csviscube_py1.fits'
97 97 viscube['logfile'] = 'csviscube_py1.log'
98 98 viscube['chatter'] = 2
  99 + viscube['publish'] = True
99 100  
100 101 # Run script
101 102 viscube.logFileOpen() # Make sure we get a log file
... ...
test/test_ctselect.py
... ... @@ -177,6 +177,7 @@ class Test(test):
177 177 cpy_select['outobs'] = 'ctselect_py2.fits'
178 178 cpy_select['logfile'] = 'ctselect_py2.log'
179 179 cpy_select['chatter'] = 3
  180 + cpy_select['publish'] = True
180 181 cpy_select.logFileOpen() # Needed to get a new log file
181 182 cpy_select.execute()
182 183  
... ...