Commit b7dd76b35e6d2fd74ff010258ffa7606e072dbf5
1 parent
371a3061
Removed PROGRESS MAP, use STATUS MAP to indicate fit status and progress of computations
Showing
3 changed files
with
106 additions
and
105 deletions
cscripts/cstsmapmerge.py
| ... | ... | @@ -46,7 +46,7 @@ class cstsmapmerge(ctools.cscript): |
| 46 | 46 | self._files = None |
| 47 | 47 | self._in_filename = '' |
| 48 | 48 | self._tsmap = gammalib.GSkyMap() # Empty sky map |
| 49 | - self._progressmap = gammalib.GSkyMap() # Empty sky map | |
| 49 | + self._statusmap = gammalib.GSkyMap() # Empty sky map | |
| 50 | 50 | self._maps = [] |
| 51 | 51 | self._mapnames = [] |
| 52 | 52 | self._merged_files = [] |
| ... | ... | @@ -119,9 +119,7 @@ class cstsmapmerge(ctools.cscript): |
| 119 | 119 | self['outmap'].filename() |
| 120 | 120 | |
| 121 | 121 | # Write input parameters into logger |
| 122 | - if self._logTerse(): | |
| 123 | - self._log_parameters() | |
| 124 | - self._log('\n') | |
| 122 | + self._log_parameters(gammalib.TERSE) | |
| 125 | 123 | |
| 126 | 124 | # Return |
| 127 | 125 | return |
| ... | ... | @@ -136,11 +134,11 @@ class cstsmapmerge(ctools.cscript): |
| 136 | 134 | # Open FITS file |
| 137 | 135 | fits = gammalib.GFits(fitsfile) |
| 138 | 136 | |
| 139 | - # Read TS and progress maps | |
| 137 | + # Read TS and status maps | |
| 140 | 138 | self._tsmap = gammalib.GSkyMap() |
| 141 | 139 | self._tsmap.read(fits[0]) |
| 142 | - self._progressmap = gammalib.GSkyMap() | |
| 143 | - self._progressmap.read(fits["PROGRESS MAP"]) | |
| 140 | + self._statusmap = gammalib.GSkyMap() | |
| 141 | + self._statusmap.read(fits['STATUS MAP']) | |
| 144 | 142 | |
| 145 | 143 | # Get other maps |
| 146 | 144 | self._maps = [] |
| ... | ... | @@ -149,8 +147,8 @@ class cstsmapmerge(ctools.cscript): |
| 149 | 147 | # Loop over extensions |
| 150 | 148 | for hdu in fits: |
| 151 | 149 | |
| 152 | - # Leave out primary and progress extension | |
| 153 | - if hdu.extname() != "IMAGE" and hdu.extname() != "PROGRESS MAP": | |
| 150 | + # Leave out primary and status extension | |
| 151 | + if hdu.extname() != "IMAGE" and hdu.extname() != 'STATUS MAP': | |
| 154 | 152 | |
| 155 | 153 | # Add present maps |
| 156 | 154 | skymap = gammalib.GSkyMap() |
| ... | ... | @@ -174,11 +172,11 @@ class cstsmapmerge(ctools.cscript): |
| 174 | 172 | # Open FITS file |
| 175 | 173 | fits = gammalib.GFits(fitsfile) |
| 176 | 174 | |
| 177 | - # Read TS and progress maps | |
| 175 | + # Read TS and status maps | |
| 178 | 176 | add_tsmap = gammalib.GSkyMap() |
| 179 | 177 | add_tsmap.read(fits[0]) |
| 180 | - add_progressmap = gammalib.GSkyMap() | |
| 181 | - add_progressmap.read(fits["PROGRESS MAP"]) | |
| 178 | + add_statusmap = gammalib.GSkyMap() | |
| 179 | + add_statusmap.read(fits['STATUS MAP']) | |
| 182 | 180 | |
| 183 | 181 | # Get other maps |
| 184 | 182 | add_maps = [] |
| ... | ... | @@ -186,8 +184,8 @@ class cstsmapmerge(ctools.cscript): |
| 186 | 184 | # Loop over extensions |
| 187 | 185 | for hdu in fits: |
| 188 | 186 | |
| 189 | - # Leave out primary and progress extension | |
| 190 | - if hdu.extname() != "IMAGE" and hdu.extname() != "PROGRESS MAP": | |
| 187 | + # Leave out primary and status extension | |
| 188 | + if hdu.extname() != "IMAGE" and hdu.extname() != 'STATUS MAP': | |
| 191 | 189 | |
| 192 | 190 | # Add present maps |
| 193 | 191 | skymap = gammalib.GSkyMap() |
| ... | ... | @@ -208,10 +206,10 @@ class cstsmapmerge(ctools.cscript): |
| 208 | 206 | for i in range(self._tsmap.npix()): |
| 209 | 207 | |
| 210 | 208 | # Consider only bins that have been computed |
| 211 | - if add_progressmap[i] > 0.5: | |
| 209 | + if add_statusmap[i] > -0.5: | |
| 212 | 210 | |
| 213 | 211 | # Raise exception if this bin has already been computed |
| 214 | - if self._progressmap[i] > 0.5 and not self._overwrite: | |
| 212 | + if self._statusmap[i] > -0.5 and not self._overwrite: | |
| 215 | 213 | msg = "Attempt to merge bin which apparently has "+\ |
| 216 | 214 | "already been merged. File \""+fitsfile+"\" "+\ |
| 217 | 215 | "contains already merged bins. Set hidden "+\ |
| ... | ... | @@ -221,8 +219,8 @@ class cstsmapmerge(ctools.cscript): |
| 221 | 219 | # Copy TS values |
| 222 | 220 | self._tsmap[i] = add_tsmap[i] |
| 223 | 221 | |
| 224 | - # Copy progress | |
| 225 | - self._progressmap[i] = add_progressmap[i] | |
| 222 | + # Copy status | |
| 223 | + self._statusmap[i] = add_statusmap[i] | |
| 226 | 224 | |
| 227 | 225 | # Loop over maps and copy entries |
| 228 | 226 | for j in range(len(self._maps)): |
| ... | ... | @@ -241,13 +239,13 @@ class cstsmapmerge(ctools.cscript): |
| 241 | 239 | Returns: |
| 242 | 240 | Number of pixels for which TS has been computed. |
| 243 | 241 | """ |
| 244 | - # Get progress map for this file | |
| 245 | - progress = gammalib.GSkyMap(fitsfile+"[PROGRESS MAP]") | |
| 242 | + # Get status map for this file | |
| 243 | + status = gammalib.GSkyMap(fitsfile+"[STATUS MAP]") | |
| 246 | 244 | |
| 247 | 245 | # Count number of pixels with TS status set |
| 248 | 246 | count = 0 |
| 249 | - for pix in progress: | |
| 250 | - if pix > 0.5: | |
| 247 | + for pix in status: | |
| 248 | + if pix > -0.5: | |
| 251 | 249 | count += 1 |
| 252 | 250 | |
| 253 | 251 | # Return number of pixels |
| ... | ... | @@ -275,49 +273,56 @@ class cstsmapmerge(ctools.cscript): |
| 275 | 273 | file0 = "" |
| 276 | 274 | self._merged_files = [] |
| 277 | 275 | |
| 278 | - # Test files for the entry progress map. Use the first one to appear | |
| 276 | + # Test files for the entry status map. Use the first one to appear | |
| 279 | 277 | # useful |
| 280 | 278 | for fitsfile in self._files: |
| 281 | 279 | |
| 282 | 280 | # Skip file if it's not a FITS file |
| 283 | 281 | if not gammalib.GFilename(fitsfile).is_fits(): |
| 284 | - if self._logExplicit(): | |
| 285 | - self._log(gammalib.parformat("Skip file")) | |
| 286 | - self._log(fitsfile) | |
| 287 | - self._log(" (not a FITS file)\n") | |
| 282 | + | |
| 283 | + # Log message | |
| 284 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (not a FITS file)") | |
| 285 | + | |
| 286 | + # Continue | |
| 288 | 287 | continue |
| 289 | 288 | |
| 290 | 289 | # Open FITS file |
| 291 | 290 | fits = gammalib.GFits(fitsfile) |
| 292 | 291 | |
| 293 | - # If file contains a progress map then use it | |
| 294 | - if fits.contains("PROGRESS MAP"): | |
| 292 | + # If file contains a status map then use it | |
| 293 | + if fits.contains('STATUS MAP'): | |
| 294 | + | |
| 295 | + # Close FITS file | |
| 295 | 296 | fits.close() |
| 297 | + | |
| 298 | + # Set filename to initial filename | |
| 296 | 299 | file0 = fitsfile |
| 297 | - if self._logTerse(): | |
| 298 | - self._log(gammalib.parformat("Initial TS map file")) | |
| 299 | - self._log(fitsfile) | |
| 300 | - count = self._get_number_of_ts_pixels(fitsfile) | |
| 301 | - self._log(" (%d TS pixels computed)" % count) | |
| 302 | - self._log("\n") | |
| 300 | + | |
| 301 | + # Log message | |
| 302 | + pix_info = " (%d TS pixels computed)" % self._get_number_of_ts_pixels(fitsfile) | |
| 303 | + self._log_value(gammalib.TERSE, "Initial TS map file", fitsfile + pix_info) | |
| 304 | + | |
| 305 | + # Leave loop | |
| 303 | 306 | break |
| 304 | 307 | |
| 305 | 308 | # ... otherwise signal that file is useless |
| 306 | 309 | else: |
| 307 | - fits.close() | |
| 308 | - if self._logExplicit(): | |
| 309 | - self._log(gammalib.parformat("Skip file")) | |
| 310 | - self._log(fitsfile) | |
| 311 | - self._log(" (no \"PROGRESS MAP\" extension)\n") | |
| 310 | + | |
| 311 | + # Close fits file | |
| 312 | + fits.close() | |
| 313 | + | |
| 314 | + # Info message | |
| 315 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (no \"STATUS MAP\" extension)") | |
| 316 | + | |
| 317 | + # Continue | |
| 312 | 318 | continue |
| 313 | 319 | |
| 314 | 320 | # Signal if no suitable file was found |
| 315 | 321 | if file0 == "": |
| 316 | - if self._logTerse(): | |
| 317 | - self._log("None of the provided files seems to be a sliced " | |
| 318 | - "TS map file (none has a \"PROGRESS MAP\" " | |
| 319 | - "extension).\n") | |
| 320 | - | |
| 322 | + self._log_string(gammalib.TERSE, "None of the provided files seems to be a sliced " | |
| 323 | + "TS map file (none has a \"STATUS MAP\" " | |
| 324 | + "extension).\n") | |
| 325 | + | |
| 321 | 326 | # ... otherwise merge files |
| 322 | 327 | else: |
| 323 | 328 | |
| ... | ... | @@ -338,34 +343,24 @@ class cstsmapmerge(ctools.cscript): |
| 338 | 343 | |
| 339 | 344 | # Skip if file is not FITS |
| 340 | 345 | if not gammalib.GFilename(fitsfile).is_fits(): |
| 341 | - if self._logExplicit(): | |
| 342 | - self._log(gammalib.parformat("Skip file")) | |
| 343 | - self._log(fitsfile) | |
| 344 | - self._log(" (not a FITS file)\n") | |
| 346 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (not a FITS file)") | |
| 345 | 347 | continue |
| 346 | 348 | |
| 347 | 349 | # Open FITS file |
| 348 | 350 | fits = gammalib.GFits(fitsfile) |
| 349 | 351 | |
| 350 | - # Skip if file does not contain progress map | |
| 351 | - if not fits.contains("PROGRESS MAP"): | |
| 352 | + # Skip if file does not contain status map | |
| 353 | + if not fits.contains('STATUS MAP'): | |
| 352 | 354 | fits.close() |
| 353 | - if self._logExplicit(): | |
| 354 | - self._log(gammalib.parformat("Skip file")) | |
| 355 | - self._log(fitsfile) | |
| 356 | - self._log(" (no \"PROGRESS MAP\" extension)\n") | |
| 355 | + self._log_value(gammalib.EXPLICIT, "Skip file", fitsfile +" (no \"STATUS MAP\" extension)") | |
| 357 | 356 | continue |
| 358 | 357 | |
| 359 | 358 | # Close FITS file |
| 360 | 359 | fits.close() |
| 361 | 360 | |
| 362 | 361 | # Logging |
| 363 | - if self._logTerse(): | |
| 364 | - self._log(gammalib.parformat("Merge TS map file")) | |
| 365 | - self._log(fitsfile) | |
| 366 | - count = self._get_number_of_ts_pixels(fitsfile) | |
| 367 | - self._log(" (%d TS pixels computed)" % count) | |
| 368 | - self._log("\n") | |
| 362 | + pix_info = " (%d TS pixels computed)" % self._get_number_of_ts_pixels(fitsfile) | |
| 363 | + self._log_value(gammalib.TERSE, "Merge TS map file", fitsfile + pix_info) | |
| 369 | 364 | |
| 370 | 365 | # Merge TS map |
| 371 | 366 | self._merge_ts_map(fitsfile) |
| ... | ... | @@ -380,19 +375,9 @@ class cstsmapmerge(ctools.cscript): |
| 380 | 375 | """ |
| 381 | 376 | Save TS map and remove slices if requested. |
| 382 | 377 | """ |
| 383 | - # Write header | |
| 384 | - if self._logTerse(): | |
| 385 | - self._log("\n") | |
| 386 | - self._log.header1("Save TS map") | |
| 387 | 378 | |
| 388 | 379 | # Get output filename in case it was not read ahead |
| 389 | 380 | outmap = self["outmap"].filename() |
| 390 | - | |
| 391 | - # Log filename | |
| 392 | - if self._logTerse(): | |
| 393 | - self._log(gammalib.parformat("TS map file")) | |
| 394 | - self._log(outmap.url()) | |
| 395 | - self._log("\n") | |
| 396 | 381 | |
| 397 | 382 | # Create FITS file |
| 398 | 383 | fits = gammalib.GFits() |
| ... | ... | @@ -408,29 +393,58 @@ class cstsmapmerge(ctools.cscript): |
| 408 | 393 | for i in range(len(self._mapnames)): |
| 409 | 394 | fits[i+1].extname(self._mapnames[i]) |
| 410 | 395 | |
| 396 | + # Treat status map separately | |
| 397 | + self._statusmap.write(fits) | |
| 398 | + fits[fits.size()-1].extname('STATUS MAP') | |
| 399 | + | |
| 411 | 400 | # Check if map is fully done |
| 412 | - done = True | |
| 413 | - for pix in self._progressmap: | |
| 414 | - if pix < 0.5: | |
| 415 | - done = False | |
| 416 | - break | |
| 401 | + bins_merged = 0 | |
| 402 | + for pix in self._statusmap: | |
| 403 | + if pix > -0.5: | |
| 404 | + bins_merged += 1 | |
| 405 | + | |
| 406 | + # Set boolean if map is fully done | |
| 407 | + done = (bins_merged == self._tsmaps.npix()) | |
| 417 | 408 | |
| 418 | - # Write progress map if we are not done yet | |
| 409 | + # Log summary header | |
| 410 | + self._log_header2(gammalib.TERSE, "Merging Summary") | |
| 411 | + | |
| 412 | + # Write status map if we are not done yet | |
| 419 | 413 | if not done: |
| 420 | - self._progressmap.write(fits) | |
| 421 | - fits[fits.size()-1].extname("PROGRESS MAP") | |
| 414 | + | |
| 415 | + # Log bins that were computed and those that were missing | |
| 416 | + self._log_value(gammalib.TERSE, "TS map bins", self._tsmap.npix()) | |
| 417 | + self._log_value(gammalib.TERSE, "Bins computed and merged", bins_merged ) | |
| 418 | + self._log_value(gammalib.TERSE, "Bins missing", self._tsmap.npix() - bins_merged) | |
| 419 | + | |
| 420 | + else: | |
| 421 | + | |
| 422 | + # Write success message | |
| 423 | + self._log_string(gammalib.TERSE, "TS map was fully computed and successfully merged") | |
| 424 | + | |
| 425 | + # Write header | |
| 426 | + self._log_header1(gammalib.TERSE, "Save TS map") | |
| 427 | + | |
| 428 | + # Log filename | |
| 429 | + self._log_value(gammalib.TERSE, "TS map file", outmap.url()) | |
| 422 | 430 | |
| 423 | 431 | # Save FITS file |
| 424 | - fits.saveto(outmap, self._clobber()) | |
| 432 | + fits.saveto(outmap, self._clobber()) | |
| 425 | 433 | |
| 426 | - # Delete TS input maps if requested | |
| 427 | - if self._delete: | |
| 434 | + # Delete TS input maps if requested and map is fully done | |
| 435 | + if self._delete and done: | |
| 436 | + | |
| 437 | + # Log header | |
| 438 | + self._log_header2(gammalib.TERSE, "Delete slices TS map files") | |
| 439 | + | |
| 440 | + # Loop over sliced files | |
| 428 | 441 | for filename in self._merged_files: |
| 442 | + | |
| 443 | + # Remove file | |
| 429 | 444 | os.remove(filename) |
| 430 | - if self._logTerse(): | |
| 431 | - self._log(gammalib.parformat("Deleted input file")) | |
| 432 | - self._log(filename) | |
| 433 | - self._log("\n") | |
| 445 | + | |
| 446 | + # Log message about file | |
| 447 | + self._log_value(gammalib.TERSE,"Deleted input file", filename) | |
| 434 | 448 | |
| 435 | 449 | # Return |
| 436 | 450 | return | ... | ... |
src/cttsmap/cttsmap.cpp
| ... | ... | @@ -210,10 +210,7 @@ void cttsmap::run(void) |
| 210 | 210 | get_parameters(); |
| 211 | 211 | |
| 212 | 212 | // Write parameters into logger |
| 213 | - if (logTerse()) { | |
| 214 | - log_parameters(); | |
| 215 | - log << std::endl; | |
| 216 | - } | |
| 213 | + log_parameters(TERSE); | |
| 217 | 214 | |
| 218 | 215 | // Set energy dispersion flag for all CTA observations and save old |
| 219 | 216 | // values in save_edisp vector |
| ... | ... | @@ -372,9 +369,6 @@ void cttsmap::run(void) |
| 372 | 369 | // Set Fit status of the bin |
| 373 | 370 | m_statusmap(i) = status; |
| 374 | 371 | |
| 375 | - // Add bin to progress map | |
| 376 | - m_progressmap(i) = 1.0; | |
| 377 | - | |
| 378 | 372 | // Remove model from container |
| 379 | 373 | models.remove(m_srcname); |
| 380 | 374 | |
| ... | ... | @@ -444,12 +438,6 @@ void cttsmap::save(void) |
| 444 | 438 | m_statusmap.write(fits); |
| 445 | 439 | fits[fits.size()-1]->extname("FITSTATUS"); |
| 446 | 440 | |
| 447 | - // Add computation log if not all bins are computed | |
| 448 | - if (m_binmin != -1 || m_binmax != -1) { | |
| 449 | - m_progressmap.write(fits); | |
| 450 | - fits[m_mapnames.size()+1]->extname("PROGRESS MAP"); | |
| 451 | - } | |
| 452 | - | |
| 453 | 441 | // Save FITS file |
| 454 | 442 | fits.saveto(m_outmap, clobber()); |
| 455 | 443 | |
| ... | ... | @@ -518,7 +506,6 @@ void cttsmap::init_members(void) |
| 518 | 506 | m_logL0 = 0.0; |
| 519 | 507 | m_tsmap.clear(); |
| 520 | 508 | m_statusmap.clear(); |
| 521 | - m_progressmap.clear(); | |
| 522 | 509 | m_mapnames.clear(); |
| 523 | 510 | m_maps.clear(); |
| 524 | 511 | m_testsource = NULL; |
| ... | ... | @@ -551,7 +538,6 @@ void cttsmap::copy_members(const cttsmap& app) |
| 551 | 538 | m_mapnames = app.m_mapnames; |
| 552 | 539 | m_maps = app.m_maps; |
| 553 | 540 | m_statusmap = app.m_statusmap; |
| 554 | - m_progressmap = app.m_progressmap; | |
| 555 | 541 | |
| 556 | 542 | // Clone protected members |
| 557 | 543 | m_testsource = (app.m_testsource != NULL) ? app.m_testsource->clone() : NULL; |
| ... | ... | @@ -684,11 +670,13 @@ void cttsmap::init_maps(const GSkyMap& map) |
| 684 | 670 | |
| 685 | 671 | // Initialise map information |
| 686 | 672 | m_statusmap.clear(); |
| 687 | - m_progressmap.clear(); | |
| 688 | 673 | |
| 689 | 674 | // Create status map and progress map |
| 690 | - m_statusmap = GSkyMap(map); | |
| 691 | - m_progressmap = GSkyMap(map); | |
| 675 | + m_statusmap = GSkyMap(map); | |
| 676 | + | |
| 677 | + // Set status map to invalid value -1 to signal | |
| 678 | + // that bin wasn't computed yet | |
| 679 | + m_statusmap = -1.0; | |
| 692 | 680 | |
| 693 | 681 | // Initialise maps of free parameters |
| 694 | 682 | if (m_testsource != NULL) { | ... | ... |
src/cttsmap/cttsmap.hpp
| ... | ... | @@ -100,7 +100,6 @@ protected: |
| 100 | 100 | GObservations m_obs; //!< Observation container |
| 101 | 101 | GSkyMap m_tsmap; //!< TS map |
| 102 | 102 | GSkyMap m_statusmap; //!< Map of optimizer fit status |
| 103 | - GSkyMap m_progressmap; //!< Map of computed bins | |
| 104 | 103 | std::vector<std::string> m_mapnames; //!< Names of free parameters |
| 105 | 104 | std::vector<GSkyMap> m_maps; //!< Sky maps for each free parameter |
| 106 | 105 | GModel* m_testsource; //!< Pointer to test source for TS computation | ... | ... |