diff --git a/cscripts/cshessobs.py b/cscripts/cshessobs.py index 9d0482e..5ddca56 100755 --- a/cscripts/cshessobs.py +++ b/cscripts/cshessobs.py @@ -374,8 +374,8 @@ class cshessobs(ctools.cscript): # Initialise empty xml file and append an observation list self.xml = gammalib.GXml() - self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")); - lib = self.xml.element("observation_list", 0); + self.xml.append(gammalib.GXmlElement("observation_list title=\"observation list\"")) + lib = self.xml.element("observation_list", 0) # Read runlist from file runlist = [] diff --git a/cscripts/cspull.py b/cscripts/cspull.py index 8723fc7..9c4a686 100755 --- a/cscripts/cspull.py +++ b/cscripts/cspull.py @@ -337,16 +337,16 @@ class cspull(ctools.cscript): """ # Setup observation definition list - obsdeflist = obsutils.set_obs_patterns(self.m_pattern, \ - ra=self["ra"].real(), dec=self["dec"].real(), \ + 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(), \ + 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 @@ -366,14 +366,14 @@ class cspull(ctools.cscript): self.log.header2("Trial "+str(seed+1)) # Simulate events - obs = obsutils.sim(self.obs, \ - nbins=self.m_enumbins, \ - seed=seed, \ - binsz=self.m_binsz, \ - npix=self.m_npix, \ - edisp=self.m_edisp, \ - log=self.m_log, \ - debug=self.m_debug, \ + obs = obsutils.sim(self.obs, + nbins=self.m_enumbins, + seed=seed, + binsz=self.m_binsz, + npix=self.m_npix, + edisp=self.m_edisp, + log=self.m_log, + debug=self.m_debug, chatter=self.m_chatter) # If stacked, add stacked responses and model @@ -398,14 +398,14 @@ class cspull(ctools.cscript): models = obs.models() for i in range(models.size()): model_name = models[i].name() - like = obsutils.cterror(obs, model_name, \ - log=self.m_log, \ + like = obsutils.cterror(obs, model_name, + log=self.m_log, debug=self.m_debug, chatter=self.m_chatter) else: - like = obsutils.fit(obs, edisp=self.m_edisp, \ - log=self.m_log, \ - debug=self.m_debug, \ + like = obsutils.fit(obs, edisp=self.m_edisp, + log=self.m_log, + debug=self.m_debug, chatter=self.m_chatter) # Store results diff --git a/cscripts/cssens.py b/cscripts/cssens.py index 0fbfb3b..11edebc 100755 --- a/cscripts/cssens.py +++ b/cscripts/cssens.py @@ -166,8 +166,8 @@ class cssens(ctools.cscript): self.m_debug = self["debug"].boolean() # Debugging in client tools # Derive some parameters - self.m_ebounds = gammalib.GEbounds(self.m_bins, \ - gammalib.GEnergy(self.m_emin, "TeV"), \ + self.m_ebounds = gammalib.GEbounds(self.m_bins, + gammalib.GEnergy(self.m_emin, "TeV"), gammalib.GEnergy(self.m_emax, "TeV")) # Return @@ -200,7 +200,7 @@ class cssens(ctools.cscript): self.log("\n") # Initialise script - colnames = ['loge', 'emin', 'emax', 'crab_flux', 'photon_flux', \ + colnames = ['loge', 'emin', 'emax', 'crab_flux', 'photon_flux', 'energy_flux', 'sensitivity'] results = [] @@ -242,7 +242,7 @@ class cssens(ctools.cscript): raise gammalib.GException.invalid_value("cssens", msg) # Determine sensitivity - result = self.get_sensitivity(self.obs, emin, emax, \ + result = self.get_sensitivity(self.obs, emin, emax, bkg_model, full_model) # Write results @@ -297,8 +297,8 @@ class cssens(ctools.cscript): pntdir.lb_deg(lpnt, bpnt) # Create CTA observation - run = obsutils.set_obs(pntdir, caldb=caldb, irf=irf, \ - duration=duration, deadc=deadc, \ + run = obsutils.set_obs(pntdir, caldb=caldb, irf=irf, + duration=duration, deadc=deadc, emin=emin, emax=emax, rad=rad) # Append observation to container @@ -464,8 +464,8 @@ class cssens(ctools.cscript): obs.models(src_model) # Simulate events - sim = obsutils.sim(obs, nbins=self.m_enumbins, seed=iter, \ - binsz=self.m_binsz, npix=self.m_npix, \ + sim = obsutils.sim(obs, nbins=self.m_enumbins, seed=iter, + binsz=self.m_binsz, npix=self.m_npix, log=self.m_log, debug=self.m_debug) # Determine number of events in simulation diff --git a/cscripts/cstsdist.py b/cscripts/cstsdist.py index a428bbd..af633fa 100755 --- a/cscripts/cstsdist.py +++ b/cscripts/cstsdist.py @@ -328,16 +328,19 @@ class cstsdist(ctools.cscript): """ # Setup observation definition list - obsdeflist = obsutils.set_obs_patterns(self.m_pattern, \ - ra=self["ra"].real(), dec=self["dec"].real(), \ + 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(), \ + 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 @@ -355,11 +358,11 @@ class cstsdist(ctools.cscript): self.log.header2("Trial "+str(seed+1)) # Simulate events - sim = obsutils.sim(self.obs, \ - nbins=self.m_enumbins, \ - seed=seed, \ - binsz=self.m_binsz, \ - npix=self.m_npix, \ + sim = obsutils.sim(self.obs, + nbins=self.m_enumbins, + seed=seed, + binsz=self.m_binsz, + npix=self.m_npix, log=self.m_log, debug=self.m_debug) # Determine number of events in simulation diff --git a/examples/benchmark_cta_analysis.py b/examples/benchmark_cta_analysis.py index 7cd45e1..96f827a 100755 --- a/examples/benchmark_cta_analysis.py +++ b/examples/benchmark_cta_analysis.py @@ -20,7 +20,6 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib import ctools import time try: diff --git a/examples/check_models.py b/examples/check_models.py index cc1d8d8..936d61d 100755 --- a/examples/check_models.py +++ b/examples/check_models.py @@ -24,114 +24,113 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib -import ctools import sys +import ctools # ================= # # Analysis pipeline # # ================= # def pipeline(model_name): - """ - Unbinned analysis pipeline - keep intermediate results in memory. - + """ + Unbinned analysis pipeline - keep intermediate results in memory. + This function implements an analysis pipeline that successively calls ctobssim, ctselect and ctlike without saving the intermediate results as - FITS files on disk. All data is only hold in memory. - """ - # Set script parameters - caldb = "prod2" - irf = "South_50h" - ra = 83.63 - dec = 22.01 - rad_sim = 10.0 - tstart = 0.0 - tstop = 1800.0 - emin = 0.1 - emax = 100.0 - rad_select = 3.0 - - # Write model name - print("*** Model: "+model_name+" ************************************") - - # Initialise timing - wall_seconds = 0.0 - cpu_seconds = 0.0 - - # Simulate events - sim = ctools.ctobssim() - sim["inmodel"] = model_name - sim["caldb"] = caldb - sim["irf"] = irf - sim["ra"] = ra - sim["dec"] = dec - sim["rad"] = rad_sim - sim["tmin"] = tstart - sim["tmax"] = tstop - sim["emin"] = emin - sim["emax"] = emax - sim.run() - - # Select events - select = ctools.ctselect(sim.obs()) - select["ra"] = ra - select["dec"] = dec - select["rad"] = rad_select - select["tmin"] = tstart - select["tmax"] = tstop - select["emin"] = emin - select["emax"] = emax - select.run() - - # Perform maximum likelihood fitting - like = ctools.ctlike(select.obs()) - like.run() - - # Show model fitting results - print(like.obs().models()[0]) - - # Return - return + FITS files on disk. All data is only hold in memory. + """ + # Set script parameters + caldb = "prod2" + irf = "South_50h" + ra = 83.63 + dec = 22.01 + rad_sim = 10.0 + tstart = 0.0 + tstop = 1800.0 + emin = 0.1 + emax = 100.0 + rad_select = 3.0 + + # Write model name + print("*** Model: "+model_name+" ************************************") + + # Initialise timing + wall_seconds = 0.0 + cpu_seconds = 0.0 + + # Simulate events + sim = ctools.ctobssim() + sim["inmodel"] = model_name + sim["caldb"] = caldb + sim["irf"] = irf + sim["ra"] = ra + sim["dec"] = dec + sim["rad"] = rad_sim + sim["tmin"] = tstart + sim["tmax"] = tstop + sim["emin"] = emin + sim["emax"] = emax + sim.run() + + # Select events + select = ctools.ctselect(sim.obs()) + select["ra"] = ra + select["dec"] = dec + select["rad"] = rad_select + select["tmin"] = tstart + select["tmax"] = tstop + select["emin"] = emin + select["emax"] = emax + select.run() + + # Perform maximum likelihood fitting + like = ctools.ctlike(select.obs()) + like.run() + + # Show model fitting results + print(like.obs().models()[0]) + + # Return + return #==========================# # Main routine entry point # #==========================# if __name__ == '__main__': - """ - Perform unbinned analyses for various models. - """ - # Initialise flags - need_help = False - - # Test for command line arguments - print(sys.argv[0]) - if (len(sys.argv) > 1): - if sys.argv[1] == "-h": - need_help = True - else: - need_help = True - - # Print help if needed and exit - if need_help: - print("Usage: check_models.py [OPTIONS]") - print(" -h Display this usage message") - sys.exit() - - # Dump header - print("*******************************************") - print("* Check models using an unbinned analysis *") - print("*******************************************") - - # Perform analysis for Crab model - pipeline("$CTOOLS/share/models/crab.xml") - - # Perform analysis for disk model - pipeline("$CTOOLS/share/models/disk.xml") - - # Perform analysis for Gaussian model - pipeline("$CTOOLS/share/models/gauss.xml") - - # Perform analysis for shell model - pipeline("$CTOOLS/share/models/shell.xml") + """ + Perform unbinned analyses for various models. + """ + # Initialise flags + need_help = False + + # Test for command line arguments + print(sys.argv[0]) + if (len(sys.argv) > 1): + if sys.argv[1] == "-h": + need_help = True + else: + need_help = True + + # Print help if needed and exit + if need_help: + print("Usage: check_models.py [OPTIONS]") + print(" -h Display this usage message") + sys.exit() + + # Dump header + print("*******************************************") + print("* Check models using an unbinned analysis *") + print("*******************************************") + + # Perform analysis for Crab model + pipeline("$CTOOLS/share/models/crab.xml") + + # Perform analysis for disk model + pipeline("$CTOOLS/share/models/disk.xml") + + # Perform analysis for Gaussian model + pipeline("$CTOOLS/share/models/gauss.xml") + + # Perform analysis for shell model + pipeline("$CTOOLS/share/models/shell.xml") diff --git a/examples/make_pointings.py b/examples/make_pointings.py index 8ed3d79..259e06a 100755 --- a/examples/make_pointings.py +++ b/examples/make_pointings.py @@ -23,9 +23,9 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib import sys import math +import gammalib # ============================================================ # @@ -82,8 +82,8 @@ def get_positions(xmin, xmax, ymin, ymax, step): # ====================== # # Setup patch on the sky # # ====================== # -def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, \ - separation=3.0, hours=100.0, \ +def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, + separation=3.0, hours=100.0, site=None, lst=True, autodec=0.0): """ Setup pointing patch on the sky. @@ -147,11 +147,11 @@ def set_patch(lmin=-30.0, lmax=30.0, bmin=-1.5, bmax=+1.5, \ # Dump statistics print("Number of pointings: %d (%.2f sec)" % (n_pnt,duration)) - print("South array .......: %.2f hours (%.2f%%)" % \ - (exposure_south/3600.0, \ + print("South array .......: %.2f hours (%.2f%%)" % + (exposure_south/3600.0, 100.0*exposure_south/(exposure_south+exposure_north))) - print("North array .......: %.2f hours (%.2f%%)" % \ - (exposure_north/3600.0, \ + print("North array .......: %.2f hours (%.2f%%)" % + (exposure_north/3600.0, 100.0*exposure_north/(exposure_south+exposure_north))) # Return observation definition @@ -169,28 +169,28 @@ def set_gps(separation=3.0, bmin=-1.3, bmax=1.3, lst=True): obsdef = [] # Add inner region South - obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax, \ - separation=separation, hours=780, \ + obsdef.extend(set_patch(lmin=-60.0, lmax=60.0, bmin=bmin, bmax=bmax, + separation=separation, hours=780, site="South", lst=lst)) # Add Vela & Carina region - obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax, \ - separation=separation, hours=180, \ + obsdef.extend(set_patch(lmin=240.0, lmax=300.0, bmin=bmin, bmax=bmax, + separation=separation, hours=180, site="South", lst=lst)) # Add 210-240 region - obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax, \ - separation=separation, hours=60, \ + obsdef.extend(set_patch(lmin=210.0, lmax=240.0, bmin=bmin, bmax=bmax, + separation=separation, hours=60, site="South", lst=lst)) # Add Cygnus, Perseus - obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax, \ - separation=separation, hours=450, \ + obsdef.extend(set_patch(lmin=60.0, lmax=150.0, bmin=bmin, bmax=bmax, + separation=separation, hours=450, site="North", lst=lst)) # Add Anticentre - obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax, \ - separation=separation, hours=150, \ + obsdef.extend(set_patch(lmin=150.0, lmax=210.0, bmin=bmin, bmax=bmax, + separation=separation, hours=150, site="North", lst=lst)) # Return observation definition @@ -208,8 +208,8 @@ def set_extgal(separation=3.0, lst=True): obsdef = [] # Set patch - obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0, \ - separation=separation, hours=1000, \ + obsdef.extend(set_patch(lmin=-90.0, lmax=90.0, bmin=+5.0, bmax=+88.0, + separation=separation, hours=1000, site="Automatic", lst=lst, autodec=10.0)) # Return observation definition @@ -227,13 +227,13 @@ def set_gc(lst=True): obsdef = [] # Central wobble - obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5, \ - separation=0.1, hours=525, \ + obsdef.extend(set_patch(lmin=-0.5, lmax=0.5, bmin=-0.5, bmax=0.5, + separation=0.1, hours=525, site="South", lst=lst)) # Extended region - obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0, \ - separation=1.5, hours=300, \ + obsdef.extend(set_patch(lmin=-10.0, lmax=10.0, bmin=-10.0, bmax=10.0, + separation=1.5, hours=300, site="South", lst=lst)) # Return observation definition @@ -322,7 +322,7 @@ def write_obsdef(filename, obsdef): dec = obs["dec"] # Write information - file.write("%8.4f,%8.4f,%.4f,%s,%s\n" % \ + file.write("%8.4f,%8.4f,%.4f,%s,%s\n" % (ra, dec, obs['duration'], obs['caldb'], obs['irf'])) # Close file @@ -387,5 +387,4 @@ if __name__ == '__main__': # Invalid pattern else: - print("Unknown option \""+obsname+"\"") - + print('Unknown option "' + obsname + '"') diff --git a/examples/make_pull_at_sensitivity_limit.py b/examples/make_pull_at_sensitivity_limit.py index fda1105..937a20c 100755 --- a/examples/make_pull_at_sensitivity_limit.py +++ b/examples/make_pull_at_sensitivity_limit.py @@ -24,11 +24,11 @@ # along with this program. If not, see . # # ========================================================================== -from ctools import * -from gammalib import * -from cspull import * import sys import time +import csv +import gammalib +from cscripts import cspull # Try importing processing module has_processing = False @@ -42,7 +42,7 @@ except: # ======================== # # Create pull distribution # # ======================== # -def create_pull(loge, emin, emax, models, ntrials=100, duration=180000.0, \ +def create_pull(loge, emin, emax, models, ntrials=100, duration=180000.0, enumbins=0, log=False): """ Create pull distribution @@ -94,8 +94,8 @@ def create_model(flux, index=-2.48, fitidx=False): flux - Flux in Crab units """ # Define background model - bgd_radial = GCTAModelRadialGauss(3.0) - bgd_spectrum = GModelSpectralPlaw(61.8, -1.85) + bgd_radial = gammalib.GCTAModelRadialGauss(3.0) + bgd_spectrum = gammalib.GModelSpectralPlaw(61.8, -1.85) bgd_spectrum["Prefactor"].scale(1.0e-6) bgd_spectrum["PivotEnergy"].value(1.0) bgd_spectrum["PivotEnergy"].scale(1.0e6) @@ -103,15 +103,15 @@ def create_model(flux, index=-2.48, fitidx=False): bgd_spectrum["Index"].free() else: bgd_spectrum["Index"].fix() - bgd_model = GCTAModelRadialAcceptance(bgd_radial, bgd_spectrum) + bgd_model = gammalib.GCTAModelRadialAcceptance(bgd_radial, bgd_spectrum) bgd_model.name("Background") bgd_model.instruments("CTA") # Define source spectrum - location = GSkyDir() + location = gammalib.GSkyDir() location.radec_deg(83.6331, 22.0145) - src_spatial = GModelSpatialPtsrc(location) - src_spectrum = GModelSpectralPlaw(flux, index) + src_spatial = gammalib.GModelSpatialPtsrc(location) + src_spectrum = gammalib.GModelSpectralPlaw(flux, index) src_spectrum["Prefactor"].scale(5.7e-16) src_spectrum["PivotEnergy"].value(0.3) src_spectrum["PivotEnergy"].scale(1.0e6) @@ -119,11 +119,11 @@ def create_model(flux, index=-2.48, fitidx=False): src_spectrum["Index"].free() else: src_spectrum["Index"].fix() - src_model = GModelPointSource(src_spatial, src_spectrum) + src_model = gammalib.GModelPointSource(src_spatial, src_spectrum) src_model.name("Test") # Add models to container - models = GModels() + models = gammalib.GModels() models.append(bgd_model) models.append(src_model) @@ -141,7 +141,11 @@ if __name__ == '__main__': cssens script. """ # Get input arguments - usage = "make_pull_at_sensitivity_limit filename [max_threads]" + usage = """ + make_pull_at_sensitivity_limit filename [max_threads] + + Run cssens to create the input file. + """ if len(sys.argv) < 2 or len(sys.argv) > 3: print(usage) sys.exit() diff --git a/examples/make_spectrum.py b/examples/make_spectrum.py index 4492633..bc3820e 100755 --- a/examples/make_spectrum.py +++ b/examples/make_spectrum.py @@ -20,7 +20,7 @@ # ========================================================================== import gammalib import ctools -from ctools import obsutils +from cscripts import obsutils try: import matplotlib.pyplot as plt has_matplotlib = True @@ -84,10 +84,10 @@ def plot_spectrum(spectrum): plt.title("Crab spectrum") # Plot spectrum - plt.loglog(spectrum['energy']['value'], \ + plt.loglog(spectrum['energy']['value'], spectrum['flux']['value'], 'ro', label='Crab') - plt.errorbar(spectrum['energy']['value'], \ - spectrum['flux']['value'], \ + plt.errorbar(spectrum['energy']['value'], + spectrum['flux']['value'], spectrum['flux']['ed_value'], ecolor='r') # Put labels @@ -115,4 +115,3 @@ if __name__ == '__main__': # Plot spectrum if has_matplotlib: plot_spectrum(spectrum) - \ No newline at end of file diff --git a/examples/make_survey.py b/examples/make_survey.py index 9fafb21..f5fb536 100755 --- a/examples/make_survey.py +++ b/examples/make_survey.py @@ -23,11 +23,12 @@ # along with this program. If not, see . # # ========================================================================== -import gammalib -from ctools import obsutils import os import glob import sys +import math +import gammalib +from cscripts import obsutils # =========== # @@ -86,7 +87,7 @@ def plot_counts(obs): counts[index] = counts[index] + 1.0 # Create error bars - error = [sqrt(c) for c in counts] + error = [math.sqrt(c) for c in counts] # Plot spectrum plt.loglog(energy, counts, 'ro', label='data') @@ -140,7 +141,7 @@ def plot_counts(obs): counts[index] = counts[index] + 1.0 # Create error bars - error = [sqrt(c) for c in counts] + error = [math.sqrt(c) for c in counts] # Plot distribution #plt.semilogy(offset2, counts, 'ro', label='data') diff --git a/examples/make_ts_distributions.py b/examples/make_ts_distributions.py index 3b5daa8..ca9d0ed 100755 --- a/examples/make_ts_distributions.py +++ b/examples/make_ts_distributions.py @@ -28,9 +28,9 @@ # along with this program. If not, see . # # ========================================================================== -from ctools.cstsdist import * import sys import time +from cscripts import cstsdist # Try importing processing module has_processing = False @@ -44,7 +44,7 @@ except: # ====================== # # Create TS distribution # # ====================== # -def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, \ +def create_ts(loge, emin, emax, ntrials=100, duration=180000.0, enumbins=0, log=False): """ Create TS distribution. @@ -110,9 +110,9 @@ if __name__ == '__main__': max_threads = 1 # Parameter dictionnary - pars = [{'option': '-n', 'value': ntrials}, \ - {'option': '-e', 'value': enumbins}, \ - {'option': '-d', 'value': duration}, \ + pars = [{'option': '-n', 'value': ntrials}, + {'option': '-e', 'value': enumbins}, + {'option': '-d', 'value': duration}, {'option': '-m', 'value': max_threads}] # Gather parameters from command line @@ -165,7 +165,7 @@ if __name__ == '__main__': # Set arguments args = (loge, emin, emax) - kwargs = {'ntrials': ntrials, 'enumbins': enumbins, \ + kwargs = {'ntrials': ntrials, 'enumbins': enumbins, 'duration': duration} # Generate pull distribution @@ -178,7 +178,7 @@ if __name__ == '__main__': # ... no else: - create_ts(loge, emin, emax, ntrials=ntrials, enumbins=enumbins, \ + create_ts(loge, emin, emax, ntrials=ntrials, enumbins=enumbins, duration=duration) # Processing support diff --git a/examples/pipeline_binned_disk.py b/examples/pipeline_binned_disk.py index 21830a5..7c71c3d 100755 --- a/examples/pipeline_binned_disk.py +++ b/examples/pipeline_binned_disk.py @@ -27,15 +27,15 @@ # ========================================================================== import gammalib import ctools -from ctools import obsutils +from cscripts import obsutils # ================== # # Setup observations # # ================== # -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, \ +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. @@ -54,18 +54,18 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \ irf - Instrument response function (default: cta_dummy_irf) """ # Set list of observations - obs_def_list = obsutils.set_obs_patterns(pattern, \ - ra=ra, \ - dec=dec, \ + 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, \ + obs = obsutils.set_obs_list(obs_def_list, + duration=duration, + emin=emin, + emax=emax, + rad=rad, + caldb=caldb, irf=irf) # Return observation container @@ -92,11 +92,11 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): # ================================ # # Simulation and analysis pipeline # # ================================ # -def run_pipeline(obs, emin=0.1, emax=100.0, \ - enumbins=20, nxpix=200, nypix=200, binsz=0.02, \ - coordsys="CEL", proj="CAR", \ - model="${CTOOLS}/share/models/crab.xml", \ - caldb="prod2", irf="South_50h", \ +def run_pipeline(obs, emin=0.1, emax=100.0, + enumbins=20, nxpix=200, nypix=200, binsz=0.02, + coordsys="CEL", proj="CAR", + model="${CTOOLS}/share/models/crab.xml", + caldb="prod2", irf="South_50h", debug=False): """ Simulation and binned analysis pipeline. diff --git a/examples/pipeline_binned_mem.py b/examples/pipeline_binned_mem.py index 010f274..389787b 100755 --- a/examples/pipeline_binned_mem.py +++ b/examples/pipeline_binned_mem.py @@ -27,15 +27,15 @@ # ========================================================================== import gammalib import ctools -from ctools import obsutils +from cscripts import obsutils # ================== # # Setup observations # # ================== # -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, \ +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. @@ -54,18 +54,18 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \ irf - Instrument response function (default: cta_dummy_irf) """ # Set list of observations - obs_def_list = obsutils.set_obs_patterns(pattern, \ - ra=ra, \ - dec=dec, \ + 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, \ + obs = obsutils.set_obs_list(obs_def_list, + duration=duration, + emin=emin, + emax=emax, + rad=rad, + caldb=caldb, irf=irf) # Return observation container @@ -92,8 +92,8 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): # ================================ # # Simulation and analysis pipeline # # ================================ # -def run_pipeline(obs, emin=0.1, emax=100.0, \ - enumbins=20, nxpix=200, nypix=200, binsz=0.02, \ +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): """ Simulation and binned analysis pipeline. diff --git a/examples/pipeline_stacked_disk.py b/examples/pipeline_stacked_disk.py index d6aa738..e0876fa 100755 --- a/examples/pipeline_stacked_disk.py +++ b/examples/pipeline_stacked_disk.py @@ -27,15 +27,15 @@ # ========================================================================== import gammalib import ctools -from ctools import obsutils +from cscripts import obsutils # ================== # # Setup observations # # ================== # -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, \ +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. @@ -54,18 +54,18 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \ irf - Instrument response function (default: cta_dummy_irf) """ # Set list of observations - obs_def_list = obsutils.set_obs_patterns(pattern, \ - ra=ra, \ - dec=dec, \ + 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, \ + obs = obsutils.set_obs_list(obs_def_list, + duration=duration, + emin=emin, + emax=emax, + rad=rad, + caldb=caldb, irf=irf) # Return observation container @@ -92,11 +92,11 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): # ================================ # # Simulation and analysis pipeline # # ================================ # -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="${CTOOLS}/share/models/crab.xml", \ - caldb="prod2", irf="South_50h", \ +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="${CTOOLS}/share/models/crab.xml", + caldb="prod2", irf="South_50h", debug=False): """ Simulation and stacked analysis pipeline. diff --git a/examples/pipeline_stacked_mem.py b/examples/pipeline_stacked_mem.py index c48bfa8..7e6477d 100755 --- a/examples/pipeline_stacked_mem.py +++ b/examples/pipeline_stacked_mem.py @@ -27,15 +27,15 @@ # ========================================================================== import gammalib import ctools -from ctools import obsutils +from cscripts import obsutils # ================== # # Setup observations # # ================== # -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, \ +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. @@ -54,18 +54,18 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \ irf - Instrument response function (default: cta_dummy_irf) """ # Set list of observations - obs_def_list = obsutils.set_obs_patterns(pattern, \ - ra=ra, \ - dec=dec, \ + 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, \ + obs = obsutils.set_obs_list(obs_def_list, + duration=duration, + emin=emin, + emax=emax, + rad=rad, + caldb=caldb, irf=irf) # Return observation container @@ -92,8 +92,8 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): # ================================ # # Simulation and analysis pipeline # # ================================ # -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, \ +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): """ Simulation and stacked analysis pipeline. diff --git a/examples/pipeline_unbinned_disk.py b/examples/pipeline_unbinned_disk.py index e10425d..b81e20d 100755 --- a/examples/pipeline_unbinned_disk.py +++ b/examples/pipeline_unbinned_disk.py @@ -27,15 +27,15 @@ # ========================================================================== import gammalib import ctools -from ctools import obsutils +from cscripts import obsutils # ================== # # Setup observations # # ================== # -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, \ +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. @@ -54,18 +54,18 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \ irf - Instrument response function (default: cta_dummy_irf) """ # Set list of observations - obs_def_list = obsutils.set_obs_patterns(pattern, \ - ra=ra, \ - dec=dec, \ + 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, \ + obs = obsutils.set_obs_list(obs_def_list, + duration=duration, + emin=emin, + emax=emax, + rad=rad, + caldb=caldb, irf=irf) # Return observation container @@ -92,11 +92,11 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): # ================================ # # Simulation and analysis pipeline # # ================================ # -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="${CTOOLS}/share/models/crab.xml", \ - caldb="prod2", irf="South_50h", \ +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="${CTOOLS}/share/models/crab.xml", + caldb="prod2", irf="South_50h", debug=False): """ Simulation and unbinned analysis pipeline. diff --git a/examples/pipeline_unbinned_mem.py b/examples/pipeline_unbinned_mem.py index 3c31df1..d34c09e 100755 --- a/examples/pipeline_unbinned_mem.py +++ b/examples/pipeline_unbinned_mem.py @@ -27,15 +27,15 @@ # ========================================================================== import gammalib import ctools -from ctools import obsutils +from cscripts import obsutils # ================== # # Setup observations # # ================== # -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, \ +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. @@ -54,18 +54,18 @@ def setup_observations(pattern="four", ra=83.63, dec=22.01, offset=1.5, \ irf - Instrument response function (default: cta_dummy_irf) """ # Set list of observations - obs_def_list = obsutils.set_obs_patterns(pattern, \ - ra=ra, \ - dec=dec, \ + 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, \ + obs = obsutils.set_obs_list(obs_def_list, + duration=duration, + emin=emin, + emax=emax, + rad=rad, + caldb=caldb, irf=irf) # Return observation container @@ -92,9 +92,9 @@ def setup_model(obs, model="${CTOOLS}/share/models/crab.xml"): # ================================ # # Simulation and analysis pipeline # # ================================ # -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, \ +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, debug=False): """ Simulation and unbinned analysis pipeline. diff --git a/examples/show_pha.py b/examples/show_pha.py index a8b358e..e9a3450 100755 --- a/examples/show_pha.py +++ b/examples/show_pha.py @@ -24,7 +24,7 @@ # ========================================================================== import sys import math -from gammalib import * +import gammalib # ================= # @@ -93,7 +93,7 @@ if __name__ == '__main__': filename = sys.argv[1] # Load PHA spectrum - pha = GPha(filename) + pha = gammalib.GPha(filename) #print(pha) # Try importing matplotlib diff --git a/examples/show_response.py b/examples/show_response.py index bcd8632..e6a5aaa 100755 --- a/examples/show_response.py +++ b/examples/show_response.py @@ -265,18 +265,18 @@ if __name__ == '__main__': # Set response dictionary rsps = [ - {'dbname': "dummy", \ - 'rspname': "cta_dummy_irf", \ - 'name': "Prod1 (Array E, MPIK)", \ - 'color': "b"}, \ - {'dbname': "e", \ - 'rspname': "IFAE20120510_50h", \ - 'name': "Prod1 (Array E, IFAE)", \ - 'color': "g"}, \ - {'dbname': "aar", \ - 'rspname': "DESY20140105_50h", \ - 'name': "Prod2 (Aar, DESY)", \ - 'color': "r"} \ + {'dbname': "dummy", + 'rspname': "cta_dummy_irf", + 'name': "Prod1 (Array E, MPIK)", + 'color': "b"}, + {'dbname': "e", + 'rspname': "IFAE20120510_50h", + 'name': "Prod1 (Array E, IFAE)", + 'color': "g"}, + {'dbname': "aar", + 'rspname': "DESY20140105_50h", + 'name': "Prod2 (Aar, DESY)", + 'color': "r"} ] # Loop over all responses @@ -297,4 +297,3 @@ if __name__ == '__main__': # Show plot plt.show() - \ No newline at end of file diff --git a/examples/show_ts_distribution.py b/examples/show_ts_distribution.py index 13dcdb8..06de278 100755 --- a/examples/show_ts_distribution.py +++ b/examples/show_ts_distribution.py @@ -178,8 +178,8 @@ def dist_pdf(values, nbins, title): nbins += 1 # Create histogram - n, bins, patches = plt.hist(values, nbins, range=[min_value, max_value], \ - align='mid', facecolor='green', \ + n, bins, patches = plt.hist(values, nbins, range=[min_value, max_value], + align='mid', facecolor='green', log=True, label="simulations") # Create expected distribution (onyl for positive TS). We compute the @@ -239,9 +239,9 @@ if __name__ == '__main__': plot = "pdf" # Parameter dictionnary - pars = [{'option': '-n', 'value': nbins}, \ - {'option': '-c', 'value': tsname}, \ - {'option': '-t', 'value': title}, \ + pars = [{'option': '-n', 'value': nbins}, + {'option': '-c', 'value': tsname}, + {'option': '-t', 'value': title}, {'option': '-p', 'value': plot}] # Gather parameters from command line @@ -280,5 +280,3 @@ if __name__ == '__main__': dist_pdf(values, nbins, title) else: dist_cdf(values, nbins, title) - - \ No newline at end of file diff --git a/examples/simulate_events.py b/examples/simulate_events.py index ff8801d..100a14a 100755 --- a/examples/simulate_events.py +++ b/examples/simulate_events.py @@ -36,8 +36,8 @@ except: # ======================== # # Create CTA observation # # ======================== # -def createobs(ra=86.171648, dec=-1.4774586, rad=5.0, \ - emin=0.1, emax=100.0, duration=360000.0, deadc=0.95, \ +def createobs(ra=86.171648, dec=-1.4774586, rad=5.0, + emin=0.1, emax=100.0, duration=360000.0, deadc=0.95, irf="South_50h", caldb="prod2"): """ Create CTA observation.