king.py

Knödlseder Jürgen, 02/17/2013 12:41 AM

Download (2.25 KB)

 
1
#! /usr/bin/env python
2
# ===========================================================================================#
3
# This script checks the King profile integration
4
# ===========================================================================================#
5
import math
6
import matplotlib.pyplot as plt
7

    
8

    
9
# ============================= #
10
# Show King profile integration #
11
# ============================= #
12
def show(sigma, gamma, color):
13
    """
14
    Show photons using matplotlib (if available).
15
    """
16
    # Set binning
17
    num   = 1000
18
    delta = 0.1
19
    
20
    # Create r axis
21
    r = []
22
    for i in range(num):
23
        r.append(i*delta)
24

    
25
    # Create integral curve
26
    integral = []
27
    sigma2   = sigma*sigma
28
    for i in range(num):
29
        u     = 0.5 * r[i] * r[i] / sigma2
30
        value = 1.0 - math.pow(1.0+u/gamma, 1.0-gamma)
31
        integral.append(value)
32

    
33
    # Compute 68% r value
34
    F    = 0.68
35
    u_68 = gamma * (math.pow(1.0-F, 1.0/(1.0-gamma)) - 1.0)
36
    r_68 = sigma * math.sqrt(2.0 * u_68)
37
    print r_68, u_68
38

    
39
    # Show integral
40
    plt.plot(r, integral, color)
41
    plt.plot([r_68, r_68], [0.0, 0.68], color)
42
    plt.plot([0.0, r_68], [0.68, 0.68], color)
43
    plt.xlabel("r")
44
    plt.ylabel("Integral")
45

    
46
    # Return
47
    return
48

    
49

    
50
# ======================= #
51
# Show slope versus gamma #
52
# ======================= #
53
def slope(F, color):
54
    """
55
    Show slope versus gamma.
56
    """
57
    # Set binning
58
    gmin  = 1.3
59
    gmax  = 2.5
60
    delta = 0.05
61
    num   = int((gmax-gmin)/delta)+2
62
    
63
    # Create gamma axis
64
    g = []
65
    for i in range(num):
66
        g.append(gmin+i*delta)
67

    
68
    # Compute slope
69
    slope = []
70
    for i in range(num):
71
        umax = g[i] * (math.pow(1.0-F, 1.0/(1.0-g[i])) - 1.0)
72
        s    = 1.0/math.sqrt(2.0 * umax)
73
        slope.append(s)
74

    
75
    # Show integral
76
    plt.plot(g, slope, color)
77
    plt.xlabel("Gamma")
78
    plt.ylabel("Slope")
79

    
80
    # Return
81
    return
82

    
83

    
84
#==========================#
85
# Main routine entry point #
86
#==========================#
87
if __name__ == '__main__':
88
    """
89
    Compute integral
90
    """
91
    plt.figure(1)
92
    #show(0.5, 2.0, "r-")
93
    #show(1.0, 1.5, "b-.")
94
    #show(1.0, 2.0, "b-")
95
    #show(1.0, 2.5, "b--")
96
    #show(2.0, 2.0, "g-")
97
    
98
    show(1.0, 1.2, "r-")
99
    
100
    #slope(0.68, "ro")
101
    
102
    plt.show()