Commit 2897316901a3fd78e66d552edfabb8c83c22a46b
1 parent
3b94d0ca
Adapt to GammaLib 1.0.0
Showing
6 changed files
with
35 additions
and
63 deletions
examples/make_binned_analysis.py
| ... | ... | @@ -73,8 +73,8 @@ def pipeline_v1(): |
| 73 | 73 | # Simulate events |
| 74 | 74 | sim = ctools.ctobssim() |
| 75 | 75 | sim.logFileOpen() # We need this to explicitely open the log file in Python mode |
| 76 | - sim["infile"].filename(model_name) | |
| 77 | - sim["outfile"].filename(events_name) | |
| 76 | + sim["inmodel"].filename(model_name) | |
| 77 | + sim["outevents"].filename(events_name) | |
| 78 | 78 | sim["caldb"].string(caldb) |
| 79 | 79 | sim["irf"].string(irf) |
| 80 | 80 | sim["ra"].real(ra) |
| ... | ... | @@ -94,8 +94,8 @@ def pipeline_v1(): |
| 94 | 94 | # Bin events into counts map |
| 95 | 95 | bin = ctools.ctbin() |
| 96 | 96 | bin.logFileOpen() # We need this to explicitely open the log file in Python mode |
| 97 | - bin["evfile"].filename(events_name) | |
| 98 | - bin["outfile"].filename(cntmap_name) | |
| 97 | + bin["inobs"].filename(events_name) | |
| 98 | + bin["outcube"].filename(cntmap_name) | |
| 99 | 99 | bin["ebinalg"].string("LOG") |
| 100 | 100 | bin["emin"].real(emin) |
| 101 | 101 | bin["emax"].real(emax) |
| ... | ... | @@ -117,9 +117,9 @@ def pipeline_v1(): |
| 117 | 117 | # Perform maximum likelihood fitting |
| 118 | 118 | like = ctools.ctlike() |
| 119 | 119 | like.logFileOpen() # We need this to explicitely open the log file in Python mode |
| 120 | - like["infile"].filename(cntmap_name) | |
| 121 | - like["srcmdl"].filename(model_name) | |
| 122 | - like["outmdl"].filename(result_name) | |
| 120 | + like["inobs"].filename(cntmap_name) | |
| 121 | + like["inmodel"].filename(model_name) | |
| 122 | + like["outmodel"].filename(result_name) | |
| 123 | 123 | like["caldb"].string(caldb) |
| 124 | 124 | like["irf"].string(irf) |
| 125 | 125 | like.execute() |
| ... | ... | @@ -174,7 +174,7 @@ def pipeline_v2(): |
| 174 | 174 | |
| 175 | 175 | # Simulate events |
| 176 | 176 | sim = ctools.ctobssim() |
| 177 | - sim["infile"].filename(model_name) | |
| 177 | + sim["inmodel"].filename(model_name) | |
| 178 | 178 | sim["caldb"].string(caldb) |
| 179 | 179 | sim["irf"].string(irf) |
| 180 | 180 | sim["ra"].real(ra) | ... | ... |
examples/make_cube_analysis.py
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | # ========================================================================== |
| 21 | 21 | import ctools |
| 22 | 22 | import gammalib |
| 23 | +from ctools import obsutils | |
| 23 | 24 | |
| 24 | 25 | |
| 25 | 26 | # ================= # |
| ... | ... | @@ -39,10 +40,10 @@ def pipeline(caldb = "dummy", \ |
| 39 | 40 | model - Source model |
| 40 | 41 | """ |
| 41 | 42 | # Set pointing pattern (4 pointings) |
| 42 | - pointings = ctools.obsutils.set_obs_patterns("four", offset=2.0) | |
| 43 | + pointings = obsutils.set_obs_patterns("four", offset=2.0) | |
| 43 | 44 | |
| 44 | 45 | # Set CTA observations (default: 1800 sec per pointing) |
| 45 | - obs = ctools.obsutils.set_obs_list(pointings, caldb=caldb, irf=irf) | |
| 46 | + obs = obsutils.set_obs_list(pointings, caldb=caldb, irf=irf) | |
| 46 | 47 | |
| 47 | 48 | # Load models |
| 48 | 49 | models = gammalib.GModels(model) |
| ... | ... | @@ -56,7 +57,7 @@ def pipeline(caldb = "dummy", \ |
| 56 | 57 | # Run ctbin (builds stacked event cube) |
| 57 | 58 | bin = ctools.ctbin(sim.obs()) |
| 58 | 59 | bin.logFileOpen() |
| 59 | - bin["outfile"].filename("cntmap.fits") | |
| 60 | + bin["outcube"].filename("cntmap.fits") | |
| 60 | 61 | bin["ebinalg"].string("LOG") |
| 61 | 62 | bin["emin"].real(0.1) |
| 62 | 63 | bin["emax"].real(100.0) |
| ... | ... | @@ -74,8 +75,8 @@ def pipeline(caldb = "dummy", \ |
| 74 | 75 | # Run ctexpcube (builds exposure cube) |
| 75 | 76 | expcube = ctools.ctexpcube(sim.obs()) |
| 76 | 77 | expcube.logFileOpen() |
| 77 | - expcube["cntmap"].filename("cntmap.fits") | |
| 78 | - expcube["outfile"].filename("expcube.fits") | |
| 78 | + expcube["incube"].filename("cntmap.fits") | |
| 79 | + expcube["outcube"].filename("expcube.fits") | |
| 79 | 80 | expcube["caldb"].string(caldb) |
| 80 | 81 | expcube["irf"].string(irf) |
| 81 | 82 | expcube.execute() |
| ... | ... | @@ -83,8 +84,8 @@ def pipeline(caldb = "dummy", \ |
| 83 | 84 | # Run ctpsfcube (builds PSF cube) |
| 84 | 85 | psfcube = ctools.ctpsfcube(sim.obs()) |
| 85 | 86 | psfcube.logFileOpen() |
| 86 | - psfcube["cntmap"].filename("NONE") | |
| 87 | - psfcube["outfile"].filename("psfcube.fits") | |
| 87 | + psfcube["incube"].filename("NONE") | |
| 88 | + psfcube["outcube"].filename("psfcube.fits") | |
| 88 | 89 | psfcube["caldb"].string(caldb) |
| 89 | 90 | psfcube["irf"].string(irf) |
| 90 | 91 | psfcube["ebinalg"].string("LOG") |
| ... | ... | @@ -105,33 +106,23 @@ def pipeline(caldb = "dummy", \ |
| 105 | 106 | # Run ctbkgcube (builds background cube) |
| 106 | 107 | bkgcube = ctools.ctbkgcube(sim.obs()) |
| 107 | 108 | bkgcube.logFileOpen() |
| 108 | - bkgcube["cntmap"].filename("cntmap.fits") | |
| 109 | - bkgcube["bkgmdl"].filename(model) | |
| 110 | - bkgcube["outfile"].filename("bkgcube.fits") | |
| 109 | + bkgcube["incube"].filename("cntmap.fits") | |
| 110 | + bkgcube["inmodel"].filename(model) | |
| 111 | + bkgcube["outcube"].filename("bkgcube.fits") | |
| 112 | + bkgcube["outmodel"].filename("bkgcube.xml") | |
| 111 | 113 | bkgcube.execute() |
| 112 | 114 | |
| 113 | 115 | # Create observation container for stacked cube analysis |
| 114 | 116 | obs.clear() |
| 115 | 117 | cta = gammalib.GCTAObservation("cntmap.fits", "expcube.fits", "psfcube.fits") |
| 116 | 118 | obs.append(cta) |
| 117 | - | |
| 118 | - # Create model for stacked cube analysis | |
| 119 | - models = gammalib.GModels(model) | |
| 120 | - models.remove("Background") | |
| 121 | - spatial = gammalib.GModelSpatialDiffuseCube("bkgcube.fits") | |
| 122 | - spectral = gammalib.GModelSpectralConst() | |
| 123 | - background = gammalib.GCTAModelCubeBackground(spatial, spectral) | |
| 124 | - models.append(background) | |
| 125 | - models.save("cube_model.xml") | |
| 126 | - | |
| 127 | - # Append model to observation container | |
| 128 | - obs.models(models) | |
| 119 | + obs.models(gammalib.GModels("bkgcube.xml")) | |
| 129 | 120 | |
| 130 | 121 | # Run ctlike |
| 131 | 122 | like = ctools.ctlike(obs) |
| 132 | 123 | like.logFileOpen() |
| 133 | 124 | like["debug"].boolean(True) |
| 134 | - like["outmdl"].filename("cube_results.xml") | |
| 125 | + like["outmodel"].filename("cube_results.xml") | |
| 135 | 126 | like.execute() |
| 136 | 127 | |
| 137 | 128 | # Return | ... | ... |
examples/make_spectrum.py
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | # ========================================================================== |
| 21 | 21 | import gammalib |
| 22 | 22 | import ctools |
| 23 | +from ctools import obsutils | |
| 23 | 24 | try: |
| 24 | 25 | import matplotlib.pyplot as plt |
| 25 | 26 | has_matplotlib = True |
| ... | ... | @@ -47,7 +48,7 @@ def make_spectrum(): |
| 47 | 48 | |
| 48 | 49 | # Simulate events |
| 49 | 50 | sim = ctools.ctobssim() |
| 50 | - sim["infile"].filename(model_name) | |
| 51 | + sim["inmodel"].filename(model_name) | |
| 51 | 52 | sim["caldb"].string(caldb) |
| 52 | 53 | sim["irf"].string(irf) |
| 53 | 54 | sim["ra"].real(ra) |
| ... | ... | @@ -65,7 +66,7 @@ def make_spectrum(): |
| 65 | 66 | ebounds = gammalib.GEbounds(10, e_min, e_max) |
| 66 | 67 | |
| 67 | 68 | # Generate spectral points |
| 68 | - spectrum = ctools.obsutils.spectrum(sim.obs(), "Crab", ebounds) | |
| 69 | + spectrum = obsutils.spectrum(sim.obs(), "Crab", ebounds) | |
| 69 | 70 | |
| 70 | 71 | # Return spectrum |
| 71 | 72 | return spectrum | ... | ... |
examples/make_ts_distributions.py
| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | # Required 3rd party modules: |
| 13 | 13 | # - processing (optional) |
| 14 | 14 | # |
| 15 | -# Copyright (C) 2011 Jurgen Knodlseder | |
| 15 | +# Copyright (C) 2011-2015 Jurgen Knodlseder | |
| 16 | 16 | # |
| 17 | 17 | # This program is free software: you can redistribute it and/or modify |
| 18 | 18 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -28,8 +28,6 @@ |
| 28 | 28 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 29 | 29 | # |
| 30 | 30 | # ========================================================================== |
| 31 | -from ctools import * | |
| 32 | -from gammalib import * | |
| 33 | 31 | from cstsdist import * |
| 34 | 32 | import sys |
| 35 | 33 | import time | ... | ... |
examples/make_unbinned_analysis.py
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | # Required 3rd party modules: |
| 8 | 8 | # None |
| 9 | 9 | # |
| 10 | -# Copyright (C) 2011-2014 Jurgen Knodlseder | |
| 10 | +# Copyright (C) 2011-2015 Jurgen Knodlseder | |
| 11 | 11 | # |
| 12 | 12 | # This program is free software: you can redistribute it and/or modify |
| 13 | 13 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -23,9 +23,6 @@ |
| 23 | 23 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | 24 | # |
| 25 | 25 | # ========================================================================== |
| 26 | -#from ctools import * | |
| 27 | -#from gammalib import * | |
| 28 | -#from math import * | |
| 29 | 26 | import gammalib |
| 30 | 27 | import ctools |
| 31 | 28 | import math |
| ... | ... | @@ -74,8 +71,8 @@ def pipeline_v1(): |
| 74 | 71 | # Simulate events |
| 75 | 72 | sim = ctools.ctobssim() |
| 76 | 73 | sim.logFileOpen() |
| 77 | - sim["infile"].filename(model_name) | |
| 78 | - sim["outfile"].filename(events_name) | |
| 74 | + sim["inmodel"].filename(model_name) | |
| 75 | + sim["outevents"].filename(events_name) | |
| 79 | 76 | sim["caldb"].string(caldb) |
| 80 | 77 | sim["irf"].string(irf) |
| 81 | 78 | sim["ra"].real(ra) |
| ... | ... | @@ -95,8 +92,8 @@ def pipeline_v1(): |
| 95 | 92 | # Select events |
| 96 | 93 | select = ctools.ctselect() |
| 97 | 94 | select.logFileOpen() |
| 98 | - select["infile"].filename(events_name) | |
| 99 | - select["outfile"].filename(selected_events_name) | |
| 95 | + select["inobs"].filename(events_name) | |
| 96 | + select["outobs"].filename(selected_events_name) | |
| 100 | 97 | select["ra"].real(ra) |
| 101 | 98 | select["dec"].real(dec) |
| 102 | 99 | select["rad"].real(rad_select) |
| ... | ... | @@ -114,9 +111,9 @@ def pipeline_v1(): |
| 114 | 111 | # Perform maximum likelihood fitting |
| 115 | 112 | like = ctools.ctlike() |
| 116 | 113 | like.logFileOpen() |
| 117 | - like["infile"].filename(selected_events_name) | |
| 118 | - like["srcmdl"].filename(model_name) | |
| 119 | - like["outmdl"].filename(result_name) | |
| 114 | + like["inobs"].filename(selected_events_name) | |
| 115 | + like["inmodel"].filename(model_name) | |
| 116 | + like["outmodel"].filename(result_name) | |
| 120 | 117 | like["caldb"].string(caldb) |
| 121 | 118 | like["irf"].string(irf) |
| 122 | 119 | like.execute() |
| ... | ... | @@ -164,7 +161,7 @@ def pipeline_v2(show_data): |
| 164 | 161 | |
| 165 | 162 | # Simulate events |
| 166 | 163 | sim = ctools.ctobssim() |
| 167 | - sim["infile"].filename(model_name) | |
| 164 | + sim["inmodel"].filename(model_name) | |
| 168 | 165 | sim["caldb"].string(caldb) |
| 169 | 166 | sim["irf"].string(irf) |
| 170 | 167 | sim["ra"].real(ra) |
| ... | ... | @@ -210,9 +207,6 @@ def pipeline_v2(show_data): |
| 210 | 207 | print("Total wall time elapsed: "+str(wall_seconds)+" seconds") |
| 211 | 208 | print("Total CPU time used ...: "+str(cpu_seconds)+" seconds") |
| 212 | 209 | |
| 213 | - # Show model fitting results | |
| 214 | - #print like.obs().models() | |
| 215 | - | |
| 216 | 210 | # Optionally plot counts |
| 217 | 211 | if show_data: |
| 218 | 212 | if has_matplotlib: | ... | ... |
examples/model_bgd.xml deleted
| 1 | -<?xml version="1.0" standalone="no"?> | |
| 2 | -<source_library title="source library"> | |
| 3 | - <source name="Background" type="RadialAcceptance" instrument="CTA"> | |
| 4 | - <spectrum type="FileFunction" file="$CTOOLS/share/models/bkg_dummy.txt"> | |
| 5 | - <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/> | |
| 6 | - </spectrum> | |
| 7 | - <radialModel type="Gaussian"> | |
| 8 | - <parameter name="Sigma" scale="1.0" value="3.0" min="0.01" max="10.0" free="1"/> | |
| 9 | - </radialModel> | |
| 10 | - </source> | |
| 11 | -</source_library> | |
| 12 | - |