Commit 5a2aa22f064fc9d3c902fd8460598564faa42307

Authored by Jürgen Knödlseder
1 parent 86ba546b

Merge in code

cscripts/csspec.par
... ... @@ -31,19 +31,19 @@ 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"
35   -ebinalg, s, a, LOG,FILE|LIN|LOG,, "Algorithm for defining energy bins"
36   -emin, r, a, 0.1,,, "Start value for first energy bin in TeV"
37   -emax, r, a, 100.0,,, "Stop value for last energy bin in TeV"
38   -enumbins, i, a, 20,1,200, "Number of energy bins"
39   -ebinfile, f, a, NONE,,, "Name of the file containing the energy bin definition"
40   -statistic, s, h, DEFAULT,DEFAULT|CSTAT|WSTAT|CHI2,, "Optimization statistic"
41   -calc_ts, b, h, yes,,, "Compute TS value in each bin"
42   -calc_ulim, b, h, yes,,, "Compute upper limit in each bin"
43   -fix_srcs, b, h, yes,,, "Fix other skymodel parameters"
44   -fix_bkg, b, h, no,,, "Fix background parameters"
45   -dll_sigstep, r, h, 0,0,100, "Step size in standard deviations for log-like profiles"
46   -dll_sigmax, r, h, 5,1,100, "Maximum number of standard deviations for log-like profiles"
  34 +method, s, a, AUTO,SLICE|NODES|AUTO,, "Spectrum generation method"
  35 +ebinalg, s, a, LOG,FILE|LIN|LOG,, "Algorithm for defining energy bins"
  36 +emin, r, a, 0.1,,, "Start value for first energy bin in TeV"
  37 +emax, r, a, 100.0,,, "Stop value for last energy bin in TeV"
  38 +enumbins, i, a, 20,1,200, "Number of energy bins"
  39 +ebinfile, f, a, NONE,,, "Name of the file containing the energy bin definition"
  40 +statistic, s, h, DEFAULT,DEFAULT|CSTAT|WSTAT|CHI2,, "Optimization statistic"
  41 +calc_ts, b, h, yes,,, "Compute TS value in each bin"
  42 +calc_ulim, b, h, yes,,, "Compute upper limit in each bin"
  43 +fix_srcs, b, h, yes,,, "Fix other skymodel parameters"
  44 +fix_bkg, b, h, no,,, "Fix background parameters"
  45 +dll_sigstep, r, h, 0.0,0.0,100.0, "Step size in standard deviations for log-like profiles"
  46 +dll_sigmax, r, h, 5.0,1.0,100.0, "Maximum number of standard deviations for log-like profiles"
47 47 dll_freenodes, b, h, no,,, "Free nodes not being fit when computing log-like profiles"
48 48  
49 49 #
... ...
cscripts/csspec.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Generates a spectrum.
4 4 #
5   -# Copyright (C) 2014-2019 Michael Mayer
  5 +# Copyright (C) 2014-2020 Michael Mayer
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
... ... @@ -1031,7 +1031,6 @@ class csspec(ctools.csobservation):
1031 1031 # from [10^-24, 10^-14] or [norm, 10^-14] whichever is broader
1032 1032 log_start = -24 if (log_norm > -24) else log_norm
1033 1033 log_step = (-14 - log_start) / (sigsteps-1)
1034   -
1035 1034 norm_vals = [10 ** (log_start + i*log_step) for i in range(sigsteps)]
1036 1035  
1037 1036 # Loop through normalizations
... ... @@ -1042,14 +1041,15 @@ class csspec(ctools.csobservation):
1042 1041  
1043 1042 # Re-run the fit
1044 1043 like.run()
1045   -
  1044 +
1046 1045 # Store dlikelihood & norm
1047 1046 dloglike.append(loglike - like.obs().logL())
1048 1047 if self._method == 'SLICE':
1049 1048 norm_scan.append(spectral.eval(elogmean))
1050 1049 else:
1051 1050 norm_scan.append(new_norm)
1052   -
  1051 +
  1052 + # Return
1053 1053 return (norm_scan, dloglike, -loglike)
1054 1054  
1055 1055 def _create_fits(self, results):
... ...
doc/source/users/reference_manual/csspec.rst
... ... @@ -145,17 +145,17 @@ General parameters
145 145 ``(fix_bkg = no) [boolean]``
146 146 Fix background model parameters?
147 147  
148   -``(dll_sigstep) [real]``
  148 +``(dll_sigstep = 0) [real]``
149 149 Step size in standard deviations for log-like profiles. Note this value
150 150 determines the number of steps to use.
151 151  
152   -``(dll_sigmax) [real]``
  152 +``(dll_sigmax = 5.0) [real]``
153 153 Maximum number of standard deviations for log-like profiles. The final number
154 154 of bins generated in the likelihood profile will be:
155 155 2*(dll_sigmax/dll_sigstep) + 1
156 156 ensuring that the central flux will always be evaluated.
157 157  
158   -``(dll_freenodes) [boolean]``
  158 +``(dll_freenodes = no) [boolean]``
159 159 Free nodes not being fit when computing log-like profiles. This parameter
160 160 only has an effect if 'method=NODES' is set.
161 161  
... ...
examples/show_spectrum.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # Display spectrum generated by csspec
4 4 #
5   -# Copyright (C) 2015-2019 Juergen Knoedlseder
  5 +# Copyright (C) 2015-2020 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
... ... @@ -107,13 +107,13 @@ def get_spectrum_fits(fits):
107 107  
108 108 # Determine if we can load the delta-log-likelihood profiles
109 109 has_sedtype = table.has_card('SED_TYPE')
110   - load_dll = False
  110 + load_dll = False
111 111 if has_sedtype:
112 112 seds = table.card('SED_TYPE').string().split(',')
113 113  
114 114 # Load likelhood columns if present
115 115 if seds[0] == 'likelihood':
116   - load_dll = True
  116 + load_dll = True
117 117 c_loglike = table['loglike']
118 118 c_norm_scan = table['norm_scan']
119 119 c_dll_scan = table['dloglike_scan']
... ... @@ -150,7 +150,7 @@ def get_spectrum_fits(fits):
150 150 spec['dll_scan'] = np.zeros((nrows, c_norm_scan.elements(0)))
151 151  
152 152 for row in range(nrows):
153   - loglike = c_loglike.real(row)
  153 + loglike = c_loglike.real(row)
154 154 spec['loglike'].append(loglike)
155 155 spec['engs_scan'].append(c_energy.real(row) - c_ed.real(row))
156 156 for col in range(c_norm_scan.elements(row)):
... ...