Commit 902c40cc40da55cf4e05d0b5ac2a07bb3335a937

Authored by Jürgen Knödlseder
2 parents d8fcfdf3 b6c89800

Merge branch '1797-cstssplit' into integration

cscripts/Makefile.am
@@ -16,6 +16,7 @@ pythonscripts = __init__.py \ @@ -16,6 +16,7 @@ pythonscripts = __init__.py \
16 cssens.py \ 16 cssens.py \
17 csspec.py \ 17 csspec.py \
18 cstsdist.py \ 18 cstsdist.py \
  19 + cstsmapsplit.py \
19 cstsmapmerge.py \ 20 cstsmapmerge.py \
20 csworkflow.py \ 21 csworkflow.py \
21 csfindobs.py \ 22 csfindobs.py \
@@ -38,6 +39,7 @@ parfiles = cscaldb.par \ @@ -38,6 +39,7 @@ parfiles = cscaldb.par \
38 cssens.par \ 39 cssens.par \
39 csspec.par \ 40 csspec.par \
40 cstsdist.par \ 41 cstsdist.par \
  42 + cstsmapsplit.par \
41 cstsmapmerge.par \ 43 cstsmapmerge.par \
42 csworkflow.par \ 44 csworkflow.par \
43 csfindobs.par \ 45 csfindobs.par \
@@ -60,6 +62,7 @@ linkscripts = cscaldb \ @@ -60,6 +62,7 @@ linkscripts = cscaldb \
60 cssens \ 62 cssens \
61 csspec \ 63 csspec \
62 cstsdist \ 64 cstsdist \
  65 + cstsmapsplit \
63 cstsmapmerge \ 66 cstsmapmerge \
64 csworkflow \ 67 csworkflow \
65 csfindobs \ 68 csfindobs \
@@ -84,6 +87,7 @@ testscripts = tests/__init__.py \ @@ -84,6 +87,7 @@ testscripts = tests/__init__.py \
84 ../test/test_cssens.py \ 87 ../test/test_cssens.py \
85 ../test/test_csspec.py \ 88 ../test/test_csspec.py \
86 ../test/test_cstsdist.py \ 89 ../test/test_cstsdist.py \
  90 + ../test/test_cstsmapsplit.py \
87 ../test/test_cstsmapmerge.py \ 91 ../test/test_cstsmapmerge.py \
88 ../test/test_csworkflow.py \ 92 ../test/test_csworkflow.py \
89 ../test/test_csfindobs.py \ 93 ../test/test_csfindobs.py \
cscripts/__init__.py.in
@@ -38,6 +38,7 @@ __all__ = [ @@ -38,6 +38,7 @@ __all__ = [
38 "cssens", 38 "cssens",
39 "csspec", 39 "csspec",
40 "cstsdist", 40 "cstsdist",
  41 + "cstsmapsplit",
41 "cstsmapmerge", 42 "cstsmapmerge",
42 "csworkflow", 43 "csworkflow",
43 "obsutils" 44 "obsutils"
@@ -63,6 +64,7 @@ from cscripts.csroot2caldb import csroot2caldb @@ -63,6 +64,7 @@ from cscripts.csroot2caldb import csroot2caldb
63 from cscripts.cssens import cssens 64 from cscripts.cssens import cssens
64 from cscripts.csspec import csspec 65 from cscripts.csspec import csspec
65 from cscripts.cstsdist import cstsdist 66 from cscripts.cstsdist import cstsdist
  67 +from cscripts.cstsmapsplit import cstsmapsplit
66 from cscripts.cstsmapmerge import cstsmapmerge 68 from cscripts.cstsmapmerge import cstsmapmerge
67 from cscripts.csworkflow import csworkflow 69 from cscripts.csworkflow import csworkflow
68 from cscripts import obsutils 70 from cscripts import obsutils
cscripts/cstsmapsplit.par 0 → 100644
  1 +#############################################################################
  2 +# #
  3 +# CTA Science Analysis Tools #
  4 +# #
  5 +# ------------------------------------------------------------------------- #
  6 +# #
  7 +# File: cstsmapsplit.par #
  8 +# Version: 1.1.0 #
  9 +# #
  10 +# Author: Michael Mayer #
  11 +# michael.mayer@physik.hu-berlin.de #
  12 +# HU Berlin #
  13 +# #
  14 +# Purpose: Parameter file for the cstsmapsplit application #
  15 +# #
  16 +#############################################################################
  17 +#
  18 +# General parameters
  19 +#===================
  20 +inobs, f, a, events.fits,,, "Input event list, counts cube or observation definition XML file"
  21 +inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file"
  22 +srcname, s, a, Crab,,, "Test source name"
  23 +expcube, f, a, NONE,,, "Input exposure cube file (only needed for stacked analysis)"
  24 +psfcube, f, a, NONE,,, "Input PSF cube file (only needed for stacked analysis)"
  25 +edispcube, f, a, NONE,,, "Input energy dispersion cube file (only needed for stacked analysis)"
  26 +bkgcube, f, a, NONE,,, "Input background cube file (only needed for stacked analysis)"
  27 +caldb, s, a, prod2,,, "Calibration database"
  28 +irf, s, a, South_0.5h,,, "Instrument response function"
  29 +edisp, b, h, no,,, "Apply energy dispersion?"
  30 +outmap, f, a, tsmap.fits,,, "Output Test Statistic map file"
  31 +bins_per_job, i, a, 5,,, "Number of TS map bins per running job"
  32 +compute_null, b, a, yes,,,"Compute null hypothesis first?"
  33 +outfile, f, a, commands.txt,,, "ASCII file containing all commands"
  34 +
  35 +#
  36 +# Spatial binning parameters
  37 +#===========================
  38 +usepnt, b, h, no,,, "Use pointing instead of xref/yref parameters?"
  39 +nxpix, i, a, 200,,, "Size of the X axis in pixels"
  40 +nypix, i, a, 200,,, "Size of the Y axis in pixels"
  41 +binsz, r, a, 0.02,,, "Image scale (in degrees/pixel)"
  42 +coordsys, s, a, CEL, CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)"
  43 +xref, r, a, 83.63,0,360, "First coordinate of image center in degrees (RA or galactic l)"
  44 +yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DEC or galactic b)"
  45 +proj, s, a, CAR, AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method"
  46 +
  47 +#
  48 +# Standard parameters
  49 +#====================
  50 +publish, b, h, no,,, "Publish Test Statistic map on VO Hub?"
  51 +chatter, i, h, 2,0,4, "Chattiness of output"
  52 +clobber, b, h, yes,,, "Overwrite existing output files with new output files?"
  53 +debug, b, h, no,,, "Debugging mode activated"
  54 +mode, s, h, "ql",,, "Mode of automatic parameters"
  55 +logfile, f, h, cstsmapsplit.log,,, "Log filename"
cscripts/cstsmapsplit.py 0 → 100755
  1 +#!/usr/bin/env python
  2 +# ==========================================================================
  3 +# Create commands to split TS map computation
  4 +#
  5 +# Copyright (C) 2016 Michael Mayer
  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 sys
  22 +import os
  23 +import math
  24 +import gammalib
  25 +import ctools
  26 +
  27 +
  28 +# ================== #
  29 +# cstsmapsplit class #
  30 +# ================== #
  31 +class cstsmapsplit(ctools.cscript):
  32 + """
  33 + Generates commands to split TS map computation
  34 +
  35 + This class implements the creation of file containing commands to split
  36 + the computation of a TS map into several machines. It derives from
  37 + the ctools.cscript class which provides support for parameter files,
  38 + command line arguments, and logging. In that way the Python script
  39 + behaves just as a regular ctool.
  40 + """
  41 +
  42 + # Consructor
  43 + def __init__(self, *argv):
  44 + """
  45 + Constructor
  46 + """
  47 +
  48 + # Set name and version
  49 + self._name = 'cstsmapsplit'
  50 + self._version = '1.1.0'
  51 +
  52 + # Set data members
  53 + self._outmap = gammalib.GFilename()
  54 + self._bins_per_job = 0
  55 + self._compute_null = False
  56 + self._outfile = gammalib.GFilename()
  57 + self._map = gammalib.GSkyMap()
  58 + self._cmd = []
  59 +
  60 + # Initialise observation container from constructor arguments.
  61 + self._obs, argv = self._set_input_obs(argv)
  62 +
  63 + # Initialise application by calling the appropriate class
  64 + # constructor.
  65 + self._init_cscript(argv)
  66 +
  67 + # Return
  68 + return
  69 +
  70 +
  71 + # Private methods
  72 + def _get_parameters(self):
  73 + """
  74 + Get parameters from parfile and setup the observation
  75 + """
  76 +
  77 + # If there are no observations in container then get some ...
  78 + if self._obs.size() == 0:
  79 + self._obs = self._get_observations()
  80 +
  81 + # Set models if we have none
  82 + if self._obs.models().size() == 0:
  83 + self._obs.models(self['inmodel'].filename())
  84 +
  85 + # Get TS map paramters
  86 + self._map = self._create_map(self._obs)
  87 + self._srcname = self['srcname'].string()
  88 + self._outmap = self['outmap'].filename()
  89 +
  90 + # Get additional parameters
  91 + self._bins_per_job = self['bins_per_job'].integer()
  92 + self._compute_null = self['compute_null'].boolean()
  93 + self._outfile = self['outfile'].filename()
  94 +
  95 + # Write input parameters into logger
  96 + if self._logTerse():
  97 + self._log_parameters()
  98 + self._log('\n')
  99 +
  100 + # Return
  101 + return
  102 +
  103 +
  104 + def _compute_null_hypothesis(self):
  105 + """
  106 + Compute null hypothesis
  107 +
  108 + Returns
  109 + -------
  110 + logl : float
  111 + Log-likelihood of null hypothesis
  112 + """
  113 +
  114 + # Store original models
  115 + models_orig = self._obs.models()
  116 +
  117 + # Get models instance
  118 + models0 = self._obs.models()
  119 +
  120 + # Remove test source
  121 + models0.remove(self._srcname)
  122 +
  123 + # Initialise optimizer
  124 + opt = gammalib.GOptimizerLM()
  125 +
  126 + # Set models for null hypothesis
  127 + self._obs.models(models0)
  128 +
  129 + # Optimise observation container
  130 + self._obs.optimize(opt)
  131 +
  132 + # Set original models to container
  133 + self._obs.models(models_orig)
  134 +
  135 + # Return optimised log-likelihood of null hypothesis
  136 + return -(opt.value())
  137 +
  138 +
  139 + def run(self):
  140 + """
  141 + Run the script
  142 + """
  143 +
  144 + # Switch screen logging on in debug mode
  145 + if self._logDebug():
  146 + self._log.cout(True)
  147 +
  148 + # Get parameters
  149 + self._get_parameters()
  150 +
  151 + # Write information into logger
  152 + if self._logTerse():
  153 + self._log('\n')
  154 + self._log.header1('Test source')
  155 + model = self._obs.models()[self._srcname]
  156 + self._log(str(model))
  157 + self._log('\n')
  158 +
  159 + # Set log-likelihood to zero
  160 + logL0 = 0.0
  161 +
  162 + # Pre-compute null hypothesis if requested
  163 + if self._compute_null:
  164 +
  165 + # Write information into logger
  166 + if self._logTerse():
  167 + self._log('\n')
  168 + self._log.header1('Compute null hypothesis')
  169 +
  170 + # Compute null hypothesis
  171 + logL0 = self._compute_null_hypothesis()
  172 +
  173 + # Write likelihood into logger
  174 + if self._logTerse():
  175 + self._log(gammalib.parformat('Source removed'))
  176 + self._log(self._srcname)
  177 + self._log('\n')
  178 + self._log(gammalib.parformat('Log-likelihood'))
  179 + self._log(repr(logL0))
  180 + self._log('\n')
  181 +
  182 + # Get parameters of TS map ctool
  183 + pars = gammalib.GApplicationPars('cttsmap.par')
  184 +
  185 + # Compute total number of jobs
  186 + nbins = self._map.npix()
  187 + njobs = int(math.ceil(float(nbins) / float(self._bins_per_job)) + 0.1)
  188 +
  189 + # Set parameters to be skipped now, we will deal with them later
  190 + skip_pars = ['binmin', 'binmax', 'logL0', 'outmap', 'logfile']
  191 +
  192 + # Set tool name for computation
  193 + base_command = 'cttsmap'
  194 +
  195 + # Write information into logger
  196 + if self._logTerse():
  197 + self._log('\n')
  198 + self._log.header1('Create commands')
  199 + self._log(gammalib.parformat('Number of cttsmap calls'))
  200 + self._log(str(njobs))
  201 + self._log('\n')
  202 +
  203 + # Loop over TS map parameters
  204 + for par in pars:
  205 +
  206 + # Skip if we deal with them later
  207 + if par.name() in skip_pars:
  208 + continue
  209 +
  210 + # Skip if they need to be queried
  211 + # This way we ensure we pass only parameters
  212 + # that were queried before
  213 + if self[par.name()].is_query():
  214 + continue
  215 +
  216 + # Set TS map parameter according to input from
  217 + # this script
  218 + par.value(self[par.name()].value())
  219 +
  220 + # Append command to set parameter
  221 + base_command += ' ' + par.name() + '=' + par.value()
  222 +
  223 + # Append null hypothesis parameter
  224 + base_command += ' logL0=' + repr(logL0)
  225 +
  226 + # Set binning to start from zero
  227 + binmin = 0
  228 + binmax = 0
  229 +
  230 + # Clear command sequence
  231 + self._cmd = []
  232 +
  233 + # Loop over jobs and create commands
  234 + for job in range(njobs):
  235 +
  236 + # Set specific outmap file name
  237 + outmap = self._outmap.url().replace('.fits', '_'+str(job)+'.fits')
  238 +
  239 + # Set bin numbers to be computed in this job
  240 + binmin = binmax
  241 + binmax = binmin + self._bins_per_job
  242 + if binmax > nbins:
  243 + binmax = nbins
  244 +
  245 + # Setup sliced command
  246 + sliced_command = '%s binmin=%s binmax=%s outmap=%s logfile=%s' % \
  247 + (base_command, str(binmin), str(binmax),
  248 + outmap, outmap.replace('.fits','.log'))
  249 +
  250 + # Append command to list of commands
  251 + self._cmd.append(sliced_command)
  252 +
  253 + # Write information into logger
  254 + if self._logExplicit():
  255 + self._log('\n')
  256 + self._log.header2('Commands')
  257 + for cmd in self._cmd:
  258 + self._log(cmd)
  259 + self._log('\n')
  260 + self._log('\n')
  261 +
  262 + # Return
  263 + return
  264 +
  265 +
  266 + def execute(self):
  267 + """
  268 + Execute the script
  269 + """
  270 +
  271 + # Run the script
  272 + self.run()
  273 +
  274 + # Save results
  275 + self.save()
  276 +
  277 + # Return
  278 + return
  279 +
  280 +
  281 + def save(self):
  282 + """
  283 + Save commands to ASCII file
  284 + """
  285 +
  286 + # Open file
  287 + f = open(self._outfile.url(), 'w')
  288 +
  289 + # Write commands to file
  290 + for cmd in self._cmd:
  291 + f.write(cmd + '\n')
  292 +
  293 + # Close file
  294 + f.close()
  295 +
  296 + # Return
  297 + return
  298 +
  299 +
  300 +# ======================== #
  301 +# Main routine entry point #
  302 +# ======================== #
  303 +if __name__ == '__main__':
  304 +
  305 + # Create instance of application
  306 + app = cstsmapsplit(sys.argv)
  307 +
  308 + # Execute application
  309 + app.execute()
doc/source/users/reference_manual/cstsmapsplit.rst 0 → 100644
  1 +.. _cstsmapsplit:
  2 +
  3 +cstsmapsplit
  4 +============
  5 +
  6 +Generate commands to split the Test Statistic map computation
  7 +
  8 +
  9 +Synopsis
  10 +--------
  11 +
  12 +This script generates a sequence of commands to split the Test Statistic (TS)
  13 +map computation into a distinct number of :ref:`cttsmap` computations. The
  14 +sequence of commands is written into an ASCII file, where each line in the
  15 +file corresponds to the command for an individual :ref:`cttsmap` run. Each TS
  16 +map computed in that way will be suffixed with the command number, and the
  17 +map can be combined into a single TS map using the :ref:`cstsmapmerge` script.
  18 +
  19 +
  20 +General parameters
  21 +------------------
  22 +
  23 +``inobs [file]``
  24 + Input event list, counts cube or observation definition XML file.
  25 +
  26 +``inmodel [file]``
  27 + Input model XML file.
  28 +
  29 +``srcname [string]``
  30 + Name of source model for which the TS map should be computed.
  31 +
  32 +``expcube [file]``
  33 + Input exposure cube file (only needed for stacked analysis).
  34 +
  35 +``psfcube [file]``
  36 + Input PSF cube file (only needed for stacked analysis).
  37 +
  38 +``bkgcube [file]``
  39 + Input background cube file (only needed for stacked analysis).
  40 +
  41 +``caldb [string]``
  42 + Calibration database.
  43 +
  44 +``irf [string]``
  45 + Instrumental response function.
  46 +
  47 +``(edisp = no) [boolean]``
  48 + Applies energy dispersion to response computation.
  49 +
  50 +``outmap [file]``
  51 + Output Test Statistic map file.
  52 +
  53 +``bins_per_job [integer]``
  54 + Number of bins of the TS map that should be computed within one command
  55 +
  56 +``compute_null [boolean]``
  57 + Pre-computes the null hypothesis globally and passes the value to the
  58 + individual commands. If the parameter is set to ``no``, the null
  59 + hypothesis will be computed in each run of :ref:`cttsmap` individually.
  60 +
  61 +``outfile [file]``
  62 + Output ASCII file name where the commands are written to.
  63 +
  64 +``(usepnt = no) [boolean]``
  65 + Use CTA pointing direction for map centre instead of xref/yref parameters?
  66 +
  67 +``nxpix [integer]``
  68 + Number of map pixels in Right Ascension or Galactic longitude.
  69 +
  70 +``nypix [integer]``
  71 + Number of map pixels in Declination or Galactic latitude.
  72 +
  73 +``binsz [real]``
  74 + Map pixel size (in degrees/pixel).
  75 +
  76 +``coordsys <CEL|GAL> [string]``
  77 + Coordinate system (CEL - celestial, GAL - galactic).
  78 +
  79 +``xref [real]``
  80 + Right Ascension / Galactic longitude of map centre (J2000, in degrees).
  81 +
  82 +``yref [real]``
  83 + Declination / Galactic latitude of map centre (J2000, in degrees).
  84 +
  85 +``proj <AIT|AZP|CAR|MER|MOL|STG|TAN> [string]``
  86 + Projection method.
  87 +
  88 +
  89 +
  90 +Standard parameters
  91 +-------------------
  92 +
  93 +``(publish = no) [boolean]``
  94 + Specifies whether the TS map should be published on VO Hub.
  95 +
  96 +``(chatter = 2) [integer]``
  97 + Verbosity of the executable:
  98 + chatter = 0: no information will be logged
  99 +
  100 + chatter = 1: only errors will be logged
  101 +
  102 + chatter = 2: errors and actions will be logged
  103 +
  104 + chatter = 3: report about the task execution
  105 +
  106 + chatter = 4: detailed report about the task execution
  107 +
  108 +``(clobber = yes) [boolean]``
  109 + Specifies whether an existing output TS map file should be overwritten.
  110 +
  111 +``(debug = no) [boolean]``
  112 + Enables debug mode. In debug mode the executable will dump any log file
  113 + output to the console.
  114 +
  115 +``(mode = ql) [string]``
  116 + Mode of automatic parameters (default is "ql", i.e. "query and learn").
  117 +
  118 +``(logfile = cstsmapsplit.log) [string]``
  119 + Name of log file.
  120 +
  121 +
  122 +Related tools or scripts
  123 +------------------------
  124 +
  125 +:ref:`cttsmap`
  126 +:ref:`cstsmapmerge`
  127 +
doc/source/users/reference_manual/index.rst
@@ -49,8 +49,10 @@ cscripts @@ -49,8 +49,10 @@ cscripts
49 csresmap --- Generates residual map <csresmap> 49 csresmap --- Generates residual map <csresmap>
50 cssens --- Computes CTA sensitivity <cssens> 50 cssens --- Computes CTA sensitivity <cssens>
51 csspec --- Computes spectral points <csspec> 51 csspec --- Computes spectral points <csspec>
52 - cstsdist --- Generates TS distribution <cstsdist>  
53 - cstsmapmerge --- Merges slices from ts map computations <cstsmapmerge> 52 + cstsdist --- Generates Test Statistic distribution <cstsdist>
  53 + cstsmapsplit --- Creates commands to split the Test Statistic map computations <cstsmapsplit>
  54 + cstsmapmerge --- Merges slices from Test Statistic map computations <cstsmapmerge>
  55 +
54 56
55 57
56 Scripts to manage an IACT database 58 Scripts to manage an IACT database
test/test_cstsmapsplit.py 0 → 100755
  1 +#! /usr/bin/env python
  2 +# ==========================================================================
  3 +# This scripts performs unit tests for the cstsmapsplit script.
  4 +#
  5 +# Copyright (C) 2016 Michael Mayer
  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 cstssplit script #
  28 +# =============================== #
  29 +class Test(gammalib.GPythonTestSuite):
  30 + """
  31 + Test class for cstssplit script
  32 +
  33 + This test class makes unit tests for the csstsplit 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('cstsmapsplit')
  55 +
  56 + # Append tests
  57 + self.append(self._test_cmd, 'Test cstsmapsplit on command line')
  58 + #self.append(self._test_python, 'Test cstsmapsplit from Python')
  59 +
  60 + # Return
  61 + return
  62 +
  63 + # Test cstsmapsplit on command line
  64 + def _test_cmd(self):
  65 + """
  66 + Test cstsmapsplit on the command line.
  67 + """
  68 + # Kluge to set the command (installed version has no README file)
  69 + if os.path.isfile("README.md"):
  70 + cstsmapsplit = "../cscripts/cstsmapsplit.py"
  71 + else:
  72 + cstsmapsplit = "cstsmapsplit"
  73 +
  74 + # Setup cstsmapsplit command
  75 + cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \
  76 + ' inmodel="data/crab.xml"'+ \
  77 + ' srcname="Crab"'+ \
  78 + ' caldb="prod2"'+ \
  79 + ' irf="South_0.5h"'+ \
  80 + ' outmap="tsmap.fits"'+ \
  81 + ' nxpix=5'+ \
  82 + ' nypix=5'+ \
  83 + ' binsz=0.05'+ \
  84 + ' coordsys="CEL"'+ \
  85 + ' xref=83.63'+ \
  86 + ' yref=22.01'+ \
  87 + ' proj="CAR"'+ \
  88 + ' compute_null=yes'+ \
  89 + ' bins_per_job=5'+ \
  90 + ' outfile="tsmap_cmds1.txt"'
  91 +
  92 +
  93 + # Execute cstssplit, make sure we catch any exception
  94 + try:
  95 + rc = os.system(cmd+" >/dev/null 2>&1")
  96 + except:
  97 + pass
  98 +
  99 + # Check if execution was successful
  100 + self.test_assert(rc == 0,
  101 + "Successful cstsssplit execution on command line")
  102 +
  103 + # Check observation definition XML file
  104 + self._check_cmdfile('tsmap_cmds1.txt')
  105 +
  106 + # Setup cstsmapsplit command
  107 + cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \
  108 + ' inmodel="data/crab.xml"'+ \
  109 + ' srcname="Does_not_exist"'+ \
  110 + ' caldb="prod2"'+ \
  111 + ' irf="South_0.5h"'+ \
  112 + ' outmap="tsmap.fits"'+ \
  113 + ' nxpix=5'+ \
  114 + ' nypix=5'+ \
  115 + ' binsz=0.05'+ \
  116 + ' coordsys="CEL"'+ \
  117 + ' xref=83.63'+ \
  118 + ' yref=22.01'+ \
  119 + ' proj="CAR"'+ \
  120 + ' compute_null=yes'+ \
  121 + ' bins_per_job=5'+ \
  122 + ' outfile="tsmap_cmds2.txt"'
  123 +
  124 +
  125 + # Execute cstssplit, make sure we catch any exception
  126 + try:
  127 + rc = os.system(cmd+" >/dev/null 2>&1")
  128 + except:
  129 + pass
  130 +
  131 + # Check if execution failed
  132 + self.test_assert(rc != 0,
  133 + "Failure of cstssplit execution on command line")
  134 +
  135 + # Return
  136 + return
  137 +
  138 + # Test cstsmapsplit from Python
  139 + def _test_python(self):
  140 + """
  141 + Test cstsmapsplit from Python.
  142 + """
  143 + # Set-up cstsmapsplit
  144 + tsmapsplit = cscripts.cstsmapsplit()
  145 + tsmapsplit['inobs'] = 'obs_selected.xml'
  146 + tsmapsplit['inmodel'] = 'data/crab.xml'
  147 + tsmapsplit['xref'] = 83.6331
  148 + tsmapsplit['yref'] = 22.01
  149 + tsmapsplit['coordsys'] = 'CEL'
  150 + tsmapsplit['proj'] = 'CAR'
  151 + tsmapsplit['binsz'] = 0.05
  152 + tsmapsplit['nxpix'] = 5
  153 + tsmapsplit['nypix'] = 5
  154 + tsmapsplit['compute_null'] = False
  155 + tsmapsplit['bins_per_job'] = 5
  156 + tsmapsplit['outfile'] = 'tsmap_cmd_py1.txt'
  157 +
  158 + # Run cstssplit script and save run list
  159 + tsmapsplit.logFileOpen() # Make sure we get a log file
  160 + tsmapsplit.run()
  161 + tsmapsplit.save()
  162 +
  163 + # Check observation definition XML file
  164 + self._check_cmdfile('tsmap_cmd_py1.txt')
  165 +
  166 + # Return
  167 + return
  168 +
  169 + # Check observation definition XML file
  170 + def _check_cmdfile(self, filename):
  171 + """
  172 + Check ascii files containing commands
  173 + """
  174 +
  175 + # Create file name instance
  176 + fname = gammalib.GFilename(filename)
  177 +
  178 + # Check if execution was successful
  179 + self.test_assert(fname.exists(), 'Check of output filename exists')
  180 +
  181 + # Return
  182 + return
test/test_python_cscripts.py
@@ -37,6 +37,7 @@ import test_csroot2caldb @@ -37,6 +37,7 @@ import test_csroot2caldb
37 import test_cssens 37 import test_cssens
38 import test_csspec 38 import test_csspec
39 import test_cstsdist 39 import test_cstsdist
  40 +import test_cstsmapsplit
40 import test_cstsmapmerge 41 import test_cstsmapmerge
41 import test_csworkflow 42 import test_csworkflow
42 import test_csiactcopy 43 import test_csiactcopy
@@ -111,6 +112,7 @@ def test(installed=False, debug=False): @@ -111,6 +112,7 @@ def test(installed=False, debug=False):
111 suite_cssens = test_cssens.Test() 112 suite_cssens = test_cssens.Test()
112 suite_csspec = test_csspec.Test() 113 suite_csspec = test_csspec.Test()
113 suite_cstsdist = test_cstsdist.Test() 114 suite_cstsdist = test_cstsdist.Test()
  115 + suite_cstsmapsplit = test_cstsmapsplit.Test()
114 suite_cstsmapmerge = test_cstsmapmerge.Test() 116 suite_cstsmapmerge = test_cstsmapmerge.Test()
115 suite_csworkflow = test_csworkflow.Test() 117 suite_csworkflow = test_csworkflow.Test()
116 118
@@ -128,6 +130,7 @@ def test(installed=False, debug=False): @@ -128,6 +130,7 @@ def test(installed=False, debug=False):
128 suite_cssens.set() 130 suite_cssens.set()
129 suite_csspec.set() 131 suite_csspec.set()
130 suite_cstsdist.set() 132 suite_cstsdist.set()
  133 + suite_cstsmapsplit.set()
131 suite_cstsmapmerge.set() 134 suite_cstsmapmerge.set()
132 suite_csworkflow.set() 135 suite_csworkflow.set()
133 136
@@ -145,6 +148,7 @@ def test(installed=False, debug=False): @@ -145,6 +148,7 @@ def test(installed=False, debug=False):
145 suites.append(suite_cssens) 148 suites.append(suite_cssens)
146 suites.append(suite_csspec) 149 suites.append(suite_csspec)
147 suites.append(suite_cstsdist) 150 suites.append(suite_cstsdist)
  151 + suites.append(suite_cstsmapsplit)
148 suites.append(suite_cstsmapmerge) 152 suites.append(suite_cstsmapmerge)
149 suites.append(suite_csworkflow) 153 suites.append(suite_csworkflow)
150 154