diff --git a/examples/pipeline_binned_disk.py b/examples/pipeline_binned_disk.py index 0638eed..f89ca25 100755 --- a/examples/pipeline_binned_disk.py +++ b/examples/pipeline_binned_disk.py @@ -1,6 +1,6 @@ #! /usr/bin/env python # ========================================================================== -# Perform binned CTA analysis based of simulated CTA data. +# Perform binned analysis of simulated CTA data. # # Copyright (C) 2015-2016 Juergen Knoedlseder # @@ -30,26 +30,26 @@ 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. + Returns an observation container Parameters ---------- pattern : str, optional Pointing pattern, either 'single' or 'four' ra : float, optional - Right Ascension of pattern centre [deg] + Right Ascension of pattern centre (deg) dec : float, optional - Delication of pattern centre [deg] + Declination of pattern centre (deg) offset : float, optional - Offset between observations of pattern [deg] + Offset between observations of pattern (deg) emin : float, optional - Minimum energy [TeV] + Minimum energy (TeV) emax : float, optional - Maximum energy [TeV] + Maximum energy (TeV) rad : float, optional - ROI radius used for analysis [deg] + ROI radius used for analysis (deg) duration : float, optional - Duration of one CTA observation [seconds] + Duration of one CTA observation (s) deadc : float, optional Deadtime correction factor caldb : str, optional @@ -86,7 +86,7 @@ def setup_observations(pattern='four', ra=83.63, dec=22.01, offset=1.5, # =========== # def setup_model(obs, model='data/crab.xml'): """ - Setup model for analysis. + Setup model for analysis Parameters ---------- @@ -117,16 +117,16 @@ def run_pipeline(obs, emin=0.1, emax=100.0, caldb='prod2', irf='South_0.5h', debug=False): """ - Simulation and binned analysis pipeline. + Simulation and binned analysis pipeline Parameters ---------- obs : `~gammalib.GObservations` Observation container emin : float, optional - Minimum energy [TeV] + Minimum energy (TeV) emax : float, optional - Maximum energy [TeV] + Maximum energy (TeV) enumbins : int, optional Number of energy bins nxpix : int, optional @@ -134,7 +134,7 @@ def run_pipeline(obs, emin=0.1, emax=100.0, nypix : int, optional Number of pixels in Y axis binsz : float, optional - Pixel size [deg/pixel] + Pixel size (deg) coordsys : str, optional Coordinate system proj : str, optional diff --git a/examples/pipeline_binned_mem.py b/examples/pipeline_binned_mem.py index b7f1002..fa89ba4 100755 --- a/examples/pipeline_binned_mem.py +++ b/examples/pipeline_binned_mem.py @@ -1,15 +1,8 @@ #! /usr/bin/env python # ========================================================================== -# This script illustrates how to perform a binned CTA analysis based on -# simulated CTA data. You may use and adapt this script to implement your -# own pipeline. +# Perform binned in-memory analysis of simulated CTA data. # -# Usage: -# ./pipeline_binned_mem.py -# -# ========================================================================== -# -# Copyright (C) 2015 Juergen Knoedlseder +# Copyright (C) 2015-2016 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,25 +26,41 @@ from cscripts import obsutils # ================== # # Setup observations # # ================== # -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, +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_50h"): + deadc=0.95, caldb='prod2', irf='South_0.5h'): """ - 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) + 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, @@ -77,10 +86,19 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, # =========== # def setup_model(obs, model='data/crab.xml'): """ - Setup model for analysis. - - Keywords: - model - Model Xml file + Setup model for analysis + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + model : str, optional + Model definition XML file + + Returns + ------- + obs : `~gammalib.GObservations` + Observation container """ # Append model from file to observation container obs.models(gammalib.GModels(model)) @@ -94,24 +112,36 @@ def setup_model(obs, model='data/crab.xml'): # ================================ # def run_pipeline(obs, emin=0.1, emax=100.0, enumbins=20, nxpix=200, nypix=200, binsz=0.02, - coordsys="CEL", proj="CAR", debug=False): + coordsys='CEL', proj='CAR', debug=False): """ - Simulation and binned analysis pipeline. - - Keywords: - emin - Minimum energy of cube [TeV] (default: 0.1) - emax - Maximum energy of cube [TeV] (default: 100.0) - enumbins - Number of energy bins in cube (default: 20) - nxpix - Number of RA pixels in cube (default: 200) - nypix - Number of DEC pixels in cube (default: 200) - binsz - Spatial cube bin size [deg] (default: 0.02) - coordsys - Cube coordinate system (CEL or GAL) - proj - Cube World Coordinate System (WCS) projection - debug - Enable debugging (default: False) + Simulation and binned analysis pipeline + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + emin : float, optional + Minimum energy (TeV) + emax : float, optional + Maximum energy (TeV) + enumbins : int, optional + Number of energy bins + nxpix : int, optional + Number of pixels in X axis + nypix : int, optional + Number of pixels in Y axis + binsz : float, optional + Pixel size (deg) + coordsys : str, optional + Coordinate system + proj : str, optional + Coordinate projection + debug : bool, optional + Debug function """ # Simulate events sim = ctools.ctobssim(obs) - sim["debug"] = debug + sim['debug'] = debug sim.run() # Bin events by looping over all observations in the container @@ -125,16 +155,16 @@ def run_pipeline(obs, emin=0.1, emax=100.0, # Bin events for that observation bin = ctools.ctbin(container) - bin["ebinalg"] = "LOG" - bin["emin"] = emin - bin["emax"] = emax - bin["enumbins"] = enumbins - bin["nxpix"] = nxpix - bin["nypix"] = nypix - bin["binsz"] = binsz - bin["coordsys"] = coordsys - bin["usepnt"] = True - bin["proj"] = proj + bin['ebinalg'] = 'LOG' + bin['emin'] = emin + bin['emax'] = emax + bin['enumbins'] = enumbins + bin['nxpix'] = nxpix + bin['nypix'] = nypix + bin['binsz'] = binsz + bin['coordsys'] = coordsys + bin['usepnt'] = True + bin['proj'] = proj bin.run() # Append result to observations @@ -142,7 +172,7 @@ def run_pipeline(obs, emin=0.1, emax=100.0, # Perform maximum likelihood fitting like = ctools.ctlike(obs) - like["debug"] = True # Switch this always on for results in console + like['debug'] = True # Switch this always on for results in console like.run() # Return @@ -155,9 +185,9 @@ def run_pipeline(obs, emin=0.1, emax=100.0, if __name__ == '__main__': # Dump header - print("********************************************") - print("* CTA binned analysis pipeline *") - print("********************************************") + print('********************************************') + print('* CTA binned analysis pipeline *') + print('********************************************') # Setup observations obs = setup_observations() diff --git a/examples/pipeline_stacked_disk.py b/examples/pipeline_stacked_disk.py index 8ec9a82..4db9d11 100755 --- a/examples/pipeline_stacked_disk.py +++ b/examples/pipeline_stacked_disk.py @@ -1,15 +1,8 @@ #! /usr/bin/env python # ========================================================================== -# This script illustrates how to perform a stacked CTA analysis based on -# simulated CTA data. You may use and adapt this script to implement your -# own pipeline. +# Perform stacked analysis of simulated CTA data. # -# Usage: -# ./pipeline_stacked_disk.py -# -# ========================================================================== -# -# Copyright (C) 2015 Juergen Knoedlseder +# Copyright (C) 2015-2016 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,25 +26,41 @@ from cscripts import obsutils # ================== # # Setup observations # # ================== # -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, +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_50h"): + deadc=0.95, caldb='prod2', irf='South_0.5h'): """ - 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) + 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, @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, # =========== # # Setup model # # =========== # -def setup_model(obs, model="data/crab.xml"): +def setup_model(obs, model='data/crab.xml'): """ - Setup model for analysis. + Setup model for analysis + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + model : str, optional + Model definition XML file - Keywords: - model - Model Xml file + Returns + ------- + obs : `~gammalib.GObservations` + Observation container """ # Append model from file to observation container obs.models(gammalib.GModels(model)) @@ -94,126 +112,146 @@ def setup_model(obs, model="data/crab.xml"): # ================================ # def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, enumbins=20, nxpix=200, nypix=200, binsz=0.02, - coordsys="CEL", proj="CAR", - model="data/crab.xml", - caldb="prod2", irf="South_50h", + coordsys='CEL', proj='CAR', + model='data/crab.xml', + caldb='prod2', irf='South_0.5h', debug=False): """ - Simulation and stacked analysis pipeline. - - Keywords: - ra - RA of cube centre [deg] (default: 83.6331) - dec - DEC of cube centre [deg] (default: 22.0145) - emin - Minimum energy of cube [TeV] (default: 0.1) - emax - Maximum energy of cube [TeV] (default: 100.0) - enumbins - Number of energy bins in cube (default: 20) - nxpix - Number of RA pixels in cube (default: 200) - nypix - Number of DEC pixels in cube (default: 200) - binsz - Spatial cube bin size [deg] (default: 0.02) - coordsys - Cube coordinate system (CEL or GAL) - proj - Cube World Coordinate System (WCS) projection - debug - Enable debugging (default: False) + Simulation and stacked analysis pipeline + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + ra : float, optional + Right Ascension of counts cube centre (deg) + dec : float, optional + Declination of Region of counts cube centre (deg) + emin : float, optional + Minimum energy (TeV) + emax : float, optional + Maximum energy (TeV) + enumbins : int, optional + Number of energy bins + nxpix : int, optional + Number of pixels in X axis + nypix : int, optional + Number of pixels in Y axis + binsz : float, optional + Pixel size (deg) + coordsys : str, optional + Coordinate system + proj : str, optional + Coordinate projection + model : str, optional + Model definition XML file + caldb : str, optional + Calibration database path + irf : str, optional + Instrument response function + debug : bool, optional + Debug function """ # Simulate events sim = ctools.ctobssim(obs) - sim["debug"] = debug - sim["outevents"] = "obs.xml" + sim['debug'] = debug + sim['outevents'] = 'obs.xml' sim.execute() # Bin events into counts map bin = ctools.ctbin() - bin["inobs"] = "obs.xml" - bin["outcube"] = "cntcube.fits" - bin["ebinalg"] = "LOG" - bin["emin"] = emin - bin["emax"] = emax - bin["enumbins"] = enumbins - bin["nxpix"] = nxpix - bin["nypix"] = nypix - bin["binsz"] = binsz - bin["coordsys"] = coordsys - bin["proj"] = proj - bin["xref"] = ra - bin["yref"] = dec - bin["debug"] = debug + bin['inobs'] = 'obs.xml' + bin['outcube'] = 'cntcube.fits' + bin['ebinalg'] = 'LOG' + bin['emin'] = emin + bin['emax'] = emax + bin['enumbins'] = enumbins + bin['nxpix'] = nxpix + bin['nypix'] = nypix + bin['binsz'] = binsz + bin['coordsys'] = coordsys + bin['proj'] = proj + bin['xref'] = ra + bin['yref'] = dec + bin['debug'] = debug bin.execute() # Create exposure cube expcube = ctools.ctexpcube() - expcube["inobs"] = "obs.xml" - expcube["incube"] = "cntcube.fits" - expcube["outcube"] = "expcube.fits" - expcube["caldb"] = caldb - expcube["irf"] = irf - expcube["ebinalg"] = "LOG" - expcube["emin"] = emin - expcube["emax"] = emax - expcube["enumbins"] = enumbins - expcube["nxpix"] = nxpix - expcube["nypix"] = nypix - expcube["binsz"] = binsz - expcube["coordsys"] = coordsys - expcube["proj"] = proj - expcube["xref"] = ra - expcube["yref"] = dec - expcube["debug"] = debug + expcube['inobs'] = 'obs.xml' + expcube['incube'] = 'cntcube.fits' + expcube['outcube'] = 'expcube.fits' + expcube['caldb'] = caldb + expcube['irf'] = irf + expcube['ebinalg'] = 'LOG' + expcube['emin'] = emin + expcube['emax'] = emax + expcube['enumbins'] = enumbins + expcube['nxpix'] = nxpix + expcube['nypix'] = nypix + expcube['binsz'] = binsz + expcube['coordsys'] = coordsys + expcube['proj'] = proj + expcube['xref'] = ra + expcube['yref'] = dec + expcube['debug'] = debug expcube.execute() # Create PSF cube psfcube = ctools.ctpsfcube() - psfcube["inobs"] = "obs.xml" - psfcube["incube"] = "NONE" - psfcube["outcube"] = "psfcube.fits" - psfcube["caldb"] = caldb - psfcube["irf"] = irf - psfcube["ebinalg"] = "LOG" - psfcube["emin"] = emin - psfcube["emax"] = emax - psfcube["enumbins"] = enumbins - psfcube["nxpix"] = 10 - psfcube["nypix"] = 10 - psfcube["binsz"] = 1.0 - psfcube["coordsys"] = coordsys - psfcube["proj"] = proj - psfcube["xref"] = ra - psfcube["yref"] = dec - psfcube["debug"] = debug + psfcube['inobs'] = 'obs.xml' + psfcube['incube'] = 'NONE' + psfcube['outcube'] = 'psfcube.fits' + psfcube['caldb'] = caldb + psfcube['irf'] = irf + psfcube['ebinalg'] = 'LOG' + psfcube['emin'] = emin + psfcube['emax'] = emax + psfcube['enumbins'] = enumbins + psfcube['nxpix'] = 10 + psfcube['nypix'] = 10 + psfcube['binsz'] = 1.0 + psfcube['coordsys'] = coordsys + psfcube['proj'] = proj + psfcube['xref'] = ra + psfcube['yref'] = dec + psfcube['debug'] = debug psfcube.execute() # Create background cube bkgcube = ctools.ctbkgcube() - bkgcube["inobs"] = "obs.xml" - bkgcube["inmodel"] = model - bkgcube["incube"] = "cntcube.fits" - bkgcube["outcube"] = "bkgcube.fits" - bkgcube["outmodel"] = "model_bkg.xml" - bkgcube["caldb"] = caldb - bkgcube["irf"] = irf - bkgcube["ebinalg"] = "LOG" - bkgcube["emin"] = emin - bkgcube["emax"] = emax - bkgcube["enumbins"] = enumbins - bkgcube["nxpix"] = 10 - bkgcube["nypix"] = 10 - bkgcube["binsz"] = 1.0 - bkgcube["coordsys"] = coordsys - bkgcube["proj"] = proj - bkgcube["xref"] = ra - bkgcube["yref"] = dec - bkgcube["debug"] = debug + bkgcube['inobs'] = 'obs.xml' + bkgcube['inmodel'] = model + bkgcube['incube'] = 'NONE' + bkgcube['outcube'] = 'bkgcube.fits' + bkgcube['outmodel'] = 'model_bkg.xml' + bkgcube['caldb'] = caldb + bkgcube['irf'] = irf + bkgcube['ebinalg'] = 'LOG' + bkgcube['emin'] = emin + bkgcube['emax'] = emax + bkgcube['enumbins'] = enumbins + bkgcube['nxpix'] = 10 + bkgcube['nypix'] = 10 + bkgcube['binsz'] = 1.0 + bkgcube['coordsys'] = coordsys + bkgcube['proj'] = proj + bkgcube['xref'] = ra + bkgcube['yref'] = dec + bkgcube['debug'] = debug bkgcube.execute() # Perform maximum likelihood fitting like = ctools.ctlike() - like["inobs"] = "cntcube.fits" - like["inmodel"] = "model_bkg.xml" - like["outmodel"] = "fit_results.xml" - like["expcube"] = "expcube.fits" - like["psfcube"] = "psfcube.fits" - like["bkgcube"] = "bkgcube.fits" - like["caldb"] = caldb - like["irf"] = irf - like["debug"] = True # Switch this always on for results in console + like['inobs'] = 'cntcube.fits' + like['inmodel'] = 'model_bkg.xml' + like['outmodel'] = 'fit_results.xml' + like['expcube'] = 'expcube.fits' + like['psfcube'] = 'psfcube.fits' + like['bkgcube'] = 'bkgcube.fits' + like['caldb'] = caldb + like['irf'] = irf + like['debug'] = True # Switch this always on for results in console like.execute() # Return @@ -226,9 +264,9 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, if __name__ == '__main__': # Dump header - print("********************************************") - print("* CTA stacked analysis pipeline *") - print("********************************************") + print('********************************************') + print('* CTA stacked analysis pipeline *') + print('********************************************') # Setup observations obs = setup_observations() diff --git a/examples/pipeline_stacked_mem.py b/examples/pipeline_stacked_mem.py index d7b5360..a0c6986 100755 --- a/examples/pipeline_stacked_mem.py +++ b/examples/pipeline_stacked_mem.py @@ -1,15 +1,8 @@ #! /usr/bin/env python # ========================================================================== -# This script illustrates how to perform a stacked CTA analysis based on -# simulated CTA data. You may use and adapt this script to implement your -# own pipeline. +# Perform stacked in-memory analysis of simulated CTA data # -# Usage: -# ./pipeline_stacked_mem.py -# -# ========================================================================== -# -# Copyright (C) 2014-2015 Juergen Knoedlseder +# Copyright (C) 2014-2016 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,25 +26,41 @@ from cscripts import obsutils # ================== # # Setup observations # # ================== # -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, +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_50h"): + deadc=0.95, caldb='prod2', irf='South_0.5h'): """ - 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) + 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, @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, # =========== # # Setup model # # =========== # -def setup_model(obs, model="data/crab.xml"): +def setup_model(obs, model='data/crab.xml'): """ - Setup model for analysis. - - Keywords: - model - Model Xml file + Setup model for analysis + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + model : str, optional + Model definition XML file + + Returns + ------- + obs : `~gammalib.GObservations` + Observation container """ # Append model from file to observation container obs.models(gammalib.GModels(model)) @@ -94,93 +112,107 @@ def setup_model(obs, model="data/crab.xml"): # ================================ # def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, enumbins=20, nxpix=200, nypix=200, binsz=0.02, - coordsys="CEL", proj="CAR", debug=False): + coordsys='CEL', proj='CAR', debug=False): """ - Simulation and stacked analysis pipeline. - - Keywords: - ra - RA of cube centre [deg] (default: 83.6331) - dec - DEC of cube centre [deg] (default: 22.0145) - emin - Minimum energy of cube [TeV] (default: 0.1) - emax - Maximum energy of cube [TeV] (default: 100.0) - enumbins - Number of energy bins in cube (default: 20) - nxpix - Number of RA pixels in cube (default: 200) - nypix - Number of DEC pixels in cube (default: 200) - binsz - Spatial cube bin size [deg] (default: 0.02) - coordsys - Cube coordinate system (CEL or GAL) - proj - Cube World Coordinate System (WCS) projection - debug - Enable debugging (default: False) + Simulation and stacked analysis pipeline + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + ra : float, optional + Right Ascension of counts cube centre (deg) + dec : float, optional + Declination of Region of counts cube centre (deg) + emin : float, optional + Minimum energy (TeV) + emax : float, optional + Maximum energy (TeV) + enumbins : int, optional + Number of energy bins + nxpix : int, optional + Number of pixels in X axis + nypix : int, optional + Number of pixels in Y axis + binsz : float, optional + Pixel size (deg) + coordsys : str, optional + Coordinate system + proj : str, optional + Coordinate projection + debug : bool, optional + Debug function """ # Simulate events sim = ctools.ctobssim(obs) - sim["debug"] = debug + sim['debug'] = debug sim.run() # Bin events into counts map bin = ctools.ctbin(sim.obs()) - bin["ebinalg"] = "LOG" - bin["emin"] = emin - bin["emax"] = emax - bin["enumbins"] = enumbins - bin["nxpix"] = nxpix - bin["nypix"] = nypix - bin["binsz"] = binsz - bin["coordsys"] = coordsys - bin["proj"] = proj - bin["xref"] = ra - bin["yref"] = dec - bin["debug"] = debug + bin['ebinalg'] = 'LOG' + bin['emin'] = emin + bin['emax'] = emax + bin['enumbins'] = enumbins + bin['nxpix'] = nxpix + bin['nypix'] = nypix + bin['binsz'] = binsz + bin['coordsys'] = coordsys + bin['proj'] = proj + bin['xref'] = ra + bin['yref'] = dec + bin['debug'] = debug bin.run() # Create exposure cube expcube = ctools.ctexpcube(sim.obs()) - expcube["incube"] = "NONE" - expcube["ebinalg"] = "LOG" - expcube["emin"] = emin - expcube["emax"] = emax - expcube["enumbins"] = enumbins - expcube["nxpix"] = nxpix - expcube["nypix"] = nypix - expcube["binsz"] = binsz - expcube["coordsys"] = coordsys - expcube["proj"] = proj - expcube["xref"] = ra - expcube["yref"] = dec - expcube["debug"] = debug + expcube['incube'] = 'NONE' + expcube['ebinalg'] = 'LOG' + expcube['emin'] = emin + expcube['emax'] = emax + expcube['enumbins'] = enumbins + expcube['nxpix'] = nxpix + expcube['nypix'] = nypix + expcube['binsz'] = binsz + expcube['coordsys'] = coordsys + expcube['proj'] = proj + expcube['xref'] = ra + expcube['yref'] = dec + expcube['debug'] = debug expcube.run() # Create PSF cube psfcube = ctools.ctpsfcube(sim.obs()) - psfcube["incube"] = "NONE" - psfcube["ebinalg"] = "LOG" - psfcube["emin"] = emin - psfcube["emax"] = emax - psfcube["enumbins"] = enumbins - psfcube["nxpix"] = 10 - psfcube["nypix"] = 10 - psfcube["binsz"] = 1.0 - psfcube["coordsys"] = coordsys - psfcube["proj"] = proj - psfcube["xref"] = ra - psfcube["yref"] = dec - psfcube["debug"] = debug + psfcube['incube'] = 'NONE' + psfcube['ebinalg'] = 'LOG' + psfcube['emin'] = emin + psfcube['emax'] = emax + psfcube['enumbins'] = enumbins + psfcube['nxpix'] = 10 + psfcube['nypix'] = 10 + psfcube['binsz'] = 1.0 + psfcube['coordsys'] = coordsys + psfcube['proj'] = proj + psfcube['xref'] = ra + psfcube['yref'] = dec + psfcube['debug'] = debug psfcube.run() # Create background cube bkgcube = ctools.ctbkgcube(sim.obs()) - bkgcube["incube"] = "NONE" - bkgcube["ebinalg"] = "LOG" - bkgcube["emin"] = emin - bkgcube["emax"] = emax - bkgcube["enumbins"] = enumbins - bkgcube["nxpix"] = 10 - bkgcube["nypix"] = 10 - bkgcube["binsz"] = 1.0 - bkgcube["coordsys"] = coordsys - bkgcube["proj"] = proj - bkgcube["xref"] = ra - bkgcube["yref"] = dec - bkgcube["debug"] = debug + bkgcube['incube'] = 'NONE' + bkgcube['ebinalg'] = 'LOG' + bkgcube['emin'] = emin + bkgcube['emax'] = emax + bkgcube['enumbins'] = enumbins + bkgcube['nxpix'] = 10 + bkgcube['nypix'] = 10 + bkgcube['binsz'] = 1.0 + bkgcube['coordsys'] = coordsys + bkgcube['proj'] = proj + bkgcube['xref'] = ra + bkgcube['yref'] = dec + bkgcube['debug'] = debug bkgcube.run() # Attach background model to observation container @@ -192,7 +224,7 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, # Perform maximum likelihood fitting like = ctools.ctlike(bin.obs()) - like["debug"] = True # Switch this always on for results in console + like['debug'] = True # Switch this always on for results in console like.run() # Return @@ -205,9 +237,9 @@ def run_pipeline(obs, ra=83.63, dec=22.01, emin=0.1, emax=100.0, if __name__ == '__main__': # Dump header - print("********************************************") - print("* CTA stacked analysis pipeline *") - print("********************************************") + print('********************************************') + print('* CTA stacked analysis pipeline *') + print('********************************************') # Setup observations obs = setup_observations() diff --git a/examples/pipeline_unbinned_disk.py b/examples/pipeline_unbinned_disk.py index e4b3eab..1f93093 100755 --- a/examples/pipeline_unbinned_disk.py +++ b/examples/pipeline_unbinned_disk.py @@ -1,15 +1,8 @@ #! /usr/bin/env python # ========================================================================== -# This script illustrates how to perform an unbinned CTA analysis based on -# simulated CTA data. You may use and adapt this script to implement your -# own pipeline. +# Perform unbinned analysis of simulated CTA data. # -# Usage: -# ./pipeline_unbinned_disk.py -# -# ========================================================================== -# -# Copyright (C) 2015 Juergen Knoedlseder +# Copyright (C) 2015-2016 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,25 +26,41 @@ from cscripts import obsutils # ================== # # Setup observations # # ================== # -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, +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_50h"): + deadc=0.95, caldb='prod2', irf='South_0.5h'): """ - 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) + 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, @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, # =========== # # Setup model # # =========== # -def setup_model(obs, model="data/crab.xml"): +def setup_model(obs, model='data/crab.xml'): """ - Setup model for analysis. - - Keywords: - model - Model Xml file + Setup model for analysis + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + model : str, optional + Model definition XML file + + Returns + ------- + obs : `~gammalib.GObservations` + Observation container """ # Append model from file to observation container obs.models(gammalib.GModels(model)) @@ -95,55 +113,69 @@ def setup_model(obs, model="data/crab.xml"): def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, emin=0.1, emax=100.0, tmin=0.0, tmax=0.0, - model="data/crab.xml", - caldb="prod2", irf="South_50h", + model='data/crab.xml', + caldb='prod2', irf='South_0.5h', debug=False): """ - Simulation and unbinned analysis pipeline. - - Keywords: - ra - RA of cube centre [deg] (default: 83.63) - dec - DEC of cube centre [deg] (default: 22.01) - rad - Selection radius [deg] (default: 3.0) - emin - Minimum energy of cube [TeV] (default: 0.1) - emax - Maximum energy of cube [TeV] (default: 100.0) - tmin - Start time [MET] (default: 0.0) - tmax - Stop time [MET] (default: 0.0) - model - Model Xml file - caldb - Calibration database path (default: "dummy") - irf - Instrument response function (default: cta_dummy_irf) - debug - Enable debugging (default: False) + Simulation and unbinned analysis pipeline + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + ra : float, optional + Right Ascension of Region of Interest centre (deg) + dec : float, optional + Declination of Region of Interest centre (deg) + rad : float, optional + Radius of Region of Interest (deg) + emin : float, optional + Minimum energy (TeV) + emax : float, optional + Maximum energy (TeV) + tmin : float, optional + Start time (s) + tmax : float, optional + Stop time (s) + model : str, optional + Model definition XML file + caldb : str, optional + Calibration database path + irf : str, optional + Instrument response function + debug : bool, optional + Debug function """ # Get model # Simulate events sim = ctools.ctobssim(obs) - sim["debug"] = debug - sim["outevents"] = "obs.xml" + sim['debug'] = debug + sim['outevents'] = 'obs.xml' sim.execute() # Select events select = ctools.ctselect() - select["inobs"] = "obs.xml" - select["outobs"] = "obs_selected.xml" - select["ra"] = ra - select["dec"] = dec - select["rad"] = rad - select["emin"] = emin - select["emax"] = emax - select["tmin"] = tmin - select["tmax"] = tmax - select["debug"] = debug + select['inobs'] = 'obs.xml' + select['outobs'] = 'obs_selected.xml' + select['ra'] = ra + select['dec'] = dec + select['rad'] = rad + select['emin'] = emin + select['emax'] = emax + select['tmin'] = tmin + select['tmax'] = tmax + select['debug'] = debug select.execute() # Perform maximum likelihood fitting like = ctools.ctlike() - like["inobs"] = "obs_selected.xml" - like["inmodel"] = model - like["outmodel"] = "fit_results.xml" - like["caldb"] = caldb - like["irf"] = irf - like["debug"] = True # Switch this always on for results in console + like['inobs'] = 'obs_selected.xml' + like['inmodel'] = model + like['outmodel'] = 'fit_results.xml' + like['caldb'] = caldb + like['irf'] = irf + like['debug'] = True # Switch this always on for results in console like.execute() # Return @@ -156,9 +188,9 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, if __name__ == '__main__': # Dump header - print("********************************************") - print("* CTA unbinned analysis pipeline *") - print("********************************************") + print('********************************************') + print('* CTA unbinned analysis pipeline *') + print('********************************************') # Setup observations obs = setup_observations() diff --git a/examples/pipeline_unbinned_mem.py b/examples/pipeline_unbinned_mem.py index 6b8ce5c..925a515 100755 --- a/examples/pipeline_unbinned_mem.py +++ b/examples/pipeline_unbinned_mem.py @@ -1,15 +1,8 @@ #! /usr/bin/env python # ========================================================================== -# This script illustrates how to perform an unbinned CTA analysis based on -# simulated CTA data. You may use and adapt this script to implement your -# own pipeline. +# Perform unbinned in-memory analysis of simulated CTA data # -# Usage: -# ./pipeline_unbinned_mem.py -# -# ========================================================================== -# -# Copyright (C) 2015 Juergen Knoedlseder +# Copyright (C) 2015-2016 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,25 +26,41 @@ from cscripts import obsutils # ================== # # Setup observations # # ================== # -def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, +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_50h"): + deadc=0.95, caldb='prod2', irf='South_0.5h'): """ - 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) + 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, @@ -75,12 +84,21 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, # =========== # # Setup model # # =========== # -def setup_model(obs, model="data/crab.xml"): +def setup_model(obs, model='data/crab.xml'): """ - Setup model for analysis. - - Keywords: - model - Model Xml file + Setup model for analysis + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + model : str, optional + Model definition XML file + + Returns + ------- + obs : `~gammalib.GObservations` + Observation container """ # Append model from file to observation container obs.models(gammalib.GModels(model)) @@ -97,38 +115,49 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, tmin=0.0, tmax=0.0, debug=False): """ - Simulation and unbinned analysis pipeline. - - Keywords: - ra - RA of cube centre [deg] (default: 83.63) - dec - DEC of cube centre [deg] (default: 22.01) - rad - Selection radius [deg] (default: 3.0) - emin - Minimum energy of cube [TeV] (default: 0.1) - emax - Maximum energy of cube [TeV] (default: 100.0) - tmin - Start time [MET] (default: 0.0) - tmax - Stop time [MET] (default: 0.0) - debug - Enable debugging (default: False) + Simulation and binned analysis pipeline + + Parameters + ---------- + obs : `~gammalib.GObservations` + Observation container + ra : float, optional + Right Ascension of Region of Interest centre (deg) + dec : float, optional + Declination of Region of Interest centre (deg) + rad : float, optional + Radius of Region of Interest (deg) + emin : float, optional + Minimum energy (TeV) + emax : float, optional + Maximum energy (TeV) + tmin : float, optional + Start time (s) + tmax : float, optional + Stop time (s) + debug : bool, optional + Debug function """ # Simulate events sim = ctools.ctobssim(obs) - sim["debug"] = debug + sim['debug'] = debug sim.run() # Select events select = ctools.ctselect(sim.obs()) - select["ra"] = ra - select["dec"] = dec - select["rad"] = rad - select["emin"] = emin - select["emax"] = emax - select["tmin"] = tmin - select["tmax"] = tmax - select["debug"] = debug + select['ra'] = ra + select['dec'] = dec + select['rad'] = rad + select['emin'] = emin + select['emax'] = emax + select['tmin'] = tmin + select['tmax'] = tmax + select['debug'] = debug select.run() # Perform maximum likelihood fitting like = ctools.ctlike(select.obs()) - like["debug"] = True # Switch this always on for results in console + like['debug'] = True # Switch this always on for results in console like.run() # Return @@ -141,9 +170,9 @@ def run_pipeline(obs, ra=83.63, dec=22.01, rad=3.0, if __name__ == '__main__': # Dump header - print("********************************************") - print("* CTA unbinned analysis pipeline *") - print("********************************************") + print('********************************************') + print('* CTA unbinned analysis pipeline *') + print('********************************************') # Setup observations obs = setup_observations()