diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am
index 3eb3233..bc9ff33 100755
--- a/cscripts/Makefile.am
+++ b/cscripts/Makefile.am
@@ -1,322 +1,648 @@
#############################################################################
+
# Makefile for cscripts scripts #
+
# ------------------------------------------------------------------------- #
+
# Copyright (C) 2016-2019 Juergen Knoedlseder #
+
# ------------------------------------------------------------------------- #
+
# #
+
# This program is free software: you can redistribute it and/or modify #
+
# it under the terms of the GNU General Public License as published by #
+
# the Free Software Foundation, either version 3 of the License, or #
+
# (at your option) any later version. #
+
# #
+
# This program is distributed in the hope that it will be useful, #
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+
# GNU General Public License for more details. #
+
# #
+
# You should have received a copy of the GNU General Public License #
+
# along with this program. If not, see . #
+
# #
+
#############################################################################
+
+
# Scripts to be distributed in $(pyexecdir)/cscripts
+
pythonscripts = $(top_builddir)/cscripts/__init__.py \
+
$(srcdir)/csbkgmodel.py \
+
$(srcdir)/cscaldb.py \
+
$(srcdir)/csebins.py \
+
$(srcdir)/csinfo.py \
+
$(srcdir)/cslightcrv.py \
+
$(srcdir)/csmodelinfo.py \
+
$(srcdir)/csmodelmerge.py \
+
$(srcdir)/csmodelselect.py \
+
$(srcdir)/csmodelsois.py \
+
$(srcdir)/csobs2caldb.py \
+
$(srcdir)/csobsdef.py \
+
$(srcdir)/csobsinfo.py \
+
$(srcdir)/csobsselect.py \
+
$(srcdir)/csphagen.py \
+
$(srcdir)/csphasecrv.py \
+
$(srcdir)/cspull.py \
+
$(srcdir)/csresmap.py \
+
$(srcdir)/csresspec.py \
+
$(srcdir)/csroot2caldb.py \
+
$(srcdir)/cssens.py \
+
$(srcdir)/csspec.py \
+
$(srcdir)/cssrcdetect.py \
+
$(srcdir)/cstsdist.py \
+
$(srcdir)/cstsmapmerge.py \
+
$(srcdir)/cstsmapsplit.py \
+
$(srcdir)/csviscube.py \
+
+ $(srcdir)/csscs.py \
$(srcdir)/csworkflow.py \
+
$(srcdir)/csfindobs.py \
+
$(srcdir)/csiactcopy.py \
+
$(srcdir)/csiactdata.py \
+
$(srcdir)/csiactobs.py \
+
$(srcdir)/obsutils.py \
+
$(srcdir)/modutils.py \
+
$(srcdir)/calutils.py \
+
$(srcdir)/ioutils.py \
+
$(srcdir)/mputils.py
+
+
# Parfiles to be distributed in $(prefix)/syspfiles
+
parfiles = $(srcdir)/csbkgmodel.par \
+
$(srcdir)/cscaldb.par \
+
$(srcdir)/csebins.par \
+
$(srcdir)/cslightcrv.par \
+
$(srcdir)/csmodelinfo.par \
+
$(srcdir)/csmodelmerge.par \
+
$(srcdir)/csmodelselect.par \
+
$(srcdir)/csmodelsois.par \
+
$(srcdir)/csobs2caldb.par \
+
$(srcdir)/csobsdef.par \
+
$(srcdir)/csobsinfo.par \
+
$(srcdir)/csobsselect.par \
+
$(srcdir)/csphagen.par \
+
$(srcdir)/csphasecrv.par \
+
$(srcdir)/cspull.par \
+
$(srcdir)/csresmap.par \
+
$(srcdir)/csresspec.par \
+
$(srcdir)/csroot2caldb.par \
+
$(srcdir)/cssens.par \
+
$(srcdir)/csspec.par \
+
$(srcdir)/cssrcdetect.par \
+
$(srcdir)/cstsdist.par \
+
$(srcdir)/cstsmapmerge.par \
+
$(srcdir)/cstsmapsplit.par \
+
$(srcdir)/csviscube.par \
+
+ $(srcdir)/csscs.par \
$(srcdir)/csworkflow.par \
+
$(srcdir)/csfindobs.par \
+
$(srcdir)/csiactcopy.par \
+
$(srcdir)/csiactdata.par \
+
$(srcdir)/csiactobs.par
+
+
# Scripts for which symbolic links will be created in bindir
+
linkscripts = csbkgmodel \
+
cscaldb \
+
csebins \
+
csinfo \
+
cslightcrv \
+
csmodelinfo \
+
csmodelmerge \
+
csmodelselect \
+
csmodelsois \
+
csobs2caldb \
+
csobsdef \
+
csobsinfo \
+
csobsselect \
+
csphagen \
+
csphasecrv \
+
cspull \
+
csresmap \
+
csresspec \
+
csroot2caldb \
+
cssens \
+
csspec \
+
cssrcdetect \
+
cstsdist \
+
cstsmapmerge \
+
cstsmapsplit \
+
csviscube \
+
+ csscs \
csworkflow \
+
csfindobs \
+
csiactcopy \
+
csiactdata \
+
csiactobs
+
+
# Test scripts to be distributed in $(pyexecdir)/cscripts/tests
+
testscripts = $(srcdir)/tests/__init__.py \
+
$(top_srcdir)/test/testing.py \
+
$(top_srcdir)/test/test_python_cscripts.py \
+
$(top_srcdir)/test/test_cscript.py \
+
$(top_srcdir)/test/test_cscaldb.py \
+
$(top_srcdir)/test/test_csbkgmodel.py \
+
$(top_srcdir)/test/test_csebins.py \
+
$(top_srcdir)/test/test_csfindobs.py \
+
$(top_srcdir)/test/test_csinfo.py \
+
$(top_srcdir)/test/test_cslightcrv.py \
+
$(top_srcdir)/test/test_csmodelinfo.py \
+
$(top_srcdir)/test/test_csmodelmerge.py \
+
$(top_srcdir)/test/test_csmodelselect.py \
+
$(top_srcdir)/test/test_csmodelsois.py \
+
$(top_srcdir)/test/test_csobs2caldb.py \
+
$(top_srcdir)/test/test_csobsdef.py \
+
$(top_srcdir)/test/test_csobsinfo.py \
+
$(top_srcdir)/test/test_csobsselect.py \
+
$(top_srcdir)/test/test_csphagen.py \
+
$(top_srcdir)/test/test_csphasecrv.py \
+
$(top_srcdir)/test/test_cspull.py \
+
$(top_srcdir)/test/test_csresmap.py \
+
$(top_srcdir)/test/test_csresspec.py \
+
$(top_srcdir)/test/test_csroot2caldb.py \
+
$(top_srcdir)/test/test_cssens.py \
+
$(top_srcdir)/test/test_csspec.py \
+
$(top_srcdir)/test/test_cssrcdetect.py \
+
$(top_srcdir)/test/test_cstsdist.py \
+
$(top_srcdir)/test/test_cstsmapmerge.py \
+
$(top_srcdir)/test/test_cstsmapsplit.py \
+
$(top_srcdir)/test/test_csviscube.py \
+
+ $(top_srcdir)/test/test_csscs.py \
$(top_srcdir)/test/test_csworkflow.py \
+
$(top_srcdir)/test/test_obsutils.py \
+
$(top_srcdir)/test/test_mputils.py \
+
$(top_srcdir)/test/test_csiactcopy.py \
+
$(top_srcdir)/test/test_csiactdata.py \
+
$(top_srcdir)/test/test_csiactobs.py
+
+
# Test data to be distributed in $(pyexecdir)/cscripts/tests/data
+
testdata = $(top_srcdir)/test/data/crab.xml \
+
$(top_srcdir)/test/data/obs_unbinned.xml \
+
$(top_srcdir)/test/data/obs_unbinned_two.xml \
+
$(top_srcdir)/test/data/obs_stacked.xml \
+
$(top_srcdir)/test/data/obs_stacked_two.xml \
+
$(top_srcdir)/test/data/crab_events.fits \
+
$(top_srcdir)/test/data/crab_cntmap.fits \
+
$(top_srcdir)/test/data/crab_expcube.fits.gz \
+
$(top_srcdir)/test/data/crab_psfcube.fits.gz \
+
$(top_srcdir)/test/data/crab_edispcube.fits.gz \
+
$(top_srcdir)/test/data/crab_bkgcube.fits.gz \
+
$(top_srcdir)/test/data/crab_onoff.xml \
+
$(top_srcdir)/test/data/crab_offaxis1.fits.gz \
+
$(top_srcdir)/test/data/crab_offaxis2.fits.gz \
+
$(top_srcdir)/test/data/crab_exclusion.fits.gz \
+
$(top_srcdir)/test/data/crab_src_reg.reg \
+
$(top_srcdir)/test/data/crab_bkg_reg.reg \
+
$(top_srcdir)/test/data/tsmap_0.fits \
+
$(top_srcdir)/test/data/tsmap_1.fits \
+
$(top_srcdir)/test/data/exclusion.reg \
+
$(top_srcdir)/test/data/pntdef_minimal.dat \
+
$(top_srcdir)/test/data/pntdef_maximal.dat \
+
$(top_srcdir)/test/data/models.txt \
+
$(top_srcdir)/test/data/tsmaps.txt \
+
$(top_srcdir)/test/data/model_cube_background1.xml \
+
$(top_srcdir)/test/data/model_cube_background2.xml \
+
$(top_srcdir)/test/data/crab_bkgcube.xml \
+
$(top_srcdir)/test/data/irf.root \
+
$(top_srcdir)/test/data/irf_file.fits.gz \
+
$(top_srcdir)/test/data/workflow.xml \
+
$(top_srcdir)/test/data/butterfly.txt \
+
$(top_srcdir)/test/data/pha.fits \
+
$(top_srcdir)/test/data/pha_channels.fits \
+
$(top_srcdir)/test/data/pull.dat \
+
$(top_srcdir)/test/data/sensitivity.dat \
+
$(top_srcdir)/test/data/sensitivity_integral.dat \
+
$(top_srcdir)/test/data/skymap.fits \
+
$(top_srcdir)/test/data/spectrum.fits \
+
$(top_srcdir)/test/data/residual.fits \
+
$(top_srcdir)/test/data/residual_onoff.fits \
+
$(top_srcdir)/test/data/lightcurve.fits \
+
$(top_srcdir)/test/data/ts.dat \
+
$(top_srcdir)/test/data/models_spatial.xml \
+
$(top_srcdir)/test/data/models_spectral.xml \
+
$(top_srcdir)/test/data/model_filefunction.txt \
+
$(top_srcdir)/test/data/model_map.fits.gz \
+
$(top_srcdir)/test/data/model_mapcube.fits.gz \
+
$(top_srcdir)/test/data/iact_runlist.dat \
+
$(top_srcdir)/test/data/iact_runlist_1.dat \
+
$(top_srcdir)/test/data/iact_runlist_2.dat \
+
$(top_srcdir)/test/data/model_temporal_phasecurve.xml \
+
$(top_srcdir)/test/data/model_temporal_phasecurve.fits \
+
$(top_srcdir)/test/data/phased_events.fits.gz \
+
$(top_srcdir)/test/data/onoff_arf.fits.gz \
+
$(top_srcdir)/test/data/onoff_arf1.fits.gz \
+
$(top_srcdir)/test/data/onoff_arf2.fits.gz \
+
$(top_srcdir)/test/data/onoff_model.xml \
+
$(top_srcdir)/test/data/onoff_obs.xml \
+
$(top_srcdir)/test/data/onoff_obs1.xml \
+
$(top_srcdir)/test/data/onoff_obs2.xml \
+
$(top_srcdir)/test/data/onoff_obs_stacked.xml \
+
$(top_srcdir)/test/data/onoff_pha_off.fits.gz \
+
$(top_srcdir)/test/data/onoff_pha_off1.fits.gz \
+
$(top_srcdir)/test/data/onoff_pha_off2.fits.gz \
+
$(top_srcdir)/test/data/onoff_pha_on.fits.gz \
+
$(top_srcdir)/test/data/onoff_pha_on1.fits.gz \
+
$(top_srcdir)/test/data/onoff_pha_on2.fits.gz \
+
$(top_srcdir)/test/data/onoff_rmf.fits.gz \
+
$(top_srcdir)/test/data/onoff_rmf1.fits.gz \
+
$(top_srcdir)/test/data/onoff_rmf2.fits.gz \
+
$(top_srcdir)/test/data/model_crab_radialacceptance.xml \
+
$(top_srcdir)/test/data/sigdist_map.fits.gz \
+
$(top_srcdir)/test/data/variability.fits.gz \
+
$(top_srcdir)/test/data/viscube.fits.gz \
+
$(top_srcdir)/test/data/hess_bkg_lookup.fits
+
+
# Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata
+
testiactdata = $(top_srcdir)/test/data/iactdata/hdu-index.fits.gz \
+
$(top_srcdir)/test/data/iactdata/master.json \
+
$(top_srcdir)/test/data/iactdata/obs-index.fits.gz
+
+
# Test data to be distributed in $(pyexecdir)/cscripts/tests/data/iactdata/events
+
testiactevents = $(top_srcdir)/test/data/iactdata/events/irf_file.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_0.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_1.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_2.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_3.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_4.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_5.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_6.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_7.fits.gz \
+
$(top_srcdir)/test/data/iactdata/events/events_8.fits.gz
+
+
# Install scripts, parfiles, test scripts and test data. Note that we don't
+
# need to prepend $(DESTDIR) here (not fully clear why, but that's the way
+
# it is)
+
binscriptsdir = $(bindir)
+
binscripts_DATA = $(binscripts)
+
pythonscriptsdir = $(pyexecdir)/cscripts
+
pythonscripts_DATA = $(pythonscripts)
+
pfilesdir = $(prefix)/syspfiles
+
pfiles_DATA = $(parfiles)
+
testscriptsdir = $(pyexecdir)/cscripts/tests
+
testscripts_DATA = $(testscripts)
+
testdatadir = $(pyexecdir)/cscripts/tests/data
+
testdata_DATA = $(testdata)
+
testiactdatadir = $(pyexecdir)/cscripts/tests/data/iactdata
+
testiactdata_DATA = $(testiactdata)
+
testiacteventsdir = $(pyexecdir)/cscripts/tests/data/iactdata/events
+
testiactevents_DATA = $(testiactevents)
+
+
# Files to be distributed in the tar file
+
EXTRA_DIST = $(binscripts) $(pythonscripts) $(parfiles) \
+
$(testscripts) $(testdata) $(testiactdata) \
+
$(testiactevents)
+
+
# Add install hook rule to copy cscripts without .py into the bindir
+
install-data-hook:
+
@binlist='$(binscripts)';\
+
for p in $$binlist; do \
+
chmod +x "$(DESTDIR)$(bindir)/$$p"; \
+
done
+
@linklist='$(linkscripts)';\
+
for p in $$linklist; do \
+
rm -rf "$(DESTDIR)$(bindir)/$$p"; \
+
cp "$(DESTDIR)$(pyexecdir)/cscripts/$$p.py" "$(DESTDIR)$(bindir)/$$p"; \
+
chmod +x "$(DESTDIR)$(bindir)/$$p"; \
+
done
+
+
# Uninstall hook rule to remove the cscripts from the bindir
+
uninstall-hook:
+
@linklist='$(linkscripts)';\
+
for p in $$linklist; do \
+
rm -rf "$(DESTDIR)$(bindir)/$$p"; \
+
done
+
+
# Files to be removed in build directory
+
clean-local:
+
@if ! [ '@top_srcdir@' -ef '@top_builddir@' ]; then \
+
rm -rf $(top_builddir)/cscripts/cs*.py; \
+
rm -rf $(top_builddir)/cscripts/obsutils.py; \
+
rm -rf $(top_builddir)/cscripts/modutils.py; \
+
rm -rf $(top_builddir)/cscripts/calutils.py; \
+
rm -rf $(top_builddir)/cscripts/ioutils.py; \
+
rm -rf $(top_builddir)/cscripts/mputils.py; \
+
rm -rf $(top_builddir)/cscripts/*.par; \
+
fi
+
rm -rf $(top_builddir)/cscripts/*.pyc
+
rm -rf $(top_builddir)/cscripts/__pycache__
+
+
# Uninstall the cscripts Python module
+
uninstall-local:
+
rm -rf $(DESTDIR)$(pyexecdir)/cscripts/*.pyc
+
rm -rf $(DESTDIR)$(pyexecdir)/cscripts/*.pyc
+
rm -rf $(DESTDIR)$(pyexecdir)/cscripts/__pycache__
+
rm -rf $(DESTDIR)$(pyexecdir)/cscripts/tests/*.pyc
+
rm -rf $(DESTDIR)$(pyexecdir)/cscripts/tests/__pycache__
+
diff --git a/cscripts/__init__.py.in b/cscripts/__init__.py.in
index 5327f27..081eda7 100755
--- a/cscripts/__init__.py.in
+++ b/cscripts/__init__.py.in
@@ -1,118 +1,238 @@
# ==========================================================================
+
# cscripts Python module
+
#
+
# Copyright (C) 2015-2018 Juergen Knoedlseder
+
#
+
# This program is free software: you can redistribute it and/or modify
+
# it under the terms of the GNU General Public License as published by
+
# the Free Software Foundation, either version 3 of the License, or
+
# (at your option) any later version.
+
#
+
# This program is distributed in the hope that it will be useful,
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+
# GNU General Public License for more details.
+
#
+
# You should have received a copy of the GNU General Public License
+
# along with this program. If not, see .
+
#
+
# ==========================================================================
+
# Python version check
+
import sys
+
req_version = (2,6)
+
cur_version = sys.version_info
+
+
# List all scripts in this module
+
__all__ = [
+
"csbkgmodel",
+
"cscaldb",
+
"csebins",
+
"csinfo",
+
"cslightcrv",
+
"csmodelinfo",
+
"csmodelmerge",
+
"csmodelselect",
+
"csmodelsois",
+
"csobs2caldb",
+
"csobsdef",
+
"csobsinfo",
+
"csobsselect",
+
"csphagen",
+
"csphasecrv",
+
"cspull",
+
"csresmap",
+
"csresspec",
+
"csroot2caldb",
+
"cssens",
+
"csspec",
+
"cssrcdetect",
+
"cstsdist",
+
"cstsmapmerge",
+
"cstsmapsplit",
+
"csviscube",
+
+ "csscs",
"csworkflow",
+
"obsutils",
+
"modutils",
+
"calutils",
+
"ioutils",
+
"mputils"
+
]
+
if cur_version > req_version:
+
__all__.extend(["csfindobs",
+
"csiactcopy",
+
"csiactdata",
+
"csiactobs"])
+
+
# Import
+
from cscripts.csbkgmodel import csbkgmodel
+
from cscripts.cscaldb import cscaldb
+
from cscripts.csebins import csebins
+
from cscripts.csinfo import csinfo
+
from cscripts.cslightcrv import cslightcrv
+
from cscripts.csmodelinfo import csmodelinfo
+
from cscripts.csmodelmerge import csmodelmerge
+
from cscripts.csmodelselect import csmodelselect
+
from cscripts.csmodelsois import csmodelsois
+
from cscripts.csobs2caldb import csobs2caldb
+
from cscripts.csobsdef import csobsdef
+
from cscripts.csobsinfo import csobsinfo
+
from cscripts.csobsselect import csobsselect
+
from cscripts.csphagen import csphagen
+
from cscripts.csphasecrv import csphasecrv
+
from cscripts.cspull import cspull
+
from cscripts.csresmap import csresmap
+
from cscripts.csresspec import csresspec
+
from cscripts.csroot2caldb import csroot2caldb
+
from cscripts.cssens import cssens
+
from cscripts.csspec import csspec
+
from cscripts.cssrcdetect import cssrcdetect
+
from cscripts.cstsdist import cstsdist
+
from cscripts.cstsmapmerge import cstsmapmerge
+
from cscripts.cstsmapsplit import cstsmapsplit
+
from cscripts.csviscube import csviscube
+
+from cscripts.csscs import csscs
from cscripts.csworkflow import csworkflow
+
from cscripts import obsutils
+
from cscripts import modutils
+
from cscripts import calutils
+
from cscripts import ioutils
+
if cur_version > req_version:
+
from cscripts.csfindobs import csfindobs
+
from cscripts.csiactcopy import csiactcopy
+
from cscripts.csiactdata import csiactdata
+
from cscripts.csiactobs import csiactobs
+
+
# Delete version check variables
+
del sys
+
del req_version
+
del cur_version
+
+
# Add test function
+
def test():
+
"""
+
Run cscripts tests.
+
"""
+
from cscripts.tests import test_python_cscripts
+
test_python_cscripts.test(installed=True)
+
+
# Add version
+
__version__ = '@PACKAGE_VERSION@'
+
diff --git a/cscripts/csscs.par b/cscripts/csscs.par
new file mode 100644
index 0000000..93cafc0
--- /dev/null
+++ b/cscripts/csscs.par
@@ -0,0 +1,28 @@
+#############################################################################
+# #
+# CTA Science Analysis Tools #
+# #
+# ------------------------------------------------------------------------- #
+# #
+# File: csscs.par #
+# #
+# Author: Luigi Tibaldo #
+# luigi.tibaldo@irap.omp.eu #
+# IRAP #
+# #
+# Purpose: Parameter file for the csscs script #
+# #
+#############################################################################
+#
+# General parameters
+#===================
+# Your parameters go here
+
+#
+# Standard parameters
+#====================
+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,,, "Activate debugging mode?"
+mode, s, h, ql,,, "Mode of automatic parameters"
+logfile, f, h, csscs.log,,, "Log filename"
diff --git a/cscripts/csscs.py b/cscripts/csscs.py
new file mode 100755
index 0000000..412981e
--- /dev/null
+++ b/cscripts/csscs.py
@@ -0,0 +1,136 @@
+#! /usr/bin/env python
+# ==========================================================================
+# Spectral component separation script
+#
+# Copyright (C) 2020 Luigi Tibaldo
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# ==========================================================================
+import sys
+import gammalib
+import ctools
+
+
+# ================= #
+# csscs class #
+# ================= #
+class csscs(ctools.csobservation):
+ """
+ Spectral component separation script
+ """
+
+ # Constructor
+ def __init__(self, *argv):
+ """
+ Constructor
+
+ Parameters
+ ----------
+ argv : list of str
+ List of IRAF command line parameter strings of the form
+ ``parameter=3``.
+ """
+ # Initialise application by calling the base class constructor
+ self._init_csobservation(self.__class__.__name__, ctools.__version__, argv)
+
+ # Return
+ return
+
+ # State methods for pickling
+ def __getstate__(self):
+ """
+ Extend ctools.csobservation __getstate__ method
+
+ Returns
+ -------
+ state : dict
+ Pickled instance
+ """
+ # Set pickled dictionary
+ state = {'base' : ctools.csobservation.__getstate__(self)}
+
+ # Return pickled dictionary
+ return state
+
+ def __setstate__(self, state):
+ """
+ Extend ctools.csobservation __setstate__ method
+
+ Parameters
+ ----------
+ state : dict
+ Pickled instance
+ """
+ # Set state
+ ctools.csobservation.__setstate__(self, state['base'])
+
+ # Return
+ return
+
+
+ # Private methods
+ def _get_parameters(self):
+ """
+ Get parameters from parfile
+ """
+ # TODO: Add code to query all relevant parameters
+
+ # Write input parameters into logger
+ self._log_parameters(gammalib.TERSE)
+
+ # Return
+ return
+
+
+ # Public methods
+ def run(self):
+ """
+ Run the script
+ """
+ # Switch screen logging on in debug mode
+ if self._logDebug():
+ self._log.cout(True)
+
+ # Get parameters
+ self._get_parameters()
+
+ # TODO: Your code goes here
+
+ # Return
+ return
+
+ def save(self):
+ """
+ Save something
+ """
+ # Write header
+ self._log_header1(gammalib.TERSE, 'Save something')
+
+ # TODO: Your code goes here
+
+ # Return
+ return
+
+
+# ======================== #
+# Main routine entry point #
+# ======================== #
+if __name__ == '__main__':
+
+ # Create instance of application
+ app = csscs(sys.argv)
+
+ # Execute application
+ app.execute()
diff --git a/doc/source/users/reference_manual/csscs.rst b/doc/source/users/reference_manual/csscs.rst
new file mode 100644
index 0000000..f78491a
--- /dev/null
+++ b/doc/source/users/reference_manual/csscs.rst
@@ -0,0 +1,54 @@
+.. _csscs:
+
+csscs
+==============================
+
+ToDo: Describe in a one liner what the script is doing.
+
+
+Synopsis
+--------
+
+ToDo: Desribe in detail what the script is doing, what it takes on input and
+what it produces on output. Please do not write more than 80 characters per
+line since this file is also used to produce a help text for the terminal.
+
+
+General parameters
+------------------
+
+ToDo: Add here your parameters.
+
+
+Standard parameters
+-------------------
+
+``(chatter = 2) [integer]``
+ Verbosity of the executable:
+ ``chatter = 0``: no information will be logged
+
+ ``chatter = 1``: only errors will be logged
+
+ ``chatter = 2``: errors and actions will be logged
+
+ ``chatter = 3``: report about the task execution
+
+ ``chatter = 4``: detailed report about the task execution
+
+``(clobber = yes) [boolean]``
+ Specifies whether an existing output file should be overwritten.
+
+``(debug = no) [boolean]``
+ 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 = csscs.log) [string]``
+ Name of log file.
+
+
+Related tools or scripts
+------------------------
+
+None
diff --git a/doc/source/users/reference_manual/index.rst b/doc/source/users/reference_manual/index.rst
index 9159f89..5782349 100755
--- a/doc/source/users/reference_manual/index.rst
+++ b/doc/source/users/reference_manual/index.rst
@@ -1,89 +1,179 @@
.. _reference:
+
+
Reference Manual
+
================
+
+
This manual provides reference information for all ctools and csripts.
+
General information on ctools usage can be found `here
+
<../user_manual/introduction.html>`_. The description of user parameters in the reference
+
manual is documented `here `__.
+
+
+
Below you find links to the command line reference for all available tools and scripts.
+
+
ctools
+
------
+
+
.. toctree::
+
:maxdepth: 1
+
+
ctbin --- Generates counts cube
+
ctbkgcube --- Generates background cube
+
ctbutterfly --- Compute butterfly
+
ctcubemask --- Filter counts cube
+
ctedispcube --- Generates energy dispersion cube
+
cterror --- Calculates likelihood profile errors
+
ctexpcube --- Generates exposure cube
+
ctfindvar --- Search for source variability
+
ctlike --- Performs maximum likelihood fitting
+
ctmapcube --- Generates a map cube
+
ctmodel --- Computes model counts cube
+
ctobssim --- Simulate observations
+
ctphase --- Computes the phase of each event
+
ctprob --- Computes event probability for a given model
+
ctpsfcube --- Generates point spread function cube
+
ctselect --- Selects event data
+
ctskymap --- Generates sky map
+
cttsmap --- Generates Test Statistic map
+
ctulimit --- Calculates upper limit
+
+
+
cscripts
+
--------
+
+
.. toctree::
+
:maxdepth: 1
+
+
+ csscs --- ToDo: Describe what script is doing
csbkgmodel --- Generates background model for 3D analysis
+
cscaldb --- Lists available instrument response functions
+
csebins --- Generates energy boundaries for stacked analysis
+
cslightcrv --- Computes light curve
+
csmodelinfo --- Shows model container content
+
csmodelmerge --- Merges several model containers into one file
+
csmodelselect --- Select models from model definition file
+
csmodelsois --- Generate map cube from subset of models
+
csobsdef --- Generates observation definition file
+
csobsinfo --- Shows observation container content
+
csobsselect --- Select observations from observation definition file
+
csphagen --- Generates PHA, ARF, RMF files based on source/background regions
+
csphasecrv --- Computes phase curve
+
cspull --- Generates pull distribution
+
csresmap --- Generates residual map
+
csresspec --- Generates residual spectrum
+
csroot2caldb --- Creates a caldb entry from a ROOT file
+
cssens --- Computes CTA sensitivity
+
csspec --- Computes spectral points
+
cssrcdetect --- Detects sources in sky map
+
cstsdist --- Generates Test Statistic distribution
+
cstsmapmerge --- Merges slices from Test Statistic map computations
+
cstsmapsplit --- Creates commands to split the Test Statistic map computations
+
csviscube --- Computes visibility cube
+
+
+
Scripts to manage an IACT database
+
----------------------------------
+
+
.. warning::
+
+
The ``csiactdata``, ``csiactobs``, ``csfindobs`` and ``csiactcopy`` scripts
+
rely on the ``json`` Python module which is only available in Python 2.6
+
or higher. These scripts will not work on older Python versions.
+
+
.. toctree::
+
:maxdepth: 1
+
+
csobs2caldb --- Creates a caldb entry from an input observation
+
csiactdata --- Shows information about IACT data available on the user machine
+
csiactobs --- Generates observation definition file for IACT data from observation IDs
+
csfindobs --- Generates a list of IACT observation IDs
+
csiactcopy --- Copies IACT data from one location to another
+
diff --git a/test/test_csscs.py b/test/test_csscs.py
new file mode 100644
index 0000000..fb47c42
--- /dev/null
+++ b/test/test_csscs.py
@@ -0,0 +1,157 @@
+#! /usr/bin/env python
+# ==========================================================================
+# This scripts performs unit tests for the csscs script.
+#
+# Copyright (C) 2020 Luigi Tibaldo
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+# ==========================================================================
+import os
+import gammalib
+import cscripts
+from testing import test
+
+
+# ========================= #
+# Test class for csscs script #
+# ========================= #
+class Test(test):
+ """
+ Test class for csscs script
+
+ This test class makes unit tests for the csscs script by using it from
+ the command line and from Python.
+ """
+
+ # Constructor
+ def __init__(self):
+ """
+ Constructor
+ """
+ # Call base class constructor
+ test.__init__(self)
+
+ # Return
+ return
+
+ # Set test functions
+ def set(self):
+ """
+ Set all test functions
+ """
+ # Set test name
+ self.name('csscs')
+
+ # Append tests
+ self.append(self._test_cmd, 'Test csscs on command line')
+ self.append(self._test_python, 'Test csscs from Python')
+ self.append(self._test_pickeling, 'Test csscs pickeling')
+
+ # Return
+ return
+
+ # Test csscs on command line
+ def _test_cmd(self):
+ """
+ Test csscs on the command line
+ """
+ # Set script name
+ csscs = self._script('csscs')
+
+ # Setup csscs command
+ cmd = csscs+' logfile="csscs_cmd1.log" chatter=1'
+
+ # Check if execution was successful
+ self.test_value(self._execute(cmd), 0,
+ 'Check successful execution from command line')
+
+ # Check csscs --help
+ self._check_help(csscs)
+
+ # Return
+ return
+
+ # Test csscs from Python
+ def _test_python(self):
+ """
+ Test csscs from Python
+ """
+ # Allocate csscs
+ script = cscripts.csscs()
+
+ # Check that saving does not nothing
+ script['logfile'] = 'csscs_py0.log'
+ script.logFileOpen()
+ script.save()
+ self.test_assert(not os.path.isfile('csscs_py0.fits'),
+ 'Check that no FITS file has been created')
+
+ # Check that clearing does not lead to an exception or segfault
+ script.clear()
+
+ # Now set csscs parameters
+ script['logfile'] = 'csscs_py1.log'
+ script['chatter'] = 2
+
+ # Run csscs script
+ script.logFileOpen()
+ script.run()
+
+ # Check result
+ self._check_result(script)
+
+ # Return
+ return
+
+ # Test csscs pickeling
+ def _test_pickeling(self):
+ """
+ Test csscs pickeling
+ """
+ # Perform pickeling test of empty class
+ self._pickeling(cscripts.csscs())
+
+ # Setup script for pickling text
+ script = cscripts.csscs()
+ script['logfile'] = 'csscs_py1_pickle.log'
+ script['chatter'] = 2
+
+ # Perform pickeling tests of filled class
+ obj = self._pickeling(script)
+
+ # Run csscs script and save result
+ obj.logFileOpen() # Make sure we get a log file
+ obj.run()
+ obj.save()
+
+ # TODO: Check result file
+
+ # Return
+ return
+
+ # Check csscs result
+ def _check_result(self, script):
+ """
+ Check content of script
+
+ Parameters
+ ----------
+ script : `~cscripts.csscs`
+ csscs instance
+ """
+ # TODO: Implement test on script result
+
+ # Return
+ return
diff --git a/test/test_python_cscripts.py b/test/test_python_cscripts.py
index 3ae5c97..affd9b7 100755
--- a/test/test_python_cscripts.py
+++ b/test/test_python_cscripts.py
@@ -1,211 +1,424 @@
#! /usr/bin/env python
+
# ==========================================================================
+
# This scripts performs unit tests for cscripts
+
#
+
# Copyright (C) 2016-2019 Juergen Knoedlseder
+
#
+
# This program is free software: you can redistribute it and/or modify
+
# it under the terms of the GNU General Public License as published by
+
# the Free Software Foundation, either version 3 of the License, or
+
# (at your option) any later version.
+
#
+
# This program is distributed in the hope that it will be useful,
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+
# GNU General Public License for more details.
+
#
+
# You should have received a copy of the GNU General Public License
+
# along with this program. If not, see .
+
#
+
# ==========================================================================
+
import os
+
import sys
+
import gammalib
+
import cscripts
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+
import test_cscript
+
import test_cscaldb
+
import test_csbkgmodel
+
import test_csebins
+
import test_csfindobs
+
import test_csinfo
+
import test_cslightcrv
+
import test_csmodelinfo
+
import test_csmodelmerge
+
import test_csmodelselect
+
import test_csmodelsois
+
import test_csobs2caldb
+
import test_csobsdef
+
import test_csobsinfo
+
import test_csobsselect
+
import test_csphagen
+
import test_csphasecrv
+
import test_cspull
+
import test_csresmap
+
import test_csresspec
+
import test_csroot2caldb
+
import test_cssens
+
import test_csspec
+
import test_cssrcdetect
+
import test_cstsdist
+
import test_cstsmapmerge
+
import test_cstsmapsplit
+
import test_csviscube
+
+import test_csscs
import test_csworkflow
+
import test_obsutils
+
import test_mputils
+
import test_csiactcopy
+
import test_csiactdata
+
import test_csiactobs
+
+
+
# ================== #
+
# Perform unit tests #
+
# ================== #
+
def test(installed=False, debug=False):
+
"""
+
Perform cscripts unit testing.
+
+
Parameters
+
----------
+
installed : bool, optional
+
Flag indicating whether the script has been installed or not
+
debug : bool, optional
+
Enables debugging
+
"""
+
# If we have an installed version then create a temporary directory and
+
# copy over all information that is needed
+
if installed:
+
+
# Create temporary working directory
+
import tempfile
+
path = tempfile.mkdtemp()
+
os.chdir(path)
+
+
# Get test directory
+
import inspect
+
testdir = inspect.getfile(cscripts.tests)
+
dirname = os.path.dirname(testdir)
+
+
# Copy test data in "data" directory
+
os.system('cp -r %s %s' % (dirname+'/data', 'data'))
+
+
# Set test data environment variable
+
os.environ['TEST_DATA'] = 'data'
+
+
# ... otherwise set the calibration database to the one shipped with the
+
# package; we don't need to set the 'TEST_DATA', this is done by the
+
# test environment
+
else:
+
os.environ['CALDB'] = '%s/caldb' % (os.environ['TEST_SRCDIR'])
+
+
# Create a local "pfiles" directory and set PFILES environment variable
+
try:
+
os.mkdir('pfiles')
+
except:
+
pass
+
os.environ['PFILES'] = 'pfiles'
+
+
# Copy the cscripts parameter files into the "pfiles" directory. For a
+
# non-installed test we copy the parameter files from the "cscripts"
+
# source directory into the "pfiles" directory, for an installed version
+
# we get all parameter files from the "syspfiles" directory. Also make
+
# sure that all parameter files are writable.
+
if not installed:
+
os.system('cp -r %s/cscripts/*.par pfiles/'% (os.environ['TEST_SRCDIR']))
+
os.system('chmod u+w pfiles/*')
+
else:
+
os.system('cp -r %s/syspfiles/*.par pfiles/' % (os.environ['CTOOLS']))
+
os.system('chmod u+w pfiles/*')
+
+
# Define list of test suites
+
tests = [test_cscript.Test(),
+
test_csbkgmodel.Test(),
+
test_cscaldb.Test(),
+
test_csebins.Test(),
+
test_csinfo.Test(),
+
test_cslightcrv.Test(),
+
test_csmodelinfo.Test(),
+
test_csmodelmerge.Test(),
+
test_csmodelselect.Test(),
+
test_csmodelsois.Test(),
+
test_csobs2caldb.Test(),
+
test_csobsdef.Test(),
+
test_csobsinfo.Test(),
+
test_csobsselect.Test(),
+
test_csphagen.Test(),
+
test_csphasecrv.Test(),
+
test_cspull.Test(),
+
test_csresmap.Test(),
+
test_csresspec.Test(),
+
test_csroot2caldb.Test(),
+
test_cssens.Test(),
+
test_csspec.Test(),
+
test_cssrcdetect.Test(),
+
test_cstsdist.Test(),
+
test_cstsmapmerge.Test(),
+
test_cstsmapsplit.Test(),
+
test_csviscube.Test(),
+
+ test_csscs.Test(),
test_csworkflow.Test(),
+
test_obsutils.Test(),
+
test_mputils.Test()]
+
+
# Append tests for Python 2.6+ (the IACT cscripts depend on the json
+
# module which is only available since Python 2.6+)
+
ver = sys.version.split()[0]
+
if ver >= '2.6.0':
+
+
# Check for VHEFITS environment variable
+
if 'VHEFITS' in os.environ:
+
+
# If the environment variable exists then unset it for the test
+
# cases. Since Python is executed in a subprocess this will not
+
# impact the environment variable in the parent shell.
+
del os.environ['VHEFITS']
+
+
# Append IACT script tests to list of test suites
+
tests.extend([test_csfindobs.Test(),
+
test_csiactcopy.Test(),
+
test_csiactdata.Test(),
+
test_csiactobs.Test()])
+
+
# Allocate test suite container
+
suites = gammalib.GTestSuites('cscripts unit testing')
+
+
# Set test suites and append them to suite container
+
for suite in tests:
+
suite.set()
+
suites.append(suite)
+
+
# Run test suite
+
success = suites.run()
+
+
# Save test results
+
if not installed:
+
suites.save('reports/cscripts.xml')
+
else:
+
suites.save('cscripts_reports.xml')
+
+
# If debuging is requested then print test suites
+
if debug:
+
print(suites)
+
+
# Remove temporary direction
+
if installed:
+
os.system('rm -rf %s' % (path))
+
+
# Raise an exception in case of failure
+
if not success:
+
raise RuntimeError('At least one error occured during the test.')
+
+
# Return
+
return
+
+
+
# ======================== #
+
# Main routine entry point #
+
# ======================== #
+
if __name__ == '__main__':
+
+
# Run tests
+
test()
+