Commit 59a13a3d72c28122be5e4f94d884946da121e5e1

Authored by Jürgen Knödlseder
1 parent 2a41df90

Remove show_resmap.py script (not relevant)

Showing 1 changed file with 0 additions and 152 deletions
examples/show_resmap.py deleted
1   -#! /usr/bin/env python
2   -# ==========================================================================
3   -# Shows histogram of residual map
4   -#
5   -# Copyright (C) 2018 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 sys
22   -import gammalib
23   -import cscripts
24   -try:
25   - import matplotlib.pyplot as plt
26   - import matplotlib.mlab as mlab
27   - plt.figure()
28   - plt.close()
29   -except (ImportError, RuntimeError):
30   - print('This script needs the "matplotlib" module')
31   - sys.exit()
32   -
33   -
34   -# ============ #
35   -# Create array #
36   -# ============ #
37   -def create_array(map,step_nx=10,step_ny=10,step_neng=1):
38   - """
39   - """
40   - # Initialise array of values
41   - values = []
42   -
43   - # Loop over sky map
44   - for ix in range(0,map.nx(),step_nx):
45   - for iy in range(0,map.ny(),step_ny):
46   - for ieng in range(0,map.nmaps(),step_neng):
47   -
48   - # Initialise value
49   - value = 0.0
50   -
51   - # Loop over sub block
52   - for ix_sub in range(step_nx):
53   - ix_abs = ix + ix_sub
54   - if ix_abs < map.nx():
55   - for iy_sub in range(step_ny):
56   - iy_abs = iy + iy_sub
57   - if iy_abs < map.ny():
58   - inx = ix_abs + iy_abs*map.nx()
59   - for ieng_sub in range(step_neng):
60   - ieng_abs = ieng + ieng_sub
61   - if ieng_abs < map.nmaps():
62   - value += map(inx,ieng_abs)
63   -
64   - # If value differs from zero than append it
65   - if value != 0.0:
66   - values.append(value)
67   -
68   - # Return values
69   - return values
70   -
71   -
72   -# ================= #
73   -# Plot residual map #
74   -# ================= #
75   -def plot_resmap(filename, nbins, plotfile):
76   - """
77   - Plot pull histogram
78   -
79   - Parameters
80   - ----------
81   - filename : str
82   - Residual map filename
83   - nbins : int
84   - Number of hisogram bins
85   - plotfile : str
86   - Plot filename
87   - """
88   - # Open residual map
89   - map = gammalib.GSkyMap(filename)
90   -
91   - # Create array of values
92   - values = create_array(map)
93   -
94   - # Create histogram
95   - _, bins, _ = plt.hist(values, nbins, range=[-4.0,4.0],
96   - normed=True, facecolor='green')
97   -
98   - # Create expected distribution
99   - y = mlab.normpdf(bins, 0.0, 1.0)
100   - plt.plot(bins, y, 'r-', linewidth=2)
101   -
102   - # Set plot
103   - plt.xlabel('Pull')
104   - plt.ylabel('Arbitrary units')
105   - #plt.title(parname)
106   - plt.grid(True)
107   -
108   - # Show figure
109   - if len(plotfile) > 0:
110   - plt.savefig(plotfile)
111   - else:
112   - plt.show()
113   -
114   - # Return
115   - return
116   -
117   -
118   -# ================= #
119   -# Show residual map #
120   -# ================= #
121   -def show_resmap():
122   - """
123   - Show residual map
124   - """
125   - # Set usage string
126   - usage = 'show_resmap.py [-n bins] [-p plotfile] file'
127   -
128   - # Set default options
129   - options = [{'option': '-n', 'value': '50'},
130   - {'option': '-p', 'value': ''}]
131   -
132   - # Get arguments and options from command line arguments
133   - args, options = cscripts.ioutils.get_args_options(options, usage)
134   -
135   - # Extract script parameters from options
136   - nbins = int(options[0]['value'])
137   - plotfile = options[1]['value']
138   -
139   - # Plot residual map
140   - plot_resmap(args[0], nbins, plotfile)
141   -
142   - # Return
143   - return
144   -
145   -
146   -# ======================== #
147   -# Main routine entry point #
148   -# ======================== #
149   -if __name__ == '__main__':
150   -
151   - # Show residual map
152   - show_resmap()