def _set_obs(self): """ Set an observation container. Returns: Observation container. """ # Setup observation definition list obsdeflist = obsutils.set_obs_patterns(self._pattern, ra=self["ra"].real(), dec=self["dec"].real(), offset=self["offset"].real()) # Create list of observations obs = obsutils.set_obs_list(obsdeflist, tstart=self["tmin"].real(), duration=self["tmax"].real() - self["tmin"].real(), deadc=self["deadc"].real(), emin=self["emin"].real(), emax=self["emax"].real(), rad=self["rad"].real(), irf=self["irf"].string(), caldb=self["caldb"].string()) # Return observation container return obs
def _set_obs(self): """ Set CTA observation(s) Returns ------- obs : `~gammalib.GObservations` Observation container. """ # Setup observation definition list obsdeflist = obsutils.set_obs_patterns(self._pattern, ra=self['ra'].real(), dec=self['dec'].real(), offset=self['offset'].real()) # Create list of observations obs = obsutils.set_obs_list(obsdeflist, tstart=self['tmin'].real(), duration=self['tmax'].real()-self['tmin'].real(), deadc=self['deadc'].real(), emin=self['emin'].real(), emax=self['emax'].real(), rad=self['rad'].real(), irf=self['irf'].string(), caldb=self['caldb'].string()) # Return observation container return obs
def set_obs(self): """ Returns an observation container with a set of CTA observations. Keywords: """ # Setup observation definition list obsdeflist = obsutils.set_obs_patterns(self.m_pattern, ra=self["ra"].real(), dec=self["dec"].real(), offset=self["offset"].real()) # Create list of observations obs = obsutils.set_obs_list(obsdeflist, tstart=self["tmin"].real(), duration=self["tmax"].real()-self["tmin"].real(), deadc=self["deadc"].real(), emin=self["emin"].real(), emax=self["emax"].real(), rad=self["rad"].real(), irf=self["irf"].string(), caldb=self["caldb"].string()) # Return observation container return obs
def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, emin=0.1, emax=100.0, rad=5.0, duration=180.0, deadc=0.95, caldb='prod2', irf='South_0.5h'): """ Returns an observation container Parameters ---------- pattern : str, optional Pointing pattern, either 'single' or 'four' ra : float, optional Right Ascension of pattern centre (deg) dec : float, optional Declination of pattern centre (deg) offset : float, optional Offset between observations of pattern (deg) emin : float, optional Minimum energy (TeV) emax : float, optional Maximum energy (TeV) rad : float, optional ROI radius used for analysis (deg) duration : float, optional Duration of one CTA observation (s) deadc : float, optional Deadtime correction factor caldb : str, optional Calibration database path irf : str, optional Instrument response function Returns ------- obs : `~gammalib.GObservations` Observation container """ # Set list of observations obs_def_list = obsutils.set_obs_patterns(pattern, ra=ra, dec=dec, offset=offset) # Get observation container obs = obsutils.set_obs_list(obs_def_list, duration=duration, emin=emin, emax=emax, rad=rad, caldb=caldb, irf=irf) # Return observation container return obs
def _test_set_obs_list(self): """ Test set_obs_list() function """ # Setup observation definition list obsdeflist = [{'ra': 83.63, 'dec': 22.51}] # Setup observation container res = obsutils.set_obs_list(obsdeflist) # Check result self.test_value(res.size(), 1, 'Check number of observations') self.test_value(res.models().size(), 0, 'Check number of models') self.test_value(res.nobserved(), 0, 'Check number of observed events') self.test_value(res.npred(), 0.0, 'Check number of predicted events') self.test_value(res[0].eventtype(), 'EventList', 'Check event type') self.test_value(res[0].pointing().dir().ra_deg(), 83.63, 'Check pointing Right Ascension') self.test_value(res[0].pointing().dir().dec_deg(), 22.51, 'Check pointing declination') # Return return
def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, emin=0.1, emax=100.0, rad=5.0, duration=1800.0, deadc=0.95, caldb="prod2", irf="South_50h"): """ Returns an observation container. Keywords: pattern - Pointing pattern, either "single" or "four" ra - RA of pattern centre [deg] (default: 83.6331) dec - DEC of pattern centre [deg] (default: 22.0145) offset - Offset between observations of pattern [deg] (default: 1.5) emin - Minimum energy [TeV] (default: 0.1) emax - Maximum energy [TeV] (default: 100.0) rad - ROI radius used for analysis [deg] (default: 5.0) duration - Duration of one CTA observation [seconds] (default: 1800.0) deadc - Deadtime correction factor (default: 0.95) caldb - Calibration database path (default: "dummy") irf - Instrument response function (default: cta_dummy_irf) """ # Set list of observations obs_def_list = obsutils.set_obs_patterns(pattern, ra=ra, dec=dec, offset=offset) # Get observation container obs = obsutils.set_obs_list(obs_def_list, duration=duration, emin=emin, emax=emax, rad=rad, caldb=caldb, irf=irf) # Return observation container return obs
def _test_ctobssim_python(self): """ Test ctobssim from Python """ # Allocate ctobssim sim = ctools.ctobssim() # Check that empty ctobssim tool holds an empty observation self.test_value(sim.obs().size(), 0, 'Check number of observations') # Check that saving saves an empty model definition file sim['outevents'] = 'ctobssim_py0.fits' sim['logfile'] = 'ctobssim_py0.log' sim.logFileOpen() sim.save() self.test_assert(not os.path.isfile('ctobssim_py0.fits'), 'Check that no event list has been created') # Check that clearing does not lead to an exception or segfault sim.clear() # Now set ctobssim parameters sim = ctools.ctobssim() sim['inmodel'] = self._model sim['caldb'] = self._caldb sim['irf'] = self._irf sim['ra'] = 83.63 sim['dec'] = 22.01 sim['rad'] = 3.0 sim['tmin'] = '2020-01-01T00:00:00' sim['tmax'] = '2020-01-01T00:05:00' sim['emin'] = 0.1 sim['emax'] = 100.0 sim['outevents'] = 'ctobssim_py1.fits' sim['logfile'] = 'ctobssim_py1.log' sim['chatter'] = 2 # Run tool sim.logFileOpen() sim.run() # Check content of observation self._test_observation(sim) self._test_list(sim.obs()[0].events(), 3775) # Save events sim.save() # Load counts cube and check content. evt = gammalib.GCTAEventList('ctobssim_py1.fits') self._test_list(evt, 3775) # Copy ctobssim tool cpy_sim = sim.copy() # Retrieve observation and check content of copy self._test_observation(cpy_sim) self._test_list(cpy_sim.obs()[0].events(), 3775) # Execute copy of ctobssim tool again, now with a higher chatter # level than before cpy_sim['outevents'] = 'ctobssim_py2.fits' cpy_sim['logfile'] = 'ctobssim_py2.log' cpy_sim['chatter'] = 3 cpy_sim['publish'] = True cpy_sim.logFileOpen() # Needed to get a new log file cpy_sim.execute() # Load counts cube and check content. evt = gammalib.GCTAEventList('ctobssim_py2.fits') self._test_list(evt, 3775) # Set-up observation container pnts = [{'ra': 83.63, 'dec': 21.01}, {'ra': 84.63, 'dec': 22.01}] obs = obsutils.set_obs_list(pnts, caldb=self._caldb, irf=self._irf, duration=300.0, rad=3.0) # Set-up ctobssim tool from observation container sim = ctools.ctobssim(obs) sim['inmodel'] = self._model sim['outevents'] = 'ctobssim_py3.xml' sim['logfile'] = 'ctobssim_py3.log' sim['chatter'] = 3 # Double maximum event range max_rate = sim.max_rate() sim.max_rate(2.0*max_rate) self.test_value(sim.max_rate(), 2.0*max_rate, 1.0e-3, 'Check setting of maximum event rate') # Run ctobssim tool sim.logFileOpen() sim.run() # Retrieve observation and check content self._test_observation(sim, nobs=2, pnts=pnts) self._test_list(sim.obs()[0].events(), 3569) self._test_list(sim.obs()[1].events(), 3521) # Save events sim.save() # Load events obs = gammalib.GObservations('ctobssim_py3.xml') # Retrieve observation and check content self._test_list(obs[0].events(), 3569) self._test_list(obs[1].events(), 3521) # Return return
def _test_ctobssim_python(self): """ Test ctobssim from Python """ # Allocate ctobssim sim = ctools.ctobssim() # Check that empty ctobssim tool holds an empty observation self.test_value(sim.obs().size(), 0, 'Check number of observations') # Check that saving saves an empty model definition file sim['outevents'] = 'ctobssim_py0.fits' sim['logfile'] = 'ctobssim_py0.log' sim.logFileOpen() sim.save() self.test_assert(not os.path.isfile('ctobssim_py0.fits'), 'Check that no event list has been created') # Check that clearing does not lead to an exception or segfault sim.clear() # Now set ctobssim parameters sim = ctools.ctobssim() sim['inmodel'] = self._model sim['caldb'] = self._caldb sim['irf'] = self._irf sim['ra'] = 83.63 sim['dec'] = 22.01 sim['rad'] = 2.0 sim['tmin'] = '2020-01-01T00:00:00' sim['tmax'] = '2020-01-01T00:05:00' sim['emin'] = 1.0 sim['emax'] = 100.0 sim['outevents'] = 'ctobssim_py1.fits' sim['logfile'] = 'ctobssim_py1.log' sim['chatter'] = 2 # Run tool sim.logFileOpen() sim.run() # Check content of observation self._test_observation(sim) self._test_list(sim.obs()[0].events(), 261) # Save events sim.save() # Load counts cube and check content. evt = gammalib.GCTAEventList('ctobssim_py1.fits') self._test_list(evt, 261) # Copy ctobssim tool cpy_sim = sim.copy() # Retrieve observation and check content of copy self._test_observation(cpy_sim) self._test_list(cpy_sim.obs()[0].events(), 261) # Execute copy of ctobssim tool again, now with a higher chatter # level than before cpy_sim['outevents'] = 'ctobssim_py2.fits' cpy_sim['logfile'] = 'ctobssim_py2.log' cpy_sim['chatter'] = 3 cpy_sim['publish'] = True cpy_sim.logFileOpen() # Needed to get a new log file cpy_sim.execute() # Load counts cube and check content. evt = gammalib.GCTAEventList('ctobssim_py2.fits') self._test_list(evt, 261) # Set-up observation container pnts = [{'ra': 83.63, 'dec': 21.01}, {'ra': 84.63, 'dec': 22.01}] obs = obsutils.set_obs_list(pnts, caldb=self._caldb, irf=self._irf, duration=300.0, rad=3.0) # Set-up ctobssim tool from observation container sim = ctools.ctobssim(obs) sim['inmodel'] = self._model sim['outevents'] = 'ctobssim_py3.xml' sim['logfile'] = 'ctobssim_py3.log' sim['chatter'] = 3 # Double maximum event range max_rate = sim.max_rate() sim.max_rate(2.0*max_rate) self.test_value(sim.max_rate(), 2.0*max_rate, 1.0e-3, 'Check setting of maximum event rate') # Run ctobssim tool sim.logFileOpen() sim.run() # Retrieve observation and check content self._test_observation(sim, nobs=2, pnts=pnts) self._test_list(sim.obs()[0].events(), 3630) self._test_list(sim.obs()[1].events(), 3594) # Save events sim.save() # Load events obs = gammalib.GObservations('ctobssim_py3.xml') # Retrieve observation and check content self._test_list(obs[0].events(), 3630) self._test_list(obs[1].events(), 3594) # Return return
def _test_ctobssim_python(self): """ Test ctobssim from Python """ # Set-up ctobssim sim = ctools.ctobssim() sim['inmodel'] = self._model sim['outevents'] = 'events.fits' sim['caldb'] = self._caldb sim['irf'] = self._irf sim['ra'] = 83.63 sim['dec'] = 22.01 sim['rad'] = 10.0 sim['tmin'] = 0.0 sim['tmax'] = 1800.0 sim['emin'] = 0.1 sim['emax'] = 100.0 # Run tool sim.run() # Check content of observation self._test_observation(sim) self._test_list(sim.obs()[0].events(), 6881) # Save events sim.save() # Load counts cube and check content. evt = gammalib.GCTAEventList('events.fits') self._test_list(evt, 6881) # Set-up observation container pnts = [{'ra': 83.63, 'dec': 21.01}, {'ra': 84.63, 'dec': 22.01}, {'ra': 83.63, 'dec': 23.01}, {'ra': 82.63, 'dec': 22.01}] obs = obsutils.set_obs_list(pnts, caldb=self._caldb, irf=self._irf) # Set-up ctobssim from observation container sim = ctools.ctobssim(obs) sim['outevents'] = 'sim_events.xml' sim['inmodel'] = self._model # Run tool sim.run() # Retrieve observation and check content self._test_observation(sim, nobs=4, pnts=pnts) self._test_list(sim.obs()[0].events(), 6003) self._test_list(sim.obs()[1].events(), 6084) self._test_list(sim.obs()[2].events(), 5955) self._test_list(sim.obs()[3].events(), 6030) # Save events sim.save() # Load events obs = gammalib.GObservations('sim_events.xml') # Retrieve observation and check content self._test_list(obs[0].events(), 6003) self._test_list(obs[1].events(), 6084) self._test_list(obs[2].events(), 5955) self._test_list(obs[3].events(), 6030) # Set-up ctobssim with invalid event file sim = ctools.ctobssim() sim['inmodel'] = 'model_file_that_does_not_exist.xml' sim['outevents'] = 'events.fits' sim['caldb'] = self._caldb sim['irf'] = self._irf sim['ra'] = 83.63 sim['dec'] = 22.01 sim['rad'] = 10.0 sim['tmin'] = 0.0 sim['tmax'] = 1800.0 sim['emin'] = 0.1 sim['emax'] = 100.0 # Run ctbin tool self.test_try('Run ctobssim with invalid model file') try: sim.run() self.test_try_failure() except: self.test_try_success() # Return return