From ead63241a70554abeb6fb02504539cb4b57c9f04 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Mon, 14 Mar 2016 12:33:24 +0100 Subject: [PATCH] Added parameter files for all cscripts (#1740). --- cscripts/Makefile.am | 5 +++-- cscripts/csfindobs.par | 44 ++++++++++++++++++++++++++++++++++++++++++++ cscripts/csfindobs.py | 81 ++++++++++++++++++++++++--------------------------------------------------------- cscripts/csiactcopy.par | 32 ++++++++++++++++++++++++++++++++ cscripts/csiactcopy.py | 484 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- cscripts/csiactdata.par | 31 +++++++++++++++++++++++++++++++ cscripts/csiactdata.py | 61 +++++++++++++++++++------------------------------------------ cscripts/csiactobs.par | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ cscripts/csiactobs.py | 128 +++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------- cscripts/cslightcrv.par | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ cscripts/cslightcrv.py | 56 -------------------------------------------------------- 11 files changed, 545 insertions(+), 496 deletions(-) create mode 100644 cscripts/csfindobs.par create mode 100644 cscripts/csiactcopy.par create mode 100644 cscripts/csiactdata.par create mode 100644 cscripts/csiactobs.par create mode 100644 cscripts/cslightcrv.par diff --git a/cscripts/Makefile.am b/cscripts/Makefile.am index 6826fc9..7fbfd42 100644 --- a/cscripts/Makefile.am +++ b/cscripts/Makefile.am @@ -11,9 +11,10 @@ pythonscripts = __init__.py \ # Parfiles to be distributed in $(prefix)/syspfiles parfiles = cspull.par cssens.par cstsdist.par cscaldb.par csresmap.par \ - csobsdef.par csspec.par csobsinfo.par \ + csobsdef.par csspec.par cslightcrv.par csobsinfo.par \ csmodelinfo.par csmodelmerge.par cstsmapmerge.par \ - csobs2caldb.par + csobs2caldb.par \ + csfindobs.par csiactcopy.par csiactdata.par csiactobs.par # Scripts for which symbolic links will be created in bindir linkscripts = cspull cssens cstsdist cscaldb csresmap \ diff --git a/cscripts/csfindobs.par b/cscripts/csfindobs.par new file mode 100644 index 0000000..a4767d6 --- /dev/null +++ b/cscripts/csfindobs.par @@ -0,0 +1,44 @@ +############################################################################# +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: csfindobs.par # +# Version: 1.1.0 # +# # +# Author: Michael Mayer # +# michael.mayer@physik.hu-berlin.de # +# HU Berlin # +# # +# Purpose: Parameter file for the csfindobs script # +# # +############################################################################# +# +# Input and output parameters +#============================ +datapath, s, a, $VHEFITS,,, "Path were data are located" +prodname, s, a, prod-name,,, "Name of FITS production (Run csiactdata to view your options)" +outfile, f, a, runlist.lis,,, "Output runlist file" + +# +# Script parameters +#================== +ra, r, a, 83.63,,, "Right ascension of selection region centre (deg)" +dec, r, a, 22.01,,, "Declination of selection region centre (deg)" +rad, r, a, 2.5,,, "Search radius of selection region (deg)" +min_qual, i, h, 0,0|1|2,, "Minimum data quality (0=perfect, 1=ok, 2=bad)" +expression, s, h, NONE,,, "Additional expression" +master_indx, s, h, master.json,,, "Name of master index file" + +# +# 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,,, "Debugging mode activated" +mode, s, h, ql,,, "Mode of automatic parameters" +logfile, f, h, csfindobs.log,,, "Log filename" + + + diff --git a/cscripts/csfindobs.py b/cscripts/csfindobs.py index e163020..485ed14 100755 --- a/cscripts/csfindobs.py +++ b/cscripts/csfindobs.py @@ -44,9 +44,6 @@ class csfindobs(ctools.cscript): self._verbose = False self._datapath = os.getenv("VHEFITS","") - # Make sure that parfile exists - self._parfile() - # Initialise application if len(argv) == 0: ctools.cscript.__init__(self, self._name, self._version) @@ -73,39 +70,8 @@ class csfindobs(ctools.cscript): # Return return - def _parfile(self): - """ - Check if parfile exists. If parfile does not exist then create a - default parfile. This kluge avoids shipping the cscript with a - parfile. - """ - # Set parfile name - parfile = self._name+".par" - - try: - pars = gammalib.GApplicationPars(parfile) - except: - # Signal if parfile was not found - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") - - # Create default parfile - pars = gammalib.GApplicationPars() - 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_standard() - pars.append(gammalib.GApplicationPar("logfile","f","h","csfindobs.log","","","Log filename")) - pars.save(parfile) - - # Return - return - + + # Private methods def _get_parameters(self): """ Get parameters from parfile and setup the observation. @@ -209,27 +175,7 @@ class csfindobs(ctools.cscript): # Return return - def obs_ids(self): - """ - Return OBS IDs - """ - - # Return - return self.runs - - def execute(self): - """ - Execute the script. - """ - # Run the script - self.run() - - # Save residual map - self.save(self._outfile) - - # Return - return - + # Public methods def run(self): """ Run the script. @@ -304,6 +250,19 @@ class csfindobs(ctools.cscript): # Return return + def execute(self): + """ + Execute the script. + """ + # Run the script + self.run() + + # Save residual map + self.save(self._outfile) + + # Return + return + def save(self, outfile): """ Save. @@ -323,6 +282,14 @@ class csfindobs(ctools.cscript): # Return return + def obs_ids(self): + """ + Return OBS IDs + """ + + # Return + return self._runs + # ======================== # # Main routine entry point # diff --git a/cscripts/csiactcopy.par b/cscripts/csiactcopy.par new file mode 100644 index 0000000..a9257a4 --- /dev/null +++ b/cscripts/csiactcopy.par @@ -0,0 +1,32 @@ +############################################################################# +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: csiactcopy.par # +# Version: 1.1.0 # +# # +# Author: Michael Mayer # +# michael.mayer@physik.hu-berlin.de # +# HU Berlin # +# # +# Purpose: Parameter file for the csiactcopy script # +# # +############################################################################# +# +# Input and output parameters +#============================ +remote_master, f, a, /Volumes/mountpoint/master.json,,, "Location of remote master file" +prodname, s, a, iact-fits,,, "Name of FITS production to download" +runlist, f, h, NONE,,, "Input list of observation IDs" +outpath, s, a, /path/to/fits,,, "Destination path of FITS data" + +# +# 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,,, "Debugging mode activated" +mode, s, h, ql,,, "Mode of automatic parameters" +logfile, f, h, csiactcopy.log,,, "Log filename" diff --git a/cscripts/csiactcopy.py b/cscripts/csiactcopy.py index 5ea41de..2cd6562 100755 --- a/cscripts/csiactcopy.py +++ b/cscripts/csiactcopy.py @@ -34,6 +34,8 @@ class csiactcopy(ctools.cscript): It can take a list of observation IDs to allow the download specific observations. Index files get merged and updated accordingly. """ + + # Constructors and destructors def __init__(self, *argv): """ Constructor. @@ -43,9 +45,6 @@ class csiactcopy(ctools.cscript): self._version = "1.1.0" self._datapath = os.getenv("VHEFITS","") - # Make sure that parfile exists - self._parfile() - # Initialise application if len(argv) == 0: ctools.cscript.__init__(self, self._name, self._version) @@ -69,34 +68,8 @@ class csiactcopy(ctools.cscript): # Return return - def _parfile(self): - """ - Check if parfile exists. If parfile does not exist then create a - default parfile. This kluge avoids shipping the cscript with a - parfile. - """ - # Set parfile name - parfile = self._name+".par" - - try: - pars = gammalib.GApplicationPars(parfile) - except: - # Signal if parfile was not found - print("Parfile "+parfile+" not found. Create default parfile.") - - # Create default parfile - pars = gammalib.GApplicationPars() - pars.append(gammalib.GApplicationPar("remote_master","f","a","/Volumes/mountpoint/master.json","","","Location of remote master file")) - pars.append(gammalib.GApplicationPar("prodname","s","a","iact-fits","","","Name of FITS production to download")) - pars.append(gammalib.GApplicationPar("outpath","s","a","/path/to/fits","","","Destination path of FITS data")) - pars.append(gammalib.GApplicationPar("runlist","f","h","NONE","","","List of observation IDs")) - pars.append_standard() - pars.append(gammalib.GApplicationPar("logfile","f","h","csiactcopy.log","","","Log filename")) - pars.save(parfile) - - # Return - return + # Private methods def _get_parameters(self): """ Get parameters from parfile and setup the observation. @@ -114,20 +87,233 @@ class csiactcopy(ctools.cscript): self._prodname = self["prodname"].string() self._outpath = gammalib.expand_env(self["outpath"].string()) self._runlist = self["runlist"].filename() - + + # Write input parameters into logger + if self._logTerse(): + self._log_parameters() + self._log("\n") + # Return return - def execute(self): + def copy(self, source, clobber): """ - Execute the script. + copy file to _outpath """ - # Run the script - self.run() + # Get file destination + destination = os.path.join(self._outpath, + os.path.relpath(source, self._remote_base)) + + # Initialise return value + filesize = 0.0 + + # Logging + if self._logVerbose(): + self._log("\n") + self._log.header3("Copy file") + self._log.parformat("Source") + self._log(str(source)) + self._log("\n") + self._log.parformat("Destination") + self._log(str(destination)) + self._log("\n") + self._log.parformat("Already exists") + self._log(str(os.path.isfile(destination))) + self._log("\n") + self._log.parformat("Overwrite") + self._log(str(clobber)) + self._log("\n") + self._log.parformat("Copying") + + # Flag if file destination is already available + is_file = os.path.isfile(destination) + + # check if file could be skipped because clobber=no + if is_file and clobber == False: + if self._logVerbose(): + self._log("Skip (clobber=no)") + self._log("\n") + + # check if file could be skipped because it is the same file + elif is_file and os.path.samefile(destination, source): + if self._logVerbose(): + self._log("Skip (same file)") + self._log("\n") + + else: + # Create directory if not existent + dest_dir = os.path.dirname(destination) + if not os.path.isdir(dest_dir): + os.makedirs(dest_dir) + + # Copy file (if source not identical to destination) + shutil.copy2(source, destination) + + # Get filesize + filesize = os.stat(destination).st_size + + # Logging + if self._logVerbose(): + self._log("Done!") + self._log("\n") + + # Return + return filesize + + + def merge(self, localfits, remotefits, hduname, clobber): + """ + merge remote and local fits file + If local fits file not present, a new one is created + """ + + if self._logTerse(): + self._log.parformat("Local file") + self._log(str(localfits)) + self._log("\n") + self._log.parformat("Remote file") + self._log(str(remotefits)) + self._log("\n") + self._log.parformat("HDU name") + self._log(str(hduname)) + self._log("\n") + self._log.parformat("Conflict preference") + if clobber: + self._log("Remote") + else: + self._log("Local") + self._log("\n") + + # Check if local fits file is available + if os.path.isfile(localfits): + local = gammalib.GFits(str(localfits)) + local_hdu = local[hduname] + else: + # Otherwise load remote fits file and delete rows + local = gammalib.GFits(str(remotefits)) + local_hdu = local[hduname] + local_hdu.remove_rows(0,local_hdu.nrows()) + + # find local obs_id + local_obs = [] + lobs_col = local_hdu["OBS_ID"] + for obs_id in lobs_col: + local_obs.append(obs_id) + + # Create selection expression for opening remote fits file + selection = "" + if len(self._runs): + selection += "["+hduname+"][" + for run in self._runs: + selection += "OBS_ID=="+str(run) + selection += "||" + selection = selection[:-2] + selection += "]" + + # Create file name + remotefile = remotefits + selection + + # open remote fits file + remote = gammalib.GFits(str(remotefile)) + remote_hdu = remote[hduname] + + # Get remote obs_id + remote_obs = [] + robs_col = remote_hdu["OBS_ID"] + for obs_id in robs_col: + remote_obs.append(obs_id) + + if self._logTerse(): + self._log.parformat("Remote entries") + self._log(str(len(remote_obs))) + self._log("\n") + self._log.parformat("Local entries") + self._log(str(len(local_obs))) + self._log("\n") + + # initialise counter for logging + removed_rows = 0 + + # If clobber=yes, we use the remote content to overwrite + # corresponding local content + if clobber: + + # Loop over remote obs_ids + for remote_obs_id in remote_obs: + + # Check if remote obs_id is present locally + if remote_obs_id in local_obs: + + # Remove local obs_id entries + table_has_obsid = True + while table_has_obsid: + for i in range(local_hdu.nrows()): + if remote_obs_id == local_hdu["OBS_ID"][i]: + local_hdu.remove_rows(i,1) + removed_rows += 1 + break + table_has_obsid = False + for i in range(local_hdu.nrows()): + if remote_obs_id == local_hdu["OBS_ID"][i]: + table_has_obsid = True + break + + # If clobber=false, we keep the local content unchanged and just + # expand by remote content + else: + # Loop over remote obs_ids + for local_obs_id in local_obs: + + # Check if local obs_id is present remotely + if local_obs_id in remote_obs: + + # Remove remote obs_id entries + table_has_obsid = True + while table_has_obsid: + for i in range(remote_hdu.nrows()): + if local_obs_id == remote_hdu["OBS_ID"][i]: + remote_hdu.remove_rows(i,1) + removed_rows += 1 + break + table_has_obsid = False + for i in range(remote_hdu.nrows()): + if local_obs_id == remote_hdu["OBS_ID"][i]: + table_has_obsid = True + break + + # Store number of local rows + old_local_rows = local_hdu.nrows() + + # Add rmeote HDUs + local_hdu.insert_rows(old_local_rows, remote_hdu.nrows()) + + if self._logTerse(): + if clobber: + self._log.parformat("Removed local rows") + else: + self._log.parformat("Skipped remote rows") + self._log(str(removed_rows)) + self._log("\n") + # Loop over columns + for i in range(local_hdu.ncols()): + + # Get local and remote columns + local_col = local_hdu[i] + remote_col = remote_hdu[i] + + # Loop over entries and merge + for j in range(remote_col.length()): + local_col[j+old_local_rows] = remote_col[j] + + # Save local fits file + local.saveto(str(localfits), True) + # Return return - + + + # Public methods def run(self): """ Run the script. @@ -138,11 +324,6 @@ class csiactcopy(ctools.cscript): # Get parameters self._get_parameters() - # Write input parameters into logger - if self._logTerse(): - self._log_parameters() - self._log("\n") - # Make destination directory if not available if not os.path.isdir(self._outpath): os.makedirs(self._outpath) @@ -516,221 +697,19 @@ class csiactcopy(ctools.cscript): # Return return - def copy(self, source, clobber): - """ - copy file to m_outpath + def execute(self): """ - # Get file destination - destination = os.path.join(self._outpath, - os.path.relpath(source, self._remote_base)) - - # Initialise return value - filesize = 0.0 - - # Logging - if self._logVerbose(): - self._log("\n") - self._log.header3("Copy file") - self._log.parformat("Source") - self._log(str(source)) - self._log("\n") - self._log.parformat("Destination") - self._log(str(destination)) - self._log("\n") - self._log.parformat("Already exists") - self._log(str(os.path.isfile(destination))) - self._log("\n") - self._log.parformat("Overwrite") - self._log(str(clobber)) - self._log("\n") - self._log.parformat("Copying") - - # Flag if file destination is already available - is_file = os.path.isfile(destination) - - # check if file could be skipped because clobber=no - if is_file and clobber == False: - if self._logVerbose(): - self._log("Skip (clobber=no)") - self._log("\n") - - # check if file could be skipped because it is the same file - elif is_file and os.path.samefile(destination, source): - if self._logVerbose(): - self._log("Skip (same file)") - self._log("\n") - - else: - # Create directory if not existent - dest_dir = os.path.dirname(destination) - if not os.path.isdir(dest_dir): - os.makedirs(dest_dir) - - # Copy file (if source not identical to destination) - shutil.copy2(source, destination) - - # Get filesize - filesize = os.stat(destination).st_size - - # Logging - if self._logVerbose(): - self._log("Done!") - self._log("\n") - - # Return - return filesize - - - def merge(self, localfits, remotefits, hduname, clobber): + Execute the script. """ - merge remote and local fits file - If local fits file not present, a new one is created - """ - - if self._logTerse(): - self._log.parformat("Local file") - self._log(str(localfits)) - self._log("\n") - self._log.parformat("Remote file") - self._log(str(remotefits)) - self._log("\n") - self._log.parformat("HDU name") - self._log(str(hduname)) - self._log("\n") - self._log.parformat("Conflict preference") - if clobber: - self._log("Remote") - else: - self._log("Local") - self._log("\n") - - # Check if local fits file is available - if os.path.isfile(localfits): - local = gammalib.GFits(str(localfits)) - local_hdu = local[hduname] - else: - # Otherwise load remote fits file and delete rows - local = gammalib.GFits(str(remotefits)) - local_hdu = local[hduname] - local_hdu.remove_rows(0,local_hdu.nrows()) - - # find local obs_id - local_obs = [] - lobs_col = local_hdu["OBS_ID"] - for obs_id in lobs_col: - local_obs.append(obs_id) - - # Create selection expression for opening remote fits file - selection = "" - if len(self._runs): - selection += "["+hduname+"][" - for run in self._runs: - selection += "OBS_ID=="+str(run) - selection += "||" - selection = selection[:-2] - selection += "]" - - # Create file name - remotefile = remotefits + selection - - # open remote fits file - remote = gammalib.GFits(str(remotefile)) - remote_hdu = remote[hduname] - - # Get remote obs_id - remote_obs = [] - robs_col = remote_hdu["OBS_ID"] - for obs_id in robs_col: - remote_obs.append(obs_id) - - if self._logTerse(): - self._log.parformat("Remote entries") - self._log(str(len(remote_obs))) - self._log("\n") - self._log.parformat("Local entries") - self._log(str(len(local_obs))) - self._log("\n") - - # initialise counter for logging - removed_rows = 0 - - # If clobber=yes, we use the remote content to overwrite - # corresponding local content - if clobber: - - # Loop over remote obs_ids - for remote_obs_id in remote_obs: - - # Check if remote obs_id is present locally - if remote_obs_id in local_obs: - - # Remove local obs_id entries - table_has_obsid = True - while table_has_obsid: - for i in range(local_hdu.nrows()): - if remote_obs_id == local_hdu["OBS_ID"][i]: - local_hdu.remove_rows(i,1) - removed_rows += 1 - break - table_has_obsid = False - for i in range(local_hdu.nrows()): - if remote_obs_id == local_hdu["OBS_ID"][i]: - table_has_obsid = True - break - - # If clobber=false, we keep the local content unchanged and just - # expand by remote content - else: - # Loop over remote obs_ids - for local_obs_id in local_obs: - - # Check if local obs_id is present remotely - if local_obs_id in remote_obs: - - # Remove remote obs_id entries - table_has_obsid = True - while table_has_obsid: - for i in range(remote_hdu.nrows()): - if local_obs_id == remote_hdu["OBS_ID"][i]: - remote_hdu.remove_rows(i,1) - removed_rows += 1 - break - table_has_obsid = False - for i in range(remote_hdu.nrows()): - if local_obs_id == remote_hdu["OBS_ID"][i]: - table_has_obsid = True - break - - # Store number of local rows - old_local_rows = local_hdu.nrows() - - # Add rmeote HDUs - local_hdu.insert_rows(old_local_rows, remote_hdu.nrows()) - - if self._logTerse(): - if clobber: - self._log.parformat("Removed local rows") - else: - self._log.parformat("Skipped remote rows") - self._log(str(removed_rows)) - self._log("\n") + # Open logfile + self._logFileOpen() + + # Run the script + self.run() - # Loop over columns - for i in range(local_hdu.ncols()): - - # Get local and remote columns - local_col = local_hdu[i] - remote_col = remote_hdu[i] - - # Loop over entries and merge - for j in range(remote_col.length()): - local_col[j+old_local_rows] = remote_col[j] - - # Save local fits file - local.saveto(str(localfits), True) - # Return return + # ======================== # # Main routine entry point # @@ -740,8 +719,5 @@ if __name__ == '__main__': # Create instance of application app = csiactcopy(sys.argv) - # Open logfile - app._logFileOpen() - # Execute application app.execute() diff --git a/cscripts/csiactdata.par b/cscripts/csiactdata.par new file mode 100644 index 0000000..b13434f --- /dev/null +++ b/cscripts/csiactdata.par @@ -0,0 +1,31 @@ +############################################################################# +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: csiactdata.par # +# Version: 1.1.0 # +# # +# Author: Michael Mayer # +# michael.mayer@physik.hu-berlin.de # +# HU Berlin # +# # +# Purpose: Parameter file for the csiactdata script # +# # +############################################################################# +# +# Input and output parameters +#============================ +datapath, s, a, $VHEFITS,,, "Path were data is located" +master_indx, s, h, master.json,,, "Name of master index file" + +# +# 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,,, "Debugging mode activated" +mode, s, h, ql,,, "Mode of automatic parameters" +logfile, f, h, csiactdata.log,,, "Log filename" + diff --git a/cscripts/csiactdata.py b/cscripts/csiactdata.py index c8524e3..2fd5eb7 100755 --- a/cscripts/csiactdata.py +++ b/cscripts/csiactdata.py @@ -2,7 +2,7 @@ # ========================================================================== # Inspection of IACT data storage # -# Copyright (C) 2015 Michael Mayer +# Copyright (C) 2015-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 @@ -35,6 +35,8 @@ class csiactdata(ctools.cscript): file or prints it on the screen. These information can be used as input for 'csiactobs'. """ + + # Constructors and destructors def __init__(self, *argv): """ Constructor. @@ -45,9 +47,6 @@ class csiactdata(ctools.cscript): self._datapath = os.getenv("VHEFITS","") self._prodnames = [] - # Make sure that parfile exists - file = self._parfile() - # Initialise application if len(argv) == 0: ctools.cscript.__init__(self, self._name, self._version) @@ -70,32 +69,8 @@ class csiactdata(ctools.cscript): # Return return - def _parfile(self): - """ - Check if parfile exists. If parfile does not exist then create a - default parfile. This kluge avoids shipping the cscript with a - parfile. - """ - # Set parfile name - parfile = self._name+".par" - - try: - pars = gammalib.GApplicationPars(parfile) - except: - # Signal if parfile was not found - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") - - # Create default parfile - pars = gammalib.GApplicationPars() - pars.append(gammalib.GApplicationPar("datapath","s","a",self._datapath,"","","Path were data is located")) - pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) - pars.append_standard() - pars.append(gammalib.GApplicationPar("logfile","f","h","csiactdata.log","","","Log filename")) - pars.save(parfile) - - # Return - return + # Private methods def get_parameters(self): """ Get parameters from parfile and setup the observation. @@ -119,16 +94,7 @@ class csiactdata(ctools.cscript): # Return return - def execute(self): - """ - Execute the script. - """ - # Run the script - self.run() - - # Return - return - + # Public methods def run(self): """ Run the script. @@ -222,6 +188,20 @@ class csiactdata(ctools.cscript): # Return return + def execute(self): + """ + Execute the script. + """ + # Open logfile + self._logFileOpen() + + # Run the script + self.run() + + # Return + return + + def names(self): """ Return available FITS production names @@ -239,8 +219,5 @@ if __name__ == '__main__': # Create instance of application app = csiactdata(sys.argv) - # Open logfile - app._logFileOpen() - # Execute application app.execute() diff --git a/cscripts/csiactobs.par b/cscripts/csiactobs.par new file mode 100644 index 0000000..d6e2aa5 --- /dev/null +++ b/cscripts/csiactobs.par @@ -0,0 +1,54 @@ +############################################################################# +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: csiactobs.par # +# Version: 1.1.0 # +# # +# Author: Michael Mayer # +# michael.mayer@physik.hu-berlin.de # +# HU Berlin # +# # +# Purpose: Parameter file for the csiactobs script # +# # +############################################################################# +# +# Input and output parameters +#============================ +datapath, s, a, $VHEFITS,,, "Path were data is located" +prodname, s, a, ,,, "Data storage name" +infile, f, a, runlist.lis,,, "Input runlist file" +inmodel, f, h, NONE,,, "Input model definition XML file (optional)" +master_indx, s, h, master.json,,, "Input master index file" +outobs, f, a, obs.xml,,, "Output observation definition XML file" +outmodel, f, a, bgmodels.xml,,, "Output model definition XML file" + +# +# Script parameters +#================== +bkgpars, i, a, 1,,, "Number of free parameters per background model" +bkg_scale, b, h, yes,,, "Apply background scaling factor from observation index file if available?" +ev_hiera, s, h, events,,, "Hierarchy of event formats" +aeff_hiera, s, h, aeff_2d,,, "Hierarchy of effective area formats" +psf_hiera, s, h, psf_king|psf_3gauss,,, "Hierarchy of psf formats" +edisp_hiera, s, h, edisp_2d,,, "Hierarchy of energy dispersion formats" +bkg_hiera, s, h, bkg_3d,,, "Hierarchy of background formats" +bkg_mod_hiera, s, h, irf|aeff|gauss,,, "Hierarchy of background models" +bkg_gauss_norm, r, h, 1e-8,,, "Input normalisation for Gaussian background" +bkg_gauss_index, r, h, -2.0,,, "Input spectral index for Gaussian background" +bkg_gauss_sigma, r, h, 2.5,,, "Input sigma for Gaussian background" +bkg_aeff_norm, r, h, 1e-14,,, "Input normalisation for effective area background" +bkg_aeff_index, r, h, -2.0,,, "Input spectral index for effective area background" +bkg_range_factor, r, h, 100.0,,, "Factor to determine range of background normalisation" + +# +# 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,,, "Debugging mode activated" +mode, s, h, ql,,, "Mode of automatic parameters" +logfile, f, h, csiactobs.log,,, "Log filename" + diff --git a/cscripts/csiactobs.py b/cscripts/csiactobs.py index f4ae29c..1c2db5a 100755 --- a/cscripts/csiactobs.py +++ b/cscripts/csiactobs.py @@ -37,6 +37,8 @@ class csiactobs(ctools.cscript): described here: http://gamma-astro-data-formats.readthedocs.org/en/latest/ """ + + # Constructors and destructors def __init__(self, *argv): """ Constructor. @@ -53,9 +55,6 @@ class csiactobs(ctools.cscript): self._models = gammalib.GModels() self._runlist = [] - # Make sure that parfile exists - file = self._parfile() - # Initialise application if len(argv) == 0: ctools.cscript.__init__(self, self._name, self._version) @@ -78,50 +77,8 @@ class csiactobs(ctools.cscript): # Return return - def _parfile(self): - """ - Check if parfile exists. If parfile does not exist then create a - default parfile. This kluge avoids shipping the cscript with a parfile. - """ - # Set parfile name - parfile = self._name+".par" - - try: - pars = gammalib.GApplicationPars(parfile) - except: - # Signal if parfile was not found - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") - - # Create default parfile - 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("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("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")) - pars.append(gammalib.GApplicationPar("aeff_hiera","s","h","aeff_2d","","","Hierarchy of effective area formats")) - pars.append(gammalib.GApplicationPar("psf_hiera","s","h","psf_king|psf_3gauss","","","Hierarchy of psf formats")) - pars.append(gammalib.GApplicationPar("edisp_hiera","s","h","edisp_2d","","","Hierarchy of energy dispersion formats")) - pars.append(gammalib.GApplicationPar("bkg_hiera","s","h","bkg_3d","","","Hierarchy of background formats")) - pars.append(gammalib.GApplicationPar("bkg_mod_hiera","s","h","irf|aeff|gauss","","","Hierarchy of background models")) - pars.append(gammalib.GApplicationPar("bkg_gauss_norm","r","h","1e-8","","","Input normalisation for Gaussian background")) - pars.append(gammalib.GApplicationPar("bkg_gauss_index","r","h","-2.0","","","Input spectral index for Gaussian background")) - pars.append(gammalib.GApplicationPar("bkg_gauss_sigma","r","h","2.5","","","Input sigma for Gaussian background")) - pars.append(gammalib.GApplicationPar("bkg_aeff_norm","r","h","1e-14","","","Input normalisation for effective area background")) - pars.append(gammalib.GApplicationPar("bkg_aeff_index","r","h","-2.0","","","Input spectral index for effective area background")) - pars.append(gammalib.GApplicationPar("bkg_range_factor","r","h","100.0","","","Factor to determine range of background normalisation")) - pars.append_standard() - pars.append(gammalib.GApplicationPar("logfile","f","h","csiactobs.log","","","Log filename")) - pars.save(parfile) - - # Return - return + # Private methods def _get_parameters(self): """ Get parameters from parfile and setup the observation. @@ -366,43 +323,8 @@ class csiactobs(ctools.cscript): # Return model return model - def ebounds(self): - """ - Returns runlist energy range - """ - return self._ebounds - - def obs(self): - """ - Returns GObservations object - """ - # Initialise observations - obs = gammalib.GObservations() - - # Read observations if XML is filled - if self._xml.size(): - obs.read(self._xml) - - # Assign models - obs.models(self._models) - - # Return observations - return obs - - - def execute(self): - """ - Execute the script. - """ - # Run the script - self.run() - - # Save residual map - self.save(self._outobs, self._clobber) - - # Return - return + # Public methods def run(self): """ Run the script. @@ -665,6 +587,22 @@ class csiactobs(ctools.cscript): # Return return + def execute(self): + """ + Execute the script. + """ + # Open logfile + self._logFileOpen() + + # Run the script + self.run() + + # Save residual map + self.save(self._outobs, self._clobber) + + # Return + return + def save(self,outfile,clobber): # Save observation XML file @@ -676,6 +614,29 @@ class csiactobs(ctools.cscript): # Return return + def ebounds(self): + """ + Returns runlist energy range + """ + return self._ebounds + + def obs(self): + """ + Returns GObservations object + """ + # Initialise observations + obs = gammalib.GObservations() + + # Read observations if XML is filled + if self._xml.size(): + obs.read(self._xml) + + # Assign models + obs.models(self._models) + + # Return observations + return obs + # ======================== # # Main routine entry point # @@ -685,8 +646,5 @@ if __name__ == '__main__': # Create instance of application app = csiactobs(sys.argv) - # Open logfile - app._logFileOpen() - # Execute application app.execute() diff --git a/cscripts/cslightcrv.par b/cscripts/cslightcrv.par new file mode 100644 index 0000000..ce4829e --- /dev/null +++ b/cscripts/cslightcrv.par @@ -0,0 +1,65 @@ +############################################################################# +# # +# CTA Science Analysis Tools # +# # +# ------------------------------------------------------------------------- # +# # +# File: cslightcrv.par # +# Version: 1.1.0 # +# # +# Author: Juergen Knoedlseder # +# Jurgen.Knodlseder@irap.omp.eu # +# IRAP # +# # +# Purpose: Parameter file for the cslightcrv script # +# # +############################################################################# +# +# Input and output parameters +#============================ +inobs, f, h, 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,,, "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?" +outfile, f, a, lightcurve.fits,,, "Output light curve file" + +# +# Script parameters +#================== +tbinalg, s, a, GTI,FILE|LIN|GTI,, "Algorithm for defining time bins" +tmin, r, a, 51544.5,,,"Lightcurve start time (MJD])" +tmax, r, a, 51544.6,,,"Lightcurve stop time (MJD)" +tbins, i, a, 5,,, "Number of time bins" +tbinfile, f, a, NONE,,, "File defining the time binning" +emin, r, a, 0.1,,, "Lower energy limit of events (TeV)" +emax, r, a, 100.0,,, "Upper energy limit of events (TeV)" +enumbins, i, a, 0,,, "Number of energy bins for binned (0=unbinned)" +coordsys, s, a, CEL,CEL|GAL,, "Coordinate System" +proj, s, a, CAR,AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method" +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)" +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,,, "Pixel size (deg/pixel)" +calc_ts, b, h, yes,,, "Compute TS value for each bin?" +calc_ulim, b, h, yes,,, "Compute upper limit for each bin?" +fix_srcs, b, h, yes,,, "Fix other sky model parameters?" +fix_bkg, b, h, no,,, "Fix background model parameters?" + +# +# 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,,, "Debugging mode activated" +mode, s, h, ql,,, "Mode of automatic parameters" +logfile, f, h, cslightcrv.log,,, "Log filename" + + + diff --git a/cscripts/cslightcrv.py b/cscripts/cslightcrv.py index b90268c..8749055 100755 --- a/cscripts/cslightcrv.py +++ b/cscripts/cslightcrv.py @@ -56,9 +56,6 @@ class cslightcrv(ctools.cscript): else: self._obs = gammalib.GObservations() - # Make sure that parfile exists - self._parfile() - # Initialise application if len(argv) == 0: ctools.cscript.__init__(self, self._name, self._version) @@ -83,59 +80,6 @@ class cslightcrv(ctools.cscript): # Private methods - def _parfile(self): - """ - Check if parfile exists. If parfile does not exist then create a - default parfile. This kluge avoids shipping the cscript with a parfile. - """ - # Set parfile name - parfile = self._name+".par" - - try: - pars = gammalib.GApplicationPars(parfile) - except: - # Signal if parfile was not found - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") - - # Create default parfile - pars = gammalib.GApplicationPars() - pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Input event list, counts cube, or observation definition XML file")) - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) - pars.append(gammalib.GApplicationPar("srcname","s","a","Crab","","","Source name")) - pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Input exposure cube file (only needed for stacked analysis)")) - pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","Input PSF cube file (only needed for stacked analysis)")) - pars.append(gammalib.GApplicationPar("edispcube","f","a","NONE","","","Input energy dispersion cube file (only needed for stacked analysis)")) - pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Input background cube file (only needed for stacked analysis)")) - pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) - pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) - pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) - pars.append(gammalib.GApplicationPar("outfile","f","a","lightcurve.fits","","","Output light curve file")) - pars.append(gammalib.GApplicationPar("tbinalg","s","a","GTI","FILE|LIN|GTI","", "Algorithm for defining time bins")) - pars.append(gammalib.GApplicationPar("tmin","r","a","51544.5","","days","Lightcurve start time [MJD]")) - pars.append(gammalib.GApplicationPar("tmax","r","a","51544.6","","days","Lightcurve stop time [MJD]")) - pars.append(gammalib.GApplicationPar("tbins","i","a","5","","","Number of time bins")) - pars.append(gammalib.GApplicationPar("tbinfile","f","a","tbins.fits","","", "File defining the time binning")) - pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins per light curve bin (0=unbinned)")) - pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit of events (TeV)")) - pars.append(gammalib.GApplicationPar("emax","r","a","100.0","","","Upper energy limit of events (TeV)")) - pars.append(gammalib.GApplicationPar("coordsys","s","a","CEL","CEL|GAL","","Coordinate System")) - pars.append(gammalib.GApplicationPar("proj","s","a","CAR","AIT|AZP|CAR|MER|MOL|STG|TAN","","Projection method")) - pars.append(gammalib.GApplicationPar("xref","r","a","83.63","0","360","First coordinate of image center in degrees (RA or galactic l)")) - pars.append(gammalib.GApplicationPar("yref","r","a","22.01","-90","90","Second coordinate of image center in degrees (DEC or galactic b)")) - pars.append(gammalib.GApplicationPar("nxpix","i","a","200","","","Size of the X axis in pixels")) - pars.append(gammalib.GApplicationPar("nypix","i","a","200","","","Size of the Y axis in pixels")) - pars.append(gammalib.GApplicationPar("binsz","r","a","0.02","","","Pixel size (deg/pixel)")) - pars.append(gammalib.GApplicationPar("calc_ts","b","h","yes","yes|no","","Compute TS value for each bin?")) - pars.append(gammalib.GApplicationPar("calc_ulim","b","h","yes","yes|no","","Compute upper limit for each bin?")) - pars.append(gammalib.GApplicationPar("fix_srcs","b","h","yes","yes|no","","Fix other sky model parameters?")) - pars.append(gammalib.GApplicationPar("fix_bkg","b","h","no","yes|no","","Fix background model parameters?")) - pars.append_standard() - pars.append(gammalib.GApplicationPar("logfile","f","h","cslightcrv.log","","","Log filename")) - pars.save(parfile) - - # Return - return - def _create_tbounds(self): # Create time bin container -- libgit2 0.21.4