Commit 51c7615b69d100f186d9f6fcbf5cbffa63776717
Try solving merge conflicts
Showing
8 changed files
with
212 additions
and
28 deletions
cscripts/cstsmapmerge.py
| @@ -46,7 +46,7 @@ class cstsmapmerge(ctools.cscript): | @@ -46,7 +46,7 @@ class cstsmapmerge(ctools.cscript): | ||
| 46 | self._files = None | 46 | self._files = None |
| 47 | self._in_filename = '' | 47 | self._in_filename = '' |
| 48 | self._tsmap = gammalib.GSkyMap() # Empty sky map | 48 | self._tsmap = gammalib.GSkyMap() # Empty sky map |
| 49 | - self._statusmap = gammalib.GSkyMap() # Empty sky map | 49 | + self._statusmap = gammalib.GSkyMap() # Empty sky map |
| 50 | self._maps = [] | 50 | self._maps = [] |
| 51 | self._mapnames = [] | 51 | self._mapnames = [] |
| 52 | self._merged_files = [] | 52 | self._merged_files = [] |
| @@ -118,7 +118,11 @@ class cstsmapmerge(ctools.cscript): | @@ -118,7 +118,11 @@ class cstsmapmerge(ctools.cscript): | ||
| 118 | if self._read_ahead(): | 118 | if self._read_ahead(): |
| 119 | self['outmap'].filename() | 119 | self['outmap'].filename() |
| 120 | 120 | ||
| 121 | +<<<<<<< HEAD | ||
| 121 | # Write input parameters into logger | 122 | # Write input parameters into logger |
| 123 | +======= | ||
| 124 | + # Write input parameters into logger | ||
| 125 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 122 | self._log_parameters(gammalib.TERSE) | 126 | self._log_parameters(gammalib.TERSE) |
| 123 | 127 | ||
| 124 | # Return | 128 | # Return |
| @@ -153,7 +157,11 @@ class cstsmapmerge(ctools.cscript): | @@ -153,7 +157,11 @@ class cstsmapmerge(ctools.cscript): | ||
| 153 | for hdu in fits: | 157 | for hdu in fits: |
| 154 | 158 | ||
| 155 | # Leave out primary and status extension | 159 | # Leave out primary and status extension |
| 160 | +<<<<<<< HEAD | ||
| 156 | if hdu.extname() != 'IMAGE' and hdu.extname() != 'STATUS MAP': | 161 | if hdu.extname() != 'IMAGE' and hdu.extname() != 'STATUS MAP': |
| 162 | +======= | ||
| 163 | + if hdu.extname() != "IMAGE" and hdu.extname() != 'STATUS MAP': | ||
| 164 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 157 | 165 | ||
| 158 | # Add present maps | 166 | # Add present maps |
| 159 | skymap = gammalib.GSkyMap() | 167 | skymap = gammalib.GSkyMap() |
| @@ -192,7 +200,11 @@ class cstsmapmerge(ctools.cscript): | @@ -192,7 +200,11 @@ class cstsmapmerge(ctools.cscript): | ||
| 192 | for hdu in fits: | 200 | for hdu in fits: |
| 193 | 201 | ||
| 194 | # Leave out primary and status extension | 202 | # Leave out primary and status extension |
| 203 | +<<<<<<< HEAD | ||
| 195 | if hdu.extname() != 'IMAGE' and hdu.extname() != 'STATUS MAP': | 204 | if hdu.extname() != 'IMAGE' and hdu.extname() != 'STATUS MAP': |
| 205 | +======= | ||
| 206 | + if hdu.extname() != "IMAGE" and hdu.extname() != 'STATUS MAP': | ||
| 207 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 196 | 208 | ||
| 197 | # Add present maps | 209 | # Add present maps |
| 198 | skymap = gammalib.GSkyMap() | 210 | skymap = gammalib.GSkyMap() |
| @@ -213,14 +225,22 @@ class cstsmapmerge(ctools.cscript): | @@ -213,14 +225,22 @@ class cstsmapmerge(ctools.cscript): | ||
| 213 | for i in range(self._tsmap.npix()): | 225 | for i in range(self._tsmap.npix()): |
| 214 | 226 | ||
| 215 | # Consider only bins that have been computed | 227 | # Consider only bins that have been computed |
| 216 | - if add_statusmap[i] > 0.5: | 228 | + if add_statusmap[i] > -0.5: |
| 217 | 229 | ||
| 218 | # Raise exception if this bin has already been computed | 230 | # Raise exception if this bin has already been computed |
| 231 | +<<<<<<< HEAD | ||
| 219 | if self._statusmap[i] > 0.5 and not self._overwrite: | 232 | if self._statusmap[i] > 0.5 and not self._overwrite: |
| 220 | msg = ('Attempt to merge bin which apparently has already ' | 233 | msg = ('Attempt to merge bin which apparently has already ' |
| 221 | 'been merged. File "%s" contains already merged ' | 234 | 'been merged. File "%s" contains already merged ' |
| 222 | 'bins. Set hidden parameter "overwrite=yes" to ' | 235 | 'bins. Set hidden parameter "overwrite=yes" to ' |
| 223 | 'avoid this error.' % fitsfile) | 236 | 'avoid this error.' % fitsfile) |
| 237 | +======= | ||
| 238 | + if self._statusmap[i] > -0.5 and not self._overwrite: | ||
| 239 | + msg = "Attempt to merge bin which apparently has "+\ | ||
| 240 | + "already been merged. File \""+fitsfile+"\" "+\ | ||
| 241 | + "contains already merged bins. Set hidden "+\ | ||
| 242 | + "parameter \"overwrite=yes\" to avoid this error." | ||
| 243 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 224 | raise RuntimeError(msg) | 244 | raise RuntimeError(msg) |
| 225 | 245 | ||
| 226 | # Copy TS values | 246 | # Copy TS values |
| @@ -256,7 +276,7 @@ class cstsmapmerge(ctools.cscript): | @@ -256,7 +276,7 @@ class cstsmapmerge(ctools.cscript): | ||
| 256 | # Count number of pixels with TS status set | 276 | # Count number of pixels with TS status set |
| 257 | count = 0 | 277 | count = 0 |
| 258 | for pix in status: | 278 | for pix in status: |
| 259 | - if pix > 0.5: | 279 | + if pix > -0.5: |
| 260 | count += 1 | 280 | count += 1 |
| 261 | 281 | ||
| 262 | # Return number of pixels | 282 | # Return number of pixels |
| @@ -290,8 +310,16 @@ class cstsmapmerge(ctools.cscript): | @@ -290,8 +310,16 @@ class cstsmapmerge(ctools.cscript): | ||
| 290 | 310 | ||
| 291 | # Skip file if it's not a FITS file | 311 | # Skip file if it's not a FITS file |
| 292 | if not gammalib.GFilename(fitsfile).is_fits(): | 312 | if not gammalib.GFilename(fitsfile).is_fits(): |
| 313 | +<<<<<<< HEAD | ||
| 293 | self._log_value(gammalib.EXPLICIT, 'Skip file', | 314 | self._log_value(gammalib.EXPLICIT, 'Skip file', |
| 294 | '%s (not a FITS file)' % fitsfile) | 315 | '%s (not a FITS file)' % fitsfile) |
| 316 | +======= | ||
| 317 | + | ||
| 318 | + # Log message | ||
| 319 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (not a FITS file)") | ||
| 320 | + | ||
| 321 | + # Continue | ||
| 322 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 295 | continue | 323 | continue |
| 296 | 324 | ||
| 297 | # Open FITS file | 325 | # Open FITS file |
| @@ -299,18 +327,35 @@ class cstsmapmerge(ctools.cscript): | @@ -299,18 +327,35 @@ class cstsmapmerge(ctools.cscript): | ||
| 299 | 327 | ||
| 300 | # If file contains a status map then use it | 328 | # If file contains a status map then use it |
| 301 | if fits.contains('STATUS MAP'): | 329 | if fits.contains('STATUS MAP'): |
| 330 | +<<<<<<< HEAD | ||
| 331 | +======= | ||
| 332 | + | ||
| 333 | + # Close FITS file | ||
| 334 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 302 | fits.close() | 335 | fits.close() |
| 336 | + | ||
| 337 | + # Set filename to initial filename | ||
| 303 | file0 = fitsfile | 338 | file0 = fitsfile |
| 339 | +<<<<<<< HEAD | ||
| 304 | if self._logTerse(): | 340 | if self._logTerse(): |
| 305 | self._log(gammalib.parformat('Initial TS map file')) | 341 | self._log(gammalib.parformat('Initial TS map file')) |
| 306 | self._log(fitsfile) | 342 | self._log(fitsfile) |
| 307 | count = self._get_number_of_ts_pixels(fitsfile) | 343 | count = self._get_number_of_ts_pixels(fitsfile) |
| 308 | self._log(' (%d TS pixels computed)' % count) | 344 | self._log(' (%d TS pixels computed)' % count) |
| 309 | self._log('\n') | 345 | self._log('\n') |
| 346 | +======= | ||
| 347 | + | ||
| 348 | + # Log message | ||
| 349 | + pix_info = " (%d TS pixels computed)" % self._get_number_of_ts_pixels(fitsfile) | ||
| 350 | + self._log_value(gammalib.TERSE, "Initial TS map file", fitsfile + pix_info) | ||
| 351 | + | ||
| 352 | + # Leave loop | ||
| 353 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 310 | break | 354 | break |
| 311 | 355 | ||
| 312 | # ... otherwise signal that file is useless | 356 | # ... otherwise signal that file is useless |
| 313 | else: | 357 | else: |
| 358 | +<<<<<<< HEAD | ||
| 314 | fits.close() | 359 | fits.close() |
| 315 | self._log_value(gammalib.EXPLICIT, 'Skip file', | 360 | self._log_value(gammalib.EXPLICIT, 'Skip file', |
| 316 | '%s (no "STATUS MAP" extension)' % fitsfile) | 361 | '%s (no "STATUS MAP" extension)' % fitsfile) |
| @@ -322,6 +367,24 @@ class cstsmapmerge(ctools.cscript): | @@ -322,6 +367,24 @@ class cstsmapmerge(ctools.cscript): | ||
| 322 | self._log('None of the provided files seems to be a sliced ' | 367 | self._log('None of the provided files seems to be a sliced ' |
| 323 | 'TS map file (none has a "STATUS MAP" extension).\n') | 368 | 'TS map file (none has a "STATUS MAP" extension).\n') |
| 324 | 369 | ||
| 370 | +======= | ||
| 371 | + | ||
| 372 | + # Close fits file | ||
| 373 | + fits.close() | ||
| 374 | + | ||
| 375 | + # Info message | ||
| 376 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (no \"STATUS MAP\" extension)") | ||
| 377 | + | ||
| 378 | + # Continue | ||
| 379 | + continue | ||
| 380 | + | ||
| 381 | + # Signal if no suitable file was found | ||
| 382 | + if file0 == "": | ||
| 383 | + self._log_string(gammalib.TERSE, "None of the provided files seems to be a sliced " | ||
| 384 | + "TS map file (none has a \"STATUS MAP\" " | ||
| 385 | + "extension).\n") | ||
| 386 | + | ||
| 387 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 325 | # ... otherwise merge files | 388 | # ... otherwise merge files |
| 326 | else: | 389 | else: |
| 327 | 390 | ||
| @@ -342,9 +405,14 @@ class cstsmapmerge(ctools.cscript): | @@ -342,9 +405,14 @@ class cstsmapmerge(ctools.cscript): | ||
| 342 | 405 | ||
| 343 | # Skip if file is not FITS | 406 | # Skip if file is not FITS |
| 344 | if not gammalib.GFilename(fitsfile).is_fits(): | 407 | if not gammalib.GFilename(fitsfile).is_fits(): |
| 408 | +<<<<<<< HEAD | ||
| 345 | self._log_value(gammalib.EXPLICIT, 'Skip file', | 409 | self._log_value(gammalib.EXPLICIT, 'Skip file', |
| 346 | '%s (not a FITS file)' % fitsfile) | 410 | '%s (not a FITS file)' % fitsfile) |
| 347 | continue | 411 | continue |
| 412 | +======= | ||
| 413 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (not a FITS file)") | ||
| 414 | + continue | ||
| 415 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 348 | 416 | ||
| 349 | # Open FITS file | 417 | # Open FITS file |
| 350 | fits = gammalib.GFits(fitsfile) | 418 | fits = gammalib.GFits(fitsfile) |
| @@ -352,20 +420,29 @@ class cstsmapmerge(ctools.cscript): | @@ -352,20 +420,29 @@ class cstsmapmerge(ctools.cscript): | ||
| 352 | # Skip if file does not contain status map | 420 | # Skip if file does not contain status map |
| 353 | if not fits.contains('STATUS MAP'): | 421 | if not fits.contains('STATUS MAP'): |
| 354 | fits.close() | 422 | fits.close() |
| 423 | +<<<<<<< HEAD | ||
| 355 | self._log_value(gammalib.EXPLICIT, 'Skip file', | 424 | self._log_value(gammalib.EXPLICIT, 'Skip file', |
| 356 | '%s (no "STATUS MAP" extension)' % fitsfile) | 425 | '%s (no "STATUS MAP" extension)' % fitsfile) |
| 426 | +======= | ||
| 427 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (no \"STATUS MAP\" extension)") | ||
| 428 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 357 | continue | 429 | continue |
| 358 | 430 | ||
| 359 | # Close FITS file | 431 | # Close FITS file |
| 360 | fits.close() | 432 | fits.close() |
| 361 | 433 | ||
| 362 | # Logging | 434 | # Logging |
| 435 | +<<<<<<< HEAD | ||
| 363 | if self._logTerse(): | 436 | if self._logTerse(): |
| 364 | self._log(gammalib.parformat('Merge TS map file')) | 437 | self._log(gammalib.parformat('Merge TS map file')) |
| 365 | self._log(fitsfile) | 438 | self._log(fitsfile) |
| 366 | count = self._get_number_of_ts_pixels(fitsfile) | 439 | count = self._get_number_of_ts_pixels(fitsfile) |
| 367 | self._log(' (%d TS pixels computed)' % count) | 440 | self._log(' (%d TS pixels computed)' % count) |
| 368 | self._log('\n') | 441 | self._log('\n') |
| 442 | +======= | ||
| 443 | + pix_info = " (%d TS pixels computed)" % self._get_number_of_ts_pixels(fitsfile) | ||
| 444 | + self._log_value(gammalib.TERSE, "Merge TS map file", fitsfile + pix_info) | ||
| 445 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 369 | 446 | ||
| 370 | # Merge TS map | 447 | # Merge TS map |
| 371 | self._merge_ts_map(fitsfile) | 448 | self._merge_ts_map(fitsfile) |
| @@ -380,6 +457,7 @@ class cstsmapmerge(ctools.cscript): | @@ -380,6 +457,7 @@ class cstsmapmerge(ctools.cscript): | ||
| 380 | """ | 457 | """ |
| 381 | Save TS map and remove slices if requested | 458 | Save TS map and remove slices if requested |
| 382 | """ | 459 | """ |
| 460 | +<<<<<<< HEAD | ||
| 383 | # Write header | 461 | # Write header |
| 384 | self._log_header1(gammalib.TERSE, 'Save TS map') | 462 | self._log_header1(gammalib.TERSE, 'Save TS map') |
| 385 | 463 | ||
| @@ -388,6 +466,11 @@ class cstsmapmerge(ctools.cscript): | @@ -388,6 +466,11 @@ class cstsmapmerge(ctools.cscript): | ||
| 388 | 466 | ||
| 389 | # Log filename | 467 | # Log filename |
| 390 | self._log_value(gammalib.TERSE, 'TS map file', outmap.url()) | 468 | self._log_value(gammalib.TERSE, 'TS map file', outmap.url()) |
| 469 | +======= | ||
| 470 | + | ||
| 471 | + # Get output filename in case it was not read ahead | ||
| 472 | + outmap = self["outmap"].filename() | ||
| 473 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 391 | 474 | ||
| 392 | # Create FITS file | 475 | # Create FITS file |
| 393 | fits = gammalib.GFits() | 476 | fits = gammalib.GFits() |
| @@ -403,26 +486,67 @@ class cstsmapmerge(ctools.cscript): | @@ -403,26 +486,67 @@ class cstsmapmerge(ctools.cscript): | ||
| 403 | for i in range(len(self._mapnames)): | 486 | for i in range(len(self._mapnames)): |
| 404 | fits[i+1].extname(self._mapnames[i]) | 487 | fits[i+1].extname(self._mapnames[i]) |
| 405 | 488 | ||
| 489 | + # Treat status map separately | ||
| 490 | + self._statusmap.write(fits) | ||
| 491 | + fits[fits.size()-1].extname('STATUS MAP') | ||
| 492 | + | ||
| 406 | # Check if map is fully done | 493 | # Check if map is fully done |
| 407 | - done = True | 494 | + bins_merged = 0 |
| 408 | for pix in self._statusmap: | 495 | for pix in self._statusmap: |
| 409 | - if pix < 0.5: | ||
| 410 | - done = False | ||
| 411 | - break | 496 | + if pix > -0.5: |
| 497 | + bins_merged += 1 | ||
| 498 | + | ||
| 499 | + # Set boolean if map is fully done | ||
| 500 | + done = (bins_merged == self._tsmaps.npix()) | ||
| 412 | 501 | ||
| 502 | + # Log summary header | ||
| 503 | + self._log_header2(gammalib.TERSE, "Merging Summary") | ||
| 504 | + | ||
| 413 | # Write status map if we are not done yet | 505 | # Write status map if we are not done yet |
| 414 | if not done: | 506 | if not done: |
| 507 | +<<<<<<< HEAD | ||
| 415 | self._statusmap.write(fits) | 508 | self._statusmap.write(fits) |
| 416 | fits[fits.size()-1].extname('STATUS MAP') | 509 | fits[fits.size()-1].extname('STATUS MAP') |
| 510 | +======= | ||
| 511 | + | ||
| 512 | + # Log bins that were computed and those that were missing | ||
| 513 | + self._log_value(gammalib.TERSE, "TS map bins", self._tsmap.npix()) | ||
| 514 | + self._log_value(gammalib.TERSE, "Bins computed and merged", bins_merged ) | ||
| 515 | + self._log_value(gammalib.TERSE, "Bins missing", self._tsmap.npix() - bins_merged) | ||
| 516 | + | ||
| 517 | + else: | ||
| 518 | + | ||
| 519 | + # Write success message | ||
| 520 | + self._log_string(gammalib.TERSE, "TS map was fully computed and successfully merged") | ||
| 521 | + | ||
| 522 | + # Write header | ||
| 523 | + self._log_header1(gammalib.TERSE, "Save TS map") | ||
| 524 | + | ||
| 525 | + # Log filename | ||
| 526 | + self._log_value(gammalib.TERSE, "TS map file", outmap.url()) | ||
| 527 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 417 | 528 | ||
| 418 | # Save FITS file | 529 | # Save FITS file |
| 419 | - fits.saveto(outmap, self._clobber()) | 530 | + fits.saveto(outmap, self._clobber()) |
| 420 | 531 | ||
| 421 | - # Delete TS input maps if requested | ||
| 422 | - if self._delete: | 532 | + # Delete TS input maps if requested and map is fully done |
| 533 | + if self._delete and done: | ||
| 534 | + | ||
| 535 | + # Log header | ||
| 536 | + self._log_header2(gammalib.TERSE, "Delete slices TS map files") | ||
| 537 | + | ||
| 538 | + # Loop over sliced files | ||
| 423 | for filename in self._merged_files: | 539 | for filename in self._merged_files: |
| 540 | + | ||
| 541 | + # Remove file | ||
| 424 | os.remove(filename) | 542 | os.remove(filename) |
| 543 | +<<<<<<< HEAD | ||
| 425 | self._log_value(gammalib.TERSE, 'Deleted input file', filename) | 544 | self._log_value(gammalib.TERSE, 'Deleted input file', filename) |
| 545 | +======= | ||
| 546 | + | ||
| 547 | + # Log message about file | ||
| 548 | + self._log_value(gammalib.TERSE,"Deleted input file", filename) | ||
| 549 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 426 | 550 | ||
| 427 | # Return | 551 | # Return |
| 428 | return | 552 | return |
cscripts/cstsmapsplit.par
| @@ -27,6 +27,7 @@ bkgcube, f, a, NONE,,, "Input background cube file (only needed for stacke | @@ -27,6 +27,7 @@ bkgcube, f, a, NONE,,, "Input background cube file (only needed for stacke | ||
| 27 | caldb, s, a, prod2,,, "Calibration database" | 27 | caldb, s, a, prod2,,, "Calibration database" |
| 28 | irf, s, a, South_0.5h,,, "Instrument response function" | 28 | irf, s, a, South_0.5h,,, "Instrument response function" |
| 29 | edisp, b, h, no,,, "Apply energy dispersion?" | 29 | edisp, b, h, no,,, "Apply energy dispersion?" |
| 30 | +errors, b, h, no,,, "Compute/store parameter errors?" | ||
| 30 | outmap, f, a, tsmap.fits,,, "Output Test Statistic map file" | 31 | outmap, f, a, tsmap.fits,,, "Output Test Statistic map file" |
| 31 | bins_per_job, i, a, 5,,, "Number of TS map bins per task" | 32 | bins_per_job, i, a, 5,,, "Number of TS map bins per task" |
| 32 | compute_null, b, a, yes,,,"Compute null hypothesis first?" | 33 | compute_null, b, a, yes,,,"Compute null hypothesis first?" |
src/cttsmap/cttsmap.cpp
| @@ -215,6 +215,12 @@ void cttsmap::run(void) | @@ -215,6 +215,12 @@ void cttsmap::run(void) | ||
| 215 | // Get task parameters | 215 | // Get task parameters |
| 216 | get_parameters(); | 216 | get_parameters(); |
| 217 | 217 | ||
| 218 | +<<<<<<< HEAD | ||
| 219 | +======= | ||
| 220 | + // Write parameters into logger | ||
| 221 | + log_parameters(TERSE); | ||
| 222 | + | ||
| 223 | +>>>>>>> b7dd76b35e6d2fd74ff010258ffa7606e072dbf5 | ||
| 218 | // Set energy dispersion flag for all CTA observations and save old | 224 | // Set energy dispersion flag for all CTA observations and save old |
| 219 | // values in save_edisp vector | 225 | // values in save_edisp vector |
| 220 | std::vector<bool> save_edisp; | 226 | std::vector<bool> save_edisp; |
| @@ -315,6 +321,14 @@ void cttsmap::run(void) | @@ -315,6 +321,14 @@ void cttsmap::run(void) | ||
| 315 | // Optimize observation container | 321 | // Optimize observation container |
| 316 | m_obs.optimize(*opt); | 322 | m_obs.optimize(*opt); |
| 317 | 323 | ||
| 324 | + // Compute errors if necessary | ||
| 325 | + if (m_errors) { | ||
| 326 | + m_obs.errors(*opt); | ||
| 327 | + } | ||
| 328 | + | ||
| 329 | + // Get status of optimization | ||
| 330 | + int status = opt->status(); | ||
| 331 | + | ||
| 318 | // Retrieve the Likelihood value | 332 | // Retrieve the Likelihood value |
| 319 | double logL1 = -(opt->value()); | 333 | double logL1 = -(opt->value()); |
| 320 | 334 | ||
| @@ -326,6 +340,7 @@ void cttsmap::run(void) | @@ -326,6 +340,7 @@ void cttsmap::run(void) | ||
| 326 | log << " TS value ....: "; | 340 | log << " TS value ....: "; |
| 327 | log << ts << std::endl; | 341 | log << ts << std::endl; |
| 328 | } | 342 | } |
| 343 | + | ||
| 329 | else if (logTerse()) { | 344 | else if (logTerse()) { |
| 330 | log << "TS for bin number "; | 345 | log << "TS for bin number "; |
| 331 | log << i; | 346 | log << i; |
| @@ -345,12 +360,23 @@ void cttsmap::run(void) | @@ -345,12 +360,23 @@ void cttsmap::run(void) | ||
| 345 | // Extract fitted test source parameters | 360 | // Extract fitted test source parameters |
| 346 | if (m_testsource != NULL) { | 361 | if (m_testsource != NULL) { |
| 347 | for (int j = 0; j < m_mapnames.size(); ++j) { | 362 | for (int j = 0; j < m_mapnames.size(); ++j) { |
| 348 | - m_maps[j](i) = (*testsource)[m_mapnames[j]].value(); | 363 | + |
| 364 | + // Set parameter value and error maps | ||
| 365 | + if (m_mapnames[j].substr(0,2) == "e_") { | ||
| 366 | + | ||
| 367 | + // Get Parameter name by removing the error prefix | ||
| 368 | + std::string parname = m_mapnames[j].substr(2, m_mapnames[j].size()); | ||
| 369 | + m_maps[j](i) = (*testsource)[parname].error(); | ||
| 370 | + | ||
| 371 | + } | ||
| 372 | + else { | ||
| 373 | + m_maps[j](i) = (*testsource)[m_mapnames[j]].value(); | ||
| 374 | + } | ||
| 349 | } | 375 | } |
| 350 | } | 376 | } |
| 351 | 377 | ||
| 352 | - // Set status of bin to true | ||
| 353 | - m_statusmap(i) = 1.0; | 378 | + // Set Fit status of the bin |
| 379 | + m_statusmap(i) = status; | ||
| 354 | 380 | ||
| 355 | // Remove model from container | 381 | // Remove model from container |
| 356 | models.remove(m_srcname); | 382 | models.remove(m_srcname); |
| @@ -417,11 +443,9 @@ void cttsmap::save(void) | @@ -417,11 +443,9 @@ void cttsmap::save(void) | ||
| 417 | fits[i+1]->extname(m_mapnames[i]); | 443 | fits[i+1]->extname(m_mapnames[i]); |
| 418 | } | 444 | } |
| 419 | 445 | ||
| 420 | - // Add computation log if not all bins are computed | ||
| 421 | - if (m_binmin != -1 || m_binmax != -1) { | ||
| 422 | - m_statusmap.write(fits); | ||
| 423 | - fits[m_mapnames.size()+1]->extname("STATUS MAP"); | ||
| 424 | - } | 446 | + // Write Fit status map |
| 447 | + m_statusmap.write(fits); | ||
| 448 | + fits[fits.size()-1]->extname("FITSTATUS"); | ||
| 425 | 449 | ||
| 426 | // Save FITS file | 450 | // Save FITS file |
| 427 | fits.saveto(m_outmap, clobber()); | 451 | fits.saveto(m_outmap, clobber()); |
| @@ -482,6 +506,7 @@ void cttsmap::init_members(void) | @@ -482,6 +506,7 @@ void cttsmap::init_members(void) | ||
| 482 | m_outmap.clear(); | 506 | m_outmap.clear(); |
| 483 | m_apply_edisp = false; | 507 | m_apply_edisp = false; |
| 484 | m_publish = false; | 508 | m_publish = false; |
| 509 | + m_errors = false; | ||
| 485 | 510 | ||
| 486 | // Initialise protected members | 511 | // Initialise protected members |
| 487 | m_obs.clear(); | 512 | m_obs.clear(); |
| @@ -511,16 +536,17 @@ void cttsmap::copy_members(const cttsmap& app) | @@ -511,16 +536,17 @@ void cttsmap::copy_members(const cttsmap& app) | ||
| 511 | m_outmap = app.m_outmap; | 536 | m_outmap = app.m_outmap; |
| 512 | m_apply_edisp = app.m_apply_edisp; | 537 | m_apply_edisp = app.m_apply_edisp; |
| 513 | m_publish = app.m_publish; | 538 | m_publish = app.m_publish; |
| 539 | + m_errors = app.m_errors; | ||
| 514 | 540 | ||
| 515 | // Copy protected members | 541 | // Copy protected members |
| 516 | - m_binmin = app.m_binmin; | ||
| 517 | - m_binmax = app.m_binmax; | ||
| 518 | - m_logL0 = app.m_logL0; | ||
| 519 | - m_obs = app.m_obs; | ||
| 520 | - m_tsmap = app.m_tsmap; | ||
| 521 | - m_mapnames = app.m_mapnames; | ||
| 522 | - m_maps = app.m_maps; | ||
| 523 | - m_statusmap = app.m_statusmap; | 542 | + m_binmin = app.m_binmin; |
| 543 | + m_binmax = app.m_binmax; | ||
| 544 | + m_logL0 = app.m_logL0; | ||
| 545 | + m_obs = app.m_obs; | ||
| 546 | + m_tsmap = app.m_tsmap; | ||
| 547 | + m_mapnames = app.m_mapnames; | ||
| 548 | + m_maps = app.m_maps; | ||
| 549 | + m_statusmap = app.m_statusmap; | ||
| 524 | 550 | ||
| 525 | // Clone protected members | 551 | // Clone protected members |
| 526 | m_testsource = (app.m_testsource != NULL) ? app.m_testsource->clone() : NULL; | 552 | m_testsource = (app.m_testsource != NULL) ? app.m_testsource->clone() : NULL; |
| @@ -612,6 +638,9 @@ void cttsmap::get_parameters(void) | @@ -612,6 +638,9 @@ void cttsmap::get_parameters(void) | ||
| 612 | // Create sky map based on task parameters | 638 | // Create sky map based on task parameters |
| 613 | GSkyMap map = create_map(m_obs); | 639 | GSkyMap map = create_map(m_obs); |
| 614 | 640 | ||
| 641 | + // Check if errors should be computed | ||
| 642 | + m_errors = (*this)["errors"].boolean(); | ||
| 643 | + | ||
| 615 | // Initialise maps from user parameters | 644 | // Initialise maps from user parameters |
| 616 | init_maps(map); | 645 | init_maps(map); |
| 617 | 646 | ||
| @@ -654,9 +683,13 @@ void cttsmap::init_maps(const GSkyMap& map) | @@ -654,9 +683,13 @@ void cttsmap::init_maps(const GSkyMap& map) | ||
| 654 | // Initialise map information | 683 | // Initialise map information |
| 655 | m_statusmap.clear(); | 684 | m_statusmap.clear(); |
| 656 | 685 | ||
| 657 | - // Create status map | 686 | + // Create status map and progress map |
| 658 | m_statusmap = GSkyMap(map); | 687 | m_statusmap = GSkyMap(map); |
| 659 | 688 | ||
| 689 | + // Set status map to invalid value -1 to signal | ||
| 690 | + // that bin wasn't computed yet | ||
| 691 | + m_statusmap = -1.0; | ||
| 692 | + | ||
| 660 | // Initialise maps of free parameters | 693 | // Initialise maps of free parameters |
| 661 | if (m_testsource != NULL) { | 694 | if (m_testsource != NULL) { |
| 662 | 695 | ||
| @@ -674,6 +707,16 @@ void cttsmap::init_maps(const GSkyMap& map) | @@ -674,6 +707,16 @@ void cttsmap::init_maps(const GSkyMap& map) | ||
| 674 | 707 | ||
| 675 | // Store parameter name | 708 | // Store parameter name |
| 676 | m_mapnames.push_back((*m_testsource)[i].name()); | 709 | m_mapnames.push_back((*m_testsource)[i].name()); |
| 710 | + | ||
| 711 | + // Add parameter errors if requested | ||
| 712 | + if (m_errors) { | ||
| 713 | + | ||
| 714 | + // Add sky map for fit error of the free parameter | ||
| 715 | + m_maps.push_back(map); | ||
| 716 | + | ||
| 717 | + // Store name of parameter error | ||
| 718 | + m_mapnames.push_back("e_" + (*m_testsource)[i].name()); | ||
| 719 | + } | ||
| 677 | 720 | ||
| 678 | } // endfor: looped over all model parameters | 721 | } // endfor: looped over all model parameters |
| 679 | 722 |
src/cttsmap/cttsmap.hpp
| @@ -89,6 +89,7 @@ protected: | @@ -89,6 +89,7 @@ protected: | ||
| 89 | GFilename m_outmap; //!< Output TS map file name | 89 | GFilename m_outmap; //!< Output TS map file name |
| 90 | bool m_apply_edisp; //!< Apply energy dispersion? | 90 | bool m_apply_edisp; //!< Apply energy dispersion? |
| 91 | bool m_publish; //!< Publish TS map? | 91 | bool m_publish; //!< Publish TS map? |
| 92 | + bool m_errors; //!< Compute and store parameter errors? | ||
| 92 | 93 | ||
| 93 | // Parameters to control speed and job splitting | 94 | // Parameters to control speed and job splitting |
| 94 | int m_binmin; //!< Map bin number from which computation should start | 95 | int m_binmin; //!< Map bin number from which computation should start |
| @@ -98,7 +99,7 @@ protected: | @@ -98,7 +99,7 @@ protected: | ||
| 98 | // Protected members | 99 | // Protected members |
| 99 | GObservations m_obs; //!< Observation container | 100 | GObservations m_obs; //!< Observation container |
| 100 | GSkyMap m_tsmap; //!< TS map | 101 | GSkyMap m_tsmap; //!< TS map |
| 101 | - GSkyMap m_statusmap; //!< Map of computed bins | 102 | + GSkyMap m_statusmap; //!< Map of optimizer fit status |
| 102 | std::vector<std::string> m_mapnames; //!< Names of free parameters | 103 | std::vector<std::string> m_mapnames; //!< Names of free parameters |
| 103 | std::vector<GSkyMap> m_maps; //!< Sky maps for each free parameter | 104 | std::vector<GSkyMap> m_maps; //!< Sky maps for each free parameter |
| 104 | GModel* m_testsource; //!< Pointer to test source for TS computation | 105 | GModel* m_testsource; //!< Pointer to test source for TS computation |
src/cttsmap/cttsmap.par
| @@ -27,6 +27,7 @@ bkgcube, f, a, "NONE",,, "Input background cube file (only needed for stacked | @@ -27,6 +27,7 @@ bkgcube, f, a, "NONE",,, "Input background cube file (only needed for stacked | ||
| 27 | caldb, s, a, "prod2",,, "Calibration database" | 27 | caldb, s, a, "prod2",,, "Calibration database" |
| 28 | irf, s, a, "South_0.5h",,, "Instrument response function" | 28 | irf, s, a, "South_0.5h",,, "Instrument response function" |
| 29 | edisp, b, h, no,,, "Apply energy dispersion?" | 29 | edisp, b, h, no,,, "Apply energy dispersion?" |
| 30 | +errors, b, h, no,,, "Compute/store parameter errors?" | ||
| 30 | outmap, f, a, "tsmap.fits",,, "Output Test Statistic map file" | 31 | outmap, f, a, "tsmap.fits",,, "Output Test Statistic map file" |
| 31 | 32 | ||
| 32 | # | 33 | # |
test/data/tsmap_0.fits
No preview for this file type
test/data/tsmap_1.fits
No preview for this file type
test/test_cttsmap.py
| @@ -96,6 +96,20 @@ class Test(test): | @@ -96,6 +96,20 @@ class Test(test): | ||
| 96 | # Check if execution failed | 96 | # Check if execution failed |
| 97 | self.test_assert(self._execute(cmd) != 0, | 97 | self.test_assert(self._execute(cmd) != 0, |
| 98 | 'Check invalid input file when executed from command line') | 98 | 'Check invalid input file when executed from command line') |
| 99 | + | ||
| 100 | + # Setup cttsmap command | ||
| 101 | + cmd = cttsmap+' inobs="'+self._events+'"'+ \ | ||
| 102 | + ' inmodel="'+self._model+'" srcname="Crab"'+ \ | ||
| 103 | + ' caldb="'+self._caldb+'" irf="'+self._irf+'"'+ \ | ||
| 104 | + ' errors=yes'+ \ | ||
| 105 | + ' outmap="cttsmap_cmd1.fits"'+ \ | ||
| 106 | + ' nxpix=5 nypix=5 binsz=0.02'+ \ | ||
| 107 | + ' coordsys="CEL" proj="CAR" xref=83.63 yref=22.01'+ \ | ||
| 108 | + ' logfile="cttsmap_cmd1.log" chatter=1' | ||
| 109 | + | ||
| 110 | + # Check if execution was successful | ||
| 111 | + self.test_assert(self._execute(cmd) == 0, | ||
| 112 | + 'Check successful execution from command line') | ||
| 99 | 113 | ||
| 100 | # Return | 114 | # Return |
| 101 | return | 115 | return |