diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am index 7aeb394..da3a7bf 100644 --- a/cscripts/Makefile.am +++ b/cscripts/Makefile.am @@ -16,13 +16,13 @@ pythonscripts = __init__.py \ cssens.py \ csspec.py \ cstsdist.py \ + cstsmapsplit.py \ cstsmapmerge.py \ csworkflow.py \ csfindobs.py \ csiactcopy.py \ csiactdata.py \ csiactobs.py \ - cstssplit.py \ obsutils.py # Parfiles to be distributed in $(prefix)/syspfiles @@ -39,12 +39,12 @@ parfiles = cscaldb.par \ cssens.par \ csspec.par \ cstsdist.par \ + cstsmapsplit.par \ cstsmapmerge.par \ csworkflow.par \ csfindobs.par \ csiactcopy.par \ csiactdata.par \ - cstssplit.par \ csiactobs.par # Scripts for which symbolic links will be created in bindir @@ -62,12 +62,12 @@ linkscripts = cscaldb \ cssens \ csspec \ cstsdist \ + cstsmapsplit \ cstsmapmerge \ csworkflow \ csfindobs \ csiactcopy \ csiactdata \ - cstssplit \ csiactobs # Test scripts to be distributed in $(pyexecdir)/cscripts/tests @@ -86,12 +86,12 @@ testscripts = tests/__init__.py \ ../test/test_cssens.py \ ../test/test_csspec.py \ ../test/test_cstsdist.py \ + ../test/test_cstsmapsplit.py \ ../test/test_cstsmapmerge.py \ ../test/test_csworkflow.py \ ../test/test_csfindobs.py \ ../test/test_csiactcopy.py \ ../test/test_csiactdata.py \ - ../test/test_cstssplit.py \ ../test/test_csiactobs.py # Test data to be distributed in $(pyexecdir)/cscripts/tests/data diff --git a/cscripts/__init__.py.in b/cscripts/__init__.py.in index 59aff7b..36ced7a 100644 --- a/cscripts/__init__.py.in +++ b/cscripts/__init__.py.in @@ -38,9 +38,9 @@ __all__ = [ "cssens", "csspec", "cstsdist", + "cstsmapsplit", "cstsmapmerge", "csworkflow", - "cstssplit", "obsutils" ] if cur_version > req_version: @@ -64,9 +64,9 @@ from cscripts.csroot2caldb import csroot2caldb from cscripts.cssens import cssens from cscripts.csspec import csspec from cscripts.cstsdist import cstsdist +from cscripts.cstsmapsplit import cstsmapsplit from cscripts.cstsmapmerge import cstsmapmerge from cscripts.csworkflow import csworkflow -from cscripts.cstssplit import cstssplit from cscripts import obsutils if cur_version > req_version: from cscripts.csfindobs import csfindobs diff --git a/cscripts/cstssplit.par b/cscripts/cstsmapsplit.par index 2308969..db7065c 100644 --- a/cscripts/cstssplit.par +++ b/cscripts/cstsmapsplit.par @@ -4,33 +4,33 @@ # # # ------------------------------------------------------------------------- # # # -# File: cstssplit.par # +# File: cstsmapsplit.par # # Version: 1.1.0 # # # # Author: Michael Mayer # # michael.mayer@physik.hu-berlin.de # # HU Berlin # # # -# Purpose: Parameter file for the cttsmap application # +# Purpose: Parameter file for the cstsmapsplit application # # # ############################################################################# # # General parameters #=================== -inobs, f, a, "events.fits",,, "Input event list, counts cube or observation definition XML file" -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Input model XML file" -srcname, s, a, "Crab",,, "Test source name" -expcube, f, a, "NONE",,, "Input exposure cube file (only needed for stacked analysis)" -psfcube, f, a, "NONE",,, "Input PSF cube file (only needed for stacked analysis)" -edispcube, f, a, "NONE",,, "Input energy dispersion cube file (only needed for stacked analysis)" -bkgcube, f, a, "NONE",,, "Input background cube file (only needed for stacked analysis)" -caldb, s, a, "prod2",,, "Calibration database" -irf, s, a, "South_0.5h",,, "Instrument response function" +inobs, f, a, events.fits,,, "Input event list, counts cube or observation definition XML file" +inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file" +srcname, s, a, Crab,,, "Test source name" +expcube, f, a, NONE,,, "Input exposure cube file (only needed for stacked analysis)" +psfcube, f, a, NONE,,, "Input PSF cube file (only needed for stacked analysis)" +edispcube, f, a, NONE,,, "Input energy dispersion cube file (only needed for stacked analysis)" +bkgcube, f, a, NONE,,, "Input background cube file (only needed for stacked analysis)" +caldb, s, a, prod2,,, "Calibration database" +irf, s, a, South_0.5h,,, "Instrument response function" edisp, b, h, no,,, "Apply energy dispersion?" -outmap, f, a, "tsmap.fits",,, "Output Test Statistic map file" +outmap, f, a, tsmap.fits,,, "Output Test Statistic map file" bins_per_job, i, a, 5,,, "Number of TS map bins per running job" compute_null, b, a, yes,,,"Compute null hypothesis first?" -outfile, f, a, "commands.txt",,, "ASCII file containing all commands" +outfile, f, a, commands.txt,,, "ASCII file containing all commands" # # Spatial binning parameters @@ -39,10 +39,10 @@ usepnt, b, h, no,,, "Use pointing instead of xref/yref parameters?" nxpix, i, a, 200,,, "Size of the X axis in pixels" nypix, i, a, 200,,, "Size of the Y axis in pixels" binsz, r, a, 0.02,,, "Image scale (in degrees/pixel)" -coordsys, s, a, "CEL", CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)" +coordsys, s, a, CEL, CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)" xref, r, a, 83.63,0,360, "First coordinate of image center in degrees (RA or galactic l)" yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DEC or galactic b)" -proj, s, a, "CAR", AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method" +proj, s, a, CAR, AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method" # # Standard parameters @@ -52,4 +52,4 @@ chatter, i, h, 2,0,4, "Chattiness of output" clobber, b, h, yes,,, "Overwrite existing output files with new output files?" debug, b, h, no,,, "Debugging mode activated" mode, s, h, "ql",,, "Mode of automatic parameters" -logfile, f, h, "cstssplit.log",,, "Log filename" +logfile, f, h, cstsmapsplit.log,,, "Log filename" diff --git a/cscripts/cstssplit.py b/cscripts/cstsmapsplit.py index c45c3de..135ca08 100755 --- a/cscripts/cstssplit.py +++ b/cscripts/cstsmapsplit.py @@ -25,10 +25,10 @@ import gammalib import ctools -# ============== # -# cstssplit class # -# ============== # -class cstssplit(ctools.cscript): +# ================== # +# cstsmapsplit class # +# ================== # +class cstsmapsplit(ctools.cscript): """ Generates commands to split TS map computation @@ -42,18 +42,20 @@ class cstssplit(ctools.cscript): # Consructor def __init__(self, *argv): """ - Constructor. + Constructor """ - # Set name - self._name = 'cstssplit' + # Set name and version + self._name = 'cstsmapsplit' self._version = '1.1.0' - self._outmap = gammalib.GFilename() + + # Set data members + self._outmap = gammalib.GFilename() self._bins_per_job = 0 self._compute_null = False - self._outfile = gammalib.GFilename() - self._map = gammalib.GSkyMap() - self._cmd = [] + self._outfile = gammalib.GFilename() + self._map = gammalib.GSkyMap() + self._cmd = [] # Initialise observation container from constructor arguments. self._obs, argv = self._set_input_obs(argv) @@ -69,7 +71,7 @@ class cstssplit(ctools.cscript): # Private methods def _get_parameters(self): """ - Get parameters from parfile and setup the observation. + Get parameters from parfile and setup the observation """ # If there are no observations in container then get some ... @@ -103,7 +105,9 @@ class cstssplit(ctools.cscript): """ Compute null hypothesis - Returns: + Returns + ------- + logl : float Log-likelihood of null hypothesis """ @@ -134,7 +138,7 @@ class cstssplit(ctools.cscript): def run(self): """ - Run the script. + Run the script """ # Switch screen logging on in debug mode @@ -238,9 +242,10 @@ class cstssplit(ctools.cscript): if binmax > nbins: binmax = nbins - # Complete command by binning parameters - sliced_command = base_command + ' binmin='+str(binmin)+' binmax='+str(binmax) - sliced_command += ' outmap='+outmap + ' logfile='+outmap.replace('.fits','.log') + # Setup sliced command + sliced_command = '%s binmin=%s binmax=%s outmap=%s logfile=%s' % \ + (base_command, str(binmin), str(binmax), + outmap, outmap.replace('.fits','.log')) # Append command to list of commands self._cmd.append(sliced_command) @@ -260,7 +265,7 @@ class cstssplit(ctools.cscript): def execute(self): """ - Execute the script. + Execute the script """ # Run the script @@ -290,18 +295,15 @@ class cstssplit(ctools.cscript): # Return return + + # ======================== # # Main routine entry point # # ======================== # if __name__ == '__main__': - """ - Generates splitted TS map commands - """ # Create instance of application - app = cstssplit(sys.argv) + app = cstsmapsplit(sys.argv) # Execute application app.execute() - -# diff --git a/doc/source/users/reference_manual/cstssplit.rst b/doc/source/users/reference_manual/cstsmapsplit.rst index cd250bc..40eb71e 100644 --- a/doc/source/users/reference_manual/cstssplit.rst +++ b/doc/source/users/reference_manual/cstsmapsplit.rst @@ -1,21 +1,20 @@ -.. _cstssplit: +.. _cstsmapsplit: -cstssplit -======= +cstsmapsplit +============ -Generate commands to split TS map computation +Generate commands to split the Test Statistic map computation Synopsis -------- -This tool allows to generate a command sequence in order to compute a -Test Statistic (TS) map using e.g. several machines. The command sequence -is stored in an ASCII file. Each line contains an individual command. -Each command will call the tool :ref:`cttsmap` with the appropriate parameters. -To split the computation, each TS map that is computed has a suffix to the filename -according to the number of the command. The resulting individual TS maps can then be -merged via :ref:`cstsmapmerge`. +This script generates a sequence of commands to split the Test Statistic (TS) +map computation into a distinct number of :ref:`cttsmap` computations. The +sequence of commands is written into an ASCII file, where each line in the +file corresponds to the command for an individual :ref:`cttsmap` run. Each TS +map computed in that way will be suffixed with the command number, and the +map can be combined into a single TS map using the :ref:`cstsmapmerge` script. General parameters @@ -50,7 +49,18 @@ General parameters ``outmap [file]`` Output Test Statistic map file. - + +``bins_per_job [integer]`` + Number of bins of the TS map that should be computed within one command + +``compute_null [boolean]`` + Pre-computes the null hypothesis globally and passes the value to the + individual commands. If the parameter is set to ``no``, the null + hypothesis will be computed in each run of :ref:`cttsmap` individually. + +``outfile [file]`` + Output ASCII file name where the commands are written to. + ``(usepnt = no) [boolean]`` Use CTA pointing direction for map centre instead of xref/yref parameters? @@ -75,16 +85,7 @@ General parameters ``proj [string]`` Projection method. -``bins_per_job [integer]`` - Number of bins of the TS map that should be computed within one command -``compute_null [boolean]`` - Pre-computes the null hypothesis globally and passes the value to the individual commands - If 'false', the null hypothesis will be computed in each run of :ref:`cttsmap` individually. - -``outfile [file]`` - Output ASCII file name where the commands are written to. - Standard parameters ------------------- @@ -108,12 +109,13 @@ Standard parameters Specifies whether an existing output TS map file should be overwritten. ``(debug = no) [boolean]`` - Enables debug mode. In debug mode the executable will dump any log file output to the console. + Enables debug mode. In debug mode the executable will dump any log file + output to the console. ``(mode = ql) [string]`` Mode of automatic parameters (default is "ql", i.e. "query and learn"). -``(logfile = cttsmap.log) [string]`` +``(logfile = cstsmapsplit.log) [string]`` Name of log file. @@ -123,4 +125,3 @@ Related tools or scripts :ref:`cttsmap` :ref:`cstsmapmerge` - diff --git a/doc/source/users/reference_manual/index.rst b/doc/source/users/reference_manual/index.rst index 269b1c9..566035e 100644 --- a/doc/source/users/reference_manual/index.rst +++ b/doc/source/users/reference_manual/index.rst @@ -49,9 +49,9 @@ cscripts csresmap --- Generates residual map cssens --- Computes CTA sensitivity csspec --- Computes spectral points - cstsdist --- Generates TS distribution - cstssplit --- Creates commands to slice the ts map computations - cstsmapmerge --- Merges slices from ts map computations + cstsdist --- Generates Test Statistic distribution + cstsmapsplit --- Creates commands to split the Test Statistic map computations + cstsmapmerge --- Merges slices from Test Statistic map computations diff --git a/test/test_cstssplit.py b/test/test_cstsmapsplit.py index 66ef1f8..d41fcb6 100755 --- a/test/test_cstssplit.py +++ b/test/test_cstsmapsplit.py @@ -1,6 +1,6 @@ #! /usr/bin/env python # ========================================================================== -# This scripts performs unit tests for the cstssplit script. +# This scripts performs unit tests for the cstsmapsplit script. # # Copyright (C) 2016 Michael Mayer # @@ -28,7 +28,7 @@ import cscripts # =============================== # class Test(gammalib.GPythonTestSuite): """ - Test class for cstssplit script. + Test class for cstssplit script This test class makes unit tests for the csstsplit script by using it from the command line and from Python. @@ -37,7 +37,7 @@ class Test(gammalib.GPythonTestSuite): # Constructor def __init__(self): """ - Constructor. + Constructor """ # Call base class constructor gammalib.GPythonTestSuite.__init__(self) @@ -48,46 +48,46 @@ class Test(gammalib.GPythonTestSuite): # Set test functions def set(self): """ - Set all test functions. + Set all test functions """ # Set test name - self.name('cstssplit') + self.name('cstsmapsplit') # Append tests - self.append(self._test_cmd, "Test cstssplit on command line") - #self.append(self._test_python, "Test cstssplit from Python") + self.append(self._test_cmd, 'Test cstsmapsplit on command line') + #self.append(self._test_python, 'Test cstsmapsplit from Python') # Return return - # Test cstssplit on command line + # Test cstsmapsplit on command line def _test_cmd(self): """ - Test cstssplit on the command line. + Test cstsmapsplit on the command line. """ # Kluge to set the command (installed version has no README file) if os.path.isfile("README.md"): - cstssplit = "../cscripts/cstssplit.py" + cstsmapsplit = "../cscripts/cstsmapsplit.py" else: - cstssplit = "cstssplit" - - # Setup cstssplit command - cmd = cstssplit+' inobs="selected_events.fits"'+ \ - ' inmodel="data/crab.xml"'+ \ - ' srcname="Crab"'+ \ - ' caldb="irf"'+ \ - ' irf="cta_dummy_irf"'+ \ - ' outmap="tsmap.fits"'+ \ - ' nxpix=5'+ \ - ' nypix=5'+ \ - ' binsz=0.05'+ \ - ' coordsys="CEL"'+ \ - ' xref=83.63'+ \ - ' yref=22.01'+ \ - ' proj="CAR"'+ \ - ' compute_null=yes'+ \ - ' bins_per_job=5'+ \ - ' outfile="tsmap_cmds1.txt"' + cstsmapsplit = "cstsmapsplit" + + # Setup cstsmapsplit command + cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ + ' inmodel="data/crab.xml"'+ \ + ' srcname="Crab"'+ \ + ' caldb="prod2"'+ \ + ' irf="South_0.5h"'+ \ + ' outmap="tsmap.fits"'+ \ + ' nxpix=5'+ \ + ' nypix=5'+ \ + ' binsz=0.05'+ \ + ' coordsys="CEL"'+ \ + ' xref=83.63'+ \ + ' yref=22.01'+ \ + ' proj="CAR"'+ \ + ' compute_null=yes'+ \ + ' bins_per_job=5'+ \ + ' outfile="tsmap_cmds1.txt"' # Execute cstssplit, make sure we catch any exception @@ -103,23 +103,23 @@ class Test(gammalib.GPythonTestSuite): # Check observation definition XML file self._check_cmdfile('tsmap_cmds1.txt') - # Setup cstssplit command - cmd = cstssplit+' inobs="selected_events.fits"'+ \ - ' inmodel="data/crab.xml"'+ \ - ' srcname="Does_not_exist"'+ \ - ' caldb="irf"'+ \ - ' irf="cta_dummy_irf"'+ \ - ' outmap="tsmap.fits"'+ \ - ' nxpix=5'+ \ - ' nypix=5'+ \ - ' binsz=0.05'+ \ - ' coordsys="CEL"'+ \ - ' xref=83.63'+ \ - ' yref=22.01'+ \ - ' proj="CAR"'+ \ - ' compute_null=yes'+ \ - ' bins_per_job=5'+ \ - ' outfile="tsmap_cmds2.txt"' + # Setup cstsmapsplit command + cmd = cstsmapsplit+' inobs="selected_events.fits"'+ \ + ' inmodel="data/crab.xml"'+ \ + ' srcname="Does_not_exist"'+ \ + ' caldb="prod2"'+ \ + ' irf="South_0.5h"'+ \ + ' outmap="tsmap.fits"'+ \ + ' nxpix=5'+ \ + ' nypix=5'+ \ + ' binsz=0.05'+ \ + ' coordsys="CEL"'+ \ + ' xref=83.63'+ \ + ' yref=22.01'+ \ + ' proj="CAR"'+ \ + ' compute_null=yes'+ \ + ' bins_per_job=5'+ \ + ' outfile="tsmap_cmds2.txt"' # Execute cstssplit, make sure we catch any exception @@ -135,31 +135,30 @@ class Test(gammalib.GPythonTestSuite): # Return return - # Test cstssplit from Python + # Test cstsmapsplit from Python def _test_python(self): """ - Test cstssplit from Python. + Test cstsmapsplit from Python. """ - # Set-up cstssplit - tssplit = cscripts.cstssplit() - tssplit['inobs'] = 'obs_selected.xml' - tssplit['inmodel'] = 'data/crab.xml' - tssplit['xref'] = 83.6331 - tssplit['yref'] = 22.01 - tssplit['coordsys'] = 'CEL' - tssplit['proj'] = 'CAR' - tssplit['binsz'] = 0.05 - tssplit['nxpix'] = 5 - tssplit['nypix'] = 5 - tssplit['compute_null'] = False - tssplit['bins_per_job'] = 5 - tssplit['outfile'] = 'tsmap_cmd_py1.txt' - + # Set-up cstsmapsplit + tsmapsplit = cscripts.cstsmapsplit() + tsmapsplit['inobs'] = 'obs_selected.xml' + tsmapsplit['inmodel'] = 'data/crab.xml' + tsmapsplit['xref'] = 83.6331 + tsmapsplit['yref'] = 22.01 + tsmapsplit['coordsys'] = 'CEL' + tsmapsplit['proj'] = 'CAR' + tsmapsplit['binsz'] = 0.05 + tsmapsplit['nxpix'] = 5 + tsmapsplit['nypix'] = 5 + tsmapsplit['compute_null'] = False + tsmapsplit['bins_per_job'] = 5 + tsmapsplit['outfile'] = 'tsmap_cmd_py1.txt' # Run cstssplit script and save run list - tssplit.logFileOpen() # Make sure we get a log file - tssplit.run() - tssplit.save() + tsmapsplit.logFileOpen() # Make sure we get a log file + tsmapsplit.run() + tsmapsplit.save() # Check observation definition XML file self._check_cmdfile('tsmap_cmd_py1.txt') @@ -177,8 +176,7 @@ class Test(gammalib.GPythonTestSuite): fname = gammalib.GFilename(filename) # Check if execution was successful - self.test_assert(fname.exists(), - "Output of cstssplit exists") + self.test_assert(fname.exists(), 'Check of output filename exists') # Return return diff --git a/test/test_python_cscripts.py b/test/test_python_cscripts.py index 231ccc4..63c6150 100755 --- a/test/test_python_cscripts.py +++ b/test/test_python_cscripts.py @@ -37,12 +37,12 @@ import test_csroot2caldb import test_cssens import test_csspec import test_cstsdist +import test_cstsmapsplit import test_cstsmapmerge import test_csworkflow import test_csiactcopy import test_csiactdata import test_csiactobs -import test_cstssplit # ================== # @@ -112,9 +112,9 @@ def test(installed=False, debug=False): suite_cssens = test_cssens.Test() suite_csspec = test_csspec.Test() suite_cstsdist = test_cstsdist.Test() + suite_cstsmapsplit = test_cstsmapsplit.Test() suite_cstsmapmerge = test_cstsmapmerge.Test() suite_csworkflow = test_csworkflow.Test() - suite_cstssplit = test_cstssplit.Test() # Setup unit tests suite_cscaldb.set() @@ -130,9 +130,9 @@ def test(installed=False, debug=False): suite_cssens.set() suite_csspec.set() suite_cstsdist.set() + suite_cstsmapsplit.set() suite_cstsmapmerge.set() suite_csworkflow.set() - suite_cstssplit.set() # Append tests to container suites.append(suite_cscaldb) @@ -148,9 +148,9 @@ def test(installed=False, debug=False): suites.append(suite_cssens) suites.append(suite_csspec) suites.append(suite_cstsdist) + suites.append(suite_cstsmapsplit) suites.append(suite_cstsmapmerge) suites.append(suite_csworkflow) - suites.append(suite_cstssplit) # Append tests for Python 2.6+ (the IACT cscripts depend on the json # module which is only available since Python 2.6+