Commit ea342bf13896ba2a31b08a826b960c5d4007f9ea

Authored by Jürgen Knödlseder
1 parent 239868b4

Add optional cntcube parameter to obsutils.get_stacked_response()

Showing 1 changed file with 25 additions and 15 deletions
cscripts/obsutils.py
@@ -517,7 +517,7 @@ def set_observations(ra, dec, rad, tstart, duration, emin, emax, irf, caldb, @@ -517,7 +517,7 @@ def set_observations(ra, dec, rad, tstart, duration, emin, emax, irf, caldb,
517 def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, 517 def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
518 emin=0.1, emax=100.0, enumbins=20, edisp=False, 518 emin=0.1, emax=100.0, enumbins=20, edisp=False,
519 coordsys='GAL', proj='TAN', addbounds=False, 519 coordsys='GAL', proj='TAN', addbounds=False,
520 - log=False, debug=False, chatter=2): 520 + cntcube=None, log=False, debug=False, chatter=2):
521 """ 521 """
522 Get stacked response cubes 522 Get stacked response cubes
523 523
@@ -556,6 +556,8 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -556,6 +556,8 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
556 Projection 556 Projection
557 addbounds : bool, optional 557 addbounds : bool, optional
558 Add boundaries at observation energies 558 Add boundaries at observation energies
  559 + cntcube : `~gammalib.GCTAEventCube`, optional
  560 + Counts cube
559 log : bool, optional 561 log : bool, optional
560 Create log file(s) 562 Create log file(s)
561 debug : bool, optional 563 debug : bool, optional
@@ -637,23 +639,26 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200, @@ -637,23 +639,26 @@ def get_stacked_response(obs, xref, yref, binsz=0.05, nxpix=200, nypix=200,
637 # for the counts cube since no interpolation should be actually done 639 # for the counts cube since no interpolation should be actually done
638 # for the background cube. 640 # for the background cube.
639 bkgcube = ctools.ctbkgcube(obs) 641 bkgcube = ctools.ctbkgcube(obs)
640 - bkgcube['incube'] = 'NONE' 642 + if cntcube != None:
  643 + bkgcube.cntcube(cntcube)
  644 + else:
  645 + bkgcube['incube'] = 'NONE'
  646 + bkgcube['ebinalg'] = 'LOG'
  647 + bkgcube['binsz'] = binsz
  648 + bkgcube['nxpix'] = nxpix
  649 + bkgcube['nypix'] = nypix
  650 + bkgcube['enumbins'] = enumbins
  651 + bkgcube['emin'] = emin
  652 + bkgcube['emax'] = emax
  653 + bkgcube['coordsys'] = coordsys
  654 + bkgcube['proj'] = proj
  655 + if not usepnt:
  656 + bkgcube['xref'] = xref
  657 + bkgcube['yref'] = yref
641 bkgcube['usepnt'] = usepnt 658 bkgcube['usepnt'] = usepnt
642 - bkgcube['ebinalg'] = 'LOG'  
643 - bkgcube['binsz'] = binsz  
644 - bkgcube['nxpix'] = nxpix  
645 - bkgcube['nypix'] = nypix  
646 - bkgcube['enumbins'] = enumbins  
647 - bkgcube['emin'] = emin  
648 - bkgcube['emax'] = emax  
649 - bkgcube['coordsys'] = coordsys  
650 - bkgcube['proj'] = proj  
651 bkgcube['addbounds'] = addbounds 659 bkgcube['addbounds'] = addbounds
652 bkgcube['debug'] = debug 660 bkgcube['debug'] = debug
653 bkgcube['chatter'] = chatter 661 bkgcube['chatter'] = chatter
654 - if not usepnt:  
655 - bkgcube['xref'] = xref  
656 - bkgcube['yref'] = yref  
657 if log: 662 if log:
658 bkgcube.logFileOpen() 663 bkgcube.logFileOpen()
659 bkgcube.run() 664 bkgcube.run()
@@ -735,6 +740,10 @@ def get_stacked_obs(cls, obs): @@ -735,6 +740,10 @@ def get_stacked_obs(cls, obs):
735 cntcube['proj'] = cls['proj'].string() 740 cntcube['proj'] = cls['proj'].string()
736 cntcube.run() 741 cntcube.run()
737 742
  743 + # Store counts cube so that we can use it to build the background
  744 + # cube
  745 + cube = cntcube.cube().copy()
  746 +
738 # Write header 747 # Write header
739 if cls._logExplicit(): 748 if cls._logExplicit():
740 cls._log.header3('Creating stacked response') 749 cls._log.header3('Creating stacked response')
@@ -751,7 +760,8 @@ def get_stacked_obs(cls, obs): @@ -751,7 +760,8 @@ def get_stacked_obs(cls, obs):
751 enumbins=cls['enumbins'].integer(), 760 enumbins=cls['enumbins'].integer(),
752 edisp=cls['edisp'].boolean(), 761 edisp=cls['edisp'].boolean(),
753 coordsys=cls['coordsys'].string(), 762 coordsys=cls['coordsys'].string(),
754 - proj=cls['proj'].string()) 763 + proj=cls['proj'].string(),
  764 + cntcube=cube)
755 765
756 # Retrieve a new oberservation container 766 # Retrieve a new oberservation container
757 new_obs = cntcube.obs().copy() 767 new_obs = cntcube.obs().copy()