test.py

Knödlseder Jürgen, 04/12/2017 09:35 AM

Download (2.52 KB)

 
1
#! /usr/bin/env python
2

    
3
import gammalib
4
import ctools as ct
5
import matplotlib as mp
6
import matplotlib.pyplot as plt
7

    
8

    
9
def _scatter(array1, array2, xtitle="", ytitle="", maintitle=""):
10
    plt.scatter(array1, array2, marker=".")
11
    plt.ylabel(ytitle)
12
    plt.xlabel(xtitle)
13
    plt.show()
14

    
15
def _plot_energy(filename):
16
    events = gammalib.GCTAEventList(filename)
17
    event_num = [events[i].event_id() for i in range(events.size())]
18
    energy_TeV = [events[i].energy().TeV() for i in range(events.size())]
19
    _scatter(event_num, energy_TeV, "Event Number", "Energy [TeV]")
20

    
21
def _plot_phase(filename):
22
    events    = gammalib.GCTAEventList(filename)
23
    fits      = gammalib.GFits("phased_events.fits")
24
    event_num = [events[i].event_id() for i in range(events.size())]
25
    times     = [events[i].time().mjd() for i in range(events.size())]
26
    phases    = [fits[1]["PHASE"][i] for i in range(fits[1]["PHASE"].length())]
27
    _scatter(times, phases, "MJD", "Phase")
28

    
29
def _plot_energy_time(filename):
30
    events = gammalib.GCTAEventList(filename)
31
    energy_TeV = [events[i].energy().TeV() for i in range(events.size())]
32
    times = [events[i].time().mjd() for i in range(events.size())]
33
    _scatter(times, energy_TeV, "MJD", "Energy [TeV]")
34

    
35
def _plot_phase_distribution(filename):
36
    fits      = gammalib.GFits(filename)
37
    phases    = [fits[1]["PHASE"][i] for i in range(fits[1]["PHASE"].length())]
38
    plt.hist(phases, 10)
39
    plt.xlim(0.,1.)
40
    plt.ylabel("Counts")
41
    plt.xlabel("Phase")
42
    plt.show()
43

    
44
if __name__ == '__main__':
45

    
46
    # Simulate some data with no phase information
47
    obs = ct.ctobssim()
48
    obs["inobs"] = ""
49
    obs["inmodel"] = "test_model.xml"
50
    obs["outevents"] = "events.fits"
51
    obs["caldb"] = "prod2"
52
    obs["irf"] = "South_0.5h"
53
    obs["ra"] = 83.63
54
    obs["dec"] = 22.01
55
    obs["rad"] = 2.5
56
    obs["tmin"] = 0
57
    obs["tmax"] = 1800
58
    obs["emin"] = 0.1
59
    obs["emax"] = 100.0
60
    obs.execute()
61

    
62
    # Append phase information to the events data
63
    phase = ct.ctphase()
64
    phase["inobs"] = "events.fits"
65
    phase["outobs"] = "phased_events.fits"
66
    phase["inmodel"] = "test_model.xml"
67
    phase["srcname"] = "Crab"
68
    phase["mjd"] = 51544.5
69
    phase["phase"] = 0.0
70
    phase["f0"] = 0.2345
71
    phase["f1"] = -1.0e-10
72
    phase["f2"] = -1.0e-13
73
    phase.logFileOpen()
74
    phase.execute()
75

    
76
    # Plot the phase values
77
    #_plot_energy("events.fits")
78

    
79
    #_plot_energy("phased_events.fits")
80

    
81
    _plot_phase("phased_events.fits")
82

    
83
    _plot_phase_distribution("phased_events.fits")
84

    
85
    #_plot_energy_time("events.fits")
86