Commit 3cdb23e67a219e1e036162a8c05d23fcfaf80d02
Merge branch 'devel' of https://cta-gitlab.irap.omp.eu/ctools/ctools into 1757-c…
…ssens-respect-ebounds
Showing
56 changed files
with
3135 additions
and
1062 deletions
.gitignore
ChangeLog
| 1 | -2016-04-25 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 1 | +2016-06-21 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 2 | 2 | |
| 3 | 3 | * Version 1.1.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Handle zero parameter errors in ctulimit (#1795) | |
| 7 | + Compute counts cube weights in ctbin (#1789) | |
| 8 | + Adapt to new stacked cube interface (#1788) | |
| 9 | + Add ctools and cscripts unit tests | |
| 6 | 10 | Add "bgdoversample" and "bgdinfill" parameters to csroot2caldb |
| 7 | 11 | Add csobsdef.pntdef() method (#1771) |
| 8 | 12 | Add ctmapcube tool (#1760) |
| 9 | 13 | Add "seed" parameter to cspull (#1755) |
| 10 | 14 | Add ctedispcube tool (#1724) |
| 11 | 15 | Test and import IACT scripts only for Python 2.6+ (#1715) |
| 12 | - Add documentation for IACT analysis (#1646) | |
| 13 | 16 | Adapt to revise GTime operators (#1714) |
| 14 | 17 | Add publish() methods to tools producing images (#1710) |
| 15 | 18 | Read ahead output filename in cterror (#1700) |
| 16 | 19 | Subdivide simulation energy range in ctobssim (#1673) |
| 17 | 20 | Delete existing events before simulation in ctobssim (#1663) |
| 18 | 21 | Add csiactcopy script (#1661) |
| 22 | + Add documentation for IACT analysis (#1646) | |
| 19 | 23 | ctselect allows usage of non-default events and GTI extensions (#1598) |
| 20 | 24 | Add csworkflow workflow manager script (#1508) |
| 21 | 25 | ... | ... |
Makefile.am
NEWS
| 1 | 1 | New Features and Important Changes in ctools 1.1.0 |
| 2 | 2 | |
| 3 | -25 April 2016 | |
| 3 | +21 June 2016 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | Introduction |
| ... | ... | @@ -92,6 +92,14 @@ ctbin - CTA event binning |
| 92 | 92 | Add publish() method to publish the counts cube via a SAMP Hub to Virtual |
| 93 | 93 | Observatory interoperable tools (e.g. Aladin). |
| 94 | 94 | |
| 95 | +The tool now computes the counts cube weights according to the overlaps | |
| 96 | +between the Region of Interests and energy boundaries with the counts | |
| 97 | +cube bins. This allows in particular for a proper handling of different | |
| 98 | +energy thresholds between observations that will be stacked into a single | |
| 99 | +cube. Also different Region of Interests are now properly handled, and | |
| 100 | +there is no longer an issue with counts cubes that are larger than the | |
| 101 | +Region of Interest of the event list (#1789). | |
| 102 | + | |
| 95 | 103 | |
| 96 | 104 | ctlike - Maximum likelihood fitting |
| 97 | 105 | ----------------------------------- |
| ... | ... | @@ -175,6 +183,9 @@ ctulimit - Compute upper limit |
| 175 | 183 | Add "edispcube" parameter to support energy dispersion for stacked analysis |
| 176 | 184 | (#1724). |
| 177 | 185 | |
| 186 | +In case that the parameter error is zero, the parameter value is taken as | |
| 187 | +parameter error to define the bracketing parameter values (#1795). | |
| 188 | + | |
| 178 | 189 | |
| 179 | 190 | cterror - Likelihood profile error computation |
| 180 | 191 | ---------------------------------------------- |
| ... | ... | @@ -208,6 +219,8 @@ sampling than the spatial sampling in the ROOT file. |
| 208 | 219 | Add csobsdef.pntdef() method to set directly a pointing definition from a |
| 209 | 220 | gammalib.GCsv object (#1771). |
| 210 | 221 | |
| 222 | +Unit tests have been added for all cscripts. | |
| 223 | + | |
| 211 | 224 | |
| 212 | 225 | Examples |
| 213 | 226 | -------- | ... | ... |
README renamed to README.md
| 1 | 1 | ctools information |
| 2 | 2 | ================== |
| 3 | -Version: 1.1.0dev (11 January 2016) | |
| 4 | -Author: Juergen Knodlseder (jurgen.knodlseder@irap.omp.eu) | |
| 5 | -GammaLib dependency: 1.1.0dev | |
| 3 | +* Version: 1.1.0.dev1 (21 June 2016) | |
| 4 | +* Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) | |
| 5 | +* GammaLib dependency: 1.1.0.dev1 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | License information | ... | ... |
configure.ac
| ... | ... | @@ -32,9 +32,9 @@ |
| 32 | 32 | AC_INIT([ctools], [1.1.0.dev1], [jurgen.knodlseder@irap.omp.eu], [ctools]) |
| 33 | 33 | AC_CONFIG_SRCDIR([src/ctselect/ctselect.cpp]) |
| 34 | 34 | AC_CONFIG_MACRO_DIR([m4]) |
| 35 | -#AM_INIT_AUTOMAKE([gnu no-dependencies]) | |
| 36 | -AM_INIT_AUTOMAKE([gnu -Wno-portability]) | |
| 37 | -#AM_INIT_AUTOMAKE([gnu -Wno-portability serial-tests]) | |
| 35 | +#AM_INIT_AUTOMAKE([gnu no-dependencies foreign]) | |
| 36 | +AM_INIT_AUTOMAKE([gnu -Wno-portability foreign]) | |
| 37 | +#AM_INIT_AUTOMAKE([gnu -Wno-portability serial-tests foreign]) | |
| 38 | 38 | AC_CONFIG_HEADER([config.h]) |
| 39 | 39 | |
| 40 | 40 | ... | ... |
cscripts/Makefile.am
| ... | ... | @@ -71,14 +71,19 @@ linkscripts = cscaldb \ |
| 71 | 71 | testscripts = tests/__init__.py \ |
| 72 | 72 | ../test/test_python_cscripts.py \ |
| 73 | 73 | ../test/test_cscaldb.py \ |
| 74 | - ../test/test_cslightcrv.py \ | |
| 75 | 74 | ../test/test_csmodelinfo.py \ |
| 76 | 75 | ../test/test_csmodelmerge.py \ |
| 77 | 76 | ../test/test_csobs2caldb.py \ |
| 78 | 77 | ../test/test_csobsdef.py \ |
| 79 | 78 | ../test/test_csobsinfo.py \ |
| 79 | + ../test/test_cslightcrv.py \ | |
| 80 | 80 | ../test/test_cspull.py \ |
| 81 | + ../test/test_csresmap.py \ | |
| 81 | 82 | ../test/test_csroot2caldb.py \ |
| 83 | + ../test/test_cssens.py \ | |
| 84 | + ../test/test_csspec.py \ | |
| 85 | + ../test/test_cstsdist.py \ | |
| 86 | + ../test/test_cstsmapmerge.py \ | |
| 82 | 87 | ../test/test_csworkflow.py \ |
| 83 | 88 | ../test/test_csfindobs.py \ |
| 84 | 89 | ../test/test_csiactcopy.py \ |
| ... | ... | @@ -91,12 +96,17 @@ testdata = ../test/data/crab.xml \ |
| 91 | 96 | ../test/data/obs_stacked.xml \ |
| 92 | 97 | ../test/data/crab_events.fits.gz \ |
| 93 | 98 | ../test/data/crab_cntmap.fits.gz \ |
| 99 | + ../test/data/crab_cntmap_small.fits.gz \ | |
| 94 | 100 | ../test/data/crab_expcube.fits.gz \ |
| 95 | 101 | ../test/data/crab_psfcube.fits.gz \ |
| 102 | + ../test/data/crab_edispcube.fits.gz \ | |
| 96 | 103 | ../test/data/crab_bkgcube.fits.gz \ |
| 104 | + ../test/data/tsmap_0.fits \ | |
| 105 | + ../test/data/tsmap_1.fits \ | |
| 97 | 106 | ../test/data/exclusion.reg \ |
| 98 | 107 | ../test/data/pntdef.dat \ |
| 99 | 108 | ../test/data/models.txt \ |
| 109 | + ../test/data/tsmaps.txt \ | |
| 100 | 110 | ../test/data/model_cube_background.xml \ |
| 101 | 111 | ../test/data/model_cube_background2.xml \ |
| 102 | 112 | ../test/data/crab_bkgcube.xml \ | ... | ... |
cscripts/csresmap.par
| ... | ... | @@ -33,10 +33,10 @@ outmap, f, a, resmap.fits,,, "Output residual map file" |
| 33 | 33 | # Script parameters |
| 34 | 34 | #================== |
| 35 | 35 | ebinalg, s, h, LOG,LIN|LOG|FILE,, "Binning algorithm" |
| 36 | -emin, r, h, 0.1,,, "Lower energy limit (TeV)" | |
| 37 | -emax, r, h, 100.0,,, "Upper energy limit (TeV)" | |
| 38 | -enumbins, i, h, 20,,, "Number of energy bins (0=unbinned)" | |
| 39 | -ebinfile, f, h, NONE,,, "Name of the file containing the energy bin definition" | |
| 36 | +emin, r, a, 0.1,,, "Lower energy limit (TeV)" | |
| 37 | +emax, r, a, 100.0,,, "Upper energy limit (TeV)" | |
| 38 | +enumbins, i, a, 20,,, "Number of energy bins (0=unbinned)" | |
| 39 | +ebinfile, f, a, NONE,,, "Name of the file containing the energy bin definition" | |
| 40 | 40 | coordsys, s, a, CEL,CEL|GAL,, "Coordinate System" |
| 41 | 41 | proj, s, a, CAR,AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method" |
| 42 | 42 | xref, r, a, 83.63,0,360, "First coordinate of image center in degrees (RA or galactic l)" | ... | ... |
cscripts/csresmap.py
| ... | ... | @@ -228,7 +228,7 @@ class csresmap(ctools.cscript): |
| 228 | 228 | cta_counts_cube = bin.cube() |
| 229 | 229 | |
| 230 | 230 | # Assign GCTAEventCube to skymap |
| 231 | - countmap = cta_counts_cube.map() | |
| 231 | + countmap = cta_counts_cube.counts() | |
| 232 | 232 | |
| 233 | 233 | # Write header |
| 234 | 234 | if self._logTerse(): |
| ... | ... | @@ -245,13 +245,13 @@ class csresmap(ctools.cscript): |
| 245 | 245 | model.run() |
| 246 | 246 | |
| 247 | 247 | # Get model map into GSkyMap object |
| 248 | - modelmap = model.cube().map().copy() | |
| 248 | + modelmap = model.cube().counts().copy() | |
| 249 | 249 | |
| 250 | 250 | # Store counts map as residual map. Note that we need a |
| 251 | 251 | # special construct here to avoid memory leaks. This seems |
| 252 | 252 | # to be a SWIG feature as SWIG creates a new object when |
| 253 | 253 | # calling bin.cube() |
| 254 | - #residualmap = bin.cube().map() | |
| 254 | + #residualmap = bin.cube().counts() | |
| 255 | 255 | self._resmap = countmap.copy() |
| 256 | 256 | self._resmap.stack_maps() |
| 257 | 257 | modelmap.stack_maps() | ... | ... |
cscripts/csspec.py
| ... | ... | @@ -42,8 +42,8 @@ class csspec(ctools.cscript): |
| 42 | 42 | Constructor. |
| 43 | 43 | """ |
| 44 | 44 | # Set name |
| 45 | - self._name = "csspec" | |
| 46 | - self._version = "1.1.0" | |
| 45 | + self._name = 'csspec' | |
| 46 | + self._version = '1.1.0' | |
| 47 | 47 | |
| 48 | 48 | # Initialise some members |
| 49 | 49 | self._ebounds = gammalib.GEbounds() |
| ... | ... | @@ -136,56 +136,58 @@ class csspec(ctools.cscript): |
| 136 | 136 | """ |
| 137 | 137 | # Get ebounds |
| 138 | 138 | if self._binned_mode: |
| 139 | - | |
| 139 | + | |
| 140 | + # Initialise energy boundaries for spectrum | |
| 141 | + self._ebounds = gammalib.GEbounds() | |
| 142 | + | |
| 143 | + # Create energy boundaries according to user parameters | |
| 144 | + ebounds = self._create_ebounds() | |
| 145 | + | |
| 140 | 146 | # Extract cube ebounds |
| 141 | 147 | cube_ebounds = self._obs[0].events().ebounds() |
| 142 | - | |
| 143 | - # Read user parameters | |
| 144 | - enumbins = self["enumbins"].integer() | |
| 145 | - emin_val = self["emin"].real() - 1e-6 # Rounding tolerance | |
| 146 | - emax_val = self["emax"].real() + 1e-6 # Rounding tolerance | |
| 147 | - | |
| 148 | - # Set energy range | |
| 149 | - emin = gammalib.GEnergy(emin_val, "TeV") | |
| 150 | - emax = gammalib.GEnergy(emax_val, "TeV") | |
| 151 | - | |
| 152 | - # Determine all cube layers that overlap with the [emin,emax] | |
| 153 | - # energy range. | |
| 154 | - use_layers = [] | |
| 155 | - for i in range(cube_ebounds.size()): | |
| 156 | - if cube_ebounds.emin(i) < emax and cube_ebounds.emax(i) > emin: | |
| 157 | - use_layers.append(i) | |
| 158 | - | |
| 159 | - # If no layers overlap then throw an exception | |
| 160 | - if (len(use_layers) == 0): | |
| 161 | - msg = "Energy range ["+str(cube_ebounds.emin())+ \ | |
| 162 | - ", "+str(cube_ebounds.emax())+"] of counts "+ \ | |
| 163 | - "cube does not overlap with specified energy "+ \ | |
| 164 | - "range ["+ \ | |
| 165 | - str(emin)+", "+str(emax)+"]. Specify "+ \ | |
| 166 | - "overlapping energy range." | |
| 167 | - raise RuntimeError(msg) | |
| 168 | - | |
| 169 | - # Determine number of layers to use for each spectral bin | |
| 170 | - n_layers = int(len(use_layers) / enumbins) | |
| 171 | 148 | |
| 172 | - # Don't allow zero layers | |
| 173 | - if n_layers == 0: | |
| 174 | - n_layers = 1 | |
| 149 | + # Loop over user energy boundaries and collect all layers | |
| 150 | + # that overlap | |
| 151 | + for i in range(ebounds.size()): | |
| 152 | + | |
| 153 | + # Extract minimum and maximum energy of user energy bin, | |
| 154 | + # including some rounding tolerance | |
| 155 | + emin = ebounds.emin(i).TeV() - 1e-6 # Rounding tolerance | |
| 156 | + emax = ebounds.emax(i).TeV() + 1e-6 # Rounding tolerance | |
| 157 | + | |
| 158 | + # Set number of overlapping energy bins | |
| 159 | + nbins = 0 | |
| 160 | + | |
| 161 | + # Search first cube bin that is comprised within user energy bin | |
| 162 | + for k in range(cube_ebounds.size()): | |
| 163 | + if cube_ebounds.emin(k).TeV() >= emin and \ | |
| 164 | + cube_ebounds.emax(k).TeV() <= emax: | |
| 165 | + emin_value = cube_ebounds.emin(k).TeV() | |
| 166 | + break | |
| 167 | + | |
| 168 | + # Search last cube bin that is comprised within user energy bin | |
| 169 | + for k in range(cube_ebounds.size()): | |
| 170 | + if cube_ebounds.emin(k).TeV() >= emin and \ | |
| 171 | + cube_ebounds.emax(k).TeV() <= emax: | |
| 172 | + emax_value = cube_ebounds.emax(k).TeV() | |
| 173 | + nbins += 1 | |
| 174 | + | |
| 175 | + # Append energy bin if there are overlapping bins in the | |
| 176 | + # counts cube | |
| 177 | + if nbins > 0: | |
| 178 | + self._ebounds.append(gammalib.GEnergy(emin_value, 'TeV'), | |
| 179 | + gammalib.GEnergy(emax_value, 'TeV')) | |
| 180 | + | |
| 181 | + # Raise an exception if there are no overlapping layers | |
| 182 | + if (len(self._ebounds) == 0): | |
| 183 | + msg = 'Energy range ['+str(cube_ebounds.emin())+ \ | |
| 184 | + ', '+str(cube_ebounds.emax())+'] of counts '+ \ | |
| 185 | + 'cube does not overlap with specified energy '+ \ | |
| 186 | + 'range ['+ \ | |
| 187 | + str(ebounds.emin())+', '+str(ebounds.emax())+'].'+ \ | |
| 188 | + ' Specify overlapping energy range.' | |
| 189 | + raise RuntimeError(msg) | |
| 175 | 190 | |
| 176 | - # Create energy boundaries | |
| 177 | - self._ebounds = gammalib.GEbounds() | |
| 178 | - i_start = 0 | |
| 179 | - i_stop = n_layers - 1 | |
| 180 | - while i_start < len(use_layers): | |
| 181 | - if i_stop >= len(use_layers): | |
| 182 | - i_stop = len(use_layers) - 1 | |
| 183 | - ebinmin = cube_ebounds.emin(use_layers[i_start]) | |
| 184 | - ebinmax = cube_ebounds.emax(use_layers[i_stop]) | |
| 185 | - self._ebounds.append(ebinmin, ebinmax) | |
| 186 | - i_start += n_layers | |
| 187 | - i_stop += n_layers | |
| 188 | - | |
| 189 | 191 | # Unbinned mode |
| 190 | 192 | else: |
| 191 | 193 | self._ebounds = self._create_ebounds() | ... | ... |
cscripts/cstsmapmerge.py
| ... | ... | @@ -39,12 +39,12 @@ class cstsmapmerge(ctools.cscript): |
| 39 | 39 | Constructor. |
| 40 | 40 | """ |
| 41 | 41 | # Set name |
| 42 | - self._name = "cstsmapmerge" | |
| 43 | - self._version = "1.1.0" | |
| 42 | + self._name = 'cstsmapmerge' | |
| 43 | + self._version = '1.1.0' | |
| 44 | 44 | |
| 45 | 45 | # Initialise class members |
| 46 | 46 | self._files = None |
| 47 | - self._in_filename = "" | |
| 47 | + self._in_filename = '' | |
| 48 | 48 | self._tsmap = gammalib.GSkyMap() # Empty sky map |
| 49 | 49 | self._statusmap = gammalib.GSkyMap() # Empty sky map |
| 50 | 50 | self._maps = [] |
| ... | ... | @@ -67,49 +67,49 @@ class cstsmapmerge(ctools.cscript): |
| 67 | 67 | Get parameters from parfile. |
| 68 | 68 | """ |
| 69 | 69 | # Get input maps string |
| 70 | - inmaps = self["inmaps"].string() | |
| 70 | + inmaps = self['inmaps'].string() | |
| 71 | 71 | |
| 72 | 72 | # Handle ascii files |
| 73 | - if "@" == inmaps[0]: | |
| 74 | - self._files = open(inmaps.replace("@","")).read().splitlines() | |
| 73 | + if '@' == inmaps[0]: | |
| 74 | + self._files = open(inmaps.replace('@','')).read().splitlines() | |
| 75 | 75 | |
| 76 | 76 | # Handle wild card strings |
| 77 | - elif "*" in inmaps: | |
| 77 | + elif '*' in inmaps: | |
| 78 | 78 | self._files = glob.glob(inmaps) |
| 79 | 79 | |
| 80 | 80 | # Handle space-separated list |
| 81 | - elif " " in inmaps: | |
| 82 | - self._files = inmaps.split(" ") | |
| 81 | + elif ' ' in inmaps: | |
| 82 | + self._files = inmaps.split(' ') | |
| 83 | 83 | |
| 84 | 84 | # Handle semi-colon separated list |
| 85 | - elif ";" in inmaps: | |
| 86 | - self._files = inmaps.split(";") | |
| 85 | + elif ';' in inmaps: | |
| 86 | + self._files = inmaps.split(';') | |
| 87 | 87 | |
| 88 | 88 | # Throw exception if input models cannot be decoded |
| 89 | 89 | else: |
| 90 | - msg = "Parameter \"inmaps\" must contain either an @ASCII "\ | |
| 91 | - "file, a semi-colon-separated or whitespace-separated "\ | |
| 92 | - "list of files or a wildcard string." | |
| 90 | + msg = 'Parameter "inmaps" must contain either an @ASCII '\ | |
| 91 | + 'file, a semi-colon-separated or whitespace-separated '\ | |
| 92 | + 'list of files or a wildcard string.' | |
| 93 | 93 | raise RuntimeError(msg) |
| 94 | 94 | |
| 95 | 95 | # Check number of files. We need at least two files. |
| 96 | 96 | if len(self._files) <= 1: |
| 97 | - msg = "Need at least two files to start merging, "+\ | |
| 98 | - str(len(self._files))+" file(s) given." | |
| 97 | + msg = 'Need at least two files to start merging, '+\ | |
| 98 | + str(len(self._files))+' file(s) given.' | |
| 99 | 99 | raise RuntimeError(msg) |
| 100 | 100 | |
| 101 | 101 | # Get other parameters |
| 102 | - self._overwrite = self["overwrite"].boolean() | |
| 103 | - self._delete = self["delete"].boolean() | |
| 102 | + self._overwrite = self['overwrite'].boolean() | |
| 103 | + self._delete = self['delete'].boolean() | |
| 104 | 104 | |
| 105 | 105 | # Read ahead output filename |
| 106 | 106 | if self._read_ahead(): |
| 107 | - self["outmap"].filename() | |
| 107 | + self['outmap'].filename() | |
| 108 | 108 | |
| 109 | 109 | # Write input parameters into logger |
| 110 | 110 | if self._logTerse(): |
| 111 | 111 | self._log_parameters() |
| 112 | - self._log("\n") | |
| 112 | + self._log('\n') | |
| 113 | 113 | |
| 114 | 114 | # Return |
| 115 | 115 | return | ... | ... |
cscripts/csworkflow.par
doc/source/about.rst
| ... | ... | @@ -38,14 +38,20 @@ Acknowledging or citing ctools |
| 38 | 38 | ------------------------------ |
| 39 | 39 | |
| 40 | 40 | If you use ctools for work/research presented in a publication we ask you |
| 41 | -that you include the following standard acknowledgment: | |
| 41 | +to include the formal reference | |
| 42 | + | |
| 43 | + J. Knoedlseder, M. Mayer, C. Deil, J.-B. Cayrou, E. Owen, N. Kelley-Hoskins, | |
| 44 | + C.-C. Lu, R. Buehler, F. Forest, T. Louge, H. Siejkowski, K. Kosack, | |
| 45 | + L. Gerard, A. Schulz, P. Martin, D. Sanchez, S. Ohm, T. Hassan, and | |
| 46 | + S. Brau-Nogue, 2016, A&A, in press (`arXiv:1606.00393 <http://arxiv.org/abs/1606.00393>`_) | |
| 47 | + | |
| 48 | +in your paper and that you add the following acknowledgment: | |
| 42 | 49 | |
| 43 | 50 | *This research made use of ctools, a community-developed analysis package |
| 44 | 51 | for Imaging Air Cherenkov Telescope data. ctools is based on GammaLib, |
| 45 | 52 | a community-developed toolbox for the high-level analysis of astronomical |
| 46 | 53 | gamma-ray data.* |
| 47 | 54 | |
| 48 | - | |
| 49 | 55 | If you wish, you can also include a link to http://cta.irap.omp.eu/ctools/ |
| 50 | 56 | (if the journal allows this) in addition to the above text. |
| 51 | 57 | ... | ... |
doc/source/reference_manual/csresmap.rst
| ... | ... | @@ -61,16 +61,16 @@ General parameters |
| 61 | 61 | ``(ebinalg = LOG) <FILE|LIN|LOG> [string]`` |
| 62 | 62 | Algorithm for defining energy bins. |
| 63 | 63 | |
| 64 | -``(emin = 0.1) [real]`` | |
| 64 | +``emin [real]`` | |
| 65 | 65 | Lower energy value for first energy bin (in TeV). |
| 66 | 66 | |
| 67 | -``(emax = 100.0) [real]`` | |
| 67 | +``emax [real]`` | |
| 68 | 68 | Upper energy value for last energy bin (in TeV). |
| 69 | 69 | |
| 70 | -``(enumbins = 20) [integer]`` | |
| 70 | +``enumbins [integer]`` | |
| 71 | 71 | Number of energy bins. |
| 72 | 72 | |
| 73 | -``(ebinfile = NONE) [file]`` | |
| 73 | +``ebinfile [file]`` | |
| 74 | 74 | Name of the file containing the energy bin definition. |
| 75 | 75 | |
| 76 | 76 | ``coordsys <CEL|GAL> [string]`` | ... | ... |
pyext/Makefile.am
| ... | ... | @@ -41,6 +41,7 @@ testscripts = ctools/tests/__init__.py \ |
| 41 | 41 | ../test/test_ctskymap.py \ |
| 42 | 42 | ../test/test_ctexpcube.py \ |
| 43 | 43 | ../test/test_ctpsfcube.py \ |
| 44 | + ../test/test_ctedispcube.py \ | |
| 44 | 45 | ../test/test_ctbkgcube.py \ |
| 45 | 46 | ../test/test_ctmapcube.py \ |
| 46 | 47 | ../test/test_ctcubemask.py \ | ... | ... |
pyext/setup.py.in
| ... | ... | @@ -52,7 +52,7 @@ if sys.platform.lower().startswith("darwin"): |
| 52 | 52 | else: |
| 53 | 53 | ldshared_rm += option + ' ' |
| 54 | 54 | if (len(ldshared_rm) > 0): |
| 55 | - sys.stdout.write("Removed following option(s) from LDSHARED: "+ldshared_rm+"\n"); | |
| 55 | + sys.stdout.write("Removed following option(s) from LDSHARED: "+ldshared_rm+"\n") | |
| 56 | 56 | |
| 57 | 57 | # Set LDSHARED |
| 58 | 58 | cvars['LDSHARED'] = ldshared_new | ... | ... |
src/ctbin/ctbin.cpp
| ... | ... | @@ -39,9 +39,9 @@ |
| 39 | 39 | /* __ Debug definitions __________________________________________________ */ |
| 40 | 40 | |
| 41 | 41 | /* __ Coding definitions _________________________________________________ */ |
| 42 | +#define G_PLAW_WEIGHTS //!< Use power law in energy weight computation | |
| 42 | 43 | |
| 43 | 44 | /* __ Constants __________________________________________________________ */ |
| 44 | -const GEnergy g_energy_margin(1.0e-12, "TeV"); | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | /*========================================================================== |
| ... | ... | @@ -62,7 +62,7 @@ ctbin::ctbin(void) : ctool(CTBIN_NAME, CTBIN_VERSION) |
| 62 | 62 | |
| 63 | 63 | // Return |
| 64 | 64 | return; |
| 65 | -} // GCOV_EXCL_LINE | |
| 65 | +} | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | /***********************************************************************//** |
| ... | ... | @@ -211,7 +211,9 @@ void ctbin::clear(void) |
| 211 | 211 | * @brief Run the ctbin tool |
| 212 | 212 | * |
| 213 | 213 | * Gets the user parameters and loops over all CTA observations in the |
| 214 | - * observation container to bin the events into a single counts cube. | |
| 214 | + * observation container to bin the events into a single counts cube. All | |
| 215 | + * observations in the observation container that do not contain CTA event | |
| 216 | + * lists will be skipped. | |
| 215 | 217 | ***************************************************************************/ |
| 216 | 218 | void ctbin::run(void) |
| 217 | 219 | { |
| ... | ... | @@ -275,6 +277,15 @@ void ctbin::run(void) |
| 275 | 277 | |
| 276 | 278 | } // endfor: looped over observations |
| 277 | 279 | |
| 280 | + // Normalize weights counts map | |
| 281 | + if (m_livetime > 0.0) { | |
| 282 | + for (int iebin = 0; iebin < m_weights.nmaps(); ++iebin) { | |
| 283 | + for (int index = 0; index < m_weights.npix(); ++index) { | |
| 284 | + m_weights(index, iebin) /= m_livetime; | |
| 285 | + } | |
| 286 | + } | |
| 287 | + } | |
| 288 | + | |
| 278 | 289 | // Set a single cube in the observation container |
| 279 | 290 | obs_cube(); |
| 280 | 291 | |
| ... | ... | @@ -364,7 +375,7 @@ void ctbin::publish(const std::string& name) |
| 364 | 375 | } |
| 365 | 376 | |
| 366 | 377 | // Publish counts cube |
| 367 | - m_cube.publish(user_name); | |
| 378 | + m_counts.publish(user_name); | |
| 368 | 379 | |
| 369 | 380 | // Return |
| 370 | 381 | return; |
| ... | ... | @@ -389,7 +400,8 @@ void ctbin::init_members(void) |
| 389 | 400 | |
| 390 | 401 | // Initialise protected members |
| 391 | 402 | m_obs.clear(); |
| 392 | - m_cube.clear(); | |
| 403 | + m_counts.clear(); | |
| 404 | + m_weights.clear(); | |
| 393 | 405 | m_ebounds.clear(); |
| 394 | 406 | m_gti.clear(); |
| 395 | 407 | m_ontime = 0.0; |
| ... | ... | @@ -414,7 +426,8 @@ void ctbin::copy_members(const ctbin& app) |
| 414 | 426 | |
| 415 | 427 | // Copy protected members |
| 416 | 428 | m_obs = app.m_obs; |
| 417 | - m_cube = app.m_cube; | |
| 429 | + m_counts = app.m_counts; | |
| 430 | + m_weights = app.m_weights; | |
| 418 | 431 | m_ebounds = app.m_ebounds; |
| 419 | 432 | m_gti = app.m_gti; |
| 420 | 433 | m_ontime = app.m_ontime; |
| ... | ... | @@ -464,9 +477,11 @@ void ctbin::get_parameters(void) |
| 464 | 477 | // Create an event cube based on task parameters |
| 465 | 478 | GCTAEventCube cube = create_cube(m_obs); |
| 466 | 479 | |
| 467 | - // Get the skymap from the cube and initialise all pixels to zero | |
| 468 | - m_cube = cube.map(); | |
| 469 | - m_cube = 0.0; | |
| 480 | + // Get the skymap from the cube and initialise all counts cube bins and | |
| 481 | + // weights to zero | |
| 482 | + m_counts = cube.counts(); | |
| 483 | + m_counts = 0.0; | |
| 484 | + m_weights = m_counts; | |
| 470 | 485 | |
| 471 | 486 | // Get energy boundaries |
| 472 | 487 | m_ebounds = cube.ebounds(); |
| ... | ... | @@ -497,7 +512,7 @@ void ctbin::get_parameters(void) |
| 497 | 512 | * @param[in] obs CTA observation. |
| 498 | 513 | * |
| 499 | 514 | * @exception GException::invalid_value |
| 500 | - * No event list found in observation. | |
| 515 | + * No event list or valid RoI found in observation. | |
| 501 | 516 | * |
| 502 | 517 | * Fills the events from an event list in the counts cube setup by init_cube. |
| 503 | 518 | ***************************************************************************/ |
| ... | ... | @@ -508,7 +523,8 @@ void ctbin::fill_cube(GCTAObservation* obs) |
| 508 | 523 | |
| 509 | 524 | // Make sure that the observation holds a CTA event list. If this |
| 510 | 525 | // is not the case then throw an exception. |
| 511 | - const GCTAEventList* events = dynamic_cast<const GCTAEventList*>(obs->events()); | |
| 526 | + const GCTAEventList* events = | |
| 527 | + dynamic_cast<const GCTAEventList*>(obs->events()); | |
| 512 | 528 | if (events == NULL) { |
| 513 | 529 | std::string msg = "CTA Observation does not contain an event " |
| 514 | 530 | "list. An event list is needed to fill the " |
| ... | ... | @@ -519,9 +535,6 @@ void ctbin::fill_cube(GCTAObservation* obs) |
| 519 | 535 | // Get the RoI |
| 520 | 536 | const GCTARoi& roi = events->roi(); |
| 521 | 537 | |
| 522 | - // Get the ebounds | |
| 523 | - const GEbounds& obs_ebounds = events->ebounds(); | |
| 524 | - | |
| 525 | 538 | // Check for RoI sanity |
| 526 | 539 | if (!roi.is_valid()) { |
| 527 | 540 | std::string msg = "No valid RoI found in input observation " |
| ... | ... | @@ -537,7 +550,7 @@ void ctbin::fill_cube(GCTAObservation* obs) |
| 537 | 550 | int num_outside_ebds = 0; |
| 538 | 551 | int num_in_map = 0; |
| 539 | 552 | |
| 540 | - // Fill sky map | |
| 553 | + // Fill counts sky map | |
| 541 | 554 | for (int i = 0; i < events->size(); ++i) { |
| 542 | 555 | |
| 543 | 556 | // Get event |
| ... | ... | @@ -546,7 +559,7 @@ void ctbin::fill_cube(GCTAObservation* obs) |
| 546 | 559 | // Determine sky pixel |
| 547 | 560 | GCTAInstDir* inst = (GCTAInstDir*)&(event->dir()); |
| 548 | 561 | GSkyDir dir = inst->dir(); |
| 549 | - GSkyPixel pixel = m_cube.dir2pix(dir); | |
| 562 | + GSkyPixel pixel = m_counts.dir2pix(dir); | |
| 550 | 563 | |
| 551 | 564 | // Skip if pixel is outside RoI |
| 552 | 565 | if (roi.centre().dir().dist_deg(dir) > roi.radius()) { |
| ... | ... | @@ -554,28 +567,42 @@ void ctbin::fill_cube(GCTAObservation* obs) |
| 554 | 567 | continue; |
| 555 | 568 | } |
| 556 | 569 | |
| 557 | - // Skip if pixel is out of range | |
| 558 | - if (pixel.x() < -0.5 || pixel.x() > (m_cube.nx()-0.5) || | |
| 559 | - pixel.y() < -0.5 || pixel.y() > (m_cube.ny()-0.5)) { | |
| 570 | + // Skip if pixel is out of map range | |
| 571 | + if (pixel.x() < -0.5 || pixel.x() > (m_counts.nx()-0.5) || | |
| 572 | + pixel.y() < -0.5 || pixel.y() > (m_counts.ny()-0.5)) { | |
| 560 | 573 | num_outside_map++; |
| 561 | 574 | continue; |
| 562 | 575 | } |
| 563 | 576 | |
| 564 | - // Determine energy bin. Skip if we are outside the energy range | |
| 565 | - int index = m_ebounds.index(event->energy()); | |
| 566 | - if (index == -1 || | |
| 567 | - !obs_ebounds.contains(m_ebounds.emin(index)+g_energy_margin, | |
| 568 | - m_ebounds.emax(index)-g_energy_margin)) { | |
| 577 | + // Determine energy bin | |
| 578 | + int iebin = m_ebounds.index(event->energy()); | |
| 579 | + | |
| 580 | + // Skip if energy bin is outside counts cube boundaries | |
| 581 | + if (iebin == -1) { | |
| 569 | 582 | num_outside_ebds++; |
| 570 | 583 | continue; |
| 571 | 584 | } |
| 572 | 585 | |
| 573 | 586 | // Fill event in skymap |
| 574 | - m_cube(pixel, index) += 1.0; | |
| 587 | + m_counts(pixel, iebin) += 1.0; | |
| 575 | 588 | num_in_map++; |
| 576 | 589 | |
| 577 | 590 | } // endfor: looped over all events |
| 578 | 591 | |
| 592 | + // Get RoI and energy weights | |
| 593 | + GSkyMap roi_weights = set_roi_weights(roi); | |
| 594 | + std::vector<double> energy_weights = set_energy_weights(events->ebounds()); | |
| 595 | + | |
| 596 | + // Add weights multiplied by livetime to weight map. The map is later | |
| 597 | + // divided by the cumulative livetime in run(). | |
| 598 | + for (int iebin = 0; iebin < energy_weights.size(); ++iebin) { | |
| 599 | + for (int index = 0; index < roi_weights.npix(); ++index) { | |
| 600 | + m_weights(index, iebin) += roi_weights(index) * | |
| 601 | + energy_weights[iebin] * | |
| 602 | + obs->livetime(); | |
| 603 | + } | |
| 604 | + } | |
| 605 | + | |
| 579 | 606 | // Append GTIs |
| 580 | 607 | m_gti.extend(events->gti()); |
| 581 | 608 | |
| ... | ... | @@ -600,7 +627,7 @@ void ctbin::fill_cube(GCTAObservation* obs) |
| 600 | 627 | // Log cube |
| 601 | 628 | if (logExplicit()) { |
| 602 | 629 | log.header1("Counts cube"); |
| 603 | - log << m_cube << std::endl; | |
| 630 | + log << m_counts << std::endl; | |
| 604 | 631 | } |
| 605 | 632 | |
| 606 | 633 | } // endif: observation was valid |
| ... | ... | @@ -647,7 +674,7 @@ void ctbin::obs_cube(void) |
| 647 | 674 | else { |
| 648 | 675 | |
| 649 | 676 | // Create empty counts cube |
| 650 | - GCTAEventCube cube(m_cube, m_ebounds, obs->gti()); | |
| 677 | + GCTAEventCube cube(m_counts, m_weights, m_ebounds, obs->gti()); | |
| 651 | 678 | |
| 652 | 679 | // Assign empty cube to observation |
| 653 | 680 | obs->events(cube); |
| ... | ... | @@ -732,3 +759,165 @@ void ctbin::obs_cube(void) |
| 732 | 759 | // Return |
| 733 | 760 | return; |
| 734 | 761 | } |
| 762 | + | |
| 763 | + | |
| 764 | +/***********************************************************************//** | |
| 765 | + * @brief Set RoI weights. | |
| 766 | + * | |
| 767 | + * @param[in] roi Region of Interest. | |
| 768 | + * @return Sky map with Region of Interest weights. | |
| 769 | + * | |
| 770 | + * Computes a sky map of Region of Interest (RoI) weights. All pixels of the | |
| 771 | + * sky map that are fully comprised within the RoI will be set to unity. | |
| 772 | + * Pixels that are only partly comprised will be devided into a 10x10 subgrid, | |
| 773 | + * and a weight corresponding to the fraction of subgrid points that are | |
| 774 | + * fully comprised within the RoI will be assigned to the sky map pixel. | |
| 775 | + * The precision of the weights is about 1%. | |
| 776 | + ***************************************************************************/ | |
| 777 | +GSkyMap ctbin::set_roi_weights(const GCTARoi& roi) const | |
| 778 | +{ | |
| 779 | + // Set number of points in subgrid | |
| 780 | + const int n_subgrid = 10; | |
| 781 | + | |
| 782 | + // Initialise ROI weight sky map with zero weights | |
| 783 | + GSkyMap weights(m_counts.extract(0)); | |
| 784 | + weights = 0.0; | |
| 785 | + | |
| 786 | + // Compute save RoI radius. All pixels with bin centre within that radius | |
| 787 | + // will be set to unity. In case that the counts cube is not a WCS map | |
| 788 | + // no pixels will be considered within the safe radius. | |
| 789 | + double margin(roi.radius()); | |
| 790 | + const GWcs* wcs(dynamic_cast<const GWcs*>(m_counts.projection())); | |
| 791 | + if (wcs != NULL) { | |
| 792 | + double dx = wcs->cdelt(0); | |
| 793 | + double dy = wcs->cdelt(1); | |
| 794 | + margin = (dx > dy) ? dx : dy; | |
| 795 | + } | |
| 796 | + double safe_radius = roi.radius() - margin; | |
| 797 | + | |
| 798 | + // Loop over all sky map pixels | |
| 799 | + for (int i = 0; i < weights.npix(); ++i) { | |
| 800 | + | |
| 801 | + // Get pixel sky direction | |
| 802 | + GSkyDir dir(weights.inx2dir(i)); | |
| 803 | + | |
| 804 | + // If pixel is within the safe radius then set the pixel weight to | |
| 805 | + // unity ... | |
| 806 | + if (roi.centre().dir().dist_deg(dir) <= safe_radius) { | |
| 807 | + weights(i) = 1.0; | |
| 808 | + } | |
| 809 | + | |
| 810 | + // ... otherwise define a subgrid a check all positions within that | |
| 811 | + // subgrid that fall within the RoI. This is an approximation that | |
| 812 | + // determines the weight of the pixels | |
| 813 | + else { | |
| 814 | + | |
| 815 | + // Set pixel centre | |
| 816 | + GSkyPixel centre(weights.inx2pix(i)); | |
| 817 | + | |
| 818 | + // Compute subgrid pixel step size | |
| 819 | + double step = 1.0 / double(n_subgrid-1); | |
| 820 | + | |
| 821 | + // Compute sky direction weight | |
| 822 | + double weight = 1.0 / (double(n_subgrid) * double(n_subgrid)); | |
| 823 | + | |
| 824 | + // Loop over X subgrid | |
| 825 | + for (int ix = 0; ix < n_subgrid; ++ix) { | |
| 826 | + | |
| 827 | + // Compute X pixel value | |
| 828 | + double x = ix * step - 0.5; | |
| 829 | + | |
| 830 | + // Loop over Y subgrid | |
| 831 | + for (int iy = 0; iy < n_subgrid; ++iy) { | |
| 832 | + | |
| 833 | + // Compute Y pixel value | |
| 834 | + double y = iy * step - 0.5; | |
| 835 | + | |
| 836 | + // Set pixel value | |
| 837 | + GSkyPixel pixel(centre.x()+x, centre.y()+y); | |
| 838 | + | |
| 839 | + // Get pixel sky direction | |
| 840 | + GSkyDir dir(weights.pix2dir(pixel)); | |
| 841 | + | |
| 842 | + // If sky direction is within the RoI then add the direction | |
| 843 | + // to the weight for this pixel | |
| 844 | + if (roi.centre().dir().dist_deg(dir) <= roi.radius()) { | |
| 845 | + weights(i) += weight; | |
| 846 | + } | |
| 847 | + | |
| 848 | + } // endfor: loop over Y subgrid | |
| 849 | + | |
| 850 | + } // endfor: loop over X subgrid | |
| 851 | + | |
| 852 | + } // endelse: pixel was outside safe radius | |
| 853 | + | |
| 854 | + } // endfor: looped over all pixel sky maps | |
| 855 | + | |
| 856 | + // Return | |
| 857 | + return weights; | |
| 858 | +} | |
| 859 | + | |
| 860 | + | |
| 861 | +/***********************************************************************//** | |
| 862 | + * @brief Set energy weights. | |
| 863 | + * | |
| 864 | + * @param[in] ebounds Energy boundaries. | |
| 865 | + * @return Vector of energy boundary weights. | |
| 866 | + * | |
| 867 | + * Computes a vector of energy boundary weights from the overlap of the | |
| 868 | + * event list energy boundaries with the counts cube boundaries. It is | |
| 869 | + * assumed that within a bin the events are distributed according to a power | |
| 870 | + * law with spectral index of -2, and the weights are computed according | |
| 871 | + * to the fraction of this power law that is comprised within a counts cube | |
| 872 | + * bin. | |
| 873 | + * | |
| 874 | + * This method properly handles event lists with multiple energy boundaries. | |
| 875 | + ***************************************************************************/ | |
| 876 | +std::vector<double> ctbin::set_energy_weights(const GEbounds& ebounds) const | |
| 877 | +{ | |
| 878 | + // Initialise energy boundary weights with zero weights | |
| 879 | + std::vector<double> weights(m_ebounds.size(), 0.0); | |
| 880 | + | |
| 881 | + // Loop over all energy bins of counts cube | |
| 882 | + for (int i = 0; i < m_ebounds.size(); ++i) { | |
| 883 | + | |
| 884 | + // Get energy boundaries of counts cube bin | |
| 885 | + GEnergy emin(m_ebounds.emin(i)); | |
| 886 | + GEnergy emax(m_ebounds.emax(i)); | |
| 887 | + | |
| 888 | + // Loop over all energy boundaries of the event list and add the | |
| 889 | + // coverage fraction to the weights | |
| 890 | + for (int k = 0; k < ebounds.size(); ++k) { | |
| 891 | + | |
| 892 | + // If there is no overlap then check next boundary | |
| 893 | + if ((ebounds.emax(k) <= emin) || (ebounds.emin(k) >= emax)) { | |
| 894 | + continue; | |
| 895 | + } | |
| 896 | + | |
| 897 | + // Get minimum and maximum energy of overlap region | |
| 898 | + GEnergy elow = (ebounds.emin(k) > emin) ? ebounds.emin(k) : emin; | |
| 899 | + GEnergy ehigh = (ebounds.emax(k) < emax) ? ebounds.emax(k) : emax; | |
| 900 | + | |
| 901 | + // Compute overlap weight | |
| 902 | + #if defined(G_PLAW_WEIGHTS) | |
| 903 | + double w_overlap = gammalib::plaw_photon_flux(elow.TeV(), | |
| 904 | + ehigh.TeV(), | |
| 905 | + 1.0, -2.0); | |
| 906 | + double w_full = gammalib::plaw_photon_flux(emin.TeV(), | |
| 907 | + emax.TeV(), | |
| 908 | + 1.0, -2.0); | |
| 909 | + double weight = w_overlap / w_full; | |
| 910 | + #else | |
| 911 | + double weight = (ehigh - elow) / (emax - emin); | |
| 912 | + #endif | |
| 913 | + | |
| 914 | + // Add overlap weight | |
| 915 | + weights[i] += weight; | |
| 916 | + | |
| 917 | + } // endfor: looped over all energy boundaries of the event list | |
| 918 | + | |
| 919 | + } // endfor: looped over all energy boundaries of the counts cube | |
| 920 | + | |
| 921 | + // Return | |
| 922 | + return weights; | |
| 923 | +} | ... | ... |
src/ctbin/ctbin.hpp
| ... | ... | @@ -28,6 +28,7 @@ |
| 28 | 28 | #define CTBIN_HPP |
| 29 | 29 | |
| 30 | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | +#include <vector> | |
| 31 | 32 | #include "GammaLib.hpp" |
| 32 | 33 | #include "GCTALib.hpp" |
| 33 | 34 | #include "ctool.hpp" |
| ... | ... | @@ -84,12 +85,14 @@ public: |
| 84 | 85 | |
| 85 | 86 | protected: |
| 86 | 87 | // Protected methods |
| 87 | - void init_members(void); | |
| 88 | - void copy_members(const ctbin& app); | |
| 89 | - void free_members(void); | |
| 90 | - void get_parameters(void); | |
| 91 | - void fill_cube(GCTAObservation* obs); | |
| 92 | - void obs_cube(void); | |
| 88 | + void init_members(void); | |
| 89 | + void copy_members(const ctbin& app); | |
| 90 | + void free_members(void); | |
| 91 | + void get_parameters(void); | |
| 92 | + void fill_cube(GCTAObservation* obs); | |
| 93 | + void obs_cube(void); | |
| 94 | + GSkyMap set_roi_weights(const GCTARoi& roi) const; | |
| 95 | + std::vector<double> set_energy_weights(const GEbounds& ebounds) const; | |
| 93 | 96 | |
| 94 | 97 | // User parameters |
| 95 | 98 | GFilename m_outcube; //!< Output counts map file name |
| ... | ... | @@ -98,7 +101,8 @@ protected: |
| 98 | 101 | |
| 99 | 102 | // Protected members |
| 100 | 103 | GObservations m_obs; //!< Observation container |
| 101 | - GSkyMap m_cube; //!< Event cube | |
| 104 | + GSkyMap m_counts; //!< Event cube counts | |
| 105 | + GSkyMap m_weights; //!< Event cube weights | |
| 102 | 106 | GEbounds m_ebounds; //!< Energy boundaries |
| 103 | 107 | GGti m_gti; //!< Good time intervals |
| 104 | 108 | double m_ontime; //!< Total ontime |
| ... | ... | @@ -128,7 +132,7 @@ inline |
| 128 | 132 | GCTAEventCube ctbin::cube(void) const |
| 129 | 133 | { |
| 130 | 134 | // Build event cube |
| 131 | - GCTAEventCube cube(m_cube, m_ebounds, m_gti); | |
| 135 | + GCTAEventCube cube(m_counts, m_weights, m_ebounds, m_gti); | |
| 132 | 136 | |
| 133 | 137 | // Return cube |
| 134 | 138 | return cube; | ... | ... |
src/ctcubemask/ctcubemask.cpp
| ... | ... | @@ -383,7 +383,7 @@ void ctcubemask::publish(const std::string& name) |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | // Publish counts cube |
| 386 | - cube->map().publish(user_name); | |
| 386 | + cube->counts().publish(user_name); | |
| 387 | 387 | |
| 388 | 388 | } |
| 389 | 389 | } |
| ... | ... | @@ -492,7 +492,7 @@ void ctcubemask::apply_mask(GCTAObservation* obs) |
| 492 | 492 | if (cube != NULL) { |
| 493 | 493 | |
| 494 | 494 | // Extract event cube and energy boundaries |
| 495 | - GSkyMap map = cube->map(); | |
| 495 | + GSkyMap map = cube->counts(); | |
| 496 | 496 | const GEbounds& ebounds = cube->ebounds(); |
| 497 | 497 | |
| 498 | 498 | // If no energy selection is required set energy boundaries to cube boundaries |
| ... | ... | @@ -625,7 +625,7 @@ void ctcubemask::apply_mask(GCTAObservation* obs) |
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | // Put back map into the event cube |
| 628 | - cube->map(map); | |
| 628 | + cube->counts(map); | |
| 629 | 629 | |
| 630 | 630 | } // endif: observation contained an event cube |
| 631 | 631 | ... | ... |
src/ctmodel/ctmodel.cpp
src/ctobssim/ctobssim.cpp
| ... | ... | @@ -39,8 +39,8 @@ |
| 39 | 39 | "GModels&, GRan&, GLog*)" |
| 40 | 40 | #define G_SIMULATE_INTERVAL "ctobssim::simulate_interval(GCTAObservation*"\ |
| 41 | 41 | ", GCTAEventList*, GCTAResponseIrf*, GModels&, GTime&"\ |
| 42 | - ", GTime&, GEnergy&, GEnergy&, GSkyDir&, double&"\ | |
| 43 | - ", double&, GRan&, GLog*, int&)" | |
| 42 | + ", GTime&, GEnergy&, GEnergy&, GEnergy&, GEnergy&"\ | |
| 43 | + ", GSkyDir&, double&, double&, GRan&, GLog*, int&)" | |
| 44 | 44 | #define G_GET_AREA "ctobssim::get_area(GCTAObservation* obs, GEnergy&, "\ |
| 45 | 45 | "GEnergy&)" |
| 46 | 46 | |
| ... | ... | @@ -711,7 +711,8 @@ void ctobssim::simulate_source(GCTAObservation* obs, |
| 711 | 711 | GCTAEventList* events = static_cast<GCTAEventList*>(obs->events()); |
| 712 | 712 | |
| 713 | 713 | // Get CTA response |
| 714 | - const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*>(obs->response()); | |
| 714 | + const GCTAResponseIrf* rsp = | |
| 715 | + dynamic_cast<const GCTAResponseIrf*>(obs->response()); | |
| 715 | 716 | if (rsp == NULL) { |
| 716 | 717 | std::string cls = std::string(typeid(obs->response()).name()); |
| 717 | 718 | std::string msg = "Response of type \""+cls+"\" is not a CTA " |
| ... | ... | @@ -767,28 +768,28 @@ void ctobssim::simulate_source(GCTAObservation* obs, |
| 767 | 768 | // Loop over all energy boundaries |
| 768 | 769 | for (int ie = 0; ie < ebounds.size(); ++ie) { |
| 769 | 770 | |
| 770 | - // Set energy interval | |
| 771 | - GEnergy emin = ebounds.emin(ie); | |
| 772 | - GEnergy emax = ebounds.emax(ie); | |
| 771 | + // Set reconstructed energy interval | |
| 772 | + GEnergy ereco_min = ebounds.emin(ie); | |
| 773 | + GEnergy ereco_max = ebounds.emax(ie); | |
| 773 | 774 | |
| 774 | 775 | // Set true photon energy limits for simulation. If the |
| 775 | 776 | // observation has energy dispersion then add a margin. |
| 776 | - GEnergy e_true_min = emin; | |
| 777 | - GEnergy e_true_max = emax; | |
| 777 | + GEnergy etrue_min = ereco_min; | |
| 778 | + GEnergy etrue_max = ereco_max; | |
| 778 | 779 | if (rsp->use_edisp()) { |
| 779 | - e_true_min = rsp->ebounds(e_true_min).emin(); | |
| 780 | - e_true_max = rsp->ebounds(e_true_max).emax(); | |
| 780 | + etrue_min = rsp->ebounds(etrue_min).emin(); | |
| 781 | + etrue_max = rsp->ebounds(etrue_max).emax(); | |
| 781 | 782 | } |
| 782 | 783 | |
| 783 | 784 | // Determine simulation area |
| 784 | - double area = get_area(obs, emin, emax); | |
| 785 | + double area = get_area(obs, ereco_min, ereco_max); | |
| 785 | 786 | |
| 786 | 787 | // Log energy range and simulation area |
| 787 | 788 | if (logNormal()) { |
| 788 | 789 | *wrklog << gammalib::parformat("Photon energy range", indent); |
| 789 | - *wrklog << e_true_min << " - " << e_true_max << std::endl; | |
| 790 | + *wrklog << etrue_min << " - " << etrue_max << std::endl; | |
| 790 | 791 | *wrklog << gammalib::parformat("Event energy range", indent); |
| 791 | - *wrklog << emin << " - " << emax << std::endl; | |
| 792 | + *wrklog << ereco_min << " - " << ereco_max << std::endl; | |
| 792 | 793 | } |
| 793 | 794 | |
| 794 | 795 | // Increment indentation if there are several energy |
| ... | ... | @@ -811,7 +812,8 @@ void ctobssim::simulate_source(GCTAObservation* obs, |
| 811 | 812 | |
| 812 | 813 | // Simulate events for this time and energy interval |
| 813 | 814 | simulate_interval(obs, rsp, events, models, tmin, tmax, |
| 814 | - e_true_min, e_true_max, dir, rad, area, | |
| 815 | + etrue_min, etrue_max, ereco_min, ereco_max, | |
| 816 | + dir, rad, area, | |
| 815 | 817 | ran, wrklog, indent, nphotons, nevents); |
| 816 | 818 | |
| 817 | 819 | // Log simulation results |
| ... | ... | @@ -887,8 +889,10 @@ void ctobssim::simulate_source(GCTAObservation* obs, |
| 887 | 889 | * @param[in] models Model list. |
| 888 | 890 | * @param[in] tmin Start time. |
| 889 | 891 | * @param[in] tmax Stop time. |
| 890 | - * @param[in] emin Minimum energy. | |
| 891 | - * @param[in] emax Maximum energy. | |
| 892 | + * @param[in] etrue_min Minimum true energy. | |
| 893 | + * @param[in] etrue_max Maximum true energy. | |
| 894 | + * @param[in] ereco_min Minimum reconstructed energy. | |
| 895 | + * @param[in] ereco_max Maximum reconstructed energy. | |
| 892 | 896 | * @param[in] dir Simulation cone centre. |
| 893 | 897 | * @param[in] rad Simulation cone radius (degrees). |
| 894 | 898 | * @param[in] area Simulation area (cm^2). |
| ... | ... | @@ -906,8 +910,10 @@ void ctobssim::simulate_interval(GCTAObservation* obs, |
| 906 | 910 | const GModels& models, |
| 907 | 911 | const GTime& tmin, |
| 908 | 912 | const GTime& tmax, |
| 909 | - const GEnergy& emin, | |
| 910 | - const GEnergy& emax, | |
| 913 | + const GEnergy& etrue_min, | |
| 914 | + const GEnergy& etrue_max, | |
| 915 | + const GEnergy& ereco_min, | |
| 916 | + const GEnergy& ereco_max, | |
| 911 | 917 | const GSkyDir& dir, |
| 912 | 918 | const double& rad, |
| 913 | 919 | const double& area, |
| ... | ... | @@ -938,7 +944,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, |
| 938 | 944 | // simulated photons to m_max_photons. The photon rate is estimated |
| 939 | 945 | // from the model flux and used to set the duration of the time |
| 940 | 946 | // slice. |
| 941 | - double flux = get_model_flux(model, emin, emax, dir, rad, | |
| 947 | + double flux = get_model_flux(model, etrue_min, etrue_max, dir, rad, | |
| 942 | 948 | indent, wrklog); |
| 943 | 949 | double rate = flux * area; |
| 944 | 950 | double duration = 1800.0; // default: 1800 sec |
| ... | ... | @@ -1017,7 +1023,8 @@ void ctobssim::simulate_interval(GCTAObservation* obs, |
| 1017 | 1023 | |
| 1018 | 1024 | // Simulate time slice |
| 1019 | 1025 | simulate_time_slice(obs, rsp, events, model, tstart, tstop, |
| 1020 | - emin, emax, dir, rad, area, | |
| 1026 | + etrue_min, etrue_max, ereco_min, ereco_max, | |
| 1027 | + dir, rad, area, | |
| 1021 | 1028 | ran, wrklog, indent, |
| 1022 | 1029 | nphotons[i], nevents[i]); |
| 1023 | 1030 | |
| ... | ... | @@ -1067,8 +1074,10 @@ void ctobssim::simulate_interval(GCTAObservation* obs, |
| 1067 | 1074 | * @param[in] models Model list. |
| 1068 | 1075 | * @param[in] tmin Start time. |
| 1069 | 1076 | * @param[in] tmax Stop time. |
| 1070 | - * @param[in] emin Minimum energy. | |
| 1071 | - * @param[in] emax Maximum energy. | |
| 1077 | + * @param[in] etrue_min Minimum true energy. | |
| 1078 | + * @param[in] etrue_max Maximum true energy. | |
| 1079 | + * @param[in] ereco_min Minimum reconstructed energy. | |
| 1080 | + * @param[in] ereco_max Maximum reconstructed energy. | |
| 1072 | 1081 | * @param[in] dir Simulation cone centre. |
| 1073 | 1082 | * @param[in] rad Simulation cone radius (degrees). |
| 1074 | 1083 | * @param[in] area Simulation area (cm^2). |
| ... | ... | @@ -1086,8 +1095,10 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, |
| 1086 | 1095 | const GModelSky* model, |
| 1087 | 1096 | const GTime& tstart, |
| 1088 | 1097 | const GTime& tstop, |
| 1089 | - const GEnergy& emin, | |
| 1090 | - const GEnergy& emax, | |
| 1098 | + const GEnergy& etrue_min, | |
| 1099 | + const GEnergy& etrue_max, | |
| 1100 | + const GEnergy& ereco_min, | |
| 1101 | + const GEnergy& ereco_max, | |
| 1091 | 1102 | const GSkyDir& dir, |
| 1092 | 1103 | const double& rad, |
| 1093 | 1104 | const double& area, |
| ... | ... | @@ -1098,8 +1109,8 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, |
| 1098 | 1109 | int& nevents) |
| 1099 | 1110 | { |
| 1100 | 1111 | // Get photons |
| 1101 | - GPhotons photons = model->mc(area, dir, rad, emin, emax, tstart, tstop, | |
| 1102 | - ran); | |
| 1112 | + GPhotons photons = model->mc(area, dir, rad, etrue_min, etrue_max, | |
| 1113 | + tstart, tstop, ran); | |
| 1103 | 1114 | |
| 1104 | 1115 | // Dump number of simulated photons |
| 1105 | 1116 | if (logExplicit()) { |
| ... | ... | @@ -1122,11 +1133,11 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, |
| 1122 | 1133 | GCTAEventAtom* event = rsp->mc(area, photons[i], *obs, ran); |
| 1123 | 1134 | |
| 1124 | 1135 | // Use event only if it exists and if it falls within ROI, the |
| 1125 | - // energy interval and the time slice | |
| 1136 | + // reconstructed energy interval and the time slice | |
| 1126 | 1137 | if (event != NULL) { |
| 1127 | 1138 | if (events->roi().contains(*event) && |
| 1128 | - event->energy() >= emin && | |
| 1129 | - event->energy() <= emax && | |
| 1139 | + event->energy() >= ereco_min && | |
| 1140 | + event->energy() <= ereco_max && | |
| 1130 | 1141 | event->time() >= tstart && |
| 1131 | 1142 | event->time() <= tstop) { |
| 1132 | 1143 | event->event_id(m_event_id); | ... | ... |
src/ctobssim/ctobssim.hpp
| ... | ... | @@ -85,8 +85,10 @@ protected: |
| 85 | 85 | const GModels& models, |
| 86 | 86 | const GTime& tmin, |
| 87 | 87 | const GTime& tmax, |
| 88 | - const GEnergy& emin, | |
| 89 | - const GEnergy& emax, | |
| 88 | + const GEnergy& etrue_min, | |
| 89 | + const GEnergy& etrue_max, | |
| 90 | + const GEnergy& ereco_min, | |
| 91 | + const GEnergy& ereco_max, | |
| 90 | 92 | const GSkyDir& dir, |
| 91 | 93 | const double& rad, |
| 92 | 94 | const double& area, |
| ... | ... | @@ -101,8 +103,10 @@ protected: |
| 101 | 103 | const GModelSky* model, |
| 102 | 104 | const GTime& tstart, |
| 103 | 105 | const GTime& tstop, |
| 104 | - const GEnergy& emin, | |
| 105 | - const GEnergy& emax, | |
| 106 | + const GEnergy& etrue_min, | |
| 107 | + const GEnergy& etrue_max, | |
| 108 | + const GEnergy& ereco_min, | |
| 109 | + const GEnergy& ereco_max, | |
| 106 | 110 | const GSkyDir& dir, |
| 107 | 111 | const double& rad, |
| 108 | 112 | const double& area, | ... | ... |
src/ctulimit/ctulimit.cpp
| ... | ... | @@ -290,14 +290,20 @@ void ctulimit::run(void) |
| 290 | 290 | |
| 291 | 291 | } // endif: likelihood was zero |
| 292 | 292 | |
| 293 | - // Extract current value | |
| 293 | + // Extract current value and error | |
| 294 | 294 | double value = m_model_par->factor_value(); |
| 295 | + double error = m_model_par->factor_error(); | |
| 295 | 296 | |
| 296 | - // Compute parameter bracketing | |
| 297 | + // If parameter error is zero then take parameter value as error | |
| 298 | + if (error == 0) { | |
| 299 | + error = value; | |
| 300 | + } | |
| 301 | + | |
| 302 | + // Compute parameter bracketing. In case that the parameter error is | |
| 297 | 303 | double parmin = std::max(m_model_par->factor_min(), |
| 298 | - value - m_sigma_min * m_model_par->factor_error()); | |
| 304 | + value - m_sigma_min * error); | |
| 299 | 305 | double parmax = std::min(m_model_par->factor_max(), |
| 300 | - value + m_sigma_max * m_model_par->factor_error()); | |
| 306 | + value + m_sigma_max * error); | |
| 301 | 307 | |
| 302 | 308 | // Write header |
| 303 | 309 | if (logTerse()) { | ... | ... |
test/Makefile.am
| ... | ... | @@ -17,9 +17,7 @@ TESTS_ENVIRONMENT = @RUNSHARED@=$(top_builddir)/src/.libs$(TEST_ENV_DIR):$(LIBDI |
| 17 | 17 | $(TEST_PYTHON_ENV) |
| 18 | 18 | |
| 19 | 19 | # Tests (these are the tests to be executed) |
| 20 | -TESTS = test_ctools.sh \ | |
| 21 | - $(TEST_CSCRIPTS) \ | |
| 22 | - $(TEST_PYTHON_CTOOLS) \ | |
| 20 | +TESTS = $(TEST_PYTHON_CTOOLS) \ | |
| 23 | 21 | $(TEST_PYTHON_CSCRIPTS) |
| 24 | 22 | |
| 25 | 23 | # Add Valgrind rule | ... | ... |
test/data/crab_bkgcube.fits.gz
No preview for this file type
test/data/crab_edispcube.fits.gz
No preview for this file type
test/data/crab_expcube.fits.gz
No preview for this file type
test/data/crab_psfcube.fits.gz
No preview for this file type
test/data/sciver/crab_map_nn.xml
| ... | ... | @@ -7,7 +7,7 @@ |
| 7 | 7 | <parameter name="Scale" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> |
| 8 | 8 | </spectrum> |
| 9 | 9 | <spatialModel type="SpatialMap" file="data/sciver/cena_lobes_parkes.fits" normalize="0"> |
| 10 | - <parameter scale="1" name="Prefactor" min="0.001" max="1000.0" value="3" free="0"/> | |
| 10 | + <parameter scale="1" name="Prefactor" min="0.001" max="1000.0" value="0.3" free="0"/> | |
| 11 | 11 | </spatialModel> |
| 12 | 12 | </source> |
| 13 | 13 | <source name="Background" type="CTAIrfBackground" instrument="CTA"> | ... | ... |
test/data/sciver/crab_plaw_edisp.xml
0 → 100644
| 1 | +<?xml version="1.0" standalone="no"?> | |
| 2 | +<source_library title="source library"> | |
| 3 | + <source name="Crab" type="PointSource"> | |
| 4 | + <spectrum type="PowerLaw"> | |
| 5 | + <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/> | |
| 6 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | |
| 7 | + <parameter name="Scale" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | |
| 8 | + </spectrum> | |
| 9 | + <spatialModel type="SkyDirFunction"> | |
| 10 | + <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="0"/> | |
| 11 | + <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="0"/> | |
| 12 | + </spatialModel> | |
| 13 | + </source> | |
| 14 | + <source name="Background" type="CTAIrfBackground" instrument="CTA"> | |
| 15 | + <spectrum type="PowerLaw"> | |
| 16 | + <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e3" free="1"/> | |
| 17 | + <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/> | |
| 18 | + <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/> | |
| 19 | + </spectrum> | |
| 20 | + </source> | |
| 21 | +</source_library> | ... | ... |
test/data/tsmaps.txt
0 → 100644
test/science_verification.py
| ... | ... | @@ -10,7 +10,7 @@ |
| 10 | 10 | # |
| 11 | 11 | # -------------------------------------------------------------------------- |
| 12 | 12 | # |
| 13 | -# Copyright (C) 2015 Juergen Knoedlseder | |
| 13 | +# Copyright (C) 2015-2016 Juergen Knoedlseder | |
| 14 | 14 | # |
| 15 | 15 | # This program is free software: you can redistribute it and/or modify |
| 16 | 16 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -39,53 +39,100 @@ import sys |
| 39 | 39 | # Generate pull distribution # |
| 40 | 40 | # ========================== # |
| 41 | 41 | def generate_pull_distribution(model, trials=100, \ |
| 42 | - caldb="prod2", irf="South_50h", \ | |
| 42 | + caldb='prod2', irf='South_50h', \ | |
| 43 | 43 | deadc=0.95, edisp=False, \ |
| 44 | 44 | ra=83.63, dec=22.01, rad=5.0, \ |
| 45 | 45 | emin=0.1, emax=100.0, enumbins=0, \ |
| 46 | 46 | duration=1800.0, \ |
| 47 | 47 | npix=200, binsz=0.02, \ |
| 48 | - coordsys="CEL", proj="TAN", \ | |
| 49 | - pattern="single", offset=1.5, \ | |
| 48 | + coordsys='CEL', proj='TAN', \ | |
| 49 | + pattern='single', offset=1.5, \ | |
| 50 | 50 | debug=False, chatter=2): |
| 51 | 51 | """ |
| 52 | - Generates pull distribution for a given model. | |
| 53 | - | |
| 54 | - Parameters: | |
| 55 | - model - Model XML filename (without .xml extension) | |
| 52 | + Generates pull distribution for a given model | |
| 53 | + | |
| 54 | + Parameters | |
| 55 | + ---------- | |
| 56 | + model : str | |
| 57 | + Model XML filename (without .xml extension) | |
| 58 | + trials : int, optional | |
| 59 | + Number of trials | |
| 60 | + caldb : str, optional | |
| 61 | + Calibration database | |
| 62 | + irf : str, optional | |
| 63 | + Name of instrument response function | |
| 64 | + deadc : float, optional | |
| 65 | + Deadtime correction factor | |
| 66 | + edisp : bool, optional | |
| 67 | + Use energy dispersion? | |
| 68 | + ra : float, optional | |
| 69 | + Right Ascension of pointing (deg) | |
| 70 | + dec : float, optional | |
| 71 | + Declination of pointing (deg) | |
| 72 | + rad : float, optional | |
| 73 | + Simulation radius (deg) | |
| 74 | + emin : float, optional | |
| 75 | + Minimum energy (TeV) | |
| 76 | + emax : float, optional | |
| 77 | + Maximum energy (TeV) | |
| 78 | + enumbins : int, optional | |
| 79 | + Number of energy bins (0 for unbinned analysis) | |
| 80 | + duration : float, optional | |
| 81 | + Observation duration (sec) | |
| 82 | + npix : int, optional | |
| 83 | + Number of pixels | |
| 84 | + binsz : float, optional | |
| 85 | + Pixel size (deg/pixel) | |
| 86 | + coordsys : str, optional | |
| 87 | + Coordinate system (CEL or GAL) | |
| 88 | + proj : str, optional | |
| 89 | + Sky projection | |
| 90 | + pattern : str, optional | |
| 91 | + Pointing pattern | |
| 92 | + offset : float, optional | |
| 93 | + Offset between pointing directions | |
| 94 | + debug : bool, optional | |
| 95 | + Enable debugging? | |
| 96 | + chatter : int, optional | |
| 97 | + Chatter level | |
| 98 | + | |
| 99 | + Returns | |
| 100 | + ------- | |
| 101 | + outfile : str | |
| 102 | + Name of pull distribution output file | |
| 56 | 103 | """ |
| 57 | 104 | # Derive parameters |
| 58 | 105 | head, tail = os.path.split(model) |
| 59 | - inmodel = model + ".xml" | |
| 60 | - outfile = "cspull_" + tail + ".dat" | |
| 106 | + inmodel = model + '.xml' | |
| 107 | + outfile = 'cspull_' + tail + '.dat' | |
| 61 | 108 | |
| 62 | 109 | # Setup pull distribution generation |
| 63 | 110 | pull = cscripts.cspull() |
| 64 | - pull["inobs"] = "NONE" | |
| 65 | - pull["inmodel"] = inmodel | |
| 66 | - pull["outfile"] = outfile | |
| 67 | - pull["caldb"] = caldb | |
| 68 | - pull["irf"] = irf | |
| 69 | - pull["edisp"] = edisp | |
| 70 | - pull["ra"] = ra | |
| 71 | - pull["dec"] = dec | |
| 72 | - pull["rad"] = rad | |
| 73 | - pull["emin"] = emin | |
| 74 | - pull["emax"] = emax | |
| 75 | - pull["tmin"] = 0.0 | |
| 76 | - pull["tmax"] = duration | |
| 77 | - pull["enumbins"] = enumbins | |
| 78 | - pull["npix"] = npix | |
| 79 | - pull["binsz"] = binsz | |
| 80 | - pull["coordsys"] = coordsys | |
| 81 | - pull["proj"] = proj | |
| 82 | - pull["deadc"] = deadc | |
| 83 | - pull["rad"] = rad | |
| 84 | - pull["pattern"] = pattern | |
| 85 | - pull["offset"] = offset | |
| 86 | - pull["ntrials"] = trials | |
| 87 | - pull["debug"] = debug | |
| 88 | - pull["chatter"] = chatter | |
| 111 | + pull['inobs'] = 'NONE' | |
| 112 | + pull['inmodel'] = inmodel | |
| 113 | + pull['outfile'] = outfile | |
| 114 | + pull['caldb'] = caldb | |
| 115 | + pull['irf'] = irf | |
| 116 | + pull['edisp'] = edisp | |
| 117 | + pull['ra'] = ra | |
| 118 | + pull['dec'] = dec | |
| 119 | + pull['rad'] = rad | |
| 120 | + pull['emin'] = emin | |
| 121 | + pull['emax'] = emax | |
| 122 | + pull['tmin'] = 0.0 | |
| 123 | + pull['tmax'] = duration | |
| 124 | + pull['enumbins'] = enumbins | |
| 125 | + pull['npix'] = npix | |
| 126 | + pull['binsz'] = binsz | |
| 127 | + pull['coordsys'] = coordsys | |
| 128 | + pull['proj'] = proj | |
| 129 | + pull['deadc'] = deadc | |
| 130 | + pull['rad'] = rad | |
| 131 | + pull['pattern'] = pattern | |
| 132 | + pull['offset'] = offset | |
| 133 | + pull['ntrials'] = trials | |
| 134 | + pull['debug'] = debug | |
| 135 | + pull['chatter'] = chatter | |
| 89 | 136 | |
| 90 | 137 | # Generate pull distributions |
| 91 | 138 | pull.run() |
| ... | ... | @@ -99,10 +146,17 @@ def generate_pull_distribution(model, trials=100, \ |
| 99 | 146 | # ========================= # |
| 100 | 147 | def analyse_pull_distribution(filename): |
| 101 | 148 | """ |
| 102 | - Compute mean and standard deviation of pull distribution. | |
| 149 | + Compute mean and standard deviation of pull distribution | |
| 150 | + | |
| 151 | + Parameters | |
| 152 | + ---------- | |
| 153 | + filename : str | |
| 154 | + Pull distribution ASCII file to analyse | |
| 103 | 155 | |
| 104 | - Parameter: | |
| 105 | - filename - Pull distribution ASCII file to analyse. | |
| 156 | + Returns | |
| 157 | + ------- | |
| 158 | + results : dict | |
| 159 | + Result dictionary | |
| 106 | 160 | """ |
| 107 | 161 | # Initialise column names, means and standard deviations |
| 108 | 162 | colnames = [] |
| ... | ... | @@ -161,7 +215,7 @@ class sciver(gammalib.GPythonTestSuite): |
| 161 | 215 | # Constructor |
| 162 | 216 | def __init__(self): |
| 163 | 217 | """ |
| 164 | - Constructor. | |
| 218 | + Constructor | |
| 165 | 219 | """ |
| 166 | 220 | # Call base class constructor |
| 167 | 221 | gammalib.GPythonTestSuite.__init__(self) |
| ... | ... | @@ -175,45 +229,65 @@ class sciver(gammalib.GPythonTestSuite): |
| 175 | 229 | # Set test functions |
| 176 | 230 | def set(self): |
| 177 | 231 | """ |
| 178 | - Set all test functions. | |
| 232 | + Set all test functions | |
| 179 | 233 | """ |
| 180 | 234 | # Set test name |
| 181 | - self.name("Science Verification") | |
| 235 | + self.name('Science Verification') | |
| 182 | 236 | |
| 183 | 237 | # Append spectral tests |
| 184 | - self.append(self.spec_plaw, "Test power law model") | |
| 185 | - self.append(self.spec_plaw2, "Test power law 2 model") | |
| 186 | - self.append(self.spec_eplaw, "Test exponentially cut off power law model") | |
| 187 | - self.append(self.spec_supeplaw, "Test super exponentially cut off power law model") | |
| 188 | - self.append(self.spec_logparabola, "Test log parabola model") | |
| 189 | - self.append(self.spec_gauss, "Test Gaussian model") | |
| 190 | - self.append(self.spec_filefct, "Test file function model") | |
| 191 | - self.append(self.spec_nodes, "Test nodes model") | |
| 238 | + self.append(self.spec_plaw, 'Test power law model') | |
| 239 | + self.append(self.spec_plaw_edisp, 'Test power law model with energy dispersion') | |
| 240 | + self.append(self.spec_plaw2, 'Test power law 2 model') | |
| 241 | + self.append(self.spec_eplaw, 'Test exponentially cut off power law model') | |
| 242 | + self.append(self.spec_supeplaw, 'Test super exponentially cut off power law model') | |
| 243 | + self.append(self.spec_logparabola, 'Test log parabola model') | |
| 244 | + self.append(self.spec_gauss, 'Test Gaussian model') | |
| 245 | + self.append(self.spec_filefct, 'Test file function model') | |
| 246 | + self.append(self.spec_nodes, 'Test nodes model') | |
| 192 | 247 | |
| 193 | 248 | # Append spatial tests |
| 194 | - self.append(self.spat_ptsrc, "Test point source model") | |
| 195 | - self.append(self.spat_rdisk, "Test radial disk model") | |
| 196 | - self.append(self.spat_rgauss, "Test radial Gaussian model") | |
| 197 | - self.append(self.spat_rshell, "Test radial shell model") | |
| 198 | - self.append(self.spat_edisk, "Test elliptical disk model") | |
| 199 | - self.append(self.spat_egauss, "Test elliptical Gaussian model") | |
| 200 | - self.append(self.spat_const, "Test diffuse isotropic model") | |
| 201 | - self.append(self.spat_map, "Test diffuse map model") | |
| 202 | - self.append(self.spat_map_roi, "Test diffuse map model (small ROI)") | |
| 203 | - self.append(self.spat_map_nn, "Test diffuse map model (not normalized and scaled)") | |
| 204 | - self.append(self.spat_cube, "Test diffuse cube model") | |
| 249 | + self.append(self.spat_ptsrc, 'Test point source model') | |
| 250 | + self.append(self.spat_rdisk, 'Test radial disk model') | |
| 251 | + self.append(self.spat_rgauss, 'Test radial Gaussian model') | |
| 252 | + self.append(self.spat_rshell, 'Test radial shell model') | |
| 253 | + self.append(self.spat_edisk, 'Test elliptical disk model') | |
| 254 | + self.append(self.spat_egauss, 'Test elliptical Gaussian model') | |
| 255 | + self.append(self.spat_const, 'Test diffuse isotropic model') | |
| 256 | + self.append(self.spat_map, 'Test diffuse map model') | |
| 257 | + self.append(self.spat_map_roi, 'Test diffuse map model (small ROI)') | |
| 258 | + self.append(self.spat_map_nn, 'Test diffuse map model (not normalized and scaled)') | |
| 259 | + self.append(self.spat_cube, 'Test diffuse cube model') | |
| 205 | 260 | |
| 206 | 261 | # Return |
| 207 | 262 | return |
| 208 | 263 | |
| 209 | 264 | # Generate and analyse pull distributions |
| 210 | - def pull(self, model, trials=100, ra=83.63, dec=22.01, rad=5.0): | |
| 211 | - """ | |
| 212 | - Generate and analyse pull distributions. | |
| 265 | + def pull(self, model, trials=100, ra=83.63, dec=22.01, rad=5.0, | |
| 266 | + edisp=False, debug=False): | |
| 267 | + """ | |
| 268 | + Generate and analyse pull distributions | |
| 269 | + | |
| 270 | + Parameters | |
| 271 | + ---------- | |
| 272 | + model : str | |
| 273 | + Model XML filename (without .xml extension) | |
| 274 | + trials : int, optional | |
| 275 | + Number of trials | |
| 276 | + ra : float, optional | |
| 277 | + Right Ascension of pointing (deg) | |
| 278 | + dec : float, optional | |
| 279 | + Declination of pointing (deg) | |
| 280 | + rad : float, optional | |
| 281 | + Simulation radius (deg) | |
| 282 | + edisp : bool, optional | |
| 283 | + Use energy dispersion? | |
| 284 | + debug : bool, optional | |
| 285 | + Enable debugging? | |
| 213 | 286 | """ |
| 214 | 287 | # Generate pull distribution |
| 215 | 288 | outfile = generate_pull_distribution(model, trials=trials, |
| 216 | - ra=ra, dec=dec, rad=rad) | |
| 289 | + ra=ra, dec=dec, rad=rad, | |
| 290 | + edisp=edisp, debug=debug) | |
| 217 | 291 | |
| 218 | 292 | # Analyse pull distribution |
| 219 | 293 | self.results = analyse_pull_distribution(outfile) |
| ... | ... | @@ -224,18 +298,23 @@ class sciver(gammalib.GPythonTestSuite): |
| 224 | 298 | # Test parameter result |
| 225 | 299 | def test(self, name): |
| 226 | 300 | """ |
| 227 | - Test one parameter. | |
| 301 | + Test one parameter | |
| 302 | + | |
| 303 | + Parameters | |
| 304 | + ---------- | |
| 305 | + name : str | |
| 306 | + Parameter name | |
| 228 | 307 | """ |
| 229 | 308 | # Test mean |
| 230 | - mean = self.results[name]["mean"] | |
| 309 | + mean = self.results[name]['mean'] | |
| 231 | 310 | valid = (mean >= -0.40) and (mean <= +0.40) |
| 232 | - text = "Mean %.5f of %s should be within [-0.4,0.4] range" % (mean, name) | |
| 311 | + text = 'Mean %.5f of %s should be within [-0.4,0.4] range' % (mean, name) | |
| 233 | 312 | self.test_assert(valid, text) |
| 234 | 313 | |
| 235 | 314 | # Test standard deviation |
| 236 | - std = self.results[name]["std"] | |
| 315 | + std = self.results[name]['std'] | |
| 237 | 316 | valid = (std >= 0.80) and (std <= 1.20) |
| 238 | - text = "Standard deviation %.5f of %s should be within [0.8,1.2] range" % (std, name) | |
| 317 | + text = 'Standard deviation %.5f of %s should be within [0.8,1.2] range' % (std, name) | |
| 239 | 318 | self.test_assert(valid, text) |
| 240 | 319 | |
| 241 | 320 | # Return |
| ... | ... | @@ -244,257 +323,269 @@ class sciver(gammalib.GPythonTestSuite): |
| 244 | 323 | # Test power law model |
| 245 | 324 | def spec_plaw(self): |
| 246 | 325 | """ |
| 247 | - Test power law model. | |
| 326 | + Test power law model | |
| 248 | 327 | """ |
| 249 | - self.pull("data/sciver/crab_plaw") | |
| 250 | - self.test("Pull_Crab_Prefactor") | |
| 251 | - self.test("Pull_Crab_Index") | |
| 252 | - self.test("Pull_Background_Prefactor") | |
| 253 | - self.test("Pull_Background_Index") | |
| 328 | + self.pull('data/sciver/crab_plaw') | |
| 329 | + self.test('Pull_Crab_Prefactor') | |
| 330 | + self.test('Pull_Crab_Index') | |
| 331 | + self.test('Pull_Background_Prefactor') | |
| 332 | + self.test('Pull_Background_Index') | |
| 333 | + return | |
| 334 | + | |
| 335 | + # Test power law model with energy dispersion | |
| 336 | + def spec_plaw_edisp(self): | |
| 337 | + """ | |
| 338 | + Test power law model with energy dispersion | |
| 339 | + """ | |
| 340 | + self.pull('data/sciver/crab_plaw_edisp', edisp=True) | |
| 341 | + self.test('Pull_Crab_Prefactor') | |
| 342 | + self.test('Pull_Crab_Index') | |
| 343 | + self.test('Pull_Background_Prefactor') | |
| 344 | + self.test('Pull_Background_Index') | |
| 254 | 345 | return |
| 255 | 346 | |
| 256 | 347 | # Test power law 2 model |
| 257 | 348 | def spec_plaw2(self): |
| 258 | 349 | """ |
| 259 | - Test power law 2 model. | |
| 350 | + Test power law 2 model | |
| 260 | 351 | """ |
| 261 | - self.pull("data/sciver/crab_plaw2") | |
| 262 | - self.test("Pull_Crab_Integral") | |
| 263 | - self.test("Pull_Crab_Index") | |
| 264 | - self.test("Pull_Background_Prefactor") | |
| 265 | - self.test("Pull_Background_Index") | |
| 352 | + self.pull('data/sciver/crab_plaw2') | |
| 353 | + self.test('Pull_Crab_Integral') | |
| 354 | + self.test('Pull_Crab_Index') | |
| 355 | + self.test('Pull_Background_Prefactor') | |
| 356 | + self.test('Pull_Background_Index') | |
| 266 | 357 | return |
| 267 | 358 | |
| 268 | 359 | # Test exponentially cut off power law model |
| 269 | 360 | def spec_eplaw(self): |
| 270 | 361 | """ |
| 271 | - Test exponentially cut off power law model. | |
| 362 | + Test exponentially cut off power law model | |
| 272 | 363 | """ |
| 273 | - self.pull("data/sciver/crab_eplaw") | |
| 274 | - self.test("Pull_Crab_Prefactor") | |
| 275 | - self.test("Pull_Crab_Index") | |
| 276 | - self.test("Pull_Crab_Cutoff") | |
| 277 | - self.test("Pull_Background_Prefactor") | |
| 278 | - self.test("Pull_Background_Index") | |
| 364 | + self.pull('data/sciver/crab_eplaw') | |
| 365 | + self.test('Pull_Crab_Prefactor') | |
| 366 | + self.test('Pull_Crab_Index') | |
| 367 | + self.test('Pull_Crab_Cutoff') | |
| 368 | + self.test('Pull_Background_Prefactor') | |
| 369 | + self.test('Pull_Background_Index') | |
| 279 | 370 | return |
| 280 | 371 | |
| 281 | 372 | # Test super exponentially cut off power law model |
| 282 | 373 | def spec_supeplaw(self): |
| 283 | 374 | """ |
| 284 | - Test super exponentially cut off power law model. | |
| 375 | + Test super exponentially cut off power law model | |
| 285 | 376 | """ |
| 286 | - self.pull("data/sciver/crab_supeplaw") | |
| 287 | - self.test("Pull_Crab_Prefactor") | |
| 288 | - self.test("Pull_Crab_Index1") | |
| 289 | - self.test("Pull_Crab_Index2") | |
| 290 | - self.test("Pull_Crab_Cutoff") | |
| 291 | - self.test("Pull_Background_Prefactor") | |
| 292 | - self.test("Pull_Background_Index") | |
| 377 | + self.pull('data/sciver/crab_supeplaw') | |
| 378 | + self.test('Pull_Crab_Prefactor') | |
| 379 | + self.test('Pull_Crab_Index1') | |
| 380 | + self.test('Pull_Crab_Index2') | |
| 381 | + self.test('Pull_Crab_Cutoff') | |
| 382 | + self.test('Pull_Background_Prefactor') | |
| 383 | + self.test('Pull_Background_Index') | |
| 293 | 384 | return |
| 294 | 385 | |
| 295 | 386 | # Test log parabola model |
| 296 | 387 | def spec_logparabola(self): |
| 297 | 388 | """ |
| 298 | - Test log parabola model. | |
| 389 | + Test log parabola model | |
| 299 | 390 | """ |
| 300 | - self.pull("data/sciver/crab_logparabola") | |
| 301 | - self.test("Pull_Crab_Prefactor") | |
| 302 | - self.test("Pull_Crab_Index") | |
| 303 | - self.test("Pull_Crab_Curvature") | |
| 304 | - self.test("Pull_Background_Prefactor") | |
| 305 | - self.test("Pull_Background_Index") | |
| 391 | + self.pull('data/sciver/crab_logparabola') | |
| 392 | + self.test('Pull_Crab_Prefactor') | |
| 393 | + self.test('Pull_Crab_Index') | |
| 394 | + self.test('Pull_Crab_Curvature') | |
| 395 | + self.test('Pull_Background_Prefactor') | |
| 396 | + self.test('Pull_Background_Index') | |
| 306 | 397 | return |
| 307 | 398 | |
| 308 | 399 | # Test Gaussian model |
| 309 | 400 | def spec_gauss(self): |
| 310 | 401 | """ |
| 311 | - Test Gaussian model. | |
| 402 | + Test Gaussian model | |
| 312 | 403 | """ |
| 313 | - self.pull("data/sciver/crab_gauss") | |
| 314 | - self.test("Pull_Crab_Normalization") | |
| 315 | - self.test("Pull_Crab_Mean") | |
| 316 | - self.test("Pull_Crab_Sigma") | |
| 317 | - self.test("Pull_Background_Prefactor") | |
| 318 | - self.test("Pull_Background_Index") | |
| 404 | + self.pull('data/sciver/crab_gauss') | |
| 405 | + self.test('Pull_Crab_Normalization') | |
| 406 | + self.test('Pull_Crab_Mean') | |
| 407 | + self.test('Pull_Crab_Sigma') | |
| 408 | + self.test('Pull_Background_Prefactor') | |
| 409 | + self.test('Pull_Background_Index') | |
| 319 | 410 | return |
| 320 | 411 | |
| 321 | 412 | # Test file function model |
| 322 | 413 | def spec_filefct(self): |
| 323 | 414 | """ |
| 324 | - Test file function model. | |
| 415 | + Test file function model | |
| 325 | 416 | """ |
| 326 | - self.pull("data/sciver/crab_filefct") | |
| 327 | - self.test("Pull_Crab_Normalization") | |
| 328 | - self.test("Pull_Background_Prefactor") | |
| 329 | - self.test("Pull_Background_Index") | |
| 417 | + self.pull('data/sciver/crab_filefct') | |
| 418 | + self.test('Pull_Crab_Normalization') | |
| 419 | + self.test('Pull_Background_Prefactor') | |
| 420 | + self.test('Pull_Background_Index') | |
| 330 | 421 | return |
| 331 | 422 | |
| 332 | 423 | # Test nodes model |
| 333 | 424 | def spec_nodes(self): |
| 334 | 425 | """ |
| 335 | - Test nodes model. | |
| 426 | + Test nodes model | |
| 336 | 427 | """ |
| 337 | - self.pull("data/sciver/crab_nodes") | |
| 338 | - self.test("Pull_Crab_Intensity0") | |
| 339 | - self.test("Pull_Crab_Intensity1") | |
| 340 | - self.test("Pull_Crab_Intensity2") | |
| 341 | - self.test("Pull_Crab_Intensity3") | |
| 342 | - self.test("Pull_Background_Prefactor") | |
| 343 | - self.test("Pull_Background_Index") | |
| 428 | + self.pull('data/sciver/crab_nodes') | |
| 429 | + self.test('Pull_Crab_Intensity0') | |
| 430 | + self.test('Pull_Crab_Intensity1') | |
| 431 | + self.test('Pull_Crab_Intensity2') | |
| 432 | + self.test('Pull_Crab_Intensity3') | |
| 433 | + self.test('Pull_Background_Prefactor') | |
| 434 | + self.test('Pull_Background_Index') | |
| 344 | 435 | return |
| 345 | 436 | |
| 346 | 437 | # Test point source model |
| 347 | 438 | def spat_ptsrc(self): |
| 348 | 439 | """ |
| 349 | - Test point source model. | |
| 440 | + Test point source model | |
| 350 | 441 | """ |
| 351 | - self.pull("data/sciver/crab_ptsrc") | |
| 352 | - self.test("Pull_Crab_Prefactor") | |
| 353 | - self.test("Pull_Crab_Index") | |
| 354 | - self.test("Pull_Crab_RA") | |
| 355 | - self.test("Pull_Crab_DEC") | |
| 356 | - self.test("Pull_Background_Prefactor") | |
| 357 | - self.test("Pull_Background_Index") | |
| 442 | + self.pull('data/sciver/crab_ptsrc') | |
| 443 | + self.test('Pull_Crab_Prefactor') | |
| 444 | + self.test('Pull_Crab_Index') | |
| 445 | + self.test('Pull_Crab_RA') | |
| 446 | + self.test('Pull_Crab_DEC') | |
| 447 | + self.test('Pull_Background_Prefactor') | |
| 448 | + self.test('Pull_Background_Index') | |
| 358 | 449 | return |
| 359 | 450 | |
| 360 | 451 | # Test radial disk model |
| 361 | 452 | def spat_rdisk(self): |
| 362 | 453 | """ |
| 363 | - Test radial disk model. | |
| 454 | + Test radial disk model | |
| 364 | 455 | """ |
| 365 | - self.pull("data/sciver/crab_rdisk") | |
| 366 | - self.test("Pull_Crab_Prefactor") | |
| 367 | - self.test("Pull_Crab_Index") | |
| 368 | - self.test("Pull_Crab_RA") | |
| 369 | - self.test("Pull_Crab_DEC") | |
| 370 | - self.test("Pull_Crab_Radius") | |
| 371 | - self.test("Pull_Background_Prefactor") | |
| 372 | - self.test("Pull_Background_Index") | |
| 456 | + self.pull('data/sciver/crab_rdisk') | |
| 457 | + self.test('Pull_Crab_Prefactor') | |
| 458 | + self.test('Pull_Crab_Index') | |
| 459 | + self.test('Pull_Crab_RA') | |
| 460 | + self.test('Pull_Crab_DEC') | |
| 461 | + self.test('Pull_Crab_Radius') | |
| 462 | + self.test('Pull_Background_Prefactor') | |
| 463 | + self.test('Pull_Background_Index') | |
| 373 | 464 | return |
| 374 | 465 | |
| 375 | 466 | # Test radial Gaussian model |
| 376 | 467 | def spat_rgauss(self): |
| 377 | 468 | """ |
| 378 | - Test radial Gaussian model. | |
| 469 | + Test radial Gaussian model | |
| 379 | 470 | """ |
| 380 | - self.pull("data/sciver/crab_rgauss") | |
| 381 | - self.test("Pull_Crab_Prefactor") | |
| 382 | - self.test("Pull_Crab_Index") | |
| 383 | - self.test("Pull_Crab_RA") | |
| 384 | - self.test("Pull_Crab_DEC") | |
| 385 | - self.test("Pull_Crab_Sigma") | |
| 386 | - self.test("Pull_Background_Prefactor") | |
| 387 | - self.test("Pull_Background_Index") | |
| 471 | + self.pull('data/sciver/crab_rgauss') | |
| 472 | + self.test('Pull_Crab_Prefactor') | |
| 473 | + self.test('Pull_Crab_Index') | |
| 474 | + self.test('Pull_Crab_RA') | |
| 475 | + self.test('Pull_Crab_DEC') | |
| 476 | + self.test('Pull_Crab_Sigma') | |
| 477 | + self.test('Pull_Background_Prefactor') | |
| 478 | + self.test('Pull_Background_Index') | |
| 388 | 479 | return |
| 389 | 480 | |
| 390 | 481 | # Test radial shell model |
| 391 | 482 | def spat_rshell(self): |
| 392 | 483 | """ |
| 393 | - Test radial shell model. | |
| 394 | - """ | |
| 395 | - self.pull("data/sciver/crab_rshell") | |
| 396 | - self.test("Pull_Crab_Prefactor") | |
| 397 | - self.test("Pull_Crab_Index") | |
| 398 | - self.test("Pull_Crab_RA") | |
| 399 | - self.test("Pull_Crab_DEC") | |
| 400 | - self.test("Pull_Crab_Radius") | |
| 401 | - self.test("Pull_Crab_Width") | |
| 402 | - self.test("Pull_Background_Prefactor") | |
| 403 | - self.test("Pull_Background_Index") | |
| 484 | + Test radial shell model | |
| 485 | + """ | |
| 486 | + self.pull('data/sciver/crab_rshell') | |
| 487 | + self.test('Pull_Crab_Prefactor') | |
| 488 | + self.test('Pull_Crab_Index') | |
| 489 | + self.test('Pull_Crab_RA') | |
| 490 | + self.test('Pull_Crab_DEC') | |
| 491 | + self.test('Pull_Crab_Radius') | |
| 492 | + self.test('Pull_Crab_Width') | |
| 493 | + self.test('Pull_Background_Prefactor') | |
| 494 | + self.test('Pull_Background_Index') | |
| 404 | 495 | return |
| 405 | 496 | |
| 406 | 497 | # Test elliptical disk model |
| 407 | 498 | def spat_edisk(self): |
| 408 | 499 | """ |
| 409 | - Test elliptical disk model. | |
| 410 | - """ | |
| 411 | - self.pull("data/sciver/crab_edisk") | |
| 412 | - self.test("Pull_Crab_Prefactor") | |
| 413 | - self.test("Pull_Crab_Index") | |
| 414 | - self.test("Pull_Crab_RA") | |
| 415 | - self.test("Pull_Crab_DEC") | |
| 416 | - self.test("Pull_Crab_PA") | |
| 417 | - self.test("Pull_Crab_MinorRadius") | |
| 418 | - self.test("Pull_Crab_MajorRadius") | |
| 419 | - self.test("Pull_Background_Prefactor") | |
| 420 | - self.test("Pull_Background_Index") | |
| 500 | + Test elliptical disk model | |
| 501 | + """ | |
| 502 | + self.pull('data/sciver/crab_edisk') | |
| 503 | + self.test('Pull_Crab_Prefactor') | |
| 504 | + self.test('Pull_Crab_Index') | |
| 505 | + self.test('Pull_Crab_RA') | |
| 506 | + self.test('Pull_Crab_DEC') | |
| 507 | + self.test('Pull_Crab_PA') | |
| 508 | + self.test('Pull_Crab_MinorRadius') | |
| 509 | + self.test('Pull_Crab_MajorRadius') | |
| 510 | + self.test('Pull_Background_Prefactor') | |
| 511 | + self.test('Pull_Background_Index') | |
| 421 | 512 | return |
| 422 | 513 | |
| 423 | 514 | # Test elliptical Gaussian model |
| 424 | 515 | def spat_egauss(self): |
| 425 | 516 | """ |
| 426 | - Test elliptical Gaussian model. | |
| 427 | - """ | |
| 428 | - self.pull("data/sciver/crab_egauss") | |
| 429 | - self.test("Pull_Crab_Prefactor") | |
| 430 | - self.test("Pull_Crab_Index") | |
| 431 | - self.test("Pull_Crab_RA") | |
| 432 | - self.test("Pull_Crab_DEC") | |
| 433 | - self.test("Pull_Crab_PA") | |
| 434 | - self.test("Pull_Crab_MinorRadius") | |
| 435 | - self.test("Pull_Crab_MajorRadius") | |
| 436 | - self.test("Pull_Background_Prefactor") | |
| 437 | - self.test("Pull_Background_Index") | |
| 517 | + Test elliptical Gaussian model | |
| 518 | + """ | |
| 519 | + self.pull('data/sciver/crab_egauss') | |
| 520 | + self.test('Pull_Crab_Prefactor') | |
| 521 | + self.test('Pull_Crab_Index') | |
| 522 | + self.test('Pull_Crab_RA') | |
| 523 | + self.test('Pull_Crab_DEC') | |
| 524 | + self.test('Pull_Crab_PA') | |
| 525 | + self.test('Pull_Crab_MinorRadius') | |
| 526 | + self.test('Pull_Crab_MajorRadius') | |
| 527 | + self.test('Pull_Background_Prefactor') | |
| 528 | + self.test('Pull_Background_Index') | |
| 438 | 529 | return |
| 439 | 530 | |
| 440 | 531 | # Test diffuse isotropic model |
| 441 | 532 | def spat_const(self): |
| 442 | 533 | """ |
| 443 | - Test diffuse isotropic model. | |
| 534 | + Test diffuse isotropic model | |
| 444 | 535 | """ |
| 445 | - self.pull("data/sciver/crab_const") | |
| 446 | - self.test("Pull_Crab_Prefactor") | |
| 447 | - self.test("Pull_Crab_Index") | |
| 448 | - self.test("Pull_Background_Prefactor") | |
| 449 | - self.test("Pull_Background_Index") | |
| 536 | + self.pull('data/sciver/crab_const') | |
| 537 | + self.test('Pull_Crab_Prefactor') | |
| 538 | + self.test('Pull_Crab_Index') | |
| 539 | + self.test('Pull_Background_Prefactor') | |
| 540 | + self.test('Pull_Background_Index') | |
| 450 | 541 | return |
| 451 | 542 | |
| 452 | 543 | # Test diffuse map model |
| 453 | 544 | def spat_map(self): |
| 454 | 545 | """ |
| 455 | - Test diffuse map model. | |
| 546 | + Test diffuse map model | |
| 456 | 547 | """ |
| 457 | - self.pull("data/sciver/crab_map", ra=201.3651, dec=-43.0191) | |
| 458 | - self.test("Pull_Crab_Prefactor") | |
| 459 | - self.test("Pull_Crab_Index") | |
| 460 | - self.test("Pull_Background_Prefactor") | |
| 461 | - self.test("Pull_Background_Index") | |
| 548 | + self.pull('data/sciver/crab_map', ra=201.3651, dec=-43.0191) | |
| 549 | + self.test('Pull_Crab_Prefactor') | |
| 550 | + self.test('Pull_Crab_Index') | |
| 551 | + self.test('Pull_Background_Prefactor') | |
| 552 | + self.test('Pull_Background_Index') | |
| 462 | 553 | return |
| 463 | 554 | |
| 464 | 555 | # Test diffuse map model (small ROI) |
| 465 | 556 | def spat_map_roi(self): |
| 466 | 557 | """ |
| 467 | - Test diffuse map model (small ROI). | |
| 558 | + Test diffuse map model (small ROI) | |
| 468 | 559 | """ |
| 469 | - self.pull("data/sciver/crab_map_roi", ra=201.3651, dec=-43.0191, rad=1.5) | |
| 470 | - self.test("Pull_Crab_Prefactor") | |
| 471 | - self.test("Pull_Crab_Index") | |
| 472 | - self.test("Pull_Background_Prefactor") | |
| 473 | - self.test("Pull_Background_Index") | |
| 560 | + self.pull('data/sciver/crab_map_roi', ra=201.3651, dec=-43.0191, rad=1.5) | |
| 561 | + self.test('Pull_Crab_Prefactor') | |
| 562 | + self.test('Pull_Crab_Index') | |
| 563 | + self.test('Pull_Background_Prefactor') | |
| 564 | + self.test('Pull_Background_Index') | |
| 474 | 565 | return |
| 475 | 566 | |
| 476 | 567 | # Test diffuse map model (not normalized and scaled) |
| 477 | 568 | def spat_map_nn(self): |
| 478 | 569 | """ |
| 479 | - Test diffuse map model (not normalized and scaled). | |
| 570 | + Test diffuse map model (not normalized and scaled) | |
| 480 | 571 | """ |
| 481 | - self.pull("data/sciver/crab_map_nn", ra=201.3651, dec=-43.0191, rad=1.5) | |
| 482 | - self.test("Pull_Crab_Prefactor") | |
| 483 | - self.test("Pull_Crab_Index") | |
| 484 | - self.test("Pull_Background_Prefactor") | |
| 485 | - self.test("Pull_Background_Index") | |
| 572 | + self.pull('data/sciver/crab_map_nn', ra=201.3651, dec=-43.0191, rad=1.5) | |
| 573 | + self.test('Pull_Crab_Prefactor') | |
| 574 | + self.test('Pull_Crab_Index') | |
| 575 | + self.test('Pull_Background_Prefactor') | |
| 576 | + self.test('Pull_Background_Index') | |
| 486 | 577 | return |
| 487 | 578 | |
| 488 | 579 | # Test diffuse cube model |
| 489 | 580 | def spat_cube(self): |
| 490 | 581 | """ |
| 491 | - Test diffuse cube model. | |
| 582 | + Test diffuse cube model | |
| 492 | 583 | """ |
| 493 | - self.pull("data/sciver/crab_cube") | |
| 494 | - self.test("Pull_Crab_Prefactor") | |
| 495 | - self.test("Pull_Crab_Index") | |
| 496 | - self.test("Pull_Background_Prefactor") | |
| 497 | - self.test("Pull_Background_Index") | |
| 584 | + self.pull('data/sciver/crab_cube') | |
| 585 | + self.test('Pull_Crab_Prefactor') | |
| 586 | + self.test('Pull_Crab_Index') | |
| 587 | + self.test('Pull_Background_Prefactor') | |
| 588 | + self.test('Pull_Background_Index') | |
| 498 | 589 | return |
| 499 | 590 | |
| 500 | 591 | |
| ... | ... | @@ -502,11 +593,9 @@ class sciver(gammalib.GPythonTestSuite): |
| 502 | 593 | # Main routine entry point # |
| 503 | 594 | # ======================== # |
| 504 | 595 | if __name__ == '__main__': |
| 505 | - """ | |
| 506 | - Perform ctools science verification | |
| 507 | - """ | |
| 596 | + | |
| 508 | 597 | # Allocate test suite container |
| 509 | - suites = gammalib.GTestSuites("ctools science verification") | |
| 598 | + suites = gammalib.GTestSuites('ctools science verification') | |
| 510 | 599 | |
| 511 | 600 | # Allocate test suite and append it to the container |
| 512 | 601 | suite_sciver = sciver() |
| ... | ... | @@ -519,17 +608,17 @@ if __name__ == '__main__': |
| 519 | 608 | |
| 520 | 609 | # Set PFILES environment variable |
| 521 | 610 | try: |
| 522 | - os.mkdir("pfiles") | |
| 611 | + os.mkdir('pfiles') | |
| 523 | 612 | except: |
| 524 | 613 | pass |
| 525 | - os.system("cp -r ../src/*/*.par pfiles/") | |
| 526 | - os.environ['PFILES'] = "pfiles" | |
| 614 | + os.system('cp -r ../src/*/*.par pfiles/') | |
| 615 | + os.environ['PFILES'] = 'pfiles' | |
| 527 | 616 | |
| 528 | 617 | # Run test suite |
| 529 | 618 | success = suites.run() |
| 530 | 619 | |
| 531 | 620 | # Save test results |
| 532 | - suites.save("reports/sciver.xml") | |
| 621 | + suites.save('reports/sciver.xml') | |
| 533 | 622 | |
| 534 | 623 | # Set return code |
| 535 | 624 | if success: | ... | ... |
test/test_cscaldb.py
| ... | ... | @@ -51,11 +51,11 @@ class Test(gammalib.GPythonTestSuite): |
| 51 | 51 | Set all test functions. |
| 52 | 52 | """ |
| 53 | 53 | # Set test name |
| 54 | - self.name("cscaldb") | |
| 54 | + self.name('cscaldb') | |
| 55 | 55 | |
| 56 | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test cscaldb on command line") | |
| 58 | - self.append(self._test_python, "Test cscaldb from Python") | |
| 57 | + self.append(self._test_cmd, 'Test cscaldb on command line') | |
| 58 | + self.append(self._test_python, 'Test cscaldb from Python') | |
| 59 | 59 | |
| 60 | 60 | # Return |
| 61 | 61 | return |
| ... | ... | @@ -66,23 +66,23 @@ class Test(gammalib.GPythonTestSuite): |
| 66 | 66 | Test cscaldb on the command line. |
| 67 | 67 | """ |
| 68 | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | |
| 70 | - cscaldb = "../cscripts/cscaldb.py" | |
| 69 | + if os.path.isfile('README'): | |
| 70 | + cscaldb = '../cscripts/cscaldb.py' | |
| 71 | 71 | else: |
| 72 | - cscaldb = "cscaldb" | |
| 72 | + cscaldb = 'cscaldb' | |
| 73 | 73 | |
| 74 | 74 | # Setup cscaldb command |
| 75 | 75 | cmd = cscaldb+' logfile="cscaldb_cmd1.log" chatter=1' |
| 76 | 76 | |
| 77 | 77 | # Execute cscaldb, make sure we catch any exception |
| 78 | 78 | try: |
| 79 | - rc = os.system(cmd+" >/dev/null 2>&1") | |
| 79 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 80 | 80 | except: |
| 81 | 81 | pass |
| 82 | 82 | |
| 83 | 83 | # Check if execution was successful |
| 84 | 84 | self.test_assert(rc == 0, |
| 85 | - "Successful cscaldb execution on command line") | |
| 85 | + 'Successful cscaldb execution on command line') | |
| 86 | 86 | |
| 87 | 87 | # Return |
| 88 | 88 | return |
| ... | ... | @@ -94,8 +94,8 @@ class Test(gammalib.GPythonTestSuite): |
| 94 | 94 | """ |
| 95 | 95 | # Set-up cscaldb |
| 96 | 96 | caldb = cscripts.cscaldb() |
| 97 | - caldb["logfile"] = "cscaldb_py1.log" | |
| 98 | - caldb["chatter"] = 2 | |
| 97 | + caldb['logfile'] = 'cscaldb_py1.log' | |
| 98 | + caldb['chatter'] = 2 | |
| 99 | 99 | |
| 100 | 100 | # Run script |
| 101 | 101 | caldb.logFileOpen() # Make sure we get a log file | ... | ... |
test/test_cscripts.sh.in
| ... | ... | @@ -257,9 +257,9 @@ else |
| 257 | 257 | exit 1 |
| 258 | 258 | fi |
| 259 | 259 | # === ascii-file === |
| 260 | -ls data/tsmap_*.fits > tsmaps.txt | |
| 260 | +#ls data/tsmap_*.fits > tsmaps.txt | |
| 261 | 261 | @PYTHON_COVERAGE@@abs_top_srcdir@/cscripts/cstsmapmerge.py \ |
| 262 | - inmaps="@tsmaps.txt" \ | |
| 262 | + inmaps="@data/tsmaps.txt" \ | |
| 263 | 263 | outmap="merged_tsmap4.fits" > cstsmapmerge.log |
| 264 | 264 | $ECHO -n "." |
| 265 | 265 | if [ -s "merged_tsmap4.fits" ] | ... | ... |
test/test_csfindobs.py
| ... | ... | @@ -51,11 +51,11 @@ class Test(gammalib.GPythonTestSuite): |
| 51 | 51 | Set all test functions. |
| 52 | 52 | """ |
| 53 | 53 | # Set test name |
| 54 | - self.name("csfindobs") | |
| 54 | + self.name('csfindobs') | |
| 55 | 55 | |
| 56 | 56 | # Append tests |
| 57 | - self.append(self._test_cmd, "Test csfindobs on command line") | |
| 58 | - self.append(self._test_python, "Test csfindobs from Python") | |
| 57 | + self.append(self._test_cmd, 'Test csfindobs on command line') | |
| 58 | + self.append(self._test_python, 'Test csfindobs from Python') | |
| 59 | 59 | |
| 60 | 60 | # Return |
| 61 | 61 | return |
| ... | ... | @@ -66,10 +66,10 @@ class Test(gammalib.GPythonTestSuite): |
| 66 | 66 | Test csfindobs on the command line. |
| 67 | 67 | """ |
| 68 | 68 | # Kluge to set the command (installed version has no README file) |
| 69 | - if os.path.isfile("README"): | |
| 70 | - csfindobs = "../cscripts/csfindobs.py" | |
| 69 | + if os.path.isfile('README'): | |
| 70 | + csfindobs = '../cscripts/csfindobs.py' | |
| 71 | 71 | else: |
| 72 | - csfindobs = "csfindobs" | |
| 72 | + csfindobs = 'csfindobs' | |
| 73 | 73 | |
| 74 | 74 | # Setup csfindobs command |
| 75 | 75 | cmd = csfindobs+' datapath="iactdata/"'+ \ |
| ... | ... | @@ -80,16 +80,16 @@ class Test(gammalib.GPythonTestSuite): |
| 80 | 80 | |
| 81 | 81 | # Execute csfindobs, make sure we catch any exception |
| 82 | 82 | try: |
| 83 | - rc = os.system(cmd+" >/dev/null 2>&1") | |
| 83 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 84 | 84 | except: |
| 85 | 85 | pass |
| 86 | 86 | |
| 87 | 87 | # Check if execution was successful |
| 88 | 88 | self.test_assert(rc == 0, |
| 89 | - "Successful csfindobs execution on command line") | |
| 89 | + 'Successful csfindobs execution on command line') | |
| 90 | 90 | |
| 91 | 91 | # Check run list |
| 92 | - self._check_runlist("runlist_cmd1.dat") | |
| 92 | + self._check_runlist('runlist_cmd1.dat') | |
| 93 | 93 | |
| 94 | 94 | # Setup csfindobs command |
| 95 | 95 | cmd = csfindobs+' datapath="path_that_does_not_exist"'+ \ |
| ... | ... | @@ -100,13 +100,13 @@ class Test(gammalib.GPythonTestSuite): |
| 100 | 100 | |
| 101 | 101 | # Execute csfindobs, make sure we catch any exception |
| 102 | 102 | try: |
| 103 | - rc = os.system(cmd+" >/dev/null 2>&1") | |
| 103 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 104 | 104 | except: |
| 105 | 105 | pass |
| 106 | 106 | |
| 107 | 107 | # Check if execution failed |
| 108 | 108 | self.test_assert(rc != 0, |
| 109 | - "Failure of csfindobs execution on command line") | |
| 109 | + 'Failure of csfindobs execution on command line') | |
| 110 | 110 | |
| 111 | 111 | # Return |
| 112 | 112 | return |
| ... | ... | @@ -118,14 +118,14 @@ class Test(gammalib.GPythonTestSuite): |
| 118 | 118 | """ |
| 119 | 119 | # Set-up csfindobs |
| 120 | 120 | findobs = cscripts.csfindobs() |
| 121 | - findobs["datapath"] = "iactdata/" | |
| 122 | - findobs["prodname"] = "unit-test" | |
| 123 | - findobs["outfile"] = "runlist_py1.dat" | |
| 124 | - findobs["ra"] = 83.63 | |
| 125 | - findobs["dec"] = 22.01 | |
| 126 | - findobs["rad"] = 1.0 | |
| 127 | - findobs["logfile"] = "csfindobs_py1.log" | |
| 128 | - findobs["chatter"] = 2 | |
| 121 | + findobs['datapath'] = 'iactdata/' | |
| 122 | + findobs['prodname'] = 'unit-test' | |
| 123 | + findobs['outfile'] = 'runlist_py1.dat' | |
| 124 | + findobs['ra'] = 83.63 | |
| 125 | + findobs['dec'] = 22.01 | |
| 126 | + findobs['rad'] = 1.0 | |
| 127 | + findobs['logfile'] = 'csfindobs_py1.log' | |
| 128 | + findobs['chatter'] = 2 | |
| 129 | 129 | |
| 130 | 130 | # Run csfindobs script and save run list |
| 131 | 131 | findobs.logFileOpen() # Make sure we get a log file |
| ... | ... | @@ -133,7 +133,7 @@ class Test(gammalib.GPythonTestSuite): |
| 133 | 133 | findobs.save() |
| 134 | 134 | |
| 135 | 135 | # Check run list |
| 136 | - self._check_runlist("runlist_py1.dat") | |
| 136 | + self._check_runlist('runlist_py1.dat') | |
| 137 | 137 | |
| 138 | 138 | # Return |
| 139 | 139 | return | ... | ... |
test/test_cslightcrv.py
| ... | ... | @@ -43,8 +43,8 @@ class Test(gammalib.GPythonTestSuite): |
| 43 | 43 | gammalib.GPythonTestSuite.__init__(self) |
| 44 | 44 | |
| 45 | 45 | # Set members |
| 46 | - self._events_name = "data/crab_events.fits" | |
| 47 | - self._model_name = "data/crab.xml" | |
| 46 | + self._events_name = 'data/crab_events.fits' | |
| 47 | + self._model_name = 'data/crab.xml' | |
| 48 | 48 | |
| 49 | 49 | # Return |
| 50 | 50 | return |
| ... | ... | @@ -55,11 +55,11 @@ class Test(gammalib.GPythonTestSuite): |
| 55 | 55 | Set all test functions. |
| 56 | 56 | """ |
| 57 | 57 | # Set test name |
| 58 | - self.name("cslightcrv") | |
| 58 | + self.name('cslightcrv') | |
| 59 | 59 | |
| 60 | 60 | # Append tests |
| 61 | - self.append(self._test_cmd, "Test cslightcrv on command line") | |
| 62 | - self.append(self._test_python, "Test cslightcrv from Python") | |
| 61 | + self.append(self._test_cmd, 'Test cslightcrv on command line') | |
| 62 | + self.append(self._test_python, 'Test cslightcrv from Python') | |
| 63 | 63 | |
| 64 | 64 | # Return |
| 65 | 65 | return |
| ... | ... | @@ -70,10 +70,10 @@ class Test(gammalib.GPythonTestSuite): |
| 70 | 70 | Test cslightcrv on the command line. |
| 71 | 71 | """ |
| 72 | 72 | # Kluge to set the command (installed version has no README file) |
| 73 | - if os.path.isfile("README"): | |
| 74 | - cslightcrv = "../cscripts/cslightcrv.py" | |
| 73 | + if os.path.isfile('README'): | |
| 74 | + cslightcrv = '../cscripts/cslightcrv.py' | |
| 75 | 75 | else: |
| 76 | - cslightcrv = "cslightcrv" | |
| 76 | + cslightcrv = 'cslightcrv' | |
| 77 | 77 | |
| 78 | 78 | # Setup cslightcrv command |
| 79 | 79 | cmd = cslightcrv+' inobs="'+self._events_name+'"'+ \ |
| ... | ... | @@ -86,16 +86,16 @@ class Test(gammalib.GPythonTestSuite): |
| 86 | 86 | |
| 87 | 87 | # Execute cslightcrv, make sure we catch any exception |
| 88 | 88 | try: |
| 89 | - rc = os.system(cmd+" >/dev/null 2>&1") | |
| 89 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 90 | 90 | except: |
| 91 | 91 | pass |
| 92 | 92 | |
| 93 | 93 | # Check if execution was successful |
| 94 | 94 | self.test_assert(rc == 0, |
| 95 | - "Successful cslightcrv execution on command line") | |
| 95 | + 'Successful cslightcrv execution on command line') | |
| 96 | 96 | |
| 97 | 97 | # Check light curve |
| 98 | - self._check_light_curve("lightcurve_cmd1.fits", 3) | |
| 98 | + self._check_light_curve('lightcurve_cmd1.fits', 3) | |
| 99 | 99 | |
| 100 | 100 | # Setup cslightcrv command |
| 101 | 101 | cmd = cslightcrv+' inobs="events_that_do_not_exist.fits"'+ \ |
| ... | ... | @@ -108,13 +108,13 @@ class Test(gammalib.GPythonTestSuite): |
| 108 | 108 | |
| 109 | 109 | # Execute cslightcrv, make sure we catch any exception |
| 110 | 110 | try: |
| 111 | - rc = os.system(cmd+" >/dev/null 2>&1") | |
| 111 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 112 | 112 | except: |
| 113 | 113 | pass |
| 114 | 114 | |
| 115 | 115 | # Check if execution failed |
| 116 | 116 | self.test_assert(rc != 0, |
| 117 | - "Failure of cslightcrv execution on command line") | |
| 117 | + 'Failure of cslightcrv execution on command line') | |
| 118 | 118 | |
| 119 | 119 | # Return |
| 120 | 120 | return |
| ... | ... | @@ -126,21 +126,21 @@ class Test(gammalib.GPythonTestSuite): |
| 126 | 126 | """ |
| 127 | 127 | # Set-up unbinned cslightcrv |
| 128 | 128 | lcrv = cscripts.cslightcrv() |
| 129 | - lcrv["inobs"] = self._events_name | |
| 130 | - lcrv["inmodel"] = self._model_name | |
| 131 | - lcrv["srcname"] = "Crab" | |
| 132 | - lcrv["caldb"] = "prod2" | |
| 133 | - lcrv["irf"] = "South_0.5h" | |
| 134 | - lcrv["tbinalg"] = "LIN" | |
| 135 | - lcrv["tmin"] = 51544.50 | |
| 136 | - lcrv["tmax"] = 51544.53 | |
| 137 | - lcrv["tbins"] = 3 | |
| 138 | - lcrv["enumbins"] = 0 | |
| 139 | - lcrv["emin"] = 0.1 | |
| 140 | - lcrv["emax"] = 100.0 | |
| 141 | - lcrv["outfile"] = "lightcurve_py1.fits" | |
| 142 | - lcrv["logfile"] = "cslightcrv_py1.log" | |
| 143 | - lcrv["chatter"] = 2 | |
| 129 | + lcrv['inobs'] = self._events_name | |
| 130 | + lcrv['inmodel'] = self._model_name | |
| 131 | + lcrv['srcname'] = 'Crab' | |
| 132 | + lcrv['caldb'] = 'prod2' | |
| 133 | + lcrv['irf'] = 'South_0.5h' | |
| 134 | + lcrv['tbinalg'] = 'LIN' | |
| 135 | + lcrv['tmin'] = 51544.50 | |
| 136 | + lcrv['tmax'] = 51544.53 | |
| 137 | + lcrv['tbins'] = 3 | |
| 138 | + lcrv['enumbins'] = 0 | |
| 139 | + lcrv['emin'] = 0.1 | |
| 140 | + lcrv['emax'] = 100.0 | |
| 141 | + lcrv['outfile'] = 'cslightcrv_py1.fits' | |
| 142 | + lcrv['logfile'] = 'cslightcrv_py1.log' | |
| 143 | + lcrv['chatter'] = 2 | |
| 144 | 144 | |
| 145 | 145 | # Run cslightcrv script and save light curve |
| 146 | 146 | lcrv.logFileOpen() # Make sure we get a log file |
| ... | ... | @@ -148,7 +148,7 @@ class Test(gammalib.GPythonTestSuite): |
| 148 | 148 | lcrv.save() |
| 149 | 149 | |
| 150 | 150 | # Check light curve |
| 151 | - self._check_light_curve("lightcurve_py1.fits", 3) | |
| 151 | + self._check_light_curve('cslightcrv_py1.fits', 3) | |
| 152 | 152 | |
| 153 | 153 | # Now use FILE as time bin algorithm. For this we need first to |
| 154 | 154 | # create an ASCII file. We use now 6 time bins. The ASCII file |
| ... | ... | @@ -157,31 +157,32 @@ class Test(gammalib.GPythonTestSuite): |
| 157 | 157 | tmin = 51544.50 |
| 158 | 158 | tdelta = 0.01 |
| 159 | 159 | for i in range(csv.nrows()): |
| 160 | - csv[i,0] = "%.5f" % (tmin + i * tdelta) | |
| 161 | - csv[i,1] = "%.5f" % (tmin + (i+1) * tdelta) | |
| 162 | - csv.save("lightcurve_py2.dat", " ", True) | |
| 160 | + csv[i,0] = '%.5f' % (tmin + i * tdelta) | |
| 161 | + csv[i,1] = '%.5f' % (tmin + (i+1) * tdelta) | |
| 162 | + csv.save('cslightcrv_py2.dat', ' ', True) | |
| 163 | 163 | |
| 164 | 164 | # Set-up unbinned cslightcrv |
| 165 | 165 | lcrv = cscripts.cslightcrv() |
| 166 | - lcrv["inobs"] = self._events_name | |
| 167 | - lcrv["inmodel"] = self._model_name | |
| 168 | - lcrv["srcname"] = "Crab" | |
| 169 | - lcrv["caldb"] = "prod2" | |
| 170 | - lcrv["irf"] = "South_0.5h" | |
| 171 | - lcrv["tbinalg"] = "FILE" | |
| 172 | - lcrv["tbinfile"] = "lightcurve_py2.dat" | |
| 173 | - lcrv["enumbins"] = 0 | |
| 174 | - lcrv["emin"] = 0.1 | |
| 175 | - lcrv["emax"] = 100.0 | |
| 176 | - lcrv["outfile"] = "lightcurve_py2.fits" | |
| 177 | - lcrv["logfile"] = "cslightcrv_py2.log" | |
| 178 | - lcrv["chatter"] = 3 | |
| 166 | + lcrv['inobs'] = self._events_name | |
| 167 | + lcrv['inmodel'] = self._model_name | |
| 168 | + lcrv['srcname'] = 'Crab' | |
| 169 | + lcrv['caldb'] = 'prod2' | |
| 170 | + lcrv['irf'] = 'South_0.5h' | |
| 171 | + lcrv['tbinalg'] = 'FILE' | |
| 172 | + lcrv['tbinfile'] = 'cslightcrv_py2.dat' | |
| 173 | + lcrv['enumbins'] = 0 | |
| 174 | + lcrv['emin'] = 0.1 | |
| 175 | + lcrv['emax'] = 100.0 | |
| 176 | + lcrv['fix_bkg'] = True | |
| 177 | + lcrv['outfile'] = 'cslightcrv_py2.fits' | |
| 178 | + lcrv['logfile'] = 'cslightcrv_py2.log' | |
| 179 | + lcrv['chatter'] = 3 | |
| 179 | 180 | |
| 180 | 181 | # Execute cslightcrv script |
| 181 | 182 | lcrv.execute() |
| 182 | 183 | |
| 183 | 184 | # Check light curve |
| 184 | - self._check_light_curve("lightcurve_py2.fits", 2) | |
| 185 | + self._check_light_curve('cslightcrv_py2.fits', 2) | |
| 185 | 186 | |
| 186 | 187 | # Now we setup an observation container on input. We attached the |
| 187 | 188 | # model to the observation container so that cslightcrv should |
| ... | ... | @@ -194,53 +195,53 @@ class Test(gammalib.GPythonTestSuite): |
| 194 | 195 | # Set-up unbinned cslightcrv from observation container. Now use |
| 195 | 196 | # the GTI algorithm so that we test all timing algorithms. |
| 196 | 197 | lcrv = cscripts.cslightcrv(obs) |
| 197 | - lcrv["srcname"] = "Crab" | |
| 198 | - lcrv["caldb"] = "prod2" | |
| 199 | - lcrv["irf"] = "South_0.5h" | |
| 200 | - lcrv["tbinalg"] = "GTI" | |
| 201 | - lcrv["enumbins"] = 0 | |
| 202 | - lcrv["emin"] = 0.1 | |
| 203 | - lcrv["emax"] = 100.0 | |
| 204 | - lcrv["outfile"] = "lightcurve_py3.fits" | |
| 205 | - lcrv["logfile"] = "cslightcrv_py3.log" | |
| 206 | - lcrv["chatter"] = 4 | |
| 198 | + lcrv['srcname'] = 'Crab' | |
| 199 | + lcrv['caldb'] = 'prod2' | |
| 200 | + lcrv['irf'] = 'South_0.5h' | |
| 201 | + lcrv['tbinalg'] = 'GTI' | |
| 202 | + lcrv['enumbins'] = 0 | |
| 203 | + lcrv['emin'] = 0.1 | |
| 204 | + lcrv['emax'] = 100.0 | |
| 205 | + lcrv['outfile'] = 'cslightcrv_py3.fits' | |
| 206 | + lcrv['logfile'] = 'cslightcrv_py3.log' | |
| 207 | + lcrv['chatter'] = 4 | |
| 207 | 208 | |
| 208 | 209 | # Execute cslightcrv script |
| 209 | 210 | lcrv.execute() |
| 210 | 211 | |
| 211 | 212 | # Check light curve |
| 212 | - self._check_light_curve("lightcurve_py3.fits", 1) | |
| 213 | + self._check_light_curve('cslightcrv_py3.fits', 1) | |
| 213 | 214 | |
| 214 | 215 | # Finally we set-up a binned cslightcrv |
| 215 | 216 | lcrv = cscripts.cslightcrv() |
| 216 | - lcrv["inobs"] = self._events_name | |
| 217 | - lcrv["inmodel"] = self._model_name | |
| 218 | - lcrv["srcname"] = "Crab" | |
| 219 | - lcrv["caldb"] = "prod2" | |
| 220 | - lcrv["irf"] = "South_0.5h" | |
| 221 | - lcrv["tbinalg"] = "LIN" | |
| 222 | - lcrv["tmin"] = 51544.50 | |
| 223 | - lcrv["tmax"] = 51544.53 | |
| 224 | - lcrv["tbins"] = 2 | |
| 225 | - lcrv["emin"] = 0.1 | |
| 226 | - lcrv["emax"] = 100.0 | |
| 227 | - lcrv["enumbins"] = 10 | |
| 228 | - lcrv["coordsys"] = "CEL" | |
| 229 | - lcrv["proj"] = "TAN" | |
| 230 | - lcrv["xref"] = 83.63 | |
| 231 | - lcrv["yref"] = 22.01 | |
| 232 | - lcrv["nxpix"] = 20 | |
| 233 | - lcrv["nypix"] = 20 | |
| 234 | - lcrv["binsz"] = 0.02 | |
| 235 | - lcrv["outfile"] = "lightcurve_py4.fits" | |
| 236 | - lcrv["logfile"] = "cslightcrv_py4.log" | |
| 237 | - lcrv["chatter"] = 4 | |
| 217 | + lcrv['inobs'] = self._events_name | |
| 218 | + lcrv['inmodel'] = self._model_name | |
| 219 | + lcrv['srcname'] = 'Crab' | |
| 220 | + lcrv['caldb'] = 'prod2' | |
| 221 | + lcrv['irf'] = 'South_0.5h' | |
| 222 | + lcrv['tbinalg'] = 'LIN' | |
| 223 | + lcrv['tmin'] = 51544.50 | |
| 224 | + lcrv['tmax'] = 51544.53 | |
| 225 | + lcrv['tbins'] = 2 | |
| 226 | + lcrv['emin'] = 0.1 | |
| 227 | + lcrv['emax'] = 100.0 | |
| 228 | + lcrv['enumbins'] = 10 | |
| 229 | + lcrv['coordsys'] = 'CEL' | |
| 230 | + lcrv['proj'] = 'TAN' | |
| 231 | + lcrv['xref'] = 83.63 | |
| 232 | + lcrv['yref'] = 22.01 | |
| 233 | + lcrv['nxpix'] = 20 | |
| 234 | + lcrv['nypix'] = 20 | |
| 235 | + lcrv['binsz'] = 0.02 | |
| 236 | + lcrv['outfile'] = 'cslightcrv_py4.fits' | |
| 237 | + lcrv['logfile'] = 'cslightcrv_py4.log' | |
| 238 | + lcrv['chatter'] = 4 | |
| 238 | 239 | |
| 239 | 240 | # Execute cslightcrv script |
| 240 | 241 | lcrv.execute() |
| 241 | 242 | |
| 242 | 243 | # Check light curve |
| 243 | - self._check_light_curve("lightcurve_py4.fits", 2) | |
| 244 | + self._check_light_curve('cslightcrv_py4.fits', 2) | |
| 244 | 245 | |
| 245 | 246 | # Return |
| 246 | 247 | return |
| ... | ... | @@ -251,8 +252,8 @@ class Test(gammalib.GPythonTestSuite): |
| 251 | 252 | Check light curve file. |
| 252 | 253 | """ |
| 253 | 254 | # Expected column names |
| 254 | - cols = ["MJD", "e_MJD", "Prefactor", "e_Prefactor", | |
| 255 | - "Index", "e_Index", "TS", "UpperLimit"] | |
| 255 | + cols = ['MJD', 'e_MJD', 'Prefactor', 'e_Prefactor', | |
| 256 | + 'Index', 'e_Index', 'TS', 'UpperLimit'] | |
| 256 | 257 | |
| 257 | 258 | # Open FITS file |
| 258 | 259 | fits = gammalib.GFits(filename) |
| ... | ... | @@ -260,11 +261,11 @@ class Test(gammalib.GPythonTestSuite): |
| 260 | 261 | # Check FITS file structure |
| 261 | 262 | self.test_value(fits.size(), 2, |
| 262 | 263 | 'Check for 2 extensions in light curve FITS file') |
| 263 | - self.test_assert(fits.contains("LIGHTCURVE"), | |
| 264 | + self.test_assert(fits.contains('LIGHTCURVE'), | |
| 264 | 265 | 'FITS file contains "LIGHTCURVE" extension') |
| 265 | 266 | |
| 266 | 267 | # Get LIGHTCURVE table |
| 267 | - table = fits["LIGHTCURVE"] | |
| 268 | + table = fits['LIGHTCURVE'] | |
| 268 | 269 | |
| 269 | 270 | # Check FITS table structure |
| 270 | 271 | self.test_value(table.ncols(), len(cols), | ... | ... |
test/test_csresmap.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the csresmap script. | |
| 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 gammalib | |
| 23 | +import cscripts | |
| 24 | + | |
| 25 | + | |
| 26 | +# ============================== # | |
| 27 | +# Test class for csresmap script # | |
| 28 | +# ============================== # | |
| 29 | +class Test(gammalib.GPythonTestSuite): | |
| 30 | + """ | |
| 31 | + Test class for csresmap script. | |
| 32 | + | |
| 33 | + This test class makes unit tests for the csresmap script by using it | |
| 34 | + from the command line and from Python. | |
| 35 | + """ | |
| 36 | + | |
| 37 | + # Constructor | |
| 38 | + def __init__(self): | |
| 39 | + """ | |
| 40 | + Constructor. | |
| 41 | + """ | |
| 42 | + # Call base class constructor | |
| 43 | + gammalib.GPythonTestSuite.__init__(self) | |
| 44 | + | |
| 45 | + # Return | |
| 46 | + return | |
| 47 | + | |
| 48 | + # Set test functions | |
| 49 | + def set(self): | |
| 50 | + """ | |
| 51 | + Set all test functions. | |
| 52 | + """ | |
| 53 | + # Set test name | |
| 54 | + self.name('csresmap') | |
| 55 | + | |
| 56 | + # Append tests | |
| 57 | + self.append(self._test_cmd, 'Test csresmap on command line') | |
| 58 | + self.append(self._test_python, 'Test csresmap from Python') | |
| 59 | + | |
| 60 | + # Return | |
| 61 | + return | |
| 62 | + | |
| 63 | + # Test csresmap on command line | |
| 64 | + def _test_cmd(self): | |
| 65 | + """ | |
| 66 | + Test csresmap on the command line. | |
| 67 | + """ | |
| 68 | + # Kluge to set the command (installed version has no README file) | |
| 69 | + if os.path.isfile('README'): | |
| 70 | + csresmap = '../cscripts/csresmap.py' | |
| 71 | + else: | |
| 72 | + csresmap = 'csresmap' | |
| 73 | + | |
| 74 | + # Setup csresmap command | |
| 75 | + cmd = csresmap+' inobs="data/crab_events.fits"'+ \ | |
| 76 | + ' outmap="csresmap_cmd1.fits"'+ \ | |
| 77 | + ' inmodel="data/crab.xml"'+ \ | |
| 78 | + ' caldb="prod2" irf="South_0.5h"' + \ | |
| 79 | + ' emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 80 | + ' nxpix=50 nypix=50 binsz=0.02'+ \ | |
| 81 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 82 | + ' algorithm="SUBDIV"'+ \ | |
| 83 | + ' logfile="csresmap_cmd1.log" chatter=1' | |
| 84 | + | |
| 85 | + # Execute csresmap, make sure we catch any exception | |
| 86 | + try: | |
| 87 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 88 | + except: | |
| 89 | + pass | |
| 90 | + | |
| 91 | + # Check if execution was successful | |
| 92 | + self.test_assert(rc == 0, | |
| 93 | + 'Successful csresmap execution on command line') | |
| 94 | + | |
| 95 | + # Check result file | |
| 96 | + self._check_result_file('csresmap_cmd1.fits') | |
| 97 | + | |
| 98 | + # Setup csresmap command | |
| 99 | + cmd = csresmap+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 100 | + ' outmap="csresmap_cmd1.fits"'+ \ | |
| 101 | + ' inmodel="data/crab.xml"'+ \ | |
| 102 | + ' caldb="prod2" irf="South_0.5h"' + \ | |
| 103 | + ' emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 104 | + ' nxpix=50 nypix=50 binsz=0.02'+ \ | |
| 105 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 106 | + ' algorithm="SUBDIV"'+ \ | |
| 107 | + ' logfile="csresmap_cmd2.log" chatter=2' | |
| 108 | + | |
| 109 | + # Execute csresmap, make sure we catch any exception | |
| 110 | + try: | |
| 111 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 112 | + except: | |
| 113 | + pass | |
| 114 | + | |
| 115 | + # Check if execution failed | |
| 116 | + self.test_assert(rc != 0, | |
| 117 | + 'Failure of csresmap execution on command line') | |
| 118 | + | |
| 119 | + # Return | |
| 120 | + return | |
| 121 | + | |
| 122 | + # Test csresmap from Python | |
| 123 | + def _test_python(self): | |
| 124 | + """ | |
| 125 | + Test csresmap from Python. | |
| 126 | + """ | |
| 127 | + # Set-up csresmap for event list | |
| 128 | + resmap = cscripts.csresmap() | |
| 129 | + resmap['inobs'] = 'data/crab_events.fits' | |
| 130 | + resmap['outmap'] = 'csresmap_py1.fits' | |
| 131 | + resmap['inmodel'] = 'data/crab.xml' | |
| 132 | + resmap['caldb'] = 'prod2' | |
| 133 | + resmap['irf'] = 'South_0.5h' | |
| 134 | + resmap['emin'] = 0.1 | |
| 135 | + resmap['emax'] = 100.0 | |
| 136 | + resmap['enumbins'] = 20 | |
| 137 | + resmap['nxpix'] = 50 | |
| 138 | + resmap['nypix'] = 50 | |
| 139 | + resmap['binsz'] = 0.02 | |
| 140 | + resmap['coordsys'] = 'CEL' | |
| 141 | + resmap['proj'] = 'CAR' | |
| 142 | + resmap['xref'] = 83.63 | |
| 143 | + resmap['yref'] = 22.01 | |
| 144 | + resmap['algorithm'] = 'SUBDIV' | |
| 145 | + resmap['logfile'] = 'csresmap_py1.log' | |
| 146 | + resmap['chatter'] = 2 | |
| 147 | + | |
| 148 | + # Run csresmap script | |
| 149 | + resmap.logFileOpen() # Make sure we get a log file | |
| 150 | + resmap.run() | |
| 151 | + resmap.save() | |
| 152 | + | |
| 153 | + # Check pull distribution file | |
| 154 | + self._check_result_file('csresmap_py1.fits') | |
| 155 | + | |
| 156 | + # Set-up csresmap for counts cube | |
| 157 | + resmap = cscripts.csresmap() | |
| 158 | + resmap['inobs'] = 'data/crab_cntmap.fits' | |
| 159 | + resmap['modcube'] = 'NONE' | |
| 160 | + resmap['expcube'] = 'NONE' | |
| 161 | + resmap['psfcube'] = 'NONE' | |
| 162 | + resmap['edispcube'] = 'NONE' | |
| 163 | + resmap['bkgcube'] = 'NONE' | |
| 164 | + resmap['caldb'] = 'prod2' | |
| 165 | + resmap['irf'] = 'South_0.5h' | |
| 166 | + resmap['inmodel'] = 'data/crab.xml' | |
| 167 | + resmap['outmap'] = 'csresmap_py2.fits' | |
| 168 | + resmap['algorithm'] = 'SUBDIV' | |
| 169 | + resmap['logfile'] = 'csresmap_py2.log' | |
| 170 | + resmap['chatter'] = 3 | |
| 171 | + | |
| 172 | + # Run csresmap script | |
| 173 | + resmap.execute() | |
| 174 | + | |
| 175 | + # Check pull distribution file | |
| 176 | + self._check_result_file('csresmap_py2.fits', nx=200, ny=200) | |
| 177 | + | |
| 178 | + # Return | |
| 179 | + return | |
| 180 | + | |
| 181 | + # Check result file | |
| 182 | + def _check_result_file(self, filename, nx=50, ny=50): | |
| 183 | + """ | |
| 184 | + Check result file. | |
| 185 | + """ | |
| 186 | + # Load residual map | |
| 187 | + residual = gammalib.GSkyMap(filename) | |
| 188 | + | |
| 189 | + # Check residual map | |
| 190 | + self.test_value(residual.nmaps(), 1, 'One map') | |
| 191 | + self.test_value(residual.nx(), nx, '%d pixels in X' % nx) | |
| 192 | + self.test_value(residual.ny(), ny, '%d pixels in Y' % ny) | |
| 193 | + | |
| 194 | + # Return | |
| 195 | + return | ... | ... |
test/test_cssens.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the cssens script. | |
| 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 gammalib | |
| 23 | +import cscripts | |
| 24 | + | |
| 25 | + | |
| 26 | +# ============================ # | |
| 27 | +# Test class for cssens script # | |
| 28 | +# ============================ # | |
| 29 | +class Test(gammalib.GPythonTestSuite): | |
| 30 | + """ | |
| 31 | + Test class for cssens script. | |
| 32 | + | |
| 33 | + This test class makes unit tests for the cssens script by using it | |
| 34 | + from the command line and from Python. | |
| 35 | + """ | |
| 36 | + | |
| 37 | + # Constructor | |
| 38 | + def __init__(self): | |
| 39 | + """ | |
| 40 | + Constructor. | |
| 41 | + """ | |
| 42 | + # Call base class constructor | |
| 43 | + gammalib.GPythonTestSuite.__init__(self) | |
| 44 | + | |
| 45 | + # Return | |
| 46 | + return | |
| 47 | + | |
| 48 | + # Set test functions | |
| 49 | + def set(self): | |
| 50 | + """ | |
| 51 | + Set all test functions. | |
| 52 | + """ | |
| 53 | + # Set test name | |
| 54 | + self.name('cssens') | |
| 55 | + | |
| 56 | + # Append tests | |
| 57 | + self.append(self._test_cmd, 'Test cssens on command line') | |
| 58 | + self.append(self._test_python, 'Test cssens from Python') | |
| 59 | + | |
| 60 | + # Return | |
| 61 | + return | |
| 62 | + | |
| 63 | + # Test cssens on command line | |
| 64 | + def _test_cmd(self): | |
| 65 | + """ | |
| 66 | + Test cssens on the command line. | |
| 67 | + """ | |
| 68 | + # Kluge to set the command (installed version has no README file) | |
| 69 | + if os.path.isfile('README'): | |
| 70 | + cssens = '../cscripts/cssens.py' | |
| 71 | + else: | |
| 72 | + cssens = 'cssens' | |
| 73 | + | |
| 74 | + # Setup cssens command | |
| 75 | + cmd = cssens+' inmodel="data/crab.xml"'+ \ | |
| 76 | + ' srcname="Crab" caldb="prod2" irf="South_0.5h"' + \ | |
| 77 | + ' duration=1800.0 rad=3.0 emin=1.0 emax=10.0 bins=1'+ \ | |
| 78 | + ' outfile="cssens_cmd1.dat"'+ \ | |
| 79 | + ' logfile="cssens_cmd1.log" chatter=1' | |
| 80 | + | |
| 81 | + # Execute cssens, make sure we catch any exception | |
| 82 | + try: | |
| 83 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 84 | + except: | |
| 85 | + pass | |
| 86 | + | |
| 87 | + # Check if execution was successful | |
| 88 | + self.test_assert(rc == 0, | |
| 89 | + 'Successful cssens execution on command line') | |
| 90 | + | |
| 91 | + # Check result file | |
| 92 | + self._check_result_file('cssens_cmd1.dat') | |
| 93 | + | |
| 94 | + # Setup cssens command | |
| 95 | + cmd = cssens+' inmodel="model_that_does_not_exist.xml"'+ \ | |
| 96 | + ' srcname="Crab" caldb="prod2" irf="South_0.5h"' + \ | |
| 97 | + ' duration=1800.0 rad=3.0 emin=1.0 emax=10.0 bins=1'+ \ | |
| 98 | + ' outfile="cssens_cmd2.dat"'+ \ | |
| 99 | + ' logfile="cssens_cmd2.log" chatter=2' | |
| 100 | + | |
| 101 | + # Execute cssens, make sure we catch any exception | |
| 102 | + try: | |
| 103 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 104 | + except: | |
| 105 | + pass | |
| 106 | + | |
| 107 | + # Check if execution failed | |
| 108 | + self.test_assert(rc != 0, | |
| 109 | + 'Failure of cssens execution on command line') | |
| 110 | + | |
| 111 | + # Return | |
| 112 | + return | |
| 113 | + | |
| 114 | + # Test cssens from Python | |
| 115 | + def _test_python(self): | |
| 116 | + """ | |
| 117 | + Test cssens from Python. | |
| 118 | + """ | |
| 119 | + # Set-up cssens | |
| 120 | + sens = cscripts.cssens() | |
| 121 | + sens['inobs'] = 'NONE' | |
| 122 | + sens['inmodel'] = 'data/crab.xml' | |
| 123 | + sens['srcname'] = 'Crab' | |
| 124 | + sens['caldb'] = 'prod2' | |
| 125 | + sens['irf'] = 'South_0.5h' | |
| 126 | + sens['outfile'] = 'cssens_py1.dat' | |
| 127 | + sens['duration'] = 1800.0 | |
| 128 | + sens['rad'] = 3.0 | |
| 129 | + sens['emin'] = 1.0 | |
| 130 | + sens['emax'] = 10.0 | |
| 131 | + sens['bins'] = 1 | |
| 132 | + sens['logfile'] = 'cssens_py1.log' | |
| 133 | + sens['chatter'] = 2 | |
| 134 | + | |
| 135 | + # Run cssens script | |
| 136 | + sens.logFileOpen() # Make sure we get a log file | |
| 137 | + sens.run() | |
| 138 | + sens.save() | |
| 139 | + | |
| 140 | + # Check pull distribution file | |
| 141 | + self._check_result_file('cssens_py1.dat') | |
| 142 | + | |
| 143 | + # Return | |
| 144 | + return | |
| 145 | + | |
| 146 | + # Check result file | |
| 147 | + def _check_result_file(self, filename): | |
| 148 | + """ | |
| 149 | + Check result file. | |
| 150 | + """ | |
| 151 | + # Open result file as CSV file | |
| 152 | + results = gammalib.GCsv(filename, ',') | |
| 153 | + | |
| 154 | + # Check dimensions | |
| 155 | + self.test_value(results.nrows(), 2, 'Check for 2 rows in sensitivity file') | |
| 156 | + self.test_value(results.ncols(), 7, 'Check for 7 columns in sensitivity file') | |
| 157 | + | |
| 158 | + # Return | |
| 159 | + return | ... | ... |
test/test_csspec.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the csspec script. | |
| 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 gammalib | |
| 23 | +import cscripts | |
| 24 | + | |
| 25 | + | |
| 26 | +# ============================ # | |
| 27 | +# Test class for csspec script # | |
| 28 | +# ============================ # | |
| 29 | +class Test(gammalib.GPythonTestSuite): | |
| 30 | + """ | |
| 31 | + Test class for csspec script. | |
| 32 | + | |
| 33 | + This test class makes unit tests for the csspec script by using it | |
| 34 | + from the command line and from Python. | |
| 35 | + """ | |
| 36 | + | |
| 37 | + # Constructor | |
| 38 | + def __init__(self): | |
| 39 | + """ | |
| 40 | + Constructor. | |
| 41 | + """ | |
| 42 | + # Call base class constructor | |
| 43 | + gammalib.GPythonTestSuite.__init__(self) | |
| 44 | + | |
| 45 | + # Return | |
| 46 | + return | |
| 47 | + | |
| 48 | + # Set test functions | |
| 49 | + def set(self): | |
| 50 | + """ | |
| 51 | + Set all test functions. | |
| 52 | + """ | |
| 53 | + # Set test name | |
| 54 | + self.name('csspec') | |
| 55 | + | |
| 56 | + # Append tests | |
| 57 | + self.append(self._test_cmd, 'Test csspec on command line') | |
| 58 | + self.append(self._test_python, 'Test csspec from Python') | |
| 59 | + | |
| 60 | + # Return | |
| 61 | + return | |
| 62 | + | |
| 63 | + # Test csspec on command line | |
| 64 | + def _test_cmd(self): | |
| 65 | + """ | |
| 66 | + Test csspec on the command line. | |
| 67 | + """ | |
| 68 | + # Kluge to set the command (installed version has no README file) | |
| 69 | + if os.path.isfile('README'): | |
| 70 | + csspec = '../cscripts/csspec.py' | |
| 71 | + else: | |
| 72 | + csspec = 'csspec' | |
| 73 | + | |
| 74 | + # Setup csspec command | |
| 75 | + cmd = csspec+' inobs="data/crab_events.fits"'+ \ | |
| 76 | + ' inmodel="data/crab.xml"'+ \ | |
| 77 | + ' srcname="Crab" caldb="prod2" irf="South_0.5h"' + \ | |
| 78 | + ' ebinalg="LOG" enumbins=5 emin=0.1 emax=100.0'+ \ | |
| 79 | + ' outfile="csspec_cmd1.fits"'+ \ | |
| 80 | + ' logfile="csspec_cmd1.log" chatter=1' | |
| 81 | + | |
| 82 | + # Execute csspec, make sure we catch any exception | |
| 83 | + try: | |
| 84 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 85 | + except: | |
| 86 | + pass | |
| 87 | + | |
| 88 | + # Check if execution was successful | |
| 89 | + self.test_assert(rc == 0, | |
| 90 | + 'Successful csspec execution on command line') | |
| 91 | + | |
| 92 | + # Check result file | |
| 93 | + self._check_result_file('csspec_cmd1.fits', 5) | |
| 94 | + | |
| 95 | + # Setup csspec command | |
| 96 | + cmd = csspec+' inobs="input_file_that_does_not_exist.fits"'+ \ | |
| 97 | + ' inmodel="data/crab.xml"'+ \ | |
| 98 | + ' srcname="Crab" caldb="prod2" irf="South_0.5h"' + \ | |
| 99 | + ' ebinalg="LOG" enumbins=5 emin=0.1 emax=100.0'+ \ | |
| 100 | + ' outfile="csspec_cmd2.fits"'+ \ | |
| 101 | + ' logfile="csspec_cmd2.log" chatter=1' | |
| 102 | + | |
| 103 | + # Execute csspec, make sure we catch any exception | |
| 104 | + try: | |
| 105 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 106 | + except: | |
| 107 | + pass | |
| 108 | + | |
| 109 | + # Check if execution failed | |
| 110 | + self.test_assert(rc != 0, | |
| 111 | + 'Failure of csspec execution on command line') | |
| 112 | + | |
| 113 | + # Return | |
| 114 | + return | |
| 115 | + | |
| 116 | + # Test csspec from Python | |
| 117 | + def _test_python(self): | |
| 118 | + """ | |
| 119 | + Test csspec from Python. | |
| 120 | + """ | |
| 121 | + # Set-up unbinned csspec | |
| 122 | + spec = cscripts.csspec() | |
| 123 | + spec['inobs'] = 'data/crab_events.fits' | |
| 124 | + spec['inmodel'] = 'data/crab.xml' | |
| 125 | + spec['srcname'] = 'Crab' | |
| 126 | + spec['caldb'] = 'prod2' | |
| 127 | + spec['irf'] = 'South_0.5h' | |
| 128 | + spec['outfile'] = 'csspec_py1.fits' | |
| 129 | + spec['ebinalg'] = 'LOG' | |
| 130 | + spec['enumbins'] = 5 | |
| 131 | + spec['emin'] = 0.1 | |
| 132 | + spec['emax'] = 100.0 | |
| 133 | + spec['logfile'] = 'csspec_py1.log' | |
| 134 | + spec['chatter'] = 2 | |
| 135 | + | |
| 136 | + # Run csspec script | |
| 137 | + spec.logFileOpen() # Make sure we get a log file | |
| 138 | + spec.run() | |
| 139 | + spec.save() | |
| 140 | + | |
| 141 | + # Check pull distribution file | |
| 142 | + self._check_result_file('csspec_py1.fits', 5) | |
| 143 | + | |
| 144 | + # Set-up binned csspec | |
| 145 | + spec = cscripts.csspec() | |
| 146 | + spec['inobs'] = 'data/crab_cntmap_small.fits' | |
| 147 | + spec['expcube'] = 'data/crab_expcube.fits' | |
| 148 | + spec['psfcube'] = 'data/crab_psfcube.fits' | |
| 149 | + spec['edispcube'] = 'data/crab_edispcube.fits' | |
| 150 | + spec['bkgcube'] = 'data/crab_bkgcube.fits' | |
| 151 | + spec['inmodel'] = 'data/crab.xml' | |
| 152 | + spec['srcname'] = 'Crab' | |
| 153 | + spec['outfile'] = 'csspec_py2.fits' | |
| 154 | + spec['ebinalg'] = 'LOG' | |
| 155 | + spec['enumbins'] = 2 | |
| 156 | + spec['emin'] = 0.1 | |
| 157 | + spec['emax'] = 100.0 | |
| 158 | + spec['logfile'] = 'csspec_py2.log' | |
| 159 | + spec['chatter'] = 3 | |
| 160 | + | |
| 161 | + # Execute csspec script | |
| 162 | + spec.execute() | |
| 163 | + | |
| 164 | + # Check pull distribution file | |
| 165 | + self._check_result_file('csspec_py2.fits', 2) | |
| 166 | + | |
| 167 | + # Return | |
| 168 | + return | |
| 169 | + | |
| 170 | + # Check result file | |
| 171 | + def _check_result_file(self, filename, bins): | |
| 172 | + """ | |
| 173 | + Check result file. | |
| 174 | + """ | |
| 175 | + # Open result file | |
| 176 | + fits = gammalib.GFits(filename) | |
| 177 | + | |
| 178 | + # Get spectrum table | |
| 179 | + spectrum = fits['SPECTRUM'] | |
| 180 | + | |
| 181 | + # Check dimensions | |
| 182 | + self.test_value(spectrum.nrows(), bins, 'Check for %d rows in spectrum' % bins) | |
| 183 | + self.test_value(spectrum.ncols(), 8, 'Check for 8 columns in spectrum') | |
| 184 | + | |
| 185 | + # Return | |
| 186 | + return | ... | ... |
test/test_cstsdist.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the cstsdist script. | |
| 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 gammalib | |
| 23 | +import cscripts | |
| 24 | + | |
| 25 | + | |
| 26 | +# ============================== # | |
| 27 | +# Test class for cstsdist script # | |
| 28 | +# ============================== # | |
| 29 | +class Test(gammalib.GPythonTestSuite): | |
| 30 | + """ | |
| 31 | + Test class for cstsdist script. | |
| 32 | + | |
| 33 | + This test class makes unit tests for the cstsdist script by using it | |
| 34 | + from the command line and from Python. | |
| 35 | + """ | |
| 36 | + | |
| 37 | + # Constructor | |
| 38 | + def __init__(self): | |
| 39 | + """ | |
| 40 | + Constructor. | |
| 41 | + """ | |
| 42 | + # Call base class constructor | |
| 43 | + gammalib.GPythonTestSuite.__init__(self) | |
| 44 | + | |
| 45 | + # Return | |
| 46 | + return | |
| 47 | + | |
| 48 | + # Set test functions | |
| 49 | + def set(self): | |
| 50 | + """ | |
| 51 | + Set all test functions. | |
| 52 | + """ | |
| 53 | + # Set test name | |
| 54 | + self.name('cstsdist') | |
| 55 | + | |
| 56 | + # Append tests | |
| 57 | + self.append(self._test_cmd, 'Test cstsdist on command line') | |
| 58 | + self.append(self._test_python, 'Test cstsdist from Python') | |
| 59 | + | |
| 60 | + # Return | |
| 61 | + return | |
| 62 | + | |
| 63 | + # Test cstsdist on command line | |
| 64 | + def _test_cmd(self): | |
| 65 | + """ | |
| 66 | + Test cstsdist on the command line. | |
| 67 | + """ | |
| 68 | + # Kluge to set the command (installed version has no README file) | |
| 69 | + if os.path.isfile('README'): | |
| 70 | + cstsdist = '../cscripts/cstsdist.py' | |
| 71 | + else: | |
| 72 | + cstsdist = 'cstsdist' | |
| 73 | + | |
| 74 | + # Setup cstsdist command | |
| 75 | + cmd = cstsdist+' inmodel="data/crab.xml"'+ \ | |
| 76 | + ' srcname="Crab" caldb="prod2" irf="South_0.5h"' + \ | |
| 77 | + ' ntrials=1 ra=83.63 dec=22.01 emin=0.1 emax=100.0'+ \ | |
| 78 | + ' enumbins=0 tmax=1800.0 rad=5.0 npix=200 npix=200'+ \ | |
| 79 | + ' binsz=0.05'+ \ | |
| 80 | + ' outfile="cstsdist_cmd1.dat"'+ \ | |
| 81 | + ' logfile="cstsdist_cmd1.log" chatter=1' | |
| 82 | + | |
| 83 | + # Execute cstsdist, make sure we catch any exception | |
| 84 | + try: | |
| 85 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 86 | + except: | |
| 87 | + pass | |
| 88 | + | |
| 89 | + # Check if execution was successful | |
| 90 | + self.test_assert(rc == 0, | |
| 91 | + 'Successful cstsdist execution on command line') | |
| 92 | + | |
| 93 | + # Check result file | |
| 94 | + self._check_result_file('cstsdist_cmd1.dat') | |
| 95 | + | |
| 96 | + # Setup cstsdist command | |
| 97 | + cmd = cstsdist+' inmodel="model_that_does_not_exist.xml"'+ \ | |
| 98 | + ' srcname="Crab" caldb="prod2" irf="South_0.5h"' + \ | |
| 99 | + ' ntrials=1 ra=83.63 dec=22.01 emin=0.1 emax=100.0'+ \ | |
| 100 | + ' enumbins=0 tmax=1800.0 rad=5.0 npix=200 npix=200'+ \ | |
| 101 | + ' binsz=0.05'+ \ | |
| 102 | + ' outfile="cstsdist_cmd2.dat"'+ \ | |
| 103 | + ' logfile="cstsdist_cmd2.log" chatter=2' | |
| 104 | + | |
| 105 | + # Execute cstsdist, make sure we catch any exception | |
| 106 | + try: | |
| 107 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 108 | + except: | |
| 109 | + pass | |
| 110 | + | |
| 111 | + # Check if execution failed | |
| 112 | + self.test_assert(rc != 0, | |
| 113 | + 'Failure of cstsdist execution on command line') | |
| 114 | + | |
| 115 | + # Return | |
| 116 | + return | |
| 117 | + | |
| 118 | + # Test cstsdist from Python | |
| 119 | + def _test_python(self): | |
| 120 | + """ | |
| 121 | + Test cstsdist from Python. | |
| 122 | + """ | |
| 123 | + # Set-up cstsdist | |
| 124 | + tsdist = cscripts.cstsdist() | |
| 125 | + tsdist['inmodel'] = 'data/crab.xml' | |
| 126 | + tsdist['srcname'] = 'Crab' | |
| 127 | + tsdist['caldb'] = 'prod2' | |
| 128 | + tsdist['irf'] = 'South_0.5h' | |
| 129 | + tsdist['outfile'] = 'cstsdist_py1.dat' | |
| 130 | + tsdist['ntrials'] = 1 | |
| 131 | + tsdist['ra'] = 83.63 | |
| 132 | + tsdist['dec'] = 22.01 | |
| 133 | + tsdist['emin'] = 0.1 | |
| 134 | + tsdist['emax'] = 100.0 | |
| 135 | + tsdist['enumbins'] = 0 | |
| 136 | + tsdist['tmax'] = 1800.0 | |
| 137 | + tsdist['rad'] = 5.0 | |
| 138 | + tsdist['npix'] = 200 | |
| 139 | + tsdist['binsz'] = 0.05 | |
| 140 | + tsdist['logfile'] = 'cstsdist_py1.log' | |
| 141 | + tsdist['chatter'] = 2 | |
| 142 | + | |
| 143 | + # Run cstsdist script | |
| 144 | + tsdist.logFileOpen() # Make sure we get a log file | |
| 145 | + tsdist.run() | |
| 146 | + tsdist.save() | |
| 147 | + | |
| 148 | + # Check pull distribution file | |
| 149 | + self._check_result_file('cstsdist_py1.dat') | |
| 150 | + | |
| 151 | + # Return | |
| 152 | + return | |
| 153 | + | |
| 154 | + # Check result file | |
| 155 | + def _check_result_file(self, filename): | |
| 156 | + """ | |
| 157 | + Check result file. | |
| 158 | + """ | |
| 159 | + # Open result file as CSV file | |
| 160 | + results = gammalib.GCsv(filename, ',') | |
| 161 | + | |
| 162 | + # Check dimensions | |
| 163 | + self.test_value(results.nrows(), 2, 'Check for 2 rows in TS file') | |
| 164 | + self.test_value(results.ncols(), 14, 'Check for 14 columns in TS file') | |
| 165 | + | |
| 166 | + # Return | |
| 167 | + return | ... | ... |
test/test_cstsmapmerge.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the cstsmapmerge script. | |
| 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 gammalib | |
| 23 | +import cscripts | |
| 24 | + | |
| 25 | + | |
| 26 | +# ================================== # | |
| 27 | +# Test class for cstsmapmerge script # | |
| 28 | +# ================================== # | |
| 29 | +class Test(gammalib.GPythonTestSuite): | |
| 30 | + """ | |
| 31 | + Test class for cstsmapmerge script. | |
| 32 | + | |
| 33 | + This test class makes unit tests for the cstsmapmerge script by using it | |
| 34 | + from the command line and from Python. | |
| 35 | + """ | |
| 36 | + | |
| 37 | + # Constructor | |
| 38 | + def __init__(self): | |
| 39 | + """ | |
| 40 | + Constructor. | |
| 41 | + """ | |
| 42 | + # Call base class constructor | |
| 43 | + gammalib.GPythonTestSuite.__init__(self) | |
| 44 | + | |
| 45 | + # Return | |
| 46 | + return | |
| 47 | + | |
| 48 | + # Set test functions | |
| 49 | + def set(self): | |
| 50 | + """ | |
| 51 | + Set all test functions. | |
| 52 | + """ | |
| 53 | + # Set test name | |
| 54 | + self.name('cstsmapmerge') | |
| 55 | + | |
| 56 | + # Append tests | |
| 57 | + self.append(self._test_cmd, 'Test cstsmapmerge on command line') | |
| 58 | + self.append(self._test_python, 'Test cstsmapmerge from Python') | |
| 59 | + | |
| 60 | + # Return | |
| 61 | + return | |
| 62 | + | |
| 63 | + # Test cstsmapmerge on command line | |
| 64 | + def _test_cmd(self): | |
| 65 | + """ | |
| 66 | + Test cstsmapmerge on the command line. | |
| 67 | + """ | |
| 68 | + # Kluge to set the command (installed version has no README file) | |
| 69 | + if os.path.isfile('README'): | |
| 70 | + cstsmapmerge = '../cscripts/cstsmapmerge.py' | |
| 71 | + else: | |
| 72 | + cstsmapmerge = 'cstsmapmerge' | |
| 73 | + | |
| 74 | + # Setup cstsmapmerge command | |
| 75 | + cmd = cstsmapmerge+' inmaps="data/tsmap_0.fits;data/tsmap_1.fits"'+ \ | |
| 76 | + ' outmap="cstsmapmerge_cmd1.fits"'+ \ | |
| 77 | + ' logfile="cstsmapmerge_cmd1.log" chatter=1' | |
| 78 | + | |
| 79 | + # Execute cstsmapmerge, make sure we catch any exception | |
| 80 | + try: | |
| 81 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 82 | + except: | |
| 83 | + pass | |
| 84 | + | |
| 85 | + # Check if execution was successful | |
| 86 | + self.test_assert(rc == 0, | |
| 87 | + 'Successful cstsmapmerge execution on command line') | |
| 88 | + | |
| 89 | + # Check result file | |
| 90 | + self._check_result_file('cstsmapmerge_cmd1.fits') | |
| 91 | + | |
| 92 | + # Setup cstsmapmerge command | |
| 93 | + cmd = cstsmapmerge+' inmaps="map_that_does_not_exist.fits"'+ \ | |
| 94 | + ' outmap="cstsmapmerge_cmd2.fits"'+ \ | |
| 95 | + ' logfile="cstsmapmerge_cmd2.log" chatter=2' | |
| 96 | + | |
| 97 | + # Execute cstsmapmerge, make sure we catch any exception | |
| 98 | + try: | |
| 99 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 100 | + except: | |
| 101 | + pass | |
| 102 | + | |
| 103 | + # Check if execution failed | |
| 104 | + self.test_assert(rc != 0, | |
| 105 | + 'Failure of cstsmapmerge execution on command line') | |
| 106 | + | |
| 107 | + # Return | |
| 108 | + return | |
| 109 | + | |
| 110 | + # Test cstsmapmerge from Python | |
| 111 | + def _test_python(self): | |
| 112 | + """ | |
| 113 | + Test cstsmapmerge from Python. | |
| 114 | + """ | |
| 115 | + # Set-up semi-colon separated cstsmapmerge | |
| 116 | + merge = cscripts.cstsmapmerge() | |
| 117 | + merge['inmaps'] = 'data/tsmap_0.fits;data/tsmap_1.fits' | |
| 118 | + merge['outmap'] = 'cstsmapmerge_py1.fits' | |
| 119 | + merge['logfile'] = 'cstsmapmerge_py1.log' | |
| 120 | + merge['chatter'] = 2 | |
| 121 | + | |
| 122 | + # Run cstsmapmerge script | |
| 123 | + merge.logFileOpen() # Make sure we get a log file | |
| 124 | + merge.run() | |
| 125 | + merge.save() | |
| 126 | + | |
| 127 | + # Check pull distribution file | |
| 128 | + self._check_result_file('cstsmapmerge_py1.fits') | |
| 129 | + | |
| 130 | + # Set-up space-separated cstsmapmerge | |
| 131 | + merge = cscripts.cstsmapmerge() | |
| 132 | + merge['inmaps'] = 'data/tsmap_0.fits data/tsmap_1.fits' | |
| 133 | + merge['outmap'] = 'cstsmapmerge_py2.fits' | |
| 134 | + merge['logfile'] = 'cstsmapmerge_py2.log' | |
| 135 | + merge['chatter'] = 3 | |
| 136 | + | |
| 137 | + # Run cstsmapmerge script | |
| 138 | + merge.execute() | |
| 139 | + | |
| 140 | + # Check pull distribution file | |
| 141 | + self._check_result_file('cstsmapmerge_py2.fits') | |
| 142 | + | |
| 143 | + # Set-up wildcard string cstsmapmerge | |
| 144 | + merge = cscripts.cstsmapmerge() | |
| 145 | + merge['inmaps'] = 'data/tsmap_*.fits' | |
| 146 | + merge['outmap'] = 'cstsmapmerge_py3.fits' | |
| 147 | + merge['logfile'] = 'cstsmapmerge_py3.log' | |
| 148 | + merge['chatter'] = 4 | |
| 149 | + | |
| 150 | + # Run cstsmapmerge script | |
| 151 | + merge.execute() | |
| 152 | + | |
| 153 | + # Check pull distribution file | |
| 154 | + self._check_result_file('cstsmapmerge_py3.fits') | |
| 155 | + | |
| 156 | + # Set-up ASCII file cstsmapmerge | |
| 157 | + merge = cscripts.cstsmapmerge() | |
| 158 | + merge['inmaps'] = '@data/tsmaps.txt' | |
| 159 | + merge['outmap'] = 'cstsmapmerge_py4.fits' | |
| 160 | + merge['logfile'] = 'cstsmapmerge_py4.log' | |
| 161 | + merge['chatter'] = 4 | |
| 162 | + | |
| 163 | + # Run cstsmapmerge script | |
| 164 | + merge.execute() | |
| 165 | + | |
| 166 | + # Check pull distribution file | |
| 167 | + self._check_result_file('cstsmapmerge_py4.fits') | |
| 168 | + | |
| 169 | + # Return | |
| 170 | + return | |
| 171 | + | |
| 172 | + # Check result file | |
| 173 | + def _check_result_file(self, filename): | |
| 174 | + """ | |
| 175 | + Check result file. | |
| 176 | + """ | |
| 177 | + # Open result file | |
| 178 | + fits = gammalib.GFits(filename) | |
| 179 | + | |
| 180 | + # Get HDUs | |
| 181 | + ts = fits['Primary'] | |
| 182 | + prefactor = fits['Prefactor'] | |
| 183 | + index = fits['Index'] | |
| 184 | + | |
| 185 | + # Check dimensions | |
| 186 | + self.test_value(ts.naxis(), 2, 'Check for 2 dimensions') | |
| 187 | + self.test_value(ts.naxes(0), 2, 'Check for 2 pixels in X') | |
| 188 | + self.test_value(ts.naxes(1), 1, 'Check for 1 pixel in Y') | |
| 189 | + self.test_value(prefactor.naxis(), 2, 'Check for 2 dimensions') | |
| 190 | + self.test_value(prefactor.naxes(0), 2, 'Check for 2 pixels in X') | |
| 191 | + self.test_value(prefactor.naxes(1), 1, 'Check for 1 pixel in Y') | |
| 192 | + self.test_value(index.naxis(), 2, 'Check for 2 dimensions') | |
| 193 | + self.test_value(index.naxes(0), 2, 'Check for 2 pixels in X') | |
| 194 | + self.test_value(index.naxes(1), 1, 'Check for 1 pixel in Y') | |
| 195 | + | |
| 196 | + # Return | |
| 197 | + return | ... | ... |
test/test_ctbkgcube.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,12 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.bkg_model = "data/crab.xml" | |
| 43 | - self.caldb = "irf" | |
| 44 | - self.irf = "cta_dummy_irf" | |
| 45 | - | |
| 46 | 41 | # Return |
| 47 | 42 | return |
| 48 | 43 | |
| ... | ... | @@ -52,61 +47,125 @@ class Test(gammalib.GPythonTestSuite): |
| 52 | 47 | Set all test functions. |
| 53 | 48 | """ |
| 54 | 49 | # Set test name |
| 55 | - self.name("ctbkgcube") | |
| 50 | + self.name('ctbkgcube') | |
| 56 | 51 | |
| 57 | 52 | # Append tests |
| 58 | - self.append(self.test_functional, "Test ctbkgcube functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctbkgcube on command line') | |
| 54 | + self.append(self._test_python, 'Test ctbkgcube from Python') | |
| 59 | 55 | |
| 60 | 56 | # Return |
| 61 | 57 | return |
| 62 | 58 | |
| 63 | - # Test ctbkgcube functionnality | |
| 64 | - def test_functional(self): | |
| 59 | + # Test ctbkgcube on command line | |
| 60 | + def _test_cmd(self): | |
| 65 | 61 | """ |
| 66 | - Test ctbkgcube functionnality. | |
| 62 | + Test ctbkgcube on the command line. | |
| 67 | 63 | """ |
| 68 | - # Set-up ctbkgcube | |
| 69 | - bkgcube = ctools.ctbkgcube() | |
| 70 | - bkgcube["inobs"] = self.events_name | |
| 71 | - bkgcube["inmodel"] = self.bkg_model | |
| 72 | - bkgcube["incube"] = "NONE" | |
| 73 | - bkgcube["outcube"] = "bkgcube.fits" | |
| 74 | - bkgcube["outmodel"] = "bkgcube.xml" | |
| 75 | - bkgcube["caldb"] = self.caldb | |
| 76 | - bkgcube["irf"] = self.irf | |
| 77 | - bkgcube["ebinalg"] = "LOG" | |
| 78 | - bkgcube["emin"] = 0.1 | |
| 79 | - bkgcube["emax"] = 100 | |
| 80 | - bkgcube["enumbins"] = 20 | |
| 81 | - bkgcube["nxpix"] = 10 | |
| 82 | - bkgcube["nypix"] = 10 | |
| 83 | - bkgcube["binsz"] = 0.4 | |
| 84 | - bkgcube["coordsys"] = "CEL" | |
| 85 | - bkgcube["proj"] = "CAR" | |
| 86 | - bkgcube["xref"] = 83.63 | |
| 87 | - bkgcube["yref"] = 22.01 | |
| 88 | - | |
| 89 | - # Run tool | |
| 90 | - self.test_try("Run ctbkgcube") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctbkgcube = '../src/ctbkgcube/ctbkgcube' | |
| 67 | + else: | |
| 68 | + ctbkgcube = 'ctbkgcube' | |
| 69 | + | |
| 70 | + # Setup ctbkgcube command | |
| 71 | + cmd = ctbkgcube+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' inmodel="data/crab.xml"'+ \ | |
| 73 | + ' incube="NONE"'+ \ | |
| 74 | + ' outcube="ctbkgcube_cmd1.fits"'+ \ | |
| 75 | + ' outmodel="ctbkgcube_cmd1.xml"'+ \ | |
| 76 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 77 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 78 | + ' nxpix=10 nypix=10 binsz=0.4'+ \ | |
| 79 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 80 | + ' logfile="ctbkgcube_cmd1.log" chatter=1' | |
| 81 | + | |
| 82 | + # Execute ctbkgcube, make sure we catch any exception | |
| 91 | 83 | try: |
| 92 | - bkgcube.run() | |
| 93 | - self.test_try_success() | |
| 94 | - #except Exception as e: | |
| 95 | - # msg = "Exception occured in ctbkgcube: %s." % (e,) | |
| 84 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 96 | 85 | except: |
| 97 | - msg = "Exception occured in ctbkgcube." | |
| 98 | - self.test_try_failure(msg) | |
| 86 | + pass | |
| 87 | + | |
| 88 | + # Check if execution was successful | |
| 89 | + self.test_assert(rc == 0, | |
| 90 | + 'Successful ctbkgcube execution on command line') | |
| 91 | + | |
| 92 | + # Check result file | |
| 93 | + self._check_result_file('ctbkgcube_cmd1.fits') | |
| 99 | 94 | |
| 100 | - # Save background cube | |
| 101 | - self.test_try("Save background cube") | |
| 95 | + # Setup ctbkgcube command | |
| 96 | + cmd = ctbkgcube+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 97 | + ' inmodel="data/crab.xml"'+ \ | |
| 98 | + ' incube="NONE"'+ \ | |
| 99 | + ' outcube="ctbkgcube_cmd2.fits"'+ \ | |
| 100 | + ' outmodel="ctbkgcube_cmd2.xml"'+ \ | |
| 101 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 102 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 103 | + ' nxpix=10 nypix=10 binsz=0.4'+ \ | |
| 104 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 105 | + ' logfile="ctbkgcube_cmd2.log" chatter=1' | |
| 106 | + | |
| 107 | + # Execute ctbkgcube, make sure we catch any exception | |
| 102 | 108 | try: |
| 103 | - bkgcube.save() | |
| 104 | - self.test_try_success() | |
| 105 | - #except Exception as e: | |
| 106 | - # msg = "Exception occured in saving background cube: %s." % (e,) | |
| 109 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 107 | 110 | except: |
| 108 | - msg = "Exception occured in saving background cube." | |
| 109 | - self.test_try_failure(msg) | |
| 111 | + pass | |
| 112 | + | |
| 113 | + # Check if execution failed | |
| 114 | + self.test_assert(rc != 0, | |
| 115 | + 'Failure of ctbkgcube execution on command line') | |
| 116 | + | |
| 117 | + # Return | |
| 118 | + return | |
| 119 | + | |
| 120 | + # Test ctbkgcube from Python | |
| 121 | + def _test_python(self): | |
| 122 | + """ | |
| 123 | + Test ctbkgcube from Python. | |
| 124 | + """ | |
| 125 | + # Set-up ctbkgcube | |
| 126 | + bkgcube = ctools.ctbkgcube() | |
| 127 | + bkgcube['inobs'] = 'data/crab_events.fits' | |
| 128 | + bkgcube['inmodel'] = 'data/crab.xml' | |
| 129 | + bkgcube['incube'] = 'NONE' | |
| 130 | + bkgcube['outcube'] = 'ctbkgcube_py1.fits' | |
| 131 | + bkgcube['outmodel'] = 'ctbkgcube_py1.xml' | |
| 132 | + bkgcube['caldb'] = 'prod2' | |
| 133 | + bkgcube['irf'] = 'South_0.5h' | |
| 134 | + bkgcube['ebinalg'] = 'LOG' | |
| 135 | + bkgcube['emin'] = 0.1 | |
| 136 | + bkgcube['emax'] = 100 | |
| 137 | + bkgcube['enumbins'] = 20 | |
| 138 | + bkgcube['nxpix'] = 10 | |
| 139 | + bkgcube['nypix'] = 10 | |
| 140 | + bkgcube['binsz'] = 0.4 | |
| 141 | + bkgcube['coordsys'] = 'CEL' | |
| 142 | + bkgcube['proj'] = 'CAR' | |
| 143 | + bkgcube['xref'] = 83.63 | |
| 144 | + bkgcube['yref'] = 22.01 | |
| 145 | + bkgcube['logfile'] = 'ctbkgcube_py1.log' | |
| 146 | + bkgcube['chatter'] = 2 | |
| 147 | + | |
| 148 | + # Run ctbkgcube tool | |
| 149 | + bkgcube.logFileOpen() # Make sure we get a log file | |
| 150 | + bkgcube.run() | |
| 151 | + bkgcube.save() | |
| 152 | + | |
| 153 | + # Check result file | |
| 154 | + self._check_result_file('ctbkgcube_py1.fits') | |
| 155 | + | |
| 156 | + # Return | |
| 157 | + return | |
| 158 | + | |
| 159 | + # Check result file | |
| 160 | + def _check_result_file(self, filename): | |
| 161 | + """ | |
| 162 | + Check result file. | |
| 163 | + """ | |
| 164 | + # Open result file | |
| 165 | + result = gammalib.GCTACubeBackground(filename) | |
| 166 | + | |
| 167 | + # Check dimensions | |
| 168 | + self.test_value(len(result.energies()), 21, 'Check for 21 energy values') | |
| 110 | 169 | |
| 111 | 170 | # Return |
| 112 | 171 | return | ... | ... |
test/test_ctbutterfly.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,12 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.model_name = "data/crab.xml" | |
| 43 | - self.caldb = "irf" | |
| 44 | - self.irf = "cta_dummy_irf" | |
| 45 | - | |
| 46 | 41 | # Return |
| 47 | 42 | return |
| 48 | 43 | |
| ... | ... | @@ -52,51 +47,108 @@ class Test(gammalib.GPythonTestSuite): |
| 52 | 47 | Set all test functions. |
| 53 | 48 | """ |
| 54 | 49 | # Set test name |
| 55 | - self.name("ctbutterfly") | |
| 50 | + self.name('ctbutterfly') | |
| 56 | 51 | |
| 57 | 52 | # Append tests |
| 58 | - self.append(self.test_functional, "Test ctbutterfly functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctbutterfly on command line') | |
| 54 | + self.append(self._test_python, 'Test ctbutterfly from Python') | |
| 59 | 55 | |
| 60 | 56 | # Return |
| 61 | 57 | return |
| 62 | 58 | |
| 63 | - # Test ctbutterfly functionnality | |
| 64 | - def test_functional(self): | |
| 59 | + # Test ctbutterfly on command line | |
| 60 | + def _test_cmd(self): | |
| 65 | 61 | """ |
| 66 | - Test ctbutterfly functionnality. | |
| 62 | + Test ctbutterfly on the command line. | |
| 67 | 63 | """ |
| 68 | - # Set-up ctbutterfly | |
| 69 | - butterfly = ctools.ctbutterfly() | |
| 70 | - butterfly["inobs"] = self.events_name | |
| 71 | - butterfly["inmodel"] = self.model_name | |
| 72 | - butterfly["srcname"] = "Crab" | |
| 73 | - butterfly["caldb"] = self.caldb | |
| 74 | - butterfly["irf"] = self.irf | |
| 75 | - butterfly["emin"] = 0.1 | |
| 76 | - butterfly["emax"] = 100 | |
| 77 | - butterfly["outfile"] = "butterfly.txt" | |
| 78 | - | |
| 79 | - # Run tool | |
| 80 | - self.test_try("Run ctbutterfly") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctbutterfly = '../src/ctbutterfly/ctbutterfly' | |
| 67 | + else: | |
| 68 | + ctbutterfly = 'ctbutterfly' | |
| 69 | + | |
| 70 | + # Setup ctbutterfly command | |
| 71 | + cmd = ctbutterfly+' inobs="data/crab_events.fits"'+\ | |
| 72 | + ' outfile="ctbutterfly_cmd1.txt"'+ \ | |
| 73 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 74 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 75 | + ' emin=0.1 emax=100.0'+ \ | |
| 76 | + ' logfile="ctbutterfly_cmd1.log" chatter=1' | |
| 77 | + | |
| 78 | + # Execute ctbutterfly, make sure we catch any exception | |
| 81 | 79 | try: |
| 82 | - butterfly.run() | |
| 83 | - self.test_try_success() | |
| 84 | - #except Exception as e: | |
| 85 | - # msg = "Exception occured in ctbutterfly: %s." % (e,) | |
| 80 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 86 | 81 | except: |
| 87 | - msg = "Exception occured in ctbutterfly." | |
| 88 | - self.test_try_failure(msg) | |
| 82 | + pass | |
| 83 | + | |
| 84 | + # Check if execution was successful | |
| 85 | + self.test_assert(rc == 0, | |
| 86 | + 'Successful ctbutterfly execution on command line') | |
| 87 | + | |
| 88 | + # Check result file | |
| 89 | + self._check_result_file('ctbutterfly_cmd1.txt') | |
| 89 | 90 | |
| 90 | - # Save results | |
| 91 | - self.test_try("Save results") | |
| 91 | + # Setup ctbutterfly command | |
| 92 | + cmd = ctbutterfly+' inobs="event_file_that_does_not_exist.fits"'+\ | |
| 93 | + ' outfile="ctbutterfly_cmd2.txt"'+ \ | |
| 94 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 95 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 96 | + ' emin=0.1 emax=100.0'+ \ | |
| 97 | + ' logfile="ctbutterfly_cmd2.log" chatter=1' | |
| 98 | + | |
| 99 | + # Execute ctbutterfly, make sure we catch any exception | |
| 92 | 100 | try: |
| 93 | - butterfly.save() | |
| 94 | - self.test_try_success() | |
| 95 | - #except Exception as e: | |
| 96 | - # msg = "Exception occured in saving butterfly diagram: %s." % (e,) | |
| 101 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 97 | 102 | except: |
| 98 | - msg = "Exception occured in saving butterfly diagram." | |
| 99 | - self.test_try_failure(msg) | |
| 103 | + pass | |
| 104 | + | |
| 105 | + # Check if execution failed | |
| 106 | + self.test_assert(rc != 0, | |
| 107 | + 'Failure of ctbutterfly execution on command line') | |
| 108 | + | |
| 109 | + # Return | |
| 110 | + return | |
| 111 | + | |
| 112 | + # Test ctbutterfly from Python | |
| 113 | + def _test_python(self): | |
| 114 | + """ | |
| 115 | + Test ctbutterfly from Python. | |
| 116 | + """ | |
| 117 | + # Set-up ctbutterfly | |
| 118 | + butterfly = ctools.ctbutterfly() | |
| 119 | + butterfly['inobs'] = 'data/crab_events.fits' | |
| 120 | + butterfly['inmodel'] = 'data/crab.xml' | |
| 121 | + butterfly['srcname'] = 'Crab' | |
| 122 | + butterfly['caldb'] = 'prod2' | |
| 123 | + butterfly['irf'] = 'South_0.5h' | |
| 124 | + butterfly['emin'] = 0.1 | |
| 125 | + butterfly['emax'] = 100.0 | |
| 126 | + butterfly['outfile'] = 'ctbutterfly_py1.txt' | |
| 127 | + butterfly['logfile'] = 'ctbutterfly_py1.log' | |
| 128 | + butterfly['chatter'] = 2 | |
| 129 | + | |
| 130 | + # Run ctbutterfly tool | |
| 131 | + butterfly.logFileOpen() # Make sure we get a log file | |
| 132 | + butterfly.run() | |
| 133 | + butterfly.save() | |
| 134 | + | |
| 135 | + # Check result file | |
| 136 | + self._check_result_file('ctbutterfly_py1.txt') | |
| 137 | + | |
| 138 | + # Return | |
| 139 | + return | |
| 140 | + | |
| 141 | + # Check result file | |
| 142 | + def _check_result_file(self, filename): | |
| 143 | + """ | |
| 144 | + Check result file. | |
| 145 | + """ | |
| 146 | + # Open result file as CSV file | |
| 147 | + results = gammalib.GCsv(filename) | |
| 148 | + | |
| 149 | + # Check dimensions | |
| 150 | + self.test_value(results.nrows(), 100, 'Check for 100 rows in butterfly file') | |
| 151 | + self.test_value(results.ncols(), 4, 'Check for 4 columns in butterfly file') | |
| 100 | 152 | |
| 101 | 153 | # Return |
| 102 | 154 | return | ... | ... |
test/test_ctcubemask.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,10 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.cntmap_name = "data/crab_cntmap.fits" | |
| 42 | - self.regfile = "data/exclusion.reg" | |
| 43 | - | |
| 44 | 41 | # Return |
| 45 | 42 | return |
| 46 | 43 | |
| ... | ... | @@ -50,51 +47,108 @@ class Test(gammalib.GPythonTestSuite): |
| 50 | 47 | Set all test functions. |
| 51 | 48 | """ |
| 52 | 49 | # Set test name |
| 53 | - self.name("ctcubemask") | |
| 50 | + self.name('ctcubemask') | |
| 54 | 51 | |
| 55 | 52 | # Append tests |
| 56 | - self.append(self.test_functional, "Test ctcubemask functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctcubemask on command line') | |
| 54 | + self.append(self._test_python, 'Test ctcubemask from Python') | |
| 57 | 55 | |
| 58 | 56 | # Return |
| 59 | 57 | return |
| 60 | 58 | |
| 61 | - # Test ctcubemask functionnality | |
| 62 | - def test_functional(self): | |
| 59 | + # Test ctcubemask on command line | |
| 60 | + def _test_cmd(self): | |
| 63 | 61 | """ |
| 64 | - Test ctcubemask functionnality. | |
| 62 | + Test ctcubemask on the command line. | |
| 65 | 63 | """ |
| 66 | - # Set-up ctcubemask | |
| 67 | - mask = ctools.ctcubemask() | |
| 68 | - mask["inobs"] = self.cntmap_name | |
| 69 | - mask["regfile"] = self.regfile | |
| 70 | - mask["outcube"] = "filtered_cntmap.fits" | |
| 71 | - mask["ra"] = 83.63 | |
| 72 | - mask["dec"] = 22.01 | |
| 73 | - mask["rad"] = 2.0 | |
| 74 | - mask["emin"] = 0.1 | |
| 75 | - mask["emax"] = 100 | |
| 76 | - | |
| 77 | - # Run tool | |
| 78 | - self.test_try("Run ctcubemask") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctcubemask = '../src/ctcubemask/ctcubemask' | |
| 67 | + else: | |
| 68 | + ctcubemask = 'ctcubemask' | |
| 69 | + | |
| 70 | + # Setup ctcubemask command | |
| 71 | + cmd = ctcubemask+' inobs="data/crab_cntmap.fits"'+ \ | |
| 72 | + ' regfile="data/exclusion.reg"'+ \ | |
| 73 | + ' outcube="ctcubemask_cmd1.fits"'+ \ | |
| 74 | + ' ra=83.63 dec=22.01 rad=2.0'+ \ | |
| 75 | + ' emin=0.1 emax=100.0'+ \ | |
| 76 | + ' logfile="ctcubemask_cmd1.log" chatter=1' | |
| 77 | + | |
| 78 | + # Execute ctcubemask, make sure we catch any exception | |
| 79 | 79 | try: |
| 80 | - mask.run() | |
| 81 | - self.test_try_success() | |
| 82 | - #except Exception as e: | |
| 83 | - # msg = "Exception occured in ctcubemask: %s." % (e,) | |
| 80 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 84 | 81 | except: |
| 85 | - msg = "Exception occured in ctcubemask." | |
| 86 | - self.test_try_failure(msg) | |
| 82 | + pass | |
| 83 | + | |
| 84 | + # Check if execution was successful | |
| 85 | + self.test_assert(rc == 0, | |
| 86 | + 'Successful ctcubemask execution on command line') | |
| 87 | + | |
| 88 | + # Check result file | |
| 89 | + self._check_result_file('ctcubemask_cmd1.fits') | |
| 87 | 90 | |
| 88 | - # Save counts cube | |
| 89 | - self.test_try("Save counts cube") | |
| 91 | + # Setup ctcubemask command | |
| 92 | + cmd = ctcubemask+' inobs="counts_cube_that_does_not_exist.fits"'+ \ | |
| 93 | + ' regfile="data/exclusion.reg"'+ \ | |
| 94 | + ' outcube="ctcubemask_cmd2.fits"'+ \ | |
| 95 | + ' ra=83.63 dec=22.01 rad=2.0'+ \ | |
| 96 | + ' emin=0.1 emax=100.0'+ \ | |
| 97 | + ' logfile="ctcubemask_cmd2.log" chatter=2' | |
| 98 | + | |
| 99 | + # Execute ctcubemask, make sure we catch any exception | |
| 90 | 100 | try: |
| 91 | - mask.save() | |
| 92 | - self.test_try_success() | |
| 93 | - #except Exception as e: | |
| 94 | - # msg = "Exception occured in saving counts cube: %s." % (e,) | |
| 101 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 95 | 102 | except: |
| 96 | - msg = "Exception occured in saving counts cube." | |
| 97 | - self.test_try_failure(msg) | |
| 103 | + pass | |
| 104 | + | |
| 105 | + # Check if execution failed | |
| 106 | + self.test_assert(rc != 0, | |
| 107 | + 'Failure of ctcubemask execution on command line') | |
| 108 | + | |
| 109 | + # Return | |
| 110 | + return | |
| 111 | + | |
| 112 | + # Test ctcubemask from Python | |
| 113 | + def _test_python(self): | |
| 114 | + """ | |
| 115 | + Test ctcubemask from Python. | |
| 116 | + """ | |
| 117 | + # Set-up ctcubemask | |
| 118 | + mask = ctools.ctcubemask() | |
| 119 | + mask['inobs'] = 'data/crab_cntmap.fits' | |
| 120 | + mask['regfile'] = 'data/exclusion.reg' | |
| 121 | + mask['outcube'] = 'ctcubemask_py1.fits' | |
| 122 | + mask['ra'] = 83.63 | |
| 123 | + mask['dec'] = 22.01 | |
| 124 | + mask['rad'] = 2.0 | |
| 125 | + mask['emin'] = 0.1 | |
| 126 | + mask['emax'] = 100.0 | |
| 127 | + mask['logfile'] = 'ctcubemask_py1.log' | |
| 128 | + mask['chatter'] = 2 | |
| 129 | + | |
| 130 | + # Run ctcubemask tool | |
| 131 | + mask.logFileOpen() # Make sure we get a log file | |
| 132 | + mask.run() | |
| 133 | + mask.save() | |
| 134 | + | |
| 135 | + # Check result file | |
| 136 | + self._check_result_file('ctcubemask_py1.fits') | |
| 137 | + | |
| 138 | + # Return | |
| 139 | + return | |
| 140 | + | |
| 141 | + # Check result file | |
| 142 | + def _check_result_file(self, filename): | |
| 143 | + """ | |
| 144 | + Check result file. | |
| 145 | + """ | |
| 146 | + # Load counts cube | |
| 147 | + cube = gammalib.GCTAEventCube(filename) | |
| 148 | + | |
| 149 | + # Check counts cube | |
| 150 | + self.test_value(cube.size(), 800000, 'Check for 800000 cube bins') | |
| 151 | + self.test_value(cube.number(), 4921, 'Check for 4921 events') | |
| 98 | 152 | |
| 99 | 153 | # Return |
| 100 | 154 | return | ... | ... |
test/test_ctedispcube.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,11 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.caldb = "irf" | |
| 43 | - self.irf = "cta_dummy_irf" | |
| 44 | - | |
| 45 | 41 | # Return |
| 46 | 42 | return |
| 47 | 43 | |
| ... | ... | @@ -51,61 +47,124 @@ class Test(gammalib.GPythonTestSuite): |
| 51 | 47 | Set all test functions. |
| 52 | 48 | """ |
| 53 | 49 | # Set test name |
| 54 | - self.name("ctedispcube") | |
| 50 | + self.name('ctedispcube') | |
| 55 | 51 | |
| 56 | 52 | # Append tests |
| 57 | - self.append(self.test_functional, "Test ctedispcube functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctedispcube on command line') | |
| 54 | + self.append(self._test_python, 'Test ctedispcube from Python') | |
| 58 | 55 | |
| 59 | 56 | # Return |
| 60 | 57 | return |
| 61 | 58 | |
| 62 | - # Test ctedispcube functionnality | |
| 63 | - def test_functional(self): | |
| 59 | + # Test ctedispcube on command line | |
| 60 | + def _test_cmd(self): | |
| 64 | 61 | """ |
| 65 | - Test ctedispcube functionnality. | |
| 62 | + Test ctedispcube on the command line. | |
| 66 | 63 | """ |
| 67 | - # Set-up ctedispcube | |
| 68 | - edispcube = ctools.ctedispcube() | |
| 69 | - edispcube["inobs"] = self.events_name | |
| 70 | - edispcube["incube"] = "NONE" | |
| 71 | - edispcube["outcube"] = "edispcube.fits" | |
| 72 | - edispcube["caldb"] = self.caldb | |
| 73 | - edispcube["irf"] = self.irf | |
| 74 | - edispcube["ebinalg"] = "LOG" | |
| 75 | - edispcube["emin"] = 0.1 | |
| 76 | - edispcube["emax"] = 100 | |
| 77 | - edispcube["enumbins"] = 20 | |
| 78 | - edispcube["nxpix"] = 10 | |
| 79 | - edispcube["nypix"] = 10 | |
| 80 | - edispcube["binsz"] = 0.4 | |
| 81 | - edispcube["coordsys"] = "CEL" | |
| 82 | - edispcube["proj"] = "CAR" | |
| 83 | - edispcube["xref"] = 83.63 | |
| 84 | - edispcube["yref"] = 22.01 | |
| 85 | - edispcube["migramax"] = 2.0 | |
| 86 | - edispcube["migrabins"] = 10 | |
| 87 | - | |
| 88 | - # Run tool | |
| 89 | - self.test_try("Run ctedispcube") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctedispcube = '../src/ctedispcube/ctedispcube' | |
| 67 | + else: | |
| 68 | + ctedispcube = 'ctedispcube' | |
| 69 | + | |
| 70 | + # Setup ctedispcube command | |
| 71 | + cmd = ctedispcube+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' incube="NONE"'+ \ | |
| 73 | + ' outcube="ctedispcube_cmd1.fits"'+ \ | |
| 74 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 75 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 76 | + ' nxpix=10 nypix=10 binsz=0.4'+ \ | |
| 77 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 78 | + ' migramax=2.0 migrabins=10'+ \ | |
| 79 | + ' logfile="ctedispcube_cmd1.log" chatter=1' | |
| 80 | + | |
| 81 | + # Execute ctedispcube, make sure we catch any exception | |
| 90 | 82 | try: |
| 91 | - edispcube.run() | |
| 92 | - self.test_try_success() | |
| 93 | - #except Exception as e: | |
| 94 | - # msg = "Exception occured in ctedispcube: %s." % (e,) | |
| 83 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 95 | 84 | except: |
| 96 | - msg = "Exception occured in ctedispcube." | |
| 97 | - self.test_try_failure(msg) | |
| 85 | + pass | |
| 86 | + | |
| 87 | + # Check if execution was successful | |
| 88 | + self.test_assert(rc == 0, | |
| 89 | + 'Successful ctedispcube execution on command line') | |
| 90 | + | |
| 91 | + # Check result file | |
| 92 | + self._check_result_file('ctedispcube_cmd1.fits') | |
| 98 | 93 | |
| 99 | - # Save EDISP cube | |
| 100 | - self.test_try("Save EDISP cube") | |
| 94 | + # Setup ctedispcube command | |
| 95 | + cmd = ctedispcube+' inobs="events_that_do_not_exist.fits"'+ \ | |
| 96 | + ' incube="NONE"'+ \ | |
| 97 | + ' outcube="ctedispcube_cmd2.fits"'+ \ | |
| 98 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 99 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 100 | + ' nxpix=10 nypix=10 binsz=0.4'+ \ | |
| 101 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 102 | + ' migramax=2.0 migrabins=10'+ \ | |
| 103 | + ' logfile="ctedispcube_cmd2.log" chatter=2' | |
| 104 | + | |
| 105 | + # Execute ctedispcube, make sure we catch any exception | |
| 101 | 106 | try: |
| 102 | - edispcube.save() | |
| 103 | - self.test_try_success() | |
| 104 | - #except Exception as e: | |
| 105 | - # msg = "Exception occured in saving EDISP cube: %s." % (e,) | |
| 107 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 106 | 108 | except: |
| 107 | - msg = "Exception occured in saving EDISP cubes." | |
| 108 | - self.test_try_failure(msg) | |
| 109 | + pass | |
| 110 | + | |
| 111 | + # Check if execution failed | |
| 112 | + self.test_assert(rc != 0, | |
| 113 | + 'Failure of ctedispcube execution on command line') | |
| 114 | + | |
| 115 | + # Return | |
| 116 | + return | |
| 117 | + | |
| 118 | + # Test ctedispcube from Python | |
| 119 | + def _test_python(self): | |
| 120 | + """ | |
| 121 | + Test ctedispcube from Python. | |
| 122 | + """ | |
| 123 | + # Set-up ctedispcube | |
| 124 | + edispcube = ctools.ctedispcube() | |
| 125 | + edispcube['inobs'] = 'data/crab_events.fits' | |
| 126 | + edispcube['incube'] = 'NONE' | |
| 127 | + edispcube['outcube'] = 'ctedispcube_py1.fits' | |
| 128 | + edispcube['caldb'] = 'prod2' | |
| 129 | + edispcube['irf'] = 'South_0.5h' | |
| 130 | + edispcube['ebinalg'] = 'LOG' | |
| 131 | + edispcube['emin'] = 0.1 | |
| 132 | + edispcube['emax'] = 100 | |
| 133 | + edispcube['enumbins'] = 20 | |
| 134 | + edispcube['nxpix'] = 10 | |
| 135 | + edispcube['nypix'] = 10 | |
| 136 | + edispcube['binsz'] = 0.4 | |
| 137 | + edispcube['coordsys'] = 'CEL' | |
| 138 | + edispcube['proj'] = 'CAR' | |
| 139 | + edispcube['xref'] = 83.63 | |
| 140 | + edispcube['yref'] = 22.01 | |
| 141 | + edispcube['migramax'] = 2.0 | |
| 142 | + edispcube['migrabins'] = 10 | |
| 143 | + edispcube['logfile'] = 'ctedispcube_py1.log' | |
| 144 | + edispcube['chatter'] = 2 | |
| 145 | + | |
| 146 | + # Run ctedispcube tool | |
| 147 | + edispcube.logFileOpen() # Make sure we get a log file | |
| 148 | + edispcube.run() | |
| 149 | + edispcube.save() | |
| 150 | + | |
| 151 | + # Check result file | |
| 152 | + self._check_result_file('ctedispcube_py1.fits') | |
| 153 | + | |
| 154 | + # Return | |
| 155 | + return | |
| 156 | + | |
| 157 | + # Check result file | |
| 158 | + def _check_result_file(self, filename): | |
| 159 | + """ | |
| 160 | + Check result file. | |
| 161 | + """ | |
| 162 | + # Open result file | |
| 163 | + result = gammalib.GCTACubeEdisp(filename) | |
| 164 | + | |
| 165 | + # Check dimensions | |
| 166 | + self.test_value(len(result.energies()), 21, 'Check for 21 energy maps') | |
| 167 | + self.test_value(len(result.migras()), 10, 'Check for 10 migration bins') | |
| 109 | 168 | |
| 110 | 169 | # Return |
| 111 | 170 | return | ... | ... |
test/test_cterror.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -53,49 +54,122 @@ class Test(gammalib.GPythonTestSuite): |
| 53 | 54 | Set all test functions. |
| 54 | 55 | """ |
| 55 | 56 | # Set test name |
| 56 | - self.name("cterror") | |
| 57 | + self.name('cterror') | |
| 57 | 58 | |
| 58 | 59 | # Append tests |
| 59 | - self.append(self.test_functional, "Test cterror functionality") | |
| 60 | + self.append(self._test_cmd, 'Test cterror on command line') | |
| 61 | + self.append(self._test_python, 'Test cterror from Python') | |
| 60 | 62 | |
| 61 | 63 | # Return |
| 62 | 64 | return |
| 63 | 65 | |
| 64 | - # Test cttsmap functionnality | |
| 65 | - def test_functional(self): | |
| 66 | + # Test cterror on command line | |
| 67 | + def _test_cmd(self): | |
| 66 | 68 | """ |
| 67 | - Test cterror functionnality. | |
| 69 | + Test cterror on the command line. | |
| 68 | 70 | """ |
| 69 | - # Set-up cterror | |
| 70 | - error = ctools.cterror() | |
| 71 | - error["inobs"] = self.events_name | |
| 72 | - error["inmodel"] = self.model_name | |
| 73 | - error["outmodel"] = self.result_name | |
| 74 | - error["srcname"] = "Crab" | |
| 75 | - error["caldb"] = self.caldb | |
| 76 | - error["irf"] = self.irf | |
| 77 | - | |
| 78 | - # Run tool | |
| 79 | - self.test_try("Run cterror") | |
| 71 | + # Kluge to set the command (installed version has no README file) | |
| 72 | + if os.path.isfile('README'): | |
| 73 | + cterror = '../src/cterror/cterror' | |
| 74 | + else: | |
| 75 | + cterror = 'cterror' | |
| 76 | + | |
| 77 | + # Setup cterror command | |
| 78 | + cmd = cterror+' inobs="data/crab_events.fits"'+ \ | |
| 79 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 80 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 81 | + ' outmodel="cterror_cmd1.xml"'+ \ | |
| 82 | + ' logfile="cterror_cmd1.log" chatter=1' | |
| 83 | + | |
| 84 | + # Execute cterror, make sure we catch any exception | |
| 80 | 85 | try: |
| 81 | - error.run() | |
| 82 | - self.test_try_success() | |
| 83 | - #except Exception as e: | |
| 84 | - # msg = "Exception occured in cterror: %s." % (e,) | |
| 86 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 85 | 87 | except: |
| 86 | - msg = "Exception occured in cterror." | |
| 87 | - self.test_try_failure(msg) | |
| 88 | + pass | |
| 89 | + | |
| 90 | + # Check if execution was successful | |
| 91 | + self.test_assert(rc == 0, | |
| 92 | + 'Successful cterror execution on command line') | |
| 93 | + | |
| 94 | + # Check result file | |
| 95 | + self._check_result_file('cterror_cmd1.xml') | |
| 96 | + | |
| 97 | + # Setup cterror command | |
| 98 | + cmd = cterror+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 99 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 100 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 101 | + ' outmodel="cterror_cmd2.xml"'+ \ | |
| 102 | + ' logfile="cterror_cmd2.log" chatter=1' | |
| 88 | 103 | |
| 89 | - # Save results | |
| 90 | - self.test_try("Save results") | |
| 104 | + # Execute cterror, make sure we catch any exception | |
| 91 | 105 | try: |
| 92 | - error.save() | |
| 93 | - self.test_try_success() | |
| 94 | - #except Exception as e: | |
| 95 | - # msg = "Exception occured in saving results: %s." % (e,) | |
| 106 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 96 | 107 | except: |
| 97 | - msg = "Exception occured in saving results." | |
| 98 | - self.test_try_failure(msg) | |
| 108 | + pass | |
| 109 | + | |
| 110 | + # Check if execution failed | |
| 111 | + self.test_assert(rc != 0, | |
| 112 | + 'Failure of cterror execution on command line') | |
| 113 | + | |
| 114 | + # Return | |
| 115 | + return | |
| 116 | + | |
| 117 | + # Test cterror from Python | |
| 118 | + def _test_python(self): | |
| 119 | + """ | |
| 120 | + Test cterror from Python. | |
| 121 | + """ | |
| 122 | + # Set-up cterror | |
| 123 | + error = ctools.cterror() | |
| 124 | + error['inobs'] = 'data/crab_events.fits' | |
| 125 | + error['inmodel'] = 'data/crab.xml' | |
| 126 | + error['outmodel'] = 'cterror_py1.xml' | |
| 127 | + error['srcname'] = 'Crab' | |
| 128 | + error['caldb'] = 'prod2' | |
| 129 | + error['irf'] = 'South_0.5h' | |
| 130 | + error['logfile'] = 'cterror_py1.log' | |
| 131 | + error['chatter'] = 2 | |
| 132 | + | |
| 133 | + # Run cterror tool | |
| 134 | + error.logFileOpen() # Make sure we get a log file | |
| 135 | + error.run() | |
| 136 | + error.save() | |
| 137 | + | |
| 138 | + # Check result file | |
| 139 | + self._check_result_file('cterror_py1.xml') | |
| 140 | + | |
| 141 | + # Return | |
| 142 | + return | |
| 143 | + | |
| 144 | + # Check result file | |
| 145 | + def _check_result_file(self, filename): | |
| 146 | + """ | |
| 147 | + Check result file. | |
| 148 | + """ | |
| 149 | + # Open result file | |
| 150 | + result = gammalib.GModels(filename) | |
| 151 | + | |
| 152 | + # Check results | |
| 153 | + self.test_value(result['Crab']['Prefactor'].value(), 1.58907e-16, | |
| 154 | + 1.0e-3, 'Check fitted Crab Prefactor') | |
| 155 | + self.test_value(result['Crab']['Prefactor'].error(), 0.0529105e-16, | |
| 156 | + 1.0e-3, 'Check Crab Prefactor error') | |
| 157 | + self.test_value(result['Crab']['Index'].value(), -2.43549, | |
| 158 | + 1.0e-3, 'Check fitted Crab Index') | |
| 159 | + self.test_value(result['Crab']['Index'].error(), 0.027804, | |
| 160 | + 1.0e-3, 'Check Crab Index error') | |
| 161 | + self.test_value(result['Background']['Prefactor'].value(), 61.6919e-6, | |
| 162 | + 1.0e-3, 'Check fitted background Prefactor') | |
| 163 | + self.test_value(result['Background']['Prefactor'].error(), 1.49438e-6, | |
| 164 | + 1.0e-3, 'Check background Prefactor error') | |
| 165 | + self.test_value(result['Background']['Index'].value(), -2.20535, | |
| 166 | + 1.0e-3, 'Check fitted background Index') | |
| 167 | + self.test_value(result['Background']['Index'].error(), 0.0113269, | |
| 168 | + 1.0e-3, 'Check background Index error') | |
| 169 | + self.test_value(result['Background']['Sigma'].value(), 3.04252, | |
| 170 | + 1.0e-3, 'Check fitted background Sigma') | |
| 171 | + self.test_value(result['Background']['Sigma'].error(), 0.0307008, | |
| 172 | + 1.0e-3, 'Check background Sigma error') | |
| 99 | 173 | |
| 100 | 174 | # Return |
| 101 | 175 | return | ... | ... |
test/test_ctexpcube.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,11 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.caldb = "irf" | |
| 43 | - self.irf = "cta_dummy_irf" | |
| 44 | - | |
| 45 | 41 | # Return |
| 46 | 42 | return |
| 47 | 43 | |
| ... | ... | @@ -51,59 +47,119 @@ class Test(gammalib.GPythonTestSuite): |
| 51 | 47 | Set all test functions. |
| 52 | 48 | """ |
| 53 | 49 | # Set test name |
| 54 | - self.name("ctexpcube") | |
| 50 | + self.name('ctexpcube') | |
| 55 | 51 | |
| 56 | 52 | # Append tests |
| 57 | - self.append(self.test_functional, "Test ctexpcube functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctexpcube on command line') | |
| 54 | + self.append(self._test_python, 'Test ctexpcube from Python') | |
| 58 | 55 | |
| 59 | 56 | # Return |
| 60 | 57 | return |
| 61 | 58 | |
| 62 | - # Test ctexpcube functionnality | |
| 63 | - def test_functional(self): | |
| 59 | + # Test ctexpcube on command line | |
| 60 | + def _test_cmd(self): | |
| 64 | 61 | """ |
| 65 | - Test ctexpcube functionnality. | |
| 62 | + Test ctexpcube on the command line. | |
| 66 | 63 | """ |
| 67 | - # Set-up ctexpcube | |
| 68 | - expcube = ctools.ctexpcube() | |
| 69 | - expcube["inobs"] = self.events_name | |
| 70 | - expcube["incube"] = "NONE" | |
| 71 | - expcube["outcube"] = "expcube.fits" | |
| 72 | - expcube["caldb"] = self.caldb | |
| 73 | - expcube["irf"] = self.irf | |
| 74 | - expcube["ebinalg"] = "LOG" | |
| 75 | - expcube["emin"] = 0.1 | |
| 76 | - expcube["emax"] = 100 | |
| 77 | - expcube["enumbins"] = 20 | |
| 78 | - expcube["nxpix"] = 200 | |
| 79 | - expcube["nypix"] = 200 | |
| 80 | - expcube["binsz"] = 0.02 | |
| 81 | - expcube["coordsys"] = "CEL" | |
| 82 | - expcube["proj"] = "CAR" | |
| 83 | - expcube["xref"] = 83.63 | |
| 84 | - expcube["yref"] = 22.01 | |
| 85 | - | |
| 86 | - # Run tool | |
| 87 | - self.test_try("Run ctexpcube") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctexpcube = '../src/ctexpcube/ctexpcube' | |
| 67 | + else: | |
| 68 | + ctexpcube = 'ctexpcube' | |
| 69 | + | |
| 70 | + # Setup ctexpcube command | |
| 71 | + cmd = ctexpcube+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' incube="NONE"'+ \ | |
| 73 | + ' outcube="ctexpcube_cmd1.fits"'+ \ | |
| 74 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 75 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 76 | + ' nxpix=200 nypix=200 binsz=0.02'+ \ | |
| 77 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 78 | + ' logfile="ctexpcube_cmd1.log" chatter=1' | |
| 79 | + | |
| 80 | + # Execute ctexpcube, make sure we catch any exception | |
| 88 | 81 | try: |
| 89 | - expcube.run() | |
| 90 | - self.test_try_success() | |
| 91 | - #except Exception as e: | |
| 92 | - # msg = "Exception occured in ctexpcube: %s." % (e,) | |
| 82 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 93 | 83 | except: |
| 94 | - msg = "Exception occured in ctexpcube." | |
| 95 | - self.test_try_failure(msg) | |
| 84 | + pass | |
| 85 | + | |
| 86 | + # Check if execution was successful | |
| 87 | + self.test_assert(rc == 0, | |
| 88 | + 'Successful ctexpcube execution on command line') | |
| 89 | + | |
| 90 | + # Check result file | |
| 91 | + self._check_result_file('ctexpcube_cmd1.fits') | |
| 96 | 92 | |
| 97 | - # Save exposure cube | |
| 98 | - self.test_try("Save exposure cube") | |
| 93 | + # Setup ctexpcube command | |
| 94 | + cmd = ctexpcube+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 95 | + ' incube="NONE"'+ \ | |
| 96 | + ' outcube="ctexpcube_cmd2.fits"'+ \ | |
| 97 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 98 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 99 | + ' nxpix=200 nypix=200 binsz=0.02'+ \ | |
| 100 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 101 | + ' logfile="ctexpcube_cmd2.log" chatter=1' | |
| 102 | + | |
| 103 | + # Execute ctexpcube, make sure we catch any exception | |
| 99 | 104 | try: |
| 100 | - expcube.save() | |
| 101 | - self.test_try_success() | |
| 102 | - #except Exception as e: | |
| 103 | - # msg = "Exception occured in saving exposure cube: %s." % (e,) | |
| 105 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 104 | 106 | except: |
| 105 | - msg = "Exception occured in saving exposure cube." | |
| 106 | - self.test_try_failure(msg) | |
| 107 | + pass | |
| 108 | + | |
| 109 | + # Check if execution failed | |
| 110 | + self.test_assert(rc != 0, | |
| 111 | + 'Failure of ctexpcube execution on command line') | |
| 112 | + | |
| 113 | + # Return | |
| 114 | + return | |
| 115 | + | |
| 116 | + # Test ctexpcube from Python | |
| 117 | + def _test_python(self): | |
| 118 | + """ | |
| 119 | + Test ctexpcube from Python. | |
| 120 | + """ | |
| 121 | + # Set-up ctexpcube | |
| 122 | + expcube = ctools.ctexpcube() | |
| 123 | + expcube['inobs'] = 'data/crab_events.fits' | |
| 124 | + expcube['incube'] = 'NONE' | |
| 125 | + expcube['outcube'] = 'ctexpcube_py1.fits' | |
| 126 | + expcube['caldb'] = 'prod2' | |
| 127 | + expcube['irf'] = 'South_0.5h' | |
| 128 | + expcube['ebinalg'] = 'LOG' | |
| 129 | + expcube['emin'] = 0.1 | |
| 130 | + expcube['emax'] = 100 | |
| 131 | + expcube['enumbins'] = 20 | |
| 132 | + expcube['nxpix'] = 200 | |
| 133 | + expcube['nypix'] = 200 | |
| 134 | + expcube['binsz'] = 0.02 | |
| 135 | + expcube['coordsys'] = 'CEL' | |
| 136 | + expcube['proj'] = 'CAR' | |
| 137 | + expcube['xref'] = 83.63 | |
| 138 | + expcube['yref'] = 22.01 | |
| 139 | + expcube['logfile'] = 'ctexpcube_py1.log' | |
| 140 | + expcube['chatter'] = 2 | |
| 141 | + | |
| 142 | + # Run ctexpcube tool | |
| 143 | + expcube.logFileOpen() # Make sure we get a log file | |
| 144 | + expcube.run() | |
| 145 | + expcube.save() | |
| 146 | + | |
| 147 | + # Check result file | |
| 148 | + self._check_result_file('ctexpcube_py1.fits') | |
| 149 | + | |
| 150 | + # Return | |
| 151 | + return | |
| 152 | + | |
| 153 | + # Check result file | |
| 154 | + def _check_result_file(self, filename): | |
| 155 | + """ | |
| 156 | + Check result file. | |
| 157 | + """ | |
| 158 | + # Open result file | |
| 159 | + result = gammalib.GCTACubeExposure(filename) | |
| 160 | + | |
| 161 | + # Check dimensions | |
| 162 | + self.test_value(len(result.energies()), 21, 'Check for 21 energy values') | |
| 107 | 163 | |
| 108 | 164 | # Return |
| 109 | 165 | return | ... | ... |
test/test_ctlike.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,12 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.model_name = "data/crab.xml" | |
| 43 | - self.caldb = "irf" | |
| 44 | - self.irf = "cta_dummy_irf" | |
| 45 | - | |
| 46 | 41 | # Return |
| 47 | 42 | return |
| 48 | 43 | |
| ... | ... | @@ -52,48 +47,121 @@ class Test(gammalib.GPythonTestSuite): |
| 52 | 47 | Set all test functions. |
| 53 | 48 | """ |
| 54 | 49 | # Set test name |
| 55 | - self.name("ctlike") | |
| 50 | + self.name('ctlike') | |
| 56 | 51 | |
| 57 | 52 | # Append tests |
| 58 | - self.append(self.test_functional, "Test ctlike functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctlike on command line') | |
| 54 | + self.append(self._test_python, 'Test ctlike from Python') | |
| 59 | 55 | |
| 60 | 56 | # Return |
| 61 | 57 | return |
| 62 | 58 | |
| 63 | - # Test ctlike functionnality | |
| 64 | - def test_functional(self): | |
| 59 | + # Test ctlike on command line | |
| 60 | + def _test_cmd(self): | |
| 65 | 61 | """ |
| 66 | - Test ctlike functionnality. | |
| 62 | + Test ctlike on the command line. | |
| 67 | 63 | """ |
| 68 | - # Set-up ctlike | |
| 69 | - like = ctools.ctlike() | |
| 70 | - like["inobs"] = self.events_name | |
| 71 | - like["inmodel"] = self.model_name | |
| 72 | - like["caldb"] = self.caldb | |
| 73 | - like["irf"] = self.irf | |
| 74 | - like["outmodel"] = "result.xml" | |
| 75 | - | |
| 76 | - # Run tool | |
| 77 | - self.test_try("Run ctlike") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctlike = '../src/ctlike/ctlike' | |
| 67 | + else: | |
| 68 | + ctlike = 'ctlike' | |
| 69 | + | |
| 70 | + # Setup ctlike command | |
| 71 | + cmd = ctlike+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' inmodel="data/crab.xml"'+ \ | |
| 73 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 74 | + ' outmodel="ctlike_cmd1.xml"'+ \ | |
| 75 | + ' logfile="ctlike_cmd1.log" chatter=1' | |
| 76 | + | |
| 77 | + # Execute ctlike, make sure we catch any exception | |
| 78 | 78 | try: |
| 79 | - like.run() | |
| 80 | - self.test_try_success() | |
| 81 | - #except Exception as e: | |
| 82 | - # msg = "Exception occured in ctlike: %s." % (e,) | |
| 79 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 83 | 80 | except: |
| 84 | - msg = "Exception occured in ctlike." | |
| 85 | - self.test_try_failure(msg) | |
| 81 | + pass | |
| 82 | + | |
| 83 | + # Check if execution was successful | |
| 84 | + self.test_assert(rc == 0, | |
| 85 | + 'Successful ctlike execution on command line') | |
| 86 | + | |
| 87 | + # Check result file | |
| 88 | + self._check_result_file('ctlike_cmd1.xml') | |
| 86 | 89 | |
| 87 | - # Save results | |
| 88 | - self.test_try("Save results") | |
| 90 | + # Setup ctlike command | |
| 91 | + cmd = ctlike+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 92 | + ' inmodel="data/crab.xml"'+ \ | |
| 93 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 94 | + ' outmodel="ctlike_cmd2.xml"'+ \ | |
| 95 | + ' logfile="ctlike_cmd2.log" chatter=1' | |
| 96 | + | |
| 97 | + # Execute ctlike, make sure we catch any exception | |
| 89 | 98 | try: |
| 90 | - like.save() | |
| 91 | - self.test_try_success() | |
| 92 | - #except Exception as e: | |
| 93 | - # msg = "Exception occured in saving results: %s." % (e,) | |
| 99 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 94 | 100 | except: |
| 95 | - msg = "Exception occured in saving results." | |
| 96 | - self.test_try_failure(msg) | |
| 101 | + pass | |
| 102 | + | |
| 103 | + # Check if execution failed | |
| 104 | + self.test_assert(rc != 0, | |
| 105 | + 'Failure of ctlike execution on command line') | |
| 106 | + | |
| 107 | + # Return | |
| 108 | + return | |
| 109 | + | |
| 110 | + # Test ctlike from Python | |
| 111 | + def _test_python(self): | |
| 112 | + """ | |
| 113 | + Test ctlike from Python. | |
| 114 | + """ | |
| 115 | + # Set-up ctlike | |
| 116 | + like = ctools.ctlike() | |
| 117 | + like['inobs'] = 'data/crab_events.fits' | |
| 118 | + like['inmodel'] = 'data/crab.xml' | |
| 119 | + like['caldb'] = 'prod2' | |
| 120 | + like['irf'] = 'South_0.5h' | |
| 121 | + like['outmodel'] = 'ctlike_py1.xml' | |
| 122 | + like['logfile'] = 'ctlike_py1.log' | |
| 123 | + like['chatter'] = 2 | |
| 124 | + | |
| 125 | + # Run ctlike tool | |
| 126 | + like.logFileOpen() # Make sure we get a log file | |
| 127 | + like.run() | |
| 128 | + like.save() | |
| 129 | + | |
| 130 | + # Check result file | |
| 131 | + self._check_result_file('ctlike_py1.xml') | |
| 132 | + | |
| 133 | + # Return | |
| 134 | + return | |
| 135 | + | |
| 136 | + # Check result file | |
| 137 | + def _check_result_file(self, filename): | |
| 138 | + """ | |
| 139 | + Check result file. | |
| 140 | + """ | |
| 141 | + # Open result file | |
| 142 | + result = gammalib.GModels(filename) | |
| 143 | + | |
| 144 | + # Check results | |
| 145 | + self.test_value(result['Crab']['Prefactor'].value(), 1.58907e-16, | |
| 146 | + 1.0e-3, 'Check fitted Crab Prefactor') | |
| 147 | + self.test_value(result['Crab']['Prefactor'].error(), 0.0526982e-16, | |
| 148 | + 1.0e-3, 'Check Crab Prefactor error') | |
| 149 | + self.test_value(result['Crab']['Index'].value(), -2.43549, | |
| 150 | + 1.0e-3, 'Check fitted Crab Index') | |
| 151 | + self.test_value(result['Crab']['Index'].error(), 0.0248116, | |
| 152 | + 1.0e-3, 'Check Crab Index error') | |
| 153 | + self.test_value(result['Background']['Prefactor'].value(), 61.6919e-6, | |
| 154 | + 1.0e-3, 'Check fitted background Prefactor') | |
| 155 | + self.test_value(result['Background']['Prefactor'].error(), 1.49438e-6, | |
| 156 | + 1.0e-3, 'Check background Prefactor error') | |
| 157 | + self.test_value(result['Background']['Index'].value(), -2.20535, | |
| 158 | + 1.0e-3, 'Check fitted background Index') | |
| 159 | + self.test_value(result['Background']['Index'].error(), 0.0113269, | |
| 160 | + 1.0e-3, 'Check background Index error') | |
| 161 | + self.test_value(result['Background']['Sigma'].value(), 3.04252, | |
| 162 | + 1.0e-3, 'Check fitted background Sigma') | |
| 163 | + self.test_value(result['Background']['Sigma'].error(), 0.0307008, | |
| 164 | + 1.0e-3, 'Check background Sigma error') | |
| 97 | 165 | |
| 98 | 166 | # Return |
| 99 | 167 | return | ... | ... |
test/test_ctmodel.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,11 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.model_name = "data/crab.xml" | |
| 42 | - self.caldb = "irf" | |
| 43 | - self.irf = "cta_dummy_irf" | |
| 44 | - | |
| 45 | 41 | # Return |
| 46 | 42 | return |
| 47 | 43 | |
| ... | ... | @@ -51,67 +47,139 @@ class Test(gammalib.GPythonTestSuite): |
| 51 | 47 | Set all test functions. |
| 52 | 48 | """ |
| 53 | 49 | # Set test name |
| 54 | - self.name("ctmodel") | |
| 50 | + self.name('ctmodel') | |
| 55 | 51 | |
| 56 | 52 | # Append tests |
| 57 | - self.append(self.test_functional, "Test ctmodel functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctmodel on command line') | |
| 54 | + self.append(self._test_python, 'Test ctmodel from Python') | |
| 58 | 55 | |
| 59 | 56 | # Return |
| 60 | 57 | return |
| 61 | 58 | |
| 62 | - # Test ctmodel functionnality | |
| 63 | - def test_functional(self): | |
| 59 | + # Test ctmodel on command line | |
| 60 | + def _test_cmd(self): | |
| 64 | 61 | """ |
| 65 | - Test ctmodel functionnality. | |
| 62 | + Test ctmodel on the command line. | |
| 66 | 63 | """ |
| 67 | - # Set-up ctmodel from scratch | |
| 68 | - model = ctools.ctmodel() | |
| 69 | - model["incube"] = "NONE" | |
| 70 | - model["outcube"] = "modmap.fits" | |
| 71 | - model["inmodel"] = self.model_name | |
| 72 | - model["inobs"] = "NONE" | |
| 73 | - model["expcube"] = "NONE" | |
| 74 | - model["psfcube"] = "NONE" | |
| 75 | - model["bkgcube"] = "NONE" | |
| 76 | - model["caldb"] = self.caldb | |
| 77 | - model["irf"] = self.irf | |
| 78 | - model["rad"] = 5 | |
| 79 | - model["ra"] = 83.63 | |
| 80 | - model["dec"] = 22.01 | |
| 81 | - model["tmin"] = 0 | |
| 82 | - model["tmax"] = 1800 | |
| 83 | - model["emin"] = 0.1 | |
| 84 | - model["emax"] = 100 | |
| 85 | - model["enumbins"] = 20 | |
| 86 | - model["nxpix"] = 200 | |
| 87 | - model["nypix"] = 200 | |
| 88 | - model["binsz"] = 0.02 | |
| 89 | - model["coordsys"] = "CEL" | |
| 90 | - model["proj"] = "CAR" | |
| 91 | - model["xref"] = 83.63 | |
| 92 | - model["yref"] = 22.01 | |
| 93 | - | |
| 94 | - # Run tool | |
| 95 | - self.test_try("Run ctmodel") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctmodel = '../src/ctmodel/ctmodel' | |
| 67 | + else: | |
| 68 | + ctmodel = 'ctmodel' | |
| 69 | + | |
| 70 | + # Setup ctmodel command | |
| 71 | + cmd = ctmodel+' incube="NONE" inobs="NONE" expcube="NONE"'+\ | |
| 72 | + ' psfcube="NONE" bkgcube="NONE"'+ \ | |
| 73 | + ' outcube="ctmodel_cmd1.fits"'+ \ | |
| 74 | + ' inmodel="data/crab.xml"'+ \ | |
| 75 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 76 | + ' rad=5.0 ra=83.63 dec=22.01 tmin=0.0 tmax=1800'+ \ | |
| 77 | + ' emin=0.1 emax=100.0 enumbins=20 nxpix=200 nypix=200'+ \ | |
| 78 | + ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \ | |
| 79 | + ' xref=83.63 yref=22.01'+ \ | |
| 80 | + ' logfile="ctmodel_cmd1.log" chatter=1' | |
| 81 | + | |
| 82 | + # Execute ctmodel, make sure we catch any exception | |
| 96 | 83 | try: |
| 97 | - model.run() | |
| 98 | - self.test_try_success() | |
| 99 | - #except Exception as e: | |
| 100 | - # msg = "Exception occured in ctmodel: %s." % (e,) | |
| 84 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 101 | 85 | except: |
| 102 | - msg = "Exception occured in ctmodel." | |
| 103 | - self.test_try_failure(msg) | |
| 86 | + pass | |
| 87 | + | |
| 88 | + # Check if execution was successful | |
| 89 | + self.test_assert(rc == 0, | |
| 90 | + 'Successful ctmodel execution on command line') | |
| 91 | + | |
| 92 | + # Check result file | |
| 93 | + self._check_result_file('ctmodel_cmd1.fits') | |
| 104 | 94 | |
| 105 | - # Save counts cube | |
| 106 | - self.test_try("Save model cube") | |
| 95 | + # Setup ctmodel command | |
| 96 | + cmd = ctmodel+' incube="NONE" inobs="NONE" expcube="NONE"'+\ | |
| 97 | + ' psfcube="NONE" bkgcube="NONE"'+ \ | |
| 98 | + ' outcube="ctmodel_cmd2.fits"'+ \ | |
| 99 | + ' inmodel="model_that_does_not_exist.xml"'+ \ | |
| 100 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 101 | + ' rad=5.0 ra=83.63 dec=22.01 tmin=0.0 tmax=1800'+ \ | |
| 102 | + ' emin=0.1 emax=100.0 enumbins=20 nxpix=200 nypix=200'+ \ | |
| 103 | + ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \ | |
| 104 | + ' xref=83.63 yref=22.01'+ \ | |
| 105 | + ' logfile="ctmodel_cmd2.log" chatter=1' | |
| 106 | + | |
| 107 | + # Execute ctmodel, make sure we catch any exception | |
| 107 | 108 | try: |
| 108 | - model.save() | |
| 109 | - self.test_try_success() | |
| 110 | - #except Exception as e: | |
| 111 | - # msg = "Exception occured in saving model cube: %s." % (e,) | |
| 109 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 112 | 110 | except: |
| 113 | - msg = "Exception occured in saving model cube." | |
| 114 | - self.test_try_failure(msg) | |
| 111 | + pass | |
| 112 | + | |
| 113 | + # Check if execution failed | |
| 114 | + self.test_assert(rc != 0, | |
| 115 | + 'Failure of ctmodel execution on command line') | |
| 116 | + | |
| 117 | + # Return | |
| 118 | + return | |
| 119 | + | |
| 120 | + # Test ctmodel from Python | |
| 121 | + def _test_python(self): | |
| 122 | + """ | |
| 123 | + Test ctmodel from Python. | |
| 124 | + """ | |
| 125 | + # Set-up ctmodel from scratch | |
| 126 | + model = ctools.ctmodel() | |
| 127 | + model['incube'] = 'NONE' | |
| 128 | + model['outcube'] = 'ctmodel_py1.fits' | |
| 129 | + model['inmodel'] = 'data/crab.xml' | |
| 130 | + model['inobs'] = 'NONE' | |
| 131 | + model['expcube'] = 'NONE' | |
| 132 | + model['psfcube'] = 'NONE' | |
| 133 | + model['bkgcube'] = 'NONE' | |
| 134 | + model['caldb'] = 'prod2' | |
| 135 | + model['irf'] = 'South_0.5h' | |
| 136 | + model['rad'] = 5 | |
| 137 | + model['ra'] = 83.63 | |
| 138 | + model['dec'] = 22.01 | |
| 139 | + model['tmin'] = 0 | |
| 140 | + model['tmax'] = 1800 | |
| 141 | + model['emin'] = 0.1 | |
| 142 | + model['emax'] = 100 | |
| 143 | + model['enumbins'] = 20 | |
| 144 | + model['nxpix'] = 200 | |
| 145 | + model['nypix'] = 200 | |
| 146 | + model['binsz'] = 0.02 | |
| 147 | + model['coordsys'] = 'CEL' | |
| 148 | + model['proj'] = 'CAR' | |
| 149 | + model['xref'] = 83.63 | |
| 150 | + model['yref'] = 22.01 | |
| 151 | + model['logfile'] = 'ctmodel_py1.log' | |
| 152 | + model['chatter'] = 2 | |
| 153 | + | |
| 154 | + # Run ctmodel tool | |
| 155 | + model.logFileOpen() # Make sure we get a log file | |
| 156 | + model.run() | |
| 157 | + model.save() | |
| 158 | + | |
| 159 | + # Check result file | |
| 160 | + self._check_result_file('ctmodel_py1.fits') | |
| 161 | + | |
| 162 | + # Return | |
| 163 | + return | |
| 164 | + | |
| 165 | + # Check result file | |
| 166 | + def _check_result_file(self, filename): | |
| 167 | + """ | |
| 168 | + Check result file. | |
| 169 | + """ | |
| 170 | + # Open result file | |
| 171 | + fits = gammalib.GFits(filename) | |
| 172 | + | |
| 173 | + # Get HDUs | |
| 174 | + cube = fits['Primary'] | |
| 175 | + ebounds = fits['EBOUNDS'] | |
| 176 | + gti = fits['GTI'] | |
| 177 | + | |
| 178 | + # Check dimensions | |
| 179 | + self.test_value(cube.naxis(), 3, 'Check for 3 cube dimensions') | |
| 180 | + self.test_value(cube.naxes(0), 200, 'Check for 200 pixels in X') | |
| 181 | + self.test_value(cube.naxes(1), 200, 'Check for 200 pixels in Y') | |
| 182 | + self.test_value(cube.naxes(2), 20, 'Check for 20 pixels in Z') | |
| 115 | 183 | |
| 116 | 184 | # Return |
| 117 | 185 | return | ... | ... |
test/test_ctpsfcube.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,11 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.caldb = "irf" | |
| 43 | - self.irf = "cta_dummy_irf" | |
| 44 | - | |
| 45 | 41 | # Return |
| 46 | 42 | return |
| 47 | 43 | |
| ... | ... | @@ -51,61 +47,123 @@ class Test(gammalib.GPythonTestSuite): |
| 51 | 47 | Set all test functions. |
| 52 | 48 | """ |
| 53 | 49 | # Set test name |
| 54 | - self.name("ctpsfcube") | |
| 50 | + self.name('ctpsfcube') | |
| 55 | 51 | |
| 56 | 52 | # Append tests |
| 57 | - self.append(self.test_functional, "Test ctpsfcube functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctpsfcube on command line') | |
| 54 | + self.append(self._test_python, 'Test ctpsfcube from Python') | |
| 58 | 55 | |
| 59 | 56 | # Return |
| 60 | 57 | return |
| 61 | 58 | |
| 62 | - # Test ctpsfcube functionnality | |
| 63 | - def test_functional(self): | |
| 59 | + # Test ctpsfcube on command line | |
| 60 | + def _test_cmd(self): | |
| 64 | 61 | """ |
| 65 | - Test ctpsfcube functionnality. | |
| 62 | + Test ctpsfcube on the command line. | |
| 66 | 63 | """ |
| 67 | - # Set-up ctpsfcube | |
| 68 | - psfcube = ctools.ctpsfcube() | |
| 69 | - psfcube["inobs"] = self.events_name | |
| 70 | - psfcube["incube"] = "NONE" | |
| 71 | - psfcube["outcube"] = "psfcube.fits" | |
| 72 | - psfcube["caldb"] = self.caldb | |
| 73 | - psfcube["irf"] = self.irf | |
| 74 | - psfcube["ebinalg"] = "LOG" | |
| 75 | - psfcube["emin"] = 0.1 | |
| 76 | - psfcube["emax"] = 100 | |
| 77 | - psfcube["enumbins"] = 20 | |
| 78 | - psfcube["nxpix"] = 10 | |
| 79 | - psfcube["nypix"] = 10 | |
| 80 | - psfcube["binsz"] = 0.4 | |
| 81 | - psfcube["coordsys"] = "CEL" | |
| 82 | - psfcube["proj"] = "CAR" | |
| 83 | - psfcube["xref"] = 83.63 | |
| 84 | - psfcube["yref"] = 22.01 | |
| 85 | - psfcube["amax"] = 0.3 | |
| 86 | - psfcube["anumbins"] = 10 | |
| 87 | - | |
| 88 | - # Run tool | |
| 89 | - self.test_try("Run ctpsfcube") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctpsfcube = '../src/ctpsfcube/ctpsfcube' | |
| 67 | + else: | |
| 68 | + ctpsfcube = 'ctpsfcube' | |
| 69 | + | |
| 70 | + # Setup ctpsfcube command | |
| 71 | + cmd = ctpsfcube+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' incube="NONE"'+ \ | |
| 73 | + ' outcube="ctpsfcube_cmd1.fits"'+ \ | |
| 74 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 75 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 76 | + ' nxpix=200 nypix=200 binsz=0.02'+ \ | |
| 77 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 78 | + ' amax=0.3 anumbins=10'+ \ | |
| 79 | + ' logfile="ctpsfcube_cmd1.log" chatter=1' | |
| 80 | + | |
| 81 | + # Execute ctpsfcube, make sure we catch any exception | |
| 90 | 82 | try: |
| 91 | - psfcube.run() | |
| 92 | - self.test_try_success() | |
| 93 | - #except Exception as e: | |
| 94 | - # msg = "Exception occured in ctpsfcube: %s." % (e,) | |
| 83 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 95 | 84 | except: |
| 96 | - msg = "Exception occured in ctpsfcube." | |
| 97 | - self.test_try_failure(msg) | |
| 85 | + pass | |
| 86 | + | |
| 87 | + # Check if execution was successful | |
| 88 | + self.test_assert(rc == 0, | |
| 89 | + 'Successful ctpsfcube execution on command line') | |
| 90 | + | |
| 91 | + # Check result file | |
| 92 | + self._check_result_file('ctpsfcube_cmd1.fits') | |
| 98 | 93 | |
| 99 | - # Save PSF cube | |
| 100 | - self.test_try("Save PSF cube") | |
| 94 | + # Setup ctpsfcube command | |
| 95 | + cmd = ctpsfcube+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 96 | + ' incube="NONE"'+ \ | |
| 97 | + ' outcube="ctpsfcube_cmd2.fits"'+ \ | |
| 98 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 99 | + ' ebinalg="LOG" emin=0.1 emax=100.0 enumbins=20'+ \ | |
| 100 | + ' nxpix=200 nypix=200 binsz=0.02'+ \ | |
| 101 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 102 | + ' amax=0.3 anumbins=10'+ \ | |
| 103 | + ' logfile="ctpsfcube_cmd2.log" chatter=1' | |
| 104 | + | |
| 105 | + # Execute ctpsfcube, make sure we catch any exception | |
| 101 | 106 | try: |
| 102 | - psfcube.save() | |
| 103 | - self.test_try_success() | |
| 104 | - #except Exception as e: | |
| 105 | - # msg = "Exception occured in saving PSF cube: %s." % (e,) | |
| 107 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 106 | 108 | except: |
| 107 | - msg = "Exception occured in saving PSF cubes." | |
| 108 | - self.test_try_failure(msg) | |
| 109 | + pass | |
| 110 | + | |
| 111 | + # Check if execution failed | |
| 112 | + self.test_assert(rc != 0, | |
| 113 | + 'Failure of ctpsfcube execution on command line') | |
| 114 | + | |
| 115 | + # Return | |
| 116 | + return | |
| 117 | + | |
| 118 | + # Test ctpsfcube from Python | |
| 119 | + def _test_python(self): | |
| 120 | + """ | |
| 121 | + Test ctpsfcube from Python. | |
| 122 | + """ | |
| 123 | + # Set-up ctpsfcube | |
| 124 | + psfcube = ctools.ctpsfcube() | |
| 125 | + psfcube['inobs'] = 'data/crab_events.fits' | |
| 126 | + psfcube['incube'] = 'NONE' | |
| 127 | + psfcube['outcube'] = 'ctpsfcube_py1.fits' | |
| 128 | + psfcube['caldb'] = 'prod2' | |
| 129 | + psfcube['irf'] = 'South_0.5h' | |
| 130 | + psfcube['ebinalg'] = 'LOG' | |
| 131 | + psfcube['emin'] = 0.1 | |
| 132 | + psfcube['emax'] = 100 | |
| 133 | + psfcube['enumbins'] = 20 | |
| 134 | + psfcube['nxpix'] = 10 | |
| 135 | + psfcube['nypix'] = 10 | |
| 136 | + psfcube['binsz'] = 0.4 | |
| 137 | + psfcube['coordsys'] = 'CEL' | |
| 138 | + psfcube['proj'] = 'CAR' | |
| 139 | + psfcube['xref'] = 83.63 | |
| 140 | + psfcube['yref'] = 22.01 | |
| 141 | + psfcube['amax'] = 0.3 | |
| 142 | + psfcube['anumbins'] = 10 | |
| 143 | + psfcube['logfile'] = 'ctpsfcube_py1.log' | |
| 144 | + psfcube['chatter'] = 2 | |
| 145 | + | |
| 146 | + # Run ctpsfcube tool | |
| 147 | + psfcube.logFileOpen() # Make sure we get a log file | |
| 148 | + psfcube.run() | |
| 149 | + psfcube.save() | |
| 150 | + | |
| 151 | + # Check result file | |
| 152 | + self._check_result_file('ctpsfcube_py1.fits') | |
| 153 | + | |
| 154 | + # Return | |
| 155 | + return | |
| 156 | + | |
| 157 | + # Check result file | |
| 158 | + def _check_result_file(self, filename): | |
| 159 | + """ | |
| 160 | + Check result file. | |
| 161 | + """ | |
| 162 | + # Open result file | |
| 163 | + result = gammalib.GCTACubePsf(filename) | |
| 164 | + | |
| 165 | + # Check dimensions | |
| 166 | + self.test_value(len(result.energies()), 21, 'Check for 21 energy values') | |
| 109 | 167 | |
| 110 | 168 | # Return |
| 111 | 169 | return | ... | ... |
test/test_ctselect.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,9 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - | |
| 43 | 41 | # Return |
| 44 | 42 | return |
| 45 | 43 | |
| ... | ... | @@ -49,52 +47,114 @@ class Test(gammalib.GPythonTestSuite): |
| 49 | 47 | Set all test functions. |
| 50 | 48 | """ |
| 51 | 49 | # Set test name |
| 52 | - self.name("ctselect") | |
| 50 | + self.name('ctselect') | |
| 53 | 51 | |
| 54 | 52 | # Append tests |
| 55 | - self.append(self.test_functional, "Test ctselect functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctselect on command line') | |
| 54 | + self.append(self._test_python, 'Test ctselect from Python') | |
| 56 | 55 | |
| 57 | 56 | # Return |
| 58 | 57 | return |
| 59 | 58 | |
| 60 | - # Test ctselect functionnality | |
| 61 | - def test_functional(self): | |
| 59 | + # Test ctselect on command line | |
| 60 | + def _test_cmd(self): | |
| 62 | 61 | """ |
| 63 | - Test ctselect functionnality. | |
| 62 | + Test ctselect on the command line. | |
| 64 | 63 | """ |
| 65 | - # Set-up ctselect | |
| 66 | - select = ctools.ctselect() | |
| 67 | - select["inobs"] = self.events_name | |
| 68 | - select["outobs"] = "selected_events.fits" | |
| 69 | - select["ra"] = 83.63 | |
| 70 | - select["dec"] = 22.01 | |
| 71 | - select["rad"] = 3 | |
| 72 | - select["tmin"] = 0 | |
| 73 | - select["tmax"] = 1800 | |
| 74 | - select["emin"] = 0.1 | |
| 75 | - select["emax"] = 100 | |
| 76 | - | |
| 77 | - # Run tool | |
| 78 | - self.test_try("Run ctselect") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctselect = '../src/ctselect/ctselect' | |
| 67 | + else: | |
| 68 | + ctselect = 'ctselect' | |
| 69 | + | |
| 70 | + # Setup ctselect command | |
| 71 | + cmd = ctselect+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' outobs="ctselect_cmd1.fits"'+ \ | |
| 73 | + ' ra=83.63 dec=22.01 rad=3.0'+ \ | |
| 74 | + ' tmin=0.0 tmax=1800.0'+ \ | |
| 75 | + ' emin=0.1 emax=100.0'+ \ | |
| 76 | + ' logfile="ctselect_cmd1.log" chatter=1' | |
| 77 | + | |
| 78 | + # Execute ctselect, make sure we catch any exception | |
| 79 | 79 | try: |
| 80 | - select.run() | |
| 81 | - self.test_try_success() | |
| 82 | - #except Exception as e: | |
| 83 | - # msg = "Exception occured in ctselect: %s." % (e,) | |
| 80 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 84 | 81 | except: |
| 85 | - msg = "Exception occured in ctselect." | |
| 86 | - self.test_try_failure(msg) | |
| 82 | + pass | |
| 83 | + | |
| 84 | + # Check if execution was successful | |
| 85 | + self.test_assert(rc == 0, | |
| 86 | + 'Successful ctselect execution on command line') | |
| 87 | + | |
| 88 | + # Check result file | |
| 89 | + self._check_result_file('ctselect_cmd1.fits') | |
| 87 | 90 | |
| 88 | - # Save events | |
| 89 | - self.test_try("Save events") | |
| 91 | + # Setup ctselect command | |
| 92 | + cmd = ctselect+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 93 | + ' outobs="ctselect_cmd2.fits"'+ \ | |
| 94 | + ' ra=83.63 dec=22.01 rad=3.0'+ \ | |
| 95 | + ' tmin=0.0 tmax=1800.0'+ \ | |
| 96 | + ' emin=0.1 emax=100.0'+ \ | |
| 97 | + ' logfile="ctselect_cmd2.log" chatter=1' | |
| 98 | + | |
| 99 | + # Execute ctselect, make sure we catch any exception | |
| 90 | 100 | try: |
| 91 | - select.save() | |
| 92 | - self.test_try_success() | |
| 93 | - #except Exception as e: | |
| 94 | - # msg = "Exception occured in saving events: %s." % (e,) | |
| 101 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 95 | 102 | except: |
| 96 | - msg = "Exception occured in saving events." | |
| 97 | - self.test_try_failure(msg) | |
| 103 | + pass | |
| 104 | + | |
| 105 | + # Check if execution failed | |
| 106 | + self.test_assert(rc != 0, | |
| 107 | + 'Failure of ctselect execution on command line') | |
| 108 | + | |
| 109 | + # Return | |
| 110 | + return | |
| 111 | + | |
| 112 | + # Test ctselect from Python | |
| 113 | + def _test_python(self): | |
| 114 | + """ | |
| 115 | + Test ctselect from Python. | |
| 116 | + """ | |
| 117 | + # Set-up ctselect | |
| 118 | + select = ctools.ctselect() | |
| 119 | + select['inobs'] = 'data/crab_events.fits' | |
| 120 | + select['outobs'] = 'ctselect_py1.fits' | |
| 121 | + select['ra'] = 83.63 | |
| 122 | + select['dec'] = 22.01 | |
| 123 | + select['rad'] = 3 | |
| 124 | + select['tmin'] = 0 | |
| 125 | + select['tmax'] = 1800 | |
| 126 | + select['emin'] = 0.1 | |
| 127 | + select['emax'] = 100 | |
| 128 | + select['logfile'] = 'ctselect_py1.log' | |
| 129 | + select['chatter'] = 2 | |
| 130 | + | |
| 131 | + # Run ctselect tool | |
| 132 | + select.logFileOpen() # Make sure we get a log file | |
| 133 | + select.run() | |
| 134 | + select.save() | |
| 135 | + | |
| 136 | + # Check result file | |
| 137 | + self._check_result_file('ctselect_py1.fits') | |
| 138 | + | |
| 139 | + # Return | |
| 140 | + return | |
| 141 | + | |
| 142 | + # Check result file | |
| 143 | + def _check_result_file(self, filename): | |
| 144 | + """ | |
| 145 | + Check result file. | |
| 146 | + """ | |
| 147 | + # Open result file | |
| 148 | + result = gammalib.GCTAEventList(filename) | |
| 149 | + | |
| 150 | + # Check file | |
| 151 | + self.test_value(result.size(), 6127, 'Check for 6127 events') | |
| 152 | + self.test_value(result.roi().centre().dir().ra_deg(), 83.63, 1.0e-6, | |
| 153 | + 'Check for ROI Right Ascension') | |
| 154 | + self.test_value(result.roi().centre().dir().dec_deg(), 22.01, 1.0e-6, | |
| 155 | + 'Check for ROI Declination') | |
| 156 | + self.test_value(result.roi().radius(), 3.0, 1.0e-6, | |
| 157 | + 'Check for ROI Radius') | |
| 98 | 158 | |
| 99 | 159 | # Return |
| 100 | 160 | return | ... | ... |
test/test_ctskymap.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,9 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - | |
| 43 | 41 | # Return |
| 44 | 42 | return |
| 45 | 43 | |
| ... | ... | @@ -49,54 +47,112 @@ class Test(gammalib.GPythonTestSuite): |
| 49 | 47 | Set all test functions. |
| 50 | 48 | """ |
| 51 | 49 | # Set test name |
| 52 | - self.name("ctskymap") | |
| 50 | + self.name('ctskymap') | |
| 53 | 51 | |
| 54 | 52 | # Append tests |
| 55 | - self.append(self.test_functional, "Test ctskymap functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctskymap on command line') | |
| 54 | + self.append(self._test_python, 'Test ctskymap from Python') | |
| 56 | 55 | |
| 57 | 56 | # Return |
| 58 | 57 | return |
| 59 | 58 | |
| 60 | - # Test ctskymap functionnality | |
| 61 | - def test_functional(self): | |
| 59 | + # Test ctskymap on command line | |
| 60 | + def _test_cmd(self): | |
| 62 | 61 | """ |
| 63 | - Test ctskymap functionnality. | |
| 62 | + Test ctskymap on the command line. | |
| 64 | 63 | """ |
| 65 | - # Set-up ctskymap | |
| 66 | - skymap = ctools.ctskymap() | |
| 67 | - skymap["inobs"] = self.events_name | |
| 68 | - skymap["outmap"] = "skymap.fits" | |
| 69 | - skymap["emin"] = 0.1 | |
| 70 | - skymap["emax"] = 100 | |
| 71 | - skymap["nxpix"] = 200 | |
| 72 | - skymap["nypix"] = 200 | |
| 73 | - skymap["binsz"] = 0.02 | |
| 74 | - skymap["coordsys"] = "CEL" | |
| 75 | - skymap["proj"] = "CAR" | |
| 76 | - skymap["xref"] = 83.63 | |
| 77 | - skymap["yref"] = 22.01 | |
| 78 | - | |
| 79 | - # Run tool | |
| 80 | - self.test_try("Run ctskymap") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctskymap = '../src/ctskymap/ctskymap' | |
| 67 | + else: | |
| 68 | + ctskymap = 'ctskymap' | |
| 69 | + | |
| 70 | + # Setup ctskymap command | |
| 71 | + cmd = ctskymap+' inobs="data/crab_events.fits"'+\ | |
| 72 | + ' outmap="ctskymap_cmd1.fits"'+ \ | |
| 73 | + ' emin=0.1 emax=100.0 nxpix=200 nypix=200'+ \ | |
| 74 | + ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \ | |
| 75 | + ' xref=83.63 yref=22.01'+ \ | |
| 76 | + ' logfile="ctskymap_cmd1.log" chatter=1' | |
| 77 | + | |
| 78 | + # Execute ctskymap, make sure we catch any exception | |
| 81 | 79 | try: |
| 82 | - skymap.run() | |
| 83 | - self.test_try_success() | |
| 84 | - #except Exception as e: | |
| 85 | - # msg = "Exception occured in ctskymap: %s." % (e,) | |
| 80 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 86 | 81 | except: |
| 87 | - msg = "Exception occured in ctskymap." | |
| 88 | - self.test_try_failure(msg) | |
| 82 | + pass | |
| 83 | + | |
| 84 | + # Check if execution was successful | |
| 85 | + self.test_assert(rc == 0, | |
| 86 | + 'Successful ctskymap execution on command line') | |
| 87 | + | |
| 88 | + # Check result file | |
| 89 | + self._check_result_file('ctskymap_cmd1.fits') | |
| 89 | 90 | |
| 90 | - # Save counts cube | |
| 91 | - self.test_try("Save sky map") | |
| 91 | + # Setup ctskymap command | |
| 92 | + cmd = ctskymap+' inobs="event_file_that_does_not_exist.fits"'+\ | |
| 93 | + ' outmap="ctskymap_cmd2.fits"'+ \ | |
| 94 | + ' emin=0.1 emax=100.0 nxpix=200 nypix=200'+ \ | |
| 95 | + ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \ | |
| 96 | + ' xref=83.63 yref=22.01'+ \ | |
| 97 | + ' logfile="ctskymap_cmd2.log" chatter=2' | |
| 98 | + | |
| 99 | + # Execute ctskymap, make sure we catch any exception | |
| 92 | 100 | try: |
| 93 | - skymap.save() | |
| 94 | - self.test_try_success() | |
| 95 | - #except Exception as e: | |
| 96 | - # msg = "Exception occured in saving sky map: %s." % (e,) | |
| 101 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 97 | 102 | except: |
| 98 | - msg = "Exception occured in saving sky map." | |
| 99 | - self.test_try_failure(msg) | |
| 103 | + pass | |
| 104 | + | |
| 105 | + # Check if execution failed | |
| 106 | + self.test_assert(rc != 0, | |
| 107 | + 'Failure of ctskymap execution on command line') | |
| 108 | + | |
| 109 | + # Return | |
| 110 | + return | |
| 111 | + | |
| 112 | + # Test ctskymap from Python | |
| 113 | + def _test_python(self): | |
| 114 | + """ | |
| 115 | + Test ctskymap from Python. | |
| 116 | + """ | |
| 117 | + # Set-up ctskymap | |
| 118 | + skymap = ctools.ctskymap() | |
| 119 | + skymap['inobs'] = 'data/crab_events.fits' | |
| 120 | + skymap['outmap'] = 'ctskymap_py1.fits' | |
| 121 | + skymap['emin'] = 0.1 | |
| 122 | + skymap['emax'] = 100 | |
| 123 | + skymap['nxpix'] = 200 | |
| 124 | + skymap['nypix'] = 200 | |
| 125 | + skymap['binsz'] = 0.02 | |
| 126 | + skymap['coordsys'] = 'CEL' | |
| 127 | + skymap['proj'] = 'CAR' | |
| 128 | + skymap['xref'] = 83.63 | |
| 129 | + skymap['yref'] = 22.01 | |
| 130 | + skymap['logfile'] = 'ctskymap_py1.log' | |
| 131 | + skymap['chatter'] = 2 | |
| 132 | + | |
| 133 | + # Run ctskymap tool | |
| 134 | + skymap.logFileOpen() # Make sure we get a log file | |
| 135 | + skymap.run() | |
| 136 | + skymap.save() | |
| 137 | + | |
| 138 | + # Check result file | |
| 139 | + self._check_result_file('ctskymap_py1.fits') | |
| 140 | + | |
| 141 | + # Return | |
| 142 | + return | |
| 143 | + | |
| 144 | + # Check result file | |
| 145 | + def _check_result_file(self, filename): | |
| 146 | + """ | |
| 147 | + Check result file. | |
| 148 | + """ | |
| 149 | + # Open result file | |
| 150 | + result = gammalib.GSkyMap(filename) | |
| 151 | + | |
| 152 | + # Check dimensions | |
| 153 | + self.test_value(result.nmaps(), 1, 'Check for one map') | |
| 154 | + self.test_value(result.nx(), 200, 'Check for 200 pixels in X') | |
| 155 | + self.test_value(result.ny(), 200, 'Check for 200 pixels in Y') | |
| 100 | 156 | |
| 101 | 157 | # Return |
| 102 | 158 | return | ... | ... |
test/test_cttsmap.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,12 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.model_name = "data/crab.xml" | |
| 43 | - self.caldb = "irf" | |
| 44 | - self.irf = "cta_dummy_irf" | |
| 45 | - | |
| 46 | 41 | # Return |
| 47 | 42 | return |
| 48 | 43 | |
| ... | ... | @@ -52,56 +47,127 @@ class Test(gammalib.GPythonTestSuite): |
| 52 | 47 | Set all test functions. |
| 53 | 48 | """ |
| 54 | 49 | # Set test name |
| 55 | - self.name("cttsmap") | |
| 50 | + self.name('cttsmap') | |
| 56 | 51 | |
| 57 | 52 | # Append tests |
| 58 | - self.append(self.test_functional, "Test cttsmap functionality") | |
| 53 | + self.append(self._test_cmd, 'Test cttsmap on command line') | |
| 54 | + self.append(self._test_python, 'Test cttsmap from Python') | |
| 59 | 55 | |
| 60 | 56 | # Return |
| 61 | 57 | return |
| 62 | 58 | |
| 63 | - # Test cttsmap functionnality | |
| 64 | - def test_functional(self): | |
| 59 | + # Test cttsmap on command line | |
| 60 | + def _test_cmd(self): | |
| 65 | 61 | """ |
| 66 | - Test cttsmap functionality. | |
| 62 | + Test cttsmap on the command line. | |
| 67 | 63 | """ |
| 68 | - # Set-up cttsmap | |
| 69 | - tsmap = ctools.cttsmap() | |
| 70 | - tsmap["inobs"] = self.events_name | |
| 71 | - tsmap["inmodel"] = self.model_name | |
| 72 | - tsmap["srcname"] = "Crab" | |
| 73 | - tsmap["caldb"] = self.caldb | |
| 74 | - tsmap["irf"] = self.irf | |
| 75 | - tsmap["outmap"] = "tsmap.fits" | |
| 76 | - tsmap["nxpix"] = 5 | |
| 77 | - tsmap["nypix"] = 5 | |
| 78 | - tsmap["binsz"] = 0.02 | |
| 79 | - tsmap["coordsys"] = "CEL" | |
| 80 | - tsmap["proj"] = "CAR" | |
| 81 | - tsmap["xref"] = 83.63 | |
| 82 | - tsmap["yref"] = 22.01 | |
| 83 | - | |
| 84 | - # Run tool | |
| 85 | - self.test_try("Run cttsmap") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + cttsmap = '../src/cttsmap/cttsmap' | |
| 67 | + else: | |
| 68 | + cttsmap = 'cttsmap' | |
| 69 | + | |
| 70 | + # Setup cttsmap command | |
| 71 | + cmd = cttsmap+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 73 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 74 | + ' outmap="cttsmap_cmd1.fits"'+ \ | |
| 75 | + ' nxpix=5 nypix=5 binsz=0.02'+ \ | |
| 76 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 77 | + ' logfile="cttsmap_cmd1.log" chatter=1' | |
| 78 | + | |
| 79 | + # Execute cttsmap, make sure we catch any exception | |
| 86 | 80 | try: |
| 87 | - tsmap.run() | |
| 88 | - self.test_try_success() | |
| 89 | - #except Exception as e: | |
| 90 | - # msg = "Exception occured in cttsmap: %s." % (e,) | |
| 81 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 91 | 82 | except: |
| 92 | - msg = "Exception occured in cttsmap." | |
| 93 | - self.test_try_failure(msg) | |
| 83 | + pass | |
| 84 | + | |
| 85 | + # Check if execution was successful | |
| 86 | + self.test_assert(rc == 0, | |
| 87 | + 'Successful cttsmap execution on command line') | |
| 88 | + | |
| 89 | + # Check result file | |
| 90 | + self._check_result_file('cttsmap_cmd1.fits') | |
| 94 | 91 | |
| 95 | - # Save results | |
| 96 | - self.test_try("Save results") | |
| 92 | + # Setup cttsmap command | |
| 93 | + cmd = cttsmap+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 94 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 95 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 96 | + ' outmap="cttsmap_cmd2.fits"'+ \ | |
| 97 | + ' nxpix=5 nypix=5 binsz=0.02'+ \ | |
| 98 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | |
| 99 | + ' logfile="cttsmap_cmd2.log" chatter=2' | |
| 100 | + | |
| 101 | + # Execute cttsmap, make sure we catch any exception | |
| 97 | 102 | try: |
| 98 | - tsmap.save() | |
| 99 | - self.test_try_success() | |
| 100 | - #except Exception as e: | |
| 101 | - # msg = "Exception occured in saving results: %s." % (e,) | |
| 103 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 102 | 104 | except: |
| 103 | - msg = "Exception occured in saving results." | |
| 104 | - self.test_try_failure(msg) | |
| 105 | + pass | |
| 106 | + | |
| 107 | + # Check if execution failed | |
| 108 | + self.test_assert(rc != 0, | |
| 109 | + 'Failure of cttsmap execution on command line') | |
| 110 | + | |
| 111 | + # Return | |
| 112 | + return | |
| 113 | + | |
| 114 | + # Test cttsmap from Python | |
| 115 | + def _test_python(self): | |
| 116 | + """ | |
| 117 | + Test cttsmap from Python. | |
| 118 | + """ | |
| 119 | + # Set-up cttsmap | |
| 120 | + tsmap = ctools.cttsmap() | |
| 121 | + tsmap['inobs'] = 'data/crab_events.fits' | |
| 122 | + tsmap['inmodel'] = 'data/crab.xml' | |
| 123 | + tsmap['srcname'] = 'Crab' | |
| 124 | + tsmap['caldb'] = 'prod2' | |
| 125 | + tsmap['irf'] = 'South_0.5h' | |
| 126 | + tsmap['outmap'] = 'cttsmap_py1.fits' | |
| 127 | + tsmap['nxpix'] = 5 | |
| 128 | + tsmap['nypix'] = 5 | |
| 129 | + tsmap['binsz'] = 0.02 | |
| 130 | + tsmap['coordsys'] = 'CEL' | |
| 131 | + tsmap['proj'] = 'CAR' | |
| 132 | + tsmap['xref'] = 83.63 | |
| 133 | + tsmap['yref'] = 22.01 | |
| 134 | + tsmap['logfile'] = 'cttsmap_py1.log' | |
| 135 | + tsmap['chatter'] = 2 | |
| 136 | + | |
| 137 | + # Run cttsmap tool | |
| 138 | + tsmap.logFileOpen() # Make sure we get a log file | |
| 139 | + tsmap.run() | |
| 140 | + tsmap.save() | |
| 141 | + | |
| 142 | + # Check result file | |
| 143 | + self._check_result_file('cttsmap_py1.fits') | |
| 144 | + | |
| 145 | + # Return | |
| 146 | + return | |
| 147 | + | |
| 148 | + # Check result file | |
| 149 | + def _check_result_file(self, filename): | |
| 150 | + """ | |
| 151 | + Check result file. | |
| 152 | + """ | |
| 153 | + # Open result file | |
| 154 | + fits = gammalib.GFits(filename) | |
| 155 | + | |
| 156 | + # Get HDUs | |
| 157 | + ts = fits['Primary'] | |
| 158 | + prefactor = fits['Prefactor'] | |
| 159 | + index = fits['Index'] | |
| 160 | + | |
| 161 | + # Check dimensions | |
| 162 | + self.test_value(ts.naxis(), 2, 'Check for 2 dimensions') | |
| 163 | + self.test_value(ts.naxes(0), 5, 'Check for 5 pixels in X') | |
| 164 | + self.test_value(ts.naxes(1), 5, 'Check for 5 pixels in Y') | |
| 165 | + self.test_value(prefactor.naxis(), 2, 'Check for 2 dimensions') | |
| 166 | + self.test_value(prefactor.naxes(0), 5, 'Check for 5 pixels in X') | |
| 167 | + self.test_value(prefactor.naxes(1), 5, 'Check for 5 pixels in Y') | |
| 168 | + self.test_value(index.naxis(), 2, 'Check for 2 dimensions') | |
| 169 | + self.test_value(index.naxes(0), 5, 'Check for 5 pixels in X') | |
| 170 | + self.test_value(index.naxes(1), 5, 'Check for 5 pixels in Y') | |
| 105 | 171 | |
| 106 | 172 | # Return |
| 107 | 173 | return | ... | ... |
test/test_ctulimit.py
| ... | ... | @@ -18,6 +18,7 @@ |
| 18 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | # |
| 20 | 20 | # ========================================================================== |
| 21 | +import os | |
| 21 | 22 | import gammalib |
| 22 | 23 | import ctools |
| 23 | 24 | |
| ... | ... | @@ -37,12 +38,6 @@ class Test(gammalib.GPythonTestSuite): |
| 37 | 38 | # Call base class constructor |
| 38 | 39 | gammalib.GPythonTestSuite.__init__(self) |
| 39 | 40 | |
| 40 | - # Set members | |
| 41 | - self.events_name = "data/crab_events.fits" | |
| 42 | - self.model_name = "data/crab.xml" | |
| 43 | - self.caldb = "irf" | |
| 44 | - self.irf = "cta_dummy_irf" | |
| 45 | - | |
| 46 | 41 | # Return |
| 47 | 42 | return |
| 48 | 43 | |
| ... | ... | @@ -52,48 +47,94 @@ class Test(gammalib.GPythonTestSuite): |
| 52 | 47 | Set all test functions. |
| 53 | 48 | """ |
| 54 | 49 | # Set test name |
| 55 | - self.name("ctulimit") | |
| 50 | + self.name('ctulimit') | |
| 56 | 51 | |
| 57 | 52 | # Append tests |
| 58 | - self.append(self.test_functional, "Test ctulimit functionality") | |
| 53 | + self.append(self._test_cmd, 'Test ctulimit on command line') | |
| 54 | + self.append(self._test_python, 'Test ctulimit from Python') | |
| 59 | 55 | |
| 60 | 56 | # Return |
| 61 | 57 | return |
| 62 | 58 | |
| 63 | - # Test cttsmap functionnality | |
| 64 | - def test_functional(self): | |
| 59 | + # Test ctulimit on command line | |
| 60 | + def _test_cmd(self): | |
| 65 | 61 | """ |
| 66 | - Test ctulimit functionnality. | |
| 62 | + Test ctulimit on the command line. | |
| 67 | 63 | """ |
| 68 | - # Set-up cttsmap | |
| 69 | - ulimit = ctools.ctulimit() | |
| 70 | - ulimit["inobs"] = self.events_name | |
| 71 | - ulimit["inmodel"] = self.model_name | |
| 72 | - ulimit["srcname"] = "Crab" | |
| 73 | - ulimit["caldb"] = self.caldb | |
| 74 | - ulimit["irf"] = self.irf | |
| 75 | - | |
| 76 | - # Run tool | |
| 77 | - self.test_try("Run ctulimit") | |
| 64 | + # Kluge to set the command (installed version has no README file) | |
| 65 | + if os.path.isfile('README'): | |
| 66 | + ctulimit = '../src/ctulimit/ctulimit' | |
| 67 | + else: | |
| 68 | + ctulimit = 'ctulimit' | |
| 69 | + | |
| 70 | + # Setup ctulimit command | |
| 71 | + cmd = ctulimit+' inobs="data/crab_events.fits"'+ \ | |
| 72 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 73 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 74 | + ' logfile="ctulimit_cmd1.log" chatter=1' | |
| 75 | + | |
| 76 | + # Execute ctulimit, make sure we catch any exception | |
| 78 | 77 | try: |
| 79 | - ulimit.run() | |
| 80 | - self.test_try_success() | |
| 81 | - #except Exception as e: | |
| 82 | - # msg = "Exception occured in ctulimit: %s." % (e,) | |
| 78 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 83 | 79 | except: |
| 84 | - msg = "Exception occured in ctulimit." | |
| 85 | - self.test_try_failure(msg) | |
| 80 | + pass | |
| 81 | + | |
| 82 | + # Check if execution was successful | |
| 83 | + self.test_assert(rc == 0, | |
| 84 | + 'Successful ctulimit execution on command line') | |
| 85 | + | |
| 86 | + # Check result file | |
| 87 | + self._check_result_file('ctulimit_cmd1.log') | |
| 86 | 88 | |
| 87 | - # Save results | |
| 88 | - self.test_try("Save results") | |
| 89 | + # Setup ctulimit command | |
| 90 | + cmd = ctulimit+' inobs="event_file_that_does_not_exist.fits"'+ \ | |
| 91 | + ' inmodel="data/crab.xml" srcname="Crab"'+ \ | |
| 92 | + ' caldb="prod2" irf="South_0.5h"'+ \ | |
| 93 | + ' logfile="ctulimit_cmd2.log" chatter=1' | |
| 94 | + | |
| 95 | + # Execute ctulimit, make sure we catch any exception | |
| 89 | 96 | try: |
| 90 | - ulimit.save() | |
| 91 | - self.test_try_success() | |
| 92 | - #except Exception as e: | |
| 93 | - # msg = "Exception occured in saving results: %s." % (e,) | |
| 97 | + rc = os.system(cmd+' >/dev/null 2>&1') | |
| 94 | 98 | except: |
| 95 | - msg = "Exception occured in saving results." | |
| 96 | - self.test_try_failure(msg) | |
| 99 | + pass | |
| 100 | + | |
| 101 | + # Check if execution failed | |
| 102 | + self.test_assert(rc != 0, | |
| 103 | + 'Failure of ctulimit execution on command line') | |
| 104 | + | |
| 105 | + # Return | |
| 106 | + return | |
| 97 | 107 | |
| 108 | + # Test ctulimit from Python | |
| 109 | + def _test_python(self): | |
| 110 | + """ | |
| 111 | + Test ctulimit from Python. | |
| 112 | + """ | |
| 113 | + # Set-up ctulimit | |
| 114 | + ulimit = ctools.ctulimit() | |
| 115 | + ulimit['inobs'] = 'data/crab_events.fits' | |
| 116 | + ulimit['inmodel'] = 'data/crab.xml' | |
| 117 | + ulimit['srcname'] = 'Crab' | |
| 118 | + ulimit['caldb'] = 'prod2' | |
| 119 | + ulimit['irf'] = 'South_0.5h' | |
| 120 | + ulimit['logfile'] = 'ctulimit_py1.log' | |
| 121 | + ulimit['chatter'] = 2 | |
| 122 | + | |
| 123 | + # Run ctulimit tool | |
| 124 | + ulimit.logFileOpen() # Make sure we get a log file | |
| 125 | + ulimit.run() | |
| 126 | + ulimit.save() | |
| 127 | + | |
| 128 | + # Check result file | |
| 129 | + self._check_result_file('ctulimit_py1.log') | |
| 130 | + | |
| 131 | + # Return | |
| 132 | + return | |
| 133 | + | |
| 134 | + # Check result file | |
| 135 | + def _check_result_file(self, filename): | |
| 136 | + """ | |
| 137 | + Check result file. | |
| 138 | + """ | |
| 98 | 139 | # Return |
| 99 | 140 | return | ... | ... |
test/test_python_cscripts.py
| ... | ... | @@ -32,11 +32,16 @@ import test_csobs2caldb |
| 32 | 32 | import test_csobsdef |
| 33 | 33 | import test_csobsinfo |
| 34 | 34 | import test_cspull |
| 35 | +import test_csresmap | |
| 35 | 36 | import test_csroot2caldb |
| 37 | +import test_cssens | |
| 38 | +import test_csspec | |
| 39 | +import test_cstsdist | |
| 40 | +import test_cstsmapmerge | |
| 41 | +import test_csworkflow | |
| 36 | 42 | import test_csiactcopy |
| 37 | 43 | import test_csiactdata |
| 38 | 44 | import test_csiactobs |
| 39 | -import test_csworkflow | |
| 40 | 45 | |
| 41 | 46 | |
| 42 | 47 | # ================== # |
| ... | ... | @@ -45,6 +50,13 @@ import test_csworkflow |
| 45 | 50 | def test(installed=False, debug=False): |
| 46 | 51 | """ |
| 47 | 52 | Perform cscripts unit testing. |
| 53 | + | |
| 54 | + Parameters | |
| 55 | + ---------- | |
| 56 | + installed : bool, optional | |
| 57 | + Flag indicating whether the script has been installed or not | |
| 58 | + debug : bool, optional | |
| 59 | + Enables debugging | |
| 48 | 60 | """ |
| 49 | 61 | # If we have an installed version then create a temporary directory and |
| 50 | 62 | # copy over all information that is needed |
| ... | ... | @@ -61,29 +73,29 @@ def test(installed=False, debug=False): |
| 61 | 73 | dirname = os.path.dirname(testdir) |
| 62 | 74 | |
| 63 | 75 | # Copy over test data and irf |
| 64 | - os.system("cp -r %s %s" % (dirname+"/data", "data")) | |
| 65 | - os.system("cp -r %s %s" % (dirname+"/iactdata", "iactdata")) | |
| 66 | - os.system("cp -r %s %s" % (dirname+"/irf", "irf")) | |
| 76 | + os.system('cp -r %s %s' % (dirname+'/data', 'data')) | |
| 77 | + os.system('cp -r %s %s' % (dirname+'/iactdata', 'iactdata')) | |
| 78 | + os.system('cp -r %s %s' % (dirname+'/irf', 'irf')) | |
| 67 | 79 | |
| 68 | 80 | # ... otherwise set the calibration database |
| 69 | 81 | else: |
| 70 | - os.environ['CALDB'] = "../caldb" | |
| 82 | + os.environ['CALDB'] = '../caldb' | |
| 71 | 83 | |
| 72 | 84 | # Set PFILES environment variable |
| 73 | 85 | try: |
| 74 | - os.mkdir("pfiles") | |
| 86 | + os.mkdir('pfiles') | |
| 75 | 87 | except: |
| 76 | 88 | pass |
| 77 | - os.environ['PFILES'] = "pfiles" | |
| 89 | + os.environ['PFILES'] = 'pfiles' | |
| 78 | 90 | |
| 79 | 91 | # Copy over pfiles |
| 80 | 92 | if not installed: |
| 81 | - os.system("cp -r ../cscripts/*.par pfiles/") | |
| 93 | + os.system('cp -r ../cscripts/*.par pfiles/') | |
| 82 | 94 | else: |
| 83 | - os.system("cp -r %s/syspfiles/*.par pfiles/" % (os.environ['CTOOLS'])) | |
| 95 | + os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS'])) | |
| 84 | 96 | |
| 85 | 97 | # Allocate test suite container |
| 86 | - suites = gammalib.GTestSuites("cscripts unit testing") | |
| 98 | + suites = gammalib.GTestSuites('cscripts unit testing') | |
| 87 | 99 | |
| 88 | 100 | # Allocate test suites |
| 89 | 101 | suite_cscaldb = test_cscaldb.Test() |
| ... | ... | @@ -94,7 +106,12 @@ def test(installed=False, debug=False): |
| 94 | 106 | suite_csobsdef = test_csobsdef.Test() |
| 95 | 107 | suite_csobsinfo = test_csobsinfo.Test() |
| 96 | 108 | suite_cspull = test_cspull.Test() |
| 109 | + suite_csresmap = test_csresmap.Test() | |
| 97 | 110 | suite_csroot2caldb = test_csroot2caldb.Test() |
| 111 | + suite_cssens = test_cssens.Test() | |
| 112 | + suite_csspec = test_csspec.Test() | |
| 113 | + suite_cstsdist = test_cstsdist.Test() | |
| 114 | + suite_cstsmapmerge = test_cstsmapmerge.Test() | |
| 98 | 115 | suite_csworkflow = test_csworkflow.Test() |
| 99 | 116 | |
| 100 | 117 | # Setup unit tests |
| ... | ... | @@ -106,7 +123,12 @@ def test(installed=False, debug=False): |
| 106 | 123 | suite_csobsdef.set() |
| 107 | 124 | suite_csobsinfo.set() |
| 108 | 125 | suite_cspull.set() |
| 126 | + suite_csresmap.set() | |
| 109 | 127 | suite_csroot2caldb.set() |
| 128 | + suite_cssens.set() | |
| 129 | + suite_csspec.set() | |
| 130 | + suite_cstsdist.set() | |
| 131 | + suite_cstsmapmerge.set() | |
| 110 | 132 | suite_csworkflow.set() |
| 111 | 133 | |
| 112 | 134 | # Append tests to container |
| ... | ... | @@ -118,7 +140,12 @@ def test(installed=False, debug=False): |
| 118 | 140 | suites.append(suite_csobsdef) |
| 119 | 141 | suites.append(suite_csobsinfo) |
| 120 | 142 | suites.append(suite_cspull) |
| 143 | + suites.append(suite_csresmap) | |
| 121 | 144 | suites.append(suite_csroot2caldb) |
| 145 | + suites.append(suite_cssens) | |
| 146 | + suites.append(suite_csspec) | |
| 147 | + suites.append(suite_cstsdist) | |
| 148 | + suites.append(suite_cstsmapmerge) | |
| 122 | 149 | suites.append(suite_csworkflow) |
| 123 | 150 | |
| 124 | 151 | # Append tests for Python 2.6+ (the IACT cscripts depend on the json |
| ... | ... | @@ -149,7 +176,7 @@ def test(installed=False, debug=False): |
| 149 | 176 | |
| 150 | 177 | # If we have a non-installed version then save test results |
| 151 | 178 | if not installed: |
| 152 | - suites.save("reports/cscripts.xml") | |
| 179 | + suites.save('reports/cscripts.xml') | |
| 153 | 180 | |
| 154 | 181 | # If debuging is requested then print test suites |
| 155 | 182 | if debug: | ... | ... |
test/test_python_ctools.py
| ... | ... | @@ -32,6 +32,7 @@ import test_ctmodel |
| 32 | 32 | import test_ctskymap |
| 33 | 33 | import test_ctexpcube |
| 34 | 34 | import test_ctpsfcube |
| 35 | +import test_ctedispcube | |
| 35 | 36 | import test_ctbkgcube |
| 36 | 37 | import test_ctmapcube |
| 37 | 38 | import test_ctcubemask |
| ... | ... | @@ -47,9 +48,14 @@ import test_pipelines |
| 47 | 48 | def test(installed=False): |
| 48 | 49 | """ |
| 49 | 50 | Perform unit testing for ctools. |
| 51 | + | |
| 52 | + Parameters | |
| 53 | + ---------- | |
| 54 | + installed : bool, optional | |
| 55 | + Flag indicating whether the script has been installed or not | |
| 50 | 56 | """ |
| 51 | 57 | # Allocate test suite container |
| 52 | - suites = gammalib.GTestSuites("ctools unit testing") | |
| 58 | + suites = gammalib.GTestSuites('ctools unit testing') | |
| 53 | 59 | |
| 54 | 60 | # Allocate test suites and append them to the container |
| 55 | 61 | suite_ctobssim = test_ctobssim.Test() |
| ... | ... | @@ -61,6 +67,7 @@ def test(installed=False): |
| 61 | 67 | suite_ctskymap = test_ctskymap.Test() |
| 62 | 68 | suite_ctexpcube = test_ctexpcube.Test() |
| 63 | 69 | suite_ctpsfcube = test_ctpsfcube.Test() |
| 70 | + suite_ctedispcube = test_ctedispcube.Test() | |
| 64 | 71 | suite_ctbkgcube = test_ctbkgcube.Test() |
| 65 | 72 | suite_ctmapcube = test_ctmapcube.Test() |
| 66 | 73 | suite_ctcubemask = test_ctcubemask.Test() |
| ... | ... | @@ -79,6 +86,7 @@ def test(installed=False): |
| 79 | 86 | suite_ctskymap.set() |
| 80 | 87 | suite_ctexpcube.set() |
| 81 | 88 | suite_ctpsfcube.set() |
| 89 | + suite_ctedispcube.set() | |
| 82 | 90 | suite_ctbkgcube.set() |
| 83 | 91 | suite_ctmapcube.set() |
| 84 | 92 | suite_ctcubemask.set() |
| ... | ... | @@ -97,6 +105,7 @@ def test(installed=False): |
| 97 | 105 | suites.append(suite_ctskymap) |
| 98 | 106 | suites.append(suite_ctexpcube) |
| 99 | 107 | suites.append(suite_ctpsfcube) |
| 108 | + suites.append(suite_ctedispcube) | |
| 100 | 109 | suites.append(suite_ctbkgcube) |
| 101 | 110 | suites.append(suite_ctmapcube) |
| 102 | 111 | suites.append(suite_ctcubemask) |
| ... | ... | @@ -120,28 +129,28 @@ def test(installed=False): |
| 120 | 129 | dirname = os.path.dirname(testdir) |
| 121 | 130 | |
| 122 | 131 | # Copy over test data and irf |
| 123 | - os.system("cp -r %s %s" % (dirname+"/data", "data")) | |
| 124 | - os.system("cp -r %s %s" % (dirname+"/irf", "irf")) | |
| 132 | + os.system('cp -r %s %s' % (dirname+'/data', 'data')) | |
| 133 | + os.system('cp -r %s %s' % (dirname+'/irf', 'irf')) | |
| 125 | 134 | |
| 126 | 135 | # Set PFILES environment variable |
| 127 | 136 | try: |
| 128 | - os.mkdir("pfiles") | |
| 137 | + os.mkdir('pfiles') | |
| 129 | 138 | except: |
| 130 | 139 | pass |
| 131 | - os.environ['PFILES'] = "pfiles" | |
| 140 | + os.environ['PFILES'] = 'pfiles' | |
| 132 | 141 | |
| 133 | 142 | # Copy over pfiles |
| 134 | 143 | if not installed: |
| 135 | - os.system("cp -r ../src/*/*.par pfiles/") | |
| 144 | + os.system('cp -r ../src/*/*.par pfiles/') | |
| 136 | 145 | else: |
| 137 | - os.system("cp -r %s/syspfiles/*.par pfiles/" % (os.environ['CTOOLS'])) | |
| 146 | + os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS'])) | |
| 138 | 147 | |
| 139 | 148 | # Run test suite |
| 140 | 149 | success = suites.run() |
| 141 | 150 | |
| 142 | 151 | # If we have a non-installed version then save test results |
| 143 | 152 | if not installed: |
| 144 | - suites.save("reports/ctools.xml") | |
| 153 | + suites.save('reports/ctools.xml') | |
| 145 | 154 | |
| 146 | 155 | # Set return code |
| 147 | 156 | if success: | ... | ... |