Fitting to a real extended source

Weights used:

  • Spatial

This jupyter notebook fits for the polarization of a real extended source. The source (Crab) was prepared in the previous notebook. This notebook extracts the the pulsar’s phase-averaged and nebula spatially-averaged polarization separately.

[1]:
import leakagelib
>>> PyXSPEC is not installed, you will no be able to use it.

First we load the 2-8 keV data. Since the spatial weights image created last notebook was centered at IXPE pixel (300, 300) by default, we center the IXPE data on (300, 300)

[2]:
# Load the extended source data
datas = leakagelib.IXPEData.load_all_detectors_with_path("data", "02006001")

for data in datas:
    data.explicit_center(300,300)
    data.retain(data.evt_energies > 2)
    data.retain(data.evt_energies < 8)
>>> Reading (in memory) /opt/homebrew/anaconda3/lib/python3.12/site-packages/ixpeobssim/caldb/ixpe/xrt/bcf/vign/ixpe_d1_obssim20240101_vign_v013.fits...

The spatial weights image we created in the last notebook should be loaded using Source.load_file:

[3]:
settings = leakagelib.FitSettings(datas)
source = leakagelib.Source.load_file("data/13146/crab.fits")
settings.add_source(source, "neb")
settings.fix_flux("neb", 1)
settings.set_initial_qu("neb", (0, 0))

We’ll set an ROI of 60 arcseconds, to avoid the more complicated structures farther than the pulsar.

[4]:
settings.apply_circular_roi(60)
636247 events were cut for being outside the region of interest.

Now we create a fitter object so we can compare the data to the fitter’s prediction…

[5]:
fitter = leakagelib.Fitter(settings)
fitter.plot();
Data set 02006001 DU 1 had no exposure map loaded. Please load an exposure map if you are fitting to events in the vignetted portion.
/Users/jtd/Documents/research/ixpepl/code/leakagelib/src/leakagelib/ps_fit/fitter.py:197: RuntimeWarning: invalid value encountered in divide
  pred /= counts
../_images/examples_fit-extended-real_9_1.png

…but clearly, these images are not aligned. This is because the IXPE WCS is not aligned with the Chandra WCS. In a real analysis, I suggest editing the IXPE events file header (and the exposure map header, if using) to make it match the Chandra WCS. But for this demo we can fix the problem by just shifting the IXPE data set. I found using DS9 that CXO and IXPE are offset by 10.4 pixels in the horizontal direction and 1.3 pixels in the vertical. So we recenter at that position:

[6]:
datas = leakagelib.IXPEData.load_all_detectors_with_path("data", "02006001")

for data in datas:
    data.explicit_center(300 - 10.4, 300 - 1.3)
    data.retain(data.evt_energies > 2)
    data.retain(data.evt_energies < 8)

settings = leakagelib.FitSettings(datas)
settings.add_source(source, "neb")
settings.fix_flux("neb", 1)
settings.set_initial_qu("neb", (0, 0))
settings.apply_circular_roi(60)

fitter = leakagelib.Fitter(settings)
fitter.plot();
>>> Using cached xVignetting object at /opt/homebrew/anaconda3/lib/python3.12/site-packages/ixpeobssim/caldb/ixpe/xrt/bcf/vign/ixpe_d1_obssim20240101_vign_v013.fits...
509977 events were cut for being outside the region of interest.
Data set 02006001 DU 1 had no exposure map loaded. Please load an exposure map if you are fitting to events in the vignetted portion.
../_images/examples_fit-extended-real_11_1.png

That matches well. Now we need to add a source to represent the pulsar. Since the pulsar is at the origin, we can use the Source.add_point_source method.

[7]:
settings.add_point_source("psr")
settings.set_initial_flux("psr", 0.2)
settings.set_initial_qu("psr", (0, 0))

fitter = leakagelib.Fitter(settings)
fitter.plot();
Data set 02006001 DU 1 had no exposure map loaded. Please load an exposure map if you are fitting to events in the vignetted portion.
../_images/examples_fit-extended-real_13_1.png

Finally, we perform the fit

[8]:
result = fitter.fit()
result
[8]:
FitResult:
        q (neb) = 0.0805 +/- 0.0044
        u (neb) = -0.1945 +/- 0.0044
        q (psr) = -0.2596 +/- 0.0271
        u (psr) = 0.0173 +/- 0.0272
        f (psr) = 0.0973 +/- 0.0006

Polarization:
        PD (neb): 0.2105 +/- 0.0044
        PA (neb): -33.7610 deg +/- 0.5994
        PD (psr): 0.2601 +/- 0.0271
        PA (psr): 88.0959 deg +/- 2.9948
Likelihood 580849.3410922358, dof 2080089
Optimization terminated successfully.

The pulsar’s phase-averaged polarization is insignificant, which has been found in other analyses. The nebula’s very significant polarization is consistent with a magnetic field running diagonally from the upper left to lower right. More careful analyses have mapped this EVPA and found EVPA tangent to the torus, which is consistent with this result.