test_disk_approximation.py
2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/env python
# ==========================================================================
# Approximate radial disk function
# --------------------------------------------------------------------------
#
# Copyright (C) 2020 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ==========================================================================
import math
import gammalib
import matplotlib.pyplot as plt
# ========================== #
# Compare radial model to MC #
# ========================== #
def show(theta0, k=1000.0, rad_max=1.0, nrad=1000):
"""
Show smooth approximation of radial disk function.
"""
# Get dummy energy and time
energy = gammalib.GEnergy()
time = gammalib.GTime()
# Generate theta vector
theta_bin = rad_max/nrad
theta = [(i+0.5) * theta_bin for i in range(nrad)]
# Generate model vector
model = [1.0 / (1.0 + math.exp(-k * (theta0 - t))) for t in theta]
disk = [1.0 if t < theta0 else 0.0 for t in theta]
# Create figure
plt.figure(1)
plt.title('Smooth approximation of radial disk function')
# Plot data
plt.plot(theta, model, 'r-')
plt.plot(theta, disk, 'g-')
# Set axes
plt.xlabel('Offset (deg)')
plt.ylabel('Arbitrary units')
# Notify
print('PLEASE CLOSE WINDOW TO CONTINUE ...')
# Show plot
plt.show()
# Return
return
# ======================== #
# Main routine entry point #
# ======================== #
if __name__ == '__main__':
# Show radial model
show(0.5)