Note
Go to the end to download the full example code.
Basic pulsar analysis using Fermi-LAT data#
7 from ptiming_ana.phaseogram import PulsarAnalysis
8 from astropy.io import fits
9 import numpy as np
10 import matplotlib.pyplot as plt
11
12 # sphinx_gallery_multi_image = "single"
Create the PulsarAnalysis object and settings#
18 h = PulsarAnalysis()
19 h.set_config('./example_data/config_tutorial.yaml')
Alternatively we can set the parameters directly#
25 h = PulsarAnalysis()
26 h.setBackgroundLimits([0.52,0.87])
27 h.setPeaklimits(
28 P1_limits=[0,0.026, 0.983, 1],
29 P2_limits=[0.377, 0.422],
30 P3_limits=None
31 )
32 h.setBinning(50, xmin=0, xmax=1)
33 h.setTimeInterval(tint=3600*24)
34 h.setFittingParams(model='dgaussian', binned=True)
35 h.setEnergybinning(
36 np.geomspace(0.1/1e3, 1/1e3, 3),
37 do_diff=True,
38 do_integral=False
39 ) # in TeV
Extracting phases, times and energies from file and give them to the object#
For Fermi data there is a class to read these lists and use them in the main object.
48 h.setFermiInputFile('./example_data/merged2_pulsar.fits')
But in general we can read our file (FITS, DL2, DL3…) and extract phases, times and energies as lists and read them as follows:
55 f=fits.open('./example_data/merged2_pulsar.fits')
56 fits_table=f[1].data
57
58 times=np.sort(fits_table['BARYCENTRIC_TIME'].byteswap().newbyteorder())
59 phases=fits_table['PULSE_PHASE'].byteswap().newbyteorder()
60 energies=fits_table['ENERGY'].byteswap().newbyteorder()
61
62 h.setListsInput(phases, times, energies/1e6, tel='fermi', energy_units='TeV')
63
64 h.get_results = False
Run the code#
71 h.run()
/home/runner/work/PulsarTimingAnalysis/PulsarTimingAnalysis/src/ptiming_ana/phaseogram/phase_regions.py:229: RuntimeWarning: divide by zero encountered in scalar divide
self.sign_ratio = self.sign / np.sqrt(tobs)
Show the results#
Overall results#
81 phaseogram=h.draw_phaseogram(
82 phase_limits=[0, 2],
83 colorhist='xkcd:baby blue'
84 )
85 plt.tight_layout()

89 results=h.show_Presults()
Result of the fitting#
97 h.fit_model
'dgaussian'
100 fit_result = h.show_fit_results()
103 phaseogram = h.draw_phaseogram(
104 phase_limits=[0, 2],
105 colorhist='xkcd:baby blue',
106 fit=True
107 )
108 plt.tight_layout()

Results vs Time#
115 TimeEv = h.show_timeEvolution()
The periodicity tests are not available since the signal is too strong (p_value too low to extrapolate a significance).
Results vs Energy#
127 h.show_lcVsEnergy()
[<Figure size 1200x500 with 1 Axes>, <Figure size 1200x500 with 1 Axes>]
130 energy_lc=h.show_all_lc(ylimits=None)
136 energy_plots=h.show_EnergyAna()

Fit vs Energy#
143 mean_energy_plot=h.show_meanVsEnergy()
144
145 h.show_EnergyFitresults()

[ Name Value Error
0 mu 0.990064 0.001285
1 sigma 0.025658 0.001199
2 mu_2 1.384944 0.003914
3 sigma_2 0.048394 0.003781
4 A 231.375000 0.000000
5 B 80.804887 3.667207
6 C 51.361385 3.643919, Name Value Error
0 mu 0.991737 0.001711
1 sigma 0.026729 0.001598
2 mu_2 1.376496 0.004604
3 sigma_2 0.050032 0.004348
4 A 156.375000 0.000000
5 B 83.366327 4.920670
6 C 58.966419 4.808841]
Total running time of the script: (0 minutes 14.994 seconds)





