Fitting a model with polarization using ixpeOGIPSpectrumLike

Using ixpeOGIPSpectrumLike, this tutorial will download simulated data and run joint likelihood and Bayesian analyses.

[1]:
import os
import matplotlib.pyplot as plt
import numpy as np

from threeML import *
from astromodels.core.polarization import *
from ixpepy.ixpeOGIPSpectrumLike import ixpeOGIPSpectrumLike
from ixpepy.utils.stokes import get_polarization_angle, get_polarization_degree
17:19:11 WARNING   The naima package is not available. Models that depend on it will not be         functions.py:45
                  available                                                                                        
         WARNING   The GSL library or the pygsl wrapper cannot be loaded. Models that depend on it  functions.py:67
                  will not be available.                                                                           
         WARNING   The ebltable package is not available. Models that depend on it will not be     absorption.py:34
                  available                                                                                        
17:19:12 INFO      Starting 3ML!                                                                     __init__.py:44
         WARNING   WARNINGs here are NOT errors                                                      __init__.py:45
         WARNING   but are inform you about optional packages that can be installed                  __init__.py:46
         WARNING    to disable these messages, turn off start_warning in your config file            __init__.py:47
         WARNING   ROOT minimizer not available                                                minimization.py:1208
         INFO      IXPE plugin found. Enabling Gaussian source with Gaussian background. spectrum_likelihood.py:397
17:19:13 WARNING   The cthreeML package is not installed. You will not be able to use plugins which  __init__.py:95
                  require the C/C++ interface (currently HAWC)                                                     
         WARNING   Could not import plugin HAWCLike.py. Do you have the relative instrument         __init__.py:136
                  software installed and configured?                                                               
         WARNING   Env. variable OMP_NUM_THREADS is not set. Please set it to 1 for optimal         __init__.py:345
                  performances in 3ML                                                                              
         WARNING   Env. variable MKL_NUM_THREADS is not set. Please set it to 1 for optimal         __init__.py:345
                  performances in 3ML                                                                              
         WARNING   Env. variable NUMEXPR_NUM_THREADS is not set. Please set it to 1 for optimal     __init__.py:345
                  performances in 3ML                                                                              

Downloading the simulated data

[2]:
from io import BytesIO
from urllib.request import urlopen
from zipfile import ZipFile

zipurl = "https://www.dropbox.com/scl/fi/thw3ql0must8vvh34509v/toy_point_source.zip?rlkey=4b9zs2g4ue3u82d7lg2340heq&st=spirza10&dl=1"

with urlopen(zipurl) as zipresp:
    with ZipFile(BytesIO(zipresp.read())) as zfile:
        zfile.extractall('.')

Creating the model

[3]:
source_name = 'toy_point_source'
RA = 30.
DEC = 40.

spectral_shape = Powerlaw() #Spectral shapes defined by astromodels.functions
spectral_shape.K = 20
spectral_shape.index = -2

polarization   = StokesPolarization(Q=Constant(), U=Constant())
polarization.Q.Constant.k.bounds = (-1, 1)
polarization.U.Constant.k.bounds = (-1, 1)
#polarization.Q.Constant.k.prior = Uniform_prior(lower_bound=-1.0, upper_bound=1.0)
#polarization.U.Constant.k.prior = Uniform_prior(lower_bound=-1.0, upper_bound=1.0)

point_source = PointSource( source_name, RA, DEC, spectral_shape = spectral_shape, polarization = polarization)

model = Model(point_source)

model.display(complete = True)
Model summary:

N
Point sources 1
Extended sources 0
Particle sources 0


Free parameters (4):

value min_value max_value unit
toy_point_source.spectrum.main.Powerlaw.K 20.0 0.0 1000.0 keV-1 s-1 cm-2
toy_point_source.spectrum.main.Powerlaw.index -2.0 -10.0 10.0
toy_point_source.spectrum.main.polarization.Q.Constant.k 0.0 -1.0 1.0
toy_point_source.spectrum.main.polarization.U.Constant.k 0.0 -1.0 1.0


Fixed parameters (3):

value min_value max_value unit
toy_point_source.position.ra 30.0 0.0 360.0 deg
toy_point_source.position.dec 40.0 -90.0 90.0 deg
toy_point_source.spectrum.main.Powerlaw.piv 1.0 None None keV


Properties (0):

(none)


Linked parameters (0):

(none)

Independent variables:

(none)

Linked functions (0):

(none)

Creating the ixpeOGIPSpectrumLike object and retrieving the datalist

[4]:
emin, emax = 2, 8
obs_list=[]
for du in [1,2,3]:
    for stokes in ['', 'q', 'u']:
        obs_file = os.path.join('.', '%s_du%s_pha1%s.fits' % (source_name, du, stokes))
        obs_list.append(obs_file)
ixpe = ixpeOGIPSpectrumLike(energy_range='%d-%d' % (emin, emax), caldb=None)
ixpe.load_file_list(obs_list)
data = ixpe.get_datalist()
17:19:14 INFO      Loading the spectrum file: ./toy_point_source_du1_pha1.fits           ixpeOGIPSpectrumLike.py:81
         INFO      ixpeOGIPSpectrumLike will use Poisson errors for I                    ixpeOGIPSpectrumLike.py:89
         WARNING   Found 115 energy channels where STAT_ERR is 0: (array([216, 230,     ixpeOGIPSpectrumLike.py:208
                  242, 244, 250, 253, 257, 259, 260, 264, 266, 268, 269,                                           
                         270, 271, 274, 275, 276, 277, 279, 280, 281, 282, 283, 284,                               
                  285,                                                                                             
                         286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297,                               
                  298,                                                                                             
                         299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310,                               
                  311,                                                                                             
                         312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323,                               
                  324,                                                                                             
                         325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336,                               
                  337,                                                                                             
                         338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349,                               
                  350,                                                                                             
                         351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362,                               
                  363,                                                                                             
                         364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374]),)                                 
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
17:19:14 WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: poisson                                                       SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: I                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Loading the spectrum file: ./toy_point_source_du1_pha1q.fits          ixpeOGIPSpectrumLike.py:81
         WARNING   Found 115 energy channels where STAT_ERR is 0: (array([216, 230,     ixpeOGIPSpectrumLike.py:208
                  242, 244, 250, 253, 257, 259, 260, 264, 266, 268, 269,                                           
                         270, 271, 274, 275, 276, 277, 279, 280, 281, 282, 283, 284,                               
                  285,                                                                                             
                         286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297,                               
                  298,                                                                                             
                         299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310,                               
                  311,                                                                                             
                         312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323,                               
                  324,                                                                                             
                         325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336,                               
                  337,                                                                                             
                         338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349,                               
                  350,                                                                                             
                         351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362,                               
                  363,                                                                                             
                         364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374]),)                                 
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
         WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: gaussian                                                      SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: Q                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Remove channels with 0 counts for spectrum Q                         ixpeOGIPSpectrumLike.py:154
         INFO      Loading the spectrum file: ./toy_point_source_du1_pha1u.fits          ixpeOGIPSpectrumLike.py:81
         WARNING   Found 115 energy channels where STAT_ERR is 0: (array([216, 230,     ixpeOGIPSpectrumLike.py:208
                  242, 244, 250, 253, 257, 259, 260, 264, 266, 268, 269,                                           
                         270, 271, 274, 275, 276, 277, 279, 280, 281, 282, 283, 284,                               
                  285,                                                                                             
                         286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297,                               
                  298,                                                                                             
                         299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310,                               
                  311,                                                                                             
                         312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323,                               
                  324,                                                                                             
                         325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336,                               
                  337,                                                                                             
                         338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349,                               
                  350,                                                                                             
                         351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362,                               
                  363,                                                                                             
                         364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374]),)                                 
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
         WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: gaussian                                                      SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: U                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Remove channels with 0 counts for spectrum U                         ixpeOGIPSpectrumLike.py:154
         INFO      Loading the spectrum file: ./toy_point_source_du2_pha1.fits           ixpeOGIPSpectrumLike.py:81
         INFO      ixpeOGIPSpectrumLike will use Poisson errors for I                    ixpeOGIPSpectrumLike.py:89
         WARNING   Found 123 energy channels where STAT_ERR is 0: (array([232, 242,     ixpeOGIPSpectrumLike.py:208
                  245, 247, 249, 251, 253, 254, 255, 256, 257, 258, 259,                                           
                         260, 261, 263, 264, 265, 266, 267, 268, 270, 271, 272, 273,                               
                  274,                                                                                             
                         276, 277, 278, 279, 280, 282, 283, 284, 285, 286, 287, 288,                               
                  289,                                                                                             
                         290, 291, 292, 293, 294, 295, 296, 298, 299, 300, 301, 302,                               
                  303,                                                                                             
                         304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315,                               
                  316,                                                                                             
                         317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328,                               
                  329,                                                                                             
                         330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341,                               
                  342,                                                                                             
                         343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,                               
                  355,                                                                                             
                         356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367,                               
                  368,                                                                                             
                         369, 370, 371, 372, 373, 374]),)                                                          
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
         WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: poisson                                                       SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: I                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Loading the spectrum file: ./toy_point_source_du2_pha1q.fits          ixpeOGIPSpectrumLike.py:81
         WARNING   Found 123 energy channels where STAT_ERR is 0: (array([232, 242,     ixpeOGIPSpectrumLike.py:208
                  245, 247, 249, 251, 253, 254, 255, 256, 257, 258, 259,                                           
                         260, 261, 263, 264, 265, 266, 267, 268, 270, 271, 272, 273,                               
                  274,                                                                                             
                         276, 277, 278, 279, 280, 282, 283, 284, 285, 286, 287, 288,                               
                  289,                                                                                             
                         290, 291, 292, 293, 294, 295, 296, 298, 299, 300, 301, 302,                               
                  303,                                                                                             
                         304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315,                               
                  316,                                                                                             
                         317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328,                               
                  329,                                                                                             
                         330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341,                               
                  342,                                                                                             
                         343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,                               
                  355,                                                                                             
                         356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367,                               
                  368,                                                                                             
                         369, 370, 371, 372, 373, 374]),)                                                          
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
         WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: gaussian                                                      SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: Q                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Remove channels with 0 counts for spectrum Q                         ixpeOGIPSpectrumLike.py:154
         INFO      Loading the spectrum file: ./toy_point_source_du2_pha1u.fits          ixpeOGIPSpectrumLike.py:81
         WARNING   Found 123 energy channels where STAT_ERR is 0: (array([232, 242,     ixpeOGIPSpectrumLike.py:208
                  245, 247, 249, 251, 253, 254, 255, 256, 257, 258, 259,                                           
                         260, 261, 263, 264, 265, 266, 267, 268, 270, 271, 272, 273,                               
                  274,                                                                                             
                         276, 277, 278, 279, 280, 282, 283, 284, 285, 286, 287, 288,                               
                  289,                                                                                             
                         290, 291, 292, 293, 294, 295, 296, 298, 299, 300, 301, 302,                               
                  303,                                                                                             
                         304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315,                               
                  316,                                                                                             
                         317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328,                               
                  329,                                                                                             
                         330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341,                               
                  342,                                                                                             
                         343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,                               
                  355,                                                                                             
                         356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367,                               
                  368,                                                                                             
                         369, 370, 371, 372, 373, 374]),)                                                          
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
17:19:15 WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: gaussian                                                      SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
17:19:15 INFO      Plugin assigned to: U                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Remove channels with 0 counts for spectrum U                         ixpeOGIPSpectrumLike.py:154
         INFO      Loading the spectrum file: ./toy_point_source_du3_pha1.fits           ixpeOGIPSpectrumLike.py:81
         INFO      ixpeOGIPSpectrumLike will use Poisson errors for I                    ixpeOGIPSpectrumLike.py:89
         WARNING   Found 116 energy channels where STAT_ERR is 0: (array([238, 241,     ixpeOGIPSpectrumLike.py:208
                  247, 250, 252, 255, 257, 259, 260, 261, 262, 263, 264,                                           
                         265, 266, 267, 268, 269, 272, 274, 275, 276, 277, 278, 279,                               
                  280,                                                                                             
                         281, 282, 283, 284, 285, 287, 289, 290, 291, 292, 293, 294,                               
                  295,                                                                                             
                         296, 297, 298, 300, 301, 302, 303, 304, 305, 306, 307, 308,                               
                  309,                                                                                             
                         310, 311, 312, 314, 315, 316, 317, 318, 319, 320, 321, 322,                               
                  323,                                                                                             
                         324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335,                               
                  336,                                                                                             
                         337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348,                               
                  349,                                                                                             
                         350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361,                               
                  362,                                                                                             
                         363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374]),)                            
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
         WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: poisson                                                       SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: I                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Loading the spectrum file: ./toy_point_source_du3_pha1q.fits          ixpeOGIPSpectrumLike.py:81
         WARNING   Found 116 energy channels where STAT_ERR is 0: (array([238, 241,     ixpeOGIPSpectrumLike.py:208
                  247, 250, 252, 255, 257, 259, 260, 261, 262, 263, 264,                                           
                         265, 266, 267, 268, 269, 272, 274, 275, 276, 277, 278, 279,                               
                  280,                                                                                             
                         281, 282, 283, 284, 285, 287, 289, 290, 291, 292, 293, 294,                               
                  295,                                                                                             
                         296, 297, 298, 300, 301, 302, 303, 304, 305, 306, 307, 308,                               
                  309,                                                                                             
                         310, 311, 312, 314, 315, 316, 317, 318, 319, 320, 321, 322,                               
                  323,                                                                                             
                         324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335,                               
                  336,                                                                                             
                         337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348,                               
                  349,                                                                                             
                         350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361,                               
                  362,                                                                                             
                         363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374]),)                            
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
         WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: gaussian                                                      SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: Q                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Remove channels with 0 counts for spectrum Q                         ixpeOGIPSpectrumLike.py:154
         INFO      Loading the spectrum file: ./toy_point_source_du3_pha1u.fits          ixpeOGIPSpectrumLike.py:81
         WARNING   Found 116 energy channels where STAT_ERR is 0: (array([238, 241,     ixpeOGIPSpectrumLike.py:208
                  247, 250, 252, 255, 257, 259, 260, 261, 262, 263, 264,                                           
                         265, 266, 267, 268, 269, 272, 274, 275, 276, 277, 278, 279,                               
                  280,                                                                                             
                         281, 282, 283, 284, 285, 287, 289, 290, 291, 292, 293, 294,                               
                  295,                                                                                             
                         296, 297, 298, 300, 301, 302, 303, 304, 305, 306, 307, 308,                               
                  309,                                                                                             
                         310, 311, 312, 314, 315, 316, 317, 318, 319, 320, 321, 322,                               
                  323,                                                                                             
                         324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335,                               
                  336,                                                                                             
                         337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348,                               
                  349,                                                                                             
                         350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361,                               
                  362,                                                                                             
                         363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374]),)                            
         WARNING   Forcing the corresponding RATE channels to 0!                        ixpeOGIPSpectrumLike.py:209
         WARNING   Could not find QUALITY in columns or header of PHA file. This is not a valid pha_spectrum.py:201
                  OGIP file. Assuming QUALITY =0 (good)                                                            
         WARNING   Found TSTOP and TELAPSE. This file is invalid. Using TSTOP.                  pha_spectrum.py:249
         WARNING   FILTER is not set. This is not a compliant OGIP file. Assuming no FILTER.    pha_spectrum.py:385
         WARNING   Maximum MC energy (12.0) is smaller than maximum EBOUNDS energy (15.0)           response.py:125
         WARNING   Minimum MC energy (1.0) is larger than minimum EBOUNDS energy (0.0)              response.py:133
         INFO      Auto-probed noise models:                                                    SpectrumLike.py:478
         INFO      - observation: gaussian                                                      SpectrumLike.py:479
         INFO      - background: None                                                           SpectrumLike.py:480
         INFO      Plugin assigned to: U                                                ixpeOGIPSpectrumLike.py:151
         INFO      Range 2-8 translates to channels 49-199                                     SpectrumLike.py:1229
         INFO      Remove channels with 0 counts for spectrum U                         ixpeOGIPSpectrumLike.py:154

Fitting the data with JointLikelihood

[5]:
jl = JointLikelihood(model, data)
ixpe.fit_area_correction(model)

jl.fit()

results = jl.results
         INFO      set the minimizer to minuit                                              joint_likelihood.py:994
         INFO      Fitting an effective area correction for DU1                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU1_I is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU1                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU1_Q is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU1                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU1_U is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU2                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU2_I is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU2                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU2_Q is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU2                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU2_U is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU3                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU3_I is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU3                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU3_Q is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
         INFO      Fitting an effective area correction for DU3                         ixpeOGIPSpectrumLike.py:185
         INFO      ixpe_DU3_U is using effective area correction (between 0.5 and 1.2)         SpectrumLike.py:2216
Best fit values:

result unit
parameter
toy_point_source.spectrum.main.Powerlaw.K 9.84 +/- 0.04 1 / (cm2 keV s)
toy_point_source.spectrum.main.Powerlaw.index -1.998 +/- 0.004
toy_point_source...k (5.8 +/- 0.5) x 10^-2
toy_point_source...k (8.3 +/- 0.5) x 10^-2
cons_ixpe_DU2_I 1.0010 +/- 0.0024
cons_ixpe_DU3_I 1.0023 +/- 0.0024
Correlation matrix:

1.00-0.920.000.01-0.28-0.27
-0.921.00-0.01-0.010.00-0.00
0.00-0.011.000.000.00-0.00
0.01-0.010.001.00-0.000.00
-0.280.000.00-0.001.000.48
-0.27-0.00-0.000.000.481.00
Values of -log(likelihood) at the minimum:

-log(likelihood)
ixpe_DU1_I 694.526948
ixpe_DU1_Q 87.645864
ixpe_DU1_U 83.819290
ixpe_DU2_I 691.749668
ixpe_DU2_Q 68.628108
ixpe_DU2_U 88.687331
ixpe_DU3_I 687.240547
ixpe_DU3_Q 99.876708
ixpe_DU3_U 90.165734
total 2592.340199
Values of statistical measures:

statistical measures
AIC 5196.742528
BIC 5227.967425

Getting the results

[6]:
u = results.get_variates('toy_point_source.spectrum.main.polarization.U.Constant.k')
q = results.get_variates('toy_point_source.spectrum.main.polarization.Q.Constant.k')

pol_angle = get_polarization_angle(q, u)
pol_degree = get_polarization_degree(q, u)

print("PD: ", pol_degree)
print("PA: ", pol_angle)
PD:  equal-tail: (1.01 +/- 0.05) x 10^-1, hpd: (1.01 +/- 0.05) x 10^-1
PA:  equal-tail: (2.74 +/- 0.14) x 10, hpd: (2.74 -0.13 +0.15) x 10

Plotting spectrum and polarization

[7]:
%matplotlib inline
from ixpepy.io.plotting import plot_I_spectrum, plot_QU_spectra

figI = plot_I_spectrum(jl, emin, emax)
figQ, figU = plot_QU_spectra(jl, emin, emax, ymin=-3, ymax=3)
../_images/notebooks_ixpeOGIPSpectrumLike_example_13_0.png
../_images/notebooks_ixpeOGIPSpectrumLike_example_13_1.png
../_images/notebooks_ixpeOGIPSpectrumLike_example_13_2.png
[ ]:
from ixpepy.io.plotting import plot_QU_polar

fig = plot_QU_polar(q, u, sigma=True)
../_images/notebooks_ixpeOGIPSpectrumLike_example_14_0.png
[ ]:
from ixpepy.io.plotting import plot_QU

fig = plot_QU(q, u)
../_images/notebooks_ixpeOGIPSpectrumLike_example_15_0.png