test_crab_fit.py

Knödlseder Jürgen, 04/09/2020 03:19 PM

Download (1.42 KB)

 
1
#! /usr/bin/env python
2
import os
3
import gammalib
4
import ctools
5

    
6
# Set globals
7
og_dol  = '/Users/jurgen/git/gammalib/gammalib/inst/spi/test/data/obs/og_spi.fits'
8
rsp_dol = '/project-data/integral/ic/spi/rsp/spi_irf_grp_0021.fits'
9

    
10

    
11
# ====== #
12
# ctlike #
13
# ====== #
14
def ctlike():
15
    """
16
    """
17
    # Create observations
18
    og  = gammalib.GSPIObservation(og_dol)
19
    rsp = gammalib.GSPIResponse(rsp_dol)
20
    rsp.set(og)
21
    og.response(rsp)
22
    obs = gammalib.GObservations()
23
    obs.append(og)
24

    
25
    # Set sky model
26
    spatial   = gammalib.GModelSpatialPointSource(83.6331, +22.0145)
27
    spatial['RA'].free()
28
    spatial['DEC'].free()
29
    spectral  = gammalib.GModelSpectralPlaw(1.0e-5, -2.0, gammalib.GEnergy(0.1, 'MeV'))
30
    sky_model = gammalib.GModelSky(spatial, spectral)
31
    sky_model.name('Crab')
32
    sky_model.tscalc(True)
33

    
34
    # Set background model
35
    bgm_model = gammalib.GSPIModelDataSpace(og, 'GEDSAT', 'orbit,dete', 0)
36

    
37
    # Create model and append it to observations
38
    models = gammalib.GModels()
39
    models.append(sky_model)
40
    models.append(bgm_model)
41
    obs.models(models)
42

    
43
    # Run ctlike
44
    like = ctools.ctlike(obs)
45
    like['outmodel'] = 'ctlike.xml'
46
    like['chatter']  = 3
47
    like['debug']    = True
48
    like.logFileOpen()
49
    like.execute()
50

    
51
    # Return
52
    return
53

    
54

    
55
# ======================== #
56
# Main routine entry point #
57
# ======================== #
58
if __name__ == '__main__':
59

    
60
    # Run ctlike
61
    ctlike()