From 9d485f9c573661f485ef04f72cda14414b91a7e5 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 10 Jul 2019 22:19:41 +0200 Subject: [PATCH] Integrate code --- ChangeLog | 4 +++- NEWS | 18 ++++++++++++++---- doc/source/admin/release_history/1.7.rst | 2 ++ examples/show_butterfly.py | 20 +++++++++++++++----- examples/show_residuals.py | 4 ++-- examples/show_significance_distribution.py | 12 ++++++++---- examples/show_spectrum.py | 16 ++++++++++++++-- src/ctskymap/ctskymap.cpp | 3 +++ src/ctskymap/ctskymap.hpp | 2 +- 9 files changed, 62 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 753efcc..f7b962a 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,10 @@ -2019-05-29 +2019-07-10 * Version 1.7.0 released ======================== + Enabling running of example scripts from objects in memory (#2925) + 2019-06-25 diff --git a/NEWS b/NEWS index 2fef2a0..8458df6 100755 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.7.0 -5 June 2019 +10 July 2019 Introduction @@ -116,7 +116,9 @@ None ctskymap - CTA sky mapping -------------------------- -None +Added ctskymap::fits() method to allow access of FITS file object before +saving the object to disk. This allows manipulation of ctskymap results without +writing a FITS file (#2925). cttsmap - Generation of Test Statistic map @@ -216,7 +218,13 @@ None csphagen - Generate On/Off observations --------------------------------------- -None +Setting the exclusion map via csphagen.exclusion_map(object=) will now +actually use the exclusion map even if the "inexclusion" parameter is not set. +Before, the only exclusion that would be used was the exclusion passed via the +"inexclusion" "parameter. If re-running csphagen using the "inexclusion" +parameter after setting the map with csphagen.exclusion_map() you should first +call csphagen.exclusion_map(object=gammalib.GSkyRegionMap()). This makes the +map empty and csphagen then checks the "inexclusion" "parameter (#2925). csphasecrv - Generate phase curve @@ -311,7 +319,9 @@ None Examples -------- -None +The example scripts show_butterfly.py, show_spectrum.py, show_residuals.py +and show_significance_distribution.py can now be run using objects that only +exist in memory (#2925). caldb diff --git a/doc/source/admin/release_history/1.7.rst b/doc/source/admin/release_history/1.7.rst index dd55227..e297e08 100644 --- a/doc/source/admin/release_history/1.7.rst +++ b/doc/source/admin/release_history/1.7.rst @@ -22,6 +22,8 @@ Bug fixes Improvements ------------ +* [`2925 `_] - + Enabling running of example scripts from objects in memory New features diff --git a/examples/show_butterfly.py b/examples/show_butterfly.py index a152298..61fabc7 100755 --- a/examples/show_butterfly.py +++ b/examples/show_butterfly.py @@ -2,7 +2,7 @@ # ========================================================================== # Shows butterfly diagram created with ctbutterfly # -# Copyright (C) 2014-2017 Michael Mayer +# Copyright (C) 2014-2019 Michael Mayer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,6 +30,9 @@ except (ImportError, RuntimeError): sys.exit() +# ======================================== # +# Get butterfly diagram values from a file # +# ======================================== # def get_butterfly_file(filename): """ Get butterfly diagram values @@ -41,14 +44,19 @@ def get_butterfly_file(filename): Returns ------- - See `get_butterfly_csv` + btrfly : dict + Python dictionary defining butterfly plot and best fit spectrum """ # Read butterfly file csv = gammalib.GCsv(filename) + # Return dictionary return get_butterfly_csv(csv) +# =============================================== # +# Get butterfly diagram values from a GCsv object # +# =============================================== # def get_butterfly_csv(csv): """ Get butterfly diagram values from GCsv object @@ -60,7 +68,8 @@ def get_butterfly_csv(csv): Returns ------- - 'dict' defining butterfly plot and best fit spectrum + btrfly : dict + Python dictionary defining butterfly plot and best fit spectrum """ # Initialise arrays to be filled btrfly = { @@ -94,6 +103,7 @@ def get_butterfly_csv(csv): low_error = max(csv.real(index,3)*conv, 1e-26) btrfly['butterfly_y'].append(low_error) + # Return dictionary return btrfly @@ -113,14 +123,14 @@ def plot_butterfly(filename, plotfile): """ # Read butterfly file btrfly = get_butterfly_file(filename) - + # Plot the butterfly and spectral line plt.figure() plt.loglog() plt.grid() plt.xlabel('Energy (TeV)') plt.ylabel(r'E$^2$ $\times$ dN/dE (erg cm$^{-2}$ s$^{-1}$)') - + # Plot the butterfly and spectral line plt.plot(btrfly['line_x'],btrfly['line_y'],color='black',ls='-') plt.fill(btrfly['butterfly_x'],btrfly['butterfly_y'],color='green',alpha=0.5) diff --git a/examples/show_residuals.py b/examples/show_residuals.py index 0407bb5..c992f42 100755 --- a/examples/show_residuals.py +++ b/examples/show_residuals.py @@ -2,7 +2,7 @@ # ========================================================================== # Display residuals generated by csresspec # -# Copyright (C) 2017-2018 Luigi Tibaldo +# Copyright (C) 2017-2019 Luigi Tibaldo # # This program is free software: you can redistribute it and/or modify # 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): Plot file name hdu : int Number of observation to plot - fits : `~gammalib.GFits` + fits : `~gammalib.GFits`, optional GFits object containing csresspec results """ # Read spectrum file diff --git a/examples/show_significance_distribution.py b/examples/show_significance_distribution.py index 09cbc82..20d88af 100755 --- a/examples/show_significance_distribution.py +++ b/examples/show_significance_distribution.py @@ -171,7 +171,7 @@ def skymap_to_numpy_ndarray(skymap): for ipix in range(npix): array[ipix] = skymap[ipix] - # Return + # Return array return array @@ -205,6 +205,7 @@ def regions_to_map(regions, init_map): # Add ds9 region map to global map regions_map += ds9_map.map() + # Return regions map return regions_map @@ -243,7 +244,7 @@ def read_regions(fpath): raise RuntimeError('Invalid regions file detected. Please provide ' + 'a valid ds9 or FITS WCS regions file.') - # Return + # Return regions return regions @@ -323,15 +324,18 @@ def plot_significance_distribution(mappath, nbins, sigma_min, sigma_max, includedregs=include_regs, excludedregs=exclude_regs, title=title, plotfile=plotfile) + # Return return +# ========================== # +# Generate significance plot # +# ========================== # def plot_significance(sigmap, nbins, sigma_min, sigma_max, includedregs=None, excludedregs=None, title='', plotfile=''): """ - Plot the significance distribution and return instance of pyplot - figure and axis. + Generate significance plot Parameters ---------- diff --git a/examples/show_spectrum.py b/examples/show_spectrum.py index 73b7079..0cd9549 100755 --- a/examples/show_spectrum.py +++ b/examples/show_spectrum.py @@ -30,6 +30,9 @@ import gammalib import cscripts +# ===================================== # +# Extract the spectrum info from a file # +# ===================================== # def get_spectrum_file(filename): """ Extract the spectrum info from a file for plotting @@ -41,13 +44,19 @@ def get_spectrum_file(filename): Returns ------- - Python dictionary defining spectral plot parameters + spec : dict + Python dictionary defining spectral plot parameters """ # Read spectrum file fits = gammalib.GFits(filename) + + # Return dictionary return get_spectrum_fits(fits) +# ============================================= # +# Extract the spectrum info from a GFits object # +# ============================================= # def get_spectrum_fits(fits): """ Extract the spectrum info from a GFits object @@ -59,7 +68,8 @@ def get_spectrum_fits(fits): Returns ------- - Python dictionary defining spectral plot parameters + spec : dict + Python dictionary defining spectral plot parameters """ # Read spectrum objects table = fits.table(1) @@ -113,6 +123,7 @@ def get_spectrum_fits(fits): # Set upper limit errors spec['yerr'] = [0.6 * x for x in spec['ul_flux']] + # Return dictionary return spec @@ -130,6 +141,7 @@ def plot_spectrum(filename, plotfile): plotfile : str Plot file name """ + # Get spectrum parameters spec = get_spectrum_file(filename) # Create the plot diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index c784dcb..6b0a285 100755 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -291,6 +291,9 @@ void ctskymap::save(void) ***************************************************************************/ void ctskymap::construct_fits(void) { + // Clear FITS object + m_fits.clear(); + // Write sky map into FITS object write_map(m_fits, m_skymap, "SKYMAP"); diff --git a/src/ctskymap/ctskymap.hpp b/src/ctskymap/ctskymap.hpp index af8dfe0..cca16e4 100755 --- a/src/ctskymap/ctskymap.hpp +++ b/src/ctskymap/ctskymap.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctskymap - Sky mapping tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2018 by Juergen Knoedlseder * + * copyright (C) 2010-2019 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * -- libgit2 0.21.4