Commit b030e64d8212048142d6435ba07e0ad4fa446744

Authored by Jürgen Knödlseder
1 parent 9ecb561a

Add ctbutterfly::butterfly() method (#1512)

ChangeLog
1   -2018-01-22
  1 +2018-01-23
2 2  
3 3 * Version 1.5.0 released
4 4 ========================
... ... @@ -7,7 +7,8 @@
7 7 DATE-END, TIME-OBS and TIME-END
8 8 Add CUSTOM background method to csphagen script (#2284)
9 9 Add csresspec script (#2289)
10   - Add ctools::time_reference constant and remove ctools::time_reference() method (#2295)
  10 + Add ctools::time_reference constant and remove ctools::time_reference()
  11 + method (#2295)
11 12 Correctly strip .gz suffix from output filenames (#2287)
12 13 Support On/Off analysis in cslightcrv and csphasecrv (#2273)
13 14 ctselect informs about non-overlapping time interval (#2272)
... ... @@ -25,6 +26,7 @@
25 26 Add "NODES" method to csspec to support non-CTA analysis (#1927)
26 27 Use t-type parameters for all "tmin" and "tmax" parameters (#1864)
27 28 Set OBS_ID in ctobssim (#1836)
  29 + Add ctbutterfly::butterfly() method (#1512)
28 30  
29 31  
30 32 2017-07-28
... ...
1   -22 January 2018
  1 +23 January 2018
2 2  
3 3  
4 4 Introduction
... ... @@ -42,6 +42,8 @@ ctbutterfly - Generate butterfly diagrams
42 42 -----------------------------------------
43 43 Add "statistic" parameter to allow setting of optimizer statistic (#2237).
44 44  
  45 +Add butterfly() method to return the butterfly diagram as CSV object (#1512).
  46 +
45 47  
46 48 ctcubemask - CTA cube filtering
47 49 -------------------------------
... ...
doc/source/admin/release_history/1.5.rst
... ... @@ -58,6 +58,8 @@ Improvements
58 58 Add ``NODES`` method to :ref:`csspec` to support non-CTA analysis
59 59 * [`1836 <https://cta-redmine.irap.omp.eu/issues/1836>`_] -
60 60 Set ``OBS_ID`` in :ref:`ctobssim`
  61 +* [`1512 <https://cta-redmine.irap.omp.eu/issues/1512>`_] -
  62 + Add ``ctbutterfly::butterfly()`` method to return butterfly diagram
61 63  
62 64  
63 65 New features
... ...
pyext/ctbutterfly.i
1 1 /***************************************************************************
2 2 * ctbutterfly - butterfly calculation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014 by Michael Mayer *
  4 + * copyright (C) 2014-2018 by Michael Mayer *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -44,9 +44,10 @@ public:
44 44 virtual ~ctbutterfly(void);
45 45  
46 46 // Methods
47   - void clear(void);
48   - void run(void);
49   - void save(void);
  47 + void clear(void);
  48 + void run(void);
  49 + void save(void);
  50 + const GCsv& butterfly(void) const;
50 51 };
51 52  
52 53  
... ...
src/ctbutterfly/ctbutterfly.cpp
1 1 /***************************************************************************
2 2 * ctbutterfly - butterfly calculation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2017 by Michael Mayer *
  4 + * copyright (C) 2014-2018 by Michael Mayer *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -299,6 +299,9 @@ void ctbutterfly::run(void)
299 299 ellipsoid_boundary(models);
300 300 }
301 301  
  302 + // Set CSV table
  303 + set_csv();
  304 +
302 305 // Write header into logger
303 306 log_header1(TERSE, "Results");
304 307  
... ... @@ -311,7 +314,7 @@ void ctbutterfly::run(void)
311 314 gammalib::str(m_min_intensities[k])+", "+
312 315 gammalib::str(m_max_intensities[k])+") ph/cm2/s/MeV");
313 316  
314   - } //endfor: loop over energy bin
  317 + } // endfor: loop over energy bin
315 318  
316 319 // Restore energy dispersion flag for all CTA observations
317 320 for (int i = 0; i < m_obs.size(); ++i) {
... ... @@ -329,7 +332,7 @@ void ctbutterfly::run(void)
329 332 /***********************************************************************//**
330 333 * @brief Save butterfly diagram
331 334 *
332   - * Saves the butterfly diagram into an ascii file using a column separated
  335 + * Saves the butterfly diagram into an ASCII file using a column separated
333 336 * value (CSV) format with blanks as separators.
334 337 ***************************************************************************/
335 338 void ctbutterfly::save(void)
... ... @@ -346,19 +349,8 @@ void ctbutterfly::save(void)
346 349 // Log butterfly diagram file name
347 350 log_value(NORMAL, "Butterfly file", m_outfile.url());
348 351  
349   - // Create CSV table with 4 columns
350   - GCsv table(m_energies.size(), 4);
351   -
352   - // Fill CSV table
353   - for (int i = 0; i < m_energies.size(); ++i) {
354   - table.real(i, 0, m_energies[i]);
355   - table.real(i, 1, m_intensities[i]);
356   - table.real(i, 2, m_min_intensities[i]);
357   - table.real(i, 3, m_max_intensities[i]);
358   - }
359   -
360 352 // Save CSV table
361   - table.save(m_outfile.url(), " ", clobber());
  353 + m_csv.save(m_outfile.url(), " ", clobber());
362 354  
363 355 }
364 356  
... ... @@ -395,6 +387,7 @@ void ctbutterfly::init_members(void)
395 387 m_intensities.clear();
396 388 m_min_intensities.clear();
397 389 m_max_intensities.clear();
  390 + m_csv.clear();
398 391  
399 392 // Set optimizer parameters
400 393 m_opt.max_iter(m_max_iter);
... ... @@ -429,6 +422,7 @@ void ctbutterfly::copy_members(const ctbutterfly&amp; app)
429 422 m_intensities = app.m_intensities;
430 423 m_min_intensities = app.m_min_intensities;
431 424 m_max_intensities = app.m_max_intensities;
  425 + m_csv = app.m_csv;
432 426  
433 427 // Return
434 428 return;
... ... @@ -851,13 +845,13 @@ void ctbutterfly::check_model(void)
851 845 * http://www.math.harvard.edu/archive/21b_fall_04/exhibits/2dmatrices/index.html
852 846 ***************************************************************************/
853 847 void ctbutterfly::eigenvectors(const double& a,
854   - const double& b,
855   - const double& c,
856   - const double& d,
857   - double* lambda1,
858   - double* lambda2,
859   - GVector* vector1,
860   - GVector* vector2)
  848 + const double& b,
  849 + const double& c,
  850 + const double& d,
  851 + double* lambda1,
  852 + double* lambda2,
  853 + GVector* vector1,
  854 + GVector* vector2)
861 855 {
862 856 // Compute trace and determinant
863 857 double trace = a + d;
... ... @@ -896,3 +890,26 @@ void ctbutterfly::eigenvectors(const double&amp; a,
896 890 // Return
897 891 return;
898 892 }
  893 +
  894 +
  895 +/***********************************************************************//**
  896 + * @brief Set CSV object
  897 + *
  898 + * Set CSV object with results.
  899 + ***************************************************************************/
  900 +void ctbutterfly::set_csv(void)
  901 +{
  902 + // Create CSV table with 4 columns
  903 + m_csv = GCsv(m_energies.size(), 4);
  904 +
  905 + // Fill CSV table
  906 + for (int i = 0; i < m_energies.size(); ++i) {
  907 + m_csv.real(i, 0, m_energies[i]);
  908 + m_csv.real(i, 1, m_intensities[i]);
  909 + m_csv.real(i, 2, m_min_intensities[i]);
  910 + m_csv.real(i, 3, m_max_intensities[i]);
  911 + }
  912 +
  913 + // Return
  914 + return;
  915 +}
... ...
src/ctbutterfly/ctbutterfly.hpp
1 1 /***************************************************************************
2 2 * ctbutterfly - butterfly calculation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2017 by Michael Mayer *
  4 + * copyright (C) 2014-2018 by Michael Mayer *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -66,9 +66,10 @@ public:
66 66 ctbutterfly& operator=(const ctbutterfly& app);
67 67  
68 68 // Methods
69   - void clear(void);
70   - void run(void);
71   - void save(void);
  69 + void clear(void);
  70 + void run(void);
  71 + void save(void);
  72 + const GCsv& butterfly(void) const;
72 73  
73 74 protected:
74 75 // Protected methods
... ... @@ -78,8 +79,6 @@ protected:
78 79 void get_parameters(void);
79 80 void gaussian_error_propagation(GModels& models);
80 81 void ellipsoid_boundary(GModels& models);
81   -
82   -
83 82 void check_model(void);
84 83 void eigenvectors(const double& a,
85 84 const double& b,
... ... @@ -89,6 +88,7 @@ protected:
89 88 double* lambda2,
90 89 GVector* vector1,
91 90 GVector* vector2);
  91 + void set_csv(void);
92 92  
93 93 // User parameters
94 94 std::string m_srcname; //!< Name of source to compute butterfly
... ... @@ -107,7 +107,19 @@ protected:
107 107 std::vector<double> m_intensities; //!< Power law intensity
108 108 std::vector<double> m_min_intensities; //!< Minimum intensities
109 109 std::vector<double> m_max_intensities; //!< Maximum intensities
  110 + GCsv m_csv; //!< CSV table filled by run() method
110 111 };
111 112  
112 113  
  114 +/***********************************************************************//**
  115 + * @brief Return butterfly
  116 + *
  117 + * @return Butterfly as CSV table.
  118 + ***************************************************************************/
  119 +inline
  120 +const GCsv& ctbutterfly::butterfly(void) const
  121 +{
  122 + return (m_csv);
  123 +}
  124 +
113 125 #endif /* CTBUTTERFLY_HPP */
... ...
src/ctlike/ctlike.cpp
... ... @@ -360,7 +360,7 @@ void ctlike::save(void)
360 360 // Log filename
361 361 log_value(NORMAL, "Covariance matrix file", m_outcovmat.url());
362 362  
363   - // Save covarianve matrix
  363 + // Save covariance matrix
364 364 m_obs.function().save(m_outcovmat);
365 365  
366 366 }
... ...