show_zenithangle.py

Knödlseder Jürgen, 10/04/2016 09:44 AM

Download (4.53 KB)

 
1
#! /usr/bin/env python
2
# ==========================================================================
3
# This script computes a visibility cube
4
#
5
# Copyright (C) 2016 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 math
22
import gammalib
23
import matplotlib.pyplot as plt
24

    
25

    
26
# =============== #
27
# Plot visibility #
28
# =============== #
29
def plot_visibility(ra):
30
    """
31
    Plot visibility
32
    """
33
    # Load visibility cube
34
    cube = gammalib.GSkyMap(file)
35

    
36
    # Create figure
37
    plt.figure(1)
38
    plt.title(title)
39

    
40
    # Plot visibility
41
    #decs = [float(i*10)-90.0 for i in range(18)]
42
    decs = [-64.4, -54.4, -44.4, -34.4, -24.4, -14.4, -4.4, 5.6, 15.6]
43
    for dec in decs:
44

    
45
        # Get RA,DEC index
46
        index = int(ra) + int((dec+90.0))*360
47

    
48
        # Extract vectors
49
        zeniths    = [float(i) for i in range(cube.nmaps())]
50
        visibility = [cube[index, i] for i in range(cube.nmaps())]
51
        print(dec, sum(visibility))
52

    
53
        # Plot visibility
54
        plt.plot(zeniths, visibility, 'r-')
55

    
56
    # Set axes
57
    plt.xlabel('Zenith angle (degrees)')
58
    plt.ylabel('Visibility (hours)')
59

    
60
    # Return
61
    return
62

    
63

    
64
# ================= #
65
# Plot zenith angle #
66
# ================= #
67
def plot_zenith_angle(ra):
68
    """
69
    Plot zenith angle
70
    """
71
    # Load visibility cube
72
    cube = gammalib.GSkyMap(file)
73

    
74
    # Create figure
75
    plt.figure(2)
76
    plt.title(title)
77

    
78
    # Plot visibility
79
    zeniths    = [float(i) for i in range(60)]
80
    visibility = [0.0 for i in range(60)]
81
    for izenith, zenith in enumerate(zeniths):
82

    
83
        # Extract vectors
84
        visibility[izenith] = sum([cube[i,izenith] for i in range(cube.npix())])
85

    
86
    # Plot visibility
87
    plt.plot(zeniths, visibility, 'r-')
88

    
89
    # Set axes
90
    plt.xlabel('Zenith (degrees)')
91
    plt.ylabel('Visibility * Solid angle (hours deg$^2$)')
92
    plt.xlim([0,60])
93

    
94
    # Return
95
    return
96

    
97

    
98
# ================ #
99
# Plot declination #
100
# ================ #
101
def plot_declination(ra):
102
    """
103
    """
104
    # Load visibility cube
105
    cube = gammalib.GSkyMap(file)
106

    
107
    # Create figure
108
    plt.figure(3)
109
    plt.title(title)
110

    
111
    # Plot visibility
112
    decs       = [float(i)-89.5 for i in range(180)]
113
    visibility = [0.0 for i in range(180)]
114
    for idec, dec in enumerate(decs):
115

    
116
        # Get RA,DEC index
117
        index = int(ra) + idec*360
118

    
119
        # Extract vectors
120
        visibility[idec] = sum([cube[index, i] for i in range(cube.nmaps())])
121

    
122
    # Plot visibility
123
    plt.plot(decs, visibility, 'r-')
124

    
125
    # Set axes
126
    plt.xlabel('Declination (degrees)')
127
    plt.ylabel('Visibility (hours)')
128
    plt.xlim([-90,90])
129

    
130
    # Return
131
    return
132

    
133

    
134
# ========================= #
135
# Plot minimum zenith angle #
136
# ========================= #
137
def plot_min_zenith(ra):
138
    """
139
    """
140
    # Load visibility cube
141
    cube = gammalib.GSkyMap(file)
142

    
143
    # Create figure
144
    plt.figure(4)
145
    plt.title(title)
146

    
147
    # Determine minimum zenith angle for each declination
148
    decs = [float(i)-89.5 for i in range(180)]
149
    x    = []
150
    y    = []
151
    for idec, dec in enumerate(decs):
152

    
153
        # Get RA,DEC index
154
        index = int(ra) + idec*360
155

    
156
        # Search first non-zero zenith angle
157
        for iz in range(cube.nmaps()):
158
            if cube[index, iz] > 0.0:
159
                x.append(dec)
160
                y.append(float(iz))
161
                break
162

    
163
    # Plot visibility
164
    plt.plot(x, y, 'r-')
165

    
166
    # Set axes
167
    plt.xlabel('Declination (degrees)')
168
    plt.ylabel('Minimum zenith angle (deg)')
169
    plt.xlim([-90,90])
170

    
171
    # Return
172
    return
173

    
174

    
175
#==========================#
176
# Main routine entry point #
177
#==========================#
178
if __name__ == '__main__':
179

    
180
    # Set parameters
181
    #file  = 'viscube_north.fits'
182
    #title = 'CTA North'
183
    file  = 'viscube_south.fits'
184
    title = 'CTA South'
185
    ra    = 220.0
186

    
187
    # Plot zenith angle
188
    plot_visibility(ra)
189
    plot_zenith_angle(ra)
190
    plot_declination(ra)
191
    plot_min_zenith(ra)
192

    
193
    # Show plot
194
    plt.show()