Commit ae1d935c00be99fc129c6a8a0bad6554733a92da
Merge branch 'devel' of https://cta-gitlab.irap.omp.eu/ctools/ctools into 1807-s…
…how_obs-example-script
Showing
90 changed files
with
2680 additions
and
1251 deletions
.gitignore
| @@ -72,6 +72,7 @@ src/ctulimit/ctulimit | @@ -72,6 +72,7 @@ src/ctulimit/ctulimit | ||
| 72 | src/cterror/cterror | 72 | src/cterror/cterror |
| 73 | test/pfiles/ | 73 | test/pfiles/ |
| 74 | test/caldb/ | 74 | test/caldb/ |
| 75 | +test/prod3 | ||
| 75 | test/csroot2caldb_* | 76 | test/csroot2caldb_* |
| 76 | test/iactdata_* | 77 | test/iactdata_* |
| 77 | test/*.fits | 78 | test/*.fits |
| @@ -80,7 +81,9 @@ test/*.xml | @@ -80,7 +81,9 @@ test/*.xml | ||
| 80 | test/*.reg | 81 | test/*.reg |
| 81 | test/*.trs | 82 | test/*.trs |
| 82 | test/*.txt | 83 | test/*.txt |
| 84 | +test/*.eps | ||
| 83 | test/test_cscripts.sh | 85 | test/test_cscripts.sh |
| 86 | +test/test_examples.sh | ||
| 84 | test/reports/*.xml | 87 | test/reports/*.xml |
| 85 | test/butterfly.txt | 88 | test/butterfly.txt |
| 86 | test/.coverage | 89 | test/.coverage |
ChangeLog
| 1 | -2016-06-21 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | 1 | +2016-06-25 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> |
| 2 | 2 | ||
| 3 | * Version 1.1.0 released | 3 | * Version 1.1.0 released |
| 4 | ======================== | 4 | ======================== |
| 5 | 5 | ||
| 6 | + Add unit tests for all example scripts | ||
| 6 | Handle zero parameter errors in ctulimit (#1795) | 7 | Handle zero parameter errors in ctulimit (#1795) |
| 7 | Compute counts cube weights in ctbin (#1789) | 8 | Compute counts cube weights in ctbin (#1789) |
| 8 | Adapt to new stacked cube interface (#1788) | 9 | Adapt to new stacked cube interface (#1788) |
NEWS
README.md
| 1 | ctools information | 1 | ctools information |
| 2 | ================== | 2 | ================== |
| 3 | -* Version: 1.1.0.dev1 (21 June 2016) | 3 | +* Version: 1.1.0.dev1 (25 June 2016) |
| 4 | * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) | 4 | * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) |
| 5 | * GammaLib dependency: 1.1.0.dev1 | 5 | * GammaLib dependency: 1.1.0.dev1 |
| 6 | 6 |
configure.ac
| @@ -1025,6 +1025,7 @@ AC_CONFIG_FILES([Makefile | @@ -1025,6 +1025,7 @@ AC_CONFIG_FILES([Makefile | ||
| 1025 | test/test_cscripts.sh | 1025 | test/test_cscripts.sh |
| 1026 | test/test_python_ctools.sh | 1026 | test/test_python_ctools.sh |
| 1027 | test/test_python_cscripts.sh | 1027 | test/test_python_cscripts.sh |
| 1028 | + test/test_examples.sh | ||
| 1028 | pyext/Makefile | 1029 | pyext/Makefile |
| 1029 | pyext/setup.py | 1030 | pyext/setup.py |
| 1030 | pyext/ctools/__init__.py | 1031 | pyext/ctools/__init__.py |
| @@ -1038,6 +1039,7 @@ AC_CONFIG_FILES([Makefile | @@ -1038,6 +1039,7 @@ AC_CONFIG_FILES([Makefile | ||
| 1038 | [if test -f test/test_cscripts.sh; then chmod +x test/test_cscripts.sh; fi; | 1039 | [if test -f test/test_cscripts.sh; then chmod +x test/test_cscripts.sh; fi; |
| 1039 | if test -f test/test_python_ctools.sh; then chmod +x test/test_python_ctools.sh; fi; | 1040 | if test -f test/test_python_ctools.sh; then chmod +x test/test_python_ctools.sh; fi; |
| 1040 | if test -f test/test_python_cscripts.sh; then chmod +x test/test_python_cscripts.sh; fi; | 1041 | if test -f test/test_python_cscripts.sh; then chmod +x test/test_python_cscripts.sh; fi; |
| 1042 | + if test -f test/test_examples.sh; then chmod +x test/test_examples.sh; fi; | ||
| 1041 | if test -f testconf.sh; then chmod +x testconf.sh; fi]) | 1043 | if test -f testconf.sh; then chmod +x testconf.sh; fi]) |
| 1042 | AC_OUTPUT | 1044 | AC_OUTPUT |
| 1043 | 1045 |
examples/Makefile.am
| 1 | ## Process this file with automake to produce Makefile.in | 1 | ## Process this file with automake to produce Makefile.in |
| 2 | 2 | ||
| 3 | # Scripts to be distributed | 3 | # Scripts to be distributed |
| 4 | -scripts = README \ | ||
| 5 | - benchmark_cta_analysis.py \ | ||
| 6 | - check_models.py \ | ||
| 7 | - make_pull_at_sensitivity_limit.py \ | 4 | +scripts = README.md \ |
| 5 | + make_pointings.py \ | ||
| 8 | make_spectrum.py \ | 6 | make_spectrum.py \ |
| 9 | - make_survey.py \ | ||
| 10 | make_ts_distributions.py \ | 7 | make_ts_distributions.py \ |
| 11 | pipeline_binned_disk.py \ | 8 | pipeline_binned_disk.py \ |
| 12 | pipeline_binned_mem.py \ | 9 | pipeline_binned_mem.py \ |
| @@ -15,10 +12,13 @@ scripts = README \ | @@ -15,10 +12,13 @@ scripts = README \ | ||
| 15 | pipeline_unbinned_disk.py \ | 12 | pipeline_unbinned_disk.py \ |
| 16 | pipeline_unbinned_mem.py \ | 13 | pipeline_unbinned_mem.py \ |
| 17 | show_butterfly.py \ | 14 | show_butterfly.py \ |
| 15 | + show_model.py \ | ||
| 18 | show_pha.py \ | 16 | show_pha.py \ |
| 17 | + show_pull_evolution.py \ | ||
| 19 | show_pull_histogram.py \ | 18 | show_pull_histogram.py \ |
| 20 | show_response.py \ | 19 | show_response.py \ |
| 21 | show_sensitivity.py \ | 20 | show_sensitivity.py \ |
| 21 | + show_spectrum.py \ | ||
| 22 | show_ts_distribution.py | 22 | show_ts_distribution.py |
| 23 | 23 | ||
| 24 | # Set directories | 24 | # Set directories |
examples/README deleted
| 1 | -This folder contains Python example scripts that illustrate the | ||
| 2 | -usage of the ctools. | ||
| 3 | - | ||
| 4 | -benchmark_cta_analysis.py | ||
| 5 | - This script peforms a benchmark of the various CTA analysis types | ||
| 6 | - (unbinned, binned, stacked), and if matplotlib is installed, creates | ||
| 7 | - a plot of the benchmark results. | ||
| 8 | - | ||
| 9 | -check_models.py | ||
| 10 | - Checks a variety of models using an unbinned analysis. | ||
| 11 | - | ||
| 12 | -make_pointings.py | ||
| 13 | - This script creates pointings for CTA surveys. For the moment the | ||
| 14 | - Galactic Plane Survey (gps), the Extragalactic Survey (extgal), | ||
| 15 | - the Galactic Centre Survey (gc) and the LMC survey (lmc) are | ||
| 16 | - implemented. The script outputs and ASCII file that can be used by | ||
| 17 | - csobsdef. | ||
| 18 | - | ||
| 19 | -make_pull_at_sensitivity_limit.py | ||
| 20 | - This script creates pull distributions as function of energy | ||
| 21 | - for a test source that is at the 5 sigma sensitivity limit for | ||
| 22 | - 50h of effective observing time. It takes as input file the | ||
| 23 | - output file generated using cspull. | ||
| 24 | - If the Python processing module is installed the script can make | ||
| 25 | - use of multiple cores and runs in parallel. | ||
| 26 | - | ||
| 27 | -make_spectrum.py | ||
| 28 | - This script shows how to make a spectrum using obsutils. | ||
| 29 | - | ||
| 30 | -make_survey.py | ||
| 31 | - This script simulates a CTA galactic plane survey. | ||
| 32 | - | ||
| 33 | -make_ts_distributions.py | ||
| 34 | - This script creates TS distributions as function of energy for | ||
| 35 | - an off observation of 50h effective observing time. | ||
| 36 | - If the Python processing module is installed the script can make | ||
| 37 | - use of multiple cores and runs in parallel. | ||
| 38 | - | ||
| 39 | -benchmark_cta_analysis.py | ||
| 40 | - Performs performance benchmarks of the various CTA analysis types. | ||
| 41 | - | ||
| 42 | -pipeline_binned_disk.py | ||
| 43 | - Example pipeline for simulating events and performing a binned | ||
| 44 | - analysis by saving intermediate results to disk. | ||
| 45 | - | ||
| 46 | -pipeline_binned_mem.py | ||
| 47 | - Example pipeline for simulating events and performing a binned | ||
| 48 | - analysis in memory. No files will be written to disk. | ||
| 49 | - | ||
| 50 | -pipeline_stacked_disk.py | ||
| 51 | - Example pipeline for simulating events and performing a stacked | ||
| 52 | - analysis by saving intermediate results to disk. | ||
| 53 | - | ||
| 54 | -pipeline_stacked_mem.py | ||
| 55 | - Example pipeline for simulating events and performing a stacked | ||
| 56 | - analysis in memory. No files will be written to disk. | ||
| 57 | - | ||
| 58 | -pipeline_unbinned_disk.py | ||
| 59 | - Example pipeline for simulating events and performing an unbinned | ||
| 60 | - analysis by saving intermediate results to disk. | ||
| 61 | - | ||
| 62 | -pipeline_unbinned_mem.py | ||
| 63 | - Example pipeline for simulating events and performing an unbinned | ||
| 64 | - analysis in memory. No files will be written to disk. | ||
| 65 | - | ||
| 66 | -show_butterfly.py | ||
| 67 | - Displays a butterfly generated using the ctbutterfly tool. | ||
| 68 | - | ||
| 69 | -show_model.py | ||
| 70 | - Displays a spectral model. | ||
| 71 | - | ||
| 72 | -show_pha.py | ||
| 73 | - Displays a spectrum in PHA format. | ||
| 74 | - | ||
| 75 | -show_pull_histogram.py | ||
| 76 | - Displays pull histograms generated by the cspull script. | ||
| 77 | - | ||
| 78 | -show_response.py | ||
| 79 | - Displays one or several CTA response functions. | ||
| 80 | - | ||
| 81 | -show_sensitivity.py | ||
| 82 | - Displays sensitivity information generated by the cssens script. | ||
| 83 | - | ||
| 84 | -show_ts_distribution.py | ||
| 85 | - Displays Test Statistic histograms generated using the cstsdist | ||
| 86 | - script. |
examples/README.md
0 → 100644
| 1 | +ctools examples | ||
| 2 | +=============== | ||
| 3 | + | ||
| 4 | +This folder contains Python example scripts that illustrate the usage of | ||
| 5 | +the ctools. | ||
| 6 | + | ||
| 7 | +`generate_prod3_irfs/py` | ||
| 8 | +> Generates Prod3 Instrument Response Functions from FITS files. | ||
| 9 | + | ||
| 10 | +`make_pointings.py` | ||
| 11 | +> Creates pointings for CTA surveys. For the moment the Galactic Plane | ||
| 12 | +> Survey (gps), the Extragalactic Survey (extgal), the Galactic Centre | ||
| 13 | +> Survey (gc) and the LMC survey (lmc) are implemented. The script outputs | ||
| 14 | +> and ASCII file that can be used by csobsdef. | ||
| 15 | + | ||
| 16 | +`make_spectrum.py` | ||
| 17 | +> Simulates events and generates a spectrum from the using csspec. | ||
| 18 | + | ||
| 19 | +`make_ts_distributions.py` | ||
| 20 | +> Creates TS distributions as function of energy for an OFF observaition | ||
| 21 | +> of 50 hours effective observing time. If the Python processing module is | ||
| 22 | +> installed the script can make use of multiple cores and runs in parallel. | ||
| 23 | + | ||
| 24 | +`pipeline_binned_disk.py` | ||
| 25 | +> Example pipeline for simulating events and performing a binned analysis | ||
| 26 | +> by saving intermediate results to disk. | ||
| 27 | + | ||
| 28 | +`pipeline_binned_mem.py` | ||
| 29 | +> Example pipeline for simulating events and performing a binned analysis | ||
| 30 | +> in memory. No files will be written to disk. | ||
| 31 | + | ||
| 32 | +`pipeline_stacked_disk.py` | ||
| 33 | +> Example pipeline for simulating events and performing a stacked analysis | ||
| 34 | +> by saving intermediate results to disk. | ||
| 35 | + | ||
| 36 | +`pipeline_stacked_mem.py` | ||
| 37 | +> Example pipeline for simulating events and performing a stacked analysis | ||
| 38 | +> in memory. No files will be written to disk. | ||
| 39 | + | ||
| 40 | +`pipeline_unbinned_disk.py` | ||
| 41 | +> Example pipeline for simulating events and performing an unbinned analysis | ||
| 42 | +> by saving intermediate results to disk. | ||
| 43 | + | ||
| 44 | +`pipeline_unbinned_mem.py` | ||
| 45 | +> Example pipeline for simulating events and performing an unbinned analysis | ||
| 46 | +> in memory. No files will be written to disk. | ||
| 47 | + | ||
| 48 | +`show_butterfly.py` | ||
| 49 | +> Displays a butterfly generated using the ctbutterfly tool. | ||
| 50 | + | ||
| 51 | +`show_model.py` | ||
| 52 | +> Displays a spectral model. | ||
| 53 | + | ||
| 54 | +`show_pha.py` | ||
| 55 | +> Displays a spectrum in PHA format. | ||
| 56 | + | ||
| 57 | +`show_pull_evolution.py` | ||
| 58 | +> Displays the evolution of the mean and rms pull as function of number of | ||
| 59 | +> trials. | ||
| 60 | + | ||
| 61 | +`show_pull_histogram.py` | ||
| 62 | +> Displays pull histograms generated by the cspull script. | ||
| 63 | + | ||
| 64 | +`show_response.py` | ||
| 65 | +> Displays one or several CTA response functions. | ||
| 66 | + | ||
| 67 | +`show_sensitivity.py` | ||
| 68 | +> Displays the sensitivity generated by the cssens script. | ||
| 69 | + | ||
| 70 | +`show_spectrum.py` | ||
| 71 | +> Displays spectrum generated by the csspec script. | ||
| 72 | + | ||
| 73 | +`show_ts_distribution.py` | ||
| 74 | +> Displays Test Statistic histograms generated using the cstsdist script. |
examples/generate_prod3_irfs.py
| @@ -27,15 +27,30 @@ import cscripts | @@ -27,15 +27,30 @@ import cscripts | ||
| 27 | # ======================= # | 27 | # ======================= # |
| 28 | def set_prod3_desy(): | 28 | def set_prod3_desy(): |
| 29 | """ | 29 | """ |
| 30 | - Set Prod3 DESY database. | 30 | + Set Prod3 DESY database |
| 31 | + | ||
| 32 | + This function sets the calibration database. By adding dictionaries to | ||
| 33 | + the db list a number of calibrations can be defined for which IRFs | ||
| 34 | + should be generated. All calibrations will be added to the calibration | ||
| 35 | + database. | ||
| 31 | """ | 36 | """ |
| 32 | # Set database attributes | 37 | # Set database attributes |
| 33 | - path = "/project-data/cta/performance/prod3" | ||
| 34 | - psftype = "Gauss" | 38 | + #path = '/project-data/cta/performance/prod3' |
| 39 | + #file = 'DESY.d20160304.V5.ID0NIM2.prod3-paranalp05-NN.S.3HB1-ND-3.180000s.root' | ||
| 40 | + path = 'data' | ||
| 41 | + file = 'irf.root' | ||
| 42 | + psftype = 'Gauss' | ||
| 43 | + oversample = 3 | ||
| 44 | + #norm1d = True # Will normalise the on-axis 2D IRFs on the 1D IRFs | ||
| 45 | + norm1d = False | ||
| 46 | + bgdinfill = False | ||
| 47 | + bgdethres = 10.0 | ||
| 35 | 48 | ||
| 36 | # Set database content | 49 | # Set database content |
| 37 | - db = [{'inst': "prod3", 'id': "South_50h", 'psftype': psftype, 'path': path, | ||
| 38 | - 'file': "DESY.d20160304.V5.ID0NIM2.prod3-paranalp05-NN.S.3HB1-ND-3.180000s.root"} | 50 | + db = [{'inst': 'prod3', 'id': 'South_50h', 'psftype': psftype, |
| 51 | + 'oversample': oversample, 'norm1d': norm1d, | ||
| 52 | + 'bgdinfill': bgdinfill, 'bgdethres': bgdethres, | ||
| 53 | + 'path': path, 'file': file} | ||
| 39 | ] | 54 | ] |
| 40 | 55 | ||
| 41 | # Return database | 56 | # Return database |
| @@ -66,23 +81,43 @@ if __name__ == '__main__': | @@ -66,23 +81,43 @@ if __name__ == '__main__': | ||
| 66 | bgdscale = entry['bgdscale'] | 81 | bgdscale = entry['bgdscale'] |
| 67 | else: | 82 | else: |
| 68 | bgdscale = 1.0 | 83 | bgdscale = 1.0 |
| 84 | + if entry.has_key('bgdethres'): | ||
| 85 | + bgdethres = entry['bgdethres'] | ||
| 86 | + else: | ||
| 87 | + bgdethres = 1000.0 | ||
| 88 | + if entry.has_key('bgdinfill'): | ||
| 89 | + bgdinfill = entry['bgdinfill'] | ||
| 90 | + else: | ||
| 91 | + bgdinfill = False | ||
| 92 | + if entry.has_key('oversample'): | ||
| 93 | + oversample = entry['oversample'] | ||
| 94 | + else: | ||
| 95 | + oversample = 1 | ||
| 96 | + if entry.has_key('norm1d'): | ||
| 97 | + norm1d = entry['norm1d'] | ||
| 98 | + else: | ||
| 99 | + norm1d = False | ||
| 69 | 100 | ||
| 70 | # Set filename | 101 | # Set filename |
| 71 | - filename = entry['path']+"/"+entry['file'] | 102 | + filename = entry['path']+'/'+entry['file'] |
| 72 | 103 | ||
| 73 | # Set-up csroot2caldb | 104 | # Set-up csroot2caldb |
| 74 | caldb = cscripts.csroot2caldb() | 105 | caldb = cscripts.csroot2caldb() |
| 75 | - caldb["infile"] = filename | ||
| 76 | - caldb["outdir"] = "prod3" | ||
| 77 | - caldb["inst"] = entry['inst'] | ||
| 78 | - caldb["id"] = entry['id'] | ||
| 79 | - caldb["version"] = entry['inst'] | ||
| 80 | - caldb["analysis"] = "DESY" | ||
| 81 | - caldb["psftype"] = entry['psftype'] | ||
| 82 | - caldb["rebin"] = rebin | ||
| 83 | - caldb["eascale"] = eascale | ||
| 84 | - caldb["bgdscale"] = bgdscale | ||
| 85 | - caldb["logfile"] = "generate_prod3_irfs.log" | 106 | + caldb['infile'] = filename |
| 107 | + caldb['outdir'] = 'prod3' | ||
| 108 | + caldb['inst'] = entry['inst'] | ||
| 109 | + caldb['id'] = entry['id'] | ||
| 110 | + caldb['version'] = entry['inst'] | ||
| 111 | + caldb['analysis'] = 'DESY' | ||
| 112 | + caldb['psftype'] = entry['psftype'] | ||
| 113 | + caldb['norm1d'] = norm1d | ||
| 114 | + caldb['rebin'] = rebin | ||
| 115 | + caldb['eascale'] = eascale | ||
| 116 | + caldb['bgdscale'] = bgdscale | ||
| 117 | + caldb['bgdoversample'] = oversample | ||
| 118 | + caldb['bgdethres'] = bgdethres | ||
| 119 | + caldb['bgdinfill'] = bgdinfill | ||
| 120 | + caldb['logfile'] = 'generate_prod3_irfs.log' | ||
| 86 | 121 | ||
| 87 | # Add CALDB entry | 122 | # Add CALDB entry |
| 88 | caldb.execute() | 123 | caldb.execute() |
examples/make_pointings.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script generates pointing patterns for CTA observations. | 3 | +# Generates pointing patterns for CTA observations |
| 4 | # | 4 | # |
| 5 | -# Usage: | ||
| 6 | -# ./make_pointings.py | ||
| 7 | -# | ||
| 8 | -# ========================================================================== | ||
| 9 | -# | ||
| 10 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 11 | # | 6 | # |
| 12 | # 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 |
| 13 | # 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 |
| @@ -33,10 +28,30 @@ import gammalib | @@ -33,10 +28,30 @@ import gammalib | ||
| 33 | # ============================================================ # | 28 | # ============================================================ # |
| 34 | def get_positions(xmin, xmax, ymin, ymax, step): | 29 | def get_positions(xmin, xmax, ymin, ymax, step): |
| 35 | """ | 30 | """ |
| 31 | + Get pointing positions for an interleaved pattern | ||
| 32 | + | ||
| 36 | Get positions for a patch of interleaved pointings on the sky. | 33 | Get positions for a patch of interleaved pointings on the sky. |
| 37 | The function does respect the latitude dependence of the | 34 | The function does respect the latitude dependence of the |
| 38 | pointing distance. The step parameter is for a latitude of | 35 | pointing distance. The step parameter is for a latitude of |
| 39 | zero. | 36 | zero. |
| 37 | + | ||
| 38 | + Parameters | ||
| 39 | + ---------- | ||
| 40 | + xmin : float | ||
| 41 | + Minimum longitude (deg) | ||
| 42 | + xmax : float | ||
| 43 | + Maximum longitude (deg) | ||
| 44 | + ymin : float | ||
| 45 | + Minimum latitude (deg) | ||
| 46 | + ymax : float | ||
| 47 | + Maximum latitude (deg) | ||
| 48 | + step : float | ||
| 49 | + Pointing step size (deg) | ||
| 50 | + | ||
| 51 | + Returns | ||
| 52 | + ------- | ||
| 53 | + positions : list of dict | ||
| 54 | + List of dictionaries with x and y positions | ||
| 40 | """ | 55 | """ |
| 41 | # Initialise positions | 56 | # Initialise positions |
| 42 | positions = [] | 57 | positions = [] |
| @@ -46,7 +61,7 @@ def get_positions(xmin, xmax, ymin, ymax, step): | @@ -46,7 +61,7 @@ def get_positions(xmin, xmax, ymin, ymax, step): | ||
| 46 | ny = int((ymax-ymin)/ystep+1.5) | 61 | ny = int((ymax-ymin)/ystep+1.5) |
| 47 | rescale = (ymax-ymin)/(ystep*(ny-1)) | 62 | rescale = (ymax-ymin)/(ystep*(ny-1)) |
| 48 | ystep *= rescale | 63 | ystep *= rescale |
| 49 | - print("Number of rows ....: %d" % (ny)) | 64 | + print('Number of rows ....: %d' % (ny)) |
| 50 | 65 | ||
| 51 | # Loop over rows | 66 | # Loop over rows |
| 52 | y = ymin | 67 | y = ymin |
| @@ -63,7 +78,6 @@ def get_positions(xmin, xmax, ymin, ymax, step): | @@ -63,7 +78,6 @@ def get_positions(xmin, xmax, ymin, ymax, step): | ||
| 63 | x = xmin | 78 | x = xmin |
| 64 | else: | 79 | else: |
| 65 | x = xmin + 0.5 * xstep | 80 | x = xmin + 0.5 * xstep |
| 66 | - #print(row, y, nx) | ||
| 67 | 81 | ||
| 68 | # Append pointings | 82 | # Append pointings |
| 69 | for pnt in range(nx): | 83 | for pnt in range(nx): |
| @@ -86,7 +100,33 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -86,7 +100,33 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 86 | separation=3.0, hours=100.0, | 100 | separation=3.0, hours=100.0, |
| 87 | site=None, lst=True, autodec=0.0): | 101 | site=None, lst=True, autodec=0.0): |
| 88 | """ | 102 | """ |
| 89 | - Setup pointing patch on the sky. | 103 | + Setup pointing patch on the sky |
| 104 | + | ||
| 105 | + Parameters | ||
| 106 | + ---------- | ||
| 107 | + lmin : float, optional | ||
| 108 | + Minimum Galactic Longitude (deg) | ||
| 109 | + lmax : float, optional | ||
| 110 | + Maximum Galactic Longitude (deg) | ||
| 111 | + bmin : float, optional | ||
| 112 | + Minimum Galactic Latitude (deg) | ||
| 113 | + bmax : float, optional | ||
| 114 | + Maximum Galactic Latitude (deg) | ||
| 115 | + separation : float, optional | ||
| 116 | + Pointing separation (deg) | ||
| 117 | + hours : float, optional | ||
| 118 | + Total observation duration (h) | ||
| 119 | + site : str, optional | ||
| 120 | + Array site (one of 'Automatic', 'South', 'North') | ||
| 121 | + lst : bool, optional | ||
| 122 | + Use LSTs | ||
| 123 | + autodec : float, optional | ||
| 124 | + Declination for switching automatically between South and North site | ||
| 125 | + | ||
| 126 | + Returns | ||
| 127 | + ------- | ||
| 128 | + obsdef : list of dict | ||
| 129 | + List of pointing definitions | ||
| 90 | """ | 130 | """ |
| 91 | # Initialise observation definition | 131 | # Initialise observation definition |
| 92 | obsdef = [] | 132 | obsdef = [] |
| @@ -112,30 +152,30 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -112,30 +152,30 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 112 | if site != None: | 152 | if site != None: |
| 113 | 153 | ||
| 114 | # Handle automatic site switching | 154 | # Handle automatic site switching |
| 115 | - if site == "Automatic": | 155 | + if site == 'Automatic': |
| 116 | pos = gammalib.GSkyDir() | 156 | pos = gammalib.GSkyDir() |
| 117 | pos.lb_deg(pnt['x'], pnt['y']) | 157 | pos.lb_deg(pnt['x'], pnt['y']) |
| 118 | dec = pos.dec_deg() | 158 | dec = pos.dec_deg() |
| 119 | if (dec >= autodec): | 159 | if (dec >= autodec): |
| 120 | - obs_site = "North" | 160 | + obs_site = 'North' |
| 121 | else: | 161 | else: |
| 122 | - obs_site = "South" | 162 | + obs_site = 'South' |
| 123 | else: | 163 | else: |
| 124 | obs_site = site | 164 | obs_site = site |
| 125 | 165 | ||
| 126 | # Set site IRF | 166 | # Set site IRF |
| 127 | - caldb = "prod2" | ||
| 128 | - if obs_site == "North": | 167 | + caldb = 'prod2' |
| 168 | + if obs_site == 'North': | ||
| 129 | if lst: | 169 | if lst: |
| 130 | - irf = "North_50h" | 170 | + irf = 'North_50h' |
| 131 | else: | 171 | else: |
| 132 | - irf = "North_50h" | 172 | + irf = 'North_50h' |
| 133 | exposure_north += duration | 173 | exposure_north += duration |
| 134 | else: | 174 | else: |
| 135 | if lst: | 175 | if lst: |
| 136 | - irf = "South_50h" | 176 | + irf = 'South_50h' |
| 137 | else: | 177 | else: |
| 138 | - irf = "South_50h" | 178 | + irf = 'South_50h' |
| 139 | exposure_south += duration | 179 | exposure_south += duration |
| 140 | 180 | ||
| 141 | # Set IRF information | 181 | # Set IRF information |
| @@ -146,11 +186,11 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -146,11 +186,11 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 146 | obsdef.append(obs) | 186 | obsdef.append(obs) |
| 147 | 187 | ||
| 148 | # Dump statistics | 188 | # Dump statistics |
| 149 | - print("Number of pointings: %d (%.2f sec)" % (n_pnt,duration)) | ||
| 150 | - print("South array .......: %.2f hours (%.2f%%)" % | 189 | + print('Number of pointings: %d (%.2f s)' % (n_pnt,duration)) |
| 190 | + print('South array .......: %.2f hours (%.2f%%)' % | ||
| 151 | (exposure_south/3600.0, | 191 | (exposure_south/3600.0, |
| 152 | 100.0*exposure_south/(exposure_south+exposure_north))) | 192 | 100.0*exposure_south/(exposure_south+exposure_north))) |
| 153 | - print("North array .......: %.2f hours (%.2f%%)" % | 193 | + print('North array .......: %.2f hours (%.2f%%)' % |
| 154 | (exposure_north/3600.0, | 194 | (exposure_north/3600.0, |
| 155 | 100.0*exposure_north/(exposure_south+exposure_north))) | 195 | 100.0*exposure_north/(exposure_south+exposure_north))) |
| 156 | 196 | ||
| @@ -163,7 +203,23 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | @@ -163,7 +203,23 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, | ||
| 163 | # =========================== # | 203 | # =========================== # |
| 164 | def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | 204 | def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): |
| 165 | """ | 205 | """ |
| 166 | - Setup Galactic plane survey. | 206 | + Setup Galactic plane survey |
| 207 | + | ||
| 208 | + Parameters | ||
| 209 | + ---------- | ||
| 210 | + separation : float, optional | ||
| 211 | + Pointing separation (deg) | ||
| 212 | + bmin : float, optional | ||
| 213 | + Minimum Galactic Latitude (deg) | ||
| 214 | + bmax : float, optional | ||
| 215 | + Maximum Galactic Latitude (deg) | ||
| 216 | + lst : bool, optional | ||
| 217 | + Use LSTs | ||
| 218 | + | ||
| 219 | + Returns | ||
| 220 | + ------- | ||
| 221 | + obsdef : list of dict | ||
| 222 | + List of pointing definitions | ||
| 167 | """ | 223 | """ |
| 168 | # Initialise observation definition | 224 | # Initialise observation definition |
| 169 | obsdef = [] | 225 | obsdef = [] |
| @@ -171,27 +227,27 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | @@ -171,27 +227,27 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | ||
| 171 | # Add inner region South | 227 | # Add inner region South |
| 172 | obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax, | 228 | obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax, |
| 173 | separation=separation, hours=780, | 229 | separation=separation, hours=780, |
| 174 | - site="South", lst=lst)) | 230 | + site='South', lst=lst)) |
| 175 | 231 | ||
| 176 | # Add Vela & Carina region | 232 | # Add Vela & Carina region |
| 177 | obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax, | 233 | obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax, |
| 178 | separation=separation, hours=180, | 234 | separation=separation, hours=180, |
| 179 | - site="South", lst=lst)) | 235 | + site='South', lst=lst)) |
| 180 | 236 | ||
| 181 | # Add 210-240 region | 237 | # Add 210-240 region |
| 182 | obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax, | 238 | obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax, |
| 183 | separation=separation, hours=60, | 239 | separation=separation, hours=60, |
| 184 | - site="South", lst=lst)) | 240 | + site='South', lst=lst)) |
| 185 | 241 | ||
| 186 | # Add Cygnus, Perseus | 242 | # Add Cygnus, Perseus |
| 187 | obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax, | 243 | obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax, |
| 188 | separation=separation, hours=450, | 244 | separation=separation, hours=450, |
| 189 | - site="North", lst=lst)) | 245 | + site='North', lst=lst)) |
| 190 | 246 | ||
| 191 | # Add Anticentre | 247 | # Add Anticentre |
| 192 | obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax, | 248 | obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax, |
| 193 | separation=separation, hours=150, | 249 | separation=separation, hours=150, |
| 194 | - site="North", lst=lst)) | 250 | + site='North', lst=lst)) |
| 195 | 251 | ||
| 196 | # Return observation definition | 252 | # Return observation definition |
| 197 | return obsdef | 253 | return obsdef |
| @@ -203,6 +259,18 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | @@ -203,6 +259,18 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): | ||
| 203 | def set_extgal(separation=3.0, lst=True): | 259 | def set_extgal(separation=3.0, lst=True): |
| 204 | """ | 260 | """ |
| 205 | Setup Extragalactic survey. | 261 | Setup Extragalactic survey. |
| 262 | + | ||
| 263 | + Parameters | ||
| 264 | + ---------- | ||
| 265 | + separation : float, optional | ||
| 266 | + Pointing separation (deg) | ||
| 267 | + lst : bool, optional | ||
| 268 | + Use LSTs | ||
| 269 | + | ||
| 270 | + Returns | ||
| 271 | + ------- | ||
| 272 | + obsdef : list of dict | ||
| 273 | + List of pointing definitions | ||
| 206 | """ | 274 | """ |
| 207 | # Initialise observation definition | 275 | # Initialise observation definition |
| 208 | obsdef = [] | 276 | obsdef = [] |
| @@ -210,7 +278,7 @@ def set_extgal(separation=3.0, lst=True): | @@ -210,7 +278,7 @@ def set_extgal(separation=3.0, lst=True): | ||
| 210 | # Set patch | 278 | # Set patch |
| 211 | obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0, | 279 | obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0, |
| 212 | separation=separation, hours=1000, | 280 | separation=separation, hours=1000, |
| 213 | - site="Automatic", lst=lst, autodec=10.0)) | 281 | + site='Automatic', lst=lst, autodec=10.0)) |
| 214 | 282 | ||
| 215 | # Return observation definition | 283 | # Return observation definition |
| 216 | return obsdef | 284 | return obsdef |
| @@ -222,6 +290,16 @@ def set_extgal(separation=3.0, lst=True): | @@ -222,6 +290,16 @@ def set_extgal(separation=3.0, lst=True): | ||
| 222 | def set_gc(lst=True): | 290 | def set_gc(lst=True): |
| 223 | """ | 291 | """ |
| 224 | Setup Galactic centre KSP. | 292 | Setup Galactic centre KSP. |
| 293 | + | ||
| 294 | + Parameters | ||
| 295 | + ---------- | ||
| 296 | + lst : bool, optional | ||
| 297 | + Use LSTs | ||
| 298 | + | ||
| 299 | + Returns | ||
| 300 | + ------- | ||
| 301 | + obsdef : list of dict | ||
| 302 | + List of pointing definitions | ||
| 225 | """ | 303 | """ |
| 226 | # Initialise observation definition | 304 | # Initialise observation definition |
| 227 | obsdef = [] | 305 | obsdef = [] |
| @@ -229,12 +307,12 @@ def set_gc(lst=True): | @@ -229,12 +307,12 @@ def set_gc(lst=True): | ||
| 229 | # Central wobble | 307 | # Central wobble |
| 230 | obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5, | 308 | obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5, |
| 231 | separation=0.1, hours=525, | 309 | separation=0.1, hours=525, |
| 232 | - site="South", lst=lst)) | 310 | + site='South', lst=lst)) |
| 233 | 311 | ||
| 234 | # Extended region | 312 | # Extended region |
| 235 | obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0, | 313 | obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0, |
| 236 | separation=1.5, hours=300, | 314 | separation=1.5, hours=300, |
| 237 | - site="South", lst=lst)) | 315 | + site='South', lst=lst)) |
| 238 | 316 | ||
| 239 | # Return observation definition | 317 | # Return observation definition |
| 240 | return obsdef | 318 | return obsdef |
| @@ -246,6 +324,18 @@ def set_gc(lst=True): | @@ -246,6 +324,18 @@ def set_gc(lst=True): | ||
| 246 | def set_lmc(hours=250.0, lst=True): | 324 | def set_lmc(hours=250.0, lst=True): |
| 247 | """ | 325 | """ |
| 248 | Setup LMC KSP. | 326 | Setup LMC KSP. |
| 327 | + | ||
| 328 | + Parameters | ||
| 329 | + ---------- | ||
| 330 | + hours : float, optional | ||
| 331 | + Total observation duration (h) | ||
| 332 | + lst : bool, optional | ||
| 333 | + Use LSTs | ||
| 334 | + | ||
| 335 | + Returns | ||
| 336 | + ------- | ||
| 337 | + obsdef : list of dict | ||
| 338 | + List of pointing definitions | ||
| 249 | """ | 339 | """ |
| 250 | # Initialise observation definition | 340 | # Initialise observation definition |
| 251 | obsdef = [] | 341 | obsdef = [] |
| @@ -275,11 +365,11 @@ def set_lmc(hours=250.0, lst=True): | @@ -275,11 +365,11 @@ def set_lmc(hours=250.0, lst=True): | ||
| 275 | obs = {'lon': lon, 'lat': lat, 'duration': duration} | 365 | obs = {'lon': lon, 'lat': lat, 'duration': duration} |
| 276 | 366 | ||
| 277 | # Add IRF | 367 | # Add IRF |
| 278 | - caldb = "prod2" | 368 | + caldb = 'prod2' |
| 279 | if lst: | 369 | if lst: |
| 280 | - irf = "South_50h" | 370 | + irf = 'South_50h' |
| 281 | else: | 371 | else: |
| 282 | - irf = "South_50h" | 372 | + irf = 'South_50h' |
| 283 | obs['caldb'] = caldb | 373 | obs['caldb'] = caldb |
| 284 | obs['irf'] = irf | 374 | obs['irf'] = irf |
| 285 | 375 | ||
| @@ -287,7 +377,7 @@ def set_lmc(hours=250.0, lst=True): | @@ -287,7 +377,7 @@ def set_lmc(hours=250.0, lst=True): | ||
| 287 | obsdef.append(obs) | 377 | obsdef.append(obs) |
| 288 | 378 | ||
| 289 | # Dump statistics | 379 | # Dump statistics |
| 290 | - print("Number of pointings: %d (%.2f sec)" % (n_pnt,duration)) | 380 | + print('Number of pointings: %d (%.2f s)' % (n_pnt,duration)) |
| 291 | 381 | ||
| 292 | # Return observation definition | 382 | # Return observation definition |
| 293 | return obsdef | 383 | return obsdef |
| @@ -298,31 +388,38 @@ def set_lmc(hours=250.0, lst=True): | @@ -298,31 +388,38 @@ def set_lmc(hours=250.0, lst=True): | ||
| 298 | # ======================================= # | 388 | # ======================================= # |
| 299 | def write_obsdef(filename, obsdef): | 389 | def write_obsdef(filename, obsdef): |
| 300 | """ | 390 | """ |
| 301 | - Write observation definition file. | 391 | + Write observation definition file |
| 392 | + | ||
| 393 | + Parameters | ||
| 394 | + ---------- | ||
| 395 | + filename : str | ||
| 396 | + Observation definition file name | ||
| 397 | + obsdef : list of dict | ||
| 398 | + List of pointing definitions | ||
| 302 | """ | 399 | """ |
| 303 | # Open file | 400 | # Open file |
| 304 | file = open(filename, 'w') | 401 | file = open(filename, 'w') |
| 305 | 402 | ||
| 306 | # Write header | 403 | # Write header |
| 307 | - file.write("ra,dec,duration,caldb,irf\n") | 404 | + file.write('ra,dec,duration,caldb,irf\n') |
| 308 | 405 | ||
| 309 | # Loop over pointings | 406 | # Loop over pointings |
| 310 | for obs in obsdef: | 407 | for obs in obsdef: |
| 311 | 408 | ||
| 312 | # If we have lon,lat then convert into RA,Dec | 409 | # If we have lon,lat then convert into RA,Dec |
| 313 | - if "lon" in obs and "lat" in obs: | ||
| 314 | - lon = obs["lon"] | ||
| 315 | - lat = obs["lat"] | 410 | + if 'lon' in obs and 'lat' in obs: |
| 411 | + lon = obs['lon'] | ||
| 412 | + lat = obs['lat'] | ||
| 316 | dir = gammalib.GSkyDir() | 413 | dir = gammalib.GSkyDir() |
| 317 | dir.lb_deg(lon,lat) | 414 | dir.lb_deg(lon,lat) |
| 318 | ra = dir.ra_deg() | 415 | ra = dir.ra_deg() |
| 319 | dec = dir.dec_deg() | 416 | dec = dir.dec_deg() |
| 320 | else: | 417 | else: |
| 321 | - ra = obs["ra"] | ||
| 322 | - dec = obs["dec"] | 418 | + ra = obs['ra'] |
| 419 | + dec = obs['dec'] | ||
| 323 | 420 | ||
| 324 | # Write information | 421 | # Write information |
| 325 | - file.write("%8.4f,%8.4f,%.4f,%s,%s\n" % | 422 | + file.write('%8.4f,%8.4f,%.4f,%s,%s\n' % |
| 326 | (ra, dec, obs['duration'], obs['caldb'], obs['irf'])) | 423 | (ra, dec, obs['duration'], obs['caldb'], obs['irf'])) |
| 327 | 424 | ||
| 328 | # Close file | 425 | # Close file |
| @@ -336,15 +433,13 @@ def write_obsdef(filename, obsdef): | @@ -336,15 +433,13 @@ def write_obsdef(filename, obsdef): | ||
| 336 | # Main routine entry point # | 433 | # Main routine entry point # |
| 337 | # ======================== # | 434 | # ======================== # |
| 338 | if __name__ == '__main__': | 435 | if __name__ == '__main__': |
| 339 | - """ | ||
| 340 | - CTA pointing pattern generation. | ||
| 341 | - """ | 436 | + |
| 342 | # Initialise flags | 437 | # Initialise flags |
| 343 | need_help = False | 438 | need_help = False |
| 344 | 439 | ||
| 345 | # Test for command line arguments | 440 | # Test for command line arguments |
| 346 | if (len(sys.argv) > 1): | 441 | if (len(sys.argv) > 1): |
| 347 | - if sys.argv[1] == "-h": | 442 | + if sys.argv[1] == '-h': |
| 348 | need_help = True | 443 | need_help = True |
| 349 | else: | 444 | else: |
| 350 | obsname = sys.argv[1] | 445 | obsname = sys.argv[1] |
| @@ -353,37 +448,37 @@ if __name__ == '__main__': | @@ -353,37 +448,37 @@ if __name__ == '__main__': | ||
| 353 | 448 | ||
| 354 | # Print help if needed and exit | 449 | # Print help if needed and exit |
| 355 | if need_help: | 450 | if need_help: |
| 356 | - print("Usage: make_pointing.py [OPTIONS]") | ||
| 357 | - print(" -h Display this usage message") | ||
| 358 | - print(" gps Galactic plane survey (2 row scheme)") | ||
| 359 | - print(" gps3 Galactic plane survey (3 row scheme)") | ||
| 360 | - print(" extgal Extragalactic survey") | ||
| 361 | - print(" gc Galactic centre survey") | ||
| 362 | - print(" lmc LMC survey") | 451 | + print('Usage: make_pointing.py [OPTIONS]') |
| 452 | + print(' -h Display this usage message') | ||
| 453 | + print(' gps Galactic plane survey (2 row scheme)') | ||
| 454 | + print(' gps3 Galactic plane survey (3 row scheme)') | ||
| 455 | + print(' extgal Extragalactic survey') | ||
| 456 | + print(' gc Galactic centre survey') | ||
| 457 | + print(' lmc LMC survey') | ||
| 363 | sys.exit() | 458 | sys.exit() |
| 364 | 459 | ||
| 365 | # Galactic plane survey | 460 | # Galactic plane survey |
| 366 | - if obsname == "gps": | 461 | + if obsname == 'gps': |
| 367 | obsdef = set_gps(lst=True) | 462 | obsdef = set_gps(lst=True) |
| 368 | - write_obsdef("gps.dat", obsdef) | ||
| 369 | - elif obsname == "gps3": | 463 | + write_obsdef('gps.dat', obsdef) |
| 464 | + elif obsname == 'gps3': | ||
| 370 | obsdef = set_gps(separation=1.5, lst=True) | 465 | obsdef = set_gps(separation=1.5, lst=True) |
| 371 | - write_obsdef("gps3.dat", obsdef) | 466 | + write_obsdef('gps3.dat', obsdef) |
| 372 | 467 | ||
| 373 | # Extragalactic survey | 468 | # Extragalactic survey |
| 374 | - elif obsname == "extgal": | 469 | + elif obsname == 'extgal': |
| 375 | obsdef = set_extgal(lst=True) | 470 | obsdef = set_extgal(lst=True) |
| 376 | - write_obsdef("extgal.dat", obsdef) | 471 | + write_obsdef('extgal.dat', obsdef) |
| 377 | 472 | ||
| 378 | # Galactic centre | 473 | # Galactic centre |
| 379 | - elif obsname == "gc": | 474 | + elif obsname == 'gc': |
| 380 | obsdef = set_gc(lst=True) | 475 | obsdef = set_gc(lst=True) |
| 381 | - write_obsdef("gc.dat", obsdef) | 476 | + write_obsdef('gc.dat', obsdef) |
| 382 | 477 | ||
| 383 | # LMC | 478 | # LMC |
| 384 | - elif obsname == "lmc": | 479 | + elif obsname == 'lmc': |
| 385 | obsdef = set_lmc(lst=True) | 480 | obsdef = set_lmc(lst=True) |
| 386 | - write_obsdef("lmc.dat", obsdef) | 481 | + write_obsdef('lmc.dat', obsdef) |
| 387 | 482 | ||
| 388 | # Invalid pattern | 483 | # Invalid pattern |
| 389 | else: | 484 | else: |
examples/make_spectrum.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script shows how to make a spectrum using obsutils. | 3 | +# Makes spectrum and optionally plot it |
| 4 | # | 4 | # |
| 5 | # Copyright (C) 2014-2016 Juergen Knoedlseder | 5 | # Copyright (C) 2014-2016 Juergen Knoedlseder |
| 6 | # | 6 | # |
| @@ -18,11 +18,13 @@ | @@ -18,11 +18,13 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -#import gammalib | 21 | +import sys |
| 22 | import ctools | 22 | import ctools |
| 23 | import cscripts | 23 | import cscripts |
| 24 | try: | 24 | try: |
| 25 | import matplotlib.pyplot as plt | 25 | import matplotlib.pyplot as plt |
| 26 | + plt.figure() | ||
| 27 | + plt.close() | ||
| 26 | has_matplotlib = True | 28 | has_matplotlib = True |
| 27 | except: | 29 | except: |
| 28 | has_matplotlib = False | 30 | has_matplotlib = False |
| @@ -33,12 +35,17 @@ except: | @@ -33,12 +35,17 @@ except: | ||
| 33 | # =============== # | 35 | # =============== # |
| 34 | def make_spectrum(): | 36 | def make_spectrum(): |
| 35 | """ | 37 | """ |
| 36 | - Make a spectrum. | 38 | + Simulate events and generate a source spectrum |
| 39 | + | ||
| 40 | + Returns | ||
| 41 | + ------- | ||
| 42 | + spectrum : `~gammalib.GFits` | ||
| 43 | + Spectrum FITS file | ||
| 37 | """ | 44 | """ |
| 38 | # Set script parameters | 45 | # Set script parameters |
| 39 | - model_name = "${CTOOLS}/share/models/crab.xml" | ||
| 40 | - caldb = "prod2" | ||
| 41 | - irf = "South_50h" | 46 | + model_name = 'data/crab.xml' |
| 47 | + caldb = 'prod2' | ||
| 48 | + irf = 'South_0.5h' | ||
| 42 | ra = 83.63 | 49 | ra = 83.63 |
| 43 | dec = 22.01 | 50 | dec = 22.01 |
| 44 | rad_sim = 3.0 | 51 | rad_sim = 3.0 |
| @@ -50,36 +57,32 @@ def make_spectrum(): | @@ -50,36 +57,32 @@ def make_spectrum(): | ||
| 50 | 57 | ||
| 51 | # Simulate events | 58 | # Simulate events |
| 52 | sim = ctools.ctobssim() | 59 | sim = ctools.ctobssim() |
| 53 | - sim["inmodel"] = model_name | ||
| 54 | - sim["caldb"] = caldb | ||
| 55 | - sim["irf"] = irf | ||
| 56 | - sim["ra"] = ra | ||
| 57 | - sim["dec"] = dec | ||
| 58 | - sim["rad"] = rad_sim | ||
| 59 | - sim["tmin"] = tstart | ||
| 60 | - sim["tmax"] = tstop | ||
| 61 | - sim["emin"] = emin | ||
| 62 | - sim["emax"] = emax | 60 | + sim['inmodel'] = model_name |
| 61 | + sim['caldb'] = caldb | ||
| 62 | + sim['irf'] = irf | ||
| 63 | + sim['ra'] = ra | ||
| 64 | + sim['dec'] = dec | ||
| 65 | + sim['rad'] = rad_sim | ||
| 66 | + sim['tmin'] = tstart | ||
| 67 | + sim['tmax'] = tstop | ||
| 68 | + sim['emin'] = emin | ||
| 69 | + sim['emax'] = emax | ||
| 63 | sim.run() | 70 | sim.run() |
| 64 | 71 | ||
| 65 | - # Generate an energy binning | ||
| 66 | - #e_min = gammalib.GEnergy(emin, "TeV") | ||
| 67 | - #e_max = gammalib.GEnergy(emax, "TeV") | ||
| 68 | - #ebounds = gammalib.GEbounds(10, e_min, e_max) | ||
| 69 | - | ||
| 70 | - # Setup csspec run | 72 | + # Create spectrum |
| 71 | spec = cscripts.csspec(sim.obs()) | 73 | spec = cscripts.csspec(sim.obs()) |
| 72 | - spec["srcname"] = "Crab" | ||
| 73 | - spec["outfile"] = "spectrum.fits" | ||
| 74 | - spec["expcube"] = "NONE" | ||
| 75 | - spec["psfcube"] = "NONE" | ||
| 76 | - spec["bkgcube"] = "NONE" | ||
| 77 | - spec["edisp"] = False | ||
| 78 | - spec["emin"] = emin | ||
| 79 | - spec["emax"] = emax | ||
| 80 | - spec["enumbins"] = enumbins | ||
| 81 | - spec["binned"] = False | 74 | + spec['srcname'] = 'Crab' |
| 75 | + spec['outfile'] = 'example_spectrum.fits' | ||
| 76 | + spec['expcube'] = 'NONE' | ||
| 77 | + spec['psfcube'] = 'NONE' | ||
| 78 | + spec['bkgcube'] = 'NONE' | ||
| 79 | + spec['edisp'] = False | ||
| 80 | + spec['emin'] = emin | ||
| 81 | + spec['emax'] = emax | ||
| 82 | + spec['enumbins'] = enumbins | ||
| 83 | + spec['ebinalg'] = 'LOG' | ||
| 82 | spec.run() | 84 | spec.run() |
| 85 | + spec.save() | ||
| 83 | 86 | ||
| 84 | # Get copy of spectrum | 87 | # Get copy of spectrum |
| 85 | spectrum = spec.spectrum().copy() | 88 | spectrum = spec.spectrum().copy() |
| @@ -91,19 +94,26 @@ def make_spectrum(): | @@ -91,19 +94,26 @@ def make_spectrum(): | ||
| 91 | # ============= # | 94 | # ============= # |
| 92 | # Plot spectrum # | 95 | # Plot spectrum # |
| 93 | # ============= # | 96 | # ============= # |
| 94 | -def plot_spectrum(spectrum): | 97 | +def plot_spectrum(spectrum, file=False): |
| 95 | """ | 98 | """ |
| 96 | - Plot spectrum. | 99 | + Plot spectrum |
| 100 | + | ||
| 101 | + Parameters | ||
| 102 | + ---------- | ||
| 103 | + spectrum : `~gammalib.GFits` | ||
| 104 | + Spectrum FITS file | ||
| 105 | + file : bool, optional | ||
| 106 | + Plot into a file | ||
| 97 | """ | 107 | """ |
| 98 | - # Read spectrum file | 108 | + # Extract columns from spectrum file |
| 99 | table = spectrum.table(1) | 109 | table = spectrum.table(1) |
| 100 | - c_energy = table["Energy"] | ||
| 101 | - c_ed = table["ed_Energy"] | ||
| 102 | - c_eu = table["eu_Energy"] | ||
| 103 | - c_flux = table["Flux"] | ||
| 104 | - c_eflux = table["e_Flux"] | ||
| 105 | - c_ts = table["TS"] | ||
| 106 | - c_upper = table["UpperLimit"] | 110 | + c_energy = table['Energy'] |
| 111 | + c_ed = table['ed_Energy'] | ||
| 112 | + c_eu = table['eu_Energy'] | ||
| 113 | + c_flux = table['Flux'] | ||
| 114 | + c_eflux = table['e_Flux'] | ||
| 115 | + c_ts = table['TS'] | ||
| 116 | + c_upper = table['UpperLimit'] | ||
| 107 | 117 | ||
| 108 | # Initialise arrays to be filled | 118 | # Initialise arrays to be filled |
| 109 | energies = [] | 119 | energies = [] |
| @@ -115,7 +125,7 @@ def plot_spectrum(spectrum): | @@ -115,7 +125,7 @@ def plot_spectrum(spectrum): | ||
| 115 | ul_ed_engs = [] | 125 | ul_ed_engs = [] |
| 116 | ul_eu_engs = [] | 126 | ul_eu_engs = [] |
| 117 | ul_flux = [] | 127 | ul_flux = [] |
| 118 | - | 128 | + |
| 119 | # Loop over rows of the file | 129 | # Loop over rows of the file |
| 120 | nrows = table.nrows() | 130 | nrows = table.nrows() |
| 121 | for row in range(nrows): | 131 | for row in range(nrows): |
| @@ -146,33 +156,43 @@ def plot_spectrum(spectrum): | @@ -146,33 +156,43 @@ def plot_spectrum(spectrum): | ||
| 146 | 156 | ||
| 147 | # Create figure | 157 | # Create figure |
| 148 | plt.figure() | 158 | plt.figure() |
| 149 | - plt.title("Crab spectrum") | 159 | + plt.title('Crab spectrum') |
| 150 | 160 | ||
| 151 | # Plot the spectrum | 161 | # Plot the spectrum |
| 152 | plt.loglog() | 162 | plt.loglog() |
| 153 | plt.grid() | 163 | plt.grid() |
| 154 | - plt.errorbar(energies, flux, yerr=e_flux, xerr=[ed_engs, eu_engs], fmt='ro') | ||
| 155 | - plt.errorbar(ul_energies, ul_flux, xerr=[ul_ed_engs, ul_eu_engs], yerr=1.0e-11, uplims=True, fmt='ro') | ||
| 156 | - plt.xlabel("Energy (TeV)") | ||
| 157 | - plt.ylabel(r"E$^{2}$dN/dE (erg cm$^{-2}$ s$^{-1}$)") | ||
| 158 | - | ||
| 159 | - # Show spectrum | ||
| 160 | - plt.show() | 164 | + plt.errorbar(energies, flux, yerr=e_flux, xerr=[ed_engs, eu_engs], |
| 165 | + fmt='ro') | ||
| 166 | + plt.errorbar(ul_energies, ul_flux, xerr=[ul_ed_engs, ul_eu_engs], | ||
| 167 | + yerr=1.0e-11, uplims=True, fmt='ro') | ||
| 168 | + plt.xlabel('Energy (TeV)') | ||
| 169 | + plt.ylabel(r'E$^{2}$dN/dE (erg cm$^{-2}$ s$^{-1}$)') | ||
| 170 | + | ||
| 171 | + # Show spectrum or save it into file | ||
| 172 | + if file: | ||
| 173 | + plt.savefig('example_spectrum.eps') | ||
| 174 | + else: | ||
| 175 | + plt.show() | ||
| 161 | 176 | ||
| 162 | # Return | 177 | # Return |
| 163 | return | 178 | return |
| 164 | 179 | ||
| 165 | 180 | ||
| 166 | -#==========================# | 181 | +# ======================== # |
| 167 | # Main routine entry point # | 182 | # Main routine entry point # |
| 168 | -#==========================# | 183 | +# ======================== # |
| 169 | if __name__ == '__main__': | 184 | if __name__ == '__main__': |
| 170 | - """ | ||
| 171 | - Generate a Crab spectrum. | ||
| 172 | - """ | 185 | + |
| 186 | + # Initialise option | ||
| 187 | + file = False | ||
| 188 | + | ||
| 189 | + # Get any command line arguments | ||
| 190 | + if (len(sys.argv) > 1): | ||
| 191 | + file = True | ||
| 192 | + | ||
| 173 | # Generate spectrum | 193 | # Generate spectrum |
| 174 | spectrum = make_spectrum() | 194 | spectrum = make_spectrum() |
| 175 | 195 | ||
| 176 | - # Plot spectrum | 196 | + # If matplotlib is installed then plot spectrum |
| 177 | if has_matplotlib: | 197 | if has_matplotlib: |
| 178 | - plot_spectrum(spectrum) | 198 | + plot_spectrum(spectrum, file=file) |
examples/make_ts_distributions.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script generates TS distributions for the standard energy bands that | ||
| 4 | -# are also used for sensitivity computation. The script makes use of the | ||
| 5 | -# "processing" Python module, if available, that can be used for parallel | ||
| 6 | -# computing on multiple cores/CPUs. | 3 | +# Generate TS distributions as function of energy for an OFF observation |
| 7 | # | 4 | # |
| 8 | -# This script provides an illustration of how a ctools or cscript can be | ||
| 9 | -# used from within Python. It further illustrates the possibility of | ||
| 10 | -# parallel computing using the "processing" Python module. | ||
| 11 | -# | ||
| 12 | -# Required 3rd party modules: | ||
| 13 | -# - processing (optional) | ||
| 14 | -# | ||
| 15 | -# Copyright (C) 2011-2015 Jurgen Knodlseder | 5 | +# Copyright (C) 2011-2016 Jurgen Knodlseder |
| 16 | # | 6 | # |
| 17 | # 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 |
| 18 | # 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,15 +20,14 @@ | @@ -30,15 +20,14 @@ | ||
| 30 | # ========================================================================== | 20 | # ========================================================================== |
| 31 | import sys | 21 | import sys |
| 32 | import time | 22 | import time |
| 33 | -from cscripts import cstsdist | 23 | +import cscripts |
| 34 | 24 | ||
| 35 | -# Try importing processing module | ||
| 36 | -has_processing = False | 25 | +# Optionally import processing module |
| 37 | try: | 26 | try: |
| 38 | import processing | 27 | import processing |
| 39 | has_processing = True | 28 | has_processing = True |
| 40 | except: | 29 | except: |
| 41 | - pass | 30 | + has_processing = False |
| 42 | 31 | ||
| 43 | 32 | ||
| 44 | # ====================== # | 33 | # ====================== # |
| @@ -49,35 +38,44 @@ def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, | @@ -49,35 +38,44 @@ def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, | ||
| 49 | """ | 38 | """ |
| 50 | Create TS distribution. | 39 | Create TS distribution. |
| 51 | 40 | ||
| 52 | - Parameters: | ||
| 53 | - loge - Logarithm of mean energy in TeV | ||
| 54 | - emin - Minimum energy (TeV) | ||
| 55 | - emax - Maximum energy (TeV) | ||
| 56 | - Keywords: | ||
| 57 | - log - Create log file(s) | 41 | + Parameters |
| 42 | + ---------- | ||
| 43 | + loge : float | ||
| 44 | + Logarithm of mean energy (TeV) | ||
| 45 | + emin : float | ||
| 46 | + Minimum energy (TeV) | ||
| 47 | + emax : float | ||
| 48 | + Maximum energy (TeV) | ||
| 49 | + ntrials : int, optional | ||
| 50 | + Number of MC samples | ||
| 51 | + durations : float, optional | ||
| 52 | + Observation duration (s) | ||
| 53 | + enumbins : int, optional | ||
| 54 | + Number of energy bins | ||
| 55 | + log : bool, optional | ||
| 56 | + Create log file(s) | ||
| 58 | """ | 57 | """ |
| 59 | # Generate output filename | 58 | # Generate output filename |
| 60 | - outfile = "ts_"+str(loge)+".dat" | 59 | + outfile = 'ts_'+str(loge)+'.dat' |
| 61 | 60 | ||
| 62 | # Setup cstsdist tool | 61 | # Setup cstsdist tool |
| 63 | - tsdist = cstsdist() | ||
| 64 | - tsdist["inmodel"] = "$CTOOLS/share/models/crab.xml" | ||
| 65 | - tsdist["srcname"] = "Crab" | ||
| 66 | - tsdist["outfile"] = outfile | ||
| 67 | - tsdist["ntrials"] = ntrials | ||
| 68 | - tsdist["caldb"] = "prod2" | ||
| 69 | - tsdist["irf"] = "South_50h" | ||
| 70 | - tsdist["ra"] = 83.63 | ||
| 71 | - tsdist["dec"] = 22.01 | ||
| 72 | - tsdist["emin"] = emin | ||
| 73 | - tsdist["emax"] = emax | ||
| 74 | - tsdist["enumbins"] = enumbins | ||
| 75 | - tsdist["tmin"] = 0 | ||
| 76 | - tsdist["tmax"] = duration | ||
| 77 | - tsdist["rad"] = 5.0 | ||
| 78 | - tsdist["npix"] = 200 | ||
| 79 | - tsdist["binsz"] = 0.05 | ||
| 80 | - #tsdist["debug"].boolean(True) | 62 | + tsdist = cscripts.cstsdist() |
| 63 | + tsdist['inmodel'] = 'data/crab.xml' | ||
| 64 | + tsdist['srcname'] = 'Crab' | ||
| 65 | + tsdist['outfile'] = outfile | ||
| 66 | + tsdist['ntrials'] = ntrials | ||
| 67 | + tsdist['caldb'] = 'prod2' | ||
| 68 | + tsdist['irf'] = 'South_50h' | ||
| 69 | + tsdist['ra'] = 83.63 | ||
| 70 | + tsdist['dec'] = 22.01 | ||
| 71 | + tsdist['emin'] = emin | ||
| 72 | + tsdist['emax'] = emax | ||
| 73 | + tsdist['enumbins'] = enumbins | ||
| 74 | + tsdist['tmin'] = 0 | ||
| 75 | + tsdist['tmax'] = duration | ||
| 76 | + tsdist['rad'] = 5.0 | ||
| 77 | + tsdist['npix'] = 200 | ||
| 78 | + tsdist['binsz'] = 0.05 | ||
| 81 | 79 | ||
| 82 | # Optionally open the log file | 80 | # Optionally open the log file |
| 83 | if log: | 81 | if log: |
| @@ -94,11 +92,9 @@ def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, | @@ -94,11 +92,9 @@ def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, | ||
| 94 | # Main routine entry point # | 92 | # Main routine entry point # |
| 95 | # ======================== # | 93 | # ======================== # |
| 96 | if __name__ == '__main__': | 94 | if __name__ == '__main__': |
| 97 | - """ | ||
| 98 | - Create TS distribution in a number of energy bands. | ||
| 99 | - """ | 95 | + |
| 100 | # Get input arguments | 96 | # Get input arguments |
| 101 | - usage = "make_ts_distributions [-n ntrials] [-e enumbins] [-m max_threads]" | 97 | + usage = 'make_ts_distributions.py [-n ntrials] [-e enumbins] [-m max_threads]' |
| 102 | if len(sys.argv) < 1: | 98 | if len(sys.argv) < 1: |
| 103 | print(usage) | 99 | print(usage) |
| 104 | sys.exit() | 100 | sys.exit() |
| @@ -113,7 +109,7 @@ if __name__ == '__main__': | @@ -113,7 +109,7 @@ if __name__ == '__main__': | ||
| 113 | pars = [{'option': '-n', 'value': ntrials}, | 109 | pars = [{'option': '-n', 'value': ntrials}, |
| 114 | {'option': '-e', 'value': enumbins}, | 110 | {'option': '-e', 'value': enumbins}, |
| 115 | {'option': '-d', 'value': duration}, | 111 | {'option': '-d', 'value': duration}, |
| 116 | - {'option': '-m', 'value': max_threads}] | 112 | + {'option': '-m', 'value': max_threads}] |
| 117 | 113 | ||
| 118 | # Gather parameters from command line | 114 | # Gather parameters from command line |
| 119 | i = 1 | 115 | i = 1 |
| @@ -123,7 +119,7 @@ if __name__ == '__main__': | @@ -123,7 +119,7 @@ if __name__ == '__main__': | ||
| 123 | for par in pars: | 119 | for par in pars: |
| 124 | if sys.argv[i] == par['option']: | 120 | if sys.argv[i] == par['option']: |
| 125 | if len(sys.argv) > i+1: | 121 | if len(sys.argv) > i+1: |
| 126 | - i += 1 | 122 | + i += 1 |
| 127 | try: | 123 | try: |
| 128 | par['value'] = int(sys.argv[i]) | 124 | par['value'] = int(sys.argv[i]) |
| 129 | except: | 125 | except: |
| @@ -152,11 +148,12 @@ if __name__ == '__main__': | @@ -152,11 +148,12 @@ if __name__ == '__main__': | ||
| 152 | emin = pow(10.0, loge-0.1) | 148 | emin = pow(10.0, loge-0.1) |
| 153 | emax = pow(10.0, loge+0.1) | 149 | emax = pow(10.0, loge+0.1) |
| 154 | if loge < 0: | 150 | if loge < 0: |
| 155 | - loge = "m"+str(abs(loge)) | 151 | + loge = 'm'+str(abs(loge)) |
| 156 | else: | 152 | else: |
| 157 | - loge = "p"+str(abs(loge)) | 153 | + loge = 'p'+str(abs(loge)) |
| 158 | 154 | ||
| 159 | - # Processing support? | 155 | + # If processing support is available then start max_threads processes |
| 156 | + # in parallel | ||
| 160 | if has_processing: | 157 | if has_processing: |
| 161 | 158 | ||
| 162 | # Wait until one thread has finished | 159 | # Wait until one thread has finished |
| @@ -171,19 +168,17 @@ if __name__ == '__main__': | @@ -171,19 +168,17 @@ if __name__ == '__main__': | ||
| 171 | # Generate pull distribution | 168 | # Generate pull distribution |
| 172 | p = processing.Process(target=create_ts, args=args, kwargs=kwargs) | 169 | p = processing.Process(target=create_ts, args=args, kwargs=kwargs) |
| 173 | p.start() | 170 | p.start() |
| 174 | - print("Process emin=%.4f emax=%.4f started." % (emin, emax)) | 171 | + print('Process emin=%.4f emax=%.4f started.' % (emin, emax)) |
| 175 | 172 | ||
| 176 | # Wait a short time to allow process to start | 173 | # Wait a short time to allow process to start |
| 177 | time.sleep(1) | 174 | time.sleep(1) |
| 178 | 175 | ||
| 179 | - # ... no | 176 | + # ... otherwise simply start a single process |
| 180 | else: | 177 | else: |
| 181 | create_ts(loge, emin, emax, ntrials=ntrials, enumbins=enumbins, | 178 | create_ts(loge, emin, emax, ntrials=ntrials, enumbins=enumbins, |
| 182 | - duration=duration) | 179 | + duration=duration) |
| 183 | 180 | ||
| 184 | - # Processing support | 181 | + # If processing support is available then wait until all threads finished |
| 185 | if has_processing: | 182 | if has_processing: |
| 186 | - | ||
| 187 | - # Wait until all threads finished | ||
| 188 | while len(processing.activeChildren()) > 0: | 183 | while len(processing.activeChildren()) > 0: |
| 189 | time.sleep(10) | 184 | time.sleep(10) |
examples/pipeline_binned_disk.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script illustrates how to perform a binned CTA analysis based on | ||
| 4 | -# simulated CTA data. You may use and adapt this script to implement your | ||
| 5 | -# own pipeline. | 3 | +# Perform binned analysis of simulated CTA data. |
| 6 | # | 4 | # |
| 7 | -# Usage: | ||
| 8 | -# ./pipeline_binned_disk.py | ||
| 9 | -# | ||
| 10 | -# ========================================================================== | ||
| 11 | -# | ||
| 12 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 13 | # | 6 | # |
| 14 | # 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 |
| 15 | # 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 |
| @@ -33,25 +26,41 @@ from cscripts import obsutils | @@ -33,25 +26,41 @@ from cscripts import obsutils | ||
| 33 | # ================== # | 26 | # ================== # |
| 34 | # Setup observations # | 27 | # Setup observations # |
| 35 | # ================== # | 28 | # ================== # |
| 36 | -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 37 | - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, | ||
| 38 | - deadc=0.95, | ||
| 39 | - caldb="prod2", irf="South_50h"): | 29 | +def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, |
| 30 | + emin=0.1, emax=100.0, rad=5.0, duration=180.0, | ||
| 31 | + deadc=0.95, caldb='prod2', irf='South_0.5h'): | ||
| 40 | """ | 32 | """ |
| 41 | - Returns an observation container. | ||
| 42 | - | ||
| 43 | - Keywords: | ||
| 44 | - pattern - Pointing pattern, either "single" or "four" | ||
| 45 | - ra - RA of pattern centre [deg] (default: 83.6331) | ||
| 46 | - dec - DEC of pattern centre [deg] (default: 22.0145) | ||
| 47 | - offset - Offset between observations of pattern [deg] (default: 1.5) | ||
| 48 | - emin - Minimum energy [TeV] (default: 0.1) | ||
| 49 | - emax - Maximum energy [TeV] (default: 100.0) | ||
| 50 | - rad - ROI radius used for analysis [deg] (default: 5.0) | ||
| 51 | - duration - Duration of one CTA observation [seconds] (default: 1800.0) | ||
| 52 | - deadc - Deadtime correction factor (default: 0.95) | ||
| 53 | - caldb - Calibration database path (default: "dummy") | ||
| 54 | - irf - Instrument response function (default: cta_dummy_irf) | 33 | + Returns an observation container |
| 34 | + | ||
| 35 | + Parameters | ||
| 36 | + ---------- | ||
| 37 | + pattern : str, optional | ||
| 38 | + Pointing pattern, either 'single' or 'four' | ||
| 39 | + ra : float, optional | ||
| 40 | + Right Ascension of pattern centre (deg) | ||
| 41 | + dec : float, optional | ||
| 42 | + Declination of pattern centre (deg) | ||
| 43 | + offset : float, optional | ||
| 44 | + Offset between observations of pattern (deg) | ||
| 45 | + emin : float, optional | ||
| 46 | + Minimum energy (TeV) | ||
| 47 | + emax : float, optional | ||
| 48 | + Maximum energy (TeV) | ||
| 49 | + rad : float, optional | ||
| 50 | + ROI radius used for analysis (deg) | ||
| 51 | + duration : float, optional | ||
| 52 | + Duration of one CTA observation (s) | ||
| 53 | + deadc : float, optional | ||
| 54 | + Deadtime correction factor | ||
| 55 | + caldb : str, optional | ||
| 56 | + Calibration database path | ||
| 57 | + irf : str, optional | ||
| 58 | + Instrument response function | ||
| 59 | + | ||
| 60 | + Returns | ||
| 61 | + ------- | ||
| 62 | + obs : `~gammalib.GObservations` | ||
| 63 | + Observation container | ||
| 55 | """ | 64 | """ |
| 56 | # Set list of observations | 65 | # Set list of observations |
| 57 | obs_def_list = obsutils.set_obs_patterns(pattern, | 66 | obs_def_list = obsutils.set_obs_patterns(pattern, |
| @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 75 | # =========== # | 84 | # =========== # |
| 76 | # Setup model # | 85 | # Setup model # |
| 77 | # =========== # | 86 | # =========== # |
| 78 | -def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | 87 | +def setup_model(obs, model='data/crab.xml'): |
| 79 | """ | 88 | """ |
| 80 | - Setup model for analysis. | ||
| 81 | - | ||
| 82 | - Keywords: | ||
| 83 | - model - Model Xml file | 89 | + Setup model for analysis |
| 90 | + | ||
| 91 | + Parameters | ||
| 92 | + ---------- | ||
| 93 | + obs : `~gammalib.GObservations` | ||
| 94 | + Observation container | ||
| 95 | + model : str, optional | ||
| 96 | + Model definition XML file | ||
| 97 | + | ||
| 98 | + Returns | ||
| 99 | + ------- | ||
| 100 | + obs : `~gammalib.GObservations` | ||
| 101 | + Observation container | ||
| 84 | """ | 102 | """ |
| 85 | # Append model from file to observation container | 103 | # Append model from file to observation container |
| 86 | obs.models(gammalib.GModels(model)) | 104 | obs.models(gammalib.GModels(model)) |
| @@ -94,56 +112,71 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | @@ -94,56 +112,71 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | ||
| 94 | # ================================ # | 112 | # ================================ # |
| 95 | def run_pipeline(obs, emin=0.1, emax=100.0, | 113 | def run_pipeline(obs, emin=0.1, emax=100.0, |
| 96 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, | 114 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, |
| 97 | - coordsys="CEL", proj="CAR", | ||
| 98 | - model="${CTOOLS}/share/models/crab.xml", | ||
| 99 | - caldb="prod2", irf="South_50h", | 115 | + coordsys='CEL', proj='CAR', |
| 116 | + model='data/crab.xml', | ||
| 117 | + caldb='prod2', irf='South_0.5h', | ||
| 100 | debug=False): | 118 | debug=False): |
| 101 | """ | 119 | """ |
| 102 | - Simulation and binned analysis pipeline. | ||
| 103 | - | ||
| 104 | - Keywords: | ||
| 105 | - emin - Minimum energy of cube [TeV] (default: 0.1) | ||
| 106 | - emax - Maximum energy of cube [TeV] (default: 100.0) | ||
| 107 | - enumbins - Number of energy bins in cube (default: 20) | ||
| 108 | - nxpix - Number of RA pixels in cube (default: 200) | ||
| 109 | - nypix - Number of DEC pixels in cube (default: 200) | ||
| 110 | - binsz - Spatial cube bin size [deg] (default: 0.02) | ||
| 111 | - coordsys - Cube coordinate system (CEL or GAL) | ||
| 112 | - proj - Cube World Coordinate System (WCS) projection | ||
| 113 | - model - Model Xml file | ||
| 114 | - caldb - Calibration database path (default: "dummy") | ||
| 115 | - irf - Instrument response function (default: cta_dummy_irf) | ||
| 116 | - debug - Enable debugging (default: False) | 120 | + Simulation and binned analysis pipeline |
| 121 | + | ||
| 122 | + Parameters | ||
| 123 | + ---------- | ||
| 124 | + obs : `~gammalib.GObservations` | ||
| 125 | + Observation container | ||
| 126 | + emin : float, optional | ||
| 127 | + Minimum energy (TeV) | ||
| 128 | + emax : float, optional | ||
| 129 | + Maximum energy (TeV) | ||
| 130 | + enumbins : int, optional | ||
| 131 | + Number of energy bins | ||
| 132 | + nxpix : int, optional | ||
| 133 | + Number of pixels in X axis | ||
| 134 | + nypix : int, optional | ||
| 135 | + Number of pixels in Y axis | ||
| 136 | + binsz : float, optional | ||
| 137 | + Pixel size (deg) | ||
| 138 | + coordsys : str, optional | ||
| 139 | + Coordinate system | ||
| 140 | + proj : str, optional | ||
| 141 | + Coordinate projection | ||
| 142 | + model : str, optional | ||
| 143 | + Model definition XML file | ||
| 144 | + caldb : str, optional | ||
| 145 | + Calibration database path | ||
| 146 | + irf : str, optional | ||
| 147 | + Instrument response function | ||
| 148 | + debug : bool, optional | ||
| 149 | + Debug function | ||
| 117 | """ | 150 | """ |
| 118 | # Simulate events | 151 | # Simulate events |
| 119 | sim = ctools.ctobssim(obs) | 152 | sim = ctools.ctobssim(obs) |
| 120 | - sim["debug"] = debug | ||
| 121 | - sim["outevents"] = "obs.xml" | 153 | + sim['debug'] = debug |
| 154 | + sim['outevents'] = 'obs.xml' | ||
| 122 | sim.execute() | 155 | sim.execute() |
| 123 | 156 | ||
| 124 | # Bin events by looping over all observations in the container | 157 | # Bin events by looping over all observations in the container |
| 125 | - sim_obs = gammalib.GObservations("obs.xml") | 158 | + sim_obs = gammalib.GObservations('obs.xml') |
| 126 | obs = gammalib.GObservations() | 159 | obs = gammalib.GObservations() |
| 127 | for run in sim_obs: | 160 | for run in sim_obs: |
| 128 | 161 | ||
| 129 | # Get event filename and set counts cube filename | 162 | # Get event filename and set counts cube filename |
| 130 | - eventfile = run.eventfile() | ||
| 131 | - cubefile = "cube_"+eventfile | 163 | + eventfile = run.eventfile().url() |
| 164 | + cubefile = 'cube_'+eventfile | ||
| 132 | 165 | ||
| 133 | # Bin events for that observation | 166 | # Bin events for that observation |
| 134 | bin = ctools.ctbin() | 167 | bin = ctools.ctbin() |
| 135 | - bin["inobs"] = eventfile | ||
| 136 | - bin["outcube"] = cubefile | ||
| 137 | - bin["ebinalg"] = "LOG" | ||
| 138 | - bin["emin"] = emin | ||
| 139 | - bin["emax"] = emax | ||
| 140 | - bin["enumbins"] = enumbins | ||
| 141 | - bin["nxpix"] = nxpix | ||
| 142 | - bin["nypix"] = nypix | ||
| 143 | - bin["binsz"] = binsz | ||
| 144 | - bin["coordsys"] = coordsys | ||
| 145 | - bin["usepnt"] = True | ||
| 146 | - bin["proj"] = proj | 168 | + bin['inobs'] = eventfile |
| 169 | + bin['outcube'] = cubefile | ||
| 170 | + bin['ebinalg'] = 'LOG' | ||
| 171 | + bin['emin'] = emin | ||
| 172 | + bin['emax'] = emax | ||
| 173 | + bin['enumbins'] = enumbins | ||
| 174 | + bin['nxpix'] = nxpix | ||
| 175 | + bin['nypix'] = nypix | ||
| 176 | + bin['binsz'] = binsz | ||
| 177 | + bin['coordsys'] = coordsys | ||
| 178 | + bin['usepnt'] = True | ||
| 179 | + bin['proj'] = proj | ||
| 147 | bin.execute() | 180 | bin.execute() |
| 148 | 181 | ||
| 149 | # Set observation ID | 182 | # Set observation ID |
| @@ -156,19 +189,19 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | @@ -156,19 +189,19 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | ||
| 156 | # Save XML file | 189 | # Save XML file |
| 157 | xml = gammalib.GXml() | 190 | xml = gammalib.GXml() |
| 158 | obs.write(xml) | 191 | obs.write(xml) |
| 159 | - xml.save("obs_cube.xml") | 192 | + xml.save('obs_cube.xml') |
| 160 | 193 | ||
| 161 | # Perform maximum likelihood fitting | 194 | # Perform maximum likelihood fitting |
| 162 | like = ctools.ctlike() | 195 | like = ctools.ctlike() |
| 163 | - like["inobs"] = "obs_cube.xml" | ||
| 164 | - like["inmodel"] = model | ||
| 165 | - like["outmodel"] = "fit_results.xml" | ||
| 166 | - like["expcube"] = "NONE" | ||
| 167 | - like["psfcube"] = "NONE" | ||
| 168 | - like["bkgcube"] = "NONE" | ||
| 169 | - like["caldb"] = caldb | ||
| 170 | - like["irf"] = irf | ||
| 171 | - like["debug"] = True # Switch this always on for results in console | 196 | + like['inobs'] = 'obs_cube.xml' |
| 197 | + like['inmodel'] = model | ||
| 198 | + like['outmodel'] = 'fit_results.xml' | ||
| 199 | + like['expcube'] = 'NONE' | ||
| 200 | + like['psfcube'] = 'NONE' | ||
| 201 | + like['bkgcube'] = 'NONE' | ||
| 202 | + like['caldb'] = caldb | ||
| 203 | + like['irf'] = irf | ||
| 204 | + like['debug'] = True # Switch this always on for results in console | ||
| 172 | like.execute() | 205 | like.execute() |
| 173 | 206 | ||
| 174 | # Return | 207 | # Return |
| @@ -179,12 +212,11 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | @@ -179,12 +212,11 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | ||
| 179 | # Main routine entry point # | 212 | # Main routine entry point # |
| 180 | # ======================== # | 213 | # ======================== # |
| 181 | if __name__ == '__main__': | 214 | if __name__ == '__main__': |
| 182 | - """ | ||
| 183 | - """ | 215 | + |
| 184 | # Dump header | 216 | # Dump header |
| 185 | - print("********************************************") | ||
| 186 | - print("* CTA binned analysis pipeline *") | ||
| 187 | - print("********************************************") | 217 | + print('********************************************') |
| 218 | + print('* CTA binned analysis pipeline *') | ||
| 219 | + print('********************************************') | ||
| 188 | 220 | ||
| 189 | # Setup observations | 221 | # Setup observations |
| 190 | obs = setup_observations() | 222 | obs = setup_observations() |
examples/pipeline_binned_mem.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script illustrates how to perform a binned CTA analysis based on | ||
| 4 | -# simulated CTA data. You may use and adapt this script to implement your | ||
| 5 | -# own pipeline. | 3 | +# Perform binned in-memory analysis of simulated CTA data. |
| 6 | # | 4 | # |
| 7 | -# Usage: | ||
| 8 | -# ./pipeline_binned_mem.py | ||
| 9 | -# | ||
| 10 | -# ========================================================================== | ||
| 11 | -# | ||
| 12 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 13 | # | 6 | # |
| 14 | # 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 |
| 15 | # 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 |
| @@ -33,25 +26,41 @@ from cscripts import obsutils | @@ -33,25 +26,41 @@ from cscripts import obsutils | ||
| 33 | # ================== # | 26 | # ================== # |
| 34 | # Setup observations # | 27 | # Setup observations # |
| 35 | # ================== # | 28 | # ================== # |
| 36 | -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 37 | - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, | ||
| 38 | - deadc=0.95, | ||
| 39 | - caldb="prod2", irf="South_50h"): | 29 | +def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, |
| 30 | + emin=0.1, emax=100.0, rad=5.0, duration=180.0, | ||
| 31 | + deadc=0.95, caldb='prod2', irf='South_0.5h'): | ||
| 40 | """ | 32 | """ |
| 41 | - Returns an observation container. | ||
| 42 | - | ||
| 43 | - Keywords: | ||
| 44 | - pattern - Pointing pattern, either "single" or "four" | ||
| 45 | - ra - RA of pattern centre [deg] (default: 83.6331) | ||
| 46 | - dec - DEC of pattern centre [deg] (default: 22.0145) | ||
| 47 | - offset - Offset between observations of pattern [deg] (default: 1.5) | ||
| 48 | - emin - Minimum energy [TeV] (default: 0.1) | ||
| 49 | - emax - Maximum energy [TeV] (default: 100.0) | ||
| 50 | - rad - ROI radius used for analysis [deg] (default: 5.0) | ||
| 51 | - duration - Duration of one CTA observation [seconds] (default: 1800.0) | ||
| 52 | - deadc - Deadtime correction factor (default: 0.95) | ||
| 53 | - caldb - Calibration database path (default: "dummy") | ||
| 54 | - irf - Instrument response function (default: cta_dummy_irf) | 33 | + Returns an observation container |
| 34 | + | ||
| 35 | + Parameters | ||
| 36 | + ---------- | ||
| 37 | + pattern : str, optional | ||
| 38 | + Pointing pattern, either 'single' or 'four' | ||
| 39 | + ra : float, optional | ||
| 40 | + Right Ascension of pattern centre (deg) | ||
| 41 | + dec : float, optional | ||
| 42 | + Declination of pattern centre (deg) | ||
| 43 | + offset : float, optional | ||
| 44 | + Offset between observations of pattern (deg) | ||
| 45 | + emin : float, optional | ||
| 46 | + Minimum energy (TeV) | ||
| 47 | + emax : float, optional | ||
| 48 | + Maximum energy (TeV) | ||
| 49 | + rad : float, optional | ||
| 50 | + ROI radius used for analysis (deg) | ||
| 51 | + duration : float, optional | ||
| 52 | + Duration of one CTA observation (s) | ||
| 53 | + deadc : float, optional | ||
| 54 | + Deadtime correction factor | ||
| 55 | + caldb : str, optional | ||
| 56 | + Calibration database path | ||
| 57 | + irf : str, optional | ||
| 58 | + Instrument response function | ||
| 59 | + | ||
| 60 | + Returns | ||
| 61 | + ------- | ||
| 62 | + obs : `~gammalib.GObservations` | ||
| 63 | + Observation container | ||
| 55 | """ | 64 | """ |
| 56 | # Set list of observations | 65 | # Set list of observations |
| 57 | obs_def_list = obsutils.set_obs_patterns(pattern, | 66 | obs_def_list = obsutils.set_obs_patterns(pattern, |
| @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 75 | # =========== # | 84 | # =========== # |
| 76 | # Setup model # | 85 | # Setup model # |
| 77 | # =========== # | 86 | # =========== # |
| 78 | -def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | 87 | +def setup_model(obs, model='data/crab.xml'): |
| 79 | """ | 88 | """ |
| 80 | - Setup model for analysis. | ||
| 81 | - | ||
| 82 | - Keywords: | ||
| 83 | - model - Model Xml file | 89 | + Setup model for analysis |
| 90 | + | ||
| 91 | + Parameters | ||
| 92 | + ---------- | ||
| 93 | + obs : `~gammalib.GObservations` | ||
| 94 | + Observation container | ||
| 95 | + model : str, optional | ||
| 96 | + Model definition XML file | ||
| 97 | + | ||
| 98 | + Returns | ||
| 99 | + ------- | ||
| 100 | + obs : `~gammalib.GObservations` | ||
| 101 | + Observation container | ||
| 84 | """ | 102 | """ |
| 85 | # Append model from file to observation container | 103 | # Append model from file to observation container |
| 86 | obs.models(gammalib.GModels(model)) | 104 | obs.models(gammalib.GModels(model)) |
| @@ -94,24 +112,36 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | @@ -94,24 +112,36 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | ||
| 94 | # ================================ # | 112 | # ================================ # |
| 95 | def run_pipeline(obs, emin=0.1, emax=100.0, | 113 | def run_pipeline(obs, emin=0.1, emax=100.0, |
| 96 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, | 114 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, |
| 97 | - coordsys="CEL", proj="CAR", debug=False): | 115 | + coordsys='CEL', proj='CAR', debug=False): |
| 98 | """ | 116 | """ |
| 99 | - Simulation and binned analysis pipeline. | ||
| 100 | - | ||
| 101 | - Keywords: | ||
| 102 | - emin - Minimum energy of cube [TeV] (default: 0.1) | ||
| 103 | - emax - Maximum energy of cube [TeV] (default: 100.0) | ||
| 104 | - enumbins - Number of energy bins in cube (default: 20) | ||
| 105 | - nxpix - Number of RA pixels in cube (default: 200) | ||
| 106 | - nypix - Number of DEC pixels in cube (default: 200) | ||
| 107 | - binsz - Spatial cube bin size [deg] (default: 0.02) | ||
| 108 | - coordsys - Cube coordinate system (CEL or GAL) | ||
| 109 | - proj - Cube World Coordinate System (WCS) projection | ||
| 110 | - debug - Enable debugging (default: False) | 117 | + Simulation and binned analysis pipeline |
| 118 | + | ||
| 119 | + Parameters | ||
| 120 | + ---------- | ||
| 121 | + obs : `~gammalib.GObservations` | ||
| 122 | + Observation container | ||
| 123 | + emin : float, optional | ||
| 124 | + Minimum energy (TeV) | ||
| 125 | + emax : float, optional | ||
| 126 | + Maximum energy (TeV) | ||
| 127 | + enumbins : int, optional | ||
| 128 | + Number of energy bins | ||
| 129 | + nxpix : int, optional | ||
| 130 | + Number of pixels in X axis | ||
| 131 | + nypix : int, optional | ||
| 132 | + Number of pixels in Y axis | ||
| 133 | + binsz : float, optional | ||
| 134 | + Pixel size (deg) | ||
| 135 | + coordsys : str, optional | ||
| 136 | + Coordinate system | ||
| 137 | + proj : str, optional | ||
| 138 | + Coordinate projection | ||
| 139 | + debug : bool, optional | ||
| 140 | + Debug function | ||
| 111 | """ | 141 | """ |
| 112 | # Simulate events | 142 | # Simulate events |
| 113 | sim = ctools.ctobssim(obs) | 143 | sim = ctools.ctobssim(obs) |
| 114 | - sim["debug"] = debug | 144 | + sim['debug'] = debug |
| 115 | sim.run() | 145 | sim.run() |
| 116 | 146 | ||
| 117 | # Bin events by looping over all observations in the container | 147 | # Bin events by looping over all observations in the container |
| @@ -125,16 +155,16 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | @@ -125,16 +155,16 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | ||
| 125 | 155 | ||
| 126 | # Bin events for that observation | 156 | # Bin events for that observation |
| 127 | bin = ctools.ctbin(container) | 157 | bin = ctools.ctbin(container) |
| 128 | - bin["ebinalg"] = "LOG" | ||
| 129 | - bin["emin"] = emin | ||
| 130 | - bin["emax"] = emax | ||
| 131 | - bin["enumbins"] = enumbins | ||
| 132 | - bin["nxpix"] = nxpix | ||
| 133 | - bin["nypix"] = nypix | ||
| 134 | - bin["binsz"] = binsz | ||
| 135 | - bin["coordsys"] = coordsys | ||
| 136 | - bin["usepnt"] = True | ||
| 137 | - bin["proj"] = proj | 158 | + bin['ebinalg'] = 'LOG' |
| 159 | + bin['emin'] = emin | ||
| 160 | + bin['emax'] = emax | ||
| 161 | + bin['enumbins'] = enumbins | ||
| 162 | + bin['nxpix'] = nxpix | ||
| 163 | + bin['nypix'] = nypix | ||
| 164 | + bin['binsz'] = binsz | ||
| 165 | + bin['coordsys'] = coordsys | ||
| 166 | + bin['usepnt'] = True | ||
| 167 | + bin['proj'] = proj | ||
| 138 | bin.run() | 168 | bin.run() |
| 139 | 169 | ||
| 140 | # Append result to observations | 170 | # Append result to observations |
| @@ -142,7 +172,7 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | @@ -142,7 +172,7 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | ||
| 142 | 172 | ||
| 143 | # Perform maximum likelihood fitting | 173 | # Perform maximum likelihood fitting |
| 144 | like = ctools.ctlike(obs) | 174 | like = ctools.ctlike(obs) |
| 145 | - like["debug"] = True # Switch this always on for results in console | 175 | + like['debug'] = True # Switch this always on for results in console |
| 146 | like.run() | 176 | like.run() |
| 147 | 177 | ||
| 148 | # Return | 178 | # Return |
| @@ -153,12 +183,11 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | @@ -153,12 +183,11 @@ def run_pipeline(obs, emin=0.1, emax=100.0, | ||
| 153 | # Main routine entry point # | 183 | # Main routine entry point # |
| 154 | # ======================== # | 184 | # ======================== # |
| 155 | if __name__ == '__main__': | 185 | if __name__ == '__main__': |
| 156 | - """ | ||
| 157 | - """ | 186 | + |
| 158 | # Dump header | 187 | # Dump header |
| 159 | - print("********************************************") | ||
| 160 | - print("* CTA binned analysis pipeline *") | ||
| 161 | - print("********************************************") | 188 | + print('********************************************') |
| 189 | + print('* CTA binned analysis pipeline *') | ||
| 190 | + print('********************************************') | ||
| 162 | 191 | ||
| 163 | # Setup observations | 192 | # Setup observations |
| 164 | obs = setup_observations() | 193 | obs = setup_observations() |
examples/pipeline_stacked_disk.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script illustrates how to perform a stacked CTA analysis based on | ||
| 4 | -# simulated CTA data. You may use and adapt this script to implement your | ||
| 5 | -# own pipeline. | 3 | +# Perform stacked analysis of simulated CTA data. |
| 6 | # | 4 | # |
| 7 | -# Usage: | ||
| 8 | -# ./pipeline_stacked_disk.py | ||
| 9 | -# | ||
| 10 | -# ========================================================================== | ||
| 11 | -# | ||
| 12 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 13 | # | 6 | # |
| 14 | # 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 |
| 15 | # 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 |
| @@ -33,25 +26,41 @@ from cscripts import obsutils | @@ -33,25 +26,41 @@ from cscripts import obsutils | ||
| 33 | # ================== # | 26 | # ================== # |
| 34 | # Setup observations # | 27 | # Setup observations # |
| 35 | # ================== # | 28 | # ================== # |
| 36 | -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 37 | - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, | ||
| 38 | - deadc=0.95, | ||
| 39 | - caldb="prod2", irf="South_50h"): | 29 | +def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, |
| 30 | + emin=0.1, emax=100.0, rad=5.0, duration=180.0, | ||
| 31 | + deadc=0.95, caldb='prod2', irf='South_0.5h'): | ||
| 40 | """ | 32 | """ |
| 41 | - Returns an observation container. | ||
| 42 | - | ||
| 43 | - Keywords: | ||
| 44 | - pattern - Pointing pattern, either "single" or "four" | ||
| 45 | - ra - RA of pattern centre [deg] (default: 83.6331) | ||
| 46 | - dec - DEC of pattern centre [deg] (default: 22.0145) | ||
| 47 | - offset - Offset between observations of pattern [deg] (default: 1.5) | ||
| 48 | - emin - Minimum energy [TeV] (default: 0.1) | ||
| 49 | - emax - Maximum energy [TeV] (default: 100.0) | ||
| 50 | - rad - ROI radius used for analysis [deg] (default: 5.0) | ||
| 51 | - duration - Duration of one CTA observation [seconds] (default: 1800.0) | ||
| 52 | - deadc - Deadtime correction factor (default: 0.95) | ||
| 53 | - caldb - Calibration database path (default: "dummy") | ||
| 54 | - irf - Instrument response function (default: cta_dummy_irf) | 33 | + Returns an observation container |
| 34 | + | ||
| 35 | + Parameters | ||
| 36 | + ---------- | ||
| 37 | + pattern : str, optional | ||
| 38 | + Pointing pattern, either 'single' or 'four' | ||
| 39 | + ra : float, optional | ||
| 40 | + Right Ascension of pattern centre (deg) | ||
| 41 | + dec : float, optional | ||
| 42 | + Declination of pattern centre (deg) | ||
| 43 | + offset : float, optional | ||
| 44 | + Offset between observations of pattern (deg) | ||
| 45 | + emin : float, optional | ||
| 46 | + Minimum energy (TeV) | ||
| 47 | + emax : float, optional | ||
| 48 | + Maximum energy (TeV) | ||
| 49 | + rad : float, optional | ||
| 50 | + ROI radius used for analysis (deg) | ||
| 51 | + duration : float, optional | ||
| 52 | + Duration of one CTA observation (s) | ||
| 53 | + deadc : float, optional | ||
| 54 | + Deadtime correction factor | ||
| 55 | + caldb : str, optional | ||
| 56 | + Calibration database path | ||
| 57 | + irf : str, optional | ||
| 58 | + Instrument response function | ||
| 59 | + | ||
| 60 | + Returns | ||
| 61 | + ------- | ||
| 62 | + obs : `~gammalib.GObservations` | ||
| 63 | + Observation container | ||
| 55 | """ | 64 | """ |
| 56 | # Set list of observations | 65 | # Set list of observations |
| 57 | obs_def_list = obsutils.set_obs_patterns(pattern, | 66 | obs_def_list = obsutils.set_obs_patterns(pattern, |
| @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 75 | # =========== # | 84 | # =========== # |
| 76 | # Setup model # | 85 | # Setup model # |
| 77 | # =========== # | 86 | # =========== # |
| 78 | -def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | 87 | +def setup_model(obs, model='data/crab.xml'): |
| 79 | """ | 88 | """ |
| 80 | - Setup model for analysis. | 89 | + Setup model for analysis |
| 81 | 90 | ||
| 82 | - Keywords: | ||
| 83 | - model - Model Xml file | 91 | + Parameters |
| 92 | + ---------- | ||
| 93 | + obs : `~gammalib.GObservations` | ||
| 94 | + Observation container | ||
| 95 | + model : str, optional | ||
| 96 | + Model definition XML file | ||
| 97 | + | ||
| 98 | + Returns | ||
| 99 | + ------- | ||
| 100 | + obs : `~gammalib.GObservations` | ||
| 101 | + Observation container | ||
| 84 | """ | 102 | """ |
| 85 | # Append model from file to observation container | 103 | # Append model from file to observation container |
| 86 | obs.models(gammalib.GModels(model)) | 104 | obs.models(gammalib.GModels(model)) |
| @@ -94,126 +112,146 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | @@ -94,126 +112,146 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | ||
| 94 | # ================================ # | 112 | # ================================ # |
| 95 | def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | 113 | def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, |
| 96 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, | 114 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, |
| 97 | - coordsys="CEL", proj="CAR", | ||
| 98 | - model="${CTOOLS}/share/models/crab.xml", | ||
| 99 | - caldb="prod2", irf="South_50h", | 115 | + coordsys='CEL', proj='CAR', |
| 116 | + model='data/crab.xml', | ||
| 117 | + caldb='prod2', irf='South_0.5h', | ||
| 100 | debug=False): | 118 | debug=False): |
| 101 | """ | 119 | """ |
| 102 | - Simulation and stacked analysis pipeline. | ||
| 103 | - | ||
| 104 | - Keywords: | ||
| 105 | - ra - RA of cube centre [deg] (default: 83.6331) | ||
| 106 | - dec - DEC of cube centre [deg] (default: 22.0145) | ||
| 107 | - emin - Minimum energy of cube [TeV] (default: 0.1) | ||
| 108 | - emax - Maximum energy of cube [TeV] (default: 100.0) | ||
| 109 | - enumbins - Number of energy bins in cube (default: 20) | ||
| 110 | - nxpix - Number of RA pixels in cube (default: 200) | ||
| 111 | - nypix - Number of DEC pixels in cube (default: 200) | ||
| 112 | - binsz - Spatial cube bin size [deg] (default: 0.02) | ||
| 113 | - coordsys - Cube coordinate system (CEL or GAL) | ||
| 114 | - proj - Cube World Coordinate System (WCS) projection | ||
| 115 | - debug - Enable debugging (default: False) | 120 | + Simulation and stacked analysis pipeline |
| 121 | + | ||
| 122 | + Parameters | ||
| 123 | + ---------- | ||
| 124 | + obs : `~gammalib.GObservations` | ||
| 125 | + Observation container | ||
| 126 | + ra : float, optional | ||
| 127 | + Right Ascension of counts cube centre (deg) | ||
| 128 | + dec : float, optional | ||
| 129 | + Declination of Region of counts cube centre (deg) | ||
| 130 | + emin : float, optional | ||
| 131 | + Minimum energy (TeV) | ||
| 132 | + emax : float, optional | ||
| 133 | + Maximum energy (TeV) | ||
| 134 | + enumbins : int, optional | ||
| 135 | + Number of energy bins | ||
| 136 | + nxpix : int, optional | ||
| 137 | + Number of pixels in X axis | ||
| 138 | + nypix : int, optional | ||
| 139 | + Number of pixels in Y axis | ||
| 140 | + binsz : float, optional | ||
| 141 | + Pixel size (deg) | ||
| 142 | + coordsys : str, optional | ||
| 143 | + Coordinate system | ||
| 144 | + proj : str, optional | ||
| 145 | + Coordinate projection | ||
| 146 | + model : str, optional | ||
| 147 | + Model definition XML file | ||
| 148 | + caldb : str, optional | ||
| 149 | + Calibration database path | ||
| 150 | + irf : str, optional | ||
| 151 | + Instrument response function | ||
| 152 | + debug : bool, optional | ||
| 153 | + Debug function | ||
| 116 | """ | 154 | """ |
| 117 | # Simulate events | 155 | # Simulate events |
| 118 | sim = ctools.ctobssim(obs) | 156 | sim = ctools.ctobssim(obs) |
| 119 | - sim["debug"] = debug | ||
| 120 | - sim["outevents"] = "obs.xml" | 157 | + sim['debug'] = debug |
| 158 | + sim['outevents'] = 'obs.xml' | ||
| 121 | sim.execute() | 159 | sim.execute() |
| 122 | 160 | ||
| 123 | # Bin events into counts map | 161 | # Bin events into counts map |
| 124 | bin = ctools.ctbin() | 162 | bin = ctools.ctbin() |
| 125 | - bin["inobs"] = "obs.xml" | ||
| 126 | - bin["outcube"] = "cntcube.fits" | ||
| 127 | - bin["ebinalg"] = "LOG" | ||
| 128 | - bin["emin"] = emin | ||
| 129 | - bin["emax"] = emax | ||
| 130 | - bin["enumbins"] = enumbins | ||
| 131 | - bin["nxpix"] = nxpix | ||
| 132 | - bin["nypix"] = nypix | ||
| 133 | - bin["binsz"] = binsz | ||
| 134 | - bin["coordsys"] = coordsys | ||
| 135 | - bin["proj"] = proj | ||
| 136 | - bin["xref"] = ra | ||
| 137 | - bin["yref"] = dec | ||
| 138 | - bin["debug"] = debug | 163 | + bin['inobs'] = 'obs.xml' |
| 164 | + bin['outcube'] = 'cntcube.fits' | ||
| 165 | + bin['ebinalg'] = 'LOG' | ||
| 166 | + bin['emin'] = emin | ||
| 167 | + bin['emax'] = emax | ||
| 168 | + bin['enumbins'] = enumbins | ||
| 169 | + bin['nxpix'] = nxpix | ||
| 170 | + bin['nypix'] = nypix | ||
| 171 | + bin['binsz'] = binsz | ||
| 172 | + bin['coordsys'] = coordsys | ||
| 173 | + bin['proj'] = proj | ||
| 174 | + bin['xref'] = ra | ||
| 175 | + bin['yref'] = dec | ||
| 176 | + bin['debug'] = debug | ||
| 139 | bin.execute() | 177 | bin.execute() |
| 140 | 178 | ||
| 141 | # Create exposure cube | 179 | # Create exposure cube |
| 142 | expcube = ctools.ctexpcube() | 180 | expcube = ctools.ctexpcube() |
| 143 | - expcube["inobs"] = "obs.xml" | ||
| 144 | - expcube["incube"] = "cntcube.fits" | ||
| 145 | - expcube["outcube"] = "expcube.fits" | ||
| 146 | - expcube["caldb"] = caldb | ||
| 147 | - expcube["irf"] = irf | ||
| 148 | - expcube["ebinalg"] = "LOG" | ||
| 149 | - expcube["emin"] = emin | ||
| 150 | - expcube["emax"] = emax | ||
| 151 | - expcube["enumbins"] = enumbins | ||
| 152 | - expcube["nxpix"] = nxpix | ||
| 153 | - expcube["nypix"] = nypix | ||
| 154 | - expcube["binsz"] = binsz | ||
| 155 | - expcube["coordsys"] = coordsys | ||
| 156 | - expcube["proj"] = proj | ||
| 157 | - expcube["xref"] = ra | ||
| 158 | - expcube["yref"] = dec | ||
| 159 | - expcube["debug"] = debug | 181 | + expcube['inobs'] = 'obs.xml' |
| 182 | + expcube['incube'] = 'cntcube.fits' | ||
| 183 | + expcube['outcube'] = 'expcube.fits' | ||
| 184 | + expcube['caldb'] = caldb | ||
| 185 | + expcube['irf'] = irf | ||
| 186 | + expcube['ebinalg'] = 'LOG' | ||
| 187 | + expcube['emin'] = emin | ||
| 188 | + expcube['emax'] = emax | ||
| 189 | + expcube['enumbins'] = enumbins | ||
| 190 | + expcube['nxpix'] = nxpix | ||
| 191 | + expcube['nypix'] = nypix | ||
| 192 | + expcube['binsz'] = binsz | ||
| 193 | + expcube['coordsys'] = coordsys | ||
| 194 | + expcube['proj'] = proj | ||
| 195 | + expcube['xref'] = ra | ||
| 196 | + expcube['yref'] = dec | ||
| 197 | + expcube['debug'] = debug | ||
| 160 | expcube.execute() | 198 | expcube.execute() |
| 161 | 199 | ||
| 162 | # Create PSF cube | 200 | # Create PSF cube |
| 163 | psfcube = ctools.ctpsfcube() | 201 | psfcube = ctools.ctpsfcube() |
| 164 | - psfcube["inobs"] = "obs.xml" | ||
| 165 | - psfcube["incube"] = "NONE" | ||
| 166 | - psfcube["outcube"] = "psfcube.fits" | ||
| 167 | - psfcube["caldb"] = caldb | ||
| 168 | - psfcube["irf"] = irf | ||
| 169 | - psfcube["ebinalg"] = "LOG" | ||
| 170 | - psfcube["emin"] = emin | ||
| 171 | - psfcube["emax"] = emax | ||
| 172 | - psfcube["enumbins"] = enumbins | ||
| 173 | - psfcube["nxpix"] = 10 | ||
| 174 | - psfcube["nypix"] = 10 | ||
| 175 | - psfcube["binsz"] = 1.0 | ||
| 176 | - psfcube["coordsys"] = coordsys | ||
| 177 | - psfcube["proj"] = proj | ||
| 178 | - psfcube["xref"] = ra | ||
| 179 | - psfcube["yref"] = dec | ||
| 180 | - psfcube["debug"] = debug | 202 | + psfcube['inobs'] = 'obs.xml' |
| 203 | + psfcube['incube'] = 'NONE' | ||
| 204 | + psfcube['outcube'] = 'psfcube.fits' | ||
| 205 | + psfcube['caldb'] = caldb | ||
| 206 | + psfcube['irf'] = irf | ||
| 207 | + psfcube['ebinalg'] = 'LOG' | ||
| 208 | + psfcube['emin'] = emin | ||
| 209 | + psfcube['emax'] = emax | ||
| 210 | + psfcube['enumbins'] = enumbins | ||
| 211 | + psfcube['nxpix'] = 10 | ||
| 212 | + psfcube['nypix'] = 10 | ||
| 213 | + psfcube['binsz'] = 1.0 | ||
| 214 | + psfcube['coordsys'] = coordsys | ||
| 215 | + psfcube['proj'] = proj | ||
| 216 | + psfcube['xref'] = ra | ||
| 217 | + psfcube['yref'] = dec | ||
| 218 | + psfcube['debug'] = debug | ||
| 181 | psfcube.execute() | 219 | psfcube.execute() |
| 182 | 220 | ||
| 183 | # Create background cube | 221 | # Create background cube |
| 184 | bkgcube = ctools.ctbkgcube() | 222 | bkgcube = ctools.ctbkgcube() |
| 185 | - bkgcube["inobs"] = "obs.xml" | ||
| 186 | - bkgcube["inmodel"] = model | ||
| 187 | - bkgcube["incube"] = "cntcube.fits" | ||
| 188 | - bkgcube["outcube"] = "bkgcube.fits" | ||
| 189 | - bkgcube["outmodel"] = "model_bkg.xml" | ||
| 190 | - bkgcube["caldb"] = caldb | ||
| 191 | - bkgcube["irf"] = irf | ||
| 192 | - bkgcube["ebinalg"] = "LOG" | ||
| 193 | - bkgcube["emin"] = emin | ||
| 194 | - bkgcube["emax"] = emax | ||
| 195 | - bkgcube["enumbins"] = enumbins | ||
| 196 | - bkgcube["nxpix"] = 10 | ||
| 197 | - bkgcube["nypix"] = 10 | ||
| 198 | - bkgcube["binsz"] = 1.0 | ||
| 199 | - bkgcube["coordsys"] = coordsys | ||
| 200 | - bkgcube["proj"] = proj | ||
| 201 | - bkgcube["xref"] = ra | ||
| 202 | - bkgcube["yref"] = dec | ||
| 203 | - bkgcube["debug"] = debug | 223 | + bkgcube['inobs'] = 'obs.xml' |
| 224 | + bkgcube['inmodel'] = model | ||
| 225 | + bkgcube['incube'] = 'NONE' | ||
| 226 | + bkgcube['outcube'] = 'bkgcube.fits' | ||
| 227 | + bkgcube['outmodel'] = 'model_bkg.xml' | ||
| 228 | + bkgcube['caldb'] = caldb | ||
| 229 | + bkgcube['irf'] = irf | ||
| 230 | + bkgcube['ebinalg'] = 'LOG' | ||
| 231 | + bkgcube['emin'] = emin | ||
| 232 | + bkgcube['emax'] = emax | ||
| 233 | + bkgcube['enumbins'] = enumbins | ||
| 234 | + bkgcube['nxpix'] = 10 | ||
| 235 | + bkgcube['nypix'] = 10 | ||
| 236 | + bkgcube['binsz'] = 1.0 | ||
| 237 | + bkgcube['coordsys'] = coordsys | ||
| 238 | + bkgcube['proj'] = proj | ||
| 239 | + bkgcube['xref'] = ra | ||
| 240 | + bkgcube['yref'] = dec | ||
| 241 | + bkgcube['debug'] = debug | ||
| 204 | bkgcube.execute() | 242 | bkgcube.execute() |
| 205 | 243 | ||
| 206 | # Perform maximum likelihood fitting | 244 | # Perform maximum likelihood fitting |
| 207 | like = ctools.ctlike() | 245 | like = ctools.ctlike() |
| 208 | - like["inobs"] = "cntcube.fits" | ||
| 209 | - like["inmodel"] = "model_bkg.xml" | ||
| 210 | - like["outmodel"] = "fit_results.xml" | ||
| 211 | - like["expcube"] = "expcube.fits" | ||
| 212 | - like["psfcube"] = "psfcube.fits" | ||
| 213 | - like["bkgcube"] = "bkgcube.fits" | ||
| 214 | - like["caldb"] = caldb | ||
| 215 | - like["irf"] = irf | ||
| 216 | - like["debug"] = True # Switch this always on for results in console | 246 | + like['inobs'] = 'cntcube.fits' |
| 247 | + like['inmodel'] = 'model_bkg.xml' | ||
| 248 | + like['outmodel'] = 'fit_results.xml' | ||
| 249 | + like['expcube'] = 'expcube.fits' | ||
| 250 | + like['psfcube'] = 'psfcube.fits' | ||
| 251 | + like['bkgcube'] = 'bkgcube.fits' | ||
| 252 | + like['caldb'] = caldb | ||
| 253 | + like['irf'] = irf | ||
| 254 | + like['debug'] = True # Switch this always on for results in console | ||
| 217 | like.execute() | 255 | like.execute() |
| 218 | 256 | ||
| 219 | # Return | 257 | # Return |
| @@ -224,12 +262,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | @@ -224,12 +262,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | ||
| 224 | # Main routine entry point # | 262 | # Main routine entry point # |
| 225 | # ======================== # | 263 | # ======================== # |
| 226 | if __name__ == '__main__': | 264 | if __name__ == '__main__': |
| 227 | - """ | ||
| 228 | - """ | 265 | + |
| 229 | # Dump header | 266 | # Dump header |
| 230 | - print("********************************************") | ||
| 231 | - print("* CTA stacked analysis pipeline *") | ||
| 232 | - print("********************************************") | 267 | + print('********************************************') |
| 268 | + print('* CTA stacked analysis pipeline *') | ||
| 269 | + print('********************************************') | ||
| 233 | 270 | ||
| 234 | # Setup observations | 271 | # Setup observations |
| 235 | obs = setup_observations() | 272 | obs = setup_observations() |
examples/pipeline_stacked_mem.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script illustrates how to perform a stacked CTA analysis based on | ||
| 4 | -# simulated CTA data. You may use and adapt this script to implement your | ||
| 5 | -# own pipeline. | 3 | +# Perform stacked in-memory analysis of simulated CTA data |
| 6 | # | 4 | # |
| 7 | -# Usage: | ||
| 8 | -# ./pipeline_stacked_mem.py | ||
| 9 | -# | ||
| 10 | -# ========================================================================== | ||
| 11 | -# | ||
| 12 | -# Copyright (C) 2014-2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder |
| 13 | # | 6 | # |
| 14 | # 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 |
| 15 | # 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 |
| @@ -33,25 +26,41 @@ from cscripts import obsutils | @@ -33,25 +26,41 @@ from cscripts import obsutils | ||
| 33 | # ================== # | 26 | # ================== # |
| 34 | # Setup observations # | 27 | # Setup observations # |
| 35 | # ================== # | 28 | # ================== # |
| 36 | -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 37 | - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, | ||
| 38 | - deadc=0.95, | ||
| 39 | - caldb="prod2", irf="South_50h"): | 29 | +def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, |
| 30 | + emin=0.1, emax=100.0, rad=5.0, duration=180.0, | ||
| 31 | + deadc=0.95, caldb='prod2', irf='South_0.5h'): | ||
| 40 | """ | 32 | """ |
| 41 | - Returns an observation container. | ||
| 42 | - | ||
| 43 | - Keywords: | ||
| 44 | - pattern - Pointing pattern, either "single" or "four" | ||
| 45 | - ra - RA of pattern centre [deg] (default: 83.6331) | ||
| 46 | - dec - DEC of pattern centre [deg] (default: 22.0145) | ||
| 47 | - offset - Offset between observations of pattern [deg] (default: 1.5) | ||
| 48 | - emin - Minimum energy [TeV] (default: 0.1) | ||
| 49 | - emax - Maximum energy [TeV] (default: 100.0) | ||
| 50 | - rad - ROI radius used for analysis [deg] (default: 5.0) | ||
| 51 | - duration - Duration of one CTA observation [seconds] (default: 1800.0) | ||
| 52 | - deadc - Deadtime correction factor (default: 0.95) | ||
| 53 | - caldb - Calibration database path (default: "dummy") | ||
| 54 | - irf - Instrument response function (default: cta_dummy_irf) | 33 | + Returns an observation container |
| 34 | + | ||
| 35 | + Parameters | ||
| 36 | + ---------- | ||
| 37 | + pattern : str, optional | ||
| 38 | + Pointing pattern, either 'single' or 'four' | ||
| 39 | + ra : float, optional | ||
| 40 | + Right Ascension of pattern centre (deg) | ||
| 41 | + dec : float, optional | ||
| 42 | + Declination of pattern centre (deg) | ||
| 43 | + offset : float, optional | ||
| 44 | + Offset between observations of pattern (deg) | ||
| 45 | + emin : float, optional | ||
| 46 | + Minimum energy (TeV) | ||
| 47 | + emax : float, optional | ||
| 48 | + Maximum energy (TeV) | ||
| 49 | + rad : float, optional | ||
| 50 | + ROI radius used for analysis (deg) | ||
| 51 | + duration : float, optional | ||
| 52 | + Duration of one CTA observation (s) | ||
| 53 | + deadc : float, optional | ||
| 54 | + Deadtime correction factor | ||
| 55 | + caldb : str, optional | ||
| 56 | + Calibration database path | ||
| 57 | + irf : str, optional | ||
| 58 | + Instrument response function | ||
| 59 | + | ||
| 60 | + Returns | ||
| 61 | + ------- | ||
| 62 | + obs : `~gammalib.GObservations` | ||
| 63 | + Observation container | ||
| 55 | """ | 64 | """ |
| 56 | # Set list of observations | 65 | # Set list of observations |
| 57 | obs_def_list = obsutils.set_obs_patterns(pattern, | 66 | obs_def_list = obsutils.set_obs_patterns(pattern, |
| @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 75 | # =========== # | 84 | # =========== # |
| 76 | # Setup model # | 85 | # Setup model # |
| 77 | # =========== # | 86 | # =========== # |
| 78 | -def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | 87 | +def setup_model(obs, model='data/crab.xml'): |
| 79 | """ | 88 | """ |
| 80 | - Setup model for analysis. | ||
| 81 | - | ||
| 82 | - Keywords: | ||
| 83 | - model - Model Xml file | 89 | + Setup model for analysis |
| 90 | + | ||
| 91 | + Parameters | ||
| 92 | + ---------- | ||
| 93 | + obs : `~gammalib.GObservations` | ||
| 94 | + Observation container | ||
| 95 | + model : str, optional | ||
| 96 | + Model definition XML file | ||
| 97 | + | ||
| 98 | + Returns | ||
| 99 | + ------- | ||
| 100 | + obs : `~gammalib.GObservations` | ||
| 101 | + Observation container | ||
| 84 | """ | 102 | """ |
| 85 | # Append model from file to observation container | 103 | # Append model from file to observation container |
| 86 | obs.models(gammalib.GModels(model)) | 104 | obs.models(gammalib.GModels(model)) |
| @@ -94,93 +112,107 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | @@ -94,93 +112,107 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | ||
| 94 | # ================================ # | 112 | # ================================ # |
| 95 | def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | 113 | def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, |
| 96 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, | 114 | enumbins=20, nxpix=200, nypix=200, binsz=0.02, |
| 97 | - coordsys="CEL", proj="CAR", debug=False): | 115 | + coordsys='CEL', proj='CAR', debug=False): |
| 98 | """ | 116 | """ |
| 99 | - Simulation and stacked analysis pipeline. | ||
| 100 | - | ||
| 101 | - Keywords: | ||
| 102 | - ra - RA of cube centre [deg] (default: 83.6331) | ||
| 103 | - dec - DEC of cube centre [deg] (default: 22.0145) | ||
| 104 | - emin - Minimum energy of cube [TeV] (default: 0.1) | ||
| 105 | - emax - Maximum energy of cube [TeV] (default: 100.0) | ||
| 106 | - enumbins - Number of energy bins in cube (default: 20) | ||
| 107 | - nxpix - Number of RA pixels in cube (default: 200) | ||
| 108 | - nypix - Number of DEC pixels in cube (default: 200) | ||
| 109 | - binsz - Spatial cube bin size [deg] (default: 0.02) | ||
| 110 | - coordsys - Cube coordinate system (CEL or GAL) | ||
| 111 | - proj - Cube World Coordinate System (WCS) projection | ||
| 112 | - debug - Enable debugging (default: False) | 117 | + Simulation and stacked analysis pipeline |
| 118 | + | ||
| 119 | + Parameters | ||
| 120 | + ---------- | ||
| 121 | + obs : `~gammalib.GObservations` | ||
| 122 | + Observation container | ||
| 123 | + ra : float, optional | ||
| 124 | + Right Ascension of counts cube centre (deg) | ||
| 125 | + dec : float, optional | ||
| 126 | + Declination of Region of counts cube centre (deg) | ||
| 127 | + emin : float, optional | ||
| 128 | + Minimum energy (TeV) | ||
| 129 | + emax : float, optional | ||
| 130 | + Maximum energy (TeV) | ||
| 131 | + enumbins : int, optional | ||
| 132 | + Number of energy bins | ||
| 133 | + nxpix : int, optional | ||
| 134 | + Number of pixels in X axis | ||
| 135 | + nypix : int, optional | ||
| 136 | + Number of pixels in Y axis | ||
| 137 | + binsz : float, optional | ||
| 138 | + Pixel size (deg) | ||
| 139 | + coordsys : str, optional | ||
| 140 | + Coordinate system | ||
| 141 | + proj : str, optional | ||
| 142 | + Coordinate projection | ||
| 143 | + debug : bool, optional | ||
| 144 | + Debug function | ||
| 113 | """ | 145 | """ |
| 114 | # Simulate events | 146 | # Simulate events |
| 115 | sim = ctools.ctobssim(obs) | 147 | sim = ctools.ctobssim(obs) |
| 116 | - sim["debug"] = debug | 148 | + sim['debug'] = debug |
| 117 | sim.run() | 149 | sim.run() |
| 118 | 150 | ||
| 119 | # Bin events into counts map | 151 | # Bin events into counts map |
| 120 | bin = ctools.ctbin(sim.obs()) | 152 | bin = ctools.ctbin(sim.obs()) |
| 121 | - bin["ebinalg"] = "LOG" | ||
| 122 | - bin["emin"] = emin | ||
| 123 | - bin["emax"] = emax | ||
| 124 | - bin["enumbins"] = enumbins | ||
| 125 | - bin["nxpix"] = nxpix | ||
| 126 | - bin["nypix"] = nypix | ||
| 127 | - bin["binsz"] = binsz | ||
| 128 | - bin["coordsys"] = coordsys | ||
| 129 | - bin["proj"] = proj | ||
| 130 | - bin["xref"] = ra | ||
| 131 | - bin["yref"] = dec | ||
| 132 | - bin["debug"] = debug | 153 | + bin['ebinalg'] = 'LOG' |
| 154 | + bin['emin'] = emin | ||
| 155 | + bin['emax'] = emax | ||
| 156 | + bin['enumbins'] = enumbins | ||
| 157 | + bin['nxpix'] = nxpix | ||
| 158 | + bin['nypix'] = nypix | ||
| 159 | + bin['binsz'] = binsz | ||
| 160 | + bin['coordsys'] = coordsys | ||
| 161 | + bin['proj'] = proj | ||
| 162 | + bin['xref'] = ra | ||
| 163 | + bin['yref'] = dec | ||
| 164 | + bin['debug'] = debug | ||
| 133 | bin.run() | 165 | bin.run() |
| 134 | 166 | ||
| 135 | # Create exposure cube | 167 | # Create exposure cube |
| 136 | expcube = ctools.ctexpcube(sim.obs()) | 168 | expcube = ctools.ctexpcube(sim.obs()) |
| 137 | - expcube["incube"] = "NONE" | ||
| 138 | - expcube["ebinalg"] = "LOG" | ||
| 139 | - expcube["emin"] = emin | ||
| 140 | - expcube["emax"] = emax | ||
| 141 | - expcube["enumbins"] = enumbins | ||
| 142 | - expcube["nxpix"] = nxpix | ||
| 143 | - expcube["nypix"] = nypix | ||
| 144 | - expcube["binsz"] = binsz | ||
| 145 | - expcube["coordsys"] = coordsys | ||
| 146 | - expcube["proj"] = proj | ||
| 147 | - expcube["xref"] = ra | ||
| 148 | - expcube["yref"] = dec | ||
| 149 | - expcube["debug"] = debug | 169 | + expcube['incube'] = 'NONE' |
| 170 | + expcube['ebinalg'] = 'LOG' | ||
| 171 | + expcube['emin'] = emin | ||
| 172 | + expcube['emax'] = emax | ||
| 173 | + expcube['enumbins'] = enumbins | ||
| 174 | + expcube['nxpix'] = nxpix | ||
| 175 | + expcube['nypix'] = nypix | ||
| 176 | + expcube['binsz'] = binsz | ||
| 177 | + expcube['coordsys'] = coordsys | ||
| 178 | + expcube['proj'] = proj | ||
| 179 | + expcube['xref'] = ra | ||
| 180 | + expcube['yref'] = dec | ||
| 181 | + expcube['debug'] = debug | ||
| 150 | expcube.run() | 182 | expcube.run() |
| 151 | 183 | ||
| 152 | # Create PSF cube | 184 | # Create PSF cube |
| 153 | psfcube = ctools.ctpsfcube(sim.obs()) | 185 | psfcube = ctools.ctpsfcube(sim.obs()) |
| 154 | - psfcube["incube"] = "NONE" | ||
| 155 | - psfcube["ebinalg"] = "LOG" | ||
| 156 | - psfcube["emin"] = emin | ||
| 157 | - psfcube["emax"] = emax | ||
| 158 | - psfcube["enumbins"] = enumbins | ||
| 159 | - psfcube["nxpix"] = 10 | ||
| 160 | - psfcube["nypix"] = 10 | ||
| 161 | - psfcube["binsz"] = 1.0 | ||
| 162 | - psfcube["coordsys"] = coordsys | ||
| 163 | - psfcube["proj"] = proj | ||
| 164 | - psfcube["xref"] = ra | ||
| 165 | - psfcube["yref"] = dec | ||
| 166 | - psfcube["debug"] = debug | 186 | + psfcube['incube'] = 'NONE' |
| 187 | + psfcube['ebinalg'] = 'LOG' | ||
| 188 | + psfcube['emin'] = emin | ||
| 189 | + psfcube['emax'] = emax | ||
| 190 | + psfcube['enumbins'] = enumbins | ||
| 191 | + psfcube['nxpix'] = 10 | ||
| 192 | + psfcube['nypix'] = 10 | ||
| 193 | + psfcube['binsz'] = 1.0 | ||
| 194 | + psfcube['coordsys'] = coordsys | ||
| 195 | + psfcube['proj'] = proj | ||
| 196 | + psfcube['xref'] = ra | ||
| 197 | + psfcube['yref'] = dec | ||
| 198 | + psfcube['debug'] = debug | ||
| 167 | psfcube.run() | 199 | psfcube.run() |
| 168 | 200 | ||
| 169 | # Create background cube | 201 | # Create background cube |
| 170 | bkgcube = ctools.ctbkgcube(sim.obs()) | 202 | bkgcube = ctools.ctbkgcube(sim.obs()) |
| 171 | - bkgcube["incube"] = "NONE" | ||
| 172 | - bkgcube["ebinalg"] = "LOG" | ||
| 173 | - bkgcube["emin"] = emin | ||
| 174 | - bkgcube["emax"] = emax | ||
| 175 | - bkgcube["enumbins"] = enumbins | ||
| 176 | - bkgcube["nxpix"] = 10 | ||
| 177 | - bkgcube["nypix"] = 10 | ||
| 178 | - bkgcube["binsz"] = 1.0 | ||
| 179 | - bkgcube["coordsys"] = coordsys | ||
| 180 | - bkgcube["proj"] = proj | ||
| 181 | - bkgcube["xref"] = ra | ||
| 182 | - bkgcube["yref"] = dec | ||
| 183 | - bkgcube["debug"] = debug | 203 | + bkgcube['incube'] = 'NONE' |
| 204 | + bkgcube['ebinalg'] = 'LOG' | ||
| 205 | + bkgcube['emin'] = emin | ||
| 206 | + bkgcube['emax'] = emax | ||
| 207 | + bkgcube['enumbins'] = enumbins | ||
| 208 | + bkgcube['nxpix'] = 10 | ||
| 209 | + bkgcube['nypix'] = 10 | ||
| 210 | + bkgcube['binsz'] = 1.0 | ||
| 211 | + bkgcube['coordsys'] = coordsys | ||
| 212 | + bkgcube['proj'] = proj | ||
| 213 | + bkgcube['xref'] = ra | ||
| 214 | + bkgcube['yref'] = dec | ||
| 215 | + bkgcube['debug'] = debug | ||
| 184 | bkgcube.run() | 216 | bkgcube.run() |
| 185 | 217 | ||
| 186 | # Attach background model to observation container | 218 | # Attach background model to observation container |
| @@ -192,7 +224,7 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | @@ -192,7 +224,7 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | ||
| 192 | 224 | ||
| 193 | # Perform maximum likelihood fitting | 225 | # Perform maximum likelihood fitting |
| 194 | like = ctools.ctlike(bin.obs()) | 226 | like = ctools.ctlike(bin.obs()) |
| 195 | - like["debug"] = True # Switch this always on for results in console | 227 | + like['debug'] = True # Switch this always on for results in console |
| 196 | like.run() | 228 | like.run() |
| 197 | 229 | ||
| 198 | # Return | 230 | # Return |
| @@ -203,12 +235,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | @@ -203,12 +235,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, | ||
| 203 | # Main routine entry point # | 235 | # Main routine entry point # |
| 204 | # ======================== # | 236 | # ======================== # |
| 205 | if __name__ == '__main__': | 237 | if __name__ == '__main__': |
| 206 | - """ | ||
| 207 | - """ | 238 | + |
| 208 | # Dump header | 239 | # Dump header |
| 209 | - print("********************************************") | ||
| 210 | - print("* CTA stacked analysis pipeline *") | ||
| 211 | - print("********************************************") | 240 | + print('********************************************') |
| 241 | + print('* CTA stacked analysis pipeline *') | ||
| 242 | + print('********************************************') | ||
| 212 | 243 | ||
| 213 | # Setup observations | 244 | # Setup observations |
| 214 | obs = setup_observations() | 245 | obs = setup_observations() |
examples/pipeline_unbinned_disk.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script illustrates how to perform an unbinned CTA analysis based on | ||
| 4 | -# simulated CTA data. You may use and adapt this script to implement your | ||
| 5 | -# own pipeline. | 3 | +# Perform unbinned analysis of simulated CTA data. |
| 6 | # | 4 | # |
| 7 | -# Usage: | ||
| 8 | -# ./pipeline_unbinned_disk.py | ||
| 9 | -# | ||
| 10 | -# ========================================================================== | ||
| 11 | -# | ||
| 12 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 13 | # | 6 | # |
| 14 | # 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 |
| 15 | # 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 |
| @@ -33,25 +26,41 @@ from cscripts import obsutils | @@ -33,25 +26,41 @@ from cscripts import obsutils | ||
| 33 | # ================== # | 26 | # ================== # |
| 34 | # Setup observations # | 27 | # Setup observations # |
| 35 | # ================== # | 28 | # ================== # |
| 36 | -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 37 | - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, | ||
| 38 | - deadc=0.95, | ||
| 39 | - caldb="prod2", irf="South_50h"): | 29 | +def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, |
| 30 | + emin=0.1, emax=100.0, rad=5.0, duration=180.0, | ||
| 31 | + deadc=0.95, caldb='prod2', irf='South_0.5h'): | ||
| 40 | """ | 32 | """ |
| 41 | - Returns an observation container. | ||
| 42 | - | ||
| 43 | - Keywords: | ||
| 44 | - pattern - Pointing pattern, either "single" or "four" | ||
| 45 | - ra - RA of pattern centre [deg] (default: 83.6331) | ||
| 46 | - dec - DEC of pattern centre [deg] (default: 22.0145) | ||
| 47 | - offset - Offset between observations of pattern [deg] (default: 1.5) | ||
| 48 | - emin - Minimum energy [TeV] (default: 0.1) | ||
| 49 | - emax - Maximum energy [TeV] (default: 100.0) | ||
| 50 | - rad - ROI radius used for analysis [deg] (default: 5.0) | ||
| 51 | - duration - Duration of one CTA observation [seconds] (default: 1800.0) | ||
| 52 | - deadc - Deadtime correction factor (default: 0.95) | ||
| 53 | - caldb - Calibration database path (default: "dummy") | ||
| 54 | - irf - Instrument response function (default: cta_dummy_irf) | 33 | + Returns an observation container |
| 34 | + | ||
| 35 | + Parameters | ||
| 36 | + ---------- | ||
| 37 | + pattern : str, optional | ||
| 38 | + Pointing pattern, either 'single' or 'four' | ||
| 39 | + ra : float, optional | ||
| 40 | + Right Ascension of pattern centre (deg) | ||
| 41 | + dec : float, optional | ||
| 42 | + Declination of pattern centre (deg) | ||
| 43 | + offset : float, optional | ||
| 44 | + Offset between observations of pattern (deg) | ||
| 45 | + emin : float, optional | ||
| 46 | + Minimum energy (TeV) | ||
| 47 | + emax : float, optional | ||
| 48 | + Maximum energy (TeV) | ||
| 49 | + rad : float, optional | ||
| 50 | + ROI radius used for analysis (deg) | ||
| 51 | + duration : float, optional | ||
| 52 | + Duration of one CTA observation (s) | ||
| 53 | + deadc : float, optional | ||
| 54 | + Deadtime correction factor | ||
| 55 | + caldb : str, optional | ||
| 56 | + Calibration database path | ||
| 57 | + irf : str, optional | ||
| 58 | + Instrument response function | ||
| 59 | + | ||
| 60 | + Returns | ||
| 61 | + ------- | ||
| 62 | + obs : `~gammalib.GObservations` | ||
| 63 | + Observation container | ||
| 55 | """ | 64 | """ |
| 56 | # Set list of observations | 65 | # Set list of observations |
| 57 | obs_def_list = obsutils.set_obs_patterns(pattern, | 66 | obs_def_list = obsutils.set_obs_patterns(pattern, |
| @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 75 | # =========== # | 84 | # =========== # |
| 76 | # Setup model # | 85 | # Setup model # |
| 77 | # =========== # | 86 | # =========== # |
| 78 | -def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | 87 | +def setup_model(obs, model='data/crab.xml'): |
| 79 | """ | 88 | """ |
| 80 | - Setup model for analysis. | ||
| 81 | - | ||
| 82 | - Keywords: | ||
| 83 | - model - Model Xml file | 89 | + Setup model for analysis |
| 90 | + | ||
| 91 | + Parameters | ||
| 92 | + ---------- | ||
| 93 | + obs : `~gammalib.GObservations` | ||
| 94 | + Observation container | ||
| 95 | + model : str, optional | ||
| 96 | + Model definition XML file | ||
| 97 | + | ||
| 98 | + Returns | ||
| 99 | + ------- | ||
| 100 | + obs : `~gammalib.GObservations` | ||
| 101 | + Observation container | ||
| 84 | """ | 102 | """ |
| 85 | # Append model from file to observation container | 103 | # Append model from file to observation container |
| 86 | obs.models(gammalib.GModels(model)) | 104 | obs.models(gammalib.GModels(model)) |
| @@ -95,55 +113,69 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | @@ -95,55 +113,69 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | ||
| 95 | def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, | 113 | def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, |
| 96 | emin=0.1, emax=100.0, | 114 | emin=0.1, emax=100.0, |
| 97 | tmin=0.0, tmax=0.0, | 115 | tmin=0.0, tmax=0.0, |
| 98 | - model="${CTOOLS}/share/models/crab.xml", | ||
| 99 | - caldb="prod2", irf="South_50h", | 116 | + model='data/crab.xml', |
| 117 | + caldb='prod2', irf='South_0.5h', | ||
| 100 | debug=False): | 118 | debug=False): |
| 101 | """ | 119 | """ |
| 102 | - Simulation and unbinned analysis pipeline. | ||
| 103 | - | ||
| 104 | - Keywords: | ||
| 105 | - ra - RA of cube centre [deg] (default: 83.63) | ||
| 106 | - dec - DEC of cube centre [deg] (default: 22.01) | ||
| 107 | - rad - Selection radius [deg] (default: 3.0) | ||
| 108 | - emin - Minimum energy of cube [TeV] (default: 0.1) | ||
| 109 | - emax - Maximum energy of cube [TeV] (default: 100.0) | ||
| 110 | - tmin - Start time [MET] (default: 0.0) | ||
| 111 | - tmax - Stop time [MET] (default: 0.0) | ||
| 112 | - model - Model Xml file | ||
| 113 | - caldb - Calibration database path (default: "dummy") | ||
| 114 | - irf - Instrument response function (default: cta_dummy_irf) | ||
| 115 | - debug - Enable debugging (default: False) | 120 | + Simulation and unbinned analysis pipeline |
| 121 | + | ||
| 122 | + Parameters | ||
| 123 | + ---------- | ||
| 124 | + obs : `~gammalib.GObservations` | ||
| 125 | + Observation container | ||
| 126 | + ra : float, optional | ||
| 127 | + Right Ascension of Region of Interest centre (deg) | ||
| 128 | + dec : float, optional | ||
| 129 | + Declination of Region of Interest centre (deg) | ||
| 130 | + rad : float, optional | ||
| 131 | + Radius of Region of Interest (deg) | ||
| 132 | + emin : float, optional | ||
| 133 | + Minimum energy (TeV) | ||
| 134 | + emax : float, optional | ||
| 135 | + Maximum energy (TeV) | ||
| 136 | + tmin : float, optional | ||
| 137 | + Start time (s) | ||
| 138 | + tmax : float, optional | ||
| 139 | + Stop time (s) | ||
| 140 | + model : str, optional | ||
| 141 | + Model definition XML file | ||
| 142 | + caldb : str, optional | ||
| 143 | + Calibration database path | ||
| 144 | + irf : str, optional | ||
| 145 | + Instrument response function | ||
| 146 | + debug : bool, optional | ||
| 147 | + Debug function | ||
| 116 | """ | 148 | """ |
| 117 | # Get model | 149 | # Get model |
| 118 | 150 | ||
| 119 | # Simulate events | 151 | # Simulate events |
| 120 | sim = ctools.ctobssim(obs) | 152 | sim = ctools.ctobssim(obs) |
| 121 | - sim["debug"] = debug | ||
| 122 | - sim["outevents"] = "obs.xml" | 153 | + sim['debug'] = debug |
| 154 | + sim['outevents'] = 'obs.xml' | ||
| 123 | sim.execute() | 155 | sim.execute() |
| 124 | 156 | ||
| 125 | # Select events | 157 | # Select events |
| 126 | select = ctools.ctselect() | 158 | select = ctools.ctselect() |
| 127 | - select["inobs"] = "obs.xml" | ||
| 128 | - select["outobs"] = "obs_selected.xml" | ||
| 129 | - select["ra"] = ra | ||
| 130 | - select["dec"] = dec | ||
| 131 | - select["rad"] = rad | ||
| 132 | - select["emin"] = emin | ||
| 133 | - select["emax"] = emax | ||
| 134 | - select["tmin"] = tmin | ||
| 135 | - select["tmax"] = tmax | ||
| 136 | - select["debug"] = debug | 159 | + select['inobs'] = 'obs.xml' |
| 160 | + select['outobs'] = 'obs_selected.xml' | ||
| 161 | + select['ra'] = ra | ||
| 162 | + select['dec'] = dec | ||
| 163 | + select['rad'] = rad | ||
| 164 | + select['emin'] = emin | ||
| 165 | + select['emax'] = emax | ||
| 166 | + select['tmin'] = tmin | ||
| 167 | + select['tmax'] = tmax | ||
| 168 | + select['debug'] = debug | ||
| 137 | select.execute() | 169 | select.execute() |
| 138 | 170 | ||
| 139 | # Perform maximum likelihood fitting | 171 | # Perform maximum likelihood fitting |
| 140 | like = ctools.ctlike() | 172 | like = ctools.ctlike() |
| 141 | - like["inobs"] = "obs_selected.xml" | ||
| 142 | - like["inmodel"] = model | ||
| 143 | - like["outmodel"] = "fit_results.xml" | ||
| 144 | - like["caldb"] = caldb | ||
| 145 | - like["irf"] = irf | ||
| 146 | - like["debug"] = True # Switch this always on for results in console | 173 | + like['inobs'] = 'obs_selected.xml' |
| 174 | + like['inmodel'] = model | ||
| 175 | + like['outmodel'] = 'fit_results.xml' | ||
| 176 | + like['caldb'] = caldb | ||
| 177 | + like['irf'] = irf | ||
| 178 | + like['debug'] = True # Switch this always on for results in console | ||
| 147 | like.execute() | 179 | like.execute() |
| 148 | 180 | ||
| 149 | # Return | 181 | # Return |
| @@ -154,12 +186,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, | @@ -154,12 +186,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, | ||
| 154 | # Main routine entry point # | 186 | # Main routine entry point # |
| 155 | # ======================== # | 187 | # ======================== # |
| 156 | if __name__ == '__main__': | 188 | if __name__ == '__main__': |
| 157 | - """ | ||
| 158 | - """ | 189 | + |
| 159 | # Dump header | 190 | # Dump header |
| 160 | - print("********************************************") | ||
| 161 | - print("* CTA unbinned analysis pipeline *") | ||
| 162 | - print("********************************************") | 191 | + print('********************************************') |
| 192 | + print('* CTA unbinned analysis pipeline *') | ||
| 193 | + print('********************************************') | ||
| 163 | 194 | ||
| 164 | # Setup observations | 195 | # Setup observations |
| 165 | obs = setup_observations() | 196 | obs = setup_observations() |
examples/pipeline_unbinned_mem.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script illustrates how to perform an unbinned CTA analysis based on | ||
| 4 | -# simulated CTA data. You may use and adapt this script to implement your | ||
| 5 | -# own pipeline. | 3 | +# Perform unbinned in-memory analysis of simulated CTA data |
| 6 | # | 4 | # |
| 7 | -# Usage: | ||
| 8 | -# ./pipeline_unbinned_mem.py | ||
| 9 | -# | ||
| 10 | -# ========================================================================== | ||
| 11 | -# | ||
| 12 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 13 | # | 6 | # |
| 14 | # 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 |
| 15 | # 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 |
| @@ -33,25 +26,41 @@ from cscripts import obsutils | @@ -33,25 +26,41 @@ from cscripts import obsutils | ||
| 33 | # ================== # | 26 | # ================== # |
| 34 | # Setup observations # | 27 | # Setup observations # |
| 35 | # ================== # | 28 | # ================== # |
| 36 | -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 37 | - emin=0.1, emax=100.0, rad=5.0, duration=1800.0, | ||
| 38 | - deadc=0.95, | ||
| 39 | - caldb="prod2", irf="South_50h"): | 29 | +def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, |
| 30 | + emin=0.1, emax=100.0, rad=5.0, duration=180.0, | ||
| 31 | + deadc=0.95, caldb='prod2', irf='South_0.5h'): | ||
| 40 | """ | 32 | """ |
| 41 | - Returns an observation container. | ||
| 42 | - | ||
| 43 | - Keywords: | ||
| 44 | - pattern - Pointing pattern, either "single" or "four" | ||
| 45 | - ra - RA of pattern centre [deg] (default: 83.6331) | ||
| 46 | - dec - DEC of pattern centre [deg] (default: 22.0145) | ||
| 47 | - offset - Offset between observations of pattern [deg] (default: 1.5) | ||
| 48 | - emin - Minimum energy [TeV] (default: 0.1) | ||
| 49 | - emax - Maximum energy [TeV] (default: 100.0) | ||
| 50 | - rad - ROI radius used for analysis [deg] (default: 5.0) | ||
| 51 | - duration - Duration of one CTA observation [seconds] (default: 1800.0) | ||
| 52 | - deadc - Deadtime correction factor (default: 0.95) | ||
| 53 | - caldb - Calibration database path (default: "dummy") | ||
| 54 | - irf - Instrument response function (default: cta_dummy_irf) | 33 | + Returns an observation container |
| 34 | + | ||
| 35 | + Parameters | ||
| 36 | + ---------- | ||
| 37 | + pattern : str, optional | ||
| 38 | + Pointing pattern, either 'single' or 'four' | ||
| 39 | + ra : float, optional | ||
| 40 | + Right Ascension of pattern centre (deg) | ||
| 41 | + dec : float, optional | ||
| 42 | + Declination of pattern centre (deg) | ||
| 43 | + offset : float, optional | ||
| 44 | + Offset between observations of pattern (deg) | ||
| 45 | + emin : float, optional | ||
| 46 | + Minimum energy (TeV) | ||
| 47 | + emax : float, optional | ||
| 48 | + Maximum energy (TeV) | ||
| 49 | + rad : float, optional | ||
| 50 | + ROI radius used for analysis (deg) | ||
| 51 | + duration : float, optional | ||
| 52 | + Duration of one CTA observation (s) | ||
| 53 | + deadc : float, optional | ||
| 54 | + Deadtime correction factor | ||
| 55 | + caldb : str, optional | ||
| 56 | + Calibration database path | ||
| 57 | + irf : str, optional | ||
| 58 | + Instrument response function | ||
| 59 | + | ||
| 60 | + Returns | ||
| 61 | + ------- | ||
| 62 | + obs : `~gammalib.GObservations` | ||
| 63 | + Observation container | ||
| 55 | """ | 64 | """ |
| 56 | # Set list of observations | 65 | # Set list of observations |
| 57 | obs_def_list = obsutils.set_obs_patterns(pattern, | 66 | obs_def_list = obsutils.set_obs_patterns(pattern, |
| @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, | ||
| 75 | # =========== # | 84 | # =========== # |
| 76 | # Setup model # | 85 | # Setup model # |
| 77 | # =========== # | 86 | # =========== # |
| 78 | -def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): | 87 | +def setup_model(obs, model='data/crab.xml'): |
| 79 | """ | 88 | """ |
| 80 | - Setup model for analysis. | ||
| 81 | - | ||
| 82 | - Keywords: | ||
| 83 | - model - Model Xml file | 89 | + Setup model for analysis |
| 90 | + | ||
| 91 | + Parameters | ||
| 92 | + ---------- | ||
| 93 | + obs : `~gammalib.GObservations` | ||
| 94 | + Observation container | ||
| 95 | + model : str, optional | ||
| 96 | + Model definition XML file | ||
| 97 | + | ||
| 98 | + Returns | ||
| 99 | + ------- | ||
| 100 | + obs : `~gammalib.GObservations` | ||
| 101 | + Observation container | ||
| 84 | """ | 102 | """ |
| 85 | # Append model from file to observation container | 103 | # Append model from file to observation container |
| 86 | obs.models(gammalib.GModels(model)) | 104 | obs.models(gammalib.GModels(model)) |
| @@ -97,38 +115,49 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, | @@ -97,38 +115,49 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, | ||
| 97 | tmin=0.0, tmax=0.0, | 115 | tmin=0.0, tmax=0.0, |
| 98 | debug=False): | 116 | debug=False): |
| 99 | """ | 117 | """ |
| 100 | - Simulation and unbinned analysis pipeline. | ||
| 101 | - | ||
| 102 | - Keywords: | ||
| 103 | - ra - RA of cube centre [deg] (default: 83.63) | ||
| 104 | - dec - DEC of cube centre [deg] (default: 22.01) | ||
| 105 | - rad - Selection radius [deg] (default: 3.0) | ||
| 106 | - emin - Minimum energy of cube [TeV] (default: 0.1) | ||
| 107 | - emax - Maximum energy of cube [TeV] (default: 100.0) | ||
| 108 | - tmin - Start time [MET] (default: 0.0) | ||
| 109 | - tmax - Stop time [MET] (default: 0.0) | ||
| 110 | - debug - Enable debugging (default: False) | 118 | + Simulation and binned analysis pipeline |
| 119 | + | ||
| 120 | + Parameters | ||
| 121 | + ---------- | ||
| 122 | + obs : `~gammalib.GObservations` | ||
| 123 | + Observation container | ||
| 124 | + ra : float, optional | ||
| 125 | + Right Ascension of Region of Interest centre (deg) | ||
| 126 | + dec : float, optional | ||
| 127 | + Declination of Region of Interest centre (deg) | ||
| 128 | + rad : float, optional | ||
| 129 | + Radius of Region of Interest (deg) | ||
| 130 | + emin : float, optional | ||
| 131 | + Minimum energy (TeV) | ||
| 132 | + emax : float, optional | ||
| 133 | + Maximum energy (TeV) | ||
| 134 | + tmin : float, optional | ||
| 135 | + Start time (s) | ||
| 136 | + tmax : float, optional | ||
| 137 | + Stop time (s) | ||
| 138 | + debug : bool, optional | ||
| 139 | + Debug function | ||
| 111 | """ | 140 | """ |
| 112 | # Simulate events | 141 | # Simulate events |
| 113 | sim = ctools.ctobssim(obs) | 142 | sim = ctools.ctobssim(obs) |
| 114 | - sim["debug"] = debug | 143 | + sim['debug'] = debug |
| 115 | sim.run() | 144 | sim.run() |
| 116 | 145 | ||
| 117 | # Select events | 146 | # Select events |
| 118 | select = ctools.ctselect(sim.obs()) | 147 | select = ctools.ctselect(sim.obs()) |
| 119 | - select["ra"] = ra | ||
| 120 | - select["dec"] = dec | ||
| 121 | - select["rad"] = rad | ||
| 122 | - select["emin"] = emin | ||
| 123 | - select["emax"] = emax | ||
| 124 | - select["tmin"] = tmin | ||
| 125 | - select["tmax"] = tmax | ||
| 126 | - select["debug"] = debug | 148 | + select['ra'] = ra |
| 149 | + select['dec'] = dec | ||
| 150 | + select['rad'] = rad | ||
| 151 | + select['emin'] = emin | ||
| 152 | + select['emax'] = emax | ||
| 153 | + select['tmin'] = tmin | ||
| 154 | + select['tmax'] = tmax | ||
| 155 | + select['debug'] = debug | ||
| 127 | select.run() | 156 | select.run() |
| 128 | 157 | ||
| 129 | # Perform maximum likelihood fitting | 158 | # Perform maximum likelihood fitting |
| 130 | like = ctools.ctlike(select.obs()) | 159 | like = ctools.ctlike(select.obs()) |
| 131 | - like["debug"] = True # Switch this always on for results in console | 160 | + like['debug'] = True # Switch this always on for results in console |
| 132 | like.run() | 161 | like.run() |
| 133 | 162 | ||
| 134 | # Return | 163 | # Return |
| @@ -139,12 +168,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, | @@ -139,12 +168,11 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, | ||
| 139 | # Main routine entry point # | 168 | # Main routine entry point # |
| 140 | # ======================== # | 169 | # ======================== # |
| 141 | if __name__ == '__main__': | 170 | if __name__ == '__main__': |
| 142 | - """ | ||
| 143 | - """ | 171 | + |
| 144 | # Dump header | 172 | # Dump header |
| 145 | - print("********************************************") | ||
| 146 | - print("* CTA unbinned analysis pipeline *") | ||
| 147 | - print("********************************************") | 173 | + print('********************************************') |
| 174 | + print('* CTA unbinned analysis pipeline *') | ||
| 175 | + print('********************************************') | ||
| 148 | 176 | ||
| 149 | # Setup observations | 177 | # Setup observations |
| 150 | obs = setup_observations() | 178 | obs = setup_observations() |
examples/show_butterfly.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script shows how to plot a butterfly created with ctbutterfly | 3 | +# Shows butterfly diagram created with ctbutterfly |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2014-2015 Michael Mayer | 5 | +# Copyright (C) 2014-2016 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 |
| @@ -18,23 +18,30 @@ | @@ -18,23 +18,30 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import gammalib | ||
| 22 | import sys | 21 | import sys |
| 22 | +import gammalib | ||
| 23 | try: | 23 | try: |
| 24 | import matplotlib.pyplot as plt | 24 | import matplotlib.pyplot as plt |
| 25 | + plt.figure() | ||
| 26 | + plt.close() | ||
| 25 | except: | 27 | except: |
| 26 | - sys.exit("This script needs matplotlib") | 28 | + print('This script needs the "matplotlib" module') |
| 29 | + sys.exit() | ||
| 27 | 30 | ||
| 28 | 31 | ||
| 29 | # ============ # | 32 | # ============ # |
| 30 | # Script entry # | 33 | # Script entry # |
| 31 | # ============ # | 34 | # ============ # |
| 32 | -if __name__ == "__main__": | ||
| 33 | - """ | ||
| 34 | - """ | 35 | +if __name__ == '__main__': |
| 36 | + | ||
| 35 | # Check for given butterfly file | 37 | # Check for given butterfly file |
| 36 | - if not len(sys.argv) == 2: | ||
| 37 | - sys.exit("Usage: show_butterfly.py butterfly.txt") | 38 | + if len(sys.argv) < 2: |
| 39 | + sys.exit('Usage: show_butterfly.py butterfly.txt [file]') | ||
| 40 | + | ||
| 41 | + # Check if plotting in file is requested | ||
| 42 | + plotfile = '' | ||
| 43 | + if len(sys.argv) == 3: | ||
| 44 | + plotfile = sys.argv[2] | ||
| 38 | 45 | ||
| 39 | # Read given butterfly file | 46 | # Read given butterfly file |
| 40 | filename = sys.argv[1] | 47 | filename = sys.argv[1] |
| @@ -75,6 +82,11 @@ if __name__ == "__main__": | @@ -75,6 +82,11 @@ if __name__ == "__main__": | ||
| 75 | plt.grid() | 82 | plt.grid() |
| 76 | plt.plot(line_x,line_y,color='black',ls='-') | 83 | plt.plot(line_x,line_y,color='black',ls='-') |
| 77 | plt.fill(butterfly_x,butterfly_y,color='green',alpha=0.5) | 84 | plt.fill(butterfly_x,butterfly_y,color='green',alpha=0.5) |
| 78 | - plt.xlabel("Energy (MeV)") | ||
| 79 | - plt.ylabel(r"E dN/dE (MeV$^{-1}$ s$^{-1}$ cm$^{-2}$)") | ||
| 80 | - plt.show() | 85 | + plt.xlabel('Energy (MeV)') |
| 86 | + plt.ylabel(r'E $\times$ dN/dE (MeV$^{-1}$ s$^{-1}$ cm$^{-2}$)') | ||
| 87 | + | ||
| 88 | + # Show spectrum or save it into file | ||
| 89 | + if len(plotfile) > 0: | ||
| 90 | + plt.savefig(plotfile) | ||
| 91 | + else: | ||
| 92 | + plt.show() |
examples/show_model.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script shows a model | 3 | +# Shows the photon spectrum of a model |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 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 |
| @@ -18,27 +18,44 @@ | @@ -18,27 +18,44 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | -import gammalib | ||
| 22 | import sys | 21 | import sys |
| 23 | import math | 22 | import math |
| 23 | +import gammalib | ||
| 24 | try: | 24 | try: |
| 25 | import matplotlib.pyplot as plt | 25 | import matplotlib.pyplot as plt |
| 26 | + plt.figure() | ||
| 27 | + plt.close() | ||
| 26 | except: | 28 | except: |
| 27 | - sys.exit("This script needs matplotlib") | 29 | + print('This script needs the "matplotlib" module') |
| 30 | + sys.exit() | ||
| 28 | 31 | ||
| 29 | 32 | ||
| 30 | # ======================= # | 33 | # ======================= # |
| 31 | # Plot spectral component # | 34 | # Plot spectral component # |
| 32 | # ======================= # | 35 | # ======================= # |
| 33 | -def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100): | 36 | +def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100, plotfile=''): |
| 34 | """ | 37 | """ |
| 38 | + Plot spectral model component | ||
| 39 | + | ||
| 40 | + Parameters | ||
| 41 | + ---------- | ||
| 42 | + model : `~gammalib.GModel` | ||
| 43 | + Model | ||
| 44 | + emin : float, optional | ||
| 45 | + Minimum energy (TeV) | ||
| 46 | + emax : float, optional | ||
| 47 | + Maximum energy (TeV) | ||
| 48 | + enumbins : integer, optional | ||
| 49 | + Number of energy bins | ||
| 50 | + plotfile : str, optional | ||
| 51 | + Name of plot file | ||
| 35 | """ | 52 | """ |
| 36 | # Get spectral component | 53 | # Get spectral component |
| 37 | spectrum = model.spectral() | 54 | spectrum = model.spectral() |
| 38 | 55 | ||
| 39 | # Setup energy axis | 56 | # Setup energy axis |
| 40 | - e_min = gammalib.GEnergy(emin, "TeV") | ||
| 41 | - e_max = gammalib.GEnergy(emax, "TeV") | 57 | + e_min = gammalib.GEnergy(emin, 'TeV') |
| 58 | + e_max = gammalib.GEnergy(emax, 'TeV') | ||
| 42 | ebounds = gammalib.GEbounds(enumbins, e_min, e_max) | 59 | ebounds = gammalib.GEbounds(enumbins, e_min, e_max) |
| 43 | 60 | ||
| 44 | # Setup model plot | 61 | # Setup model plot |
| @@ -48,7 +65,7 @@ def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100): | @@ -48,7 +65,7 @@ def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100): | ||
| 48 | max = 0.0 | 65 | max = 0.0 |
| 49 | for i in range(enumbins): | 66 | for i in range(enumbins): |
| 50 | energy = ebounds.elogmean(i) | 67 | energy = ebounds.elogmean(i) |
| 51 | - value = spectrum.eval(energy, gammalib.GTime()) | 68 | + value = spectrum.eval(energy) |
| 52 | if value > max: | 69 | if value > max: |
| 53 | max = value | 70 | max = value |
| 54 | if value < min: | 71 | if value < min: |
| @@ -57,22 +74,27 @@ def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100): | @@ -57,22 +74,27 @@ def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100): | ||
| 57 | y.append(value) | 74 | y.append(value) |
| 58 | 75 | ||
| 59 | # Set minimum and maximum | 76 | # Set minimum and maximum |
| 60 | - max = math.pow(10.0, math.log10(max)+1) | ||
| 61 | - if min < 0.0001*max: | ||
| 62 | - min = 0.0001*max | ||
| 63 | - min = math.pow(10.0, math.log10(min)-1) | 77 | + #max = math.pow(10.0, math.log10(max)+1) |
| 78 | + #if min < 0.0001*max: | ||
| 79 | + # min = 0.0001*max | ||
| 80 | + #min = math.pow(10.0, math.log10(min)-1) | ||
| 64 | 81 | ||
| 65 | 82 | ||
| 66 | # Show spectrum | 83 | # Show spectrum |
| 67 | plt.figure() | 84 | plt.figure() |
| 68 | - plt.title(model.name()+" ("+spectrum.type()+")") | 85 | + plt.title(model.name()+' ('+spectrum.type()+')') |
| 69 | plt.loglog() | 86 | plt.loglog() |
| 70 | plt.grid() | 87 | plt.grid() |
| 71 | plt.loglog(x, y, color='red') | 88 | plt.loglog(x, y, color='red') |
| 72 | - plt.xlabel("Energy [TeV]") | ||
| 73 | - plt.ylabel(r"dN/dE [ph s$^{-1}$ cm$^{-2}$ MeV$^{-1}$]") | ||
| 74 | - plt.ylim([min,max]) | ||
| 75 | - plt.show() | 89 | + plt.xlabel('Energy (TeV)') |
| 90 | + plt.ylabel(r'dN/dE (ph s$^{-1}$ cm$^{-2}$ MeV$^{-1}$)') | ||
| 91 | + #plt.ylim([min,max]) | ||
| 92 | + | ||
| 93 | + # Show spectrum or save it into file | ||
| 94 | + if len(plotfile) > 0: | ||
| 95 | + plt.savefig(plotfile) | ||
| 96 | + else: | ||
| 97 | + plt.show() | ||
| 76 | 98 | ||
| 77 | # Return | 99 | # Return |
| 78 | return | 100 | return |
| @@ -81,25 +103,28 @@ def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100): | @@ -81,25 +103,28 @@ def plot_spectrum(model, emin=0.01, emax=100.0, enumbins=100): | ||
| 81 | # ============= # | 103 | # ============= # |
| 82 | # Script entry # | 104 | # Script entry # |
| 83 | # ============= # | 105 | # ============= # |
| 84 | -if __name__ == "__main__": | ||
| 85 | - """ | ||
| 86 | - """ | 106 | +if __name__ == '__main__': |
| 107 | + | ||
| 87 | # Check for model filename | 108 | # Check for model filename |
| 88 | if len(sys.argv) < 2: | 109 | if len(sys.argv) < 2: |
| 89 | - sys.exit("Usage: show_model.py model.xml [index]") | 110 | + sys.exit('Usage: show_model.py model.xml [name] [file]') |
| 90 | 111 | ||
| 91 | # Get optional model index | 112 | # Get optional model index |
| 92 | - if len(sys.argv) == 3: | ||
| 93 | - index = int(sys.argv[2]) | 113 | + if len(sys.argv) >= 3: |
| 114 | + name = sys.argv[2] | ||
| 115 | + else: | ||
| 116 | + name = 0 | ||
| 117 | + if len(sys.argv) == 4: | ||
| 118 | + plotfile = sys.argv[3] | ||
| 94 | else: | 119 | else: |
| 95 | - index = 0 | 120 | + plotfile = '' |
| 96 | 121 | ||
| 97 | # Read models XML file | 122 | # Read models XML file |
| 98 | filename = sys.argv[1] | 123 | filename = sys.argv[1] |
| 99 | models = gammalib.GModels(filename) | 124 | models = gammalib.GModels(filename) |
| 100 | 125 | ||
| 101 | # Extract relevant model | 126 | # Extract relevant model |
| 102 | - model = models[index] | 127 | + model = models[name] |
| 103 | 128 | ||
| 104 | # Plot spectrum | 129 | # Plot spectrum |
| 105 | - plot_spectrum(model) | 130 | + plot_spectrum(model, plotfile=plotfile) |
examples/show_pha.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script displays a spectrum in PHA format. | 3 | +# Show a spectrum in PHA format. |
| 4 | # | 4 | # |
| 5 | -# Required 3rd party modules: | ||
| 6 | -# - matplotlib | ||
| 7 | -# - numpy | ||
| 8 | -# | ||
| 9 | -# Copyright (C) 2013 Juergen Knoedlseder | 5 | +# Copyright (C) 2013-2016 Juergen Knoedlseder |
| 10 | # | 6 | # |
| 11 | # 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 |
| 12 | # 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 |
| @@ -25,17 +21,32 @@ | @@ -25,17 +21,32 @@ | ||
| 25 | import sys | 21 | import sys |
| 26 | import math | 22 | import math |
| 27 | import gammalib | 23 | import gammalib |
| 24 | +try: | ||
| 25 | + import matplotlib.pyplot as plt | ||
| 26 | + plt.figure() | ||
| 27 | + plt.close() | ||
| 28 | +except: | ||
| 29 | + print('This script needs the "matplotlib" module') | ||
| 30 | + sys.exit() | ||
| 28 | 31 | ||
| 29 | 32 | ||
| 30 | # ================= # | 33 | # ================= # |
| 31 | # Show PHA spectrum # | 34 | # Show PHA spectrum # |
| 32 | # ================= # | 35 | # ================= # |
| 33 | -def show_pha(pha): | 36 | +def show_pha(pha, plotfile=''): |
| 34 | """ | 37 | """ |
| 38 | + Show PHA spectrum | ||
| 39 | + | ||
| 40 | + Parameters | ||
| 41 | + ---------- | ||
| 42 | + spectrum : `~gammalib.GPha` | ||
| 43 | + PHA file | ||
| 44 | + plotfile : str, optional | ||
| 45 | + Plot file name | ||
| 35 | """ | 46 | """ |
| 36 | # Create figure | 47 | # Create figure |
| 37 | plt.figure(1) | 48 | plt.figure(1) |
| 38 | - plt.title("PHA spectrum (" + pha.filename() + ")") | 49 | + plt.title('PHA spectrum (' + pha.filename() + ')') |
| 39 | 50 | ||
| 40 | # Generate energy vector | 51 | # Generate energy vector |
| 41 | energy = [] | 52 | energy = [] |
| @@ -59,51 +70,46 @@ def show_pha(pha): | @@ -59,51 +70,46 @@ def show_pha(pha): | ||
| 59 | plt.semilogy(energy, counts, 'ro') | 70 | plt.semilogy(energy, counts, 'ro') |
| 60 | else: | 71 | else: |
| 61 | plt.loglog(energy, counts, 'ro') | 72 | plt.loglog(energy, counts, 'ro') |
| 62 | - plt.errorbar(energy, counts, error, fmt=None, ecolor='r') | 73 | + plt.errorbar(energy, counts, error, fmt='ro', ecolor='r') |
| 63 | 74 | ||
| 64 | # Set axes | 75 | # Set axes |
| 65 | if channels: | 76 | if channels: |
| 66 | - plt.xlabel("Channels") | 77 | + plt.xlabel('Channels') |
| 67 | else: | 78 | else: |
| 68 | - plt.xlabel("Energy (TeV)") | ||
| 69 | - plt.ylabel("Counts") | 79 | + plt.xlabel('Energy (TeV)') |
| 80 | + plt.ylabel('Counts') | ||
| 70 | 81 | ||
| 71 | - # Show plot | ||
| 72 | - plt.show() | 82 | + # Show spectrum or save it into file |
| 83 | + if len(plotfile) > 0: | ||
| 84 | + plt.savefig(plotfile) | ||
| 85 | + else: | ||
| 86 | + plt.show() | ||
| 73 | 87 | ||
| 74 | # Return | 88 | # Return |
| 75 | - #return | 89 | + return |
| 76 | 90 | ||
| 77 | 91 | ||
| 78 | # ======================== # | 92 | # ======================== # |
| 79 | # Main routine entry point # | 93 | # Main routine entry point # |
| 80 | # ======================== # | 94 | # ======================== # |
| 81 | if __name__ == '__main__': | 95 | if __name__ == '__main__': |
| 82 | - """ | ||
| 83 | - Display spectrum in PHA format. | ||
| 84 | - """ | 96 | + |
| 85 | # Print usage information | 97 | # Print usage information |
| 86 | - usage = "Usage: show_pha filename" \ | ||
| 87 | - " [-n bins] [-c column] [-t title] [-p plot]" | 98 | + usage = 'Usage: show_pha.py filename [file]' |
| 88 | if len(sys.argv) < 2: | 99 | if len(sys.argv) < 2: |
| 89 | print(usage) | 100 | print(usage) |
| 90 | sys.exit() | 101 | sys.exit() |
| 91 | 102 | ||
| 103 | + # Check if plotting in file is requested | ||
| 104 | + plotfile = '' | ||
| 105 | + if len(sys.argv) == 3: | ||
| 106 | + plotfile = sys.argv[2] | ||
| 107 | + | ||
| 92 | # Extract parameters | 108 | # Extract parameters |
| 93 | filename = sys.argv[1] | 109 | filename = sys.argv[1] |
| 94 | 110 | ||
| 95 | # Load PHA spectrum | 111 | # Load PHA spectrum |
| 96 | pha = gammalib.GPha(filename) | 112 | pha = gammalib.GPha(filename) |
| 97 | - #print(pha) | ||
| 98 | - | ||
| 99 | - # Try importing matplotlib | ||
| 100 | - try: | ||
| 101 | - import matplotlib.pyplot as plt | ||
| 102 | - has_matplotlib = True | ||
| 103 | - except ImportError: | ||
| 104 | - print("Matplotlib is not (correctly) installed on your system.") | ||
| 105 | - has_matplotlib = False | ||
| 106 | 113 | ||
| 107 | # Show PHA spectrum | 114 | # Show PHA spectrum |
| 108 | - if has_matplotlib: | ||
| 109 | - show_pha(pha) | 115 | + show_pha(pha, plotfile=plotfile) |
examples/show_pull_evolution.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script displays the evolution of the pull distributions as function | ||
| 4 | -# of the number of samples. The pull distributions are generated using the | ||
| 5 | -# cspull script. The pull is defined by | 3 | +# Shows the evolution of the mean and rms pull |
| 6 | # | 4 | # |
| 7 | -# (fitted value - simulated value) / estimated error | ||
| 8 | -# | ||
| 9 | -# and the pull histogram allows to assess possible biases in the fit | ||
| 10 | -# parameters and errors. | ||
| 11 | -# | ||
| 12 | -# Required 3rd party modules: | ||
| 13 | -# - matplotlib | ||
| 14 | -# - numpy | ||
| 15 | -# | ||
| 16 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 17 | # | 6 | # |
| 18 | # 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 |
| 19 | # 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 |
| @@ -29,10 +18,20 @@ | @@ -29,10 +18,20 @@ | ||
| 29 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 30 | # | 19 | # |
| 31 | # ========================================================================== | 20 | # ========================================================================== |
| 32 | -import matplotlib.pyplot as plt | ||
| 33 | -import numpy as np | ||
| 34 | import sys | 21 | import sys |
| 35 | import csv | 22 | import csv |
| 23 | +try: | ||
| 24 | + import matplotlib.pyplot as plt | ||
| 25 | + plt.figure() | ||
| 26 | + plt.close() | ||
| 27 | +except: | ||
| 28 | + print('This script needs the "matplotlib" module') | ||
| 29 | + sys.exit() | ||
| 30 | +try: | ||
| 31 | + import numpy as np | ||
| 32 | +except: | ||
| 33 | + print('This script needs the "numpy" module') | ||
| 34 | + sys.exit() | ||
| 36 | 35 | ||
| 37 | 36 | ||
| 38 | # ====================== # | 37 | # ====================== # |
| @@ -40,7 +39,14 @@ import csv | @@ -40,7 +39,14 @@ import csv | ||
| 40 | # ====================== # | 39 | # ====================== # |
| 41 | def read_pull(filename, parname): | 40 | def read_pull(filename, parname): |
| 42 | """ | 41 | """ |
| 43 | - Read pull distribution. | 42 | + Read pull distribution |
| 43 | + | ||
| 44 | + Parameters | ||
| 45 | + ---------- | ||
| 46 | + filename : str | ||
| 47 | + Pull distribution ASCII file | ||
| 48 | + parname : str | ||
| 49 | + Parameter | ||
| 44 | """ | 50 | """ |
| 45 | # Initialise list | 51 | # Initialise list |
| 46 | values = [] | 52 | values = [] |
| @@ -58,9 +64,9 @@ def read_pull(filename, parname): | @@ -58,9 +64,9 @@ def read_pull(filename, parname): | ||
| 58 | try: | 64 | try: |
| 59 | index = row.index(parname) | 65 | index = row.index(parname) |
| 60 | except: | 66 | except: |
| 61 | - sys.stdout.write('ERROR: Parameter "'+parname+'" not found in list:\n') | 67 | + print('ERROR: Parameter "'+parname+'" not found in list:') |
| 62 | for p in row: | 68 | for p in row: |
| 63 | - sys.stdout.write(' "'+p+'"\n') | 69 | + print(' "'+p+'"') |
| 64 | raise NameError(parname) | 70 | raise NameError(parname) |
| 65 | 71 | ||
| 66 | # Handle data rows | 72 | # Handle data rows |
| @@ -81,15 +87,18 @@ def read_pull(filename, parname): | @@ -81,15 +87,18 @@ def read_pull(filename, parname): | ||
| 81 | # Main routine entry point # | 87 | # Main routine entry point # |
| 82 | # ======================== # | 88 | # ======================== # |
| 83 | if __name__ == '__main__': | 89 | if __name__ == '__main__': |
| 84 | - """ | ||
| 85 | - Display pull evolution generated by cspull using matplotlib. | ||
| 86 | - """ | 90 | + |
| 87 | # Print usage information | 91 | # Print usage information |
| 88 | - usage = "Usage: show_pull_evolution filename parname" | 92 | + usage = 'Usage: show_pull_evolution.py filename parname [file]' |
| 89 | if len(sys.argv) < 3: | 93 | if len(sys.argv) < 3: |
| 90 | - sys.stdout.write(usage+"\n") | 94 | + print(usage) |
| 91 | sys.exit() | 95 | sys.exit() |
| 92 | 96 | ||
| 97 | + # Check if plotting in file is requested | ||
| 98 | + plotfile = '' | ||
| 99 | + if len(sys.argv) == 4: | ||
| 100 | + plotfile = sys.argv[3] | ||
| 101 | + | ||
| 93 | # Extract parameters | 102 | # Extract parameters |
| 94 | filename = sys.argv[1] | 103 | filename = sys.argv[1] |
| 95 | parname = sys.argv[2] | 104 | parname = sys.argv[2] |
| @@ -108,17 +117,20 @@ if __name__ == '__main__': | @@ -108,17 +117,20 @@ if __name__ == '__main__': | ||
| 108 | rms.append(np.std(values[0:i])) | 117 | rms.append(np.std(values[0:i])) |
| 109 | 118 | ||
| 110 | # Plot mean and rms evolution | 119 | # Plot mean and rms evolution |
| 111 | - plt.semilogx(samples, mean, 'r-', label="Mean") | ||
| 112 | - plt.semilogx(samples, rms, 'b-', label="Std. deviation") | 120 | + plt.semilogx(samples, mean, 'r-', label='Mean') |
| 121 | + plt.semilogx(samples, rms, 'b-', label='Std. deviation') | ||
| 113 | 122 | ||
| 114 | # Set plot | 123 | # Set plot |
| 115 | - plt.xlabel("Samples") | ||
| 116 | - plt.ylabel("Value") | 124 | + plt.xlabel('Samples') |
| 125 | + plt.ylabel('Value') | ||
| 117 | plt.title(parname) | 126 | plt.title(parname) |
| 118 | plt.grid(True) | 127 | plt.grid(True) |
| 119 | 128 | ||
| 120 | # Set legend | 129 | # Set legend |
| 121 | - plt.legend(loc="upper left") | 130 | + plt.legend(loc='upper left') |
| 122 | 131 | ||
| 123 | - # Show histogram | ||
| 124 | - plt.show() | 132 | + # Show figure |
| 133 | + if len(plotfile) > 0: | ||
| 134 | + plt.savefig(plotfile) | ||
| 135 | + else: | ||
| 136 | + plt.show() |
examples/show_pull_histogram.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script displays pull histograms that have been generated using the | ||
| 4 | -# cspull script. The pull is defined by | 3 | +# Shows the pull histogram |
| 5 | # | 4 | # |
| 6 | -# (fitted value - simulated value) / estimated error | ||
| 7 | -# | ||
| 8 | -# and the pull histogram allows to assess possible biases in the fit | ||
| 9 | -# parameters and errors. | ||
| 10 | -# | ||
| 11 | -# Required 3rd party modules: | ||
| 12 | -# - matplotlib | ||
| 13 | -# - numpy | ||
| 14 | -# | ||
| 15 | -# Copyright (C) 2011 Jurgen Knodlseder | 5 | +# Copyright (C) 2011-2016 Juergen Knoedlseder |
| 16 | # | 6 | # |
| 17 | # 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 |
| 18 | # 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 |
| @@ -28,11 +18,21 @@ | @@ -28,11 +18,21 @@ | ||
| 28 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 29 | # | 19 | # |
| 30 | # ========================================================================== | 20 | # ========================================================================== |
| 31 | -import matplotlib.mlab as mlab | ||
| 32 | -import matplotlib.pyplot as plt | ||
| 33 | -import numpy as np | ||
| 34 | import sys | 21 | import sys |
| 35 | import csv | 22 | import csv |
| 23 | +try: | ||
| 24 | + import matplotlib.pyplot as plt | ||
| 25 | + import matplotlib.mlab as mlab | ||
| 26 | + plt.figure() | ||
| 27 | + plt.close() | ||
| 28 | +except: | ||
| 29 | + print('This script needs the "matplotlib" module') | ||
| 30 | + sys.exit() | ||
| 31 | +try: | ||
| 32 | + import numpy as np | ||
| 33 | +except: | ||
| 34 | + print('This script needs the "numpy" module') | ||
| 35 | + sys.exit() | ||
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | # ====================== # | 38 | # ====================== # |
| @@ -40,7 +40,14 @@ import csv | @@ -40,7 +40,14 @@ import csv | ||
| 40 | # ====================== # | 40 | # ====================== # |
| 41 | def read_pull(filename, parname): | 41 | def read_pull(filename, parname): |
| 42 | """ | 42 | """ |
| 43 | - Read pull distribution. | 43 | + Read pull distribution |
| 44 | + | ||
| 45 | + Parameters | ||
| 46 | + ---------- | ||
| 47 | + filename : str | ||
| 48 | + Pull distribution ASCII file | ||
| 49 | + parname : str | ||
| 50 | + Parameter | ||
| 44 | """ | 51 | """ |
| 45 | # Initialise list | 52 | # Initialise list |
| 46 | values = [] | 53 | values = [] |
| @@ -58,9 +65,9 @@ def read_pull(filename, parname): | @@ -58,9 +65,9 @@ def read_pull(filename, parname): | ||
| 58 | try: | 65 | try: |
| 59 | index = row.index(parname) | 66 | index = row.index(parname) |
| 60 | except: | 67 | except: |
| 61 | - sys.stdout.write('ERROR: Parameter "'+parname+'" not found in list:\n') | 68 | + print('ERROR: Parameter "'+parname+'" not found in list:') |
| 62 | for p in row: | 69 | for p in row: |
| 63 | - sys.stdout.write(' "'+p+'"\n') | 70 | + print(' "'+p+'"') |
| 64 | raise NameError(parname) | 71 | raise NameError(parname) |
| 65 | 72 | ||
| 66 | # Handle data rows | 73 | # Handle data rows |
| @@ -81,13 +88,11 @@ def read_pull(filename, parname): | @@ -81,13 +88,11 @@ def read_pull(filename, parname): | ||
| 81 | # Main routine entry point # | 88 | # Main routine entry point # |
| 82 | # ======================== # | 89 | # ======================== # |
| 83 | if __name__ == '__main__': | 90 | if __name__ == '__main__': |
| 84 | - """ | ||
| 85 | - Display pull histogram generated by cspull using matplotlib. | ||
| 86 | - """ | 91 | + |
| 87 | # Print usage information | 92 | # Print usage information |
| 88 | - usage = "Usage: show_pull_histogram filename parname [bins]" | 93 | + usage = 'Usage: show_pull_histogram.py filename parname [bins] [file]' |
| 89 | if len(sys.argv) < 3: | 94 | if len(sys.argv) < 3: |
| 90 | - sys.stdout.write(usage+"\n") | 95 | + print(usage) |
| 91 | sys.exit() | 96 | sys.exit() |
| 92 | 97 | ||
| 93 | # Extract parameters | 98 | # Extract parameters |
| @@ -97,13 +102,17 @@ if __name__ == '__main__': | @@ -97,13 +102,17 @@ if __name__ == '__main__': | ||
| 97 | nbins = int(sys.argv[3]) | 102 | nbins = int(sys.argv[3]) |
| 98 | else: | 103 | else: |
| 99 | nbins = 50 | 104 | nbins = 50 |
| 105 | + if len(sys.argv) == 5: | ||
| 106 | + plotfile = sys.argv[4] | ||
| 107 | + else: | ||
| 108 | + plotfile = '' | ||
| 100 | 109 | ||
| 101 | # Read values from CSV file | 110 | # Read values from CSV file |
| 102 | values = read_pull(filename, parname) | 111 | values = read_pull(filename, parname) |
| 103 | 112 | ||
| 104 | # Create histogram | 113 | # Create histogram |
| 105 | n, bins, patches = plt.hist(values, nbins, range=[-4.0,4.0], | 114 | n, bins, patches = plt.hist(values, nbins, range=[-4.0,4.0], |
| 106 | - normed=True, facecolor='green') | 115 | + normed=True, facecolor='green') |
| 107 | 116 | ||
| 108 | # Create expected distribution | 117 | # Create expected distribution |
| 109 | y = mlab.normpdf(bins, 0.0, 1.0) | 118 | y = mlab.normpdf(bins, 0.0, 1.0) |
| @@ -118,5 +127,8 @@ if __name__ == '__main__': | @@ -118,5 +127,8 @@ if __name__ == '__main__': | ||
| 118 | plt.title(name) | 127 | plt.title(name) |
| 119 | plt.grid(True) | 128 | plt.grid(True) |
| 120 | 129 | ||
| 121 | - # Show histogram | ||
| 122 | - plt.show() | 130 | + # Show figure |
| 131 | + if len(plotfile) > 0: | ||
| 132 | + plt.savefig(plotfile) | ||
| 133 | + else: | ||
| 134 | + plt.show() |
examples/show_response.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script displays one or several CTA response functions. | 3 | +# Shows one or several CTA response functions. |
| 4 | # | 4 | # |
| 5 | -# Required 3rd party modules: | ||
| 6 | -# - matplotlib | ||
| 7 | -# - numpy | ||
| 8 | -# | ||
| 9 | -# Copyright (C) 2014-2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2014-2016 Juergen Knoedlseder |
| 10 | # | 6 | # |
| 11 | # 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 |
| 12 | # 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 |
| @@ -25,7 +21,13 @@ | @@ -25,7 +21,13 @@ | ||
| 25 | import sys | 21 | import sys |
| 26 | import math | 22 | import math |
| 27 | import gammalib | 23 | import gammalib |
| 28 | -import matplotlib.pyplot as plt | 24 | +try: |
| 25 | + import matplotlib.pyplot as plt | ||
| 26 | + plt.figure() | ||
| 27 | + plt.close() | ||
| 28 | +except: | ||
| 29 | + print('This script needs the "matplotlib" module') | ||
| 30 | + sys.exit() | ||
| 29 | 31 | ||
| 30 | 32 | ||
| 31 | # ================================== # | 33 | # ================================== # |
| @@ -35,11 +37,19 @@ def sigma_lima(Non, Noff, alpha=0.2): | @@ -35,11 +37,19 @@ def sigma_lima(Non, Noff, alpha=0.2): | ||
| 35 | """ | 37 | """ |
| 36 | Compute Eq. (17) of Li & Ma (1983). | 38 | Compute Eq. (17) of Li & Ma (1983). |
| 37 | 39 | ||
| 38 | - Parameters: | ||
| 39 | - Non - Number of on counts | ||
| 40 | - Noff - Number of off counts | ||
| 41 | - Keywords: | ||
| 42 | - alpha - Ratio of on-to-off exposure | 40 | + Parameters |
| 41 | + ---------- | ||
| 42 | + Non : float | ||
| 43 | + Number of On counts | ||
| 44 | + Noff : float | ||
| 45 | + Number of Off counts | ||
| 46 | + alpha : float, optional | ||
| 47 | + Ratio of on-to-off exposure | ||
| 48 | + | ||
| 49 | + Returns | ||
| 50 | + ------- | ||
| 51 | + sigma : float | ||
| 52 | + Detection significance in Gaussian sigma | ||
| 43 | """ | 53 | """ |
| 44 | # Compute sensitivity | 54 | # Compute sensitivity |
| 45 | alpha1 = alpha + 1.0 | 55 | alpha1 = alpha + 1.0 |
| @@ -61,11 +71,19 @@ def Non_lima(sigma, Noff, alpha=0.2): | @@ -61,11 +71,19 @@ def Non_lima(sigma, Noff, alpha=0.2): | ||
| 61 | """ | 71 | """ |
| 62 | Solve Eq. (17) of Li & Ma (1983) for Non | 72 | Solve Eq. (17) of Li & Ma (1983) for Non |
| 63 | 73 | ||
| 64 | - Parameters: | ||
| 65 | - sigma - Required significance | ||
| 66 | - Noff - Number of off counts | ||
| 67 | - Keywords: | ||
| 68 | - alpha - Ratio of on-to-off exposure | 74 | + Parameters |
| 75 | + ---------- | ||
| 76 | + sigma : float | ||
| 77 | + Required detection significance in Gaussian sigma | ||
| 78 | + Noff : float | ||
| 79 | + Number of Off counts | ||
| 80 | + alpha : float, optional | ||
| 81 | + Ratio of on-to-off exposure | ||
| 82 | + | ||
| 83 | + Returns | ||
| 84 | + ------- | ||
| 85 | + Non : float | ||
| 86 | + Number of On counts | ||
| 69 | """ | 87 | """ |
| 70 | # Set initial guess for Non | 88 | # Set initial guess for Non |
| 71 | S = 25.0 | 89 | S = 25.0 |
| @@ -89,9 +107,18 @@ def Non_lima(sigma, Noff, alpha=0.2): | @@ -89,9 +107,18 @@ def Non_lima(sigma, Noff, alpha=0.2): | ||
| 89 | # ======================= # | 107 | # ======================= # |
| 90 | # Show one effective area # | 108 | # Show one effective area # |
| 91 | # ======================= # | 109 | # ======================= # |
| 92 | -def show_one_effective_area(rsp, name, color="r"): | 110 | +def show_one_effective_area(rsp, name, color='r'): |
| 93 | """ | 111 | """ |
| 94 | - Show one effective area. | 112 | + Show one effective area |
| 113 | + | ||
| 114 | + Parameters | ||
| 115 | + ---------- | ||
| 116 | + rsp : `~gammalib.GCTAResponse` | ||
| 117 | + Response function | ||
| 118 | + name : str | ||
| 119 | + Name of the response function | ||
| 120 | + color : str, optional | ||
| 121 | + Color for plot | ||
| 95 | """ | 122 | """ |
| 96 | # Set to figure 1 | 123 | # Set to figure 1 |
| 97 | plt.figure(1) | 124 | plt.figure(1) |
| @@ -111,11 +138,11 @@ def show_one_effective_area(rsp, name, color="r"): | @@ -111,11 +138,11 @@ def show_one_effective_area(rsp, name, color="r"): | ||
| 111 | plt.loglog(E, aeff, color+'o') | 138 | plt.loglog(E, aeff, color+'o') |
| 112 | 139 | ||
| 113 | # Set axes | 140 | # Set axes |
| 114 | - plt.xlabel("Energy [TeV]") | ||
| 115 | - plt.ylabel("Effective area [cm2]") | 141 | + plt.xlabel('Energy (TeV)') |
| 142 | + plt.ylabel(r'Effective area (cm$^{2}$)') | ||
| 116 | 143 | ||
| 117 | # Set legend | 144 | # Set legend |
| 118 | - plt.legend(loc="lower right") | 145 | + plt.legend(loc='lower right') |
| 119 | 146 | ||
| 120 | # Return | 147 | # Return |
| 121 | return | 148 | return |
| @@ -124,9 +151,18 @@ def show_one_effective_area(rsp, name, color="r"): | @@ -124,9 +151,18 @@ def show_one_effective_area(rsp, name, color="r"): | ||
| 124 | # ======================== # | 151 | # ======================== # |
| 125 | # Show one background rate # | 152 | # Show one background rate # |
| 126 | # ======================== # | 153 | # ======================== # |
| 127 | -def show_one_background_rate(rsp, name, color="r"): | 154 | +def show_one_background_rate(rsp, name, color='r'): |
| 128 | """ | 155 | """ |
| 129 | - Show one background rate. | 156 | + Show one background rate |
| 157 | + | ||
| 158 | + Parameters | ||
| 159 | + ---------- | ||
| 160 | + rsp : `~gammalib.GCTAResponse` | ||
| 161 | + Response function | ||
| 162 | + name : str | ||
| 163 | + Name of the response function | ||
| 164 | + color : str, optional | ||
| 165 | + Color for plot | ||
| 130 | """ | 166 | """ |
| 131 | # Set to figure 2 | 167 | # Set to figure 2 |
| 132 | plt.figure(2) | 168 | plt.figure(2) |
| @@ -148,11 +184,11 @@ def show_one_background_rate(rsp, name, color="r"): | @@ -148,11 +184,11 @@ def show_one_background_rate(rsp, name, color="r"): | ||
| 148 | plt.loglog(E, bgrate, color+'o') | 184 | plt.loglog(E, bgrate, color+'o') |
| 149 | 185 | ||
| 150 | # Set axes | 186 | # Set axes |
| 151 | - plt.xlabel("Energy [TeV]") | ||
| 152 | - plt.ylabel("Background rate [events/s/MeV/sr]") | 187 | + plt.xlabel('Energy (TeV)') |
| 188 | + plt.ylabel(r'Background rate (counts s$^{-1}$ MeV$^{-1}$ sr$^{-1}$)') | ||
| 153 | 189 | ||
| 154 | # Set legend | 190 | # Set legend |
| 155 | - plt.legend(loc="lower left") | 191 | + plt.legend(loc='lower left') |
| 156 | 192 | ||
| 157 | # Return | 193 | # Return |
| 158 | return | 194 | return |
| @@ -161,9 +197,25 @@ def show_one_background_rate(rsp, name, color="r"): | @@ -161,9 +197,25 @@ def show_one_background_rate(rsp, name, color="r"): | ||
| 161 | # ==================== # | 197 | # ==================== # |
| 162 | # Show one sensitivity # | 198 | # Show one sensitivity # |
| 163 | # ==================== # | 199 | # ==================== # |
| 164 | -def show_one_sensitivity(rsp, name, color="r", duration=180000.0, alpha=0.2, sigma=5.0): | 200 | +def show_one_sensitivity(rsp, name, color='r', duration=180000.0, alpha=0.2, |
| 201 | + sigma=5.0): | ||
| 165 | """ | 202 | """ |
| 166 | - Show one sensitivity. | 203 | + Show one sensitivity |
| 204 | + | ||
| 205 | + Parameters | ||
| 206 | + ---------- | ||
| 207 | + rsp : `~gammalib.GCTAResponse` | ||
| 208 | + Response function | ||
| 209 | + name : str | ||
| 210 | + Name of the response function | ||
| 211 | + color : str, optional | ||
| 212 | + Color for plot | ||
| 213 | + duration : float, optional | ||
| 214 | + Duration of observation (s) | ||
| 215 | + alpha : float, optional | ||
| 216 | + Ratio of on-to-off exposure | ||
| 217 | + sigma : float, optional | ||
| 218 | + Required detection significance in Gaussian sigma | ||
| 167 | """ | 219 | """ |
| 168 | # Set constants | 220 | # Set constants |
| 169 | r68_to_sigma = 0.6624305 | 221 | r68_to_sigma = 0.6624305 |
| @@ -194,9 +246,9 @@ def show_one_sensitivity(rsp, name, color="r", duration=180000.0, alpha=0.2, sig | @@ -194,9 +246,9 @@ def show_one_sensitivity(rsp, name, color="r", duration=180000.0, alpha=0.2, sig | ||
| 194 | src_counts = 0.05*bgd_counts | 246 | src_counts = 0.05*bgd_counts |
| 195 | if src_counts < 10: | 247 | if src_counts < 10: |
| 196 | src_counts = 10.0 | 248 | src_counts = 10.0 |
| 197 | - emin = gammalib.GEnergy(math.pow(10.0, logE[i]-0.1), "TeV") | ||
| 198 | - emax = gammalib.GEnergy(math.pow(10.0, logE[i]+0.1), "TeV") | ||
| 199 | - epivot = gammalib.GEnergy(math.pow(10.0, logE[i]), "TeV") | 249 | + emin = gammalib.GEnergy(math.pow(10.0, logE[i]-0.1), 'TeV') |
| 250 | + emax = gammalib.GEnergy(math.pow(10.0, logE[i]+0.1), 'TeV') | ||
| 251 | + epivot = gammalib.GEnergy(math.pow(10.0, logE[i]), 'TeV') | ||
| 200 | plaw = gammalib.GModelSpectralPlaw(1.0e-6, -2.6, epivot) | 252 | plaw = gammalib.GModelSpectralPlaw(1.0e-6, -2.6, epivot) |
| 201 | conv = TeV2erg*E[i]*E[i]/plaw.flux(emin, emax) | 253 | conv = TeV2erg*E[i]*E[i]/plaw.flux(emin, emax) |
| 202 | flux[i] = conv * src_counts / (duration * aeff*0.68) | 254 | flux[i] = conv * src_counts / (duration * aeff*0.68) |
| @@ -206,11 +258,11 @@ def show_one_sensitivity(rsp, name, color="r", duration=180000.0, alpha=0.2, sig | @@ -206,11 +258,11 @@ def show_one_sensitivity(rsp, name, color="r", duration=180000.0, alpha=0.2, sig | ||
| 206 | plt.loglog(E, flux, color+'o') | 258 | plt.loglog(E, flux, color+'o') |
| 207 | 259 | ||
| 208 | # Set axes | 260 | # Set axes |
| 209 | - plt.xlabel("Energy [TeV]") | ||
| 210 | - plt.ylabel("Sensitivity [erg/cm2/s]") | 261 | + plt.xlabel('Energy (TeV)') |
| 262 | + plt.ylabel(r'Sensitivity (erg cm$^{-2}$ s$^{-1}$)') | ||
| 211 | 263 | ||
| 212 | # Set legend | 264 | # Set legend |
| 213 | - plt.legend(loc="upper right") | 265 | + plt.legend(loc='upper right') |
| 214 | 266 | ||
| 215 | # Return | 267 | # Return |
| 216 | return | 268 | return |
| @@ -219,9 +271,22 @@ def show_one_sensitivity(rsp, name, color="r", duration=180000.0, alpha=0.2, sig | @@ -219,9 +271,22 @@ def show_one_sensitivity(rsp, name, color="r", duration=180000.0, alpha=0.2, sig | ||
| 219 | # ==================== # | 271 | # ==================== # |
| 220 | # Show one sensitivity # | 272 | # Show one sensitivity # |
| 221 | # ==================== # | 273 | # ==================== # |
| 222 | -def show_one_response(rspname, dbname, name, rootdir=None, color="r"): | 274 | +def show_one_response(rspname, dbname, name, rootdir=None, color='r'): |
| 223 | """ | 275 | """ |
| 224 | Show one response. | 276 | Show one response. |
| 277 | + | ||
| 278 | + Parameters | ||
| 279 | + ---------- | ||
| 280 | + rspname : str | ||
| 281 | + Response name | ||
| 282 | + dbname : str | ||
| 283 | + Database name | ||
| 284 | + name : str | ||
| 285 | + Name of the response function | ||
| 286 | + rootdir : str, optional | ||
| 287 | + Response root directory | ||
| 288 | + color : str, optional | ||
| 289 | + Color for plot | ||
| 225 | """ | 290 | """ |
| 226 | # Set-up calibration database | 291 | # Set-up calibration database |
| 227 | caldb = gammalib.GCaldb() | 292 | caldb = gammalib.GCaldb() |
| @@ -230,7 +295,7 @@ def show_one_response(rspname, dbname, name, rootdir=None, color="r"): | @@ -230,7 +295,7 @@ def show_one_response(rspname, dbname, name, rootdir=None, color="r"): | ||
| 230 | if gammalib.dir_exists(dbname): | 295 | if gammalib.dir_exists(dbname): |
| 231 | caldb.rootdir(dbname) | 296 | caldb.rootdir(dbname) |
| 232 | else: | 297 | else: |
| 233 | - caldb.open("cta", dbname) | 298 | + caldb.open('cta', dbname) |
| 234 | 299 | ||
| 235 | # Load response function | 300 | # Load response function |
| 236 | rsp = gammalib.GCTAResponseIrf(rspname, caldb) | 301 | rsp = gammalib.GCTAResponseIrf(rspname, caldb) |
| @@ -252,31 +317,36 @@ def show_one_response(rspname, dbname, name, rootdir=None, color="r"): | @@ -252,31 +317,36 @@ def show_one_response(rspname, dbname, name, rootdir=None, color="r"): | ||
| 252 | # Main routine entry point # | 317 | # Main routine entry point # |
| 253 | # ======================== # | 318 | # ======================== # |
| 254 | if __name__ == '__main__': | 319 | if __name__ == '__main__': |
| 255 | - """ | ||
| 256 | - Display response information. | ||
| 257 | - """ | 320 | + |
| 321 | + # Print usage information | ||
| 322 | + usage = 'Usage: show_response.py [file]' | ||
| 323 | + if len(sys.argv) < 1: | ||
| 324 | + print(usage) | ||
| 325 | + sys.exit() | ||
| 326 | + | ||
| 327 | + # Check if plotting in file is requested | ||
| 328 | + plotfile = '' | ||
| 329 | + if len(sys.argv) == 2: | ||
| 330 | + plotfile = sys.argv[1] | ||
| 331 | + | ||
| 258 | # Create figures | 332 | # Create figures |
| 259 | plt.figure(1) | 333 | plt.figure(1) |
| 260 | - plt.title("Effective area") | 334 | + plt.title('Effective area') |
| 261 | plt.figure(2) | 335 | plt.figure(2) |
| 262 | - plt.title("Background rate") | 336 | + plt.title('Background rate') |
| 263 | plt.figure(3) | 337 | plt.figure(3) |
| 264 | - plt.title("Sensitivity") | 338 | + plt.title('Sensitivity') |
| 265 | 339 | ||
| 266 | # Set response dictionary | 340 | # Set response dictionary |
| 267 | rsps = [ | 341 | rsps = [ |
| 268 | - {'dbname': "dummy", | ||
| 269 | - 'rspname': "cta_dummy_irf", | ||
| 270 | - 'name': "Prod1 (Array E, MPIK)", | ||
| 271 | - 'color': "b"}, | ||
| 272 | - {'dbname': "e", | ||
| 273 | - 'rspname': "IFAE20120510_50h", | ||
| 274 | - 'name': "Prod1 (Array E, IFAE)", | ||
| 275 | - 'color': "g"}, | ||
| 276 | - {'dbname': "aar", | ||
| 277 | - 'rspname': "DESY20140105_50h", | ||
| 278 | - 'name': "Prod2 (Aar, DESY)", | ||
| 279 | - 'color': "r"} | 342 | + {'dbname': 'irf', |
| 343 | + 'rspname': 'cta_dummy_irf.dat', | ||
| 344 | + 'name': 'Prod1 (Array E, MPIK)', | ||
| 345 | + 'color': 'b'}, | ||
| 346 | + {'dbname': 'irf', | ||
| 347 | + 'rspname': 'irf_file.fits', | ||
| 348 | + 'name': 'Prod2 (Aar, IFAE)', | ||
| 349 | + 'color': 'r'} | ||
| 280 | ] | 350 | ] |
| 281 | 351 | ||
| 282 | # Loop over all responses | 352 | # Loop over all responses |
| @@ -295,5 +365,8 @@ if __name__ == '__main__': | @@ -295,5 +365,8 @@ if __name__ == '__main__': | ||
| 295 | # Show response | 365 | # Show response |
| 296 | show_one_response(rspname, dbname, name, rootdir=rootdir, color=color) | 366 | show_one_response(rspname, dbname, name, rootdir=rootdir, color=color) |
| 297 | 367 | ||
| 298 | - # Show plot | ||
| 299 | - plt.show() | 368 | + # Show figure |
| 369 | + if len(plotfile) > 0: | ||
| 370 | + plt.savefig(plotfile) | ||
| 371 | + else: | ||
| 372 | + plt.show() |
examples/show_sensitivity.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script displays a differential sensitivity plot generated by cssens. | 3 | +# Display differential sensitivity plot generated by cssens |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2015-2016 Juergen Knoedlseder |
| 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 |
| @@ -23,8 +23,11 @@ import math | @@ -23,8 +23,11 @@ import math | ||
| 23 | import gammalib | 23 | import gammalib |
| 24 | try: | 24 | try: |
| 25 | import matplotlib.pyplot as plt | 25 | import matplotlib.pyplot as plt |
| 26 | + plt.figure() | ||
| 27 | + plt.close() | ||
| 26 | except: | 28 | except: |
| 27 | - sys.exit("This script needs matplotlib") | 29 | + print('This script needs the "matplotlib" module') |
| 30 | + sys.exit() | ||
| 28 | 31 | ||
| 29 | 32 | ||
| 30 | # ===================== # | 33 | # ===================== # |
| @@ -32,7 +35,17 @@ except: | @@ -32,7 +35,17 @@ except: | ||
| 32 | # ===================== # | 35 | # ===================== # |
| 33 | def read_sensitivity(filename): | 36 | def read_sensitivity(filename): |
| 34 | """ | 37 | """ |
| 35 | - Read sensitivity information from CSV file. | 38 | + Read sensitivity information from CSV file |
| 39 | + | ||
| 40 | + Parameters | ||
| 41 | + ---------- | ||
| 42 | + filename : str | ||
| 43 | + Name of CSV file | ||
| 44 | + | ||
| 45 | + Returns | ||
| 46 | + ------- | ||
| 47 | + sensitivity : dict | ||
| 48 | + Dictionary with sensitivity information | ||
| 36 | """ | 49 | """ |
| 37 | # Read filename | 50 | # Read filename |
| 38 | csv = gammalib.GCsv(filename,',') | 51 | csv = gammalib.GCsv(filename,',') |
| @@ -40,39 +53,39 @@ def read_sensitivity(filename): | @@ -40,39 +53,39 @@ def read_sensitivity(filename): | ||
| 40 | # Create dictionnary | 53 | # Create dictionnary |
| 41 | sensitivity = {} | 54 | sensitivity = {} |
| 42 | for column in range(csv.ncols()): | 55 | for column in range(csv.ncols()): |
| 43 | - name = csv[0,column] | 56 | + name = csv[0,column].rstrip('\r') |
| 44 | values = [] | 57 | values = [] |
| 45 | for row in range(csv.nrows()-1): | 58 | for row in range(csv.nrows()-1): |
| 46 | values.append(float(csv[row+1,column])) | 59 | values.append(float(csv[row+1,column])) |
| 47 | sensitivity[name] = values | 60 | sensitivity[name] = values |
| 48 | 61 | ||
| 49 | # Check where file contains differential or integral sensitivity | 62 | # Check where file contains differential or integral sensitivity |
| 50 | - mode = "Integral" | ||
| 51 | - if sensitivity.has_key("emax"): | 63 | + mode = 'Integral' |
| 64 | + if sensitivity.has_key('emax'): | ||
| 52 | emax_ref = -1.0 | 65 | emax_ref = -1.0 |
| 53 | - for value in sensitivity["emax"]: | 66 | + for value in sensitivity['emax']: |
| 54 | if emax_ref < 0.0: | 67 | if emax_ref < 0.0: |
| 55 | emax_ref = value | 68 | emax_ref = value |
| 56 | elif emax_ref != value: | 69 | elif emax_ref != value: |
| 57 | - mode = "Differential" | 70 | + mode = 'Differential' |
| 58 | break | 71 | break |
| 59 | 72 | ||
| 60 | # Add mode | 73 | # Add mode |
| 61 | - sensitivity["mode"] = mode | 74 | + sensitivity['mode'] = mode |
| 62 | 75 | ||
| 63 | # Add linear energy values | 76 | # Add linear energy values |
| 64 | - if mode == "Differential": | ||
| 65 | - if sensitivity.has_key("loge"): | 77 | + if mode == 'Differential': |
| 78 | + if sensitivity.has_key('loge'): | ||
| 66 | name = 'energy' | 79 | name = 'energy' |
| 67 | values = [] | 80 | values = [] |
| 68 | - for value in sensitivity["loge"]: | 81 | + for value in sensitivity['loge']: |
| 69 | values.append(math.pow(10.0, value)) | 82 | values.append(math.pow(10.0, value)) |
| 70 | sensitivity[name] = values | 83 | sensitivity[name] = values |
| 71 | else: | 84 | else: |
| 72 | - if sensitivity.has_key("emin"): | 85 | + if sensitivity.has_key('emin'): |
| 73 | name = 'energy' | 86 | name = 'energy' |
| 74 | values = [] | 87 | values = [] |
| 75 | - for value in sensitivity["emin"]: | 88 | + for value in sensitivity['emin']: |
| 76 | values.append(value) | 89 | values.append(value) |
| 77 | sensitivity[name] = values | 90 | sensitivity[name] = values |
| 78 | 91 | ||
| @@ -83,9 +96,18 @@ def read_sensitivity(filename): | @@ -83,9 +96,18 @@ def read_sensitivity(filename): | ||
| 83 | # ===================== # | 96 | # ===================== # |
| 84 | # Show sensitivity data # | 97 | # Show sensitivity data # |
| 85 | # ===================== # | 98 | # ===================== # |
| 86 | -def show_sensitivity(sensitivity, filename): | 99 | +def show_sensitivity(sensitivity, filename, plotfile=''): |
| 87 | """ | 100 | """ |
| 88 | - Plot sensitivity. | 101 | + Plot sensitivity data |
| 102 | + | ||
| 103 | + Parameters | ||
| 104 | + ---------- | ||
| 105 | + sensitivity : dict | ||
| 106 | + Dictionary with sensitivity information | ||
| 107 | + filename : str | ||
| 108 | + Name of CSV file | ||
| 109 | + plotfile : str, optional | ||
| 110 | + Plot file name | ||
| 89 | """ | 111 | """ |
| 90 | # Build title | 112 | # Build title |
| 91 | title = sensitivity['mode'] + ' sensitivity ('+filename+')' | 113 | title = sensitivity['mode'] + ' sensitivity ('+filename+')' |
| @@ -102,14 +124,17 @@ def show_sensitivity(sensitivity, filename): | @@ -102,14 +124,17 @@ def show_sensitivity(sensitivity, filename): | ||
| 102 | plt.plot(sensitivity['energy'], sensitivity['sensitivity'], 'ro-') | 124 | plt.plot(sensitivity['energy'], sensitivity['sensitivity'], 'ro-') |
| 103 | 125 | ||
| 104 | # Set labels | 126 | # Set labels |
| 105 | - plt.xlabel("Energy (TeV)") | ||
| 106 | - if sensitivity['mode'] == "Differential": | ||
| 107 | - plt.ylabel(r"E$\times$ F(E) (erg cm$^{-2}$ s$^{-1}$)") | 127 | + plt.xlabel('Energy (TeV)') |
| 128 | + if sensitivity['mode'] == 'Differential': | ||
| 129 | + plt.ylabel(r'E $\times$ F(E) (erg cm$^{-2}$ s$^{-1}$)') | ||
| 108 | else: | 130 | else: |
| 109 | - plt.ylabel(r"E$\times$ F($>$E) (erg cm$^{-2}$ s$^{-1}$)") | 131 | + plt.ylabel(r'E $\times$ F($>$E) (erg cm$^{-2}$ s$^{-1}$)') |
| 110 | 132 | ||
| 111 | - # Show plot | ||
| 112 | - plt.show() | 133 | + # Show figure |
| 134 | + if len(plotfile) > 0: | ||
| 135 | + plt.savefig(plotfile) | ||
| 136 | + else: | ||
| 137 | + plt.show() | ||
| 113 | 138 | ||
| 114 | # Return | 139 | # Return |
| 115 | return | 140 | return |
| @@ -119,12 +144,11 @@ def show_sensitivity(sensitivity, filename): | @@ -119,12 +144,11 @@ def show_sensitivity(sensitivity, filename): | ||
| 119 | # Main routine entry point # | 144 | # Main routine entry point # |
| 120 | # ======================== # | 145 | # ======================== # |
| 121 | if __name__ == '__main__': | 146 | if __name__ == '__main__': |
| 122 | - """ | ||
| 123 | - """ | 147 | + |
| 124 | # Print usage information | 148 | # Print usage information |
| 125 | - usage = "Usage: show_sensitivity [filename]" | 149 | + usage = 'Usage: show_sensitivity.py [filename] [file]' |
| 126 | if len(sys.argv) < 1: | 150 | if len(sys.argv) < 1: |
| 127 | - sys.stdout.write(usage+"\n") | 151 | + print(usage) |
| 128 | sys.exit() | 152 | sys.exit() |
| 129 | 153 | ||
| 130 | # Extract parameters | 154 | # Extract parameters |
| @@ -132,9 +156,12 @@ if __name__ == '__main__': | @@ -132,9 +156,12 @@ if __name__ == '__main__': | ||
| 132 | filename = 'sensitivity.dat' | 156 | filename = 'sensitivity.dat' |
| 133 | else: | 157 | else: |
| 134 | filename = sys.argv[1] | 158 | filename = sys.argv[1] |
| 159 | + plotfile = '' | ||
| 160 | + if len(sys.argv) == 3: | ||
| 161 | + plotfile = sys.argv[2] | ||
| 135 | 162 | ||
| 136 | # Read sensitivity data | 163 | # Read sensitivity data |
| 137 | sensitivity = read_sensitivity(filename) | 164 | sensitivity = read_sensitivity(filename) |
| 138 | 165 | ||
| 139 | # Show sensitivity data | 166 | # Show sensitivity data |
| 140 | - show_sensitivity(sensitivity, filename) | 167 | + show_sensitivity(sensitivity, filename, plotfile=plotfile) |
examples/show_spectrum.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script shows a spectrum created with csspec | 3 | +# Display spectrum generated by csspec |
| 4 | # | 4 | # |
| 5 | # Copyright (C) 2015-2016 Juergen Knoedlseder | 5 | # Copyright (C) 2015-2016 Juergen Knoedlseder |
| 6 | # | 6 | # |
| @@ -18,37 +18,41 @@ | @@ -18,37 +18,41 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | - | ||
| 22 | -import gammalib | ||
| 23 | import sys | 21 | import sys |
| 22 | +import gammalib | ||
| 24 | try: | 23 | try: |
| 25 | import matplotlib.pyplot as plt | 24 | import matplotlib.pyplot as plt |
| 25 | + plt.figure() | ||
| 26 | + plt.close() | ||
| 26 | except: | 27 | except: |
| 27 | - sys.exit("This script needs matplotlib") | 28 | + print('This script needs the "matplotlib" module') |
| 29 | + sys.exit() | ||
| 28 | 30 | ||
| 29 | 31 | ||
| 30 | -# ============ # | ||
| 31 | -# Script entry # | ||
| 32 | -# ============ # | ||
| 33 | -if __name__ == "__main__": | ||
| 34 | - """ | 32 | +# ============= # |
| 33 | +# Show spectrum # | ||
| 34 | +# ============= # | ||
| 35 | +def show_spectrum(filename, plotfile=''): | ||
| 35 | """ | 36 | """ |
| 37 | + Plot sensitivity data | ||
| 36 | 38 | ||
| 37 | - # Check for given spectrum file | ||
| 38 | - if not len(sys.argv) == 2: | ||
| 39 | - sys.exit("Usage: show_spectrum.py spectrum.fits") | ||
| 40 | - | 39 | + Parameters |
| 40 | + ---------- | ||
| 41 | + filename : str | ||
| 42 | + Name of spectrum FITS file | ||
| 43 | + plotfile : str, optional | ||
| 44 | + Plot file name | ||
| 45 | + """ | ||
| 41 | # Read spectrum file | 46 | # Read spectrum file |
| 42 | - filename = sys.argv[1] | ||
| 43 | fits = gammalib.GFits(filename) | 47 | fits = gammalib.GFits(filename) |
| 44 | table = fits.table(1) | 48 | table = fits.table(1) |
| 45 | - c_energy = table["Energy"] | ||
| 46 | - c_ed = table["ed_Energy"] | ||
| 47 | - c_eu = table["eu_Energy"] | ||
| 48 | - c_flux = table["Flux"] | ||
| 49 | - c_eflux = table["e_Flux"] | ||
| 50 | - c_ts = table["TS"] | ||
| 51 | - c_upper = table["UpperLimit"] | 49 | + c_energy = table['Energy'] |
| 50 | + c_ed = table['ed_Energy'] | ||
| 51 | + c_eu = table['eu_Energy'] | ||
| 52 | + c_flux = table['Flux'] | ||
| 53 | + c_eflux = table['e_Flux'] | ||
| 54 | + c_ts = table['TS'] | ||
| 55 | + c_upper = table['UpperLimit'] | ||
| 52 | 56 | ||
| 53 | # Initialise arrays to be filled | 57 | # Initialise arrays to be filled |
| 54 | energies = [] | 58 | energies = [] |
| @@ -65,25 +69,22 @@ if __name__ == "__main__": | @@ -65,25 +69,22 @@ if __name__ == "__main__": | ||
| 65 | nrows = table.nrows() | 69 | nrows = table.nrows() |
| 66 | for row in range(nrows): | 70 | for row in range(nrows): |
| 67 | 71 | ||
| 68 | - # Get TS | 72 | + # Get Test Statistic, flux and flux error |
| 69 | ts = c_ts.real(row) | 73 | ts = c_ts.real(row) |
| 70 | flx = c_flux.real(row) | 74 | flx = c_flux.real(row) |
| 71 | e_flx = c_eflux.real(row) | 75 | e_flx = c_eflux.real(row) |
| 72 | 76 | ||
| 73 | - # Switch | 77 | + # If Test Statistic is larger than 9 and flux error is smaller than |
| 78 | + # flux then append flux plots ... | ||
| 74 | if ts > 9.0 and e_flx < flx: | 79 | if ts > 9.0 and e_flx < flx: |
| 75 | - | ||
| 76 | - # Add information | ||
| 77 | energies.append(c_energy.real(row)) | 80 | energies.append(c_energy.real(row)) |
| 78 | flux.append(c_flux.real(row)) | 81 | flux.append(c_flux.real(row)) |
| 79 | ed_engs.append(c_ed.real(row)) | 82 | ed_engs.append(c_ed.real(row)) |
| 80 | eu_engs.append(c_eu.real(row)) | 83 | eu_engs.append(c_eu.real(row)) |
| 81 | e_flux.append(c_eflux.real(row)) | 84 | e_flux.append(c_eflux.real(row)) |
| 82 | 85 | ||
| 83 | - # | 86 | + # ... otherwise append upper limit |
| 84 | else: | 87 | else: |
| 85 | - | ||
| 86 | - # Add information | ||
| 87 | ul_energies.append(c_energy.real(row)) | 88 | ul_energies.append(c_energy.real(row)) |
| 88 | ul_flux.append(c_upper.real(row)) | 89 | ul_flux.append(c_upper.real(row)) |
| 89 | ul_ed_engs.append(c_ed.real(row)) | 90 | ul_ed_engs.append(c_ed.real(row)) |
| @@ -93,8 +94,39 @@ if __name__ == "__main__": | @@ -93,8 +94,39 @@ if __name__ == "__main__": | ||
| 93 | plt.figure() | 94 | plt.figure() |
| 94 | plt.loglog() | 95 | plt.loglog() |
| 95 | plt.grid() | 96 | plt.grid() |
| 96 | - plt.errorbar(energies, flux, yerr=e_flux, xerr=[ed_engs, eu_engs], fmt='ro') | ||
| 97 | - plt.errorbar(ul_energies, ul_flux, xerr=[ul_ed_engs, ul_eu_engs], yerr=1.0e-11, uplims=True, fmt='ro') | ||
| 98 | - plt.xlabel("Energy (TeV)") | ||
| 99 | - plt.ylabel(r"E dN/dE (erg cm$^{-2}$ s$^{-1}$)") | ||
| 100 | - plt.show() | 97 | + plt.errorbar(energies, flux, yerr=e_flux, xerr=[ed_engs, eu_engs], |
| 98 | + fmt='ro') | ||
| 99 | + plt.errorbar(ul_energies, ul_flux, xerr=[ul_ed_engs, ul_eu_engs], | ||
| 100 | + yerr=1.0e-11, uplims=True, fmt='ro') | ||
| 101 | + plt.xlabel('Energy (TeV)') | ||
| 102 | + plt.ylabel(r'E $\times$ dN/dE (erg cm$^{-2}$ s$^{-1}$)') | ||
| 103 | + | ||
| 104 | + # Show figure | ||
| 105 | + if len(plotfile) > 0: | ||
| 106 | + plt.savefig(plotfile) | ||
| 107 | + else: | ||
| 108 | + plt.show() | ||
| 109 | + | ||
| 110 | + # Return | ||
| 111 | + return | ||
| 112 | + | ||
| 113 | + | ||
| 114 | +# ======================== # | ||
| 115 | +# Main routine entry point # | ||
| 116 | +# ======================== # | ||
| 117 | +if __name__ == '__main__': | ||
| 118 | + | ||
| 119 | + # Print usage information | ||
| 120 | + usage = 'Usage: show_spectrum.py filename [file]' | ||
| 121 | + if len(sys.argv) < 2: | ||
| 122 | + print(usage) | ||
| 123 | + sys.exit() | ||
| 124 | + | ||
| 125 | + # Extract parameters | ||
| 126 | + filename = sys.argv[1] | ||
| 127 | + plotfile = '' | ||
| 128 | + if len(sys.argv) == 3: | ||
| 129 | + plotfile = sys.argv[2] | ||
| 130 | + | ||
| 131 | + # Show spectrum | ||
| 132 | + show_spectrum(filename, plotfile=plotfile) |
examples/show_ts_distribution.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script displays the TS distribution values generated using cstsdist. | 3 | +# Display TS distribution generated by cstsdist |
| 4 | # | 4 | # |
| 5 | -# Required 3rd party modules: | ||
| 6 | -# - matplotlib | ||
| 7 | -# - numpy | ||
| 8 | -# | ||
| 9 | -# Copyright (C) 2011 Jurgen Knodlseder | 5 | +# Copyright (C) 2011-2016 Jurgen Knodlseder |
| 10 | # | 6 | # |
| 11 | # 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 |
| 12 | # 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 |
| @@ -22,20 +18,42 @@ | @@ -22,20 +18,42 @@ | ||
| 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | # | 19 | # |
| 24 | # ========================================================================== | 20 | # ========================================================================== |
| 25 | -import matplotlib.mlab as mlab | ||
| 26 | -import matplotlib.pyplot as plt | ||
| 27 | -import numpy as np | ||
| 28 | import sys | 21 | import sys |
| 29 | import csv | 22 | import csv |
| 30 | import math | 23 | import math |
| 24 | +try: | ||
| 25 | + import matplotlib.pyplot as plt | ||
| 26 | + import matplotlib.mlab as mlab | ||
| 27 | + plt.figure() | ||
| 28 | + plt.close() | ||
| 29 | +except: | ||
| 30 | + print('This script needs the "matplotlib" module') | ||
| 31 | + sys.exit() | ||
| 32 | +try: | ||
| 33 | + import numpy as np | ||
| 34 | +except: | ||
| 35 | + print('This script needs the "numpy" module') | ||
| 36 | + sys.exit() | ||
| 31 | 37 | ||
| 32 | 38 | ||
| 33 | # ==================== # | 39 | # ==================== # |
| 34 | # Read TS distribution # | 40 | # Read TS distribution # |
| 35 | # ==================== # | 41 | # ==================== # |
| 36 | -def read_ts(filename, tsname="TS"): | 42 | +def read_ts(filename, tsname='TS'): |
| 37 | """ | 43 | """ |
| 38 | - Read TS distribution values from CSV file. | 44 | + Read TS distribution values from CSV file |
| 45 | + | ||
| 46 | + Parameters | ||
| 47 | + ---------- | ||
| 48 | + filename : str | ||
| 49 | + Name of CSV file | ||
| 50 | + tsname : str, optional | ||
| 51 | + Column name of TS | ||
| 52 | + | ||
| 53 | + Returns | ||
| 54 | + ------- | ||
| 55 | + a : `numpy.array` | ||
| 56 | + Array of TS values | ||
| 39 | """ | 57 | """ |
| 40 | # Initialise list | 58 | # Initialise list |
| 41 | values = [] | 59 | values = [] |
| @@ -53,9 +71,9 @@ def read_ts(filename, tsname="TS"): | @@ -53,9 +71,9 @@ def read_ts(filename, tsname="TS"): | ||
| 53 | try: | 71 | try: |
| 54 | index = row.index(tsname) | 72 | index = row.index(tsname) |
| 55 | except: | 73 | except: |
| 56 | - sys.stdout.write('ERROR: Column "TS" not found in file\n') | ||
| 57 | - sys.stdout.write(row+"\n") | ||
| 58 | - raise NameError("TS") | 74 | + print('ERROR: Column "'+tsname+'" not found in file') |
| 75 | + print(row) | ||
| 76 | + raise NameError(tsname) | ||
| 59 | 77 | ||
| 60 | # Handle data rows | 78 | # Handle data rows |
| 61 | else: | 79 | else: |
| @@ -76,7 +94,17 @@ def read_ts(filename, tsname="TS"): | @@ -76,7 +94,17 @@ def read_ts(filename, tsname="TS"): | ||
| 76 | # =========== # | 94 | # =========== # |
| 77 | def erf(x): | 95 | def erf(x): |
| 78 | """ | 96 | """ |
| 79 | - Compute error function. | 97 | + Compute error function |
| 98 | + | ||
| 99 | + Parameters | ||
| 100 | + ---------- | ||
| 101 | + x : float | ||
| 102 | + Value | ||
| 103 | + | ||
| 104 | + Returns | ||
| 105 | + ------- | ||
| 106 | + erf(-x) : float | ||
| 107 | + Error function | ||
| 80 | """ | 108 | """ |
| 81 | # save the sign of x | 109 | # save the sign of x |
| 82 | sign = 1 | 110 | sign = 1 |
| @@ -103,9 +131,20 @@ def erf(x): | @@ -103,9 +131,20 @@ def erf(x): | ||
| 103 | # =============================== # | 131 | # =============================== # |
| 104 | # Display cumulative distribution # | 132 | # Display cumulative distribution # |
| 105 | # =============================== # | 133 | # =============================== # |
| 106 | -def dist_cdf(values, nbins, title): | 134 | +def dist_cdf(values, nbins, title, expect='', plotfile=''): |
| 107 | """ | 135 | """ |
| 108 | - Displays cumulative TS distribution and overplots expectation. | 136 | + Display cumulative TS distribution and overplots expectation |
| 137 | + | ||
| 138 | + Parameters | ||
| 139 | + ---------- | ||
| 140 | + values : float | ||
| 141 | + TS values | ||
| 142 | + nbins : int | ||
| 143 | + Number of bins | ||
| 144 | + title : str | ||
| 145 | + Plot title | ||
| 146 | + plotfile : str, optional | ||
| 147 | + Plot file name | ||
| 109 | """ | 148 | """ |
| 110 | # Set range and adapt number of bins. We make sure that we have a | 149 | # Set range and adapt number of bins. We make sure that we have a |
| 111 | # histogram bin centred on 0 that will capture the TS=0 part. | 150 | # histogram bin centred on 0 that will capture the TS=0 part. |
| @@ -142,19 +181,23 @@ def dist_cdf(values, nbins, title): | @@ -142,19 +181,23 @@ def dist_cdf(values, nbins, title): | ||
| 142 | hist_expect.append(norm) | 181 | hist_expect.append(norm) |
| 143 | 182 | ||
| 144 | # Show expected distribution (half) | 183 | # Show expected distribution (half) |
| 145 | - l = plt.semilogy(hist_x, hist_y, 'r-', linewidth=2, label="simulations") | ||
| 146 | - l = plt.semilogy(hist_x, hist_expect, 'k-', linewidth=2, label="expectation") | ||
| 147 | - l = plt.semilogy(hist_x, hist_y, 'r-', linewidth=2) | 184 | + plt.semilogy(hist_x, hist_y, 'r-', linewidth=2, label='simulations') |
| 185 | + if expect == 'show': | ||
| 186 | + plt.semilogy(hist_x, hist_expect, 'k-', linewidth=2, label='expectation') | ||
| 187 | + plt.semilogy(hist_x, hist_y, 'r-', linewidth=2) | ||
| 148 | 188 | ||
| 149 | # Set plot | 189 | # Set plot |
| 150 | plt.xlabel('TS') | 190 | plt.xlabel('TS') |
| 151 | plt.ylabel('Number of trials > TS') | 191 | plt.ylabel('Number of trials > TS') |
| 152 | plt.title(title) | 192 | plt.title(title) |
| 153 | plt.grid(True) | 193 | plt.grid(True) |
| 154 | - plt.legend(loc="upper right") | 194 | + plt.legend(loc='upper right') |
| 155 | 195 | ||
| 156 | - # Show histogram | ||
| 157 | - plt.show() | 196 | + # Show figure |
| 197 | + if len(plotfile) > 0: | ||
| 198 | + plt.savefig(plotfile) | ||
| 199 | + else: | ||
| 200 | + plt.show() | ||
| 158 | 201 | ||
| 159 | # Return | 202 | # Return |
| 160 | return | 203 | return |
| @@ -163,10 +206,20 @@ def dist_cdf(values, nbins, title): | @@ -163,10 +206,20 @@ def dist_cdf(values, nbins, title): | ||
| 163 | # ======================================== # | 206 | # ======================================== # |
| 164 | # Display probability density distribution # | 207 | # Display probability density distribution # |
| 165 | # ======================================== # | 208 | # ======================================== # |
| 166 | -def dist_pdf(values, nbins, title): | 209 | +def dist_pdf(values, nbins, title, expect='', plotfile=''): |
| 167 | """ | 210 | """ |
| 168 | - Display probability density TS distribution and overplots | ||
| 169 | - expectation. | 211 | + Display probability density TS distribution and overplots expectation |
| 212 | + | ||
| 213 | + Parameters | ||
| 214 | + ---------- | ||
| 215 | + values : float | ||
| 216 | + TS values | ||
| 217 | + nbins : int | ||
| 218 | + Number of bins | ||
| 219 | + title : str | ||
| 220 | + Plot title | ||
| 221 | + plotfile : str, optional | ||
| 222 | + Plot file name | ||
| 170 | """ | 223 | """ |
| 171 | # Set range and adapt number of bins. We make sure that we have a | 224 | # Set range and adapt number of bins. We make sure that we have a |
| 172 | # histogram bin centred on 0 that will capture the TS=0 part. | 225 | # histogram bin centred on 0 that will capture the TS=0 part. |
| @@ -180,9 +233,9 @@ def dist_pdf(values, nbins, title): | @@ -180,9 +233,9 @@ def dist_pdf(values, nbins, title): | ||
| 180 | # Create histogram | 233 | # Create histogram |
| 181 | n, bins, patches = plt.hist(values, nbins, range=[min_value, max_value], | 234 | n, bins, patches = plt.hist(values, nbins, range=[min_value, max_value], |
| 182 | align='mid', facecolor='green', | 235 | align='mid', facecolor='green', |
| 183 | - log=True, label="simulations") | 236 | + log=True, label='simulations') |
| 184 | 237 | ||
| 185 | - # Create expected distribution (onyl for positive TS). We compute the | 238 | + # Create expected distribution (only for positive TS). We compute the |
| 186 | # full and half of the distribution, as for positively constrained | 239 | # full and half of the distribution, as for positively constrained |
| 187 | # quantities half of the values have TS=0 | 240 | # quantities half of the values have TS=0 |
| 188 | x = [] | 241 | x = [] |
| @@ -202,47 +255,48 @@ def dist_pdf(values, nbins, title): | @@ -202,47 +255,48 @@ def dist_pdf(values, nbins, title): | ||
| 202 | y_half.append(0.5*y) | 255 | y_half.append(0.5*y) |
| 203 | 256 | ||
| 204 | # Show expected distribution (half) | 257 | # Show expected distribution (half) |
| 205 | - l = plt.semilogy(x, y_half, 'ro', linewidth=2, label="expectation") | 258 | + if expect == 'show': |
| 259 | + plt.semilogy(x, y_half, 'ro', linewidth=2, label='expectation') | ||
| 206 | 260 | ||
| 207 | # Set plot | 261 | # Set plot |
| 208 | plt.xlabel('TS') | 262 | plt.xlabel('TS') |
| 209 | plt.ylabel('Number of trials') | 263 | plt.ylabel('Number of trials') |
| 210 | plt.title(title) | 264 | plt.title(title) |
| 211 | plt.grid(True) | 265 | plt.grid(True) |
| 212 | - plt.legend(loc="upper right") | 266 | + plt.legend(loc='upper right') |
| 213 | 267 | ||
| 214 | - # Show histogram | ||
| 215 | - plt.show() | 268 | + # Show figure |
| 269 | + if len(plotfile) > 0: | ||
| 270 | + plt.savefig(plotfile) | ||
| 271 | + else: | ||
| 272 | + plt.show() | ||
| 273 | + | ||
| 274 | + # Return | ||
| 275 | + return | ||
| 216 | 276 | ||
| 217 | 277 | ||
| 218 | # ======================== # | 278 | # ======================== # |
| 219 | # Main routine entry point # | 279 | # Main routine entry point # |
| 220 | # ======================== # | 280 | # ======================== # |
| 221 | if __name__ == '__main__': | 281 | if __name__ == '__main__': |
| 222 | - """ | ||
| 223 | - Display TS distribution generated using cstsdist using matplotlib. | ||
| 224 | - """ | 282 | + |
| 225 | # Print usage information | 283 | # Print usage information |
| 226 | - usage = "Usage: show_ts_distribution filename" \ | ||
| 227 | - " [-n bins] [-c column] [-t title] [-p plot]" | 284 | + usage = 'Usage: show_ts_distribution.py filename' \ |
| 285 | + ' [-n bins] [-c column] [-t title] [-p plot] [-f file]' | ||
| 228 | if len(sys.argv) < 2: | 286 | if len(sys.argv) < 2: |
| 229 | - sys.stdout.write(usage+"\n") | 287 | + print(usage) |
| 230 | sys.exit() | 288 | sys.exit() |
| 231 | 289 | ||
| 232 | # Extract parameters | 290 | # Extract parameters |
| 233 | filename = sys.argv[1] | 291 | filename = sys.argv[1] |
| 234 | 292 | ||
| 235 | - # Set default parameters | ||
| 236 | - nbins = 30 | ||
| 237 | - tsname = "TS" | ||
| 238 | - title = "TS distribution" | ||
| 239 | - plot = "pdf" | ||
| 240 | - | ||
| 241 | # Parameter dictionnary | 293 | # Parameter dictionnary |
| 242 | - pars = [{'option': '-n', 'value': nbins}, | ||
| 243 | - {'option': '-c', 'value': tsname}, | ||
| 244 | - {'option': '-t', 'value': title}, | ||
| 245 | - {'option': '-p', 'value': plot}] | 294 | + pars = [{'option': '-n', 'value': 30}, |
| 295 | + {'option': '-c', 'value': 'TS'}, | ||
| 296 | + {'option': '-t', 'value': 'TS distribution'}, | ||
| 297 | + {'option': '-p', 'value': 'pdf'}, | ||
| 298 | + {'option': '-e', 'value': ''}, | ||
| 299 | + {'option': '-f', 'value': ''}] | ||
| 246 | 300 | ||
| 247 | # Gather parameters from command line | 301 | # Gather parameters from command line |
| 248 | i = 2 | 302 | i = 2 |
| @@ -256,27 +310,29 @@ if __name__ == '__main__': | @@ -256,27 +310,29 @@ if __name__ == '__main__': | ||
| 256 | try: | 310 | try: |
| 257 | par['value'] = sys.argv[i] | 311 | par['value'] = sys.argv[i] |
| 258 | except: | 312 | except: |
| 259 | - sys.stdout.write(usage+"\n") | 313 | + print(usage) |
| 260 | sys.exit() | 314 | sys.exit() |
| 261 | else: | 315 | else: |
| 262 | - sys.stdout.write(usage+"\n") | 316 | + print(usage) |
| 263 | sys.exit() | 317 | sys.exit() |
| 264 | 318 | ||
| 265 | # Next item | 319 | # Next item |
| 266 | i += 1 | 320 | i += 1 |
| 267 | 321 | ||
| 268 | # Recover parameters | 322 | # Recover parameters |
| 269 | - nbins = int(pars[0]['value']) | ||
| 270 | - tsname = pars[1]['value'] | ||
| 271 | - title = pars[2]['value'] | ||
| 272 | - plot = pars[3]['value'] | 323 | + nbins = int(pars[0]['value']) |
| 324 | + tsname = pars[1]['value'] | ||
| 325 | + title = pars[2]['value'] | ||
| 326 | + plot = pars[3]['value'] | ||
| 327 | + expect = pars[4]['value'] | ||
| 328 | + plotfile = pars[5]['value'] | ||
| 273 | 329 | ||
| 274 | # Read values from CSV file | 330 | # Read values from CSV file |
| 275 | values = read_ts(filename, tsname=tsname) | 331 | values = read_ts(filename, tsname=tsname) |
| 276 | - sys.stdout.write(len(values), "values read.\n") | 332 | + print('%d values read.' % len(values)) |
| 277 | 333 | ||
| 278 | # Show histogram | 334 | # Show histogram |
| 279 | - if plot == "pdf": | ||
| 280 | - dist_pdf(values, nbins, title) | 335 | + if plot == 'pdf': |
| 336 | + dist_pdf(values, nbins, title, expect=expect, plotfile=plotfile) | ||
| 281 | else: | 337 | else: |
| 282 | - dist_cdf(values, nbins, title) | 338 | + dist_cdf(values, nbins, title, expect=expect, plotfile=plotfile) |
sonar-project.properties
0 → 100644
| 1 | +# Required metadata | ||
| 2 | +sonar.projectKey=ctools | ||
| 3 | +sonar.projectName=ctools | ||
| 4 | +sonar.projectVersion=1.1.0.dev1 | ||
| 5 | + | ||
| 6 | +# Description | ||
| 7 | +sonar.projectDescription="Cherenkov Telescope Array Science Analysis Software" | ||
| 8 | + | ||
| 9 | +# Links | ||
| 10 | +sonar.links.ci=https://cta-jenkins.irap.omp.eu | ||
| 11 | +sonar.links.homepage=http://cta.irap.omp.eu/ctools | ||
| 12 | +sonar.links.issue=https://cta-redmine.irap.omp.eu/projects/ctools/issues | ||
| 13 | +sonar.links.scm=https://cta-gitlab.irap.omp.eu/ctools/ctools | ||
| 14 | + | ||
| 15 | +# Path to source directories | ||
| 16 | +sonar.sources=. | ||
| 17 | + | ||
| 18 | +# Path to tests | ||
| 19 | +#sonar.tests=test | ||
| 20 | + | ||
| 21 | +# Path to include directories | ||
| 22 | +sonar.cxx.includeDirectories=pyext,/home/jenkins/gcc/gcc492/include/c++/4.9.2,/home/jenkins/gcc/gcc492/include/c++/4.9.2/tr1,/home/jenkins/gcc/gcc492/include/c++/4.9.2/ext,/home/jenkins/gcc/gcc492/include/c++/4.9.2/x86_64-unknown-linux-gnu,/home/jenkins/gcc/gcc492/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/include,/usr/include,/usr/include/bits,/usr/include/gnu,/usr/include/linux | ||
| 23 | +sonar.cxx.missingIncludeWarnings=False | ||
| 24 | + | ||
| 25 | +# Exclusions | ||
| 26 | +sonar.exclusions=pyext/ctools/**,pyext/build/**,pyext/setup.py,doc/**,test/dev/** | ||
| 27 | +sonar.coverage.exclusions=pyext/ctools/**,pyext/build/**,examples/**,doc/**,test/dev/** | ||
| 28 | +#sonar.test.exclusions= | ||
| 29 | + | ||
| 30 | +# C++ configuration | ||
| 31 | +sonar.cxx.cppcheck.reportPath=cppcheck-result.xml | ||
| 32 | +sonar.cxx.cppncss.reportPath=cppncss-raw-report.xml | ||
| 33 | +#sonar.cxx.valgrind.reportPath=test/valgrind_test_*.xml | ||
| 34 | +sonar.cxx.xunit.reportPath=test/reports/*.xml | ||
| 35 | +#sonar.cxx.xunit.provideDetails=true | ||
| 36 | +#sonar.cxx.xunit.xsltURL=cppunit-1.x-to-junit-1.0.xsl | ||
| 37 | +sonar.cxx.coverage.reportPath=coverage-report-cxx.xml | ||
| 38 | + | ||
| 39 | +# Python configuration | ||
| 40 | +sonar.python.coverage.forceZeroCoverage=True | ||
| 41 | +sonar.python.coverage.reportPath=coverage-report-python.xml | ||
| 42 | +#sonar.python.xunit.reportPath=test/reports/*.xml |
src/support/ctool.cpp
| @@ -52,6 +52,7 @@ | @@ -52,6 +52,7 @@ | ||
| 52 | #define G_SETUP_OBSERVATION "ctool::setup_observations(GObservations&)" | 52 | #define G_SETUP_OBSERVATION "ctool::setup_observations(GObservations&)" |
| 53 | #define G_GET_MEAN_POINTING "ctool::get_mean_pointing(GObservations&)" | 53 | #define G_GET_MEAN_POINTING "ctool::get_mean_pointing(GObservations&)" |
| 54 | #define G_CREATE_EBOUNDS "ctool::create_ebounds()" | 54 | #define G_CREATE_EBOUNDS "ctool::create_ebounds()" |
| 55 | +#define G_SET_OBS_RESPONSE "ctool::set_obs_response(GCTAObservation*)" | ||
| 55 | #define G_PROVIDE_HELP "ctool::provide_help()" | 56 | #define G_PROVIDE_HELP "ctool::provide_help()" |
| 56 | 57 | ||
| 57 | /* __ Debug definitions __________________________________________________ */ | 58 | /* __ Debug definitions __________________________________________________ */ |
| @@ -931,6 +932,9 @@ void ctool::set_response(GObservations& obs) | @@ -931,6 +932,9 @@ void ctool::set_response(GObservations& obs) | ||
| 931 | * | 932 | * |
| 932 | * @param[in,out] obs CTA observation | 933 | * @param[in,out] obs CTA observation |
| 933 | * | 934 | * |
| 935 | + * @exception GException::invalid_value | ||
| 936 | + * Energy dispersion requested but not energy dispersion cube given | ||
| 937 | + * | ||
| 934 | * Set the response for one CTA observation. If the CTA observation contains | 938 | * Set the response for one CTA observation. If the CTA observation contains |
| 935 | * a counts cube the method first attempts to set the response information | 939 | * a counts cube the method first attempts to set the response information |
| 936 | * using the following user parameters | 940 | * using the following user parameters |
| @@ -964,13 +968,23 @@ void ctool::set_obs_response(GCTAObservation* obs) | @@ -964,13 +968,23 @@ void ctool::set_obs_response(GCTAObservation* obs) | ||
| 964 | // response information for a stacked analysis is provided, and if so, | 968 | // response information for a stacked analysis is provided, and if so, |
| 965 | // set that response information for the CTA observation | 969 | // set that response information for the CTA observation |
| 966 | if (dynamic_cast<const GCTAEventCube*>(obs->events()) != NULL) { | 970 | if (dynamic_cast<const GCTAEventCube*>(obs->events()) != NULL) { |
| 967 | - if (has_par("expcube") && has_par("psfcube") && | ||
| 968 | - has_par("edispcube") && has_par("bkgcube")) { | 971 | + |
| 972 | + // Check if response cube parameters are provided. We need all four | ||
| 973 | + // response cube parameters. | ||
| 974 | + if (has_par("expcube") && has_par("psfcube") && | ||
| 975 | + has_par("bkgcube") && has_par("edispcube")) { | ||
| 976 | + | ||
| 977 | + // Check if we need to query the energy dispersion cube. We do | ||
| 978 | + // not need to query the cube is an "edisp" parameter exists and | ||
| 979 | + // if this parameter is set to "no". | ||
| 980 | + bool query_edisp = true; | ||
| 981 | + if (has_par("edisp")) { | ||
| 982 | + query_edisp = (*this)["edisp"].boolean(); | ||
| 983 | + } | ||
| 969 | 984 | ||
| 970 | // Get filenames | 985 | // Get filenames |
| 971 | GFilename expcube((*this)["expcube"].filename()); | 986 | GFilename expcube((*this)["expcube"].filename()); |
| 972 | GFilename psfcube((*this)["psfcube"].filename()); | 987 | GFilename psfcube((*this)["psfcube"].filename()); |
| 973 | - GFilename edispcube((*this)["edispcube"].filename()); | ||
| 974 | GFilename bkgcube((*this)["bkgcube"].filename()); | 988 | GFilename bkgcube((*this)["bkgcube"].filename()); |
| 975 | 989 | ||
| 976 | // Extract stacked response information if available | 990 | // Extract stacked response information if available |
| @@ -981,21 +995,53 @@ void ctool::set_obs_response(GCTAObservation* obs) | @@ -981,21 +995,53 @@ void ctool::set_obs_response(GCTAObservation* obs) | ||
| 981 | !psfcube.is_empty() && | 995 | !psfcube.is_empty() && |
| 982 | !bkgcube.is_empty()) { | 996 | !bkgcube.is_empty()) { |
| 983 | 997 | ||
| 984 | - // Get exposure, PSF and background cubes | 998 | + // Load exposure, PSF and background cubes |
| 985 | GCTACubeExposure exposure(expcube); | 999 | GCTACubeExposure exposure(expcube); |
| 986 | GCTACubePsf psf(psfcube); | 1000 | GCTACubePsf psf(psfcube); |
| 987 | GCTACubeBackground background(bkgcube); | 1001 | GCTACubeBackground background(bkgcube); |
| 988 | 1002 | ||
| 989 | - // If an energy dispersion cube is available, get also | ||
| 990 | - // this cube, and set all information as stacked response | ||
| 991 | - // for this CTA observation | ||
| 992 | - if ((gammalib::toupper(edispcube.url()) != "NONE") && | ||
| 993 | - !edispcube.is_empty()) { | ||
| 994 | - GCTACubeEdisp edisp(edispcube); | ||
| 995 | - obs->response(exposure, psf, edisp, background); | ||
| 996 | - } | 1003 | + // If querying of energy dispersion cube is requested then |
| 1004 | + // query it now | ||
| 1005 | + if (query_edisp) { | ||
| 1006 | + | ||
| 1007 | + // Get filename | ||
| 1008 | + GFilename edispcube((*this)["edispcube"].filename()); | ||
| 1009 | + | ||
| 1010 | + // If filename is valid then use energy dispersion ... | ||
| 1011 | + if ((gammalib::toupper(edispcube.url()) != "NONE") && | ||
| 1012 | + !edispcube.is_empty()) { | ||
| 1013 | + | ||
| 1014 | + // Load energy dispersion cube | ||
| 1015 | + GCTACubeEdisp edisp(edispcube); | ||
| 1016 | + | ||
| 1017 | + // Set response with all four cubes | ||
| 1018 | + obs->response(exposure, psf, edisp, background); | ||
| 1019 | + | ||
| 1020 | + } // endif: energy dispersion cube was provided | ||
| 1021 | + | ||
| 1022 | + // ... otherwise work without energy dispersion | ||
| 1023 | + else { | ||
| 1024 | + | ||
| 1025 | + // If energy dispersion was requested but no cube | ||
| 1026 | + // was provided then throw an exception | ||
| 1027 | + if (has_par("edisp") && (*this)["edisp"].boolean()) { | ||
| 1028 | + std::string msg = "Energy dispersion requested but " | ||
| 1029 | + "no energy dispersion cube was " | ||
| 1030 | + "specified."; | ||
| 1031 | + throw GException::invalid_value(G_SET_OBS_RESPONSE, | ||
| 1032 | + msg); | ||
| 1033 | + } | ||
| 1034 | + | ||
| 1035 | + // Set response without energy dispersion | ||
| 1036 | + obs->response(exposure, psf, background); | ||
| 1037 | + | ||
| 1038 | + } // endelse: no energy dispersion was available | ||
| 1039 | + | ||
| 1040 | + } // endif: energy dispersion needed | ||
| 1041 | + | ||
| 1042 | + // ... otherwise work without energy dispersion | ||
| 997 | else { | 1043 | else { |
| 998 | - obs->response(exposure, psf, background); | 1044 | + obs->response(exposure, psf, background); |
| 999 | } | 1045 | } |
| 1000 | 1046 | ||
| 1001 | // Signal that response is available | 1047 | // Signal that response is available |
test/Makefile.am
| @@ -9,6 +9,7 @@ if WITH_PYTHON | @@ -9,6 +9,7 @@ if WITH_PYTHON | ||
| 9 | TEST_CSCRIPTS = test_cscripts.sh | 9 | TEST_CSCRIPTS = test_cscripts.sh |
| 10 | TEST_PYTHON_CTOOLS = test_python_ctools.sh | 10 | TEST_PYTHON_CTOOLS = test_python_ctools.sh |
| 11 | TEST_PYTHON_CSCRIPTS = test_python_cscripts.sh | 11 | TEST_PYTHON_CSCRIPTS = test_python_cscripts.sh |
| 12 | + TEST_PYTHON_EXAMPLES = test_examples.sh | ||
| 12 | TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir):$(top_builddir)/pyext:$(top_builddir)/pyext/build/ctools/ctools:$(pythondir):$(pyexecdir):$(PYTHONPATH) | 13 | TEST_PYTHON_ENV = PYTHONPATH=$(top_builddir):$(top_builddir)/pyext:$(top_builddir)/pyext/build/ctools/ctools:$(pythondir):$(pyexecdir):$(PYTHONPATH) |
| 13 | endif | 14 | endif |
| 14 | 15 | ||
| @@ -18,7 +19,8 @@ TESTS_ENVIRONMENT = @RUNSHARED@=$(top_builddir)/src/.libs$(TEST_ENV_DIR):$(LIBDI | @@ -18,7 +19,8 @@ TESTS_ENVIRONMENT = @RUNSHARED@=$(top_builddir)/src/.libs$(TEST_ENV_DIR):$(LIBDI | ||
| 18 | 19 | ||
| 19 | # Tests (these are the tests to be executed) | 20 | # Tests (these are the tests to be executed) |
| 20 | TESTS = $(TEST_PYTHON_CTOOLS) \ | 21 | TESTS = $(TEST_PYTHON_CTOOLS) \ |
| 21 | - $(TEST_PYTHON_CSCRIPTS) | 22 | + $(TEST_PYTHON_CSCRIPTS) \ |
| 23 | + $(TEST_PYTHON_EXAMPLES) | ||
| 22 | 24 | ||
| 23 | # Add Valgrind rule | 25 | # Add Valgrind rule |
| 24 | valgrind: | 26 | valgrind: |
test/README deleted
| 1 | -This folder contains files used for unit testing and files that serve | ||
| 2 | -as example scripts for ctools. | ||
| 3 | - | ||
| 4 | -test_cscripts.sh | ||
| 5 | - Unit test for cscripts. | ||
| 6 | - | ||
| 7 | -test_ctools.sh | ||
| 8 | - Unit test for ctools. | ||
| 9 | - | ||
| 10 | -test_python.py | ||
| 11 | - Unit test for ctools Python interface. | ||
| 12 | - | ||
| 13 | -example_models.py | ||
| 14 | - Example Python pipeline for unbinned analysis that is executed | ||
| 15 | - on a number of models (point source, disk source, Gaussian | ||
| 16 | - source, Shell source). | ||
| 17 | - | ||
| 18 | -example_survey.py | ||
| 19 | - This script illustrates how a survey can be simulated and analysed. | ||
| 20 | - The script can be easily extended to adapt specific survey | ||
| 21 | - strategies and simulated source models. |
test/README.md
0 → 100644
test/data/butterfly.txt
0 → 100644
| 1 | +103514 7.97876e-15 7.61983e-15 8.34788e-15 | ||
| 2 | +110917 6.72257e-15 6.4272e-15 7.02571e-15 | ||
| 3 | +118850 5.66416e-15 5.42109e-15 5.91312e-15 | ||
| 4 | +127350 4.77239e-15 4.57237e-15 4.97683e-15 | ||
| 5 | +136458 4.02101e-15 3.8564e-15 4.18893e-15 | ||
| 6 | +146218 3.38794e-15 3.25246e-15 3.52586e-15 | ||
| 7 | +156675 2.85454e-15 2.743e-15 2.96785e-15 | ||
| 8 | +167880 2.40511e-15 2.31326e-15 2.49824e-15 | ||
| 9 | +179887 2.02645e-15 1.95077e-15 2.10302e-15 | ||
| 10 | +192752 1.7074e-15 1.64502e-15 1.7704e-15 | ||
| 11 | +206538 1.43859e-15 1.38713e-15 1.49045e-15 | ||
| 12 | +221309 1.21209e-15 1.16962e-15 1.25483e-15 | ||
| 13 | +237137 1.02126e-15 9.86165e-16 1.05651e-15 | ||
| 14 | +254097 8.6047e-16 8.31443e-16 8.89582e-16 | ||
| 15 | +272270 7.24996e-16 7.00958e-16 7.49072e-16 | ||
| 16 | +291743 6.10851e-16 5.90916e-16 6.30794e-16 | ||
| 17 | +312608 5.14678e-16 4.9812e-16 5.31227e-16 | ||
| 18 | +334965 4.33646e-16 4.1987e-16 4.47406e-16 | ||
| 19 | +358922 3.65372e-16 3.53889e-16 3.76836e-16 | ||
| 20 | +384592 3.07847e-16 2.98257e-16 3.17421e-16 | ||
| 21 | +412098 2.59379e-16 2.51353e-16 2.67393e-16 | ||
| 22 | +441570 2.18542e-16 2.1181e-16 2.25268e-16 | ||
| 23 | +473151 1.84135e-16 1.78475e-16 1.89793e-16 | ||
| 24 | +506991 1.55144e-16 1.50375e-16 1.59917e-16 | ||
| 25 | +543250 1.30718e-16 1.26691e-16 1.34754e-16 | ||
| 26 | +582103 1.10138e-16 1.06729e-16 1.13559e-16 | ||
| 27 | +623735 9.27973e-17 8.99058e-17 9.57049e-17 | ||
| 28 | +668344 7.81872e-17 7.57292e-17 8.06636e-17 | ||
| 29 | +716143 6.58773e-17 6.37836e-17 6.79909e-17 | ||
| 30 | +767361 5.55054e-17 5.37188e-17 5.7313e-17 | ||
| 31 | +822243 4.67666e-17 4.52393e-17 4.83151e-17 | ||
| 32 | +881049 3.94036e-17 3.80959e-17 4.07323e-17 | ||
| 33 | +944061 3.31998e-17 3.20787e-17 3.43416e-17 | ||
| 34 | +1.01158e+06 2.79728e-17 2.70103e-17 2.89551e-17 | ||
| 35 | +1.08393e+06 2.35687e-17 2.27416e-17 2.44147e-17 | ||
| 36 | +1.16145e+06 1.9858e-17 1.91465e-17 2.05873e-17 | ||
| 37 | +1.24451e+06 1.67315e-17 1.6119e-17 1.73606e-17 | ||
| 38 | +1.33352e+06 1.40973e-17 1.35697e-17 1.46403e-17 | ||
| 39 | +1.42889e+06 1.18778e-17 1.1423e-17 1.23467e-17 | ||
| 40 | +1.53109e+06 1.00077e-17 9.61563e-18 1.04128e-17 | ||
| 41 | +1.64059e+06 8.4321e-18 8.09391e-18 8.78208e-18 | ||
| 42 | +1.75792e+06 7.10453e-18 6.81279e-18 7.40699e-18 | ||
| 43 | +1.88365e+06 5.98598e-18 5.73426e-18 6.24739e-18 | ||
| 44 | +2.01837e+06 5.04354e-18 4.82635e-18 5.26946e-18 | ||
| 45 | +2.16272e+06 4.24948e-18 4.06207e-18 4.44474e-18 | ||
| 46 | +2.31739e+06 3.58043e-18 3.41874e-18 3.74917e-18 | ||
| 47 | +2.48313e+06 3.01672e-18 2.87723e-18 3.16252e-18 | ||
| 48 | +2.66073e+06 2.54177e-18 2.42144e-18 2.66772e-18 | ||
| 49 | +2.85102e+06 2.14159e-18 2.03782e-18 2.25037e-18 | ||
| 50 | +3.05492e+06 1.80441e-18 1.71493e-18 1.89835e-18 | ||
| 51 | +3.27341e+06 1.52032e-18 1.44319e-18 1.60142e-18 | ||
| 52 | +3.50752e+06 1.28096e-18 1.21448e-18 1.35096e-18 | ||
| 53 | +3.75837e+06 1.07928e-18 1.02201e-18 1.13968e-18 | ||
| 54 | +4.02717e+06 9.09359e-19 8.60023e-19 9.61461e-19 | ||
| 55 | +4.31519e+06 7.66188e-19 7.23704e-19 8.11119e-19 | ||
| 56 | +4.62381e+06 6.45558e-19 6.08984e-19 6.84293e-19 | ||
| 57 | +4.9545e+06 5.43921e-19 5.12443e-19 5.77303e-19 | ||
| 58 | +5.30884e+06 4.58285e-19 4.31203e-19 4.87047e-19 | ||
| 59 | +5.68853e+06 3.86132e-19 3.62839e-19 4.10905e-19 | ||
| 60 | +6.09537e+06 3.25339e-19 3.0531e-19 3.46669e-19 | ||
| 61 | +6.53131e+06 2.74117e-19 2.569e-19 2.92478e-19 | ||
| 62 | +6.99842e+06 2.30959e-19 2.16165e-19 2.4676e-19 | ||
| 63 | +7.49894e+06 1.94597e-19 1.81887e-19 2.0819e-19 | ||
| 64 | +8.03526e+06 1.63959e-19 1.53044e-19 1.7565e-19 | ||
| 65 | +8.60994e+06 1.38145e-19 1.28773e-19 1.48196e-19 | ||
| 66 | +9.22571e+06 1.16395e-19 1.08351e-19 1.25035e-19 | ||
| 67 | +9.88553e+06 9.80699e-20 9.11675e-20 1.05493e-19 | ||
| 68 | +1.05925e+07 8.26296e-20 7.67083e-20 8.9007e-20 | ||
| 69 | +1.13501e+07 6.96202e-20 6.45422e-20 7.50971e-20 | ||
| 70 | +1.21619e+07 5.86591e-20 5.43052e-20 6.33617e-20 | ||
| 71 | +1.30317e+07 4.94237e-20 4.56918e-20 5.34601e-20 | ||
| 72 | +1.39637e+07 4.16424e-20 3.84443e-20 4.51063e-20 | ||
| 73 | +1.49624e+07 3.50861e-20 3.23463e-20 3.80579e-20 | ||
| 74 | +1.60325e+07 2.95621e-20 2.72155e-20 3.2111e-20 | ||
| 75 | +1.71791e+07 2.49078e-20 2.28983e-20 2.70936e-20 | ||
| 76 | +1.84077e+07 2.09863e-20 1.9266e-20 2.28601e-20 | ||
| 77 | +1.97242e+07 1.76822e-20 1.62098e-20 1.92882e-20 | ||
| 78 | +2.11349e+07 1.48983e-20 1.36383e-20 1.62745e-20 | ||
| 79 | +2.26464e+07 1.25527e-20 1.14748e-20 1.37317e-20 | ||
| 80 | +2.42661e+07 1.05763e-20 9.65444e-21 1.15863e-20 | ||
| 81 | +2.60016e+07 8.91119e-21 8.12282e-21 9.77606e-21 | ||
| 82 | +2.78612e+07 7.5082e-21 6.83419e-21 8.24867e-21 | ||
| 83 | +2.98538e+07 6.32609e-21 5.74997e-21 6.95995e-21 | ||
| 84 | +3.1989e+07 5.3301e-21 4.83773e-21 5.87259e-21 | ||
| 85 | +3.42768e+07 4.49092e-21 4.07022e-21 4.95511e-21 | ||
| 86 | +3.67282e+07 3.78386e-21 3.42447e-21 4.18097e-21 | ||
| 87 | +3.9355e+07 3.18813e-21 2.88116e-21 3.5278e-21 | ||
| 88 | +4.21697e+07 2.68618e-21 2.42404e-21 2.97667e-21 | ||
| 89 | +4.51856e+07 2.26327e-21 2.03945e-21 2.51165e-21 | ||
| 90 | +4.84172e+07 1.90693e-21 1.71587e-21 2.11927e-21 | ||
| 91 | +5.188e+07 1.6067e-21 1.44362e-21 1.7882e-21 | ||
| 92 | +5.55904e+07 1.35374e-21 1.21457e-21 1.50885e-21 | ||
| 93 | +5.95662e+07 1.14061e-21 1.02186e-21 1.27314e-21 | ||
| 94 | +6.38263e+07 9.61027e-22 8.59731e-22 1.07426e-21 | ||
| 95 | +6.83912e+07 8.09721e-22 7.23319e-22 9.06442e-22 | ||
| 96 | +7.32825e+07 6.82237e-22 6.0855e-22 7.64845e-22 | ||
| 97 | +7.85236e+07 5.74825e-22 5.11991e-22 6.45368e-22 | ||
| 98 | +8.41395e+07 4.84324e-22 4.30753e-22 5.44554e-22 | ||
| 99 | +9.01571e+07 4.08071e-22 3.62405e-22 4.59489e-22 | ||
| 100 | +9.66051e+07 3.43824e-22 3.04901e-22 3.87712e-22 |
test/data/obs_stacked.xml
| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <observation_list title="observation list"> | 2 | <observation_list title="observation list"> |
| 3 | <observation name="Crab" id="00001" instrument="CTA"> | 3 | <observation name="Crab" id="00001" instrument="CTA"> |
| 4 | - <parameter name="CountsCube" file="data/crab_cntmap.fits"/> | ||
| 5 | - <parameter name="ExposureCube" file="data/crab_expcube.fits"/> | ||
| 6 | - <parameter name="PsfCube" file="data/crab_psfcube.fits"/> | ||
| 7 | - <parameter name="BkgCube" file="data/crab_bkgcube.fits"/> | 4 | + <parameter name="CountsCube" file="crab_cntmap.fits"/> |
| 5 | + <parameter name="ExposureCube" file="crab_expcube.fits"/> | ||
| 6 | + <parameter name="PsfCube" file="crab_psfcube.fits"/> | ||
| 7 | + <parameter name="BkgCube" file="crab_bkgcube.fits"/> | ||
| 8 | </observation> | 8 | </observation> |
| 9 | </observation_list> | 9 | </observation_list> |
test/data/obs_unbinned.xml
| 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | <observation_list title="observation list"> | 2 | <observation_list title="observation list"> |
| 3 | <observation name="" id="00001" instrument="CTA"> | 3 | <observation name="" id="00001" instrument="CTA"> |
| 4 | - <parameter name="EventList" file="data/crab_events.fits" /> | 4 | + <parameter name="EventList" file="crab_events.fits" /> |
| 5 | <parameter name="EffectiveArea" file="irf/irf_file.fits" /> | 5 | <parameter name="EffectiveArea" file="irf/irf_file.fits" /> |
| 6 | <parameter name="PointSpreadFunction" file="irf/irf_file.fits" /> | 6 | <parameter name="PointSpreadFunction" file="irf/irf_file.fits" /> |
| 7 | <parameter name="EnergyDispersion" file="irf/irf_file.fits" /> | 7 | <parameter name="EnergyDispersion" file="irf/irf_file.fits" /> |
test/data/pha.fits
0 → 100644
No preview for this file type
test/data/pull.dat
0 → 100644
| 1 | +LogL,Sim_Events,Npred_Events,Crab_Prefactor,Pull_Crab_Prefactor,Unc_Crab_Prefactor,Crab_Index,Pull_Crab_Index,Unc_Crab_Index,Background_Prefactor,Pull_Background_Prefactor,Unc_Background_Prefactor,Background_Index,Pull_Background_Index,Unc_Background_Index | ||
| 2 | +104702.14348660898,15105.0,15104.999075727912,5.67748323458501e-16,-0.08501991498574554,2.6484107186845484e-17,-2.512994429094607,-1.1338279073158557,0.02910003262551158,0.9958218078266116,-0.17872001258319373,0.023378423675096273,-0.012229059990362811,-0.9236754329409402,0.013239563979119857 | ||
| 3 | +103330.80595191609,14818.0,14817.997797150003,5.732404092766631e-16,0.12283753926158997,2.637963358873928e-17,-2.484339613991382,-0.1554901325428316,0.027909256493730588,0.9787908971847574,-0.9101986145091182,0.023301620632196762,-0.008200032682593691,-0.6103278351854464,0.013435455848252658 | ||
| 4 | +104268.96595026793,14979.0,14978.999805565223,5.572825610413261e-16,-0.48658024310290293,2.6136365253088216e-17,-2.4950417511405485,-0.516821157597015,0.02910436409083146,1.0063046580826853,0.2716574371824787,0.02320811882816348,-0.0008417569678340521,-0.06468934227489305,0.013012297516599597 | ||
| 5 | +104821.06173253663,15107.0,15106.996064070843,5.572524365485819e-16,-0.4875817324560644,2.614446482070941e-17,-2.488742729886503,-0.3182574459681672,0.027470621653193025,0.9996316452115123,-0.015557106670414662,0.023677589688849032,-0.010871023195874276,-0.8107102927475592,0.013409257651129044 | ||
| 6 | +103881.48989070744,14862.0,14861.992397431473,5.301740735337788e-16,-1.5134244536513575,2.631510702112374e-17,-2.465301587043766,0.4827690936075433,0.030446052058549868,1.0115707161034393,0.4942920042462879,0.023408665331503164,0.0048734492051994045,0.3732789541610912,0.013055783485441917 | ||
| 7 | +104709.9140731044,15024.0,15023.989651557333,5.226837712898727e-16,-1.7954633953701884,2.6353212675979732e-17,-2.4343195831835844,1.5525972082532988,0.029421936722278975,1.017947066365573,0.7598967774868103,0.02361776875134134,0.0009326118036593681,0.07132952806775084,0.013074694715119194 | ||
| 8 | +103713.58340281199,14892.0,14891.999561522098,5.591199213471972e-16,-0.41862333613425523,2.599013889974217e-17,-2.470115751370293,0.35799682935892585,0.027609877571840587,0.9794463837010542,-0.8909844728935377,0.023068433765401575,-0.012917295469889406,-0.9740485577904611,0.013261449202482362 | ||
| 9 | +104795.70589373197,15029.0,15028.996906992426,5.435055239409328e-16,-1.0152303535510279,2.609700937959154e-17,-2.4655187514911407,0.49983528642007014,0.028972041194964666,1.0209631987169243,0.8832401674398217,0.023734426365241833,0.00466053101676357,0.3544111893768436,0.013150067369368664 | ||
| 10 | +104193.29654018967,14931.0,14930.996770551044,5.485461677632551e-16,-0.8193085256981937,2.6185291088558448e-17,-2.479088507285966,0.031657689546980165,0.028792142669831974,1.0185759089559494,0.7867635712209643,0.023610535153682555,0.008184752146355114,0.6243663808647385,0.013108893106991681 | ||
| 11 | +103628.40847429863,14848.0,14847.998122677556,6.014015930608307e-16,1.1849643924993984,2.6500030937298085e-17,-2.473150703559013,0.25987554591515094,0.026356063695286987,0.9902956776180022,-0.4187159470974005,0.02317638592289015,0.001885900145097897,0.14262284727070834,0.013222987629172232 | ||
| 12 | +105660.09206884849,15205.0,15204.992131202547,6.109854020247515e-16,1.5187149825791957,2.6986895167878697e-17,-2.4922552592625755,-0.44934245174528803,0.0272737623943052,1.00323842606026,0.13976115495783228,0.023171145524928653,-0.005994371257142875,-0.46075233874827176,0.013009963820103039 | ||
| 13 | +103835.59625385483,14858.0,14857.999995507591,5.297499346626201e-16,-1.54328568208427,2.6080761199715524e-17,-2.4319384773924724,1.701399801117752,0.028248223948276648,1.0130018036654878,0.5601780025624995,0.023210128934038485,0.006713522884626453,0.5203716357596322,0.012901400505479386 | ||
| 14 | +103482.23089354827,14807.0,14806.999524388077,5.736758548183581e-16,0.13761738296308404,2.6710686827580283e-17,-2.4701072439260923,0.3421196454712564,0.028916071336040444,0.9891275161084382,-0.4697332187670207,0.02314608262132377,-0.0006918586515145906,-0.05255682430971379,0.013164011726384277 | ||
| 15 | +102857.43398505163,14731.0,14730.999998518842,5.258007078860843e-16,-1.7041864102309696,2.5935714455043313e-17,-2.4853332222867714,-0.17651127204646544,0.03021462722996824,0.9985936056978045,-0.060149237976978034,0.023381747624695796,0.0019325678652796843,0.14603466473388227,0.013233624145345124 | ||
| 16 | +103817.91519576444,14910.0,14909.994926336014,5.329622298577745e-16,-1.4389390287441313,2.5739638304585517e-17,-2.4916943762429473,-0.39969910169305867,0.02925794977624896,1.0079906020378802,0.3407215111753502,0.023452003398070874,0.00020664358393950301,0.015738123620475775,0.013130128401752638 | ||
| 17 | +103967.78649231851,14870.0,14869.990058174044,5.260603968355675e-16,-1.6789644755360136,2.6170656857051498e-17,-2.4301686389439427,1.7352508788074,0.02871709311007826,1.0126332673580076,0.536452771161907,0.02354963575012417,0.005447900085284499,0.4147492279428597,0.013135407417889301 | ||
| 18 | +105284.40661958465,15058.0,15057.999998318428,4.927243299991711e-16,-2.9598366118818897,2.6108086402680312e-17,-2.4504493609494307,0.9673695847716703,0.03054741384860079,1.0639477867734564,2.6531725316838397,0.0241023853555697,0.02273846071513058,1.7729798337272424,0.012824996811908856 | ||
| 19 | +104830.07226830821,15032.0,15031.998093973076,5.743212958004981e-16,0.16282839716227676,2.653895681470984e-17,-2.460255056292079,0.7331750878331816,0.02693073460293763,1.009527339928993,0.40649631413313464,0.023437703117457166,0.0017910275983860455,0.13653669474155755,0.013117554967740933 | ||
| 20 | +104698.0498891591,15040.0,15039.998968232076,5.570480545515681e-16,-0.4911050777527014,2.6373063597102404e-17,-2.4920533487352197,-0.4183571629577559,0.02881114464493293,1.0144387152840497,0.6180934305102588,0.0233600853387651,0.0013844182971720093,0.10655399897505911,0.012992645142263101 | ||
| 21 | +104925.21327728468,15098.0,15097.992620766281,5.87969306777613e-16,0.6774288392926258,2.6525748145556783e-17,-2.5084885893716833,-1.0402720874605131,0.027385709676426055,1.0166071274045811,0.716918888388743,0.023164583432730087,0.003874758455068439,0.30154828940328254,0.012849545466618257 | ||
| 22 | +103716.61350507324,14871.0,14870.999265696919,5.610566829273711e-16,-0.33697545311885546,2.653996601192925e-17,-2.454976233044967,0.886385961633361,0.028231231132001506,0.9787988077612177,-0.922234954456611,0.022988927210283613,-0.011704744624020038,-0.8844478536183279,0.013233956729201437 | ||
| 23 | +103344.09380500649,14825.0,14824.999999989699,5.185881816208363e-16,-1.9630789475358086,2.6189378905876087e-17,-2.418893532303184,2.1636019917057876,0.028242933742466933,0.9802133791662438,-0.8562764603125603,0.02310774819914305,-0.013591256173913914,-1.026686644454609,0.01323797893673175 | ||
| 24 | +105469.3219667073,15214.0,15213.997120280635,5.796556830349523e-16,0.36143547823531713,2.6714818041924188e-17,-2.481092011680722,-0.03892934595915295,0.028051118091422435,0.9960380118113645,-0.16810935916980949,0.023567921549408868,-0.014903616203581289,-1.1156393733398904,0.013358811601426653 | ||
| 25 | +104469.9971681874,14961.0,14960.999082266428,5.947706132978403e-16,0.9305884258012391,2.6618226286784883e-17,-2.475757601829857,0.1572808660063672,0.02697339020228572,0.9946878034334904,-0.22520963190307067,0.023587785840331894,-0.0017152659481122583,-0.12790022377679958,0.01341096909342076 | ||
| 26 | +104826.19001967587,15063.0,15062.99608195958,5.287050347495291e-16,-1.5838597523756837,2.6072362271047778e-17,-2.4579789012405966,0.7746752179149065,0.028426233665606017,1.0185925724596263,0.7958686132990104,0.02336135908483304,-0.0002351029057570468,-0.018165082808064857,0.012942572750214319 | ||
| 27 | +103320.95695538132,14818.0,14817.998687527173,5.478498323029024e-16,-0.8523687875773152,2.598660112843289e-17,-2.490995186934019,-0.37945854402407125,0.028975989886582468,0.9953315815622235,-0.19898386538883064,0.02346129133964744,-0.0013328500645812436,-0.09997748749545347,0.01333150190078397 | ||
| 28 | +104825.19976994366,15116.0,15115.990754728477,5.315233940698427e-16,-1.460682378789519,2.6341528102805798e-17,-2.464718006751812,0.5076150170072764,0.030105479026773865,0.9928387367913682,-0.3049904020195074,0.023480290400003188,-0.018504566807966617,-1.3859269563155745,0.01335176195516118 | ||
| 29 | +103770.47872478547,14858.0,14857.991542917502,5.241689052795333e-16,-1.7674486406832426,2.5930651485720014e-17,-2.470999774704249,0.31047198034973555,0.028988848802434315,1.0142624255798223,0.613387112964016,0.02325191592451823,0.005780894385199397,0.4468102900554024,0.012938140669237033 | ||
| 30 | +103629.36892843783,14923.0,14922.999996487131,5.984682923028192e-16,1.0727263172672183,2.653826222455558e-17,-2.517783256274881,-1.3204723419015199,0.028613440112249505,0.9670801291995181,-1.4156504768341795,0.023254236366380916,-0.017944371819906522,-1.3217953180960127,0.013575756831817646 | ||
| 31 | +104202.31840266004,14969.0,14968.993306219852,6.11363636982842e-16,1.5511916803318888,2.6665716111881122e-17,-2.4805177040241033,-0.01902684336053044,0.027209138914617383,0.9743574698978508,-1.1040125515345534,0.02322666537305819,-0.012864906504281222,-0.9561276967352017,0.013455217904689712 | ||
| 32 | +104558.3210911674,14988.0,14987.99592260394,5.727035536558679e-16,0.10076888899713153,2.6829249411937305e-17,-2.4539572754877907,0.9040406708094028,0.028807027552082087,0.991942847147923,-0.3490713839169001,0.02308167676670701,-0.007233321441344711,-0.5529892440587004,0.013080401687843472 | ||
| 33 | +103295.47162555656,14883.0,14883.000000254477,5.800709280699981e-16,0.3789335257832652,2.6577031021948253e-17,-2.498719352789656,-0.6638277678957628,0.028199110816038476,0.9595872183999479,-1.7482932734147603,0.023115562025310562,-0.02304437391034645,-1.6988602430501567,0.013564608392372682 | ||
| 34 | +103258.47720670803,14845.0,14844.992307538843,5.83283553420523e-16,0.4952239600807473,2.6823325386673746e-17,-2.4589665237005023,0.7632059346150839,0.02755937204564027,0.964755489938738,-1.5351536401647652,0.022958294947911025,-0.016523138292911025,-1.2320888966887555,0.01341067055901326 | ||
| 35 | +103657.9671271524,14817.0,14816.999863026358,5.363242117977063e-16,-1.2786443217150414,2.6337103782797478e-17,-2.4323288184790695,1.6135859025493344,0.029543627919414728,1.0151591013135277,0.6351636323121661,0.023866450379636053,0.010915006913822117,0.8190878811605987,0.013325806869900458 | ||
| 36 | +104392.7082185512,15006.0,15005.995853606486,6.005823640352908e-16,1.1354123615360034,2.6935028251690447e-17,-2.4730683275167515,0.25611675736022566,0.027064501966574228,0.9714394796871246,-1.2460905368592647,0.022920100480709322,-0.017794798460961776,-1.3401186899781854,0.013278524203890809 | ||
| 37 | +105182.36065597368,15075.0,15074.989261140847,5.26313996325609e-16,-1.67692009148971,2.6051332974120466e-17,-2.4565236365198113,0.8036379946781819,0.029212610199683024,1.029479540250354,1.2428947693473755,0.023718452259504866,0.005601907621198788,0.43008379976278804,0.013025153759077906 | ||
| 38 | +103071.25151722605,14836.0,14835.999997691571,5.626870367730519e-16,-0.2758504395736606,2.651060929339331e-17,-2.4857663826203016,-0.19466445034259733,0.02962216578401001,0.9595379837552862,-1.7643536985481396,0.022933052640187388,-0.022964614426049572,-1.7082617255518946,0.013443264625407625 | ||
| 39 | +103697.65696037607,14939.0,14938.998760928765,5.389129205397533e-16,-1.1876025861552415,2.6176331899788434e-17,-2.4690490243020475,0.3886240085819805,0.02817884499187428,0.9885163863773131,-0.49579679121988196,0.0231619361521725,-0.012105401262481892,-0.9167134357594129,0.01320521854515384 | ||
| 40 | +104637.09745185435,15053.0,15052.996846537539,5.406589368501109e-16,-1.1101425795758761,2.6429995290423552e-17,-2.4389502165668464,1.4305536253574138,0.028695032961730167,0.9973647045748609,-0.11185075823051355,0.02356081860176562,-0.010884674103109395,-0.8187292691775412,0.013294595066869482 | ||
| 41 | +104582.78060549527,15024.0,15023.999395677984,5.827997309903262e-16,0.48195052823758067,2.6558184378659893e-17,-2.480763172768796,-0.027230974562203435,0.028025907301000918,0.9972408492496609,-0.11684592426392378,0.023613581455411925,-0.004849155581888444,-0.36150282462815947,0.013413880201008851 | ||
| 42 | +104660.06320954843,15025.0,15024.998351527545,5.950507262965721e-16,0.9335275835620825,2.6834478956674745e-17,-2.468672941074628,0.4151788322094137,0.027282361350393892,0.9942447528437467,-0.24704233712761414,0.023296602611399077,-0.004813342700068887,-0.3639786391517183,0.013224245003186924 | ||
| 43 | +105487.22379340562,15160.0,15159.998753761023,5.897989793185405e-16,0.7404510509478629,2.6739079231767564e-17,-2.4830216972591455,-0.10999404551766875,0.027471462158922832,1.008007621452472,0.3392549160552585,0.023603553179367128,-0.003582415027088905,-0.2709663149118288,0.013220886988312945 | ||
| 44 | +104309.2333224919,14961.0,14960.997133833138,5.993271060876569e-16,1.1023581510449902,2.6603972637981608e-17,-2.4663916652348883,0.5047187705067517,0.026962212543529037,1.0006059944066537,0.02571854685831731,0.023562544571124427,0.002877938002773262,0.2161085252295913,0.013317096119719353 | ||
| 45 | +104536.81282712151,14994.0,14993.997986296345,5.649645367970281e-16,-0.1890146539982087,2.6640596887369527e-17,-2.445895378373151,1.2164245981656017,0.02803677406579858,0.9871622217101877,-0.5497357570786212,0.02335263465129891,-0.011401907900413608,-0.8561347270640302,0.01331788974325867 | ||
| 46 | +104885.66713609539,15058.0,15057.999302468945,5.85376938187508e-16,0.5763874122125322,2.667812978163725e-17,-2.4783224283833145,0.061953861563189286,0.027077757130190266,1.011221208894034,0.4738519298700737,0.023680834004645206,0.0027051157314355177,0.20430259331033007,0.01324073124870481 | ||
| 47 | +103965.1770144278,14841.0,14840.999947621616,5.441964953783418e-16,-0.9786223699914871,2.636717227492218e-17,-2.4240347973833023,2.0660578382534425,0.027087916698405833,1.0048749802449943,0.2084331684438968,0.02338869711279427,0.004696774739682412,0.3576192508777786,0.013133450529170757 | ||
| 48 | +104657.89204800228,15025.0,15024.997235329069,5.291370559902183e-16,-1.5604400748894864,2.618680759828323e-17,-2.4474869070028125,1.119624494026985,0.029039283412107895,1.0070782890882277,0.3024366368726101,0.02340420513011186,-0.005298128388872043,-0.4048299005085303,0.013087295138567476 | ||
| 49 | +105104.3320267707,15071.0,15070.991729175797,5.95019096110726e-16,0.9335257688335624,2.6800648622680576e-17,-2.48966742734985,-0.3400391003696072,0.028430340332455842,1.0279217001184597,1.1706788386728464,0.02385086259021603,0.01347745991263468,1.0255680015129696,0.013141459067318844 | ||
| 50 | +103117.18933059537,14779.0,14778.999954219906,5.741061709636474e-16,0.1552774697240199,2.6444087290612467e-17,-2.5085237338167152,-0.9578959261781123,0.029777487341992842,0.9880764025321682,-0.5036977763199469,0.02367212647819584,-0.0007966132391824033,-0.05871465634982645,0.013567536433086148 | ||
| 51 | +103861.51126322581,14909.0,14908.999988128835,5.141729840097847e-16,-2.147589053088375,2.5995204208147898e-17,-2.4563869001257395,0.8147506117659684,0.0289819971083903,1.001915565907135,0.08215253976479471,0.023317184260150284,-0.005365587573949675,-0.4086698661866238,0.01312939371825232 | ||
| 52 | +104401.21304313006,15015.0,15014.998970160144,5.994262650853293e-16,1.0978905429865868,2.6802549009376762e-17,-2.4967114366338805,-0.5986746885080364,0.02791405241388654,0.9947189099510139,-0.22577026819208507,0.023391432766040707,-0.004090920537099004,-0.30811253302204894,0.013277358428020362 | ||
| 53 | +103896.10903963698,14907.0,14906.999883600616,5.868618849352218e-16,0.6376991535457983,2.6441755240640774e-17,-2.479523442602133,0.017226036087355272,0.027664948305589025,0.9909518757304067,-0.3908429511409154,0.023150281316781655,-0.002695578042956474,-0.20441807152789476,0.013186593645115359 | ||
| 54 | +103877.93353330657,14893.0,14892.999790511029,5.558775494680619e-16,-0.5356629666367859,2.6364433256618963e-17,-2.4743403482955824,0.2062639870749244,0.02743887473852516,1.0021831242943509,0.09496376921188177,0.022989023208207993,0.0008862487268151458,0.06861458581377454,0.01291633136459492 | ||
| 55 | +103396.93676252602,14770.0,14769.999940468431,5.867378273072098e-16,0.6352366873526242,2.6348961954583328e-17,-2.5155847264284814,-1.2077020193866677,0.029464823157746442,1.015575822278027,0.6678015218032541,0.023324029325311725,0.018553263639159025,1.4254318720711299,0.013015889431601825 | ||
| 56 | +104160.03334950031,14964.0,14963.999998356765,6.10907582479636e-16,1.520382351595521,2.690611505501016e-17,-2.470844076924422,0.34594540723430006,0.026466381354145058,0.9927990773010172,-0.3077142659053865,0.023401328754763813,-0.0006925360964855318,-0.05198559811791703,0.01332169142143325 | ||
| 57 | +104864.6850193089,15060.0,15059.999218909168,5.609746644889459e-16,-0.3411527664813018,2.6455407658400925e-17,-2.4647004340264353,0.5481903216886338,0.027909223071352622,1.0027414961956898,0.11570915352832659,0.02369299326883945,-0.005698317662346879,-0.4266719822022961,0.013355265637398148 | ||
| 58 | +104923.17543779277,15101.0,15100.995028939238,6.127117410688088e-16,1.584235014851103,2.69604829260911e-17,-2.503434209444339,-0.8389182406124437,0.02793384183330101,1.0016273884843798,0.06972600471156862,0.02333976385298056,-0.0021331039675606374,-0.1622460782952347,0.013147337611939605 | ||
| 59 | +104453.17589728598,14909.0,14908.97953769627,5.536892055352507e-16,-0.6201645362100462,2.630075328787414e-17,-2.4540288821633847,0.9320828943896502,0.02786352801123104,1.0282733858014168,1.2048710613023608,0.023465901630051383,0.016505203933255115,1.281884889389383,0.01287573016101099 | ||
| 60 | +104688.55914493323,15031.0,15030.991877826402,6.006938103496527e-16,1.1617511752543976,2.6420296362456006e-17,-2.499085904547056,-0.7049249572708577,0.027075087000675516,1.017186344545262,0.733530932235582,0.02342961119973933,0.009323142088312936,0.7143190125704435,0.013051790480508207 | ||
| 61 | +104926.93916741286,14995.0,14994.999995528324,5.463460924576351e-16,-0.9060463828756001,2.610672918012471e-17,-2.5100838929434004,-1.0195942133745202,0.029505750963251018,1.0595024692788106,2.4864521555702046,0.023930671316362114,0.029147843606924958,2.2708541683724275,0.01283562987570262 | ||
| 62 | +104418.96129561374,14975.0,14974.999993368268,5.131487853632615e-16,-2.168120600530305,2.6221426346317257e-17,-2.4229966833284244,1.9386863136486103,0.029403063440570344,1.021692983447443,0.9054165163310347,0.023959120533109186,0.004508823226188785,0.3403330078401741,0.013248268966923719 | ||
| 63 | +104597.41903067115,15024.0,15023.998585086974,5.5052416135314e-16,-0.7400989417831648,2.6315182399714976e-17,-2.4745524720532823,0.18891505066199857,0.028835859967897517,0.9960930724767406,-0.1660999857570656,0.023521540386966532,-0.009836850928478167,-0.7370514625111277,0.013346219943671375 | ||
| 64 | +105023.41205975645,15104.0,15103.99832493881,5.797871057178e-16,0.36796529273395895,2.659790450638014e-17,-2.4868954513434605,-0.2490035791048457,0.02769217763153948,0.9920885937026824,-0.3372923372634315,0.023455636026319258,-0.01239104177720175,-0.9265919584774807,0.013372705929330483 | ||
| 65 | +103289.81254198536,14773.0,14772.998796750477,5.619254179684634e-16,-0.3038067169570706,2.6578023397282623e-17,-2.482157660822906,-0.07419044378169867,0.029082732396842604,1.0184661779445874,0.779855959686005,0.02367895983255992,0.017436881008395338,1.3229099579545722,0.0131807013043847 | ||
| 66 | +102660.54003349427,14770.0,14769.999999705335,5.364790752662568e-16,-1.2975231162634542,2.5834549160307202e-17,-2.466043384426776,0.48372644345193777,0.028852289888531828,0.958831803268213,-1.8022271411880775,0.02284295680102107,-0.023476141574471938,-1.7556113526783363,0.01337206070048309 | ||
| 67 | +105006.72279247809,15048.0,15047.99465532865,5.993539114702324e-16,1.1005580354163806,2.6671843306406585e-17,-2.466000437205987,0.5172157125141147,0.027067164541391957,1.018356543752431,0.7674507997149594,0.023918854158792646,0.00983138430351044,0.737755349439672,0.013326076606530082 | ||
| 68 | +103102.28361685216,14716.0,14715.999442685392,5.674552108899239e-16,-0.09631102227788653,2.6422615500161828e-17,-2.454995788646379,0.9125078449265976,0.027401639879197092,0.9984852826342058,-0.06491044261688289,0.0233354958728976,0.009111631303170683,0.6896669209855639,0.013211640323635889 | ||
| 69 | +104531.59108373195,14950.0,14949.998318397973,5.833625674801249e-16,0.49877785891182885,2.679061879225682e-17,-2.4544331622678186,0.9389281566958414,0.027229812579221184,1.01219836264865,0.514842214521027,0.023693400239136235,0.008740556642838928,0.6596348798548487,0.013250598035025481 | ||
| 70 | +103466.32364242684,14842.0,14841.999992364486,5.559773024581159e-16,-0.5338636010041037,2.626644243119372e-17,-2.5146215085708925,-1.1450405559233547,0.030236054427761224,1.009723793948652,0.4124474334233883,0.023575838181226716,0.00721903046759916,0.545000471514331,0.013245916003596215 | ||
| 71 | +104316.6824251344,14911.0,14910.975299452331,5.863638892368771e-16,0.6201956888974903,2.638504189857696e-17,-2.4780783592346936,0.07238488048354566,0.026547543526624376,1.0340466137193263,1.440548699949866,0.023634476030217625,0.023923346759196155,1.8463064644490832,0.01295740832838096 | ||
| 72 | +105529.5151767736,15190.0,15189.99957462132,5.834717114215463e-16,0.5010886028147278,2.6884888911606908e-17,-2.4889834457321363,-0.3136735758566292,0.028639472443934322,1.0016659371683858,0.07092028990347908,0.02349027578219314,-0.009923624425733822,-0.7499001090737418,0.013233261744675887 | ||
| 73 | +105457.94736951304,15122.0,15122.00000033066,6.027761674204073e-16,1.228476892803507,2.668032879772676e-17,-2.484405248255628,-0.16595468883164577,0.026544885755513475,1.033269220492325,1.3891723116963275,0.0239489516255185,0.015526648583225076,1.1821004068806855,0.01313479675063867 | ||
| 74 | +104470.87925587903,15024.0,15023.99640239301,6.03790838846066e-16,1.2589189731428367,2.684115464691797e-17,-2.483869890747045,-0.14371975264646822,0.026926644916821823,0.9864947020215399,-0.5740287753518823,0.023527214241448623,-0.008837024981601296,-0.655230584788196,0.013486893296438342 | ||
| 75 | +105162.29126301195,15112.0,15111.999999317562,6.177356170407144e-16,1.78390671313331,2.6759032122744834e-17,-2.506380869101536,-0.9667329798802878,0.027288682242746005,1.0253507279309722,1.0574779091807105,0.023972820340628042,0.0127067997195174,0.9573832730291858,0.013272427122434208 | ||
| 76 | +103777.57790654837,14877.0,14876.995407234004,6.038262246294493e-16,1.268964516464256,2.6656556736275105e-17,-2.4620622880379215,0.6649687898115889,0.02697526897038421,0.9726737228224851,-1.1837182765463132,0.0230851189163385,-0.010148044300178573,-0.7591884031873629,0.013366964323444887 | ||
| 77 | +104806.70057053298,15096.0,15095.997686243283,5.439260391738729e-16,-0.9824410031651785,2.6539976183937103e-17,-2.485384750079234,-0.18354769817720248,0.0293370613345176,1.0113235065508546,0.4749012032977535,0.02384392052962426,-0.0047982174071041815,-0.3597467862069802,0.013337763090796671 | ||
| 78 | +105784.79092823583,15259.0,15258.997768580222,5.827961339350463e-16,0.47726383852805365,2.6811446629837503e-17,-2.5047295496039585,-0.8455934842339454,0.029245198863330865,1.0148334072555911,0.6252990634905237,0.02372210054623874,-0.005345331494155609,-0.40347832963608515,0.013248125367666706 | ||
| 79 | +105162.46385599423,15152.0,15151.990215977432,6.104114704168049e-16,1.4901748418897318,2.711861003206714e-17,-2.474470457622988,0.20105659418141558,0.027502417413986915,0.9773365909881715,-0.9704918298581112,0.02335249851113323,-0.01955450863830202,-1.4522701704146073,0.013464787087597772 | ||
| 80 | +103698.33193109326,14764.0,14763.999994387923,5.411019601513098e-16,-1.1049254973794107,2.615383563618418e-17,-2.4445338644781205,1.2428914744224622,0.028535182879389883,1.0311968370972786,1.3211549589914875,0.023613306588269496,0.023708273144118674,1.8300034868884438,0.01295531583080744 | ||
| 81 | +104821.39827733487,15059.0,15058.999246115178,5.68594851432458e-16,-0.053139051470666006,2.6442861297923464e-17,-2.466495670942182,0.4820149547355415,0.02801641095394487,1.0120587400167682,0.5137233646888311,0.023473216998943287,0.0011567486920515345,0.08829982954016835,0.013100236977528022 | ||
| 82 | +106505.23587817501,15264.0,15263.999999850623,6.218963100694398e-16,1.9102781400790376,2.7166886842610554e-17,-2.471373714397668,0.3260255898816594,0.026458921845561856,1.0244822100573021,1.0264179091613137,0.023852087769304933,0.006396545662894279,0.48529211649252724,0.013180815112195989 | ||
| 83 | +103716.65615689153,15034.0,15033.999998061632,5.577294742966784e-16,-0.46570958681866953,2.634802042007193e-17,-2.482904112111916,-0.0985414772370263,0.029470961805563557,0.9613012436149456,-1.6877220023130035,0.022929579831286302,-0.03170581928856768,-2.3653482434347395,0.013404292317873425 | ||
| 84 | +104225.27879959819,14900.0,14900.00000050222,5.199590965611082e-16,-1.9135528494747858,2.615078201400422e-17,-2.4556855368707633,0.8170335145337638,0.02975944400899101,1.0386428710542701,1.615496590731249,0.0239201192227701,0.018544221167335707,1.4217032000742367,0.01304366563032804 | ||
| 85 | +102786.34653474073,14809.0,14808.997062384125,5.671608003596035e-16,-0.10806725632187256,2.6272524509552447e-17,-2.5099327217773117,-1.0258010259966965,0.02917985166590013,0.9698004119754605,-1.3141855751175404,0.02297969829857434,-0.014914062983158742,-1.1175505167317183,0.013345314381648704 | ||
| 86 | +103693.80219318194,14925.0,14925.000000354028,6.262827577806683e-16,2.0904413060784135,2.6923864170218004e-17,-2.5411901412740177,-2.2024997893381664,0.027782132634121534,0.9887409816798305,-0.4825792434259602,0.023330921239460494,-0.000780752700560303,-0.05835466951287918,0.013379438305069774 | ||
| 87 | +104450.08142122456,15026.0,15025.994475005335,5.564571488415918e-16,-0.5143813331337013,2.632842657003666e-17,-2.4774149392783564,0.09322806764920688,0.027728352488978595,0.9801244763987085,-0.8536014915849469,0.02328431217287018,-0.019296953745379125,-1.43996889663141,0.013400951777862312 | ||
| 88 | +104737.74337394757,15065.0,15064.99996910083,5.554067901763217e-16,-0.5523022868838343,2.6422504795363372e-17,-2.4843390111399652,-0.14983936941816967,0.028957750935643706,1.0003050186229425,0.013048813191263154,0.02337520037046332,-0.008653486101637216,-0.657271863832087,0.013165763784843708 | ||
| 89 | +104812.57801906214,15006.0,15005.99998335691,5.178722422960302e-16,-1.9922068346204702,2.6165836196370893e-17,-2.427920517426411,1.7570265877928588,0.029640691231093017,1.0336105370795834,1.4217166073837435,0.023640813439911784,0.0108890268433584,0.8436609848926396,0.012906874963222445 | ||
| 90 | +106339.57096486905,15207.0,15206.999997505669,5.492624962630607e-16,-0.7780861160226986,2.6651939046210067e-17,-2.445831650210193,1.190829912702277,0.028692888401057177,1.0621195059244974,2.582425705182309,0.024054711738594643,0.02255630002191606,1.7588965807729846,0.012824119546587107 | ||
| 91 | +103728.05730247138,14836.0,14835.999999972239,5.209387563455267e-16,-1.8911654411555279,2.5942333011593222e-17,-2.4645567717301,0.5223658413199294,0.029564008685709207,1.012433963029872,0.5286900139121922,0.02351843746369132,0.005379995631329906,0.4100847184331302,0.01311922973351953 | ||
| 92 | +103639.17031866539,14849.0,14848.995763098657,5.526901347779302e-16,-0.6572633079617131,2.6336271951268132e-17,-2.4790756256950353,0.03172639935343961,0.029135808783939735,1.020468619932421,0.8708978450847256,0.023502894223408958,0.013820223566015184,1.0582294652684516,0.01305976068480504 | ||
| 93 | +104906.65266527233,15057.0,15056.999676679454,5.898564205186925e-16,0.7409408234691087,2.6798928996413046e-17,-2.4884855686348057,-0.300606433374182,0.028228167107266427,0.9987704521192002,-0.052390350346280826,0.023468976112450243,-0.00464859897558333,-0.35058822561408415,0.013259426974311319 | ||
| 94 | +103900.09432355365,14941.0,14940.999999124993,5.626494348423733e-16,-0.2802725807392193,2.622648686589148e-17,-2.5374766771077253,-1.956661148119976,0.029374875237314736,1.0177793643158666,0.7655517169966314,0.023224249807207744,0.008053383365417891,0.624695729612739,0.01289168947962929 | ||
| 95 | +105421.80459221234,15086.0,15085.991362965473,5.516294154681729e-16,-0.6898096398915645,2.6631382731495095e-17,-2.432532234555485,1.6716428368356826,0.028395877635182285,1.0247181424780918,1.0377693753611312,0.023818531424180996,0.006247790610896622,0.47575967680589687,0.013132240741465004 | ||
| 96 | +104763.55636490823,14971.0,14970.992992053427,5.754182702542043e-16,0.20500866554129127,2.6429469407540822e-17,-2.471106898042058,0.3212152695157941,0.02768580077574692,1.0213216150467694,0.912626363652129,0.023362918162308007,0.01187716446399299,0.918512218279798,0.012930872586797705 | ||
| 97 | +104010.23755771558,14983.0,14982.986816532728,5.82399109476417e-16,0.4663708032910838,2.658637588142092e-17,-2.487410895062763,-0.26203121450146666,0.02828248946165792,0.9697278266558659,-1.3016693628373415,0.02325642302754035,-0.02063547654962738,-1.5264684883010589,0.01351844254092295 | ||
| 98 | +103802.99200127616,14915.0,14914.999158519993,5.98955655549965e-16,1.0774187851228139,2.687502385311054e-17,-2.492051222393842,-0.42355797140608237,0.028452356483424656,0.9793257627282156,-0.8930739375796235,0.023149524806215908,-0.00909363354268816,-0.6818341388097926,0.013337017061894227 | ||
| 99 | +104450.88752347854,15017.0,15016.999255893796,5.809988580730963e-16,0.41359203147894474,2.65934960926737e-17,-2.4601309159680382,0.7212149320641501,0.02754946292514427,0.9867690971578991,-0.5699875949468021,0.02321261543128109,-0.010889108810203578,-0.821966945763293,0.013247623722985307 | ||
| 100 | +103991.60794535361,14949.0,14948.999999199335,5.116779889999498e-16,-2.2436615470269636,2.5994121563179454e-17,-2.4490704069391716,1.0231506789081568,0.0302297537385545,0.9920210767039928,-0.34551318825890465,0.02309296306810833,-0.01362458177359732,-1.0422571545953772,0.013072188292040678 | ||
| 101 | +104522.21161729087,14952.0,14951.996157985375,5.778641034812695e-16,0.29445980626519813,2.670688261672947e-17,-2.463321751237089,0.6036096703921505,0.027630850831258973,1.0145116280579276,0.6221761632371783,0.02332398589882278,0.00909011274137726,0.7004224247969091,0.012978043562801382 |
test/data/sensitivity.dat
0 → 100644
| 1 | +loge,emin,emax,crab_flux,photon_flux,energy_flux,sensitivity | ||
| 2 | +-1.51402150412,0.02,0.0468734582318,0.144989163852,6.60543533444e-10,3.05652923293e-11,3.56378721075e-11 | ||
| 3 | +-1.14412450369,0.0468734582318,0.109856054331,0.0561134683318,7.24745374549e-11,7.85976500012e-12,9.16416230711e-12 | ||
| 4 | +-0.774227503252,0.109856054331,0.257466658709,0.0315037806261,1.15354211075e-11,2.93193651747e-12,3.41851723554e-12 | ||
| 5 | +-0.404330502818,0.257466658709,0.603417633655,0.0244879762385,2.54200331885e-12,1.51423828719e-12,1.76553948308e-12 | ||
| 6 | +-0.0344335023848,0.603417633655,1.41421356237,0.022256802649,6.54995675049e-13,9.14436478628e-13,1.0661952755e-12 | ||
| 7 | +0.335463498049,1.41421356237,3.31445401734,0.0250217133244,2.08758967789e-13,6.83057479879e-13,7.96416891675e-13 | ||
| 8 | +0.705360498482,3.31445401734,7.76799609716,0.042333217441,1.00129446033e-13,7.67840339358e-13,8.95270214276e-13 | ||
| 9 | +1.07525749892,7.76799609716,18.2056420303,0.0929194773185,6.23074149979e-14,1.11981387734e-12,1.30565686449e-12 | ||
| 10 | +1.44515449935,18.2056420303,42.6680700645,0.14972962577,2.8463818009e-14,1.19893673197e-12,1.39791085453e-12 | ||
| 11 | +1.81505149978,42.6680700645,100.0,0.382388032371,2.06082989569e-14,2.03442769003e-12,2.37205890421e-12 |
test/data/spectrum.fits
0 → 100644
No preview for this file type
test/data/ts.dat
0 → 100644
| 1 | +TS,LogL_bgm,LogL_all,Nevents,Npred_bkg,Npred_all,Crab_Prefactor,Unc_Crab_Prefactor,CTABackgroundModel_Prefactor,Unc_CTABackgroundModel_Prefactor,CTABackgroundModel_Index,Unc_CTABackgroundModel_Index | ||
| 2 | +21858.52363364247,164117.78313692164,153188.5213201004,22947.0,22946.99999940957,22946.999182570653,5.793209910482599e-16,9.843787551860997e-18,0.9961007850466849,0.01197837072408249,-0.002988471615299611,0.007462197925324776 | ||
| 3 | +22254.447332882788,165680.6922036114,154553.46853717,23099.0,23098.999999613512,23098.998093109363,5.834991758798705e-16,9.870580046002392e-18,1.0126678419515491,0.011967610062684665,0.004782477384744285,0.007316347479857281 | ||
| 4 | +21669.561687524547,165499.35987704716,154664.57903328488,23134.0,23133.99999969615,23133.999315025623,5.759131518978944e-16,9.8078414532141e-18,1.0105363690914626,0.011967661087729033,-0.00017543331960004447,0.0073220367405137776 | ||
| 5 | +20586.996292978816,164330.2704312009,154036.77228471148,22897.0,22896.999999836524,22896.997968569693,5.555266953291272e-16,9.65303499566792e-18,1.0126646529020689,0.011972560615151874,0.005782431464096715,0.007323711254845693 | ||
| 6 | +21217.911190702056,163471.7261244653,152862.77052911426,22869.0,22868.999999925014,22868.99897334564,5.70225985492044e-16,9.781422622377391e-18,0.9910189865469351,0.011911721710682954,-0.006124951668038474,0.007435839123654169 | ||
| 7 | +21499.99581397162,164613.52000714888,153863.52210016307,22972.0,22971.999999709296,22971.999752804753,5.6910222413269675e-16,9.758624936302264e-18,0.996047801086967,0.011904474629350275,-0.006618987374187345,0.007377903239793396 | ||
| 8 | +21218.138624030922,164860.51429341873,154251.44498140327,23028.0,23027.999999721134,23027.999861910866,5.631722425238875e-16,9.709038606307067e-18,1.0013335385708708,0.011894934859389805,-0.006251748911501181,0.007319737866598979 | ||
| 9 | +21516.115901010286,164574.57805417257,153816.52010366743,22977.0,22976.999999663327,22976.99992616064,5.737703984639025e-16,9.8058501757969e-18,1.0017304453830707,0.011926394544762287,-0.0012345022004066025,0.007362686667357548 | ||
| 10 | +21814.264059167763,163757.54297349413,152850.41094391025,22865.0,22864.999999773583,22864.999780063565,5.781984731779256e-16,9.833138684097321e-18,0.9972279507003987,0.01184624889933737,0.0009075599364746032,0.007331742276660691 | ||
| 11 | +21722.886111398868,165089.47672604493,154228.0336703455,23109.0,23108.999999674452,23108.9997904007,5.709992445993981e-16,9.76964807969154e-18,0.9967680654306393,0.011876107200647554,-0.011021721057770708,0.007332464028069347 | ||
| 12 | +21598.863410390506,165201.15784713515,154401.7261419399,23121.0,23120.999999727013,23120.99956818323,5.796621137864304e-16,9.85685177987898e-18,1.0005077278386079,0.011874257987756785,-0.006437475225365512,0.007308543239518941 | ||
| 13 | +21794.114624339214,164895.88104651406,153998.82373434445,23001.0,23000.99999958087,23000.999482800085,5.798901936139489e-16,9.862163118374043e-18,1.005069551247296,0.011900250356816858,0.0019410618022905287,0.0073140103821301514 | ||
| 14 | +21227.425172272255,166038.31113511338,155424.59854897726,23106.0,23105.999999409567,23105.996163342123,5.683306232669589e-16,9.767724432554512e-18,1.0208070375514615,0.012000389287969418,0.006896248020332655,0.007278861707651359 | ||
| 15 | +21573.883430126647,163893.0064978525,153106.06478278918,22893.0,22892.999999855037,22892.997657277247,5.746330138649936e-16,9.809856798510093e-18,0.9887958563489442,0.011919769035438853,-0.007702982005473525,0.007460539914015142 | ||
| 16 | +21216.534766604716,164024.07526321124,153415.80787990888,22891.0,22890.99999976823,22890.999903703054,5.634003761042508e-16,9.713723962581571e-18,0.9988843468354479,0.011884925398741884,-0.002623626233923857,0.007345635611935417 | ||
| 17 | +21597.08751892927,165975.3560595174,155176.81230005276,23150.0,23149.99999944865,23149.998888937902,5.718580414582826e-16,9.78000524693473e-18,1.0132558638441092,0.011992693047890666,0.0002528999590185808,0.007321935314776597 | ||
| 18 | +21387.703713911586,163364.79937473897,152670.94751778318,22794.0,22793.999999815976,22793.999973829385,5.6892940405553605e-16,9.758446104823037e-18,0.9943975957184543,0.011824486448349799,-0.0008002832127617221,0.007333535186744982 | ||
| 19 | +20912.907039812184,162038.81793470908,151582.36441480299,22666.0,22665.99999997628,22665.990260466566,5.601818185889693e-16,9.694320601561969e-18,0.9751815451597996,0.011793838389151424,-0.01294140924200319,0.007455055791860874 | ||
| 20 | +21911.95291238872,163189.5450744877,152233.56861829333,22810.0,22809.999999897966,22809.998057095352,5.791145848008091e-16,9.84239549367057e-18,0.9854579489782141,0.011857156203560955,-0.005834836728800691,0.007437257754506665 | ||
| 21 | +21121.265116654686,164055.15655683712,153494.52399850977,22912.0,22911.999999787822,22911.99984896773,5.654325050779409e-16,9.741375490234794e-18,0.9999753099585894,0.01194854296456228,-0.0021040061041819437,0.00739916979858624 | ||
| 22 | +21195.306229041773,164281.77518035137,153684.12206583048,23034.0,23033.999999960743,23033.998176414847,5.70433524603058e-16,9.77671925031924e-18,0.9886794379131255,0.011878644954228475,-0.01446464700955386,0.007402981305713397 | ||
| 23 | +20846.777400515275,162770.057188395,152346.66848813737,22731.0,22730.999999907664,22730.99981226707,5.624363678525482e-16,9.712847646970035e-18,0.9909653476365609,0.011763408213370439,-0.002595590722067562,0.007301229915792391 | ||
| 24 | +20897.083739825,164019.2197518424,153570.6778819299,23003.0,23002.999999907483,23002.999556953055,5.649662099748417e-16,9.736547752010038e-18,0.9935802602295315,0.01188380653681554,-0.010805113941356031,0.007371306800476196 | ||
| 25 | +20602.686458923854,164911.49560107855,154610.15237161663,22935.0,22934.99999955501,22934.99341642103,5.530693214901318e-16,9.625543333068213e-18,1.0206021943272432,0.011985188441572748,0.00972446272247772,0.00727243068453318 | ||
| 26 | +21836.23271708103,163824.30785453672,152906.1914959962,22755.0,22754.999999495434,22754.999710735854,5.75568768540384e-16,9.811525606728942e-18,1.0043798388913345,0.01188200956164694,0.010276896104008231,0.007325165400710747 | ||
| 27 | +21420.40131879633,164409.64030012718,153699.43964072902,23001.0,23000.999999780248,23000.99928771896,5.684570967501337e-16,9.762208897347998e-18,0.9913746713865513,0.011878388317921098,-0.011560419259827103,0.007384451973090443 | ||
| 28 | +21727.81684923329,164232.132445953,153368.22402133635,22985.0,22984.99999976957,22984.998900142164,5.738813127112364e-16,9.809036890551794e-18,0.9911339994790322,0.01189255974895351,-0.009747052205701144,0.00740674910573882 | ||
| 29 | +20868.72095527401,164301.13159811447,153866.77112047747,22992.0,22991.999999802247,22991.99969008748,5.605800164321631e-16,9.703156512461817e-18,0.9973271760042328,0.011871321613801066,-0.008569072284481264,0.0073309043881014035 | ||
| 30 | +22492.009746829106,164682.28638778496,153436.2815143704,22951.0,22950.9999996003,22950.99665538983,5.879507535878784e-16,9.910190021652269e-18,1.001162832181959,0.011846315465073663,0.002987242954331668,0.0073024800531300005 | ||
| 31 | +22653.864335719903,165519.4792556914,154192.54708783145,23076.0,23075.999999249838,23075.993670520074,5.912861048051989e-16,9.940531531808007e-18,1.0024002934241467,0.011941973255326052,-0.00023952533210942385,0.007373252448619404 | ||
| 32 | +21449.306879230775,166768.10502219904,156043.45158258366,23297.0,23296.99999917116,23296.992123045784,5.7341518582148665e-16,9.807974620497261e-18,1.024760753033504,0.012028256916479971,0.0035902945030410723,0.007258563117465229 | ||
| 33 | +21486.346823231317,164876.94234162793,154133.76893001227,23003.0,23002.999999741518,23002.999859281495,5.757455861467064e-16,9.822563593405131e-18,1.004168442832293,0.011942314003147688,0.00011042172295081477,0.0073583821510989885 | ||
| 34 | +20652.239219280833,163809.36895235302,153483.2493427126,22957.0,22956.999999943808,22956.995521902107,5.528577248898855e-16,9.622644416274187e-18,0.9853639781514777,0.011834892876956514,-0.018391417942683855,0.0073803794078678014 | ||
| 35 | +21787.521341275133,164528.73527216076,153634.9746015232,22991.0,22990.99999973,22990.998358757795,5.720325280614957e-16,9.785480546850936e-18,0.9855686593361147,0.011839563015884493,-0.014781546186952868,0.007392004202286942 | ||
| 36 | +21402.38363453705,164305.6816226261,153604.4898053576,22994.0,22993.99999989152,22993.99965618869,5.712540995621592e-16,9.778682761426494e-18,0.9949474763637698,0.011898956019282798,-0.007806261712544803,0.007380964683300804 | ||
| 37 | +20141.589426982973,163856.60168552134,153785.80697202985,22929.0,22928.999999913434,22928.999999743348,5.438078945642788e-16,9.558024400005279e-18,0.9932852802680611,0.011875856351872056,-0.01340284403577944,0.007359275829012058 | ||
| 38 | +21943.395299219526,163065.74164094013,152094.04399133037,22784.0,22783.999999305994,22783.99675835668,5.79676765978459e-16,9.848370996477712e-18,0.9837834848183966,0.01187815045838842,-0.005954920583608014,0.007472494212571003 | ||
| 39 | +20834.792521972733,164064.23789739315,153646.84163640678,22895.0,22894.99999975629,22894.999530192188,5.589302026667169e-16,9.677416099688684e-18,0.9986526033294748,0.011854084906733467,-0.004096128598782811,0.007311666493293262 | ||
| 40 | +21305.324882587476,163265.06469459928,152612.40225330554,22828.0,22827.999999891683,22827.99808304598,5.713178115397861e-16,9.79512015984894e-18,0.987396852431259,0.011894410275773492,-0.007029367080902169,0.007451877733083311 | ||
| 41 | +20847.034227716562,163814.44659629313,153390.92948243485,22897.0,22896.9999996484,22896.99953025752,5.607597257232211e-16,9.688770805376503e-18,1.0047595349843508,0.011799861066908465,0.0010146013322702991,0.007215496921685529 | ||
| 42 | +21216.92292083666,164176.47242941064,153568.0109689923,22999.0,22998.999999831543,22998.9975955996,5.642001984733995e-16,9.72351332200732e-18,0.9899066275912457,0.011903062056425938,-0.013687904197762802,0.007417248945029567 | ||
| 43 | +20816.64541355765,163181.06644880498,152772.74374202616,22777.0,22776.99999988913,22776.994775080595,5.516451209091623e-16,9.618999946029458e-18,0.9869057530226409,0.011856380365721023,-0.010358640899461943,0.007409856539614678 | ||
| 44 | +21679.522176688828,163799.51890170656,152959.75781336214,22837.0,22836.99999978841,22836.99973823716,5.717636386575965e-16,9.776297868466177e-18,0.9908230482181739,0.011847216840415472,-0.0046007921454711475,0.007378504976736998 | ||
| 45 | +21106.35513021017,164821.97117069492,154268.79360558983,22917.0,22916.999999453958,22916.99841731256,5.647103860714512e-16,9.727705266059672e-18,1.01541521494636,0.011955291437595085,0.00943775316656054,0.007291252547122076 | ||
| 46 | +20837.813223739155,163866.034636364,153447.12802449442,22791.0,22790.999999713706,22790.998309820432,5.572360798379893e-16,9.654736904973028e-18,1.0091814893739082,0.011893607890048716,0.007811373787627806,0.007283734723217876 | ||
| 47 | +20780.997344649804,164108.8221487588,153718.3234764339,22982.0,22981.999999861746,22981.99986802358,5.630081040612143e-16,9.720705407249754e-18,0.9960740698856181,0.011864470017298944,-0.008531796083847434,0.007334719933560889 | ||
| 48 | +21835.693036562065,164481.7513907408,153563.90487245977,22863.0,22862.999999581152,22862.999821485086,5.719539799575279e-16,9.779590491901723e-18,1.0043623557350347,0.011875625884065816,0.0049348547201782614,0.007305172253576122 | ||
| 49 | +21653.10258389666,165542.21112609853,154715.6598341502,23262.0,23261.999999841548,23261.99499680352,5.749522283549226e-16,9.819619041947758e-18,0.9902674093404891,0.011918436489673211,-0.02105969680201884,0.007407329162175303 | ||
| 50 | +21846.154768515087,164624.27857300622,153701.20118874867,23012.0,23011.99999979313,23011.998528939348,5.833817292347365e-16,9.884966321550659e-18,0.9935369248121374,0.011882112655646851,-0.006556706861582095,0.007382216624463548 | ||
| 51 | +22013.17601596308,166235.52968944985,155228.9416814683,23227.0,23226.999999677897,23226.998673585054,5.797707114245376e-16,9.848651501252573e-18,1.006518546940583,0.011988963639015245,-0.00598127326508908,0.007364840449676914 | ||
| 52 | +21651.91926104814,163154.12158821282,152328.16195768875,22773.0,22772.99999985566,22772.998844177993,5.714396502849746e-16,9.769436981298296e-18,0.9851000302656024,0.011819450107849325,-0.006582743622206519,0.007400947537603796 | ||
| 53 | +21989.977012775722,165301.46496142616,154306.4764550383,23054.0,23053.999999486277,23053.99866206013,5.831451508774712e-16,9.873936836478257e-18,1.0070990373467372,0.011907048508928606,0.0022074936263132647,0.007300838328239046 | ||
| 54 | +21438.695088208653,163698.03314021966,152978.68559611533,22850.0,22849.999999890217,22849.999942469298,5.723101116737367e-16,9.79415042715683e-18,0.9959990059596918,0.011909255151422262,-0.0009492657684907494,0.007402029667490372 | ||
| 55 | +20838.374803555547,163909.36890479646,153490.18150301868,22825.0,22824.999999715288,22824.99939814383,5.603315148685522e-16,9.69540670910627e-18,1.0087802770334235,0.011925882318992111,0.006917357818017513,0.007318975346866552 | ||
| 56 | +21270.20557162707,165625.21774982946,154990.11496401593,23098.0,23097.999999612013,23097.99846084131,5.695134364689924e-16,9.766410999308169e-18,1.0165267626116348,0.012010348326125827,0.0042397629393144945,0.007319288376668166 | ||
| 57 | +21527.705370273616,164243.86907532276,153480.01639018595,22965.0,22964.999999743457,22964.99993603194,5.701748498974925e-16,9.771290624802224e-18,0.995702026500132,0.011874291328625755,-0.006337078712909612,0.007353017018362593 | ||
| 58 | +21055.645831402973,164272.05201691244,153744.22910121095,22913.0,22912.99999970991,22912.999921720784,5.630081490231017e-16,9.7255367108198e-18,0.9979621989156474,0.011868129706833142,-0.0043189322848428005,0.0073321006440042955 | ||
| 59 | +21156.85824884911,162399.58053200433,151821.15140757977,22706.0,22705.99999991407,22705.997403443518,5.654797040066863e-16,9.740490054150095e-18,0.9784619159402815,0.011744743142957838,-0.010617863436450973,0.007382073296970704 | ||
| 60 | +21201.688190487737,164789.7753571481,154188.93126190422,23026.0,23025.99999906124,23025.99972065303,5.667600645790645e-16,9.742584040372483e-18,1.0120410866982648,0.01207095002314141,0.002979507608702241,0.007418035938329006 | ||
| 61 | +21579.612940530176,164202.44370278623,153412.63723252114,22874.0,22873.999999804666,22874.00001950805,5.716335760382397e-16,9.78228682145465e-18,1.002323437487339,0.011916380859040334,0.0028258681377384813,0.007357128369306409 | ||
| 62 | +21460.62560378993,164011.29522604778,153280.9824241528,22951.0,22950.99999985298,22950.999919398004,5.718007013749168e-16,9.78668674780352e-18,0.9941518980348495,0.011860449976759028,-0.006570586126134151,0.007354999480418171 | ||
| 63 | +20888.288302358415,164286.87337022196,153842.72921904275,22976.0,22975.99999977232,22975.998047214835,5.544737396797197e-16,9.641570891212174e-18,1.0007779663248277,0.011916634775209257,-0.006801761329085501,0.0073460207848977796 | ||
| 64 | +20408.074956183205,164422.41163892217,154218.37416083057,22955.0,22954.999999835327,22954.995893393418,5.513465666103151e-16,9.625616231421954e-18,1.0058950024352238,0.011974149384797315,-0.0028091604581978514,0.007363395502675995 | ||
| 65 | +21802.37343549641,164500.592398738,153599.4056809898,22961.0,22960.999999757954,22960.9989212055,5.832468881001641e-16,9.890309949834711e-18,1.0034751072565908,0.011921220309959827,0.0031744106933537897,0.0073533366536048545 | ||
| 66 | +20876.450997727632,164582.49714246154,154144.27164359772,22993.0,22992.999999842265,22992.9998257974,5.648090586661093e-16,9.736675647490638e-18,1.0025225514093496,0.011933600093706552,-0.0035293846222004244,0.007354639908367345 | ||
| 67 | +21706.519023373083,164473.15900975114,153619.8994980646,22978.0,22977.999999763233,22977.999793557632,5.759940859191368e-16,9.813811252134857e-18,0.9984861958740264,0.011920224946766407,-0.0032243711331649107,0.007381393296644344 | ||
| 68 | +21656.740131683822,165712.62332411483,154884.25325827292,23262.0,23261.99999977213,23261.998757088804,5.797595166213485e-16,9.856541718951383e-18,0.9985566042942451,0.011918622406145106,-0.013482108055460828,0.007351626660765964 | ||
| 69 | +21108.65355328942,164601.01057088916,154046.68379424445,23016.0,23015.99999983359,23015.999758528997,5.653188521209414e-16,9.736939795430797e-18,0.9959645629245217,0.011889610707927175,-0.00938547147416546,0.007358851980664596 | ||
| 70 | +20647.59149535757,162669.5612982715,152345.7655505927,22734.0,22733.99999995898,22733.995853601802,5.5190264735296685e-16,9.620164290713148e-18,0.9903309324372139,0.01187206487521323,-0.005898045252815988,0.007403049951329795 | ||
| 71 | +22290.401570641203,163883.56355593016,152738.36277060956,22782.0,22781.999999546068,22781.99916149079,5.824528487203314e-16,9.864372038097642e-18,0.9966719584506485,0.011871832280126494,0.004939494731895152,0.007375380023497896 | ||
| 72 | +21624.4816204338,164856.28447951959,154044.0436693027,22996.0,22995.99999963064,22995.999887018945,5.729990754258132e-16,9.793654933564995e-18,1.0001246408759745,0.011920784556020848,-0.003433668355429103,0.007365033404665828 | ||
| 73 | +21599.218091811636,162947.49765919705,152147.88861329123,22666.0,22665.999999721185,22665.9995259345,5.76124788921756e-16,9.820444219997191e-18,0.9997434910652248,0.011837575389850108,0.010453639932065167,0.0073277935176205644 | ||
| 74 | +21352.83466984972,163983.0417331816,153306.62439825674,22833.0,22832.999999748183,22832.999677072614,5.611046191249927e-16,9.692013011636335e-18,0.9935935257673363,0.011855675126920649,-0.004991283544181841,0.007359215729362822 | ||
| 75 | +22138.833458752255,164579.4216104209,153510.00488104476,22972.0,22971.99999954863,22971.999029847222,5.82889920739159e-16,9.860552383071182e-18,1.0016245840621145,0.011965267887535018,0.0012043877283222457,0.007408104140671816 | ||
| 76 | +21460.73646459746,164025.76170268297,153295.39347038424,22919.0,22918.99999972083,22918.99998951889,5.739817859219702e-16,9.810075323312415e-18,0.9966380414703272,0.01185241980257522,-0.0028036440323137035,0.007332677333553906 | ||
| 77 | +20272.70840003481,163913.44129798363,153777.08709796623,22905.0,22904.99999986819,22904.993807344785,5.491116393214731e-16,9.603700699255587e-18,0.9993535632641539,0.01192103384820017,-0.006429848120336535,0.007364414061681116 | ||
| 78 | +22040.583799355198,164196.0694411831,153175.7775415055,22948.0,22947.999999762113,22947.998520762158,5.830729768890433e-16,9.878618700156061e-18,0.9889198731570649,0.01183479859649009,-0.00766945927540272,0.00737644490898403 | ||
| 79 | +22189.423341836373,162999.79537715373,151905.08370623554,22762.0,22761.999999802018,22761.99812426319,5.840469854404995e-16,9.88689591899704e-18,0.9874701389124014,0.011840024598898219,-0.001045075500813165,0.007415569662489257 | ||
| 80 | +21404.67148317158,163675.38150747615,152973.04576589036,22873.0,22872.99999985997,22872.999797008175,5.707784704943953e-16,9.776315626974606e-18,0.9932817805516895,0.011877174992673342,-0.004381770811720796,0.007385324275316955 | ||
| 81 | +21680.787235579046,164409.20965859844,153568.81604080892,23000.0,22999.999999595042,22999.996041215003,5.756363373649316e-16,9.818959282992611e-18,0.9911211088710422,0.011963680831576883,-0.009911884410269314,0.007474654715810191 | ||
| 82 | +21579.654693948105,164174.39769977125,153384.5703527972,22910.0,22909.999999767482,22909.999826840383,5.71987722050035e-16,9.791834857909584e-18,0.9969717770530057,0.011930237932024544,-0.0026897435561697674,0.007407652576797861 | ||
| 83 | +21297.579771767836,163385.8273468829,152737.03746099898,22844.0,22843.999999879547,22843.9991035317,5.688808155458493e-16,9.7608380955326e-18,0.987985497494533,0.011852158347747057,-0.007831002182125445,0.007402005571818617 | ||
| 84 | +22413.117900692392,165160.81083219431,153954.25188184812,23075.0,23074.99999963741,23074.9980466868,5.849262030225733e-16,9.88285352545655e-18,0.9941410946295832,0.011801812232478627,-0.008211194148192122,0.007291859455219944 | ||
| 85 | +21122.470503843215,163334.07738528133,152772.84213335972,22879.0,22878.999999898744,22878.99709745025,5.633723709743721e-16,9.722100961324131e-18,0.984984844375672,0.011857253919565828,-0.01296529513990941,0.007421939723453924 | ||
| 86 | +21282.707195805793,163941.15171670247,153299.79811879958,22909.0,22908.9999998743,22908.99996153768,5.729219609420647e-16,9.797812724663524e-18,0.9954654665694013,0.011861939156832611,-0.003583079120707077,0.007352470265065281 | ||
| 87 | +20724.34760198067,163318.72421718622,152956.55041619588,22790.0,22789.999999879707,22789.99813018993,5.550590116159096e-16,9.645783754938671e-18,0.9933982950272806,0.01187452330418287,-0.00495332364849543,0.0073808910696461375 | ||
| 88 | +21757.13207008707,165179.7837367039,154301.21770166035,23030.0,23029.999999515534,23029.999095339273,5.763186525066147e-16,9.828374022376591e-18,1.0136834107892345,0.011971605614733427,0.006510480574850554,0.007314863606454032 | ||
| 89 | +21671.1096591925,166527.63624669318,155692.08141709692,23264.0,23263.99999942336,23263.992478841574,5.84129987251449e-16,9.896922008537031e-18,1.0234213270128842,0.012014512018187535,0.006575992519346971,0.007267333319003582 | ||
| 90 | +21221.41757199116,163903.57706571487,153292.8682797193,22906.0,22905.999999861677,22905.998783516217,5.646919165369301e-16,9.724700045763518e-18,0.9900591679883312,0.011885002043500589,-0.009753133051711622,0.007408431197796472 | ||
| 91 | +21681.41252249159,165556.59745661478,154715.89119536898,23196.0,23195.999999720592,23195.99929739878,5.773631747722166e-16,9.836520659176885e-18,0.9977101559045379,0.01186422662665964,-0.012136729410717443,0.0073081040770472065 | ||
| 92 | +21153.477707419137,166277.3899099234,155700.65105621383,23255.0,23254.999999606127,23254.99604384548,5.653184419662256e-16,9.730321230819675e-18,1.019156144918438,0.01201068815115771,-0.0010363684582943512,0.007280823299749718 | ||
| 93 | +22226.132660409086,164336.5451073256,153223.47877712105,22935.0,22934.999999669544,22934.9976589201,5.8647466247030845e-16,9.907864241886007e-18,0.9988210866347508,0.011904203335735244,0.001435599985409938,0.0073741953380605406 | ||
| 94 | +21424.358322370157,164683.5971306915,153971.4179695064,22940.0,22939.99999953921,22939.999271899742,5.679278962446394e-16,9.75563702408002e-18,1.0098384925060064,0.011899202395887487,0.0050329170142471,0.007276269049906902 | ||
| 95 | +21455.353563566052,164947.2565606395,154219.57977885648,22987.0,22986.99999956718,22986.998933887335,5.706645322939917e-16,9.770262988270668e-18,1.0142244697962193,0.011960235218104793,0.007217238595620098,0.007300805026314625 | ||
| 96 | +21452.114580445574,164273.43465029492,153547.37736007213,22845.0,22844.9999995031,22844.999775048265,5.677909293087916e-16,9.751768271419505e-18,1.0082800787052053,0.011922505792565435,0.007632916428577924,0.007322032069579832 | ||
| 97 | +21019.69961927872,162935.32861177463,152425.47880213527,22657.0,22656.999999781452,22656.999043407268,5.573701521579324e-16,9.661153343333429e-18,0.994168966337365,0.011892058320532648,0.0016080034919236333,0.007408684998744538 | ||
| 98 | +21441.518593108456,164053.07922474376,153332.31992818954,22960.0,22959.99999984039,22959.999974187285,5.727077800111475e-16,9.793315534540368e-18,0.9933895462403782,0.011810199688400778,-0.0072931345463456265,0.007310683986440049 | ||
| 99 | +21781.365669648803,164462.0895137939,153571.4066789695,22877.0,22876.999999410484,22876.999794261017,5.738537591812932e-16,9.802523721098818e-18,1.0067930568779322,0.0119066595609444,0.006739517264159702,0.007318677995153281 | ||
| 100 | +21013.571768569178,162221.01090832267,151714.22502403808,22714.0,22713.999999970183,22714.000000122807,5.578526953798294e-16,9.670657005596775e-18,0.96868333949408,0.011813808188693846,-0.02057929881999145,0.007517120515436912 | ||
| 101 | +20965.61130349373,164112.7074564671,153629.90180472023,22893.0,22892.999999919695,22892.99927046633,5.5999754133615e-16,9.687391521031491e-18,0.9954549917387471,0.011910503281561615,-0.0062261048953279885,0.007392491292287055 |
test/dev/README.md
0 → 100644
| 1 | +Developer test scripts | ||
| 2 | +====================== | ||
| 3 | + | ||
| 4 | +This folder contains scripts that are used for various testing purposes | ||
| 5 | +during code development. None of the scripts actually needs to work, they | ||
| 6 | +may actually be outdated, but could still be useful for further testing | ||
| 7 | +if needed. | ||
| 8 | + | ||
| 9 | +`benchmark_cta_analysis.py` | ||
| 10 | +> This script peforms a benchmark of the various CTA analysis types | ||
| 11 | +> (unbinned, binned, stacked), and if matplotlib is installed, creates | ||
| 12 | +> a plot of the benchmark results. | ||
| 13 | + | ||
| 14 | +`check_models.py` | ||
| 15 | +> Checks a variety of models using an unbinned analysis. | ||
| 16 | + | ||
| 17 | +`make_pull_at_sensitivity_limit.py` | ||
| 18 | +> This script creates pull distributions as function of energy | ||
| 19 | +> for a test source that is at the 5 sigma sensitivity limit for | ||
| 20 | +> 50h of effective observing time. It takes as input file the | ||
| 21 | +> output file generated using cspull. | ||
| 22 | +> If the Python processing module is installed the script can make | ||
| 23 | +> use of multiple cores and runs in parallel. | ||
| 24 | + | ||
| 25 | +`make_survey.py` | ||
| 26 | +> This script simulates a CTA galactic plane survey. | ||
| 27 | + | ||
| 28 | +`simulate_events.py` | ||
| 29 | +> Simulates events and compares the simulation to the model. | ||
| 30 | + |
examples/benchmark_cta_analysis.py renamed to test/dev/benchmark_cta_analysis.py
| @@ -299,8 +299,7 @@ def stacked_pipeline(model_name, duration): | @@ -299,8 +299,7 @@ def stacked_pipeline(model_name, duration): | ||
| 299 | # Main routine entry point # | 299 | # Main routine entry point # |
| 300 | #==========================# | 300 | #==========================# |
| 301 | if __name__ == '__main__': | 301 | if __name__ == '__main__': |
| 302 | - """ | ||
| 303 | - """ | 302 | + |
| 304 | # Initialise parameters | 303 | # Initialise parameters |
| 305 | title = "CTA analysis benchmark" | 304 | title = "CTA analysis benchmark" |
| 306 | model_name = "${CTOOLS}/share/models/crab.xml" | 305 | model_name = "${CTOOLS}/share/models/crab.xml" |
examples/check_models.py renamed to test/dev/check_models.py
| 1 | #! /usr/bin/env python | 1 | #! /usr/bin/env python |
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | -# This script performs an unbinned maximum likelihood analysis for a | ||
| 4 | -# variety of models. This allows checking the models. | 3 | +# Performs unbinned maximum likelihood analysis for various models |
| 5 | # | 4 | # |
| 6 | -# Usage: | ||
| 7 | -# ./check_models.py | ||
| 8 | -# | ||
| 9 | -# ========================================================================== | ||
| 10 | -# | ||
| 11 | -# Copyright (C) 2011-2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2011-2016 Juergen Knoedlseder |
| 12 | # | 6 | # |
| 13 | # 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 |
| 14 | # 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 |
| @@ -33,26 +27,26 @@ import ctools | @@ -33,26 +27,26 @@ import ctools | ||
| 33 | # ================= # | 27 | # ================= # |
| 34 | def pipeline(model_name): | 28 | def pipeline(model_name): |
| 35 | """ | 29 | """ |
| 36 | - Unbinned analysis pipeline - keep intermediate results in memory. | 30 | + Unbinned in-memory analysis pipeline |
| 37 | 31 | ||
| 38 | This function implements an analysis pipeline that successively calls | 32 | This function implements an analysis pipeline that successively calls |
| 39 | ctobssim, ctselect and ctlike without saving the intermediate results as | 33 | ctobssim, ctselect and ctlike without saving the intermediate results as |
| 40 | FITS files on disk. All data is only hold in memory. | 34 | FITS files on disk. All data is only hold in memory. |
| 41 | """ | 35 | """ |
| 42 | # Set script parameters | 36 | # Set script parameters |
| 43 | - caldb = "prod2" | ||
| 44 | - irf = "South_50h" | 37 | + caldb = 'prod2' |
| 38 | + irf = 'South_0.5h' | ||
| 45 | ra = 83.63 | 39 | ra = 83.63 |
| 46 | dec = 22.01 | 40 | dec = 22.01 |
| 47 | - rad_sim = 10.0 | 41 | + rad_sim = 5.0 |
| 48 | tstart = 0.0 | 42 | tstart = 0.0 |
| 49 | - tstop = 1800.0 | 43 | + tstop = 180.0 |
| 50 | emin = 0.1 | 44 | emin = 0.1 |
| 51 | emax = 100.0 | 45 | emax = 100.0 |
| 52 | rad_select = 3.0 | 46 | rad_select = 3.0 |
| 53 | 47 | ||
| 54 | # Write model name | 48 | # Write model name |
| 55 | - print("*** Model: "+model_name+" ************************************") | 49 | + print('*** Model: '+model_name+' ************************************') |
| 56 | 50 | ||
| 57 | # Initialise timing | 51 | # Initialise timing |
| 58 | wall_seconds = 0.0 | 52 | wall_seconds = 0.0 |
| @@ -60,27 +54,27 @@ def pipeline(model_name): | @@ -60,27 +54,27 @@ def pipeline(model_name): | ||
| 60 | 54 | ||
| 61 | # Simulate events | 55 | # Simulate events |
| 62 | sim = ctools.ctobssim() | 56 | sim = ctools.ctobssim() |
| 63 | - sim["inmodel"] = model_name | ||
| 64 | - sim["caldb"] = caldb | ||
| 65 | - sim["irf"] = irf | ||
| 66 | - sim["ra"] = ra | ||
| 67 | - sim["dec"] = dec | ||
| 68 | - sim["rad"] = rad_sim | ||
| 69 | - sim["tmin"] = tstart | ||
| 70 | - sim["tmax"] = tstop | ||
| 71 | - sim["emin"] = emin | ||
| 72 | - sim["emax"] = emax | 57 | + sim['inmodel'] = model_name |
| 58 | + sim['caldb'] = caldb | ||
| 59 | + sim['irf'] = irf | ||
| 60 | + sim['ra'] = ra | ||
| 61 | + sim['dec'] = dec | ||
| 62 | + sim['rad'] = rad_sim | ||
| 63 | + sim['tmin'] = tstart | ||
| 64 | + sim['tmax'] = tstop | ||
| 65 | + sim['emin'] = emin | ||
| 66 | + sim['emax'] = emax | ||
| 73 | sim.run() | 67 | sim.run() |
| 74 | 68 | ||
| 75 | # Select events | 69 | # Select events |
| 76 | select = ctools.ctselect(sim.obs()) | 70 | select = ctools.ctselect(sim.obs()) |
| 77 | - select["ra"] = ra | ||
| 78 | - select["dec"] = dec | ||
| 79 | - select["rad"] = rad_select | ||
| 80 | - select["tmin"] = tstart | ||
| 81 | - select["tmax"] = tstop | ||
| 82 | - select["emin"] = emin | ||
| 83 | - select["emax"] = emax | 71 | + select['ra'] = ra |
| 72 | + select['dec'] = dec | ||
| 73 | + select['rad'] = rad_select | ||
| 74 | + select['tmin'] = tstart | ||
| 75 | + select['tmax'] = tstop | ||
| 76 | + select['emin'] = emin | ||
| 77 | + select['emax'] = emax | ||
| 84 | select.run() | 78 | select.run() |
| 85 | 79 | ||
| 86 | # Perform maximum likelihood fitting | 80 | # Perform maximum likelihood fitting |
| @@ -98,39 +92,37 @@ def pipeline(model_name): | @@ -98,39 +92,37 @@ def pipeline(model_name): | ||
| 98 | # Main routine entry point # | 92 | # Main routine entry point # |
| 99 | #==========================# | 93 | #==========================# |
| 100 | if __name__ == '__main__': | 94 | if __name__ == '__main__': |
| 101 | - """ | ||
| 102 | - Perform unbinned analyses for various models. | ||
| 103 | - """ | 95 | + |
| 104 | # Initialise flags | 96 | # Initialise flags |
| 105 | need_help = False | 97 | need_help = False |
| 106 | 98 | ||
| 107 | # Test for command line arguments | 99 | # Test for command line arguments |
| 108 | print(sys.argv[0]) | 100 | print(sys.argv[0]) |
| 109 | if (len(sys.argv) > 1): | 101 | if (len(sys.argv) > 1): |
| 110 | - if sys.argv[1] == "-h": | 102 | + if sys.argv[1] == '-h': |
| 111 | need_help = True | 103 | need_help = True |
| 112 | else: | 104 | else: |
| 113 | need_help = True | 105 | need_help = True |
| 114 | 106 | ||
| 115 | # Print help if needed and exit | 107 | # Print help if needed and exit |
| 116 | if need_help: | 108 | if need_help: |
| 117 | - print("Usage: check_models.py [OPTIONS]") | ||
| 118 | - print(" -h Display this usage message") | 109 | + print('Usage: check_models.py [OPTIONS]') |
| 110 | + print(' -h Display this usage message') | ||
| 119 | sys.exit() | 111 | sys.exit() |
| 120 | 112 | ||
| 121 | # Dump header | 113 | # Dump header |
| 122 | - print("*******************************************") | ||
| 123 | - print("* Check models using an unbinned analysis *") | ||
| 124 | - print("*******************************************") | 114 | + print('*******************************************') |
| 115 | + print('* Check models using an unbinned analysis *') | ||
| 116 | + print('*******************************************') | ||
| 125 | 117 | ||
| 126 | # Perform analysis for Crab model | 118 | # Perform analysis for Crab model |
| 127 | - pipeline("$CTOOLS/share/models/crab.xml") | 119 | + pipeline('$CTOOLS/share/models/crab.xml') |
| 128 | 120 | ||
| 129 | # Perform analysis for disk model | 121 | # Perform analysis for disk model |
| 130 | - pipeline("$CTOOLS/share/models/disk.xml") | 122 | + pipeline('$CTOOLS/share/models/disk.xml') |
| 131 | 123 | ||
| 132 | # Perform analysis for Gaussian model | 124 | # Perform analysis for Gaussian model |
| 133 | - pipeline("$CTOOLS/share/models/gauss.xml") | 125 | + pipeline('$CTOOLS/share/models/gauss.xml') |
| 134 | 126 | ||
| 135 | # Perform analysis for shell model | 127 | # Perform analysis for shell model |
| 136 | - pipeline("$CTOOLS/share/models/shell.xml") | 128 | + pipeline('$CTOOLS/share/models/shell.xml') |
cscripts/cta_kb_bkgrates.py renamed to test/dev/cta_kb_bkgrates.py
cscripts/cta_kb_root2caldb.py renamed to test/dev/cta_kb_root2caldb.py
cscripts/cta_make_nodes.py renamed to test/dev/cta_make_nodes.py
cscripts/cta_root2irf.py renamed to test/dev/cta_root2irf.py
examples/make_pull_at_sensitivity_limit.py renamed to test/dev/make_pull_at_sensitivity_limit.py
| @@ -135,11 +135,7 @@ def create_model(flux, index=-2.48, fitidx=False): | @@ -135,11 +135,7 @@ def create_model(flux, index=-2.48, fitidx=False): | ||
| 135 | # Main routine entry point # | 135 | # Main routine entry point # |
| 136 | # ======================== # | 136 | # ======================== # |
| 137 | if __name__ == '__main__': | 137 | if __name__ == '__main__': |
| 138 | - """ | ||
| 139 | - Create pull distributions for the energy bands and fluxes given in the | ||
| 140 | - file specified in the argument. The file needs to be created using the | ||
| 141 | - cssens script. | ||
| 142 | - """ | 138 | + |
| 143 | # Get input arguments | 139 | # Get input arguments |
| 144 | usage = """ | 140 | usage = """ |
| 145 | make_pull_at_sensitivity_limit filename [max_threads] | 141 | make_pull_at_sensitivity_limit filename [max_threads] |
examples/make_survey.py renamed to test/dev/make_survey.py
| @@ -303,9 +303,7 @@ def survey_gplane(lrange=10, lstep=2): | @@ -303,9 +303,7 @@ def survey_gplane(lrange=10, lstep=2): | ||
| 303 | # Main routine entry point # | 303 | # Main routine entry point # |
| 304 | #==========================# | 304 | #==========================# |
| 305 | if __name__ == '__main__': | 305 | if __name__ == '__main__': |
| 306 | - """ | ||
| 307 | - CTA survey simulation and analysis script. | ||
| 308 | - """ | 306 | + |
| 309 | # Initialise flags | 307 | # Initialise flags |
| 310 | need_help = False | 308 | need_help = False |
| 311 | 309 |
examples/simulate_events.py renamed to test/dev/simulate_events.py
| @@ -239,17 +239,15 @@ def show_events(events, xmlname, duration, emin, emax, ebins=30): | @@ -239,17 +239,15 @@ def show_events(events, xmlname, duration, emin, emax, ebins=30): | ||
| 239 | # Main routine entry point # | 239 | # Main routine entry point # |
| 240 | #==========================# | 240 | #==========================# |
| 241 | if __name__ == '__main__': | 241 | if __name__ == '__main__': |
| 242 | - """ | ||
| 243 | - Simulate events. | ||
| 244 | - """ | 242 | + |
| 245 | # Dump header | 243 | # Dump header |
| 246 | - print("") | ||
| 247 | - print("*******************") | ||
| 248 | - print("* Simulate events *") | ||
| 249 | - print("*******************") | 244 | + print('') |
| 245 | + print('*******************') | ||
| 246 | + print('* Simulate events *') | ||
| 247 | + print('*******************') | ||
| 250 | 248 | ||
| 251 | # Set XML names | 249 | # Set XML names |
| 252 | - xmlname = "model_bgd.xml" | 250 | + xmlname = 'model_bgd.xml' |
| 253 | 251 | ||
| 254 | # Set simulation parameters | 252 | # Set simulation parameters |
| 255 | duration = 360000.0 # Observation duration (s) | 253 | duration = 360000.0 # Observation duration (s) |
test/test_cscaldb.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test cscaldb on the command line. | 66 | Test cscaldb on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | cscaldb = '../cscripts/cscaldb.py' | 70 | cscaldb = '../cscripts/cscaldb.py' |
| 71 | else: | 71 | else: |
| 72 | cscaldb = 'cscaldb' | 72 | cscaldb = 'cscaldb' |
test/test_csfindobs.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csfindobs on the command line. | 66 | Test csfindobs on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | csfindobs = '../cscripts/csfindobs.py' | 70 | csfindobs = '../cscripts/csfindobs.py' |
| 71 | else: | 71 | else: |
| 72 | csfindobs = 'csfindobs' | 72 | csfindobs = 'csfindobs' |
test/test_csiactcopy.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csiactcopy on the command line. | 66 | Test csiactcopy on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | 69 | + if os.path.isfile("README.md"): |
| 70 | csiactcopy = "../cscripts/csiactcopy.py" | 70 | csiactcopy = "../cscripts/csiactcopy.py" |
| 71 | else: | 71 | else: |
| 72 | csiactcopy = "csiactcopy" | 72 | csiactcopy = "csiactcopy" |
test/test_csiactdata.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csiactdata on the command line. | 66 | Test csiactdata on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | 69 | + if os.path.isfile("README.md"): |
| 70 | csiactdata = "../cscripts/csiactdata.py" | 70 | csiactdata = "../cscripts/csiactdata.py" |
| 71 | else: | 71 | else: |
| 72 | csiactdata = "csiactdata" | 72 | csiactdata = "csiactdata" |
test/test_csiactobs.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csiactobs on the command line. | 66 | Test csiactobs on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | 69 | + if os.path.isfile("README.md"): |
| 70 | csiactobs = "../cscripts/csiactobs.py" | 70 | csiactobs = "../cscripts/csiactobs.py" |
| 71 | else: | 71 | else: |
| 72 | csiactobs = "csiactobs" | 72 | csiactobs = "csiactobs" |
test/test_cslightcrv.py
| @@ -70,7 +70,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -70,7 +70,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 70 | Test cslightcrv on the command line. | 70 | Test cslightcrv on the command line. |
| 71 | """ | 71 | """ |
| 72 | # Kluge to set the command (installed version has no README file) | 72 | # Kluge to set the command (installed version has no README file) |
| 73 | - if os.path.isfile('README'): | 73 | + if os.path.isfile('README.md'): |
| 74 | cslightcrv = '../cscripts/cslightcrv.py' | 74 | cslightcrv = '../cscripts/cslightcrv.py' |
| 75 | else: | 75 | else: |
| 76 | cslightcrv = 'cslightcrv' | 76 | cslightcrv = 'cslightcrv' |
test/test_csmodelinfo.py
| @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 69 | Test csmodelinfo on the command line. | 69 | Test csmodelinfo on the command line. |
| 70 | """ | 70 | """ |
| 71 | # Kluge to set the command (installed version has no README file) | 71 | # Kluge to set the command (installed version has no README file) |
| 72 | - if os.path.isfile("README"): | 72 | + if os.path.isfile("README.md"): |
| 73 | csmodelinfo = "../cscripts/csmodelinfo.py" | 73 | csmodelinfo = "../cscripts/csmodelinfo.py" |
| 74 | else: | 74 | else: |
| 75 | csmodelinfo = "csmodelinfo" | 75 | csmodelinfo = "csmodelinfo" |
test/test_csmodelmerge.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csmodelmerge on the command line. | 66 | Test csmodelmerge on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | 69 | + if os.path.isfile("README.md"): |
| 70 | csmodelmerge = "../cscripts/csmodelmerge.py" | 70 | csmodelmerge = "../cscripts/csmodelmerge.py" |
| 71 | else: | 71 | else: |
| 72 | csmodelmerge = "csmodelmerge" | 72 | csmodelmerge = "csmodelmerge" |
test/test_csobs2caldb.py
| @@ -73,7 +73,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -73,7 +73,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 73 | Test csobs2caldb on the command line. | 73 | Test csobs2caldb on the command line. |
| 74 | """ | 74 | """ |
| 75 | # Kluge to set the command (installed version has no README file) | 75 | # Kluge to set the command (installed version has no README file) |
| 76 | - if os.path.isfile("README"): | 76 | + if os.path.isfile("README.md"): |
| 77 | csobs2caldb = "../cscripts/csobs2caldb.py" | 77 | csobs2caldb = "../cscripts/csobs2caldb.py" |
| 78 | else: | 78 | else: |
| 79 | csobs2caldb = "csobs2caldb" | 79 | csobs2caldb = "csobs2caldb" |
test/test_csobsdef.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csobsdef on the command line. | 66 | Test csobsdef on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | csobsdef = '../cscripts/csobsdef.py' | 70 | csobsdef = '../cscripts/csobsdef.py' |
| 71 | else: | 71 | else: |
| 72 | csobsdef = 'csobsdef' | 72 | csobsdef = 'csobsdef' |
test/test_csobsinfo.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csobsinfo on the command line. | 66 | Test csobsinfo on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | 69 | + if os.path.isfile("README.md"): |
| 70 | csobsinfo = "../cscripts/csobsinfo.py" | 70 | csobsinfo = "../cscripts/csobsinfo.py" |
| 71 | else: | 71 | else: |
| 72 | csobsinfo = "csobsinfo" | 72 | csobsinfo = "csobsinfo" |
test/test_cspull.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test cspull on the command line. | 66 | Test cspull on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | 69 | + if os.path.isfile("README.md"): |
| 70 | cspull = "../cscripts/cspull.py" | 70 | cspull = "../cscripts/cspull.py" |
| 71 | else: | 71 | else: |
| 72 | cspull = "cspull" | 72 | cspull = "cspull" |
test/test_csresmap.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csresmap on the command line. | 66 | Test csresmap on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | csresmap = '../cscripts/csresmap.py' | 70 | csresmap = '../cscripts/csresmap.py' |
| 71 | else: | 71 | else: |
| 72 | csresmap = 'csresmap' | 72 | csresmap = 'csresmap' |
test/test_csroot2caldb.py
| @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 69 | Test csroot2caldb on the command line. | 69 | Test csroot2caldb on the command line. |
| 70 | """ | 70 | """ |
| 71 | # Kluge to set the command (installed version has no README file) | 71 | # Kluge to set the command (installed version has no README file) |
| 72 | - if os.path.isfile("README"): | 72 | + if os.path.isfile("README.md"): |
| 73 | csroot2caldb = "../cscripts/csroot2caldb.py" | 73 | csroot2caldb = "../cscripts/csroot2caldb.py" |
| 74 | else: | 74 | else: |
| 75 | csroot2caldb = "csroot2caldb" | 75 | csroot2caldb = "csroot2caldb" |
test/test_cssens.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test cssens on the command line. | 66 | Test cssens on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | cssens = '../cscripts/cssens.py' | 70 | cssens = '../cscripts/cssens.py' |
| 71 | else: | 71 | else: |
| 72 | cssens = 'cssens' | 72 | cssens = 'cssens' |
test/test_csspec.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test csspec on the command line. | 66 | Test csspec on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | csspec = '../cscripts/csspec.py' | 70 | csspec = '../cscripts/csspec.py' |
| 71 | else: | 71 | else: |
| 72 | csspec = 'csspec' | 72 | csspec = 'csspec' |
test/test_cstsdist.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test cstsdist on the command line. | 66 | Test cstsdist on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | cstsdist = '../cscripts/cstsdist.py' | 70 | cstsdist = '../cscripts/cstsdist.py' |
| 71 | else: | 71 | else: |
| 72 | cstsdist = 'cstsdist' | 72 | cstsdist = 'cstsdist' |
test/test_cstsmapmerge.py
| @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -66,7 +66,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 66 | Test cstsmapmerge on the command line. | 66 | Test cstsmapmerge on the command line. |
| 67 | """ | 67 | """ |
| 68 | # Kluge to set the command (installed version has no README file) | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile('README'): | 69 | + if os.path.isfile('README.md'): |
| 70 | cstsmapmerge = '../cscripts/cstsmapmerge.py' | 70 | cstsmapmerge = '../cscripts/cstsmapmerge.py' |
| 71 | else: | 71 | else: |
| 72 | cstsmapmerge = 'cstsmapmerge' | 72 | cstsmapmerge = 'cstsmapmerge' |
test/test_csworkflow.py
| @@ -64,7 +64,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -64,7 +64,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 64 | def _test_cmd(self): | 64 | def _test_cmd(self): |
| 65 | 65 | ||
| 66 | # Kluge to set the command (installed version has no README file) | 66 | # Kluge to set the command (installed version has no README file) |
| 67 | - if os.path.isfile('README'): | 67 | + if os.path.isfile('README.md'): |
| 68 | csworkflow = '../cscripts/csworkflow.py' | 68 | csworkflow = '../cscripts/csworkflow.py' |
| 69 | else: | 69 | else: |
| 70 | csworkflow = 'csworkflow' | 70 | csworkflow = 'csworkflow' |
test/test_ctbin.py
| @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 69 | Test ctbin on the command line. | 69 | Test ctbin on the command line. |
| 70 | """ | 70 | """ |
| 71 | # Kluge to set the command (installed version has no README file) | 71 | # Kluge to set the command (installed version has no README file) |
| 72 | - if os.path.isfile("README"): | 72 | + if os.path.isfile("README.md"): |
| 73 | ctbin = "../src/ctbin/ctbin" | 73 | ctbin = "../src/ctbin/ctbin" |
| 74 | else: | 74 | else: |
| 75 | ctbin = "ctbin" | 75 | ctbin = "ctbin" |
test/test_ctbkgcube.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctbkgcube on the command line. | 62 | Test ctbkgcube on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctbkgcube = '../src/ctbkgcube/ctbkgcube' | 66 | ctbkgcube = '../src/ctbkgcube/ctbkgcube' |
| 67 | else: | 67 | else: |
| 68 | ctbkgcube = 'ctbkgcube' | 68 | ctbkgcube = 'ctbkgcube' |
test/test_ctbutterfly.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctbutterfly on the command line. | 62 | Test ctbutterfly on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctbutterfly = '../src/ctbutterfly/ctbutterfly' | 66 | ctbutterfly = '../src/ctbutterfly/ctbutterfly' |
| 67 | else: | 67 | else: |
| 68 | ctbutterfly = 'ctbutterfly' | 68 | ctbutterfly = 'ctbutterfly' |
test/test_ctcubemask.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctcubemask on the command line. | 62 | Test ctcubemask on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctcubemask = '../src/ctcubemask/ctcubemask' | 66 | ctcubemask = '../src/ctcubemask/ctcubemask' |
| 67 | else: | 67 | else: |
| 68 | ctcubemask = 'ctcubemask' | 68 | ctcubemask = 'ctcubemask' |
test/test_ctedispcube.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctedispcube on the command line. | 62 | Test ctedispcube on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctedispcube = '../src/ctedispcube/ctedispcube' | 66 | ctedispcube = '../src/ctedispcube/ctedispcube' |
| 67 | else: | 67 | else: |
| 68 | ctedispcube = 'ctedispcube' | 68 | ctedispcube = 'ctedispcube' |
test/test_cterror.py
| @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 69 | Test cterror on the command line. | 69 | Test cterror on the command line. |
| 70 | """ | 70 | """ |
| 71 | # Kluge to set the command (installed version has no README file) | 71 | # Kluge to set the command (installed version has no README file) |
| 72 | - if os.path.isfile('README'): | 72 | + if os.path.isfile('README.md'): |
| 73 | cterror = '../src/cterror/cterror' | 73 | cterror = '../src/cterror/cterror' |
| 74 | else: | 74 | else: |
| 75 | cterror = 'cterror' | 75 | cterror = 'cterror' |
test/test_ctexpcube.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctexpcube on the command line. | 62 | Test ctexpcube on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctexpcube = '../src/ctexpcube/ctexpcube' | 66 | ctexpcube = '../src/ctexpcube/ctexpcube' |
| 67 | else: | 67 | else: |
| 68 | ctexpcube = 'ctexpcube' | 68 | ctexpcube = 'ctexpcube' |
test/test_ctlike.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctlike on the command line. | 62 | Test ctlike on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctlike = '../src/ctlike/ctlike' | 66 | ctlike = '../src/ctlike/ctlike' |
| 67 | else: | 67 | else: |
| 68 | ctlike = 'ctlike' | 68 | ctlike = 'ctlike' |
test/test_ctmapcube.py
| @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -69,7 +69,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 69 | Test ctmapcube on the command line. | 69 | Test ctmapcube on the command line. |
| 70 | """ | 70 | """ |
| 71 | # Kluge to set the command (installed version has no README file) | 71 | # Kluge to set the command (installed version has no README file) |
| 72 | - if os.path.isfile("README"): | 72 | + if os.path.isfile("README.md"): |
| 73 | ctmapcube = "../src/ctmapcube/ctmapcube" | 73 | ctmapcube = "../src/ctmapcube/ctmapcube" |
| 74 | else: | 74 | else: |
| 75 | ctmapcube = "ctmapcube" | 75 | ctmapcube = "ctmapcube" |
test/test_ctmodel.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctmodel on the command line. | 62 | Test ctmodel on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctmodel = '../src/ctmodel/ctmodel' | 66 | ctmodel = '../src/ctmodel/ctmodel' |
| 67 | else: | 67 | else: |
| 68 | ctmodel = 'ctmodel' | 68 | ctmodel = 'ctmodel' |
test/test_ctobssim.py
| @@ -72,7 +72,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -72,7 +72,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 72 | Test ctobssim on the command line. | 72 | Test ctobssim on the command line. |
| 73 | """ | 73 | """ |
| 74 | # Kluge to set the command (installed version has no README file) | 74 | # Kluge to set the command (installed version has no README file) |
| 75 | - if os.path.isfile("README"): | 75 | + if os.path.isfile("README.md"): |
| 76 | ctobssim = "../src/ctobssim/ctobssim" | 76 | ctobssim = "../src/ctobssim/ctobssim" |
| 77 | else: | 77 | else: |
| 78 | ctobssim = "ctobssim" | 78 | ctobssim = "ctobssim" |
test/test_ctpsfcube.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctpsfcube on the command line. | 62 | Test ctpsfcube on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctpsfcube = '../src/ctpsfcube/ctpsfcube' | 66 | ctpsfcube = '../src/ctpsfcube/ctpsfcube' |
| 67 | else: | 67 | else: |
| 68 | ctpsfcube = 'ctpsfcube' | 68 | ctpsfcube = 'ctpsfcube' |
test/test_ctselect.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctselect on the command line. | 62 | Test ctselect on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctselect = '../src/ctselect/ctselect' | 66 | ctselect = '../src/ctselect/ctselect' |
| 67 | else: | 67 | else: |
| 68 | ctselect = 'ctselect' | 68 | ctselect = 'ctselect' |
test/test_ctskymap.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctskymap on the command line. | 62 | Test ctskymap on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctskymap = '../src/ctskymap/ctskymap' | 66 | ctskymap = '../src/ctskymap/ctskymap' |
| 67 | else: | 67 | else: |
| 68 | ctskymap = 'ctskymap' | 68 | ctskymap = 'ctskymap' |
test/test_cttsmap.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test cttsmap on the command line. | 62 | Test cttsmap on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | cttsmap = '../src/cttsmap/cttsmap' | 66 | cttsmap = '../src/cttsmap/cttsmap' |
| 67 | else: | 67 | else: |
| 68 | cttsmap = 'cttsmap' | 68 | cttsmap = 'cttsmap' |
test/test_ctulimit.py
| @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | @@ -62,7 +62,7 @@ class Test(gammalib.GPythonTestSuite): | ||
| 62 | Test ctulimit on the command line. | 62 | Test ctulimit on the command line. |
| 63 | """ | 63 | """ |
| 64 | # Kluge to set the command (installed version has no README file) | 64 | # Kluge to set the command (installed version has no README file) |
| 65 | - if os.path.isfile('README'): | 65 | + if os.path.isfile('README.md'): |
| 66 | ctulimit = '../src/ctulimit/ctulimit' | 66 | ctulimit = '../src/ctulimit/ctulimit' |
| 67 | else: | 67 | else: |
| 68 | ctulimit = 'ctulimit' | 68 | ctulimit = 'ctulimit' |
test/test_examples.py
0 → 100755
| 1 | +#! /usr/bin/env python | ||
| 2 | +# ========================================================================== | ||
| 3 | +# Performs unit tests for the ctools example scripts | ||
| 4 | +# | ||
| 5 | +# Copyright (C) 2016 Juergen Knoedlseder | ||
| 6 | +# | ||
| 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 | ||
| 9 | +# the Free Software Foundation, either version 3 of the License, or | ||
| 10 | +# (at your option) any later version. | ||
| 11 | +# | ||
| 12 | +# This program is distributed in the hope that it will be useful, | ||
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | +# GNU General Public License for more details. | ||
| 16 | +# | ||
| 17 | +# You should have received a copy of the GNU General Public License | ||
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | +# | ||
| 20 | +# ========================================================================== | ||
| 21 | +import os | ||
| 22 | +import sys | ||
| 23 | +import gammalib | ||
| 24 | +import ctools | ||
| 25 | +import cscripts | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +# =============================================== # | ||
| 29 | +# Test class for example executables unit testing # | ||
| 30 | +# =============================================== # | ||
| 31 | +class Test(gammalib.GPythonTestSuite): | ||
| 32 | + """ | ||
| 33 | + Test class for GammaLib example executables | ||
| 34 | + """ | ||
| 35 | + # Constructor | ||
| 36 | + def __init__(self): | ||
| 37 | + """ | ||
| 38 | + Constructor. | ||
| 39 | + """ | ||
| 40 | + # Call base class constructor | ||
| 41 | + gammalib.GPythonTestSuite.__init__(self) | ||
| 42 | + | ||
| 43 | + # Return | ||
| 44 | + return | ||
| 45 | + | ||
| 46 | + # Execute Python script | ||
| 47 | + def _execute_python(self, name, args='', log=''): | ||
| 48 | + """ | ||
| 49 | + Execute Python script | ||
| 50 | + | ||
| 51 | + Parameters | ||
| 52 | + ---------- | ||
| 53 | + name : str | ||
| 54 | + Python script name with .py extension | ||
| 55 | + args : str, optional | ||
| 56 | + String with arguments to be passed to script | ||
| 57 | + log : str, optional | ||
| 58 | + String with name to be used for logging | ||
| 59 | + """ | ||
| 60 | + # Setup command | ||
| 61 | + cmd = '../examples/' + name + '.py' | ||
| 62 | + if len(args) > 0: | ||
| 63 | + cmd += ' ' + args | ||
| 64 | + | ||
| 65 | + # Set logname | ||
| 66 | + if len(log) > 0: | ||
| 67 | + logname = log | ||
| 68 | + else: | ||
| 69 | + logname = name | ||
| 70 | + | ||
| 71 | + # Execute Python script, make sure we catch any exception | ||
| 72 | + try: | ||
| 73 | + rc = os.system(cmd+' > example_'+logname+'.log 2>&1') | ||
| 74 | + except: | ||
| 75 | + pass | ||
| 76 | + | ||
| 77 | + # Check if execution was successful | ||
| 78 | + self.test_assert(rc == 0, 'Check "'+name+'" script from command line') | ||
| 79 | + | ||
| 80 | + # Return | ||
| 81 | + return | ||
| 82 | + | ||
| 83 | + # Set test functions | ||
| 84 | + def set(self): | ||
| 85 | + """ | ||
| 86 | + Set all test functions | ||
| 87 | + """ | ||
| 88 | + # Set test name | ||
| 89 | + self.name('examples') | ||
| 90 | + | ||
| 91 | + # Append tests | ||
| 92 | + self.append(self.test_generate_prod3_irfs, 'Test generate_prod3_irfs.py') | ||
| 93 | + self.append(self.test_make_pointings, 'Test make_pointings.py') | ||
| 94 | + self.append(self.test_make_spectrum, 'Test make_spectrum.py') | ||
| 95 | + self.append(self.test_make_ts_distributions, 'Test make_ts_distributions.py') | ||
| 96 | + self.append(self.test_pipeline_binned_disk, 'Test pipeline_binned_disk.py') | ||
| 97 | + self.append(self.test_pipeline_binned_mem, 'Test pipeline_binned_mem.py') | ||
| 98 | + self.append(self.test_pipeline_stacked_disk, 'Test pipeline_stacked_disk.py') | ||
| 99 | + self.append(self.test_pipeline_stacked_mem, 'Test pipeline_stacked_mem.py') | ||
| 100 | + self.append(self.test_pipeline_unbinned_disk, 'Test pipeline_unbinned_disk.py') | ||
| 101 | + self.append(self.test_pipeline_unbinned_mem, 'Test pipeline_unbinned_mem.py') | ||
| 102 | + self.append(self.test_show_butterfly, 'Test show_butterfly.py') | ||
| 103 | + self.append(self.test_show_model, 'Test show_model.py') | ||
| 104 | + self.append(self.test_show_pha, 'Test show_pha.py') | ||
| 105 | + self.append(self.test_show_pull_evolution, 'Test show_pull_evolution.py') | ||
| 106 | + self.append(self.test_show_pull_histogram, 'Test show_pull_histogram.py') | ||
| 107 | + self.append(self.test_show_response, 'Test test_show_response.py') | ||
| 108 | + self.append(self.test_show_sensitivity, 'Test test_show_sensitivity.py') | ||
| 109 | + self.append(self.test_show_spectrum, 'Test test_show_spectrum.py') | ||
| 110 | + self.append(self.test_show_ts_distribution, 'Test show_ts_distribution.py') | ||
| 111 | + | ||
| 112 | + # Return | ||
| 113 | + return | ||
| 114 | + | ||
| 115 | + # Test make_pointings | ||
| 116 | + def test_make_pointings(self): | ||
| 117 | + """ | ||
| 118 | + Test make_pointings | ||
| 119 | + """ | ||
| 120 | + # Set script name | ||
| 121 | + script = 'make_pointings' | ||
| 122 | + | ||
| 123 | + # Execute script | ||
| 124 | + self._execute_python(script, args='-h', log='make_pointings_h') | ||
| 125 | + self._execute_python(script, args='gps', log='make_pointings_gps') | ||
| 126 | + self._execute_python(script, args='gps3', log='make_pointings_gps3') | ||
| 127 | + self._execute_python(script, args='extgal', log='make_pointings_extgal') | ||
| 128 | + self._execute_python(script, args='gc', log='make_pointings_gc') | ||
| 129 | + self._execute_python(script, args='lmc', log='make_pointings_lmc') | ||
| 130 | + | ||
| 131 | + #TODO: Do any testing | ||
| 132 | + | ||
| 133 | + # Return | ||
| 134 | + return | ||
| 135 | + | ||
| 136 | + # Test generate_prod3_irfs | ||
| 137 | + def test_generate_prod3_irfs(self): | ||
| 138 | + """ | ||
| 139 | + Test generate_prod3_irfs | ||
| 140 | + """ | ||
| 141 | + # Execute script | ||
| 142 | + self._execute_python('generate_prod3_irfs') | ||
| 143 | + | ||
| 144 | + #TODO: Do any testing | ||
| 145 | + | ||
| 146 | + # Return | ||
| 147 | + return | ||
| 148 | + | ||
| 149 | + # Test make_spectrum | ||
| 150 | + def test_make_spectrum(self): | ||
| 151 | + """ | ||
| 152 | + Test make_spectrum | ||
| 153 | + """ | ||
| 154 | + # Execute script | ||
| 155 | + self._execute_python('make_spectrum', args='eps') | ||
| 156 | + | ||
| 157 | + #TODO: Do any testing | ||
| 158 | + | ||
| 159 | + # Return | ||
| 160 | + return | ||
| 161 | + | ||
| 162 | + # Test make_ts_distributions | ||
| 163 | + def test_make_ts_distributions(self): | ||
| 164 | + """ | ||
| 165 | + Test make_ts_distributions | ||
| 166 | + """ | ||
| 167 | + # Execute script | ||
| 168 | + self._execute_python('make_ts_distributions', args='-n 2 -e 0 -d 1800') | ||
| 169 | + | ||
| 170 | + #TODO: Do any testing | ||
| 171 | + | ||
| 172 | + # Return | ||
| 173 | + return | ||
| 174 | + | ||
| 175 | + # Test pipeline_binned_disk | ||
| 176 | + def test_pipeline_binned_disk(self): | ||
| 177 | + """ | ||
| 178 | + Test pipeline_binned_disk | ||
| 179 | + """ | ||
| 180 | + # Execute script | ||
| 181 | + self._execute_python('pipeline_binned_disk') | ||
| 182 | + | ||
| 183 | + #TODO: Do any testing | ||
| 184 | + | ||
| 185 | + # Return | ||
| 186 | + return | ||
| 187 | + | ||
| 188 | + # Test pipeline_binned_mem | ||
| 189 | + def test_pipeline_binned_mem(self): | ||
| 190 | + """ | ||
| 191 | + Test pipeline_binned_mem | ||
| 192 | + """ | ||
| 193 | + # Execute script | ||
| 194 | + self._execute_python('pipeline_binned_mem') | ||
| 195 | + | ||
| 196 | + #TODO: Do any testing | ||
| 197 | + | ||
| 198 | + # Return | ||
| 199 | + return | ||
| 200 | + | ||
| 201 | + # Test pipeline_stacked_disk | ||
| 202 | + def test_pipeline_stacked_disk(self): | ||
| 203 | + """ | ||
| 204 | + Test pipeline_stacked_disk | ||
| 205 | + """ | ||
| 206 | + # Execute script | ||
| 207 | + self._execute_python('pipeline_stacked_disk') | ||
| 208 | + | ||
| 209 | + #TODO: Do any testing | ||
| 210 | + | ||
| 211 | + # Return | ||
| 212 | + return | ||
| 213 | + | ||
| 214 | + # Test pipeline_stacked_mem | ||
| 215 | + def test_pipeline_stacked_mem(self): | ||
| 216 | + """ | ||
| 217 | + Test pipeline_stacked_mem | ||
| 218 | + """ | ||
| 219 | + # Execute script | ||
| 220 | + self._execute_python('pipeline_stacked_mem') | ||
| 221 | + | ||
| 222 | + #TODO: Do any testing | ||
| 223 | + | ||
| 224 | + # Return | ||
| 225 | + return | ||
| 226 | + | ||
| 227 | + # Test pipeline_unbinned_disk | ||
| 228 | + def test_pipeline_unbinned_disk(self): | ||
| 229 | + """ | ||
| 230 | + Test pipeline_unbinned_disk | ||
| 231 | + """ | ||
| 232 | + # Execute script | ||
| 233 | + self._execute_python('pipeline_unbinned_disk') | ||
| 234 | + | ||
| 235 | + #TODO: Do any testing | ||
| 236 | + | ||
| 237 | + # Return | ||
| 238 | + return | ||
| 239 | + | ||
| 240 | + # Test pipeline_unbinned_mem | ||
| 241 | + def test_pipeline_unbinned_mem(self): | ||
| 242 | + """ | ||
| 243 | + Test pipeline_unbinned_mem | ||
| 244 | + """ | ||
| 245 | + # Execute script | ||
| 246 | + self._execute_python('pipeline_unbinned_mem') | ||
| 247 | + | ||
| 248 | + #TODO: Do any testing | ||
| 249 | + | ||
| 250 | + # Return | ||
| 251 | + return | ||
| 252 | + | ||
| 253 | + # Test show_butterfly | ||
| 254 | + def test_show_butterfly(self): | ||
| 255 | + """ | ||
| 256 | + Test show_butterfly | ||
| 257 | + """ | ||
| 258 | + # Execute script | ||
| 259 | + self._execute_python('show_butterfly', | ||
| 260 | + args='data/butterfly.txt ' | ||
| 261 | + 'example_show_butterfly.eps') | ||
| 262 | + | ||
| 263 | + #TODO: Do any testing | ||
| 264 | + | ||
| 265 | + # Return | ||
| 266 | + return | ||
| 267 | + | ||
| 268 | + # Test show_model | ||
| 269 | + def test_show_model(self): | ||
| 270 | + """ | ||
| 271 | + Test show_model | ||
| 272 | + """ | ||
| 273 | + # Execute script | ||
| 274 | + self._execute_python('show_model', | ||
| 275 | + args='data/crab.xml Crab example_show_model.eps') | ||
| 276 | + | ||
| 277 | + #TODO: Do any testing | ||
| 278 | + | ||
| 279 | + # Return | ||
| 280 | + return | ||
| 281 | + | ||
| 282 | + # Test show_pha | ||
| 283 | + def test_show_pha(self): | ||
| 284 | + """ | ||
| 285 | + Test show_pha | ||
| 286 | + """ | ||
| 287 | + # Execute script | ||
| 288 | + self._execute_python('show_pha', | ||
| 289 | + args='data/pha.fits example_show_pha.eps') | ||
| 290 | + | ||
| 291 | + #TODO: Do any testing | ||
| 292 | + | ||
| 293 | + # Return | ||
| 294 | + return | ||
| 295 | + | ||
| 296 | + # Test show_pull_evolution | ||
| 297 | + def test_show_pull_evolution(self): | ||
| 298 | + """ | ||
| 299 | + Test show_pull_evolution | ||
| 300 | + """ | ||
| 301 | + # Execute script | ||
| 302 | + self._execute_python('show_pull_evolution', | ||
| 303 | + args='data/pull.dat Pull_Crab_Prefactor ' | ||
| 304 | + 'example_show_pull_evolution.eps') | ||
| 305 | + | ||
| 306 | + #TODO: Do any testing | ||
| 307 | + | ||
| 308 | + # Return | ||
| 309 | + return | ||
| 310 | + | ||
| 311 | + # Test show_pull_histogram | ||
| 312 | + def test_show_pull_histogram(self): | ||
| 313 | + """ | ||
| 314 | + Test show_pull_histogram | ||
| 315 | + """ | ||
| 316 | + # Execute script | ||
| 317 | + self._execute_python('show_pull_histogram', | ||
| 318 | + args='data/pull.dat Pull_Crab_Prefactor 50 ' | ||
| 319 | + 'example_show_pull_histogram.eps') | ||
| 320 | + | ||
| 321 | + #TODO: Do any testing | ||
| 322 | + | ||
| 323 | + # Return | ||
| 324 | + return | ||
| 325 | + | ||
| 326 | + # Test show_response | ||
| 327 | + def test_show_response(self): | ||
| 328 | + """ | ||
| 329 | + Test show_response | ||
| 330 | + """ | ||
| 331 | + # Execute script | ||
| 332 | + self._execute_python('show_response', args='example_show_response.eps') | ||
| 333 | + | ||
| 334 | + #TODO: Do any testing | ||
| 335 | + | ||
| 336 | + # Return | ||
| 337 | + return | ||
| 338 | + | ||
| 339 | + # Test show_sensitivity | ||
| 340 | + def test_show_sensitivity(self): | ||
| 341 | + """ | ||
| 342 | + Test show_sensitivity | ||
| 343 | + """ | ||
| 344 | + # Execute script | ||
| 345 | + self._execute_python('show_sensitivity', | ||
| 346 | + args='data/sensitivity.dat ' | ||
| 347 | + 'example_show_sensitivity.eps') | ||
| 348 | + | ||
| 349 | + #TODO: Do any testing | ||
| 350 | + | ||
| 351 | + # Return | ||
| 352 | + return | ||
| 353 | + | ||
| 354 | + # Test show_spectrum | ||
| 355 | + def test_show_spectrum(self): | ||
| 356 | + """ | ||
| 357 | + Test show_spectrum | ||
| 358 | + """ | ||
| 359 | + # Execute script | ||
| 360 | + self._execute_python('show_spectrum', | ||
| 361 | + args='data/spectrum.fits ' | ||
| 362 | + 'example_show_spectrum.eps') | ||
| 363 | + | ||
| 364 | + #TODO: Do any testing | ||
| 365 | + | ||
| 366 | + # Return | ||
| 367 | + return | ||
| 368 | + | ||
| 369 | + # Test show_ts_distribution | ||
| 370 | + def test_show_ts_distribution(self): | ||
| 371 | + """ | ||
| 372 | + Test show_ts_distribution | ||
| 373 | + """ | ||
| 374 | + # Execute script | ||
| 375 | + self._execute_python('show_ts_distribution', | ||
| 376 | + args='data/ts.dat -n 100 ' | ||
| 377 | + '-f example_show_ts_distribution.eps') | ||
| 378 | + | ||
| 379 | + #TODO: Do any testing | ||
| 380 | + | ||
| 381 | + # Return | ||
| 382 | + return | ||
| 383 | + | ||
| 384 | + | ||
| 385 | +# ======================== # | ||
| 386 | +# Main routine entry point # | ||
| 387 | +# ======================== # | ||
| 388 | +if __name__ == '__main__': | ||
| 389 | + | ||
| 390 | + # Set calibration database | ||
| 391 | + os.environ['CALDB'] = '../caldb' | ||
| 392 | + | ||
| 393 | + # Set PFILES environment variable | ||
| 394 | + try: | ||
| 395 | + os.mkdir('pfiles') | ||
| 396 | + except: | ||
| 397 | + pass | ||
| 398 | + os.environ['PFILES'] = 'pfiles' | ||
| 399 | + | ||
| 400 | + # Copy over pfiles | ||
| 401 | + os.system('cp -r ../src/*/*.par pfiles/') | ||
| 402 | + os.system('cp -r ../cscripts/*.par pfiles/') | ||
| 403 | + | ||
| 404 | + # Allocate test suites | ||
| 405 | + suites = gammalib.GTestSuites('Examples testing') | ||
| 406 | + | ||
| 407 | + # Allocate test suite, setup tests and append them to the container | ||
| 408 | + suite = Test() | ||
| 409 | + suite.set() | ||
| 410 | + suites.append(suite) | ||
| 411 | + | ||
| 412 | + # Run test suite | ||
| 413 | + success = suites.run() | ||
| 414 | + | ||
| 415 | + # Save test results | ||
| 416 | + suites.save('reports/examples.xml') | ||
| 417 | + | ||
| 418 | + # Set return code | ||
| 419 | + if success: | ||
| 420 | + rc = 0 | ||
| 421 | + else: | ||
| 422 | + rc = 1 | ||
| 423 | + | ||
| 424 | + # Exit with return code | ||
| 425 | + sys.exit(rc) |
test/test_examples.sh.in
0 → 100755
| 1 | +#! /bin/sh | ||
| 2 | +# ========================================================================== | ||
| 3 | +# This script launches the examples unit tests | ||
| 4 | +# | ||
| 5 | +# Copyright (C) 2016 Juergen Knoedlseder | ||
| 6 | +# | ||
| 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 | ||
| 9 | +# the Free Software Foundation, either version 3 of the License, or | ||
| 10 | +# (at your option) any later version. | ||
| 11 | +# | ||
| 12 | +# This program is distributed in the hope that it will be useful, | ||
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | +# GNU General Public License for more details. | ||
| 16 | +# | ||
| 17 | +# You should have received a copy of the GNU General Public License | ||
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | +# | ||
| 20 | +# ========================================================================== | ||
| 21 | + | ||
| 22 | +# | ||
| 23 | +# Run the examples test | ||
| 24 | +# ===================== | ||
| 25 | +@PYTHON_COVERAGE@./test_examples.py |
test/test_python_cscripts.py
| @@ -188,6 +188,10 @@ def test(installed=False, debug=False): | @@ -188,6 +188,10 @@ def test(installed=False, debug=False): | ||
| 188 | else: | 188 | else: |
| 189 | rc = 1 | 189 | rc = 1 |
| 190 | 190 | ||
| 191 | + # Remove temporary direction | ||
| 192 | + if installed: | ||
| 193 | + os.system('rm -rf %s' % (path)) | ||
| 194 | + | ||
| 191 | # Exit with return code | 195 | # Exit with return code |
| 192 | sys.exit(rc) | 196 | sys.exit(rc) |
| 193 | 197 |
test/test_python_ctools.py
| @@ -158,6 +158,10 @@ def test(installed=False): | @@ -158,6 +158,10 @@ def test(installed=False): | ||
| 158 | else: | 158 | else: |
| 159 | rc = 1 | 159 | rc = 1 |
| 160 | 160 | ||
| 161 | + # Remove temporary direction | ||
| 162 | + if installed: | ||
| 163 | + os.system('rm -rf %s' % (path)) | ||
| 164 | + | ||
| 161 | # Exit with return code | 165 | # Exit with return code |
| 162 | sys.exit(rc) | 166 | sys.exit(rc) |
| 163 | 167 |
testall.sh
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | # ===================================================================== | 2 | # ===================================================================== |
| 3 | -# Run all test and example scripts that come with the package. | 3 | +# Run some test scripts that come with the package |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2011-2015 Juergen Knoedlseder | 5 | +# Copyright (C) 2011-2016 Juergen Knoedlseder |
| 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 |
| @@ -25,11 +25,11 @@ base=$PWD | @@ -25,11 +25,11 @@ base=$PWD | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | # | 27 | # |
| 28 | -# examples | 28 | +# test/dev |
| 29 | # ======== | 29 | # ======== |
| 30 | echo | 30 | echo |
| 31 | -echo "=====> examples" | ||
| 32 | -cd examples | 31 | +echo "=====> test/dev" |
| 32 | +cd test/dev | ||
| 33 | 33 | ||
| 34 | # Create local environment | 34 | # Create local environment |
| 35 | rm -rf ctools | 35 | rm -rf ctools |
| @@ -41,18 +41,8 @@ export CTOOLS=$PWD/ctools | @@ -41,18 +41,8 @@ export CTOOLS=$PWD/ctools | ||
| 41 | # Run checkers | 41 | # Run checkers |
| 42 | ./check_models.py | 42 | ./check_models.py |
| 43 | 43 | ||
| 44 | -# Run pipelines | ||
| 45 | -./pipeline_binned_disk.py | ||
| 46 | -./pipeline_binned_mem.py | ||
| 47 | -./pipeline_stacked_disk.py | ||
| 48 | -./pipeline_stacked_mem.py | ||
| 49 | -./pipeline_unbinned_disk.py | ||
| 50 | -./pipeline_unbinned_mem.py | ||
| 51 | - | ||
| 52 | # Run makers | 44 | # Run makers |
| 53 | ./make_survey.py | 45 | ./make_survey.py |
| 54 | -./make_ts_distributions.py -n 2 -e 0 -d 1800 | ||
| 55 | -#./make_pull_at_sensitivity_limit.py | ||
| 56 | 46 | ||
| 57 | # Remove local environment | 47 | # Remove local environment |
| 58 | rm -rf ctools | 48 | rm -rf ctools |