Commit 9d485f9c573661f485ef04f72cda14414b91a7e5

Authored by Jürgen Knödlseder
1 parent 9117c45c

Integrate code

ChangeLog
1 -2019-05-29 1 +2019-07-10
2 2
3 * Version 1.7.0 released 3 * Version 1.7.0 released
4 ======================== 4 ========================
5 5
  6 + Enabling running of example scripts from objects in memory (#2925)
  7 +
6 8
7 2019-06-25 9 2019-06-25
8 10
1 New Features and Important Changes in ctools 1.7.0 1 New Features and Important Changes in ctools 1.7.0
2 2
3 -5 June 2019 3 +10 July 2019
4 4
5 5
6 Introduction 6 Introduction
@@ -116,7 +116,9 @@ None @@ -116,7 +116,9 @@ None
116 116
117 ctskymap - CTA sky mapping 117 ctskymap - CTA sky mapping
118 -------------------------- 118 --------------------------
119 -None 119 +Added ctskymap::fits() method to allow access of FITS file object before
  120 +saving the object to disk. This allows manipulation of ctskymap results without
  121 +writing a FITS file (#2925).
120 122
121 123
122 cttsmap - Generation of Test Statistic map 124 cttsmap - Generation of Test Statistic map
@@ -216,7 +218,13 @@ None @@ -216,7 +218,13 @@ None
216 218
217 csphagen - Generate On/Off observations 219 csphagen - Generate On/Off observations
218 --------------------------------------- 220 ---------------------------------------
219 -None 221 +Setting the exclusion map via csphagen.exclusion_map(object=<map>) will now
  222 +actually use the exclusion map even if the "inexclusion" parameter is not set.
  223 +Before, the only exclusion that would be used was the exclusion passed via the
  224 +"inexclusion" "parameter. If re-running csphagen using the "inexclusion"
  225 +parameter after setting the map with csphagen.exclusion_map() you should first
  226 +call csphagen.exclusion_map(object=gammalib.GSkyRegionMap()). This makes the
  227 +map empty and csphagen then checks the "inexclusion" "parameter (#2925).
220 228
221 229
222 csphasecrv - Generate phase curve 230 csphasecrv - Generate phase curve
@@ -311,7 +319,9 @@ None @@ -311,7 +319,9 @@ None
311 319
312 Examples 320 Examples
313 -------- 321 --------
314 -None 322 +The example scripts show_butterfly.py, show_spectrum.py, show_residuals.py
  323 +and show_significance_distribution.py can now be run using objects that only
  324 +exist in memory (#2925).
315 325
316 326
317 caldb 327 caldb
doc/source/admin/release_history/1.7.rst
@@ -22,6 +22,8 @@ Bug fixes @@ -22,6 +22,8 @@ Bug fixes
22 Improvements 22 Improvements
23 ------------ 23 ------------
24 24
  25 +* [`2925 <https://cta-redmine.irap.omp.eu/issues/2925>`_] -
  26 + Enabling running of example scripts from objects in memory
25 27
26 28
27 New features 29 New features
examples/show_butterfly.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Shows butterfly diagram created with ctbutterfly 3 # Shows butterfly diagram created with ctbutterfly
4 # 4 #
5 -# Copyright (C) 2014-2017 Michael Mayer 5 +# Copyright (C) 2014-2019 Michael Mayer
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -30,6 +30,9 @@ except (ImportError, RuntimeError): @@ -30,6 +30,9 @@ except (ImportError, RuntimeError):
30 sys.exit() 30 sys.exit()
31 31
32 32
  33 +# ======================================== #
  34 +# Get butterfly diagram values from a file #
  35 +# ======================================== #
33 def get_butterfly_file(filename): 36 def get_butterfly_file(filename):
34 """ 37 """
35 Get butterfly diagram values 38 Get butterfly diagram values
@@ -41,14 +44,19 @@ def get_butterfly_file(filename): @@ -41,14 +44,19 @@ def get_butterfly_file(filename):
41 44
42 Returns 45 Returns
43 ------- 46 -------
44 - See `get_butterfly_csv` 47 + btrfly : dict
  48 + Python dictionary defining butterfly plot and best fit spectrum
45 """ 49 """
46 # Read butterfly file 50 # Read butterfly file
47 csv = gammalib.GCsv(filename) 51 csv = gammalib.GCsv(filename)
48 52
  53 + # Return dictionary
49 return get_butterfly_csv(csv) 54 return get_butterfly_csv(csv)
50 55
51 56
  57 +# =============================================== #
  58 +# Get butterfly diagram values from a GCsv object #
  59 +# =============================================== #
52 def get_butterfly_csv(csv): 60 def get_butterfly_csv(csv):
53 """ 61 """
54 Get butterfly diagram values from GCsv object 62 Get butterfly diagram values from GCsv object
@@ -60,7 +68,8 @@ def get_butterfly_csv(csv): @@ -60,7 +68,8 @@ def get_butterfly_csv(csv):
60 68
61 Returns 69 Returns
62 ------- 70 -------
63 - 'dict' defining butterfly plot and best fit spectrum 71 + btrfly : dict
  72 + Python dictionary defining butterfly plot and best fit spectrum
64 """ 73 """
65 # Initialise arrays to be filled 74 # Initialise arrays to be filled
66 btrfly = { 75 btrfly = {
@@ -94,6 +103,7 @@ def get_butterfly_csv(csv): @@ -94,6 +103,7 @@ def get_butterfly_csv(csv):
94 low_error = max(csv.real(index,3)*conv, 1e-26) 103 low_error = max(csv.real(index,3)*conv, 1e-26)
95 btrfly['butterfly_y'].append(low_error) 104 btrfly['butterfly_y'].append(low_error)
96 105
  106 + # Return dictionary
97 return btrfly 107 return btrfly
98 108
99 109
@@ -113,14 +123,14 @@ def plot_butterfly(filename, plotfile): @@ -113,14 +123,14 @@ def plot_butterfly(filename, plotfile):
113 """ 123 """
114 # Read butterfly file 124 # Read butterfly file
115 btrfly = get_butterfly_file(filename) 125 btrfly = get_butterfly_file(filename)
116 - 126 +
117 # Plot the butterfly and spectral line 127 # Plot the butterfly and spectral line
118 plt.figure() 128 plt.figure()
119 plt.loglog() 129 plt.loglog()
120 plt.grid() 130 plt.grid()
121 plt.xlabel('Energy (TeV)') 131 plt.xlabel('Energy (TeV)')
122 plt.ylabel(r'E$^2$ $\times$ dN/dE (erg cm$^{-2}$ s$^{-1}$)') 132 plt.ylabel(r'E$^2$ $\times$ dN/dE (erg cm$^{-2}$ s$^{-1}$)')
123 - 133 +
124 # Plot the butterfly and spectral line 134 # Plot the butterfly and spectral line
125 plt.plot(btrfly['line_x'],btrfly['line_y'],color='black',ls='-') 135 plt.plot(btrfly['line_x'],btrfly['line_y'],color='black',ls='-')
126 plt.fill(btrfly['butterfly_x'],btrfly['butterfly_y'],color='green',alpha=0.5) 136 plt.fill(btrfly['butterfly_x'],btrfly['butterfly_y'],color='green',alpha=0.5)
examples/show_residuals.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # Display residuals generated by csresspec 3 # Display residuals generated by csresspec
4 # 4 #
5 -# Copyright (C) 2017-2018 Luigi Tibaldo 5 +# Copyright (C) 2017-2019 Luigi Tibaldo
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -147,7 +147,7 @@ def plot_residuals(filename, plotfile, hdu, fits=None): @@ -147,7 +147,7 @@ def plot_residuals(filename, plotfile, hdu, fits=None):
147 Plot file name 147 Plot file name
148 hdu : int 148 hdu : int
149 Number of observation to plot 149 Number of observation to plot
150 - fits : `~gammalib.GFits` 150 + fits : `~gammalib.GFits`, optional
151 GFits object containing csresspec results 151 GFits object containing csresspec results
152 """ 152 """
153 # Read spectrum file 153 # Read spectrum file
examples/show_significance_distribution.py
@@ -171,7 +171,7 @@ def skymap_to_numpy_ndarray(skymap): @@ -171,7 +171,7 @@ def skymap_to_numpy_ndarray(skymap):
171 for ipix in range(npix): 171 for ipix in range(npix):
172 array[ipix] = skymap[ipix] 172 array[ipix] = skymap[ipix]
173 173
174 - # Return 174 + # Return array
175 return array 175 return array
176 176
177 177
@@ -205,6 +205,7 @@ def regions_to_map(regions, init_map): @@ -205,6 +205,7 @@ def regions_to_map(regions, init_map):
205 # Add ds9 region map to global map 205 # Add ds9 region map to global map
206 regions_map += ds9_map.map() 206 regions_map += ds9_map.map()
207 207
  208 + # Return regions map
208 return regions_map 209 return regions_map
209 210
210 211
@@ -243,7 +244,7 @@ def read_regions(fpath): @@ -243,7 +244,7 @@ def read_regions(fpath):
243 raise RuntimeError('Invalid regions file detected. Please provide ' + 244 raise RuntimeError('Invalid regions file detected. Please provide ' +
244 'a valid ds9 or FITS WCS regions file.') 245 'a valid ds9 or FITS WCS regions file.')
245 246
246 - # Return 247 + # Return regions
247 return regions 248 return regions
248 249
249 250
@@ -323,15 +324,18 @@ def plot_significance_distribution(mappath, nbins, sigma_min, sigma_max, @@ -323,15 +324,18 @@ def plot_significance_distribution(mappath, nbins, sigma_min, sigma_max,
323 includedregs=include_regs, excludedregs=exclude_regs, 324 includedregs=include_regs, excludedregs=exclude_regs,
324 title=title, plotfile=plotfile) 325 title=title, plotfile=plotfile)
325 326
  327 + # Return
326 return 328 return
327 329
328 330
  331 +# ========================== #
  332 +# Generate significance plot #
  333 +# ========================== #
329 def plot_significance(sigmap, nbins, sigma_min, sigma_max, 334 def plot_significance(sigmap, nbins, sigma_min, sigma_max,
330 includedregs=None, excludedregs=None, 335 includedregs=None, excludedregs=None,
331 title='', plotfile=''): 336 title='', plotfile=''):
332 """ 337 """
333 - Plot the significance distribution and return instance of pyplot  
334 - figure and axis. 338 + Generate significance plot
335 339
336 Parameters 340 Parameters
337 ---------- 341 ----------
examples/show_spectrum.py
@@ -30,6 +30,9 @@ import gammalib @@ -30,6 +30,9 @@ import gammalib
30 import cscripts 30 import cscripts
31 31
32 32
  33 +# ===================================== #
  34 +# Extract the spectrum info from a file #
  35 +# ===================================== #
33 def get_spectrum_file(filename): 36 def get_spectrum_file(filename):
34 """ 37 """
35 Extract the spectrum info from a file for plotting 38 Extract the spectrum info from a file for plotting
@@ -41,13 +44,19 @@ def get_spectrum_file(filename): @@ -41,13 +44,19 @@ def get_spectrum_file(filename):
41 44
42 Returns 45 Returns
43 ------- 46 -------
44 - Python dictionary defining spectral plot parameters 47 + spec : dict
  48 + Python dictionary defining spectral plot parameters
45 """ 49 """
46 # Read spectrum file 50 # Read spectrum file
47 fits = gammalib.GFits(filename) 51 fits = gammalib.GFits(filename)
  52 +
  53 + # Return dictionary
48 return get_spectrum_fits(fits) 54 return get_spectrum_fits(fits)
49 55
50 56
  57 +# ============================================= #
  58 +# Extract the spectrum info from a GFits object #
  59 +# ============================================= #
51 def get_spectrum_fits(fits): 60 def get_spectrum_fits(fits):
52 """ 61 """
53 Extract the spectrum info from a GFits object 62 Extract the spectrum info from a GFits object
@@ -59,7 +68,8 @@ def get_spectrum_fits(fits): @@ -59,7 +68,8 @@ def get_spectrum_fits(fits):
59 68
60 Returns 69 Returns
61 ------- 70 -------
62 - Python dictionary defining spectral plot parameters 71 + spec : dict
  72 + Python dictionary defining spectral plot parameters
63 """ 73 """
64 # Read spectrum objects 74 # Read spectrum objects
65 table = fits.table(1) 75 table = fits.table(1)
@@ -113,6 +123,7 @@ def get_spectrum_fits(fits): @@ -113,6 +123,7 @@ def get_spectrum_fits(fits):
113 # Set upper limit errors 123 # Set upper limit errors
114 spec['yerr'] = [0.6 * x for x in spec['ul_flux']] 124 spec['yerr'] = [0.6 * x for x in spec['ul_flux']]
115 125
  126 + # Return dictionary
116 return spec 127 return spec
117 128
118 129
@@ -130,6 +141,7 @@ def plot_spectrum(filename, plotfile): @@ -130,6 +141,7 @@ def plot_spectrum(filename, plotfile):
130 plotfile : str 141 plotfile : str
131 Plot file name 142 Plot file name
132 """ 143 """
  144 + # Get spectrum parameters
133 spec = get_spectrum_file(filename) 145 spec = get_spectrum_file(filename)
134 146
135 # Create the plot 147 # Create the plot
src/ctskymap/ctskymap.cpp
@@ -291,6 +291,9 @@ void ctskymap::save(void) @@ -291,6 +291,9 @@ void ctskymap::save(void)
291 ***************************************************************************/ 291 ***************************************************************************/
292 void ctskymap::construct_fits(void) 292 void ctskymap::construct_fits(void)
293 { 293 {
  294 + // Clear FITS object
  295 + m_fits.clear();
  296 +
294 // Write sky map into FITS object 297 // Write sky map into FITS object
295 write_map(m_fits, m_skymap, "SKYMAP"); 298 write_map(m_fits, m_skymap, "SKYMAP");
296 299
src/ctskymap/ctskymap.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctskymap - Sky mapping tool * 2 * ctskymap - Sky mapping tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2010-2018 by Juergen Knoedlseder * 4 + * copyright (C) 2010-2019 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *