Commit a5030d6d3dfa96e006f9e8e0445e9d15d6797278
1 parent
db573ea0
Added cstsmapmerge and included documentation and unit tests
Showing
11 changed files
with
630 additions
and
13 deletions
cscripts/Makefile.am
| 1 | 1 | ## Process this file with automake to produce Makefile.in |
| 2 | 2 | |
| 3 | -# Scripts to be distributed in bindir | |
| 4 | -binscripts = tsmerge.py | |
| 5 | - | |
| 6 | 3 | # Scripts to be distributed in $(pyexecdir)/cscripts |
| 7 | 4 | pythonscripts = __init__.py \ |
| 8 | 5 | cspull.py cssens.py cstsdist.py cscaldb.py csresmap.py \ |
| 9 | 6 | cshessobs.py csobsdef.py csspec.py cslightcrv.py csobsinfo.py \ |
| 10 | - csinfo.py csmodelinfo.py csmodelmerge.py \ | |
| 7 | + csinfo.py csmodelinfo.py csmodelmerge.py cstsmapmerge.py \ | |
| 11 | 8 | obsutils.py |
| 12 | 9 | |
| 13 | 10 | # Scripts for which symbolic links will be created in bindir |
| 14 | 11 | linkscripts = cspull cssens cstsdist cscaldb csresmap \ |
| 15 | 12 | cshessobs csobsdef csspec cslightcrv csobsinfo csmodelmerge \ |
| 16 | - csinfo csmodelinfo | |
| 13 | + csinfo csmodelinfo cstsmapmerge | |
| 17 | 14 | |
| 18 | 15 | # Distribute scripts |
| 19 | 16 | EXTRA_DIST = $(binscripts) $(pythonscripts) | ... | ... |
cscripts/csmodelinfo.py
| ... | ... | @@ -499,7 +499,7 @@ class csmodelinfo(ctools.cscript): |
| 499 | 499 | # ======================== # |
| 500 | 500 | if __name__ == '__main__': |
| 501 | 501 | """ |
| 502 | - Generates caldb entry. | |
| 502 | + Generates model information output. | |
| 503 | 503 | """ |
| 504 | 504 | # Create instance of application |
| 505 | 505 | app = csmodelinfo(sys.argv) | ... | ... |
cscripts/csmodelmerge.py
| ... | ... | @@ -116,7 +116,7 @@ class csmodelmerge(ctools.cscript): |
| 116 | 116 | |
| 117 | 117 | # Throw exception if input models cannot be decoded |
| 118 | 118 | else: |
| 119 | - msg = "Parameter \"inmodels\" must contain either an @asci file, a comma-separated or space-separated list of files or a wildcard string" | |
| 119 | + msg = "Parameter \"inmodels\" must contain either an @ASCII file, a comma-separated or space-separated list of files or a wildcard string" | |
| 120 | 120 | raise gammalib.GException.invalid_argument("csmodelmerge::get_parameters", msg) |
| 121 | 121 | |
| 122 | 122 | # Get output file |
| ... | ... | @@ -205,7 +205,7 @@ class csmodelmerge(ctools.cscript): |
| 205 | 205 | # ======================== # |
| 206 | 206 | if __name__ == '__main__': |
| 207 | 207 | """ |
| 208 | - Generates caldb entry. | |
| 208 | + Merges model XML files | |
| 209 | 209 | """ |
| 210 | 210 | # Create instance of application |
| 211 | 211 | app = csmodelmerge(sys.argv) | ... | ... |
cscripts/csobsinfo.py
| ... | ... | @@ -452,7 +452,7 @@ class csobsinfo(ctools.cscript): |
| 452 | 452 | # ======================== # |
| 453 | 453 | if __name__ == '__main__': |
| 454 | 454 | """ |
| 455 | - Generates caldb entry. | |
| 455 | + Generates information about an observation container. | |
| 456 | 456 | """ |
| 457 | 457 | # Create instance of application |
| 458 | 458 | app = csobsinfo(sys.argv) | ... | ... |
cscripts/cstsmapmerge.py
0 → 100755
| 1 | +#!/usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# Merges sliced TS map files into one map | |
| 4 | +# | |
| 5 | +# Copyright (C) 2015 Michael Mayer | |
| 6 | +# | |
| 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 | |
| 9 | +# the Free Software Foundation, either version 3 of the License, or | |
| 10 | +# (at your option) any later version. | |
| 11 | +# | |
| 12 | +# This program is distributed in the hope that it will be useful, | |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | +# GNU General Public License for more details. | |
| 16 | +# | |
| 17 | +# You should have received a copy of the GNU General Public License | |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | +# | |
| 20 | +# ========================================================================== | |
| 21 | +import gammalib | |
| 22 | +import ctools | |
| 23 | +import sys | |
| 24 | +import glob | |
| 25 | +import os | |
| 26 | + | |
| 27 | + | |
| 28 | +# =============== # | |
| 29 | +# cshessobs class # | |
| 30 | +# =============== # | |
| 31 | +class cstsmapmerge(ctools.cscript): | |
| 32 | + """ | |
| 33 | + This class merges an arbitray number of model container into one output model XML file | |
| 34 | + """ | |
| 35 | + def __init__(self, *argv): | |
| 36 | + """ | |
| 37 | + Constructor. | |
| 38 | + """ | |
| 39 | + # Set name | |
| 40 | + self.name = "cstsmapmerge" | |
| 41 | + self.version = "0.1.0" | |
| 42 | + | |
| 43 | + # Make sure that parfile exists | |
| 44 | + file = self.parfile() | |
| 45 | + | |
| 46 | + # Initialise application | |
| 47 | + if len(argv) == 0: | |
| 48 | + ctools.cscript.__init__(self, self.name, self.version) | |
| 49 | + elif len(argv) == 1: | |
| 50 | + ctools.cscript.__init__(self, self.name, self.version, *argv) | |
| 51 | + else: | |
| 52 | + raise TypeError("Invalid number of arguments given.") | |
| 53 | + | |
| 54 | + # Set logger properties | |
| 55 | + self.log_header() | |
| 56 | + self.log.date(True) | |
| 57 | + | |
| 58 | + # Return | |
| 59 | + return | |
| 60 | + | |
| 61 | + def __del__(self): | |
| 62 | + """ | |
| 63 | + Destructor. | |
| 64 | + """ | |
| 65 | + # Return | |
| 66 | + return | |
| 67 | + | |
| 68 | + def parfile(self): | |
| 69 | + """ | |
| 70 | + Check if parfile exists. If parfile does not exist then create a | |
| 71 | + default parfile. This kluge avoids shipping the cscript with a parfile. | |
| 72 | + """ | |
| 73 | + | |
| 74 | + # Set parfile name | |
| 75 | + parfile = self.name+".par" | |
| 76 | + | |
| 77 | + try: | |
| 78 | + pars = gammalib.GApplicationPars(parfile) | |
| 79 | + except: | |
| 80 | + # Signal that parfile was not found | |
| 81 | + print("Parfile \""+parfile+"\" not found. Create default parfile.") | |
| 82 | + | |
| 83 | + # Create default parfile | |
| 84 | + pars = gammalib.GApplicationPars() | |
| 85 | + pars.append(gammalib.GApplicationPar("inmaps","s","a","tsmap.fits","","","Input TS map FITS files")) | |
| 86 | + pars.append(gammalib.GApplicationPar("outmap","f","a","NONE","","","Output TS map FITS file")) | |
| 87 | + pars.append(gammalib.GApplicationPar("overwrite","b","h","yes","","","Overwrite previously filled bins?")) | |
| 88 | + pars.append(gammalib.GApplicationPar("delete","b","h","no","","","Delete merged files?")) | |
| 89 | + pars.append_standard() | |
| 90 | + pars.append(gammalib.GApplicationPar("logfile","f","h","cstsmapmerge.log","","","Log filename")) | |
| 91 | + pars.save(parfile) | |
| 92 | + | |
| 93 | + # Return | |
| 94 | + return | |
| 95 | + | |
| 96 | + def get_parameters(self): | |
| 97 | + """ | |
| 98 | + Get parameters from parfile and setup the observation. | |
| 99 | + """ | |
| 100 | + # Get input models | |
| 101 | + self.inmodels = self["inmaps"].string() | |
| 102 | + | |
| 103 | + # Interpet inmodels string | |
| 104 | + # Handle ascii files | |
| 105 | + if "@" == self.inmodels[0]: | |
| 106 | + self.files = open(self.inmodels.replace("@","")).read().splitlines() | |
| 107 | + | |
| 108 | + # Handle wild card strings | |
| 109 | + elif "*" in self.inmodels: | |
| 110 | + self.files = glob.glob(self.inmodels) | |
| 111 | + | |
| 112 | + # Handle space-separated list | |
| 113 | + elif " " in self.inmodels: | |
| 114 | + self.files = self.inmodels.split(" ") | |
| 115 | + | |
| 116 | + # Handle comma-separated list | |
| 117 | + elif "," in self.inmodels: | |
| 118 | + self.files = self.inmodels.split(",") | |
| 119 | + | |
| 120 | + # Throw exception if input models cannot be decoded | |
| 121 | + else: | |
| 122 | + msg = "Parameter \"inmmaps\" must contain either an @ASCII file, a comma-separated or space-separated list of files or a wildcard string" | |
| 123 | + sys.exit(msg) | |
| 124 | + | |
| 125 | + if len(self.files) <= 1: | |
| 126 | + msg = "Need at least two files to start merging, "+str(len(self.files))+" given" | |
| 127 | + sys.exit(msg) | |
| 128 | + | |
| 129 | + # Get output file | |
| 130 | + self.outmap = self["outmap"].filename() | |
| 131 | + | |
| 132 | + # Get other parameters | |
| 133 | + self.overwrite = self["overwrite"].boolean() | |
| 134 | + self.delete = self["delete"].boolean() | |
| 135 | + | |
| 136 | + # Return | |
| 137 | + return | |
| 138 | + | |
| 139 | + | |
| 140 | + def init_map(self, fitsfile): | |
| 141 | + | |
| 142 | + self.in_filename = fitsfile | |
| 143 | + | |
| 144 | + # open FITS file | |
| 145 | + | |
| 146 | + fits = gammalib.GFits(fitsfile) | |
| 147 | + self.tsmap = gammalib.GSkyMap() | |
| 148 | + self.tsmap.read(fits[0]) | |
| 149 | + | |
| 150 | + self.statusmap = gammalib.GSkyMap() | |
| 151 | + self.statusmap.read(fits["STATUS MAP"]) | |
| 152 | + | |
| 153 | + # Get other maps | |
| 154 | + self.maps = [] | |
| 155 | + self.mapnames = [] | |
| 156 | + | |
| 157 | + # Loop over extensions | |
| 158 | + for hdu in fits: | |
| 159 | + | |
| 160 | + # Leave out primary and status extension | |
| 161 | + if hdu.extname() != "IMAGE" and hdu.extname() != "STATUS MAP": | |
| 162 | + | |
| 163 | + # Add present maps | |
| 164 | + skymap = gammalib.GSkyMap() | |
| 165 | + skymap.read(hdu) | |
| 166 | + self.maps.append(skymap) | |
| 167 | + self.mapnames.append(hdu.extname()) | |
| 168 | + | |
| 169 | + # Close FITS file | |
| 170 | + fits.close() | |
| 171 | + | |
| 172 | + # Return | |
| 173 | + return | |
| 174 | + | |
| 175 | + # Add map instances to each other | |
| 176 | + # in this way the TS maps get merged | |
| 177 | + def add(self, fitsfile): | |
| 178 | + | |
| 179 | + # open FITS file | |
| 180 | + fits = gammalib.GFits(fitsfile) | |
| 181 | + add_tsmap = gammalib.GSkyMap() | |
| 182 | + add_tsmap.read(fits[0]) | |
| 183 | + | |
| 184 | + add_statusmap = gammalib.GSkyMap() | |
| 185 | + add_statusmap.read(fits["STATUS MAP"]) | |
| 186 | + | |
| 187 | + # Get other maps | |
| 188 | + add_maps = [] | |
| 189 | + | |
| 190 | + # Loop over extensions | |
| 191 | + for hdu in fits: | |
| 192 | + | |
| 193 | + # Leave out primary and status extension | |
| 194 | + if hdu.extname() != "IMAGE" and hdu.extname() != "STATUS MAP": | |
| 195 | + | |
| 196 | + # Add present maps | |
| 197 | + skymap = gammalib.GSkyMap() | |
| 198 | + skymap.read(hdu) | |
| 199 | + add_maps.append(skymap) | |
| 200 | + | |
| 201 | + # Close FITS file | |
| 202 | + fits.close() | |
| 203 | + | |
| 204 | + # Compare size of other maps | |
| 205 | + if not len(add_maps) == len(self.maps): | |
| 206 | + self.error("Maps cannot be added: Maps from \""+self.in_filename+"\" do not match from \""+fitsfile+"\"") | |
| 207 | + | |
| 208 | + # Loop over bins | |
| 209 | + for i in range(self.tsmap.npix()): | |
| 210 | + if add_statusmap[i] > 0.5: | |
| 211 | + | |
| 212 | + # throw exception if this bin has already been computed | |
| 213 | + if self.statusmap[i] > 0.5 and not self.overwrite: | |
| 214 | + msg = "Attempt to merge bin which apparently has already been merged. File \""+fitsfile+"\" contains already merged bins." | |
| 215 | + msg += " Set hidden parameter overwrite=yes to avoid this error" | |
| 216 | + raise gammalib.GException("cstsmapmerge::add", msg) | |
| 217 | + | |
| 218 | + # Copy TS values | |
| 219 | + self.tsmap[i] = add_tsmap[i] | |
| 220 | + | |
| 221 | + # Copy status | |
| 222 | + self.statusmap[i] = add_statusmap[i] | |
| 223 | + | |
| 224 | + # Loop over maps and copy entries | |
| 225 | + for j in range(len(self.maps)): | |
| 226 | + self.maps[j][i] = add_maps[j][i] | |
| 227 | + | |
| 228 | + # Return | |
| 229 | + return | |
| 230 | + | |
| 231 | + def run(self): | |
| 232 | + """ | |
| 233 | + Run the script. | |
| 234 | + """ | |
| 235 | + # Switch screen logging on in debug mode | |
| 236 | + if self.logDebug(): | |
| 237 | + self.log.cout(True) | |
| 238 | + | |
| 239 | + # Get parameters | |
| 240 | + self.get_parameters() | |
| 241 | + | |
| 242 | + # Write input parameters into logger | |
| 243 | + if self.logTerse(): | |
| 244 | + self.log_parameters() | |
| 245 | + self.log("\n") | |
| 246 | + | |
| 247 | + if self.logTerse(): | |
| 248 | + self.log("\n") | |
| 249 | + self.log.header1("Merging sliced TS map files") | |
| 250 | + self.log("\n") | |
| 251 | + | |
| 252 | + # Initialise file to start with | |
| 253 | + file0 ="" | |
| 254 | + | |
| 255 | + self.added_files = [] | |
| 256 | + | |
| 257 | + # Test files for the entry status map | |
| 258 | + # use the first one to appear useful | |
| 259 | + for fitsfile in self.files: | |
| 260 | + if not gammalib.is_fits(fitsfile): | |
| 261 | + self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") | |
| 262 | + fits = gammalib.GFits(fitsfile) | |
| 263 | + | |
| 264 | + if fits.contains("STATUS MAP"): | |
| 265 | + self.log("Using file \""+fitsfile+"\" as initialising map\n") | |
| 266 | + file0 = fitsfile | |
| 267 | + break | |
| 268 | + else: | |
| 269 | + if self.logExplicit(): | |
| 270 | + self.log("File \""+fitsfile+"\" has not \"STATUS MAP\" extension\n") | |
| 271 | + | |
| 272 | + # Print an error message if no suitable file was provided | |
| 273 | + if file0 == "": | |
| 274 | + if self.logTerse(): | |
| 275 | + self.log("None of the provided file seems to be a sliced ts map file (no \"STATUS MAP\" extension)\n") | |
| 276 | + | |
| 277 | + # Otherwise merge files | |
| 278 | + else: | |
| 279 | + | |
| 280 | + # copy file list | |
| 281 | + workfiles = self.files | |
| 282 | + | |
| 283 | + # Remove entry which will be used to initalise the map | |
| 284 | + workfiles.remove(file0) | |
| 285 | + | |
| 286 | + # Initialise map from first file | |
| 287 | + self.init_map(file0) | |
| 288 | + | |
| 289 | + # Append to added files | |
| 290 | + self.added_files.append(file0) | |
| 291 | + | |
| 292 | + # Loop over files | |
| 293 | + for fitsfile in workfiles: | |
| 294 | + | |
| 295 | + # Skip if file is not FITS | |
| 296 | + if not gammalib.is_fits(fitsfile): | |
| 297 | + if self.logTerse(): | |
| 298 | + self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") | |
| 299 | + continue | |
| 300 | + | |
| 301 | + # Skip if file does not contain status map | |
| 302 | + fits = gammalib.GFits(fitsfile) | |
| 303 | + if not fits.contains("STATUS MAP"): | |
| 304 | + if self.logTerse(): | |
| 305 | + self.log("Skipping file \""+fitsfile+" (not a FITS file)\n") | |
| 306 | + continue | |
| 307 | + | |
| 308 | + # Logging | |
| 309 | + if self.logTerse(): | |
| 310 | + self.log("Adding TS map slice \""+fitsfile+"\"\n") | |
| 311 | + | |
| 312 | + # Add file | |
| 313 | + self.add(fitsfile) | |
| 314 | + | |
| 315 | + # Append to added files | |
| 316 | + self.added_files.append(fitsfile) | |
| 317 | + | |
| 318 | + # Return | |
| 319 | + return | |
| 320 | + | |
| 321 | + | |
| 322 | + def save(self): | |
| 323 | + """ | |
| 324 | + Save merged tsmap file and remove slices if requested | |
| 325 | + """ | |
| 326 | + | |
| 327 | + # Logging | |
| 328 | + if self.logExplicit(): | |
| 329 | + self.log("\n") | |
| 330 | + self.log.header1("Saving merged TS map") | |
| 331 | + self.log("\n") | |
| 332 | + | |
| 333 | + # Create FITS file | |
| 334 | + fits = gammalib.GFits() | |
| 335 | + | |
| 336 | + # Write TS map into primary | |
| 337 | + self.tsmap.write(fits) | |
| 338 | + | |
| 339 | + # Loop over maps and write them to fits | |
| 340 | + for i in range(len(self.maps)): | |
| 341 | + self.maps[i].write(fits) | |
| 342 | + | |
| 343 | + # Set map names as extensions | |
| 344 | + for i in range(len(self.mapnames)): | |
| 345 | + fits[i+1].extname(self.mapnames[i]) | |
| 346 | + | |
| 347 | + # Check if map is fully done | |
| 348 | + done = True | |
| 349 | + for pix in self.statusmap: | |
| 350 | + if pix < 0.5: | |
| 351 | + done = False | |
| 352 | + break | |
| 353 | + | |
| 354 | + # Write Status map if we are not done yet | |
| 355 | + if not done: | |
| 356 | + self.statusmap.write(fits) | |
| 357 | + fits[fits.size()-1].extname("STATUS MAP") | |
| 358 | + | |
| 359 | + # Save FITS file | |
| 360 | + fits.saveto(self.outmap, self.clobber()) | |
| 361 | + if self.logExplicit(): | |
| 362 | + self.log("Saved output map to \""+self.outmap+"\"\n") | |
| 363 | + if self.delete: | |
| 364 | + if self.logTerse(): | |
| 365 | + self.log("\n") | |
| 366 | + self.log.header1("Deleting slices") | |
| 367 | + self.log("\n") | |
| 368 | + for filename in self.added_files: | |
| 369 | + if self.logExplicit(): | |
| 370 | + self.log("Deleting file \""+filename+"\"\n") | |
| 371 | + os.remove(filename) | |
| 372 | + | |
| 373 | + # Return | |
| 374 | + return | |
| 375 | + | |
| 376 | + | |
| 377 | + def execute(self): | |
| 378 | + """ | |
| 379 | + Execute the script. | |
| 380 | + """ | |
| 381 | + # Run the script | |
| 382 | + self.run() | |
| 383 | + | |
| 384 | + # Save ds9 file if required | |
| 385 | + self.save() | |
| 386 | + | |
| 387 | + # Return | |
| 388 | + return | |
| 389 | + | |
| 390 | + | |
| 391 | +# ======================== # | |
| 392 | +# Main routine entry point # | |
| 393 | +# ======================== # | |
| 394 | +if __name__ == '__main__': | |
| 395 | + """ | |
| 396 | + Merges ts map slices. | |
| 397 | + """ | |
| 398 | + # Create instance of application | |
| 399 | + app = cstsmapmerge(sys.argv) | |
| 400 | + | |
| 401 | + # Open logfile | |
| 402 | + app.logFileOpen() | |
| 403 | + | |
| 404 | + # Execute application | |
| 405 | + app.execute() | ... | ... |
doc/source/reference_manual/csmodelmerge.rst
0 → 100644
| 1 | +.. _csmodelmerge: | |
| 2 | + | |
| 3 | +csmodelmerge | |
| 4 | +====== | |
| 5 | + | |
| 6 | +Merges an arbitrary number of model XML files into one file. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | + | |
| 12 | +This script can be used to merge several model XML file into one output file. | |
| 13 | +The files can be passed via the ``inmodels`` parameter. There are 4 options to specify | |
| 14 | +a list of files that should be merged: | |
| 15 | +- a space-separated list of file names (e.g. model1.xml model2.xml) | |
| 16 | +- a comma-separated list of file names (e.g. model1.xml,model2.xml) | |
| 17 | +- a wildcard string (e.g. mymodel*.xml) | |
| 18 | +- an ASCII file containing the file names, one file per line (e.g. @mymodels.txt) | |
| 19 | + | |
| 20 | +Note that the "@" needs to be specified in case of an ASCII file name. It is also important to | |
| 21 | +note that models with the same name cannot be appended. The tool will throw and exception if | |
| 22 | +the provided file contain models with the same name. | |
| 23 | + | |
| 24 | + | |
| 25 | +General parameters | |
| 26 | +------------------ | |
| 27 | + | |
| 28 | +``inmodels [string]`` | |
| 29 | + Input model XML files | |
| 30 | + | |
| 31 | +``outmodel [file]`` | |
| 32 | + Output model file | |
| 33 | + | |
| 34 | + | |
| 35 | +Standard parameters | |
| 36 | +------------------- | |
| 37 | + | |
| 38 | +``(chatter = 2) [integer]`` | |
| 39 | + Verbosity of the executable: | |
| 40 | + chatter = 0: no information will be logged | |
| 41 | + | |
| 42 | + chatter = 1: only errors will be logged | |
| 43 | + | |
| 44 | + chatter = 2: errors and actions will be logged | |
| 45 | + | |
| 46 | + chatter = 3: report about the task execution | |
| 47 | + | |
| 48 | + chatter = 4: detailed report about the task execution | |
| 49 | + | |
| 50 | +``(clobber = yes) [boolean]`` | |
| 51 | + Specifies whether an existing output counts cube should be overwritten. | |
| 52 | + | |
| 53 | +``(debug = no) [boolean]`` | |
| 54 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 55 | + | |
| 56 | +``(mode = ql) [string]`` | |
| 57 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 58 | + | |
| 59 | +``(logfile = cssens.log) [filename]`` | |
| 60 | + Log filename. | |
| 61 | + | |
| 62 | + | |
| 63 | +Related tools or scripts | |
| 64 | +------------------------ | |
| 65 | + | ... | ... |
doc/source/reference_manual/cstsmapmerge.rst
0 → 100644
| 1 | +.. _cstsmapmerge: | |
| 2 | + | |
| 3 | +cstsmapmerge | |
| 4 | +====== | |
| 5 | + | |
| 6 | +Merges slices of splitted tsmap computations. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | +In case a TS map has been computed using the option to split the calculations into | |
| 12 | +several jobs, this tool is required to merge the output into one final map again. | |
| 13 | +Running :doc:`cttsmap` with the hidden parameters ``binmin`` and ``binmax`` specified | |
| 14 | +will result in several sliced TS maps. This script merges them into one FITS file. | |
| 15 | +The input slices can be passed via the ``inmaps`` parameter. There are 4 options to specify | |
| 16 | +a list of files that should be merged: | |
| 17 | +- a space-separated list of file names (e.g. tsmap1.fits tsmap2.fits) | |
| 18 | +- a comma-separated list of file names (e.g. tsmap1.fits,tsmap2.fits) | |
| 19 | +- a wildcard string (e.g. tsmap*.xml) | |
| 20 | +- an ASCII file containing the file names, one file per line (e.g. @mymaps.txt) | |
| 21 | + | |
| 22 | +Note that the "@" needs to be specified in case of an ASCII file name. | |
| 23 | + | |
| 24 | +General parameters | |
| 25 | +------------------ | |
| 26 | + | |
| 27 | +``inmaps [string]`` | |
| 28 | + Input TS map FITS files | |
| 29 | + | |
| 30 | +``outmap [file]`` | |
| 31 | + Output TS map FITS file | |
| 32 | + | |
| 33 | +``(overwrite=yes) [boolean]`` | |
| 34 | + Overwrite previously filled bins? | |
| 35 | + | |
| 36 | +``(delete=no) [boolean]`` | |
| 37 | + Delete merged files? | |
| 38 | + | |
| 39 | + | |
| 40 | +Standard parameters | |
| 41 | +------------------- | |
| 42 | + | |
| 43 | +``(chatter = 2) [integer]`` | |
| 44 | + Verbosity of the executable: | |
| 45 | + chatter = 0: no information will be logged | |
| 46 | + | |
| 47 | + chatter = 1: only errors will be logged | |
| 48 | + | |
| 49 | + chatter = 2: errors and actions will be logged | |
| 50 | + | |
| 51 | + chatter = 3: report about the task execution | |
| 52 | + | |
| 53 | + chatter = 4: detailed report about the task execution | |
| 54 | + | |
| 55 | +``(clobber = yes) [boolean]`` | |
| 56 | + Specifies whether an existing output counts cube should be overwritten. | |
| 57 | + | |
| 58 | +``(debug = no) [boolean]`` | |
| 59 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 60 | + | |
| 61 | +``(mode = ql) [string]`` | |
| 62 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 63 | + | |
| 64 | +``(logfile = cssens.log) [filename]`` | |
| 65 | + Log filename. | |
| 66 | + | |
| 67 | + | |
| 68 | +Related tools or scripts | |
| 69 | +------------------------ | |
| 70 | + | ... | ... |
doc/source/reference_manual/index.rst
| ... | ... | @@ -47,3 +47,5 @@ cscripts |
| 47 | 47 | cstsdist --- Generates TS distribution <cstsdist> |
| 48 | 48 | csobsinfo --- Shows detailled information about an observation container |
| 49 | 49 | csmodelinfo --- Shows detailled information about a model container |
| 50 | + csmodelmerge --- Merges several model containers into one file | |
| 51 | + cstsmapmerge --- Merges slices from ts map computations | ... | ... |
test/data/tsmap_0.fits
0 → 100644
No preview for this file type
test/data/tsmap_1.fits
0 → 100644
No preview for this file type
test/test_cscripts.sh.in
| ... | ... | @@ -117,7 +117,7 @@ $ECHO " ok" |
| 117 | 117 | # |
| 118 | 118 | # Test csmodelmerge (space-separated) |
| 119 | 119 | # ============== |
| 120 | -$ECHO -n "Test csmodelmerge: " | |
| 120 | +$ECHO -n "Test csmodelmerge (space-separated): " | |
| 121 | 121 | chmod +x @abs_top_srcdir@/cscripts/csmodelmerge.py |
| 122 | 122 | @abs_top_srcdir@/cscripts/csmodelmerge.py \ |
| 123 | 123 | inmodels="data/crab.xml data/source1.xml" \ |
| ... | ... | @@ -136,7 +136,7 @@ $ECHO " ok" |
| 136 | 136 | # |
| 137 | 137 | # Test csmodelmerge (comma-separated) |
| 138 | 138 | # ============== |
| 139 | -$ECHO -n "Test csmodelmerge: " | |
| 139 | +$ECHO -n "Test csmodelmerge (comma-separated): " | |
| 140 | 140 | chmod +x @abs_top_srcdir@/cscripts/csmodelmerge.py |
| 141 | 141 | @abs_top_srcdir@/cscripts/csmodelmerge.py \ |
| 142 | 142 | inmodels="data/crab.xml,data/source1.xml" \ |
| ... | ... | @@ -155,7 +155,7 @@ $ECHO " ok" |
| 155 | 155 | # |
| 156 | 156 | # Test csmodelmerge (wildcard string) |
| 157 | 157 | # ============== |
| 158 | -$ECHO -n "Test csmodelmerge: " | |
| 158 | +$ECHO -n "Test csmodelmerge (wildcard string): " | |
| 159 | 159 | chmod +x @abs_top_srcdir@/cscripts/csmodelmerge.py |
| 160 | 160 | @abs_top_srcdir@/cscripts/csmodelmerge.py \ |
| 161 | 161 | inmodels="data/model_cube_background*.xml" \ |
| ... | ... | @@ -175,7 +175,7 @@ $ECHO " ok" |
| 175 | 175 | # Test csmodelmerge (ascii-file) |
| 176 | 176 | # ============== |
| 177 | 177 | ls data/model_cube_background* > models.txt |
| 178 | -$ECHO -n "Test csmodelmerge: " | |
| 178 | +$ECHO -n "Test csmodelmerge (ascii-file): " | |
| 179 | 179 | chmod +x @abs_top_srcdir@/cscripts/csmodelmerge.py |
| 180 | 180 | @abs_top_srcdir@/cscripts/csmodelmerge.py \ |
| 181 | 181 | inmodels="@models.txt" \ |
| ... | ... | @@ -193,6 +193,84 @@ rm models.txt |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | # |
| 196 | +# Test cstsmapmerge (comma-separated) | |
| 197 | +# ============== | |
| 198 | +$ECHO -n "Test cstsmapmerge (comma-separated): " | |
| 199 | +chmod +x @abs_top_srcdir@/cscripts/cstsmapmerge.py | |
| 200 | +@abs_top_srcdir@/cscripts/cstsmapmerge.py \ | |
| 201 | + inmaps="data/tsmap_0.fits,data/tsmap_1.fits" \ | |
| 202 | + outmap="merged_tsmap1.fits" > cstsmapmerge.log | |
| 203 | +$ECHO -n "." | |
| 204 | +if [ -s "merged_tsmap1.fits" ] | |
| 205 | +then | |
| 206 | + $ECHO -n "." | |
| 207 | +else | |
| 208 | + $ECHO " merged_tsmap1.fits file is not valid" | |
| 209 | + exit 1 | |
| 210 | +fi | |
| 211 | +$ECHO " ok" | |
| 212 | + | |
| 213 | + | |
| 214 | +# | |
| 215 | +# Test cstsmapmerge (space-separated) | |
| 216 | +# ============== | |
| 217 | +$ECHO -n "Test cstsmapmerge (space-separated): " | |
| 218 | +chmod +x @abs_top_srcdir@/cscripts/cstsmapmerge.py | |
| 219 | +@abs_top_srcdir@/cscripts/cstsmapmerge.py \ | |
| 220 | + inmaps="data/tsmap_0.fits data/tsmap_1.fits" \ | |
| 221 | + outmap="merged_tsmap2.fits" > cstsmapmerge.log | |
| 222 | +$ECHO -n "." | |
| 223 | +if [ -s "merged_tsmap2.fits" ] | |
| 224 | +then | |
| 225 | + $ECHO -n "." | |
| 226 | +else | |
| 227 | + $ECHO " merged_tsmap2.fits file is not valid" | |
| 228 | + exit 1 | |
| 229 | +fi | |
| 230 | +$ECHO " ok" | |
| 231 | + | |
| 232 | + | |
| 233 | +# | |
| 234 | +# Test cstsmapmerge (wildcard string) | |
| 235 | +# ============== | |
| 236 | +$ECHO -n "Test cstsmapmerge (wildcard string): " | |
| 237 | +chmod +x @abs_top_srcdir@/cscripts/cstsmapmerge.py | |
| 238 | +@abs_top_srcdir@/cscripts/cstsmapmerge.py \ | |
| 239 | + inmaps="data/tsmap_*.fits" \ | |
| 240 | + outmap="merged_tsmap3.fits" > cstsmapmerge.log | |
| 241 | +$ECHO -n "." | |
| 242 | +if [ -s "merged_tsmap3.fits" ] | |
| 243 | +then | |
| 244 | + $ECHO -n "." | |
| 245 | +else | |
| 246 | + $ECHO " merged_tsmap3.fits file is not valid" | |
| 247 | + exit 1 | |
| 248 | +fi | |
| 249 | +$ECHO " ok" | |
| 250 | + | |
| 251 | + | |
| 252 | +# | |
| 253 | +# Test cstsmapmerge (ascii-file) | |
| 254 | +# ============== | |
| 255 | +ls data/tsmap_*.fits > tsmaps.txt | |
| 256 | +$ECHO -n "Test cstsmapmerge (ascii-file): " | |
| 257 | +chmod +x @abs_top_srcdir@/cscripts/cstsmapmerge.py | |
| 258 | +@abs_top_srcdir@/cscripts/cstsmapmerge.py \ | |
| 259 | + inmaps="@tsmaps.txt" \ | |
| 260 | + outmap="merged_tsmap4.fits" > cstsmapmerge.log | |
| 261 | +$ECHO -n "." | |
| 262 | +if [ -s "merged_tsmap4.fits" ] | |
| 263 | +then | |
| 264 | + $ECHO -n "." | |
| 265 | +else | |
| 266 | + $ECHO " merged_tsmap4.fits file is not valid" | |
| 267 | + exit 1 | |
| 268 | +fi | |
| 269 | +$ECHO " ok" | |
| 270 | +rm tsmaps.txt | |
| 271 | + | |
| 272 | + | |
| 273 | +# | |
| 196 | 274 | # Test cspull |
| 197 | 275 | # =========== |
| 198 | 276 | $ECHO -n "Test cspull: " | ... | ... |