Commit 587d5c242ebbf82e5db6a36d805e11f4a7eaedc3

Authored by IftachSadeh
2 parents f16e6233 cee51042

Merge branch 'devel' of https://cta-gitlab.irap.omp.eu/ctools/ctools into bug355…

…5_cssens_source_location
ChangeLog
1   -2021-03-05
  1 +2021-04-30
2 2  
3 3 * Version 2.0.0 released
4 4 ========================
5 5  
  6 + Add ASCL shields to "About" page (#3630)
  7 + Use file function constructor in csspec (#3626)
  8 + Add BINS method to csspec (#3606)
6 9 Add hidden "fix_spat" parameter to cttsmap (#3562)
7 10 Add optimizer setter to ctlikelihood base class
8 11 Add Sphinx tutorials test script (#3510)
... ... @@ -15,6 +18,16 @@
15 18 Add support of rectangular On/Off regions (#3248)
16 19  
17 20  
  21 +2021-04-28
  22 +
  23 + * Bug fix version 1.7.4 released
  24 + ================================
  25 +
  26 + Add conda activation and deactivation scripts for csh (#3628)
  27 + Replace spectral model by file function in csspec (#3624)
  28 + Update csinfo script (#3623)
  29 +
  30 +
18 31 2020-12-02
19 32  
20 33 * Bug fix version 1.7.3 released
... ...
Makefile.am
... ... @@ -33,9 +33,11 @@ pkgconfig_DATA = ctools.pc
33 33  
34 34 # Conda activate directory
35 35 condaactivatedir = $(sysconfdir)/conda/activate.d
36   -condaactivate_DATA = dev/01-ctools-activate.sh
  36 +condaactivate_DATA = dev/01-ctools-activate.sh \
  37 + dev/01-ctools-activate.csh
37 38 condadeactivatedir = $(sysconfdir)/conda/deactivate.d
38   -condadeactivate_DATA = dev/00-ctools-deactivate.sh
  39 +condadeactivate_DATA = dev/00-ctools-deactivate.sh \
  40 + dev/00-ctools-deactivate.csh
39 41  
40 42 # Manual pages to install
41 43 man_MANS =
... ... @@ -55,6 +57,7 @@ EXTRA_DIST = README.md \
55 57 doc/Doxyfile doc/source \
56 58 dev/testreport.py \
57 59 dev/01-ctools-activate.sh dev/00-ctools-deactivate.sh \
  60 + dev/01-ctools-activate.csh dev/00-ctools-deactivate.csh \
58 61 dev/conda.recipe/build.sh \
59 62 dev/conda.recipe/conda_build_config.yaml \
60 63 dev/conda.recipe/meta.yaml.in
... ...
1 1 New Features and Important Changes in ctools 2.0.0
2 2  
3   -5 March 2021
  3 +30 April 2021
4 4  
5 5  
6 6 Introduction
... ... @@ -16,6 +16,8 @@ None
16 16  
17 17 Documentation
18 18 -------------
  19 +Add Astrophysics Source Code Library (ASCL) shields to "About" page (#3630).
  20 +
19 21 Add test/tutorials.py script and check-tutorial target to test the code in the
20 22 Sphinx tutorials (#3510).
21 23  
... ... @@ -285,7 +287,12 @@ None
285 287  
286 288 csspec - Generates Spectral Energy Distribution
287 289 -----------------------------------------------
288   -None
  290 +The GModelSpectralFunc spectral model constructor is now used to convert any
  291 +spectral model into a file function before spectral model fitting (#3626).
  292 +
  293 +Added BINS method that replaces the spectral model by a bin function that is
  294 +implemented by the GammaLib class GModelSpectralBins. Using a bin function
  295 +assures that spectral points are statistically independent (#3606).
289 296  
290 297  
291 298 cssrcdetect - Detects sources in sky map
... ...
README.md
1 1 ctools information
2 2 ==================
3   -* Version: 2.0.0.dev (5 March 2021)
  3 +* Version: 2.0.0.dev (30 April 2021)
4 4 * GammaLib dependency: 2.0.0.dev
5 5  
6 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=ctools-integrate-os)](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/)
... ... @@ -127,8 +127,8 @@ the following:
127 127 $ conda install ctools
128 128  
129 129  
130   -Unix Installation
131   -=================
  130 +Linux Installation
  131 +==================
132 132 To build and install ctools, simply type the following:
133 133  
134 134 $ ./configure
... ... @@ -161,14 +161,14 @@ ctools was correctly built. Make sure that all tests were successful.
161 161  
162 162 Macintosh OS X Installation
163 163 ============================
164   -ctools is known to work on various flavors of OS X. To cope with
  164 +ctools is known to work on various flavors of Mac OS. To cope with
165 165 different system versions and architectures, there are two Mac
166 166 specific configure options:
167 167  
168 168 $ ./configure --enable-universalsdk[=PATH]
169 169  
170 170 creates a universal build of ctools. The optional argument specifies
171   -which OSX SDK should be used to perform the build. This defaults to
  171 +which MacOS SDK should be used to perform the build. This defaults to
172 172 "/Developer/SDKs/MacOSX.10.4u.sdk". Specify "/" when building on a 10.5
173 173 system or higher, especially when building 64-bit code.
174 174  
... ... @@ -221,7 +221,8 @@ shared library (see "Known problems" below).
221 221  
222 222 Windows Installation
223 223 ====================
224   -There have been no efforts so far to compile ctools under Windows.
  224 +On Windows ctools needs to be installed into a virtual machine running
  225 +a Linux distribution.
225 226  
226 227  
227 228 Testing
... ...
cscripts/csinfo.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Print info about Gammalib / ctools to the console
4 4 #
5   -# Copyright (C) 2015-2016 Christoph Deil
  5 +# Copyright (C) 2015-2021 Christoph Deil
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -32,10 +32,13 @@ CTOOL_LIST = """
32 32 ctedispcube Generates energy dispersion cube
33 33 cterror Calculates likelihood profile errors
34 34 ctexpcube Generates exposure cube
  35 + ctfindvar Search for source variability
35 36 ctlike Performs maximum likelihood fitting
36 37 ctmapcube Generates a map cube
37 38 ctmodel Computes model counts cube
38 39 ctobssim Simulate CTA observations
  40 + ctphase Computes the phase of each event
  41 + ctprob Computes event probability for a given model
39 42 ctpsfcube Generates point spread function cube
40 43 ctselect Selects event data
41 44 ctskymap Generates sky map
... ... @@ -47,20 +50,31 @@ CTOOL_LIST = """
47 50 # `doc/source/users/reference_manual/index.rst`
48 51 # and needs to be manually updated and kept in sync
49 52 CSCRIPT_LIST = """
  53 + csbkgmodel Generates background model for 3D analysis
50 54 cscaldb Lists available instrument response functions
  55 + csebins Generates energy boundaries for stacked analysis
51 56 cslightcrv Computes lightcurve
52 57 csinfo Checks ctools and GammaLib installations
53 58 csmodelinfo Shows model container content
54 59 csmodelmerge Merges several model containers into one file
  60 + csmodelselect Select models from model definition file
  61 + csmodelsois Generate map cube from subset of models
55 62 csobsdef Generates observation definition file
56 63 csobsinfo Shows observation container content
  64 + csobsselect Select observations from observation definition file
  65 + csphagen Generates PHA, ARF, RMF files based on source/background regions
  66 + csphasecrv Computes phase curve
57 67 cspull Generates pull distribution
58 68 csresmap Generates residual map
  69 + csresspec Generates residual spectrum
  70 + csscs Performs spectral component separation
59 71 cssens Computes CTA sensitivity
60 72 csspec Computes spectral points
  73 + cssrcdetect Detects sources in sky map
61 74 cstsdist Generates TS distribution
  75 + cstsmapmerge Merges slices from Test Statistic map computations
62 76 cstsmapsplit Creates commands to split the Test Statistic map computations
63   - cstsmapmerge Merges slices from Test Statistic map computations\n
  77 + csviscube Computes visibility cube\n
64 78 csobs2caldb Creates a caldb entry from an input observation
65 79 csroot2caldb Creates a caldb entry from a ROOT performance file
66 80 csiactdata Shows information about IACT data available on the user machine
... ...
cscripts/csphagen.py
... ... @@ -614,7 +614,8 @@ class csphagen(ctools.csobservation):
614 614 msg = ' Skip because the number %d of regions' \
615 615 'for background estimation not overlapping ' \
616 616 'with the exclusion region is smaller than ' \
617   - '"bkgregmin"=%d.' % (bkg_reg.size(), self['bkgregmin'].integer())
  617 + '"bkgregmin"=%d.' % \
  618 + (regions.size(), self['bkgregmin'].integer())
618 619 self._log_string(gammalib.NORMAL, msg)
619 620 regions = gammalib.GSkyRegions()
620 621  
... ...
cscripts/csspec.par
... ... @@ -31,7 +31,7 @@ outfile, f, a, spectrum.fits,,, "Output spectrum file"
31 31 #
32 32 # Script parameters
33 33 #==================
34   -method, s, a, AUTO,SLICE|NODES|AUTO,, "Spectrum generation method"
  34 +method, s, a, AUTO,SLICE|NODES|BINS|AUTO,, "Spectrum generation method"
35 35 ebinalg, s, a, LOG,FILE|LIN|LOG|POW,, "Algorithm for defining energy bins"
36 36 emin, r, a, 0.1,,, "Start value for first energy bin in TeV"
37 37 emax, r, a, 100.0,,, "Stop value for last energy bin in TeV"
... ... @@ -43,6 +43,7 @@ calc_ts, b, h, yes,,, "Compute TS value in each bin"
43 43 calc_ulim, b, h, yes,,, "Compute upper limit in each bin"
44 44 fix_srcs, b, h, yes,,, "Fix other skymodel parameters"
45 45 fix_bkg, b, h, no,,, "Fix background parameters"
  46 +bingamma, r, h, -2.0,,, "Spectral index for BINS method"
46 47 dll_sigstep, r, h, 0.0,0.0,100.0, "Step size in standard deviations for log-like profiles"
47 48 dll_sigmax, r, h, 5.0,1.0,100.0, "Maximum number of standard deviations for log-like profiles"
48 49 dll_freenodes, b, h, no,,, "Free nodes not being fit when computing log-like profiles"
... ...
cscripts/csspec.py
... ... @@ -20,6 +20,7 @@
20 20 # ==========================================================================
21 21 import sys
22 22 import math
  23 +import tempfile # Kludge for file function generation
23 24 import gammalib
24 25 import ctools
25 26 from cscripts import mputils
... ... @@ -144,9 +145,9 @@ class csspec(ctools.csobservation):
144 145 n_cta = n_unbinned + n_binned + n_onoff
145 146 n_other = self.obs().size() - n_cta
146 147  
147   - # If spectrum method is not "NODES" then set spectrum method and
148   - # script mode according to type of observations
149   - if self._method != 'NODES':
  148 + # If spectrum method is not "NODES" or 'BINS" then set spectrum method
  149 + # and script mode according to type of observations
  150 + if self._method != 'NODES' and self._method != 'BINS':
150 151 if n_other > 0:
151 152 self._method = 'NODES'
152 153 else:
... ... @@ -178,6 +179,7 @@ class csspec(ctools.csobservation):
178 179 self['calc_ts'].boolean()
179 180 self['fix_bkg'].boolean()
180 181 self['fix_srcs'].boolean()
  182 + self['bingamma'].real()
181 183  
182 184 # Setup dlog-likelihood parameters
183 185 self['dll_sigstep'].real()
... ... @@ -213,10 +215,10 @@ class csspec(ctools.csobservation):
213 215 elif n_other > 0:
214 216 if self._method == 'SLICE':
215 217 msg = 'Selected "SLICE" method but none of the observations ' \
216   - 'is a CTA observation. Please select "AUTO" or "NODES" ' \
217   - 'if no CTA observation is provided.'
  218 + 'is a CTA observation. Please select "AUTO", "NODES" ' \
  219 + 'or "BINS" if no CTA observation is provided.'
218 220 raise RuntimeError(msg)
219   - else:
  221 + elif self._method == 'AUTO':
220 222 self._method = 'NODES'
221 223  
222 224 # Log selected spectrum method
... ... @@ -366,6 +368,18 @@ class csspec(ctools.csobservation):
366 368 ' Fixing "'+par.name()+'"')
367 369 par.fix()
368 370  
  371 + # Convert spectral model into a file function. The file
  372 + # function is logarithmically sampled in energy, with with
  373 + # 20 times the number of spectral bins
  374 + nbins = self._ebounds.size()
  375 + num = nbins * 50
  376 + energies = gammalib.GEnergies(num, self._ebounds.emin(0),
  377 + self._ebounds.emax(nbins-1))
  378 + spectral = gammalib.GModelSpectralFunc(model.spectral(), energies)
  379 + model.spectral(spectral)
  380 + self._log_string(gammalib.EXPLICIT, ' Converting spectral model '
  381 + 'into file function')
  382 +
369 383 # Free the normalisation parameter which is assumed to be
370 384 # the first spectral parameter
371 385 normpar = model.spectral()[0]
... ... @@ -456,6 +470,64 @@ class csspec(ctools.csobservation):
456 470 # Return
457 471 return
458 472  
  473 + def _set_replace_src_spectrum_by_bins(self):
  474 + """
  475 + Replace source spectrum by bin function
  476 + """
  477 + # Initialise model container
  478 + models = gammalib.GModels()
  479 +
  480 + # Loop over model containers
  481 + for model in self.obs().models():
  482 +
  483 + # If we deal with source model then replace the spectral model
  484 + # by a bin function
  485 + if model.name() == self['srcname'].string():
  486 +
  487 + # Get spectral bins index
  488 + bingamma = self['bingamma'].real()
  489 +
  490 + # Setup spectral bin function
  491 + spectrum = gammalib.GModelSpectralBins(model.spectral(),
  492 + self._ebounds,
  493 + bingamma)
  494 + spectrum.autoscale()
  495 +
  496 + # Make sure that all bins are positive. Autoscale all
  497 + # parameters so that their nominal value is unity.
  498 + for i in range(spectrum.bins()):
  499 + name = 'Intensity%d' % i
  500 + par = spectrum[name]
  501 + par.autoscale()
  502 + value = par.value()
  503 + minimum = 1.0e-20 * value
  504 + if minimum <= 0.0:
  505 + minimum = 1.0e-20
  506 + if minimum < value:
  507 + value = minimum
  508 + par.value(value)
  509 + par.min(minimum)
  510 +
  511 + # Set spectral component of source model
  512 + model.spectral(spectrum)
  513 +
  514 + # Make sure that TS computation is disabled (makes computation
  515 + # faster)
  516 + model.tscalc(False)
  517 +
  518 + # Append model
  519 + models.append(model)
  520 +
  521 + # ... otherwise just append model
  522 + else:
  523 + models.append(model)
  524 +
  525 + # Put new model in observation containers
  526 + self.obs().models(models)
  527 +
  528 + # Return
  529 + return
  530 +
459 531 def _select_onoff_obs(self, obs, emin, emax):
460 532 """
461 533 Select an energy interval from one CTA On/Off observation
... ... @@ -854,8 +926,8 @@ class csspec(ctools.csobservation):
854 926 # Write model results for explicit chatter level
855 927 self._log_string(gammalib.EXPLICIT, str(like.obs().models()))
856 928  
857   - # Loop over all nodes
858   - for i in range(spectrum.nodes()):
  929 + # Loop over all nodes or bins
  930 + for i in range(self._ebounds.size()):
859 931  
860 932 # Get energy boundaries
861 933 emin = self._ebounds.emin(i)
... ... @@ -878,23 +950,26 @@ class csspec(ctools.csobservation):
878 950  
879 951 # Convert differential flux and flux error to nuFnu
880 952 norm = elogmean.MeV() * elogmean.MeV() * gammalib.MeV2erg
881   - result['flux'] = spectrum[i*2+1].value()
882   - result['e2dnde'] = spectrum[i*2+1].value() * norm
883   - result['flux_err'] = spectrum[i*2+1].error()
  953 + result['flux'] = spectrum.intensity(i)
  954 + result['e2dnde'] = spectrum.intensity(i) * norm
  955 + result['flux_err'] = spectrum.error(i)
884 956  
885 957 # Compute upper flux limit
886 958 ulimit_value = -1.0
887   - parname = 'Intensity%d' % i
  959 + parname = 'Intensity%d' % i
888 960  
889 961 # Compute delta log-likelihood
890 962 if self['dll_sigstep'].real() > 0.0:
891 963  
892 964 # Extract the normalization scan values
893   - (norm_scan, dlogL, loglike) = self._profile_logL(like.copy(), parname, elogmean)
  965 + (norm_scan, dlogL, loglike) = self._profile_logL(like.copy(),
  966 + parname,
  967 + elogmean)
894 968 result['norm_scan'] = norm_scan
895 969 result['dloglike'] = dlogL
896 970 result['logL'] = loglike
897 971  
  972 + # Compute upper flux limit
898 973 if self['calc_ulim'].boolean():
899 974  
900 975 # Logging information
... ... @@ -938,7 +1013,7 @@ class csspec(ctools.csobservation):
938 1013  
939 1014 # Set intensity of node to tiny value by scaling the value
940 1015 # by a factor 1e-8.
941   - par = obs.models()[self['srcname'].string()].spectral()[i*2+1]
  1016 + par = obs.models()[self['srcname'].string()].spectral()[parname]
942 1017 par.autoscale()
943 1018 par.factor_min(1.0e-8)
944 1019 par.factor_value(1.0e-8)
... ... @@ -1006,10 +1081,11 @@ class csspec(ctools.csobservation):
1006 1081 source.tscalc(False)
1007 1082  
1008 1083 # Fix all parameters in the spectral model
1009   - if (self._method != 'NODES') or (not self['dll_freenodes'].boolean()):
  1084 + if (self._method != 'NODES' and self._method != 'BINS') or \
  1085 + (not self['dll_freenodes'].boolean()):
1010 1086 for par in spectral:
1011 1087 par.fix()
1012   -
  1088 +
1013 1089 # Re-compute the log-likelihood
1014 1090 like.run()
1015 1091 loglike = like.obs().logL()
... ... @@ -1137,7 +1213,7 @@ class csspec(ctools.csobservation):
1137 1213 table.append(dnde)
1138 1214 table.append(TSvalues)
1139 1215 table.append(Npred_values)
1140   -
  1216 +
1141 1217 # Define the SED type
1142 1218 table.card('SED_TYPE', 'norm,e2dnde,dnde,npred', 'SED type')
1143 1219  
... ... @@ -1197,6 +1273,15 @@ class csspec(ctools.csobservation):
1197 1273 # Fit model
1198 1274 results = self._fit_model()
1199 1275  
  1276 + # Case C: "BINS" method
  1277 + elif self._method == 'BINS':
  1278 +
  1279 + # Replace source spectrum by bins function
  1280 + self._set_replace_src_spectrum_by_bins()
  1281 +
  1282 + # Fit model
  1283 + results = self._fit_model()
  1284 +
1200 1285 # Create FITS file
1201 1286 self._create_fits(results)
1202 1287  
... ...
ctools.pc.in
... ... @@ -8,7 +8,7 @@ Description: CTA science analysis tools
8 8 URL: http://cta.irap.omp.eu/ctools
9 9 Version: @VERSION@
10 10 Requires:
11   -Requires.private: gammalib == @VERSION@
  11 +Requires.private: gammalib = @VERSION@
12 12 Conflicts:
13 13 Cflags: -I${includedir}/ctools @OPENMP_CXXFLAGS@
14 14 Libs: -L${libdir} -lctools
... ...
dev/00-ctools-deactivate.csh 0 → 100644
  1 +#!/bin/csh
  2 +
  3 +unsetenv CTOOLS
  4 +unsetenv CALDB
... ...
dev/01-ctools-activate.csh 0 → 100644
  1 +#!/bin/csh
  2 +
  3 +setenv CTOOLS ${CONDA_PREFIX}
  4 +source ${CTOOLS}/bin/ctools-init.csh
  5 +unsetenv PYTHONPATH
  6 +unsetenv LD_LIBRARY_PATH
  7 +unsetenv DYLD_LIBRARY_PATH
... ...
doc/source/_static/logo-cyfronet.png 0 → 100644

70.5 KB

doc/source/_static/logo-desy.png 0 → 100644

86.7 KB

doc/source/_static/logo-ecap.jpg 0 → 100644

32 KB

doc/source/_static/logo-irap.png 0 → 100644

93.5 KB

doc/source/_static/logo-lapp.png 0 → 100644

73.5 KB

doc/source/_static/logo-lupm.png 0 → 100644

25.6 KB

doc/source/_static/logo-mpik.png 0 → 100644

7.11 KB

doc/source/_templates/index.html
... ... @@ -16,14 +16,35 @@ is supported as well. {%endtrans%}&lt;/p&gt;
16 16 <p>{%trans%} ctools are based on <a href="http://cta.irap.omp.eu/gammalib">GammaLib</a>,
17 17 a versatile toolbox for the scientific analysis of astronomical gamma-ray data.
18 18 Besides CTA, GammaLib supports the analysis of H.E.S.S., MAGIC, VERITAS,
19   -Fermi/LAT, COMPTEL and INTEGRAL/SPI data. GammaLib supports in particular the
  19 +Fermi/LAT, CGRO/COMPTEL and INTEGRAL/SPI data. GammaLib supports in particular the
20 20 combination of data from different instruments in a true joint multi-wavelength
21 21 analysis that consistently handles the response of each instrument. An interface
22   -to virtual observatory ressources does also exist.
  22 +to virtual observatory resources does also exist.
23 23 {%endtrans%}</p>
24 24  
25   -<p>{%trans%} ctools are developed by a team of enthousiastic gamma-ray
26   -astronomers with support from engineers. We regularily organise
  25 +<p>{%trans%} ctools are developed by a community of enthousiastic gamma-ray
  26 +astronomers with support from engineers. The lead institute is</p>
  27 +
  28 +<table cellpadding="0" cellspacing="0" border="0">
  29 + <tr>
  30 + <td><img src="_static/logo-irap.png" alt="IRAP" height="50"></td>
  31 + </tr>
  32 +</table>
  33 +
  34 +<p>As of today there have been contributions by the following institutions:</p>
  35 +
  36 +<table cellpadding="0" cellspacing="0" border="0">
  37 + <tr>
  38 + <td><img src="_static/logo-desy.png" alt="DESY" height="50"></td>
  39 + <td><img src="_static/logo-ecap.jpg" alt="ECAP" height="50"></td>
  40 + <td><img src="_static/logo-mpik.png" alt="MPIK" height="50"></td>
  41 + <td><img src="_static/logo-cyfronet.png" alt="Cyfronet" height="50"></td>
  42 + <td><img src="_static/logo-lapp.png" alt="LAPP" height="50"></td>
  43 + <td><img src="_static/logo-lupm.png" alt="LUPM" height="50"></td>
  44 + </tr>
  45 +</table>
  46 +
  47 +<p>We regularily organise
27 48 <a href=https://cta-redmine.irap.omp.eu/projects/ctools/wiki/Coding_sprints>coding sprints</a>
28 49 where key developers but also newcomers meet to discuss the developments
29 50 and next steps, and advance with the coding of the software.
... ...
doc/source/about.rst
... ... @@ -16,11 +16,11 @@ Creation of shell or Python scripts and pipelines is supported as well.
16 16 ctools are based on GammaLib, a versatile toolbox for the scientific
17 17 analysis of astronomical gamma-ray data.
18 18 Besides CTA, GammaLib supports the analysis of H.E.S.S., MAGIC, VERITAS,
19   -Fermi/LAT, COMPTEL and INTEGRAL/SPI data.
  19 +Fermi/LAT, CGRO/COMPTEL and INTEGRAL/SPI data.
20 20 GammaLib supports in particular the combination of data from different instruments
21 21 in a true joint multi-wavelength analysis that consistently handles the response
22 22 of each instrument.
23   -An interface to virtual observatory ressources does also exist.
  23 +An interface to virtual observatory resources does also exist.
24 24  
25 25 ctools are developed by a team of enthousiastic gamma-ray astronomers with
26 26 support from engineers. We regularily organise
... ... @@ -40,20 +40,29 @@ to include the formal reference
40 40 L. Gerard, A. Schulz, P. Martin, D. Sanchez, S. Ohm, T. Hassan, and
41 41 S. Brau-Nogue, 2016, A&A, 593, A1 <https://www.aanda.org/articles/aa/pdf/2016/09/aa28822-16.pdf>`_
42 42  
43   -in your paper as well as the identifiers
44   -`ascl:1601.005 <http://ascl.net/1601.005>`_ and
45   -`ascl:1110.007 <http://ascl.net/1110.007>`_ of the ctools and GammaLib
46   -packages in the Astrophysics Source Code Library (ASCL).
47   -You can also reference ctools via
  43 +in your paper as well as the Astrophysics Source Code Library (ASCL) identifiers
  44 +
  45 +.. image:: https://img.shields.io/badge/ascl-1601.005-blue.svg?colorB=262255
  46 + :target: http://ascl.net/1601.005
  47 +
  48 +for ctools and
  49 +
  50 +.. image:: https://img.shields.io/badge/ascl-1110.007-blue.svg?colorB=262255
  51 + :target: http://ascl.net/1110.007
  52 +
  53 +for GammaLib. You may also reference the softwares by their Digital Object
  54 +Identifiers (DOI) on Zenodo, which are
48 55  
49 56 .. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3265423.svg
50 57 :target: https://doi.org/10.5281/zenodo.3265423
51 58  
52   -and GammaLib via
  59 +for ctools and
53 60  
54 61 .. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3265404.svg
55 62 :target: https://doi.org/10.5281/zenodo.3265404
56 63  
  64 +for GammaLib.
  65 +
57 66 In addition please add the following acknowledgment:
58 67  
59 68 *This research made use of ctools, a community-developed analysis package
... ...
doc/source/admin/download.rst
... ... @@ -3,7 +3,7 @@
3 3 Download
4 4 ========
5 5  
6   -The latest ctools release is ``ctools-1.7.3`` (2 December 2020).
  6 +The latest ctools release is ``ctools-1.7.4`` (28 April 2021).
7 7  
8 8 Below a table of ctools releases. Please read the :ref:`sec_release` to
9 9 learn more about new features and corrected bugs in a given release.
... ... @@ -23,6 +23,9 @@ learn more about new features and corrected bugs in a given release.
23 23 * - ctools
24 24 - gammalib
25 25 - Mac OS (10.7+) binary disk image
  26 + * - `1.7.4 <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-1.7.4.tar.gz>`_
  27 + - `1.7.4 <http://cta.irap.omp.eu/ctools/releases/gammalib/gammalib-1.7.4.tar.gz>`_
  28 + - `ctools-1.7.4-macosx10.7.dmg <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-1.7.4-macosx10.7.dmg>`_
26 29 * - `1.7.3 <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-1.7.3.tar.gz>`_
27 30 - `1.7.3 <http://cta.irap.omp.eu/ctools/releases/gammalib/gammalib-1.7.3.tar.gz>`_
28 31 - `ctools-1.7.3-macosx10.7.dmg <http://cta.irap.omp.eu/ctools/releases/ctools/ctools-1.7.3-macosx10.7.dmg>`_
... ...
doc/source/admin/install_conda.rst
... ... @@ -36,8 +36,8 @@ Installing
36 36  
37 37 .. code-block:: bash
38 38  
39   - $ conda create -n myenv python=2.7 # or e.g. python=3.5
40   - $ source activate myenv
  39 + $ conda create -n myenv python=3.5 # or one of the following Python versions: 2.7, 3.5, 3.6, 3.7, 3.8
  40 + $ conda activate myenv
41 41 (myenv) $
42 42  
43 43 - Install pre-compiled ctools conda package from Anaconda cloud with:
... ... @@ -53,7 +53,7 @@ Installing
53 53  
54 54 .. code-block:: bash
55 55  
56   - (myenv) $ source activate myenv
  56 + (myenv) $ conda activate myenv
57 57  
58 58  
59 59 Testing
... ...
doc/source/admin/release_history/1.7.4.rst 0 → 100644
  1 +.. _1.7.4:
  2 +
  3 +ctools 1.7.4 release (28 April 2021)
  4 +====================================
  5 +
  6 +Overview
  7 +--------
  8 +
  9 +ctools 1.7.4 is a bug fix release for ctools release 1.7.
  10 +
  11 +The following bugs were fixed:
  12 +
  13 +* [`3628 <https://cta-redmine.irap.omp.eu/issues/3628>`_] -
  14 + Add conda activation and deactivation scripts for csh
  15 +* [`3624 <https://cta-redmine.irap.omp.eu/issues/3624>`_] -
  16 + Replace spectral model by file function in :ref:`csspec`
  17 +* [`3623 <https://cta-redmine.irap.omp.eu/issues/3623>`_] -
  18 + Update csinfo script
... ...
doc/source/admin/release_history/2.0.rst
1 1 .. _2.0:
2 2  
3   -ctools 2.0 release (5 March 2021)
4   -=================================
  3 +ctools 2.0 release (30 April 2021)
  4 +==================================
5 5  
6 6 Overview
7 7 --------
... ... @@ -24,6 +24,12 @@ Bug fixes
24 24 Improvements
25 25 ------------
26 26  
  27 +* [`3630 <https://cta-redmine.irap.omp.eu/issues/3630>`_] -
  28 + Add ASCL shields to **About** page
  29 +* [`3626 <https://cta-redmine.irap.omp.eu/issues/3626>`_] -
  30 + Use file function constructor in csspec
  31 +* [`3606 <https://cta-redmine.irap.omp.eu/issues/3606>`_] -
  32 + Add ``BINS`` method to :ref:`csspec`
27 33 * [`3562 <https://cta-redmine.irap.omp.eu/issues/3562>`_] -
28 34 Add hidden ``fix_spat`` parameter to :ref:`cttsmap`
29 35 * Add optimizer setter to ``ctlikelihood`` base class.
... ...
doc/source/admin/release_history/index.rst
... ... @@ -7,6 +7,7 @@ Release History
7 7 :maxdepth: 1
8 8  
9 9 ctools 2.0 <2.0>
  10 + ctools 1.7.4 <1.7.4>
10 11 ctools 1.7.3 <1.7.3>
11 12 ctools 1.7.2 <1.7.2>
12 13 ctools 1.7.1 <1.7.1>
... ...
doc/source/develop/releasing/index.rst
... ... @@ -21,4 +21,5 @@ To create a new ctools release you have to go through the following steps:
21 21 * added unit tests for all new code
22 22 * added a page about the software changes to the release history
23 23 * updated the User documentation if necessary
  24 + * updated the csinfo script if necessary
24 25  
... ...
doc/source/users/reference_manual/csspec.rst
... ... @@ -19,15 +19,29 @@ significance of the source detection. Optionally, it also computes an upper
19 19 flux limit that is particularly useful in case that the source is not
20 20 significantly detected within a spectral bin (hidden parameter ``calc_ulim``).
21 21  
22   -There are two fundamental methods to run the script depending on the value of
23   -the ``method`` parameter. If ``method=SLICE`` the energy interval defined by the
24   -``emin`` and ``emax`` parameters is divided into a number of energy bins and an
25   -independent maximum likelihood fit is performed in each of the energy bins,
26   -while if ``method=NODES`` the spectral model will be replaced by a node function
27   -that will be fit to all data. The latter is particularly useful if non-CTA data
28   -should be fitted such as data from Fermi/LAT or COMPTEL. By default, ``method`` is
29   -set to ``AUTO`` which will automatically select the method based on the input data.
30   -For CTA-only observations ``SLICE`` will be used, otherwise ``NODES`` will be used.
  22 +There are three fundamental methods to run the script depending on the value of
  23 +the ``method`` parameter, ``SLICE``, ``BINS`` and ``NODES``.
  24 +
  25 +If ``method=SLICE`` the energy interval defined by the ``emin`` and ``emax``
  26 +parameters is divided into a number of energy bins and an independent maximum
  27 +likelihood fit is performed in each of the energy bins. In order to cope with
  28 +all kinds of spectral models, including composite spectra, input spectrum will
  29 +be converted into a file function, with the normalisation of the file function
  30 +being the fit parameter for each energy bin. This implies that spectral
  31 +components are merged into a single function using the model parameters that
  32 +are specified in the input model.
  33 +
  34 +If ``method=BINS`` the spectral model will be replaced by a bin function that
  35 +will be fit to all data, with ``method=NODES`` the spectral model will be replaced
  36 +by a node function. The advantage of ``BINS`` over ``NODES`` is that with ``BINS``
  37 +the spectral flux points are statistically independent, while with ``NODES`` the
  38 +underlying spectral model connects spectral flux points using a piecewise power
  39 +law. Both methods are particularly useful if non-CTA data should be fitted such
  40 +as data from Fermi/LAT, CGRO/COMPTEL or INTEGRAL/SPI.
  41 +
  42 +By default, ``method`` is set to ``AUTO`` which will automatically select the
  43 +method based on the input data. For CTA-only observations ``SLICE`` will be used,
  44 +otherwise ``NODES`` will be used.
31 45  
32 46 The spectral binning is either defined by a FITS file containing the energy
33 47 boundaries of each bin (option ``ebinalg=FILE``) or as ``enumbins`` bins spread
... ... @@ -54,9 +68,6 @@ the fitted flux and flux error, the Test Statistics value (option
54 68 ``calc_ts=yes``), the upper flux limit (option ``calc_ulim=yes``) and the
55 69 predicted number of events (only for unbinned data).
56 70  
57   -.. warning::
58   - The upper limit computation is not yet implemented for the ``NODES`` method.
59   -
60 71  
61 72 General parameters
62 73 ------------------
... ... @@ -95,13 +106,17 @@ General parameters
95 106 ``outfile [file]``
96 107 Output spectrum FITS file.
97 108  
98   -``method <SLICE|NODES|AUTO> [string]``
  109 +``method <SLICE|NODES|BINS|AUTO> [string]``
99 110 Spectrum generation method.
100   - ``SLICE`` will slice energy interval into ``enumbins`` independent bins,
101   - ``NODES`` will replace spectral model by node function with ``enumbins``
102   - nodes, and ``AUTO`` will automatically select the method based on the input
103   - data. For CTA-only observations ``SLICE`` will be used, otherwise ``NODES``
104   - will be used.
  111 + ``SLICE`` will slice the energy interval into ``enumbins`` independent
  112 + bins,
  113 + ``NODES`` will replace the spectral model by a node function with
  114 + ``enumbins`` nodes,
  115 + ``BINS`` will replace the spectral model by a bin function with
  116 + ``enumbins`` nodes,
  117 + and ``AUTO`` will automatically select the method based on the input
  118 + data. If ``AUTO`` is selected and there are only CTA observations
  119 + then ``SLICE`` will be used, otherwise ``NODES`` will be used.
105 120  
106 121 ``ebinalg <FILE|LIN|LOG|POW> [string]``
107 122 Algorithm for defining energy bins. For ``FILE``, the energy bins are defined
... ... @@ -151,6 +166,10 @@ General parameters
151 166 ``(fix_bkg = no) [boolean]``
152 167 Fix background model parameters?
153 168  
  169 +``(bingamma = -2.0) [real]``
  170 + Spectral index for ``BINS`` method. Within each spectral bin a power law
  171 + will be assumed with the specified spectral index.
  172 +
154 173 ``(dll_sigstep = 0) [real]``
155 174 Step size in standard deviations for log-like profiles. Note this value
156 175 determines the number of steps to use.
... ...
examples/show_spectrum.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Display spectrum generated by csspec
4 4 #
5   -# Copyright (C) 2015-2020 Juergen Knoedlseder
  5 +# Copyright (C) 2015-2021 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -18,6 +18,7 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
  21 +import os
21 22 import sys
22 23 try:
23 24 import matplotlib.pyplot as plt
... ... @@ -70,7 +71,7 @@ def get_spectrum_fits(fits):
70 71 ----------
71 72 fits : `~gammalib.GFits`
72 73 Spectral GFits object
73   -
  74 +
74 75 Returns
75 76 -------
76 77 spec : dict
... ... @@ -168,7 +169,7 @@ def get_spectrum_fits(fits):
168 169 # ========================= #
169 170 # Plot delta log-likelihood #
170 171 # ========================= #
171   -def plot_dloglike(spec):
  172 +def plot_dloglike(ax, spec):
172 173 """
173 174 Plot delta log-likelihood
174 175  
... ... @@ -187,7 +188,7 @@ def plot_dloglike(spec):
187 188  
188 189 # Compute the logarithmic center of each bin
189 190 fluxpnts = 10 ** ((y_bounds[1:]+y_bounds[:-1]) / 2.0)
190   -
  191 +
191 192 # Scale the boundaries on the grid
192 193 y_bounds = 10 ** y_bounds
193 194  
... ... @@ -201,12 +202,12 @@ def plot_dloglike(spec):
201 202 dll_hist = [[row[i] for row in dll_hist] for i in range(steps)]
202 203  
203 204 # Plot the likelihood profiles
204   - plt.pcolormesh(np.array(spec['engs_scan']), y_bounds,
205   - np.array(dll_hist), vmin=-10.0, vmax=0.0,
206   - cmap='Reds', alpha=0.9)
207   - cbar = plt.colorbar()
  205 + c = ax.pcolormesh(np.array(spec['engs_scan']), y_bounds,
  206 + np.array(dll_hist), vmin=-10.0, vmax=0.0,
  207 + cmap='Reds', alpha=0.9)
  208 + cbar = plt.colorbar(c)
208 209 cbar.set_label(r'$\Delta$ log-likelihood')
209   - plt.grid()
  210 + ax.grid()
210 211  
211 212 # Return
212 213 return
... ... @@ -229,27 +230,48 @@ def plot_spectrum(filename, plotfile):
229 230 # Get spectrum parameters
230 231 spec = get_spectrum_file(filename)
231 232  
  233 + # Set energy scale of spectrum
  234 + if max(spec['energies']+spec['ul_energies']) < 1.0e-3:
  235 + xlabel = 'Energy (MeV)'
  236 + conv = 1.0e6
  237 + elif max(spec['energies']) < 1.0:
  238 + xlabel = 'Energy (GeV)'
  239 + conv = 1.0e3
  240 + else:
  241 + xlabel = 'Energy (TeV)'
  242 + conv = 1.0
  243 + if conv != 1.0:
  244 + spec['energies'] = [e * 1.0e6 for e in spec['energies']]
  245 + spec['ed_engs'] = [e * 1.0e6 for e in spec['ed_engs']]
  246 + spec['eu_engs'] = [e * 1.0e6 for e in spec['eu_engs']]
  247 + spec['ul_energies'] = [e * 1.0e6 for e in spec['ul_energies']]
  248 + spec['ul_ed_engs'] = [e * 1.0e6 for e in spec['ul_ed_engs']]
  249 + spec['ul_eu_engs'] = [e * 1.0e6 for e in spec['ul_eu_engs']]
  250 +
232 251 # Create the plot
233   - plt.figure()
234   - plt.loglog()
235   - plt.grid()
236   - plt.xlabel('Energy (TeV)')
237   - plt.ylabel(r'E$^2$ $\times$ dN/dE (erg cm$^{-2}$ s$^{-1}$)')
  252 + fig = plt.figure()
  253 + fig.subplots_adjust(left=0.17, right=0.98, top=0.92, bottom=0.10)
  254 + ax = fig.add_subplot(111)
  255 + ax.loglog()
  256 + ax.grid()
  257 + ax.set_xlabel(xlabel)
  258 + ax.set_ylabel(r'E$^2$ $\times$ dN/dE (erg cm$^{-2}$ s$^{-1}$)')
  259 + ax.set_title(os.path.basename(filename))
238 260  
239 261 # Plot the spectrum
240   - plt.errorbar(spec['energies'], spec['flux'],
  262 + ax.errorbar(spec['energies'], spec['flux'],
241 263 yerr=spec['e_flux'], xerr=[spec['ed_engs'], spec['eu_engs']],
242 264 fmt='ro')
243 265  
244 266 # Plot upper limits
245 267 if len(spec['ul_energies']) > 0:
246   - plt.errorbar(spec['ul_energies'], spec['ul_flux'], yerr=spec['yerr'],
  268 + ax.errorbar(spec['ul_energies'], spec['ul_flux'], yerr=spec['yerr'],
247 269 xerr=[spec['ul_ed_engs'], spec['ul_eu_engs']],
248 270 uplims=True, fmt='ro')
249 271  
250 272 # Plot log-likelihood profiles
251 273 if len(spec['dll_scan']) > 0:
252   - plot_dloglike(spec)
  274 + plot_dloglike(ax, spec)
253 275  
254 276 # Show figure
255 277 if len(plotfile) > 0:
... ...
sonar-project.properties
... ... @@ -21,7 +21,7 @@ sonar.cxx.missingIncludeWarnings=False
21 21  
22 22 # Exclusions
23 23 sonar.exclusions=src/template/cscript_test.py,src/template/ctool_test.py,cscripts/tests/**,pyext/build/**,pyext/ctools/tools.py,pyext/ctools/*_wrap.cpp,pyext/ctools/tests/**,dev/**,doc/**,test/dev/**
24   -sonar.coverage.exclusions=src/template/**,test/science_verification.py,test/test_examples.py,test/test_mputils.py,pyext/setup.py
  24 +sonar.coverage.exclusions=src/template/**,test/science_verification.py,test/test_examples.py,test/test_mputils.py,test/tutorials.py,pyext/setup.py
25 25 sonar.cpd.exclusions=examples/**,test/**,pyext/ctools/tools.py
26 26  
27 27 # C++ configuration
... ...
test/test_cttsmap.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This scripts performs unit tests for the cttsmap tool
4 4 #
5   -# Copyright (C) 2014-2018 Juergen Knoedlseder
  5 +# Copyright (C) 2014-2021 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -175,12 +175,13 @@ class Test(test):
175 175  
176 176 # Execute copy of cttsmap tool again, now with a higher chatter
177 177 # level than before
178   - cpy_tsmap['binmin'] = 0
179   - cpy_tsmap['binmax'] = 1
180   - cpy_tsmap['outmap'] = 'cttsmap_py2.fits'
181   - cpy_tsmap['logfile'] = 'cttsmap_py2.log'
182   - cpy_tsmap['chatter'] = 3
183   - cpy_tsmap['publish'] = True
  178 + cpy_tsmap['binmin'] = 0
  179 + cpy_tsmap['binmax'] = 1
  180 + cpy_tsmap['fix_spat'] = True
  181 + cpy_tsmap['outmap'] = 'cttsmap_py2.fits'
  182 + cpy_tsmap['logfile'] = 'cttsmap_py2.log'
  183 + cpy_tsmap['chatter'] = 3
  184 + cpy_tsmap['publish'] = True
184 185 cpy_tsmap.logFileOpen() # Needed to get a new log file
185 186 cpy_tsmap.execute()
186 187  
... ...