A few plots to compare with M. Kerr's results
from nbdev import *
!date
Mon Jun  7 09:42:59 PDT 2021

This notebook generates plots for two of the sources that he examined, and compare with figures from the Kerr paper.

Note the use of ipynb_docgen allowing a cell to create a document mixing markdown and plots. Each of the plots below is displayed as a link to an attached file, and can be clicked on to see the orginal.

from wtlike import *
from utilities.ipynb_docgen import *

def kerr_test():
    r"""
    
    ### A bright pulsar, {lc1.source.name}:
    {print_out1}    
    {fig1}    
    This is to be compared with Kerr's Figure 1:    
    {kerr_fig1}
   
    ### A flaring AGN, {lc2.source.name}
    {print_out2}
    {fig2}
    
    This corresponds to the upper right panel in Kerr's Figure 2.
    {kerr_fig2}
    The Kerr paper discusses the circled point at MJD {flare.t}, during which the measured flux was
    dominated by a nearby intense solar flare. The lower panel shows fits that were marginalized over $\beta$. 
    
    """

    plt.rc('font', size=16)


    with capture_print('output from this analysis') as print_out1:
        lc1 = WtLike('Geminga', time_bins=(0,0,1))
        fig1 = figure( 
                    lc1.plot(fignum=1, figsize=(15,8),colors=('cornflowerblue', 'orange'),
                             ylim=(0.3,1.7), ts_bar_min=4,),
                    caption=None,   width=500, )
        
    kerr_fig1 = image('kerr_fig1.png', width=300, caption='Kerr Figure 1')
    
    with capture_print('output from this analysis') as print_out2:
        lc2 = WtLike('3C 279', time_bins=(0,0,1))
        flare= lc2.fluxes.loc[1893]
        
        fig2 = figure(
                    lc2.plot( fignum=2, figsize=(16,10), yscale='log' , 
                          colors=('cornflowerblue','orange'), ts_bar_min=9,
                         xlim=(56550, 56550+700),   ylim=(0.06,90)),
                    caption=None, width=500, )
        ax = fig2.axes[0]
        ax.scatter(flare.t, flare.flux, s=300, facecolors='none', edgecolor='red', lw=2, 
                   label=f'Solar flare at {flare.flux}');
    kerr_fig2 = image('kerr_fig2.png', width=500, caption='Kerr Figure 2')
   
    return locals()


nbdoc(kerr_test)
/home/burnett/miniconda3/lib/python3.7/site-packages/scipy/optimize/minpack.py:162: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last ten iterations.
  warnings.warn(msg, RuntimeWarning)

A bright pulsar, Geminga:

output from this analysis
SourceData: photons and exposure for Geminga: Restoring from cache with key "Geminga_data"
SourceData: Source Geminga with:
data: 1,219,805 photons from 2008-08-04 to 2021-06-01
exposure: 3,135,734 intervals, average flux 2783 cm^2 for 93.8 Ms
rates: source 3.38e-06/s, background 1.29e-06/s, S/N ratio 2.62e+00
CellData: Bin photon data into 4683 1-day bins from 54683.0 to 59366.0
LightCurve: select 4552 cells for fitting with e>1 & n>2

Figure 1 at images/kerr_test_fig_01.png
This is to be compared with Kerr's Figure 1:
Figure 2 at images/kerr_test_fig_02.png
Figure 2. Kerr Figure 1

A flaring AGN, 3C 279

output from this analysis
SourceData: photons and exposure for 3C 279: Restoring from cache with key "3C_279_data"
SourceData: Source 3C 279 with:
data: 146,815 photons from 2008-08-04 to 2021-06-01
exposure: 2,831,808 intervals, average flux 2845 cm^2 for 84.6 Ms
rates: source 3.74e-07/s, background 2.37e-07/s, S/N ratio 1.58e+00
CellData: Bin photon data into 4683 1-day bins from 54683.0 to 59366.0
LightCurve: select 4487 cells for fitting with e>1 & n>2

Figure 3 at images/kerr_test_fig_03.png

This corresponds to the upper right panel in Kerr's Figure 2.

Figure 4 at images/kerr_test_fig_04.png
Figure 4. Kerr Figure 2
The Kerr paper discusses the circled point at MJD 56576.5, during which the measured flux was dominated by a nearby intense solar flare. The lower panel shows fits that were marginalized over $\beta$.

Study the flare

lc2 = WtLike('3C 279', time_bins=(0,0,1))

cell= lc2.fluxes.loc[1893]; 
flare = lc2.view(56570, 56580,1)
flare.plot(tzero=56576);

flare.fluxes

flare.fit_beta_free();
SourceData: photons and exposure for 3C 279: Restoring from cache with key "3C_279_data"
SourceData: Source 3C 279 with:
	 data:       146,765 photons from 2008-08-04 to 2021-05-30
	 exposure: 2,830,618 intervals,  average flux 2845 cm^2 for 84.5 Ms
	 rates:  source 3.75e-07/s, background 2.36e-07/s, S/N ratio 1.59e+00
CellData: Bin photon data into 4681 1-day bins from 54683.0 to 59364.0
LightCurve: select 4485 cells for fitting with e>1 & n>2
CellData: Bin photon data into 10 1-day bins from 56570.0 to 56580.0
LightCurve: select 10 cells for fitting with e>1 & n>2