test_irf_method.py

Knödlseder Jürgen, 04/09/2020 02:27 PM

Download (2.07 KB)

 
1
#! /usr/bin/env python
2
import gammalib
3

    
4
# Allocate response
5
rsp_dol = '/project-data/integral/ic/spi/rsp/spi_irf_grp_0021.fits'
6
rsp     = gammalib.GSPIResponse(rsp_dol)
7
print(rsp)
8

    
9
# Set response
10
og_dol  = '/Users/jurgen/git/gammalib/gammalib/inst/spi/test/data/obs/og_spi.fits'
11
obs     = gammalib.GSPIObservation(og_dol)
12
rsp.set(obs)
13
print(rsp)
14

    
15
# Save response
16
rsp.save('irf.fits', True)
17

    
18
# Loop over event bins
19
for bin in obs.events():
20

    
21
    # Print event bin
22
    #print(bin)
23

    
24
    # Get SPI_X direction for bin
25
    spi_x = obs.events().spi_x(bin.ipt())
26
    spi_z = obs.events().spi_z(bin.ipt())
27
    #print(spi_x)
28

    
29
    # Allocate sky map
30
    map = gammalib.GSkyMap('ARC', 'CEL', spi_x.ra_deg(), spi_x.dec_deg(), 0.1, 0.1, 2000, 1500)
31
    #print(map)
32

    
33
    # Compute response for all sky map pixels
34
    for i in range(map.npix()):
35

    
36
        # Get Sky direction
37
        dir = map.inx2dir(i)
38
        #print(dir)
39

    
40
        # Get IRF
41
        irf = rsp.irf(dir, bin, 0)
42
        #break
43

    
44
        # Set sky map bin
45
        map[i] = irf
46

    
47
    # Set x direction
48
    pixel = map.dir2pix(spi_x)
49
    print(pixel)
50
    for dx in range(10):
51
        p1 = map.pix2inx(gammalib.GSkyPixel(pixel.x()+dx, pixel.y()))
52
        p2 = map.pix2inx(gammalib.GSkyPixel(pixel.x()-dx, pixel.y()))
53
        p3 = map.pix2inx(gammalib.GSkyPixel(pixel.x(), pixel.y()+dx))
54
        p4 = map.pix2inx(gammalib.GSkyPixel(pixel.x(), pixel.y()-dx))
55
        map[p1] = 32000.0
56
        map[p2] = 32000.0
57
        map[p3] = 32000.0
58
        map[p4] = 32000.0
59

    
60
    # Set z direction
61
    pixel = map.dir2pix(spi_z)
62
    for dx in range(5):
63
        for dy in range(5):
64
            p1 = map.pix2inx(gammalib.GSkyPixel(pixel.x()+dx, pixel.y()+dy))
65
            p2 = map.pix2inx(gammalib.GSkyPixel(pixel.x()+dx, pixel.y()-dy))
66
            p3 = map.pix2inx(gammalib.GSkyPixel(pixel.x()-dx, pixel.y()+dy))
67
            p4 = map.pix2inx(gammalib.GSkyPixel(pixel.x()-dx, pixel.y()-dy))
68
            map[p1] = 32000.0
69
            map[p2] = 32000.0
70
            map[p3] = 32000.0
71
            map[p4] = 32000.0
72

    
73
    # Save sky map
74
    map.save('irf_map.fits', True)
75

    
76
    # Break
77
    break