Commit ead63241a70554abeb6fb02504539cb4b57c9f04
1 parent
f8c17cb3
Added parameter files for all cscripts (#1740).
Showing
11 changed files
with
545 additions
and
496 deletions
cscripts/Makefile.am
| @@ -11,9 +11,10 @@ pythonscripts = __init__.py \ | @@ -11,9 +11,10 @@ pythonscripts = __init__.py \ | ||
| 11 | 11 | ||
| 12 | # Parfiles to be distributed in $(prefix)/syspfiles | 12 | # Parfiles to be distributed in $(prefix)/syspfiles |
| 13 | parfiles = cspull.par cssens.par cstsdist.par cscaldb.par csresmap.par \ | 13 | parfiles = cspull.par cssens.par cstsdist.par cscaldb.par csresmap.par \ |
| 14 | - csobsdef.par csspec.par csobsinfo.par \ | 14 | + csobsdef.par csspec.par cslightcrv.par csobsinfo.par \ |
| 15 | csmodelinfo.par csmodelmerge.par cstsmapmerge.par \ | 15 | csmodelinfo.par csmodelmerge.par cstsmapmerge.par \ |
| 16 | - csobs2caldb.par | 16 | + csobs2caldb.par \ |
| 17 | + csfindobs.par csiactcopy.par csiactdata.par csiactobs.par | ||
| 17 | 18 | ||
| 18 | # Scripts for which symbolic links will be created in bindir | 19 | # Scripts for which symbolic links will be created in bindir |
| 19 | linkscripts = cspull cssens cstsdist cscaldb csresmap \ | 20 | linkscripts = cspull cssens cstsdist cscaldb csresmap \ |
cscripts/csfindobs.par
0 → 100644
| 1 | +############################################################################# | ||
| 2 | +# # | ||
| 3 | +# CTA Science Analysis Tools # | ||
| 4 | +# # | ||
| 5 | +# ------------------------------------------------------------------------- # | ||
| 6 | +# # | ||
| 7 | +# File: csfindobs.par # | ||
| 8 | +# Version: 1.1.0 # | ||
| 9 | +# # | ||
| 10 | +# Author: Michael Mayer # | ||
| 11 | +# michael.mayer@physik.hu-berlin.de # | ||
| 12 | +# HU Berlin # | ||
| 13 | +# # | ||
| 14 | +# Purpose: Parameter file for the csfindobs script # | ||
| 15 | +# # | ||
| 16 | +############################################################################# | ||
| 17 | +# | ||
| 18 | +# Input and output parameters | ||
| 19 | +#============================ | ||
| 20 | +datapath, s, a, $VHEFITS,,, "Path were data are located" | ||
| 21 | +prodname, s, a, prod-name,,, "Name of FITS production (Run csiactdata to view your options)" | ||
| 22 | +outfile, f, a, runlist.lis,,, "Output runlist file" | ||
| 23 | + | ||
| 24 | +# | ||
| 25 | +# Script parameters | ||
| 26 | +#================== | ||
| 27 | +ra, r, a, 83.63,,, "Right ascension of selection region centre (deg)" | ||
| 28 | +dec, r, a, 22.01,,, "Declination of selection region centre (deg)" | ||
| 29 | +rad, r, a, 2.5,,, "Search radius of selection region (deg)" | ||
| 30 | +min_qual, i, h, 0,0|1|2,, "Minimum data quality (0=perfect, 1=ok, 2=bad)" | ||
| 31 | +expression, s, h, NONE,,, "Additional expression" | ||
| 32 | +master_indx, s, h, master.json,,, "Name of master index file" | ||
| 33 | + | ||
| 34 | +# | ||
| 35 | +# Standard parameters | ||
| 36 | +#==================== | ||
| 37 | +chatter, i, h, 2,0,4, "Chattiness of output" | ||
| 38 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | ||
| 39 | +debug, b, h, no,,, "Debugging mode activated" | ||
| 40 | +mode, s, h, ql,,, "Mode of automatic parameters" | ||
| 41 | +logfile, f, h, csfindobs.log,,, "Log filename" | ||
| 42 | + | ||
| 43 | + | ||
| 44 | + |
cscripts/csfindobs.py
| @@ -44,9 +44,6 @@ class csfindobs(ctools.cscript): | @@ -44,9 +44,6 @@ class csfindobs(ctools.cscript): | ||
| 44 | self._verbose = False | 44 | self._verbose = False |
| 45 | self._datapath = os.getenv("VHEFITS","") | 45 | self._datapath = os.getenv("VHEFITS","") |
| 46 | 46 | ||
| 47 | - # Make sure that parfile exists | ||
| 48 | - self._parfile() | ||
| 49 | - | ||
| 50 | # Initialise application | 47 | # Initialise application |
| 51 | if len(argv) == 0: | 48 | if len(argv) == 0: |
| 52 | ctools.cscript.__init__(self, self._name, self._version) | 49 | ctools.cscript.__init__(self, self._name, self._version) |
| @@ -73,39 +70,8 @@ class csfindobs(ctools.cscript): | @@ -73,39 +70,8 @@ class csfindobs(ctools.cscript): | ||
| 73 | # Return | 70 | # Return |
| 74 | return | 71 | return |
| 75 | 72 | ||
| 76 | - def _parfile(self): | ||
| 77 | - """ | ||
| 78 | - Check if parfile exists. If parfile does not exist then create a | ||
| 79 | - default parfile. This kluge avoids shipping the cscript with a | ||
| 80 | - parfile. | ||
| 81 | - """ | ||
| 82 | - # Set parfile name | ||
| 83 | - parfile = self._name+".par" | ||
| 84 | - | ||
| 85 | - try: | ||
| 86 | - pars = gammalib.GApplicationPars(parfile) | ||
| 87 | - except: | ||
| 88 | - # Signal if parfile was not found | ||
| 89 | - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") | ||
| 90 | - | ||
| 91 | - # Create default parfile | ||
| 92 | - pars = gammalib.GApplicationPars() | ||
| 93 | - pars.append(gammalib.GApplicationPar("datapath","s","a",self._datapath,"","","Path were data are located")) | ||
| 94 | - pars.append(gammalib.GApplicationPar("prodname","s","a","prod-name","","","Name of FITS production (Run csiactdata to view your options)")) | ||
| 95 | - pars.append(gammalib.GApplicationPar("outfile","f","a","runlist.lis","","","Runlist outfile")) | ||
| 96 | - pars.append(gammalib.GApplicationPar("ra","r","a","83.6331","","","Right ascension")) | ||
| 97 | - pars.append(gammalib.GApplicationPar("dec","r","a","22.01","","","Declination")) | ||
| 98 | - pars.append(gammalib.GApplicationPar("rad","r","a","2.5","","","Search radius")) | ||
| 99 | - pars.append(gammalib.GApplicationPar("min_qual","i","h","0","0|1|2","","Minimum data quality (0=perfect, 1=ok, 2=bad)")) | ||
| 100 | - pars.append(gammalib.GApplicationPar("expression","s","h","NONE","","","Additional expression")) | ||
| 101 | - pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) | ||
| 102 | - pars.append_standard() | ||
| 103 | - pars.append(gammalib.GApplicationPar("logfile","f","h","csfindobs.log","","","Log filename")) | ||
| 104 | - pars.save(parfile) | ||
| 105 | - | ||
| 106 | - # Return | ||
| 107 | - return | ||
| 108 | - | 73 | + |
| 74 | + # Private methods | ||
| 109 | def _get_parameters(self): | 75 | def _get_parameters(self): |
| 110 | """ | 76 | """ |
| 111 | Get parameters from parfile and setup the observation. | 77 | Get parameters from parfile and setup the observation. |
| @@ -209,27 +175,7 @@ class csfindobs(ctools.cscript): | @@ -209,27 +175,7 @@ class csfindobs(ctools.cscript): | ||
| 209 | # Return | 175 | # Return |
| 210 | return | 176 | return |
| 211 | 177 | ||
| 212 | - def obs_ids(self): | ||
| 213 | - """ | ||
| 214 | - Return OBS IDs | ||
| 215 | - """ | ||
| 216 | - | ||
| 217 | - # Return | ||
| 218 | - return self.runs | ||
| 219 | - | ||
| 220 | - def execute(self): | ||
| 221 | - """ | ||
| 222 | - Execute the script. | ||
| 223 | - """ | ||
| 224 | - # Run the script | ||
| 225 | - self.run() | ||
| 226 | - | ||
| 227 | - # Save residual map | ||
| 228 | - self.save(self._outfile) | ||
| 229 | - | ||
| 230 | - # Return | ||
| 231 | - return | ||
| 232 | - | 178 | + # Public methods |
| 233 | def run(self): | 179 | def run(self): |
| 234 | """ | 180 | """ |
| 235 | Run the script. | 181 | Run the script. |
| @@ -304,6 +250,19 @@ class csfindobs(ctools.cscript): | @@ -304,6 +250,19 @@ class csfindobs(ctools.cscript): | ||
| 304 | # Return | 250 | # Return |
| 305 | return | 251 | return |
| 306 | 252 | ||
| 253 | + def execute(self): | ||
| 254 | + """ | ||
| 255 | + Execute the script. | ||
| 256 | + """ | ||
| 257 | + # Run the script | ||
| 258 | + self.run() | ||
| 259 | + | ||
| 260 | + # Save residual map | ||
| 261 | + self.save(self._outfile) | ||
| 262 | + | ||
| 263 | + # Return | ||
| 264 | + return | ||
| 265 | + | ||
| 307 | def save(self, outfile): | 266 | def save(self, outfile): |
| 308 | """ | 267 | """ |
| 309 | Save. | 268 | Save. |
| @@ -323,6 +282,14 @@ class csfindobs(ctools.cscript): | @@ -323,6 +282,14 @@ class csfindobs(ctools.cscript): | ||
| 323 | # Return | 282 | # Return |
| 324 | return | 283 | return |
| 325 | 284 | ||
| 285 | + def obs_ids(self): | ||
| 286 | + """ | ||
| 287 | + Return OBS IDs | ||
| 288 | + """ | ||
| 289 | + | ||
| 290 | + # Return | ||
| 291 | + return self._runs | ||
| 292 | + | ||
| 326 | 293 | ||
| 327 | # ======================== # | 294 | # ======================== # |
| 328 | # Main routine entry point # | 295 | # Main routine entry point # |
cscripts/csiactcopy.par
0 → 100644
| 1 | +############################################################################# | ||
| 2 | +# # | ||
| 3 | +# CTA Science Analysis Tools # | ||
| 4 | +# # | ||
| 5 | +# ------------------------------------------------------------------------- # | ||
| 6 | +# # | ||
| 7 | +# File: csiactcopy.par # | ||
| 8 | +# Version: 1.1.0 # | ||
| 9 | +# # | ||
| 10 | +# Author: Michael Mayer # | ||
| 11 | +# michael.mayer@physik.hu-berlin.de # | ||
| 12 | +# HU Berlin # | ||
| 13 | +# # | ||
| 14 | +# Purpose: Parameter file for the csiactcopy script # | ||
| 15 | +# # | ||
| 16 | +############################################################################# | ||
| 17 | +# | ||
| 18 | +# Input and output parameters | ||
| 19 | +#============================ | ||
| 20 | +remote_master, f, a, /Volumes/mountpoint/master.json,,, "Location of remote master file" | ||
| 21 | +prodname, s, a, iact-fits,,, "Name of FITS production to download" | ||
| 22 | +runlist, f, h, NONE,,, "Input list of observation IDs" | ||
| 23 | +outpath, s, a, /path/to/fits,,, "Destination path of FITS data" | ||
| 24 | + | ||
| 25 | +# | ||
| 26 | +# Standard parameters | ||
| 27 | +#==================== | ||
| 28 | +chatter, i, h, 2,0,4, "Chattiness of output" | ||
| 29 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | ||
| 30 | +debug, b, h, no,,, "Debugging mode activated" | ||
| 31 | +mode, s, h, ql,,, "Mode of automatic parameters" | ||
| 32 | +logfile, f, h, csiactcopy.log,,, "Log filename" |
cscripts/csiactcopy.py
| @@ -34,6 +34,8 @@ class csiactcopy(ctools.cscript): | @@ -34,6 +34,8 @@ class csiactcopy(ctools.cscript): | ||
| 34 | It can take a list of observation IDs to allow the download specific | 34 | It can take a list of observation IDs to allow the download specific |
| 35 | observations. Index files get merged and updated accordingly. | 35 | observations. Index files get merged and updated accordingly. |
| 36 | """ | 36 | """ |
| 37 | + | ||
| 38 | + # Constructors and destructors | ||
| 37 | def __init__(self, *argv): | 39 | def __init__(self, *argv): |
| 38 | """ | 40 | """ |
| 39 | Constructor. | 41 | Constructor. |
| @@ -43,9 +45,6 @@ class csiactcopy(ctools.cscript): | @@ -43,9 +45,6 @@ class csiactcopy(ctools.cscript): | ||
| 43 | self._version = "1.1.0" | 45 | self._version = "1.1.0" |
| 44 | self._datapath = os.getenv("VHEFITS","") | 46 | self._datapath = os.getenv("VHEFITS","") |
| 45 | 47 | ||
| 46 | - # Make sure that parfile exists | ||
| 47 | - self._parfile() | ||
| 48 | - | ||
| 49 | # Initialise application | 48 | # Initialise application |
| 50 | if len(argv) == 0: | 49 | if len(argv) == 0: |
| 51 | ctools.cscript.__init__(self, self._name, self._version) | 50 | ctools.cscript.__init__(self, self._name, self._version) |
| @@ -69,34 +68,8 @@ class csiactcopy(ctools.cscript): | @@ -69,34 +68,8 @@ class csiactcopy(ctools.cscript): | ||
| 69 | # Return | 68 | # Return |
| 70 | return | 69 | return |
| 71 | 70 | ||
| 72 | - def _parfile(self): | ||
| 73 | - """ | ||
| 74 | - Check if parfile exists. If parfile does not exist then create a | ||
| 75 | - default parfile. This kluge avoids shipping the cscript with a | ||
| 76 | - parfile. | ||
| 77 | - """ | ||
| 78 | - # Set parfile name | ||
| 79 | - parfile = self._name+".par" | ||
| 80 | - | ||
| 81 | - try: | ||
| 82 | - pars = gammalib.GApplicationPars(parfile) | ||
| 83 | - except: | ||
| 84 | - # Signal if parfile was not found | ||
| 85 | - print("Parfile "+parfile+" not found. Create default parfile.") | ||
| 86 | - | ||
| 87 | - # Create default parfile | ||
| 88 | - pars = gammalib.GApplicationPars() | ||
| 89 | - pars.append(gammalib.GApplicationPar("remote_master","f","a","/Volumes/mountpoint/master.json","","","Location of remote master file")) | ||
| 90 | - pars.append(gammalib.GApplicationPar("prodname","s","a","iact-fits","","","Name of FITS production to download")) | ||
| 91 | - pars.append(gammalib.GApplicationPar("outpath","s","a","/path/to/fits","","","Destination path of FITS data")) | ||
| 92 | - pars.append(gammalib.GApplicationPar("runlist","f","h","NONE","","","List of observation IDs")) | ||
| 93 | - pars.append_standard() | ||
| 94 | - pars.append(gammalib.GApplicationPar("logfile","f","h","csiactcopy.log","","","Log filename")) | ||
| 95 | - pars.save(parfile) | ||
| 96 | - | ||
| 97 | - # Return | ||
| 98 | - return | ||
| 99 | 71 | ||
| 72 | + # Private methods | ||
| 100 | def _get_parameters(self): | 73 | def _get_parameters(self): |
| 101 | """ | 74 | """ |
| 102 | Get parameters from parfile and setup the observation. | 75 | Get parameters from parfile and setup the observation. |
| @@ -114,20 +87,233 @@ class csiactcopy(ctools.cscript): | @@ -114,20 +87,233 @@ class csiactcopy(ctools.cscript): | ||
| 114 | self._prodname = self["prodname"].string() | 87 | self._prodname = self["prodname"].string() |
| 115 | self._outpath = gammalib.expand_env(self["outpath"].string()) | 88 | self._outpath = gammalib.expand_env(self["outpath"].string()) |
| 116 | self._runlist = self["runlist"].filename() | 89 | self._runlist = self["runlist"].filename() |
| 117 | - | 90 | + |
| 91 | + # Write input parameters into logger | ||
| 92 | + if self._logTerse(): | ||
| 93 | + self._log_parameters() | ||
| 94 | + self._log("\n") | ||
| 95 | + | ||
| 118 | # Return | 96 | # Return |
| 119 | return | 97 | return |
| 120 | 98 | ||
| 121 | - def execute(self): | 99 | + def copy(self, source, clobber): |
| 122 | """ | 100 | """ |
| 123 | - Execute the script. | 101 | + copy file to _outpath |
| 124 | """ | 102 | """ |
| 125 | - # Run the script | ||
| 126 | - self.run() | 103 | + # Get file destination |
| 104 | + destination = os.path.join(self._outpath, | ||
| 105 | + os.path.relpath(source, self._remote_base)) | ||
| 106 | + | ||
| 107 | + # Initialise return value | ||
| 108 | + filesize = 0.0 | ||
| 109 | + | ||
| 110 | + # Logging | ||
| 111 | + if self._logVerbose(): | ||
| 112 | + self._log("\n") | ||
| 113 | + self._log.header3("Copy file") | ||
| 114 | + self._log.parformat("Source") | ||
| 115 | + self._log(str(source)) | ||
| 116 | + self._log("\n") | ||
| 117 | + self._log.parformat("Destination") | ||
| 118 | + self._log(str(destination)) | ||
| 119 | + self._log("\n") | ||
| 120 | + self._log.parformat("Already exists") | ||
| 121 | + self._log(str(os.path.isfile(destination))) | ||
| 122 | + self._log("\n") | ||
| 123 | + self._log.parformat("Overwrite") | ||
| 124 | + self._log(str(clobber)) | ||
| 125 | + self._log("\n") | ||
| 126 | + self._log.parformat("Copying") | ||
| 127 | + | ||
| 128 | + # Flag if file destination is already available | ||
| 129 | + is_file = os.path.isfile(destination) | ||
| 130 | + | ||
| 131 | + # check if file could be skipped because clobber=no | ||
| 132 | + if is_file and clobber == False: | ||
| 133 | + if self._logVerbose(): | ||
| 134 | + self._log("Skip (clobber=no)") | ||
| 135 | + self._log("\n") | ||
| 136 | + | ||
| 137 | + # check if file could be skipped because it is the same file | ||
| 138 | + elif is_file and os.path.samefile(destination, source): | ||
| 139 | + if self._logVerbose(): | ||
| 140 | + self._log("Skip (same file)") | ||
| 141 | + self._log("\n") | ||
| 142 | + | ||
| 143 | + else: | ||
| 144 | + # Create directory if not existent | ||
| 145 | + dest_dir = os.path.dirname(destination) | ||
| 146 | + if not os.path.isdir(dest_dir): | ||
| 147 | + os.makedirs(dest_dir) | ||
| 148 | + | ||
| 149 | + # Copy file (if source not identical to destination) | ||
| 150 | + shutil.copy2(source, destination) | ||
| 151 | + | ||
| 152 | + # Get filesize | ||
| 153 | + filesize = os.stat(destination).st_size | ||
| 154 | + | ||
| 155 | + # Logging | ||
| 156 | + if self._logVerbose(): | ||
| 157 | + self._log("Done!") | ||
| 158 | + self._log("\n") | ||
| 159 | + | ||
| 160 | + # Return | ||
| 161 | + return filesize | ||
| 162 | + | ||
| 163 | + | ||
| 164 | + def merge(self, localfits, remotefits, hduname, clobber): | ||
| 165 | + """ | ||
| 166 | + merge remote and local fits file | ||
| 167 | + If local fits file not present, a new one is created | ||
| 168 | + """ | ||
| 169 | + | ||
| 170 | + if self._logTerse(): | ||
| 171 | + self._log.parformat("Local file") | ||
| 172 | + self._log(str(localfits)) | ||
| 173 | + self._log("\n") | ||
| 174 | + self._log.parformat("Remote file") | ||
| 175 | + self._log(str(remotefits)) | ||
| 176 | + self._log("\n") | ||
| 177 | + self._log.parformat("HDU name") | ||
| 178 | + self._log(str(hduname)) | ||
| 179 | + self._log("\n") | ||
| 180 | + self._log.parformat("Conflict preference") | ||
| 181 | + if clobber: | ||
| 182 | + self._log("Remote") | ||
| 183 | + else: | ||
| 184 | + self._log("Local") | ||
| 185 | + self._log("\n") | ||
| 186 | + | ||
| 187 | + # Check if local fits file is available | ||
| 188 | + if os.path.isfile(localfits): | ||
| 189 | + local = gammalib.GFits(str(localfits)) | ||
| 190 | + local_hdu = local[hduname] | ||
| 191 | + else: | ||
| 192 | + # Otherwise load remote fits file and delete rows | ||
| 193 | + local = gammalib.GFits(str(remotefits)) | ||
| 194 | + local_hdu = local[hduname] | ||
| 195 | + local_hdu.remove_rows(0,local_hdu.nrows()) | ||
| 196 | + | ||
| 197 | + # find local obs_id | ||
| 198 | + local_obs = [] | ||
| 199 | + lobs_col = local_hdu["OBS_ID"] | ||
| 200 | + for obs_id in lobs_col: | ||
| 201 | + local_obs.append(obs_id) | ||
| 202 | + | ||
| 203 | + # Create selection expression for opening remote fits file | ||
| 204 | + selection = "" | ||
| 205 | + if len(self._runs): | ||
| 206 | + selection += "["+hduname+"][" | ||
| 207 | + for run in self._runs: | ||
| 208 | + selection += "OBS_ID=="+str(run) | ||
| 209 | + selection += "||" | ||
| 210 | + selection = selection[:-2] | ||
| 211 | + selection += "]" | ||
| 212 | + | ||
| 213 | + # Create file name | ||
| 214 | + remotefile = remotefits + selection | ||
| 215 | + | ||
| 216 | + # open remote fits file | ||
| 217 | + remote = gammalib.GFits(str(remotefile)) | ||
| 218 | + remote_hdu = remote[hduname] | ||
| 219 | + | ||
| 220 | + # Get remote obs_id | ||
| 221 | + remote_obs = [] | ||
| 222 | + robs_col = remote_hdu["OBS_ID"] | ||
| 223 | + for obs_id in robs_col: | ||
| 224 | + remote_obs.append(obs_id) | ||
| 225 | + | ||
| 226 | + if self._logTerse(): | ||
| 227 | + self._log.parformat("Remote entries") | ||
| 228 | + self._log(str(len(remote_obs))) | ||
| 229 | + self._log("\n") | ||
| 230 | + self._log.parformat("Local entries") | ||
| 231 | + self._log(str(len(local_obs))) | ||
| 232 | + self._log("\n") | ||
| 233 | + | ||
| 234 | + # initialise counter for logging | ||
| 235 | + removed_rows = 0 | ||
| 236 | + | ||
| 237 | + # If clobber=yes, we use the remote content to overwrite | ||
| 238 | + # corresponding local content | ||
| 239 | + if clobber: | ||
| 240 | + | ||
| 241 | + # Loop over remote obs_ids | ||
| 242 | + for remote_obs_id in remote_obs: | ||
| 243 | + | ||
| 244 | + # Check if remote obs_id is present locally | ||
| 245 | + if remote_obs_id in local_obs: | ||
| 246 | + | ||
| 247 | + # Remove local obs_id entries | ||
| 248 | + table_has_obsid = True | ||
| 249 | + while table_has_obsid: | ||
| 250 | + for i in range(local_hdu.nrows()): | ||
| 251 | + if remote_obs_id == local_hdu["OBS_ID"][i]: | ||
| 252 | + local_hdu.remove_rows(i,1) | ||
| 253 | + removed_rows += 1 | ||
| 254 | + break | ||
| 255 | + table_has_obsid = False | ||
| 256 | + for i in range(local_hdu.nrows()): | ||
| 257 | + if remote_obs_id == local_hdu["OBS_ID"][i]: | ||
| 258 | + table_has_obsid = True | ||
| 259 | + break | ||
| 260 | + | ||
| 261 | + # If clobber=false, we keep the local content unchanged and just | ||
| 262 | + # expand by remote content | ||
| 263 | + else: | ||
| 264 | + # Loop over remote obs_ids | ||
| 265 | + for local_obs_id in local_obs: | ||
| 266 | + | ||
| 267 | + # Check if local obs_id is present remotely | ||
| 268 | + if local_obs_id in remote_obs: | ||
| 269 | + | ||
| 270 | + # Remove remote obs_id entries | ||
| 271 | + table_has_obsid = True | ||
| 272 | + while table_has_obsid: | ||
| 273 | + for i in range(remote_hdu.nrows()): | ||
| 274 | + if local_obs_id == remote_hdu["OBS_ID"][i]: | ||
| 275 | + remote_hdu.remove_rows(i,1) | ||
| 276 | + removed_rows += 1 | ||
| 277 | + break | ||
| 278 | + table_has_obsid = False | ||
| 279 | + for i in range(remote_hdu.nrows()): | ||
| 280 | + if local_obs_id == remote_hdu["OBS_ID"][i]: | ||
| 281 | + table_has_obsid = True | ||
| 282 | + break | ||
| 283 | + | ||
| 284 | + # Store number of local rows | ||
| 285 | + old_local_rows = local_hdu.nrows() | ||
| 286 | + | ||
| 287 | + # Add rmeote HDUs | ||
| 288 | + local_hdu.insert_rows(old_local_rows, remote_hdu.nrows()) | ||
| 289 | + | ||
| 290 | + if self._logTerse(): | ||
| 291 | + if clobber: | ||
| 292 | + self._log.parformat("Removed local rows") | ||
| 293 | + else: | ||
| 294 | + self._log.parformat("Skipped remote rows") | ||
| 295 | + self._log(str(removed_rows)) | ||
| 296 | + self._log("\n") | ||
| 127 | 297 | ||
| 298 | + # Loop over columns | ||
| 299 | + for i in range(local_hdu.ncols()): | ||
| 300 | + | ||
| 301 | + # Get local and remote columns | ||
| 302 | + local_col = local_hdu[i] | ||
| 303 | + remote_col = remote_hdu[i] | ||
| 304 | + | ||
| 305 | + # Loop over entries and merge | ||
| 306 | + for j in range(remote_col.length()): | ||
| 307 | + local_col[j+old_local_rows] = remote_col[j] | ||
| 308 | + | ||
| 309 | + # Save local fits file | ||
| 310 | + local.saveto(str(localfits), True) | ||
| 311 | + | ||
| 128 | # Return | 312 | # Return |
| 129 | return | 313 | return |
| 130 | - | 314 | + |
| 315 | + | ||
| 316 | + # Public methods | ||
| 131 | def run(self): | 317 | def run(self): |
| 132 | """ | 318 | """ |
| 133 | Run the script. | 319 | Run the script. |
| @@ -138,11 +324,6 @@ class csiactcopy(ctools.cscript): | @@ -138,11 +324,6 @@ class csiactcopy(ctools.cscript): | ||
| 138 | # Get parameters | 324 | # Get parameters |
| 139 | self._get_parameters() | 325 | self._get_parameters() |
| 140 | 326 | ||
| 141 | - # Write input parameters into logger | ||
| 142 | - if self._logTerse(): | ||
| 143 | - self._log_parameters() | ||
| 144 | - self._log("\n") | ||
| 145 | - | ||
| 146 | # Make destination directory if not available | 327 | # Make destination directory if not available |
| 147 | if not os.path.isdir(self._outpath): | 328 | if not os.path.isdir(self._outpath): |
| 148 | os.makedirs(self._outpath) | 329 | os.makedirs(self._outpath) |
| @@ -516,221 +697,19 @@ class csiactcopy(ctools.cscript): | @@ -516,221 +697,19 @@ class csiactcopy(ctools.cscript): | ||
| 516 | # Return | 697 | # Return |
| 517 | return | 698 | return |
| 518 | 699 | ||
| 519 | - def copy(self, source, clobber): | ||
| 520 | - """ | ||
| 521 | - copy file to m_outpath | 700 | + def execute(self): |
| 522 | """ | 701 | """ |
| 523 | - # Get file destination | ||
| 524 | - destination = os.path.join(self._outpath, | ||
| 525 | - os.path.relpath(source, self._remote_base)) | ||
| 526 | - | ||
| 527 | - # Initialise return value | ||
| 528 | - filesize = 0.0 | ||
| 529 | - | ||
| 530 | - # Logging | ||
| 531 | - if self._logVerbose(): | ||
| 532 | - self._log("\n") | ||
| 533 | - self._log.header3("Copy file") | ||
| 534 | - self._log.parformat("Source") | ||
| 535 | - self._log(str(source)) | ||
| 536 | - self._log("\n") | ||
| 537 | - self._log.parformat("Destination") | ||
| 538 | - self._log(str(destination)) | ||
| 539 | - self._log("\n") | ||
| 540 | - self._log.parformat("Already exists") | ||
| 541 | - self._log(str(os.path.isfile(destination))) | ||
| 542 | - self._log("\n") | ||
| 543 | - self._log.parformat("Overwrite") | ||
| 544 | - self._log(str(clobber)) | ||
| 545 | - self._log("\n") | ||
| 546 | - self._log.parformat("Copying") | ||
| 547 | - | ||
| 548 | - # Flag if file destination is already available | ||
| 549 | - is_file = os.path.isfile(destination) | ||
| 550 | - | ||
| 551 | - # check if file could be skipped because clobber=no | ||
| 552 | - if is_file and clobber == False: | ||
| 553 | - if self._logVerbose(): | ||
| 554 | - self._log("Skip (clobber=no)") | ||
| 555 | - self._log("\n") | ||
| 556 | - | ||
| 557 | - # check if file could be skipped because it is the same file | ||
| 558 | - elif is_file and os.path.samefile(destination, source): | ||
| 559 | - if self._logVerbose(): | ||
| 560 | - self._log("Skip (same file)") | ||
| 561 | - self._log("\n") | ||
| 562 | - | ||
| 563 | - else: | ||
| 564 | - # Create directory if not existent | ||
| 565 | - dest_dir = os.path.dirname(destination) | ||
| 566 | - if not os.path.isdir(dest_dir): | ||
| 567 | - os.makedirs(dest_dir) | ||
| 568 | - | ||
| 569 | - # Copy file (if source not identical to destination) | ||
| 570 | - shutil.copy2(source, destination) | ||
| 571 | - | ||
| 572 | - # Get filesize | ||
| 573 | - filesize = os.stat(destination).st_size | ||
| 574 | - | ||
| 575 | - # Logging | ||
| 576 | - if self._logVerbose(): | ||
| 577 | - self._log("Done!") | ||
| 578 | - self._log("\n") | ||
| 579 | - | ||
| 580 | - # Return | ||
| 581 | - return filesize | ||
| 582 | - | ||
| 583 | - | ||
| 584 | - def merge(self, localfits, remotefits, hduname, clobber): | 702 | + Execute the script. |
| 585 | """ | 703 | """ |
| 586 | - merge remote and local fits file | ||
| 587 | - If local fits file not present, a new one is created | ||
| 588 | - """ | ||
| 589 | - | ||
| 590 | - if self._logTerse(): | ||
| 591 | - self._log.parformat("Local file") | ||
| 592 | - self._log(str(localfits)) | ||
| 593 | - self._log("\n") | ||
| 594 | - self._log.parformat("Remote file") | ||
| 595 | - self._log(str(remotefits)) | ||
| 596 | - self._log("\n") | ||
| 597 | - self._log.parformat("HDU name") | ||
| 598 | - self._log(str(hduname)) | ||
| 599 | - self._log("\n") | ||
| 600 | - self._log.parformat("Conflict preference") | ||
| 601 | - if clobber: | ||
| 602 | - self._log("Remote") | ||
| 603 | - else: | ||
| 604 | - self._log("Local") | ||
| 605 | - self._log("\n") | ||
| 606 | - | ||
| 607 | - # Check if local fits file is available | ||
| 608 | - if os.path.isfile(localfits): | ||
| 609 | - local = gammalib.GFits(str(localfits)) | ||
| 610 | - local_hdu = local[hduname] | ||
| 611 | - else: | ||
| 612 | - # Otherwise load remote fits file and delete rows | ||
| 613 | - local = gammalib.GFits(str(remotefits)) | ||
| 614 | - local_hdu = local[hduname] | ||
| 615 | - local_hdu.remove_rows(0,local_hdu.nrows()) | ||
| 616 | - | ||
| 617 | - # find local obs_id | ||
| 618 | - local_obs = [] | ||
| 619 | - lobs_col = local_hdu["OBS_ID"] | ||
| 620 | - for obs_id in lobs_col: | ||
| 621 | - local_obs.append(obs_id) | ||
| 622 | - | ||
| 623 | - # Create selection expression for opening remote fits file | ||
| 624 | - selection = "" | ||
| 625 | - if len(self._runs): | ||
| 626 | - selection += "["+hduname+"][" | ||
| 627 | - for run in self._runs: | ||
| 628 | - selection += "OBS_ID=="+str(run) | ||
| 629 | - selection += "||" | ||
| 630 | - selection = selection[:-2] | ||
| 631 | - selection += "]" | ||
| 632 | - | ||
| 633 | - # Create file name | ||
| 634 | - remotefile = remotefits + selection | ||
| 635 | - | ||
| 636 | - # open remote fits file | ||
| 637 | - remote = gammalib.GFits(str(remotefile)) | ||
| 638 | - remote_hdu = remote[hduname] | ||
| 639 | - | ||
| 640 | - # Get remote obs_id | ||
| 641 | - remote_obs = [] | ||
| 642 | - robs_col = remote_hdu["OBS_ID"] | ||
| 643 | - for obs_id in robs_col: | ||
| 644 | - remote_obs.append(obs_id) | ||
| 645 | - | ||
| 646 | - if self._logTerse(): | ||
| 647 | - self._log.parformat("Remote entries") | ||
| 648 | - self._log(str(len(remote_obs))) | ||
| 649 | - self._log("\n") | ||
| 650 | - self._log.parformat("Local entries") | ||
| 651 | - self._log(str(len(local_obs))) | ||
| 652 | - self._log("\n") | ||
| 653 | - | ||
| 654 | - # initialise counter for logging | ||
| 655 | - removed_rows = 0 | ||
| 656 | - | ||
| 657 | - # If clobber=yes, we use the remote content to overwrite | ||
| 658 | - # corresponding local content | ||
| 659 | - if clobber: | ||
| 660 | - | ||
| 661 | - # Loop over remote obs_ids | ||
| 662 | - for remote_obs_id in remote_obs: | ||
| 663 | - | ||
| 664 | - # Check if remote obs_id is present locally | ||
| 665 | - if remote_obs_id in local_obs: | ||
| 666 | - | ||
| 667 | - # Remove local obs_id entries | ||
| 668 | - table_has_obsid = True | ||
| 669 | - while table_has_obsid: | ||
| 670 | - for i in range(local_hdu.nrows()): | ||
| 671 | - if remote_obs_id == local_hdu["OBS_ID"][i]: | ||
| 672 | - local_hdu.remove_rows(i,1) | ||
| 673 | - removed_rows += 1 | ||
| 674 | - break | ||
| 675 | - table_has_obsid = False | ||
| 676 | - for i in range(local_hdu.nrows()): | ||
| 677 | - if remote_obs_id == local_hdu["OBS_ID"][i]: | ||
| 678 | - table_has_obsid = True | ||
| 679 | - break | ||
| 680 | - | ||
| 681 | - # If clobber=false, we keep the local content unchanged and just | ||
| 682 | - # expand by remote content | ||
| 683 | - else: | ||
| 684 | - # Loop over remote obs_ids | ||
| 685 | - for local_obs_id in local_obs: | ||
| 686 | - | ||
| 687 | - # Check if local obs_id is present remotely | ||
| 688 | - if local_obs_id in remote_obs: | ||
| 689 | - | ||
| 690 | - # Remove remote obs_id entries | ||
| 691 | - table_has_obsid = True | ||
| 692 | - while table_has_obsid: | ||
| 693 | - for i in range(remote_hdu.nrows()): | ||
| 694 | - if local_obs_id == remote_hdu["OBS_ID"][i]: | ||
| 695 | - remote_hdu.remove_rows(i,1) | ||
| 696 | - removed_rows += 1 | ||
| 697 | - break | ||
| 698 | - table_has_obsid = False | ||
| 699 | - for i in range(remote_hdu.nrows()): | ||
| 700 | - if local_obs_id == remote_hdu["OBS_ID"][i]: | ||
| 701 | - table_has_obsid = True | ||
| 702 | - break | ||
| 703 | - | ||
| 704 | - # Store number of local rows | ||
| 705 | - old_local_rows = local_hdu.nrows() | ||
| 706 | - | ||
| 707 | - # Add rmeote HDUs | ||
| 708 | - local_hdu.insert_rows(old_local_rows, remote_hdu.nrows()) | ||
| 709 | - | ||
| 710 | - if self._logTerse(): | ||
| 711 | - if clobber: | ||
| 712 | - self._log.parformat("Removed local rows") | ||
| 713 | - else: | ||
| 714 | - self._log.parformat("Skipped remote rows") | ||
| 715 | - self._log(str(removed_rows)) | ||
| 716 | - self._log("\n") | 704 | + # Open logfile |
| 705 | + self._logFileOpen() | ||
| 706 | + | ||
| 707 | + # Run the script | ||
| 708 | + self.run() | ||
| 717 | 709 | ||
| 718 | - # Loop over columns | ||
| 719 | - for i in range(local_hdu.ncols()): | ||
| 720 | - | ||
| 721 | - # Get local and remote columns | ||
| 722 | - local_col = local_hdu[i] | ||
| 723 | - remote_col = remote_hdu[i] | ||
| 724 | - | ||
| 725 | - # Loop over entries and merge | ||
| 726 | - for j in range(remote_col.length()): | ||
| 727 | - local_col[j+old_local_rows] = remote_col[j] | ||
| 728 | - | ||
| 729 | - # Save local fits file | ||
| 730 | - local.saveto(str(localfits), True) | ||
| 731 | - | ||
| 732 | # Return | 710 | # Return |
| 733 | return | 711 | return |
| 712 | + | ||
| 734 | 713 | ||
| 735 | # ======================== # | 714 | # ======================== # |
| 736 | # Main routine entry point # | 715 | # Main routine entry point # |
| @@ -740,8 +719,5 @@ if __name__ == '__main__': | @@ -740,8 +719,5 @@ if __name__ == '__main__': | ||
| 740 | # Create instance of application | 719 | # Create instance of application |
| 741 | app = csiactcopy(sys.argv) | 720 | app = csiactcopy(sys.argv) |
| 742 | 721 | ||
| 743 | - # Open logfile | ||
| 744 | - app._logFileOpen() | ||
| 745 | - | ||
| 746 | # Execute application | 722 | # Execute application |
| 747 | app.execute() | 723 | app.execute() |
cscripts/csiactdata.par
0 → 100644
| 1 | +############################################################################# | ||
| 2 | +# # | ||
| 3 | +# CTA Science Analysis Tools # | ||
| 4 | +# # | ||
| 5 | +# ------------------------------------------------------------------------- # | ||
| 6 | +# # | ||
| 7 | +# File: csiactdata.par # | ||
| 8 | +# Version: 1.1.0 # | ||
| 9 | +# # | ||
| 10 | +# Author: Michael Mayer # | ||
| 11 | +# michael.mayer@physik.hu-berlin.de # | ||
| 12 | +# HU Berlin # | ||
| 13 | +# # | ||
| 14 | +# Purpose: Parameter file for the csiactdata script # | ||
| 15 | +# # | ||
| 16 | +############################################################################# | ||
| 17 | +# | ||
| 18 | +# Input and output parameters | ||
| 19 | +#============================ | ||
| 20 | +datapath, s, a, $VHEFITS,,, "Path were data is located" | ||
| 21 | +master_indx, s, h, master.json,,, "Name of master index file" | ||
| 22 | + | ||
| 23 | +# | ||
| 24 | +# Standard parameters | ||
| 25 | +#==================== | ||
| 26 | +chatter, i, h, 2,0,4, "Chattiness of output" | ||
| 27 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | ||
| 28 | +debug, b, h, no,,, "Debugging mode activated" | ||
| 29 | +mode, s, h, ql,,, "Mode of automatic parameters" | ||
| 30 | +logfile, f, h, csiactdata.log,,, "Log filename" | ||
| 31 | + |
cscripts/csiactdata.py
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | # Inspection of IACT data storage | 3 | # Inspection of IACT data storage |
| 4 | # | 4 | # |
| 5 | -# Copyright (C) 2015 Michael Mayer | 5 | +# Copyright (C) 2015-2016 Michael Mayer |
| 6 | # | 6 | # |
| 7 | # This program is free software: you can redistribute it and/or modify | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -35,6 +35,8 @@ class csiactdata(ctools.cscript): | @@ -35,6 +35,8 @@ class csiactdata(ctools.cscript): | ||
| 35 | file or prints it on the screen. These information can be used as input | 35 | file or prints it on the screen. These information can be used as input |
| 36 | for 'csiactobs'. | 36 | for 'csiactobs'. |
| 37 | """ | 37 | """ |
| 38 | + | ||
| 39 | + # Constructors and destructors | ||
| 38 | def __init__(self, *argv): | 40 | def __init__(self, *argv): |
| 39 | """ | 41 | """ |
| 40 | Constructor. | 42 | Constructor. |
| @@ -45,9 +47,6 @@ class csiactdata(ctools.cscript): | @@ -45,9 +47,6 @@ class csiactdata(ctools.cscript): | ||
| 45 | self._datapath = os.getenv("VHEFITS","") | 47 | self._datapath = os.getenv("VHEFITS","") |
| 46 | self._prodnames = [] | 48 | self._prodnames = [] |
| 47 | 49 | ||
| 48 | - # Make sure that parfile exists | ||
| 49 | - file = self._parfile() | ||
| 50 | - | ||
| 51 | # Initialise application | 50 | # Initialise application |
| 52 | if len(argv) == 0: | 51 | if len(argv) == 0: |
| 53 | ctools.cscript.__init__(self, self._name, self._version) | 52 | ctools.cscript.__init__(self, self._name, self._version) |
| @@ -70,32 +69,8 @@ class csiactdata(ctools.cscript): | @@ -70,32 +69,8 @@ class csiactdata(ctools.cscript): | ||
| 70 | # Return | 69 | # Return |
| 71 | return | 70 | return |
| 72 | 71 | ||
| 73 | - def _parfile(self): | ||
| 74 | - """ | ||
| 75 | - Check if parfile exists. If parfile does not exist then create a | ||
| 76 | - default parfile. This kluge avoids shipping the cscript with a | ||
| 77 | - parfile. | ||
| 78 | - """ | ||
| 79 | - # Set parfile name | ||
| 80 | - parfile = self._name+".par" | ||
| 81 | - | ||
| 82 | - try: | ||
| 83 | - pars = gammalib.GApplicationPars(parfile) | ||
| 84 | - except: | ||
| 85 | - # Signal if parfile was not found | ||
| 86 | - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") | ||
| 87 | - | ||
| 88 | - # Create default parfile | ||
| 89 | - pars = gammalib.GApplicationPars() | ||
| 90 | - pars.append(gammalib.GApplicationPar("datapath","s","a",self._datapath,"","","Path were data is located")) | ||
| 91 | - pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) | ||
| 92 | - pars.append_standard() | ||
| 93 | - pars.append(gammalib.GApplicationPar("logfile","f","h","csiactdata.log","","","Log filename")) | ||
| 94 | - pars.save(parfile) | ||
| 95 | - | ||
| 96 | - # Return | ||
| 97 | - return | ||
| 98 | 72 | ||
| 73 | + # Private methods | ||
| 99 | def get_parameters(self): | 74 | def get_parameters(self): |
| 100 | """ | 75 | """ |
| 101 | Get parameters from parfile and setup the observation. | 76 | Get parameters from parfile and setup the observation. |
| @@ -119,16 +94,7 @@ class csiactdata(ctools.cscript): | @@ -119,16 +94,7 @@ class csiactdata(ctools.cscript): | ||
| 119 | # Return | 94 | # Return |
| 120 | return | 95 | return |
| 121 | 96 | ||
| 122 | - def execute(self): | ||
| 123 | - """ | ||
| 124 | - Execute the script. | ||
| 125 | - """ | ||
| 126 | - # Run the script | ||
| 127 | - self.run() | ||
| 128 | - | ||
| 129 | - # Return | ||
| 130 | - return | ||
| 131 | - | 97 | + # Public methods |
| 132 | def run(self): | 98 | def run(self): |
| 133 | """ | 99 | """ |
| 134 | Run the script. | 100 | Run the script. |
| @@ -222,6 +188,20 @@ class csiactdata(ctools.cscript): | @@ -222,6 +188,20 @@ class csiactdata(ctools.cscript): | ||
| 222 | # Return | 188 | # Return |
| 223 | return | 189 | return |
| 224 | 190 | ||
| 191 | + def execute(self): | ||
| 192 | + """ | ||
| 193 | + Execute the script. | ||
| 194 | + """ | ||
| 195 | + # Open logfile | ||
| 196 | + self._logFileOpen() | ||
| 197 | + | ||
| 198 | + # Run the script | ||
| 199 | + self.run() | ||
| 200 | + | ||
| 201 | + # Return | ||
| 202 | + return | ||
| 203 | + | ||
| 204 | + | ||
| 225 | def names(self): | 205 | def names(self): |
| 226 | """ | 206 | """ |
| 227 | Return available FITS production names | 207 | Return available FITS production names |
| @@ -239,8 +219,5 @@ if __name__ == '__main__': | @@ -239,8 +219,5 @@ if __name__ == '__main__': | ||
| 239 | # Create instance of application | 219 | # Create instance of application |
| 240 | app = csiactdata(sys.argv) | 220 | app = csiactdata(sys.argv) |
| 241 | 221 | ||
| 242 | - # Open logfile | ||
| 243 | - app._logFileOpen() | ||
| 244 | - | ||
| 245 | # Execute application | 222 | # Execute application |
| 246 | app.execute() | 223 | app.execute() |
cscripts/csiactobs.par
0 → 100644
| 1 | +############################################################################# | ||
| 2 | +# # | ||
| 3 | +# CTA Science Analysis Tools # | ||
| 4 | +# # | ||
| 5 | +# ------------------------------------------------------------------------- # | ||
| 6 | +# # | ||
| 7 | +# File: csiactobs.par # | ||
| 8 | +# Version: 1.1.0 # | ||
| 9 | +# # | ||
| 10 | +# Author: Michael Mayer # | ||
| 11 | +# michael.mayer@physik.hu-berlin.de # | ||
| 12 | +# HU Berlin # | ||
| 13 | +# # | ||
| 14 | +# Purpose: Parameter file for the csiactobs script # | ||
| 15 | +# # | ||
| 16 | +############################################################################# | ||
| 17 | +# | ||
| 18 | +# Input and output parameters | ||
| 19 | +#============================ | ||
| 20 | +datapath, s, a, $VHEFITS,,, "Path were data is located" | ||
| 21 | +prodname, s, a, ,,, "Data storage name" | ||
| 22 | +infile, f, a, runlist.lis,,, "Input runlist file" | ||
| 23 | +inmodel, f, h, NONE,,, "Input model definition XML file (optional)" | ||
| 24 | +master_indx, s, h, master.json,,, "Input master index file" | ||
| 25 | +outobs, f, a, obs.xml,,, "Output observation definition XML file" | ||
| 26 | +outmodel, f, a, bgmodels.xml,,, "Output model definition XML file" | ||
| 27 | + | ||
| 28 | +# | ||
| 29 | +# Script parameters | ||
| 30 | +#================== | ||
| 31 | +bkgpars, i, a, 1,,, "Number of free parameters per background model" | ||
| 32 | +bkg_scale, b, h, yes,,, "Apply background scaling factor from observation index file if available?" | ||
| 33 | +ev_hiera, s, h, events,,, "Hierarchy of event formats" | ||
| 34 | +aeff_hiera, s, h, aeff_2d,,, "Hierarchy of effective area formats" | ||
| 35 | +psf_hiera, s, h, psf_king|psf_3gauss,,, "Hierarchy of psf formats" | ||
| 36 | +edisp_hiera, s, h, edisp_2d,,, "Hierarchy of energy dispersion formats" | ||
| 37 | +bkg_hiera, s, h, bkg_3d,,, "Hierarchy of background formats" | ||
| 38 | +bkg_mod_hiera, s, h, irf|aeff|gauss,,, "Hierarchy of background models" | ||
| 39 | +bkg_gauss_norm, r, h, 1e-8,,, "Input normalisation for Gaussian background" | ||
| 40 | +bkg_gauss_index, r, h, -2.0,,, "Input spectral index for Gaussian background" | ||
| 41 | +bkg_gauss_sigma, r, h, 2.5,,, "Input sigma for Gaussian background" | ||
| 42 | +bkg_aeff_norm, r, h, 1e-14,,, "Input normalisation for effective area background" | ||
| 43 | +bkg_aeff_index, r, h, -2.0,,, "Input spectral index for effective area background" | ||
| 44 | +bkg_range_factor, r, h, 100.0,,, "Factor to determine range of background normalisation" | ||
| 45 | + | ||
| 46 | +# | ||
| 47 | +# Standard parameters | ||
| 48 | +#==================== | ||
| 49 | +chatter, i, h, 2,0,4, "Chattiness of output" | ||
| 50 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | ||
| 51 | +debug, b, h, no,,, "Debugging mode activated" | ||
| 52 | +mode, s, h, ql,,, "Mode of automatic parameters" | ||
| 53 | +logfile, f, h, csiactobs.log,,, "Log filename" | ||
| 54 | + |
cscripts/csiactobs.py
| @@ -37,6 +37,8 @@ class csiactobs(ctools.cscript): | @@ -37,6 +37,8 @@ class csiactobs(ctools.cscript): | ||
| 37 | described here: | 37 | described here: |
| 38 | http://gamma-astro-data-formats.readthedocs.org/en/latest/ | 38 | http://gamma-astro-data-formats.readthedocs.org/en/latest/ |
| 39 | """ | 39 | """ |
| 40 | + | ||
| 41 | + # Constructors and destructors | ||
| 40 | def __init__(self, *argv): | 42 | def __init__(self, *argv): |
| 41 | """ | 43 | """ |
| 42 | Constructor. | 44 | Constructor. |
| @@ -53,9 +55,6 @@ class csiactobs(ctools.cscript): | @@ -53,9 +55,6 @@ class csiactobs(ctools.cscript): | ||
| 53 | self._models = gammalib.GModels() | 55 | self._models = gammalib.GModels() |
| 54 | self._runlist = [] | 56 | self._runlist = [] |
| 55 | 57 | ||
| 56 | - # Make sure that parfile exists | ||
| 57 | - file = self._parfile() | ||
| 58 | - | ||
| 59 | # Initialise application | 58 | # Initialise application |
| 60 | if len(argv) == 0: | 59 | if len(argv) == 0: |
| 61 | ctools.cscript.__init__(self, self._name, self._version) | 60 | ctools.cscript.__init__(self, self._name, self._version) |
| @@ -78,50 +77,8 @@ class csiactobs(ctools.cscript): | @@ -78,50 +77,8 @@ class csiactobs(ctools.cscript): | ||
| 78 | # Return | 77 | # Return |
| 79 | return | 78 | return |
| 80 | 79 | ||
| 81 | - def _parfile(self): | ||
| 82 | - """ | ||
| 83 | - Check if parfile exists. If parfile does not exist then create a | ||
| 84 | - default parfile. This kluge avoids shipping the cscript with a parfile. | ||
| 85 | - """ | ||
| 86 | - # Set parfile name | ||
| 87 | - parfile = self._name+".par" | ||
| 88 | - | ||
| 89 | - try: | ||
| 90 | - pars = gammalib.GApplicationPars(parfile) | ||
| 91 | - except: | ||
| 92 | - # Signal if parfile was not found | ||
| 93 | - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") | ||
| 94 | - | ||
| 95 | - # Create default parfile | ||
| 96 | - pars = gammalib.GApplicationPars() | ||
| 97 | - pars.append(gammalib.GApplicationPar("datapath","s","a",self._datapath,"","","Path were data is located")) | ||
| 98 | - pars.append(gammalib.GApplicationPar("prodname","s","a","","","","Data storage name (Run csiactdata to view your options)")) | ||
| 99 | - pars.append(gammalib.GApplicationPar("infile","f","a","runlist.lis","","","Runlist file")) | ||
| 100 | - pars.append(gammalib.GApplicationPar("inmodel","f","h","NONE","","","Input model XML file (optional)")) | ||
| 101 | - pars.append(gammalib.GApplicationPar("outobs","f","a","obs.xml","","","Observation XML outfile")) | ||
| 102 | - pars.append(gammalib.GApplicationPar("outmodel","f","a","bgmodels.xml","","","Output model XML file")) | ||
| 103 | - pars.append(gammalib.GApplicationPar("bkgpars","i","a","1","","","Number of free parameters per background model")) | ||
| 104 | - pars.append(gammalib.GApplicationPar("master_indx","s","h","master.json","","","Name of master index file")) | ||
| 105 | - 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. ")) | ||
| 106 | - pars.append(gammalib.GApplicationPar("ev_hiera","s","h","events","","","Hierarchy of event formats")) | ||
| 107 | - pars.append(gammalib.GApplicationPar("aeff_hiera","s","h","aeff_2d","","","Hierarchy of effective area formats")) | ||
| 108 | - pars.append(gammalib.GApplicationPar("psf_hiera","s","h","psf_king|psf_3gauss","","","Hierarchy of psf formats")) | ||
| 109 | - pars.append(gammalib.GApplicationPar("edisp_hiera","s","h","edisp_2d","","","Hierarchy of energy dispersion formats")) | ||
| 110 | - pars.append(gammalib.GApplicationPar("bkg_hiera","s","h","bkg_3d","","","Hierarchy of background formats")) | ||
| 111 | - pars.append(gammalib.GApplicationPar("bkg_mod_hiera","s","h","irf|aeff|gauss","","","Hierarchy of background models")) | ||
| 112 | - pars.append(gammalib.GApplicationPar("bkg_gauss_norm","r","h","1e-8","","","Input normalisation for Gaussian background")) | ||
| 113 | - pars.append(gammalib.GApplicationPar("bkg_gauss_index","r","h","-2.0","","","Input spectral index for Gaussian background")) | ||
| 114 | - pars.append(gammalib.GApplicationPar("bkg_gauss_sigma","r","h","2.5","","","Input sigma for Gaussian background")) | ||
| 115 | - pars.append(gammalib.GApplicationPar("bkg_aeff_norm","r","h","1e-14","","","Input normalisation for effective area background")) | ||
| 116 | - pars.append(gammalib.GApplicationPar("bkg_aeff_index","r","h","-2.0","","","Input spectral index for effective area background")) | ||
| 117 | - pars.append(gammalib.GApplicationPar("bkg_range_factor","r","h","100.0","","","Factor to determine range of background normalisation")) | ||
| 118 | - pars.append_standard() | ||
| 119 | - pars.append(gammalib.GApplicationPar("logfile","f","h","csiactobs.log","","","Log filename")) | ||
| 120 | - pars.save(parfile) | ||
| 121 | - | ||
| 122 | - # Return | ||
| 123 | - return | ||
| 124 | 80 | ||
| 81 | + # Private methods | ||
| 125 | def _get_parameters(self): | 82 | def _get_parameters(self): |
| 126 | """ | 83 | """ |
| 127 | Get parameters from parfile and setup the observation. | 84 | Get parameters from parfile and setup the observation. |
| @@ -366,43 +323,8 @@ class csiactobs(ctools.cscript): | @@ -366,43 +323,8 @@ class csiactobs(ctools.cscript): | ||
| 366 | # Return model | 323 | # Return model |
| 367 | return model | 324 | return model |
| 368 | 325 | ||
| 369 | - def ebounds(self): | ||
| 370 | - """ | ||
| 371 | - Returns runlist energy range | ||
| 372 | - """ | ||
| 373 | - return self._ebounds | ||
| 374 | - | ||
| 375 | - def obs(self): | ||
| 376 | - """ | ||
| 377 | - Returns GObservations object | ||
| 378 | - """ | ||
| 379 | - # Initialise observations | ||
| 380 | - obs = gammalib.GObservations() | ||
| 381 | - | ||
| 382 | - # Read observations if XML is filled | ||
| 383 | - if self._xml.size(): | ||
| 384 | - obs.read(self._xml) | ||
| 385 | - | ||
| 386 | - # Assign models | ||
| 387 | - obs.models(self._models) | ||
| 388 | - | ||
| 389 | - # Return observations | ||
| 390 | - return obs | ||
| 391 | - | ||
| 392 | - | ||
| 393 | - def execute(self): | ||
| 394 | - """ | ||
| 395 | - Execute the script. | ||
| 396 | - """ | ||
| 397 | - # Run the script | ||
| 398 | - self.run() | ||
| 399 | - | ||
| 400 | - # Save residual map | ||
| 401 | - self.save(self._outobs, self._clobber) | ||
| 402 | - | ||
| 403 | - # Return | ||
| 404 | - return | ||
| 405 | 326 | ||
| 327 | + # Public methods | ||
| 406 | def run(self): | 328 | def run(self): |
| 407 | """ | 329 | """ |
| 408 | Run the script. | 330 | Run the script. |
| @@ -665,6 +587,22 @@ class csiactobs(ctools.cscript): | @@ -665,6 +587,22 @@ class csiactobs(ctools.cscript): | ||
| 665 | # Return | 587 | # Return |
| 666 | return | 588 | return |
| 667 | 589 | ||
| 590 | + def execute(self): | ||
| 591 | + """ | ||
| 592 | + Execute the script. | ||
| 593 | + """ | ||
| 594 | + # Open logfile | ||
| 595 | + self._logFileOpen() | ||
| 596 | + | ||
| 597 | + # Run the script | ||
| 598 | + self.run() | ||
| 599 | + | ||
| 600 | + # Save residual map | ||
| 601 | + self.save(self._outobs, self._clobber) | ||
| 602 | + | ||
| 603 | + # Return | ||
| 604 | + return | ||
| 605 | + | ||
| 668 | def save(self,outfile,clobber): | 606 | def save(self,outfile,clobber): |
| 669 | 607 | ||
| 670 | # Save observation XML file | 608 | # Save observation XML file |
| @@ -676,6 +614,29 @@ class csiactobs(ctools.cscript): | @@ -676,6 +614,29 @@ class csiactobs(ctools.cscript): | ||
| 676 | # Return | 614 | # Return |
| 677 | return | 615 | return |
| 678 | 616 | ||
| 617 | + def ebounds(self): | ||
| 618 | + """ | ||
| 619 | + Returns runlist energy range | ||
| 620 | + """ | ||
| 621 | + return self._ebounds | ||
| 622 | + | ||
| 623 | + def obs(self): | ||
| 624 | + """ | ||
| 625 | + Returns GObservations object | ||
| 626 | + """ | ||
| 627 | + # Initialise observations | ||
| 628 | + obs = gammalib.GObservations() | ||
| 629 | + | ||
| 630 | + # Read observations if XML is filled | ||
| 631 | + if self._xml.size(): | ||
| 632 | + obs.read(self._xml) | ||
| 633 | + | ||
| 634 | + # Assign models | ||
| 635 | + obs.models(self._models) | ||
| 636 | + | ||
| 637 | + # Return observations | ||
| 638 | + return obs | ||
| 639 | + | ||
| 679 | 640 | ||
| 680 | # ======================== # | 641 | # ======================== # |
| 681 | # Main routine entry point # | 642 | # Main routine entry point # |
| @@ -685,8 +646,5 @@ if __name__ == '__main__': | @@ -685,8 +646,5 @@ if __name__ == '__main__': | ||
| 685 | # Create instance of application | 646 | # Create instance of application |
| 686 | app = csiactobs(sys.argv) | 647 | app = csiactobs(sys.argv) |
| 687 | 648 | ||
| 688 | - # Open logfile | ||
| 689 | - app._logFileOpen() | ||
| 690 | - | ||
| 691 | # Execute application | 649 | # Execute application |
| 692 | app.execute() | 650 | app.execute() |
cscripts/cslightcrv.par
0 → 100644
| 1 | +############################################################################# | ||
| 2 | +# # | ||
| 3 | +# CTA Science Analysis Tools # | ||
| 4 | +# # | ||
| 5 | +# ------------------------------------------------------------------------- # | ||
| 6 | +# # | ||
| 7 | +# File: cslightcrv.par # | ||
| 8 | +# Version: 1.1.0 # | ||
| 9 | +# # | ||
| 10 | +# Author: Juergen Knoedlseder # | ||
| 11 | +# Jurgen.Knodlseder@irap.omp.eu # | ||
| 12 | +# IRAP # | ||
| 13 | +# # | ||
| 14 | +# Purpose: Parameter file for the cslightcrv script # | ||
| 15 | +# # | ||
| 16 | +############################################################################# | ||
| 17 | +# | ||
| 18 | +# Input and output parameters | ||
| 19 | +#============================ | ||
| 20 | +inobs, f, h, events.fits,,, "Input event list, counts cube, or observation definition XML file" | ||
| 21 | +inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file" | ||
| 22 | +srcname, s, a, Crab,,, "Source name" | ||
| 23 | +expcube, f, a, NONE,,, "Input exposure cube file (only needed for stacked analysis)" | ||
| 24 | +psfcube, f, a, NONE,,, "Input PSF cube file (only needed for stacked analysis)" | ||
| 25 | +edispcube, f, a, NONE,,, "Input energy dispersion cube file (only needed for stacked analysis)" | ||
| 26 | +bkgcube, f, a, NONE,,, "Input background cube file (only needed for stacked analysis)" | ||
| 27 | +caldb, s, a, prod2,,, "Calibration database" | ||
| 28 | +irf, s, a, South_0.5h,,, "Instrument response function" | ||
| 29 | +edisp, b, h, no,,, "Apply energy dispersion?" | ||
| 30 | +outfile, f, a, lightcurve.fits,,, "Output light curve file" | ||
| 31 | + | ||
| 32 | +# | ||
| 33 | +# Script parameters | ||
| 34 | +#================== | ||
| 35 | +tbinalg, s, a, GTI,FILE|LIN|GTI,, "Algorithm for defining time bins" | ||
| 36 | +tmin, r, a, 51544.5,,,"Lightcurve start time (MJD])" | ||
| 37 | +tmax, r, a, 51544.6,,,"Lightcurve stop time (MJD)" | ||
| 38 | +tbins, i, a, 5,,, "Number of time bins" | ||
| 39 | +tbinfile, f, a, NONE,,, "File defining the time binning" | ||
| 40 | +emin, r, a, 0.1,,, "Lower energy limit of events (TeV)" | ||
| 41 | +emax, r, a, 100.0,,, "Upper energy limit of events (TeV)" | ||
| 42 | +enumbins, i, a, 0,,, "Number of energy bins for binned (0=unbinned)" | ||
| 43 | +coordsys, s, a, CEL,CEL|GAL,, "Coordinate System" | ||
| 44 | +proj, s, a, CAR,AIT|AZP|CAR|MER|MOL|STG|TAN,, "Projection method" | ||
| 45 | +xref, r, a, 83.63,0,360, "First coordinate of image center in degrees (RA or galactic l)" | ||
| 46 | +yref, r, a, 22.01,-90,90, "Second coordinate of image center in degrees (DEC or galactic b)" | ||
| 47 | +nxpix, i, a, 200,,, "Size of the X axis in pixels" | ||
| 48 | +nypix, i, a, 200,,, "Size of the Y axis in pixels" | ||
| 49 | +binsz, r, a, 0.02,,, "Pixel size (deg/pixel)" | ||
| 50 | +calc_ts, b, h, yes,,, "Compute TS value for each bin?" | ||
| 51 | +calc_ulim, b, h, yes,,, "Compute upper limit for each bin?" | ||
| 52 | +fix_srcs, b, h, yes,,, "Fix other sky model parameters?" | ||
| 53 | +fix_bkg, b, h, no,,, "Fix background model parameters?" | ||
| 54 | + | ||
| 55 | +# | ||
| 56 | +# Standard parameters | ||
| 57 | +#==================== | ||
| 58 | +chatter, i, h, 2,0,4, "Chattiness of output" | ||
| 59 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | ||
| 60 | +debug, b, h, no,,, "Debugging mode activated" | ||
| 61 | +mode, s, h, ql,,, "Mode of automatic parameters" | ||
| 62 | +logfile, f, h, cslightcrv.log,,, "Log filename" | ||
| 63 | + | ||
| 64 | + | ||
| 65 | + |
cscripts/cslightcrv.py
| @@ -56,9 +56,6 @@ class cslightcrv(ctools.cscript): | @@ -56,9 +56,6 @@ class cslightcrv(ctools.cscript): | ||
| 56 | else: | 56 | else: |
| 57 | self._obs = gammalib.GObservations() | 57 | self._obs = gammalib.GObservations() |
| 58 | 58 | ||
| 59 | - # Make sure that parfile exists | ||
| 60 | - self._parfile() | ||
| 61 | - | ||
| 62 | # Initialise application | 59 | # Initialise application |
| 63 | if len(argv) == 0: | 60 | if len(argv) == 0: |
| 64 | ctools.cscript.__init__(self, self._name, self._version) | 61 | ctools.cscript.__init__(self, self._name, self._version) |
| @@ -83,59 +80,6 @@ class cslightcrv(ctools.cscript): | @@ -83,59 +80,6 @@ class cslightcrv(ctools.cscript): | ||
| 83 | 80 | ||
| 84 | 81 | ||
| 85 | # Private methods | 82 | # Private methods |
| 86 | - def _parfile(self): | ||
| 87 | - """ | ||
| 88 | - Check if parfile exists. If parfile does not exist then create a | ||
| 89 | - default parfile. This kluge avoids shipping the cscript with a parfile. | ||
| 90 | - """ | ||
| 91 | - # Set parfile name | ||
| 92 | - parfile = self._name+".par" | ||
| 93 | - | ||
| 94 | - try: | ||
| 95 | - pars = gammalib.GApplicationPars(parfile) | ||
| 96 | - except: | ||
| 97 | - # Signal if parfile was not found | ||
| 98 | - sys.stdout.write("Parfile "+parfile+" not found. Create default parfile.\n") | ||
| 99 | - | ||
| 100 | - # Create default parfile | ||
| 101 | - pars = gammalib.GApplicationPars() | ||
| 102 | - pars.append(gammalib.GApplicationPar("inobs","f","a","events.fits","","","Input event list, counts cube, or observation definition XML file")) | ||
| 103 | - pars.append(gammalib.GApplicationPar("inmodel","f","a","$CTOOLS/share/models/crab.xml","","","Input model XML file")) | ||
| 104 | - pars.append(gammalib.GApplicationPar("srcname","s","a","Crab","","","Source name")) | ||
| 105 | - pars.append(gammalib.GApplicationPar("expcube","f","a","NONE","","","Input exposure cube file (only needed for stacked analysis)")) | ||
| 106 | - pars.append(gammalib.GApplicationPar("psfcube","f","a","NONE","","","Input PSF cube file (only needed for stacked analysis)")) | ||
| 107 | - pars.append(gammalib.GApplicationPar("edispcube","f","a","NONE","","","Input energy dispersion cube file (only needed for stacked analysis)")) | ||
| 108 | - pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Input background cube file (only needed for stacked analysis)")) | ||
| 109 | - pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?")) | ||
| 110 | - pars.append(gammalib.GApplicationPar("caldb","s","a","prod2","","","Calibration database")) | ||
| 111 | - pars.append(gammalib.GApplicationPar("irf","s","a","South_0.5h","","","Instrument response function")) | ||
| 112 | - pars.append(gammalib.GApplicationPar("outfile","f","a","lightcurve.fits","","","Output light curve file")) | ||
| 113 | - pars.append(gammalib.GApplicationPar("tbinalg","s","a","GTI","FILE|LIN|GTI","", "Algorithm for defining time bins")) | ||
| 114 | - pars.append(gammalib.GApplicationPar("tmin","r","a","51544.5","","days","Lightcurve start time [MJD]")) | ||
| 115 | - pars.append(gammalib.GApplicationPar("tmax","r","a","51544.6","","days","Lightcurve stop time [MJD]")) | ||
| 116 | - pars.append(gammalib.GApplicationPar("tbins","i","a","5","","","Number of time bins")) | ||
| 117 | - pars.append(gammalib.GApplicationPar("tbinfile","f","a","tbins.fits","","", "File defining the time binning")) | ||
| 118 | - pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins per light curve bin (0=unbinned)")) | ||
| 119 | - pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit of events (TeV)")) | ||
| 120 | - pars.append(gammalib.GApplicationPar("emax","r","a","100.0","","","Upper energy limit of events (TeV)")) | ||
| 121 | - pars.append(gammalib.GApplicationPar("coordsys","s","a","CEL","CEL|GAL","","Coordinate System")) | ||
| 122 | - pars.append(gammalib.GApplicationPar("proj","s","a","CAR","AIT|AZP|CAR|MER|MOL|STG|TAN","","Projection method")) | ||
| 123 | - pars.append(gammalib.GApplicationPar("xref","r","a","83.63","0","360","First coordinate of image center in degrees (RA or galactic l)")) | ||
| 124 | - pars.append(gammalib.GApplicationPar("yref","r","a","22.01","-90","90","Second coordinate of image center in degrees (DEC or galactic b)")) | ||
| 125 | - pars.append(gammalib.GApplicationPar("nxpix","i","a","200","","","Size of the X axis in pixels")) | ||
| 126 | - pars.append(gammalib.GApplicationPar("nypix","i","a","200","","","Size of the Y axis in pixels")) | ||
| 127 | - pars.append(gammalib.GApplicationPar("binsz","r","a","0.02","","","Pixel size (deg/pixel)")) | ||
| 128 | - pars.append(gammalib.GApplicationPar("calc_ts","b","h","yes","yes|no","","Compute TS value for each bin?")) | ||
| 129 | - pars.append(gammalib.GApplicationPar("calc_ulim","b","h","yes","yes|no","","Compute upper limit for each bin?")) | ||
| 130 | - pars.append(gammalib.GApplicationPar("fix_srcs","b","h","yes","yes|no","","Fix other sky model parameters?")) | ||
| 131 | - pars.append(gammalib.GApplicationPar("fix_bkg","b","h","no","yes|no","","Fix background model parameters?")) | ||
| 132 | - pars.append_standard() | ||
| 133 | - pars.append(gammalib.GApplicationPar("logfile","f","h","cslightcrv.log","","","Log filename")) | ||
| 134 | - pars.save(parfile) | ||
| 135 | - | ||
| 136 | - # Return | ||
| 137 | - return | ||
| 138 | - | ||
| 139 | def _create_tbounds(self): | 83 | def _create_tbounds(self): |
| 140 | 84 | ||
| 141 | # Create time bin container | 85 | # Create time bin container |