test-filefunction.py
1 |
#! /usr/bin/env python
|
---|---|
2 |
# ==========================================================================
|
3 |
# Test file function
|
4 |
#
|
5 |
# Copyright (C) 2017 Juergen Knoedlseder
|
6 |
#
|
7 |
# This program is free software: you can redistribute it and/or modify
|
8 |
# it under the terms of the GNU General Public License as published by
|
9 |
# the Free Software Foundation, either version 3 of the License, or
|
10 |
# (at your option) any later version.
|
11 |
#
|
12 |
# This program is distributed in the hope that it will be useful,
|
13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
# GNU General Public License for more details.
|
16 |
#
|
17 |
# You should have received a copy of the GNU General Public License
|
18 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 |
#
|
20 |
# ==========================================================================
|
21 |
import gammalib |
22 |
import math |
23 |
import matplotlib.pyplot as plt |
24 |
|
25 |
|
26 |
# ========= #
|
27 |
# Make plot #
|
28 |
# ========= #
|
29 |
def make_plot(tmin, tmax, rate=100.0, bins=100): |
30 |
"""
|
31 |
Make plot
|
32 |
"""
|
33 |
# Load temporal file function
|
34 |
filefct = gammalib.GModelTemporalFunc("temp_filefunction.fits")
|
35 |
|
36 |
# Set reference time (should be able to extract that from file function?)
|
37 |
tref = gammalib.GTimeReference(51544.5,"s") |
38 |
|
39 |
# Set random number generator
|
40 |
ran = gammalib.GRan() |
41 |
|
42 |
# Create times
|
43 |
times = filefct.mc(rate, gammalib.GTime(tmin, tref), |
44 |
gammalib.GTime(tmax, tref), ran) |
45 |
|
46 |
# Convert times to seconds
|
47 |
seconds = [time.convert(tref) for time in times] |
48 |
|
49 |
# Create time vector for eval
|
50 |
norm = rate/float(bins)
|
51 |
eval_time = [float(i) for i in range(1800)] |
52 |
eval_value = [filefct.eval(gammalib.GTime(t, tref))*norm for t in eval_time] |
53 |
|
54 |
|
55 |
# Create figure
|
56 |
plt.figure(1)
|
57 |
|
58 |
# Plot file function
|
59 |
plt.plot(eval_time, eval_value) |
60 |
|
61 |
# Plot histogram
|
62 |
plt.hist(seconds, bins=bins) |
63 |
|
64 |
# Show plot
|
65 |
plt.show() |
66 |
|
67 |
# Return
|
68 |
return
|
69 |
|
70 |
|
71 |
# ======================== #
|
72 |
# Main routine entry point #
|
73 |
# ======================== #
|
74 |
if __name__ == '__main__': |
75 |
|
76 |
# Make plot
|
77 |
#make_plot(0.0, 1800.0, rate=1000000.0)
|
78 |
#make_plot(100.0, 1450.0, rate=1000000.0)
|
79 |
#make_plot(410.0, 1000.0, rate=1000000.0)
|
80 |
#make_plot(1178.0, 3000.0, rate=1000000.0)
|
81 |
#make_plot(2000.0, 3000.0, rate=1000000.0)
|
82 |
make_plot(-1000.0, -100.0, rate=1000000.0) |