Commit 6daa536c2e83ca3529895f51a7e5b918d73df0d0
1 parent
b3cc572c
Manage also a global datastore
Showing
1 changed file
with
54 additions
and
19 deletions
modules/comscripts/comobsbin.py
| ... | ... | @@ -40,11 +40,12 @@ class comobsbin(ctools.csobservation): |
| 40 | 40 | self._init_csobservation(self.__class__.__name__, ctools.__version__, argv) |
| 41 | 41 | |
| 42 | 42 | # Initialise members |
| 43 | - self._phases = gammalib.GPhases() | |
| 44 | - self._select = gammalib.GCOMSelection() | |
| 45 | - self._drx_suffix = '' | |
| 46 | - self._drg_suffix = '' | |
| 47 | - self._dre_suffix = '' | |
| 43 | + self._phases = gammalib.GPhases() | |
| 44 | + self._select = gammalib.GCOMSelection() | |
| 45 | + self._drx_suffix = '' | |
| 46 | + self._drg_suffix = '' | |
| 47 | + self._dre_suffix = '' | |
| 48 | + self._global_datastore = '$COMDATA/datastore' | |
| 48 | 49 | |
| 49 | 50 | # Return |
| 50 | 51 | return |
| ... | ... | @@ -399,24 +400,36 @@ class comobsbin(ctools.csobservation): |
| 399 | 400 | drxfile = gammalib.GFilename(drxname) |
| 400 | 401 | drgfile = gammalib.GFilename(drgname) |
| 401 | 402 | |
| 403 | + # Set DRG and DRX filenames in global data store | |
| 404 | + drxname_global = '%s/%s_drx%s.fits' % (self._global_datastore, obs.id(), self._drx_suffix) | |
| 405 | + drgname_global = '%s/%s%s_drg%s.fits' % (self._global_datastore, obs.id(), dri_prefix, self._drg_suffix) | |
| 406 | + drxfile_global = gammalib.GFilename(drxname_global) | |
| 407 | + drgfile_global = gammalib.GFilename(drgname_global) | |
| 408 | + | |
| 402 | 409 | # Compute DRX |
| 403 | 410 | self._log_header3(gammalib.NORMAL, 'Compute DRX') |
| 404 | - if drxfile.exists(): | |
| 405 | - self._log_value(gammalib.NORMAL, 'DRX file exists', drxfile.url()) | |
| 411 | + if drxfile_global.exists(): | |
| 412 | + drxname = drxname_global | |
| 413 | + self._log_value(gammalib.NORMAL, 'Global DRX file exists', drxfile_global.url()) | |
| 414 | + elif drxfile.exists(): | |
| 415 | + self._log_value(gammalib.NORMAL, 'Local DRX file exists', drxfile.url()) | |
| 406 | 416 | else: |
| 407 | 417 | drx.compute_drx(obs, self._select) |
| 408 | 418 | drx.save(drxfile, True) |
| 409 | - self._log_value(gammalib.NORMAL, 'DRX file created', drxfile.url()) | |
| 419 | + self._log_value(gammalib.NORMAL, 'Local DRX file created', drxfile.url()) | |
| 410 | 420 | self._log_string(gammalib.NORMAL, str(drx)) |
| 411 | 421 | |
| 412 | 422 | # Compute DRG |
| 413 | 423 | self._log_header3(gammalib.NORMAL, 'Compute DRG') |
| 414 | - if drgfile.exists(): | |
| 415 | - self._log_value(gammalib.NORMAL, 'DRG file exists', drgfile.url()) | |
| 424 | + if drgfile_global.exists(): | |
| 425 | + drgname = drgname_global | |
| 426 | + self._log_value(gammalib.NORMAL, 'Global DRG file exists', drgfile_global.url()) | |
| 427 | + elif drgfile.exists(): | |
| 428 | + self._log_value(gammalib.NORMAL, 'Local DRG file exists', drgfile.url()) | |
| 416 | 429 | else: |
| 417 | 430 | drg.compute_drg(obs, self._select, self['zetamin'].real()) |
| 418 | 431 | drg.save(drgfile, True) |
| 419 | - self._log_value(gammalib.NORMAL, 'DRG file created', drgfile.url()) | |
| 432 | + self._log_value(gammalib.NORMAL, 'Local DRG file created', drgfile.url()) | |
| 420 | 433 | self._log_string(gammalib.NORMAL, str(drg)) |
| 421 | 434 | |
| 422 | 435 | # Initialse list of DRE names |
| ... | ... | @@ -431,13 +444,24 @@ class comobsbin(ctools.csobservation): |
| 431 | 444 | ebounds.emin(i).keV(), ebounds.emax(i).keV()) |
| 432 | 445 | drefile = gammalib.GFilename(drename) |
| 433 | 446 | |
| 447 | + # Set DRE filename in global data store | |
| 448 | + drename_global = '%s/%s%s_dre%s_%6.6d-%6.6dkeV.fits' % \ | |
| 449 | + (self._global_datastore, obs.id(), dri_prefix, self._dre_suffix, | |
| 450 | + ebounds.emin(i).keV(), ebounds.emax(i).keV()) | |
| 451 | + drefile_global = gammalib.GFilename(drename_global) | |
| 452 | + | |
| 434 | 453 | # Write header |
| 435 | 454 | self._log_header3(gammalib.NORMAL, 'Compute DRE for %.3f - %.3f MeV' % \ |
| 436 | 455 | (ebounds.emin(i).MeV(), ebounds.emax(i).MeV())) |
| 437 | 456 | |
| 457 | + # If DRE file exists in global datastor then do nothing | |
| 458 | + if drefile_global.exists(): | |
| 459 | + drename = drename_global | |
| 460 | + self._log_value(gammalib.NORMAL, 'Global DRE file exists', drefile_global.url()) | |
| 461 | + | |
| 438 | 462 | # If DRE file exists then do nothing |
| 439 | - if drefile.exists(): | |
| 440 | - self._log_value(gammalib.NORMAL, 'DRE file exists', drefile.url()) | |
| 463 | + elif drefile.exists(): | |
| 464 | + self._log_value(gammalib.NORMAL, 'Local DRE file exists', drefile.url()) | |
| 441 | 465 | |
| 442 | 466 | # ... otherwise compute and save it |
| 443 | 467 | else: |
| ... | ... | @@ -452,7 +476,7 @@ class comobsbin(ctools.csobservation): |
| 452 | 476 | dre.save(drefile, True) |
| 453 | 477 | |
| 454 | 478 | # Log creation |
| 455 | - self._log_value(gammalib.NORMAL, 'DRE file created', drefile.url()) | |
| 479 | + self._log_value(gammalib.NORMAL, 'Local DRE file created', drefile.url()) | |
| 456 | 480 | |
| 457 | 481 | # Log DRE |
| 458 | 482 | self._log_string(gammalib.NORMAL, str(dre)) |
| ... | ... | @@ -479,8 +503,8 @@ class comobsbin(ctools.csobservation): |
| 479 | 503 | drbname : str |
| 480 | 504 | DRB filename |
| 481 | 505 | """ |
| 482 | - # Set DRB name | |
| 483 | - drbname = drename.replace('_dre_', '_drb_') | |
| 506 | + # Set DRB name (always in local datastore) | |
| 507 | + drbname = drename.replace('_dre_', '_drb_').replace(self._global_datastore, self['outfolder'].string()) | |
| 484 | 508 | drbfile = gammalib.GFilename(drbname) |
| 485 | 509 | |
| 486 | 510 | # Write header |
| ... | ... | @@ -570,13 +594,24 @@ class comobsbin(ctools.csobservation): |
| 570 | 594 | ebounds.emin(i).keV(), ebounds.emax(i).keV()) |
| 571 | 595 | iaqfile = gammalib.GFilename(iaqname) |
| 572 | 596 | |
| 597 | + # Set global IAQ filename | |
| 598 | + iaqname_global = '%s/iaq_%6.6d-%6.6dkeV.fits' % \ | |
| 599 | + (self._global_datastore, | |
| 600 | + ebounds.emin(i).keV(), ebounds.emax(i).keV()) | |
| 601 | + iaqfile_global = gammalib.GFilename(iaqname_global) | |
| 602 | + | |
| 573 | 603 | # Write header |
| 574 | 604 | self._log_header3(gammalib.NORMAL, 'Compute IAQ for %.3f - %.3f MeV' % \ |
| 575 | 605 | (ebounds.emin(i).MeV(), ebounds.emax(i).MeV())) |
| 576 | 606 | |
| 607 | + # If IAQ file exists in global datastore then do nothing | |
| 608 | + if iaqfile_global.exists(): | |
| 609 | + iaqname = iaqname_global | |
| 610 | + self._log_value(gammalib.NORMAL, 'Global IAQ file exists', iaqfile_global.url()) | |
| 611 | + | |
| 577 | 612 | # If IAQ file exists then do nothing |
| 578 | - if iaqfile.exists(): | |
| 579 | - self._log_value(gammalib.NORMAL, 'IAQ file exists', iaqfile.url()) | |
| 613 | + elif iaqfile.exists(): | |
| 614 | + self._log_value(gammalib.NORMAL, 'Local IAQ file exists', iaqfile.url()) | |
| 580 | 615 | |
| 581 | 616 | # ... otherwise compute and save it |
| 582 | 617 | else: |
| ... | ... | @@ -597,7 +632,7 @@ class comobsbin(ctools.csobservation): |
| 597 | 632 | iaq.save(iaqfile, True) |
| 598 | 633 | |
| 599 | 634 | # Log creation |
| 600 | - self._log_value(gammalib.NORMAL, 'IAQ file created', iaqfile.url()) | |
| 635 | + self._log_value(gammalib.NORMAL, 'Local IAQ file created', iaqfile.url()) | |
| 601 | 636 | |
| 602 | 637 | # Log IAQ |
| 603 | 638 | self._log_string(gammalib.NORMAL, str(iaq)) | ... | ... |