Commit 223e98112a1beb2accec1925d6019d1386026d77
1 parent
f6150a99
Improve show_resmap.py script
Showing
1 changed file
with
39 additions
and
6 deletions
examples/show_resmap.py
| @@ -29,11 +29,44 @@ try: | @@ -29,11 +29,44 @@ try: | ||
| 29 | except (ImportError, RuntimeError): | 29 | except (ImportError, RuntimeError): |
| 30 | print('This script needs the "matplotlib" module') | 30 | print('This script needs the "matplotlib" module') |
| 31 | sys.exit() | 31 | sys.exit() |
| 32 | -try: | ||
| 33 | - import numpy as np | ||
| 34 | -except ImportError: | ||
| 35 | - print('This script needs the "numpy" module') | ||
| 36 | - 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 | ||
| 37 | 70 | ||
| 38 | 71 | ||
| 39 | # ================= # | 72 | # ================= # |
| @@ -56,7 +89,7 @@ def plot_resmap(filename, nbins, plotfile): | @@ -56,7 +89,7 @@ def plot_resmap(filename, nbins, plotfile): | ||
| 56 | map = gammalib.GSkyMap(filename) | 89 | map = gammalib.GSkyMap(filename) |
| 57 | 90 | ||
| 58 | # Create array of values | 91 | # Create array of values |
| 59 | - values = map.array() | 92 | + values = create_array(map) |
| 60 | 93 | ||
| 61 | # Create histogram | 94 | # Create histogram |
| 62 | _, bins, _ = plt.hist(values, nbins, range=[-4.0,4.0], | 95 | _, bins, _ = plt.hist(values, nbins, range=[-4.0,4.0], |