diff --git a/cscripts/csfindobs.py b/cscripts/csfindobs.py index 3a2da42..62f9759 100755 --- a/cscripts/csfindobs.py +++ b/cscripts/csfindobs.py @@ -1,28 +1,45 @@ #!/usr/bin/env python +# ========================================================================== +# Find observations from an IACT data store +# +# Copyright (C) 2016 Michael Mayer +# +# 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 gammalib import ctools import sys import os import json -# ============== # -# csrunfinder class # -# ============== # + +# =============== # +# csfindobs class # +# =============== # class csfindobs(ctools.cscript): """ - This class can be used to find observations from an IACT data store. It derives - from the GammaLib::GApplication class which provides support for parameter - files, command line arguments, and logging. In that way the Python - script behaves just as a regular ctool. + This class can be used to find observations from an IACT data store. """ def __init__(self, *argv): """ Constructor. """ # Set name - self.name = "csfindobs" - self.version = "1.0.0" - self.verbose = False + self.name = "csfindobs" + self.version = "1.0.0" + self.verbose = False self.datapath = os.getenv("VHEFITS","") # Make sure that parfile exists @@ -70,16 +87,17 @@ class csfindobs(ctools.cscript): # Create default parfile pars = gammalib.GApplicationPars() - pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data is located")) + pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data are located")) pars.append(gammalib.GApplicationPar("prodname","s","a","prod-name","","","Name of FITS production (Run csiactdata to view your options)")) + pars.append(gammalib.GApplicationPar("outfile","f","a","runlist.lis","","","Runlist outfile")) pars.append(gammalib.GApplicationPar("ra","r","a","83.6331","","","Right ascension")) pars.append(gammalib.GApplicationPar("dec","r","a","22.01","","","Declination")) pars.append(gammalib.GApplicationPar("rad","r","a","2.5","","","Search radius")) pars.append(gammalib.GApplicationPar("min_qual","i","h","0","0|1|2","","Minimum data quality (0=perfect, 1=ok, 2=bad)")) pars.append(gammalib.GApplicationPar("expression","s","h","NONE","","","Additional expression")) pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) - pars.append(gammalib.GApplicationPar("outfile","f","a","runlist.lis","","","Runlist outfile")) pars.append_standard() + pars.append(gammalib.GApplicationPar("logfile","f","h","csfindobs.log","","","Log filename")) pars.save(parfile) # Return @@ -97,7 +115,7 @@ class csfindobs(ctools.cscript): self.datapath = gammalib.expand_env(self.datapath) # Get production name - self.m_prodname = self["prodname"].string() + self.m_prodname = self["prodname"].string() # Master index file name self.m_master_indx = self["master_indx"].string() @@ -109,8 +127,8 @@ class csfindobs(ctools.cscript): if self["ra"].is_valid() and self["dec"].is_valid() and self["rad"].is_valid(): # Read spatial parameters - self.m_ra = self["ra"].real() - self.m_dec = self["dec"].real() + self.m_ra = self["ra"].real() + self.m_dec = self["dec"].real() self.m_radius = self["rad"].real() else: @@ -121,7 +139,7 @@ class csfindobs(ctools.cscript): self.select_radec = False # Read other parameters - self.m_quality = self["min_qual"].integer() + self.m_quality = self["min_qual"].integer() self.m_expression = self["expression"].string() # Check for validity of expression @@ -159,9 +177,10 @@ class csfindobs(ctools.cscript): raise RuntimeError("FITS data store \""+self.m_prodname+"\" not available. Run csiactdata to get a list of available storage names") if not gammalib.is_fits(self.m_obs_index+"[OBS_INDEX]"): raise RuntimeError("Observation index file \""+self.m_obs_index+"[OBS_INDEX]\" for FITS data store \""+self.m_prodname+"\" not available. Check your master index file or run csdsinfo to get a list of available storage names.") - - self.m_log = False # Logging in client tools - self.m_debug = False # Debugging in client tools + + # Set other members + self.m_log = False # Logging in client tools + self.m_debug = False # Debugging in client tools self.m_clobber = self["clobber"].boolean() # Return @@ -187,8 +206,7 @@ class csfindobs(ctools.cscript): # Return return - - + def run(self): """ Run the script. @@ -241,14 +259,15 @@ class csfindobs(ctools.cscript): # Read observation IDs into array for i in range(obs_indx.nrows()): self.runs.append(obs_indx["OBS_ID"][i]) - + + # Dump expression if self.logNormal(): self.log("\n") self.log.header3("Expression") self.log(expr) self.log("\n") - - + + # Dump number of observations if self.logTerse(): self.log("\n") self.log.header3("Observations") @@ -282,7 +301,7 @@ class csfindobs(ctools.cscript): # ======================== # if __name__ == '__main__': """ - Generates residual count map. + Find IACT observations. """ # Create instance of application app = csfindobs(sys.argv) diff --git a/cscripts/csiactdata.py b/cscripts/csiactdata.py index afeb50b..32050b8 100755 --- a/cscripts/csiactdata.py +++ b/cscripts/csiactdata.py @@ -40,8 +40,8 @@ class csiactdata(ctools.cscript): Constructor. """ # Set name - self.name = "csiactdata" - self.version = "1.0.0" + self.name = "csiactdata" + self.version = "1.0.0" self.datapath = os.getenv("VHEFITS","") # Make sure that parfile exists diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index 7a06faa..731ab96 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -94,11 +94,11 @@ class csiactobs(ctools.cscript): pars = gammalib.GApplicationPars() pars.append(gammalib.GApplicationPar("datapath","s","a",self.datapath,"","","Path were data is located")) pars.append(gammalib.GApplicationPar("prodname","s","a","","","","Data storage name (Run csiactdata to view your options)")) - pars.append(gammalib.GApplicationPar("runlistfile","f","a","runlist.lis","","","Runlist file")) - pars.append(gammalib.GApplicationPar("bkgpars","i","a","1","","","Number of free parameters per background model")) + pars.append(gammalib.GApplicationPar("infile","f","a","runlist.lis","","","Runlist file")) + pars.append(gammalib.GApplicationPar("inmodel","f","h","NONE","","","Input model XML file (optional)")) pars.append(gammalib.GApplicationPar("outobs","f","a","obs.xml","","","Observation XML outfile")) pars.append(gammalib.GApplicationPar("outmodel","f","a","bgmodels.xml","","","Output model XML file")) - pars.append(gammalib.GApplicationPar("inmodel","f","h","NONE","","","Input model XML file (optional)")) + pars.append(gammalib.GApplicationPar("bkgpars","i","a","1","","","Number of free parameters per background model")) pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) pars.append(gammalib.GApplicationPar("bkg_scale","b","h","yes","","","Specifies whether the background scaling factor from the observation index file should be applied if available. ")) pars.append(gammalib.GApplicationPar("ev_hiera","s","h","events","","","Hierarchy of event formats")) @@ -133,7 +133,7 @@ class csiactobs(ctools.cscript): # Read user parameters self.m_prodname = self["prodname"].string() - self.m_runlistfile = gammalib.expand_env(self["runlistfile"].filename()) + self.m_runlistfile = gammalib.expand_env(self["infile"].filename()) self.m_bkgpars = self["bkgpars"].integer() # Output model file diff --git a/doc/source/reference_manual/csfindobs.rst b/doc/source/reference_manual/csfindobs.rst index a141d16..009940b 100644 --- a/doc/source/reference_manual/csfindobs.rst +++ b/doc/source/reference_manual/csfindobs.rst @@ -3,54 +3,65 @@ csfindobs ========= -Creates a list of observation IDs that fulfil certain criteria, e.g. pointing close to specific source +Creates a list of observation IDs that fulfils certain criteria, e.g. +pointing close to specific source. Synopsis -------- -This script can be used to create lists of observation IDs that share certain properties. For -instance, all observations pointing around a specific sky position can be selected. In addition, -the script is flexible to use expressions to further constrain criteria to select observations. -The user can e.g. select all observations within a certain zenith angle range by specifying the hidden -parameter expression: e.g. use ``csfindobs expression="ZEN_PNT<50&&ZEN_PNT>40"`` to constrain the zenith angle range -from 40 to 50 degrees. The output of this script is an ASCII file containing observation IDs that fulfil criteria -specified by the user. This file can be used as input for :doc:`csiactobs`. The script operates -on an observation index file that needs to be provided along with IACT data. `See here `__ how IACT data -should be structured. To investigate additional parameters which are available for selection, -have a look `here `__. +This script can be used to create lists of observation IDs that share certain +properties. For instance, all observations pointing around a specific sky +position can be selected. In addition, the script is flexible to use expressions +to further constrain criteria to select observations. The user can e.g. select +all observations within a certain zenith angle range by specifying the hidden +parameter expression. For example + +``csfindobs expression="ZEN_PNT<50&&ZEN_PNT>40"`` + +is used to select observations with zenith angle range between 40 and 50 degrees. + +The parameter ``datapath`` is only queried if the environment variable $VHEFITS +is not set. + +The output of this script is an ASCII file containing observation IDs that +fulfil criteria specified by the user. This file can be used as input for +:doc:`csiactobs`. The script operates on an observation index file that needs +to be provided along with IACT data. `See here `__ +how IACT data should be structured. To investigate additional parameters which +are available for selection, have a look `here `__. General parameters ------------------ ``datapath [string]`` - Path were data is located + Path were data are located. ``prodname [string]`` - Name of FITS production (Run :doc:`csiactdata` to view your options) + Name of FITS production (Run :doc:`csiactdata` to view your options). + +``outfile [file]`` + Output runlist ASCII file. ``ra [real]`` - Right ascension of search region (invoke "INDEF" to avoid spatial selection) + Right ascension of search region (invoke "INDEF" to avoid spatial selection). ``dec [real]`` - Declination of search region (invoke "INDEF" to avoid spatial selection) + Declination of search region (invoke "INDEF" to avoid spatial selection). ``rad [real]`` - Radius of search region (deg) (invoke "INDEF" or negative values to avoid spatial selection) + Radius of search region (deg) (invoke "INDEF" or negative values to avoid + spatial selection) -``outfile [file]`` - Runlist outfile - ``(min_qual = 0) [integer]`` - Minimum data quality (0=best, 1=medium, 2=bad) + Minimum data quality (0=best, 1=medium, 2=bad). ``(expression = NONE) [string]`` - Additional expression + Additional expression. ``(master_index = master.json) [string]`` - Name of master index file - + Name of master index file. Standard parameters @@ -84,4 +95,4 @@ Standard parameters Related tools or scripts ------------------------ -None \ No newline at end of file +:doc:`csiactobs` \ No newline at end of file diff --git a/doc/source/reference_manual/csiactdata.rst b/doc/source/reference_manual/csiactdata.rst index 141c98a..116a29c 100644 --- a/doc/source/reference_manual/csiactdata.rst +++ b/doc/source/reference_manual/csiactdata.rst @@ -3,26 +3,29 @@ csiactdata =========== -Dumps information about the available FITS productions of IACT data on the screen +Dumps information about the available FITS productions of IACT data on the +screen. Synopsis -------- This script inspects the local IACT FITS data storage and prints the names of -available and valid data productions on the screen. The first parameter ``datapath`` -is only queried if the environment variable $VHEFITS is not set. The path should be set -to the location of the `master index file `__. -The output of this script can be used as input for further tools that use IACT data. +available and valid data productions on the screen. The parameter ``datapath`` +is only queried if the environment variable $VHEFITS is not set. The path should +be set to the location of the `master index file `__. +The output of this script can be used as input for further tools that use IACT +data. + General parameters ------------------ ``datapath [string]`` - Path were data is located + Path were data are located. ``(master_index = master.json) [string]`` - Name of master index file + Name of master index file. Standard parameters @@ -56,4 +59,4 @@ Standard parameters Related tools or scripts ------------------------ -None \ No newline at end of file +:doc:`csfindobs` \ No newline at end of file diff --git a/doc/source/reference_manual/csiactobs.rst b/doc/source/reference_manual/csiactobs.rst index 2cc5f23..8bdee1d 100644 --- a/doc/source/reference_manual/csiactobs.rst +++ b/doc/source/reference_manual/csiactobs.rst @@ -3,98 +3,109 @@ csiactobs =========== -Creates an observation XML file for IACTs using a list of observation IDs as input +Creates an observation XML file for IACTs using a list of observation IDs as +input. Synopsis -------- -This script creates an observation XML file from a list of observation IDs provided in an ASCII file. -Such an ASCII file can for instance be created with :doc:`csfindobs`. The script operates on IACT data -that needs to be present on the user machine. `See here `__ how IACT data -should be structured. - -Besides creating an observation XML file, this script also stores a model XML file that contains background models for each -observation. The number of free parameters is steered via the ``bkgpars`` parameter. - -The user can also specify as ``inmodel`` parameter an XML model file with e.g. sky models. The output model -will then contain these models as well. - -The script further allows to specify hierarchies for the data formats and background models. The program will -pick the first available option and fall back to the next one if the first choice is unavailable. -If e.g. the IRF background model is not available, the script will assign the next background model in the hierarchy ``bkg_mod_hiera``. -If the user wants to use a Gaussian background model as first choice, the parameter ``bkg_mod_hiera`` should be specified to "gauss". -In addition, the user can specify start parameters for the background parameters that will be in the output XML model. - -If an observation that given in the input ASCII file is not available on the user machine, the script dumps a warning into the logfile -and the obsservation is skipped. +This script creates an observation XML file from a list of observation IDs +provided in an ASCII file. Such an ASCII file can for instance be created with +:doc:`csfindobs`. The script operates on IACT data that needs to be present on +the user machine. `See here `__ +how IACT data should be structured. + +The parameter ``datapath`` is only queried if the environment variable $VHEFITS +is not set. + +Besides creating an observation XML file, this script also stores a model XML +file that contains background models for each observation. The number of free +parameters is steered via the ``bkgpars`` parameter. + +The user can also specify as ``inmodel`` parameter an XML model file with e.g. +sky models. The output model will then contain these models as well. + +The script further allows to specify hierarchies for the data formats and +background models. The script will pick the first available option and fall back +to the next one if the first choice is unavailable. If e.g. the IRF background +model is not available, the script will assign the next background model in the +hierarchy ``bkg_mod_hiera``. If the user wants to use a Gaussian background model +as first choice, the parameter ``bkg_mod_hiera`` should be specified to "gauss". +In addition, the user can specify start parameters for the background parameters +that will be in the output XML model. + +If an observation that given in the input ASCII file is not available on the user +machine, the script dumps a warning into the logfile and the obsservation is +skipped. General parameters ------------------ ``datapath [string]`` - Path were data is located + Path were data are located. ``prodname [string]`` - Name of FITS production (Run :doc:`csiactdata` to view your options) + Name of FITS production (Run :doc:`csiactdata` to view your options). -``runlistfile [file]`` - Input list of observation IDs - -``bkgpars [integer]`` - Number of free parameters for each background model +``infile [file]`` + Input runlist ASCII file. +``(inmodel = NONE) [file]`` + Input model XML file. + ``outobs [file]`` - Observation XML outfile + Output Observation Definition XML file. ``outmodel [file]`` - Output model XML file + Output model XML file. + +``bkgpars [integer]`` + Number of free parameters for each background model. -``(inmodel = NONE) [file]`` - Input model XML file (optional) - ``(master_indx = master.json) [file]`` - Name of master index file + Name of master index file. ``(bkg_scale = yes) [boolean] - Specifies whether the background scaling factor from the observation index file should be applied if available. + Specifies whether the background scaling factor from the observation index + file should be applied if available. ``(ev_hiera = events) [string]`` - Hierarchy of event file formats + Hierarchy of event file formats. ``(aeff_hiera = aeff_2d) [string]`` - Hierarchy of effective area formats + Hierarchy of effective area formats. ``(psf_hiera = psf_king|psf_3gauss) [string]`` - Hierarchy of psf formats + Hierarchy of point spread function formats. ``(edisp_hiera = edisp_2d) [string]`` - Hierarchy of energy disperson formats + Hierarchy of energy disperson formats. ``(bkg_hiera = bkg_3d) [string]`` Hierarchy of background formats. ``(bkg_mod_hiera = irf|aeff|gauss) [string]`` - Hierarchy of background models + Hierarchy of background models. ``(bkg_gauss_norm = 1e-8) [real]`` - Input normalisation for Gaussian background + Input normalisation for Gaussian background. ``(bkg_gauss_index = -2.0) [real]`` - Input spectral index for Gaussian background + Input spectral index for Gaussian background. ``(bkg_gauss_sigma = 1e-8) [real]`` - Input sigma for Gaussian background + Input sigma for Gaussian background. ``(bkg_aeff_norm = 1e-14) [real]`` - Input normalisation for effective area background + Input normalisation for effective area background. ``(bkg_aeff_index = -2.0) [real]`` - Input spectral index for effective area background + Input spectral index for effective area background. ``(bkg_range_factor = 100.0) [real]`` - Factor to determine range of background normalisation + Factor to determine range of background normalisation. Standard parameters @@ -128,4 +139,4 @@ Standard parameters Related tools or scripts ------------------------ -None \ No newline at end of file +:doc:`csiactobs` \ No newline at end of file diff --git a/doc/source/reference_manual/cstsmapmerge.rst b/doc/source/reference_manual/cstsmapmerge.rst index 1370f10..3683a29 100644 --- a/doc/source/reference_manual/cstsmapmerge.rst +++ b/doc/source/reference_manual/cstsmapmerge.rst @@ -69,4 +69,4 @@ Standard parameters Related tools or scripts ------------------------ -:ref:`cstsmap` +:ref:`cttsmap` diff --git a/doc/source/reference_manual/index.rst b/doc/source/reference_manual/index.rst index 6e4fe82..f9a54c7 100644 --- a/doc/source/reference_manual/index.rst +++ b/doc/source/reference_manual/index.rst @@ -31,25 +31,33 @@ ctools cterror --- Calculates likelihood profile errors -cscripts --------- +General cscripts +---------------- .. toctree:: :maxdepth: 1 cscaldb --- Lists available instrument response functions - csobsdef --- Generates observation definition file cslightcrv --- Computes lightcurve + csmodelinfo --- Shows model container content + csmodelmerge --- Merges several model containers into one file + csobsdef --- Generates observation definition file + csobsinfo --- Shows observation container content cspull --- Generates pull distribution + csresmap --- Generates residual map cssens --- Computes CTA sensitivity csspec --- Computes spectral points - csresmap --- Generates residual map cstsdist --- Generates TS distribution - csobsinfo --- Shows observation container content - csmodelinfo --- Shows model container content - csmodelmerge --- Merges several model containers into one file cstsmapmerge --- Merges slices from ts map computations + + +IACT cscripts +------------- + +.. toctree:: + :maxdepth: 1 + csobs2caldb --- Creates a caldb entry from an input observation - csiactdata --- Dumps information about the IACT data available on the user machine - csiactobs --- Creates an observation XML file for IACTs using a list of observation IDs as input - csfindobs --- Creates a list of observation IDs + 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 diff --git a/test/test_cscripts.sh.in b/test/test_cscripts.sh.in index 25745b7..c0c531b 100755 --- a/test/test_cscripts.sh.in +++ b/test/test_cscripts.sh.in @@ -2,7 +2,7 @@ # ========================================================================== # This script tests all cscripts that are shipped with ctools # -# Copyright (C) 2011-2015 Juergen Knoedlseder +# Copyright (C) 2011-2016 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 @@ -149,7 +149,7 @@ chmod +x @abs_top_srcdir@/cscripts/csiactobs.py @abs_top_srcdir@/cscripts/csiactobs.py \ datapath="iactdata/" \ prodname="unit-test" \ - runlistfile="iactdata/runlist.txt" \ + infile="iactdata/runlist.txt" \ bkgpars="1" \ outobs="obs2.xml" \ outmodel="bkgmodels.xml" > csiactobs.log