Commit e3e3c9107d9892854adfa99fffac719b97179e5a
1 parent
98512543
Update documentation and pyext
Showing
4 changed files
with
89 additions
and
29 deletions
pyext/ctbin.i
src/ctbin/ctbin.cpp
| ... | ... | @@ -398,7 +398,6 @@ void ctbin::save(void) |
| 398 | 398 | log_header1(TERSE, "Save counts cube"); |
| 399 | 399 | |
| 400 | 400 | if (!m_stack) { |
| 401 | - std::cout << m_prefix << std::endl; | |
| 402 | 401 | |
| 403 | 402 | // Loop over all observations |
| 404 | 403 | for (size_t i = 0; i < m_obs.size(); ++i) { |
| ... | ... | @@ -428,32 +427,33 @@ void ctbin::save(void) |
| 428 | 427 | m_outcube = (*this)["outcube"].filename(); |
| 429 | 428 | m_obs.save(m_outcube); |
| 430 | 429 | } |
| 431 | - return; | |
| 432 | - } | |
| 433 | - | |
| 434 | - // Save only if filename is valid and if there is at least one | |
| 435 | - // observation | |
| 436 | - if ((*this)["outcube"].is_valid() && m_obs.size() > 0) { | |
| 437 | - | |
| 438 | - // Get counts cube filename | |
| 439 | - m_outcube = (*this)["outcube"].filename(); | |
| 440 | - | |
| 441 | - // Get CTA observation from observation container | |
| 442 | - GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]); | |
| 443 | - | |
| 444 | - // Save only if observation is valid | |
| 445 | - if (obs != NULL) { | |
| 446 | - | |
| 447 | - // Log counts cube file name | |
| 448 | - log_value(NORMAL, "Counts cube file", m_outcube.url()); | |
| 449 | - | |
| 450 | - // Save cube | |
| 451 | - obs->save(m_outcube, clobber()); | |
| 452 | - | |
| 453 | - } // endif: observation was valid | |
| 454 | - | |
| 455 | - } // endif: outcube file was valid | |
| 430 | + | |
| 431 | + } else { // else: stack | |
| 456 | 432 | |
| 433 | + // Save only if filename is valid and if there is at least one | |
| 434 | + // observation | |
| 435 | + if ((*this)["outcube"].is_valid() && m_obs.size() > 0) { | |
| 436 | + | |
| 437 | + // Get counts cube filename | |
| 438 | + m_outcube = (*this)["outcube"].filename(); | |
| 439 | + | |
| 440 | + // Get CTA observation from observation container | |
| 441 | + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]); | |
| 442 | + | |
| 443 | + // Save only if observation is valid | |
| 444 | + if (obs != NULL) { | |
| 445 | + | |
| 446 | + // Log counts cube file name | |
| 447 | + log_value(NORMAL, "Counts cube file", m_outcube.url()); | |
| 448 | + | |
| 449 | + // Save cube | |
| 450 | + obs->save(m_outcube, clobber()); | |
| 451 | + | |
| 452 | + } // endif: observation was valid | |
| 453 | + | |
| 454 | + } // endif: outcube file was valid | |
| 455 | + | |
| 456 | + } // endelse: stack | |
| 457 | 457 | // Return |
| 458 | 458 | return; |
| 459 | 459 | } | ... | ... |
src/ctbin/ctbin.hpp
| ... | ... | @@ -39,7 +39,7 @@ |
| 39 | 39 | * |
| 40 | 40 | * @brief Event binning tool |
| 41 | 41 | * |
| 42 | - * This class bins event list(s) into a single counts cube. The class can | |
| 42 | + * This class bins event list(s) into counts cubes. The class can | |
| 43 | 43 | * operate on predefined observation containers, on individual event list |
| 44 | 44 | * FITS files, and on observation definition XML files. |
| 45 | 45 | * |
| ... | ... | @@ -47,6 +47,13 @@ |
| 47 | 47 | * XML definition file, the class will merge these events into a single |
| 48 | 48 | * counts cube. |
| 49 | 49 | * |
| 50 | + * If the hidden parameter stack=no is used, one counts cube is generated for | |
| 51 | + * each individual observation. These cubes are saved to a path that can be | |
| 52 | + * specified by the hidden parameter prefix, followed by the corresponding | |
| 53 | + * observation id. An observation definition XML file containing the paths | |
| 54 | + * to the newly generated counts cubes is written to path given in the | |
| 55 | + * parameter outcube. | |
| 56 | + * | |
| 50 | 57 | * Results are stored in an observation container that can be written to disk |
| 51 | 58 | * in form of a single FITS file. On output, the observation container will |
| 52 | 59 | * have merged the input event lists into a single observation. |
| ... | ... | @@ -77,6 +84,7 @@ public: |
| 77 | 84 | void save(void); |
| 78 | 85 | void publish(const std::string& name = ""); |
| 79 | 86 | const GCTAEventCube& cube(void) const; |
| 87 | + const GCTAEventCube& cube(const size_t& index) const; | |
| 80 | 88 | |
| 81 | 89 | protected: |
| 82 | 90 | // Protected methods |
| ... | ... | @@ -104,8 +112,8 @@ protected: |
| 104 | 112 | GCTAEventCube m_cube; //!< Events cube (for cube() method) |
| 105 | 113 | double m_ontime; //!< Total ontime |
| 106 | 114 | double m_livetime; //!< Total livetime |
| 107 | - std::vector<GCTAEventCube> m_cubes; | |
| 108 | - std::vector<std::string> m_ids; | |
| 115 | + std::vector<GCTAEventCube> m_cubes; //!< Event cubes (for cube() method) | |
| 116 | + std::vector<std::string> m_ids; //!< Observation ids | |
| 109 | 117 | |
| 110 | 118 | // Cache members |
| 111 | 119 | std::vector<GSkyDir> m_dirs; //!< Cached GSkyDir for each pixel in m_counts |
| ... | ... | @@ -125,4 +133,19 @@ const GCTAEventCube& ctbin::cube(void) const |
| 125 | 133 | return m_cube; |
| 126 | 134 | } |
| 127 | 135 | |
| 136 | + | |
| 137 | +/***********************************************************************//** | |
| 138 | + * @brief Return event cube at index | |
| 139 | + * | |
| 140 | + * @param[in] index Index of cube | |
| 141 | + * @return Reference to event cube | |
| 142 | + * | |
| 143 | + * Returns a reference to the event cube at the given index. | |
| 144 | + ***************************************************************************/ | |
| 145 | +inline | |
| 146 | +const GCTAEventCube& ctbin::cube(const size_t& index) const | |
| 147 | +{ | |
| 148 | + return m_cubes[index]; | |
| 149 | +} | |
| 150 | + | |
| 128 | 151 | #endif /* CTBIN_HPP */ | ... | ... |
test/test_ctbin.py
| ... | ... | @@ -294,6 +294,42 @@ class Test(test): |
| 294 | 294 | evt = gammalib.GCTAEventCube('ctbin_py4.fits') |
| 295 | 295 | self._check_cube(evt, 245) |
| 296 | 296 | |
| 297 | + # Test unstacked version | |
| 298 | + pars = {'inobs': self._datadir+'/obs_unbinned_two.xml', 'ebinalg': 'LIN', 'emin': 1.0, | |
| 299 | + 'emax': 100.0, 'enumbins': 10, 'nxpix': 40, 'nypix': 40, | |
| 300 | + 'binsz': 0.1, 'coordsys': 'CEL', 'proj': 'CAR', | |
| 301 | + 'xref': 83.63, 'yref': 22.01, 'outcube': 'ctbin_py5.xml', | |
| 302 | + 'logfile': 'ctbin_py5.log', 'chatter': 2, | |
| 303 | + 'prefix': 'cntcube_py5_', 'stack' : False} | |
| 304 | + binning = ctools.ctbin() | |
| 305 | + binning.pardict(pars) | |
| 306 | + | |
| 307 | + binning.logFileOpen() | |
| 308 | + binning.run() | |
| 309 | + | |
| 310 | + # Check individual cubes | |
| 311 | + self._check_cube(binning.cube(0), 245) | |
| 312 | + self._check_cube(binning.cube(1), 245) | |
| 313 | + | |
| 314 | + # Save counts cube | |
| 315 | + binning.save() | |
| 316 | + | |
| 317 | + # Load observations | |
| 318 | + obs = gammalib.GObservations('ctbin_py5.xml') | |
| 319 | + self.test_value(obs.size(), 2, 'Check number of output observations') | |
| 320 | + | |
| 321 | + # Check counts cubes | |
| 322 | + evt = obs[0].events() | |
| 323 | + self._check_cube(evt, 245) | |
| 324 | + evt = obs[1].events() | |
| 325 | + self._check_cube(evt, 245) | |
| 326 | + | |
| 327 | + # Load counts cubes and check content | |
| 328 | + evt = gammalib.GCTAEventCube('cntcube_py5_00001.fits') | |
| 329 | + self._check_cube(evt, 245) | |
| 330 | + evt = gammalib.GCTAEventCube('cntcube_py5_00002.fits') | |
| 331 | + self._check_cube(evt, 245) | |
| 332 | + | |
| 297 | 333 | # Return |
| 298 | 334 | return |
| 299 | 335 | ... | ... |