Top-level interface to the rest of the package
@ipynb_doc
def phase_demo():
    """
    ### Demonstrate the phase_view with Vela and Geminga
    
    This uses the `phase_view` function to generate a view with cells that are folded according 
    to the specified period, relative to UTC {ref_date}.
    {out1}    
    {out2}
    {thefig}
    """
    plt.rc('font', size=16)
    year = 365.25; ref_date='2008'; precess=53.05

    
    fig, (ax1,ax2) = plt.subplots(1,2, figsize=(15,5)) # sharey=True)
    plt.subplots_adjust(wspace=0.25)
    thefig = figure(fig, width=800)
    
    with capture(f'Vela setup, {precess}-day period') as out1:
        vela = WtLike('Vela pulsar')
        pv = vela.phase_view( period=precess, nbins=25); 
    pv.plot(ax=ax1, xlim=(0,1), ylim=(0.97,1.03))

    with capture(f'Geminga setup: {year}-day period') as out2:
        geminga = WtLike('Geminga')
        gv = geminga.phase_view(year, nbins=50, reference=ref_date)
    gv.plot(ax=ax2, xlim=(0,1))    

    return locals()

if Config().valid:
    phase_demo()

Demonstrate the phase_view with Vela and Geminga

This uses the phase_view function to generate a view with cells that are folded according to the specified period, relative to UTC 2008.

Vela setup, 53.05-day period
SourceData:  PSR J0835-4510: Restoring from cache with key "PSR J0835-4510_data"
SourceData: Source Vela pulsar with:
data: 3,587,233 photons from 2008-08-04 to 2022-05-26
exposure: 3,269,606 intervals, average effective area 3460 cm^2 for 97.7 Ms
rates: source 8.56e-06/s, background 2.05e-06/s, TS 7052015.5
CellData.rebin: Bin photon data into 720 1-week bins from 54683.0 to 59723.0
LightCurve: select 712 cells for fitting with e>35 & n>2
CellData.phase_view: Create phase view, 25 bins with period 53.05 days.
CellData.rebin: Bin photon data into 2375 2.1-day bins from 54684.6 to 59724.3
LightCurve: select 25 cells for fitting with e>10.61 & n>2

Geminga setup: 365.25-day period
SourceData:  4FGL J0633.9+1746: Restoring from cache with key "PSR J0633+1746_data"
SourceData: Source Geminga with:
data: 1,222,521 photons from 2008-08-04 to 2022-09-28
exposure: 3,434,143 intervals, average effective area 2693 cm^2 for 102.7 Ms
rates: source 3.31e-06/s, background 1.11e-06/s, TS 2290923.9
CellData.rebin: Bin photon data into 738 1-week bins from 54683.0 to 59849.0
LightCurve: select 719 cells for fitting with e>35 & n>2
CellData.phase_view: Create phase view, 50 bins with period 365.25 days.
CellData.rebin: Bin photon data into 707 7.3-day bins from 54685.2 to 59849.8
LightCurve: select 50 cells for fitting with e>36.525 & n>2

Figure 1

class WtLike[source]

WtLike(*pars, **kwargs) :: LightCurve

Summary

There are three layers of initialization, implemented in superclasses, each with parameters. The classnames, associated parameters and data members set:

SourceData -- load photons and exposure parameters:

  - source : name, a PointSource object, or a Simulation object
  - config [Config()] : basic configuration
  - week_range [None] : range of weeks to load
  - key [''] : the cache key: '' means construct one with the source name, None to disable
  - clear [False] : if using cache, clear the contents first
sets:
  - photons
  - exposure

CellData -- create cells parameters:

  - time_bins [Config().time_bins] : binning: start, stop, binsize
sets:
  - cells
creates copies with new cells:
  - view
  - phase_view

LightCurve -- likelihood analysis of the cells parameters:

  - e_min [10] -- threshold for exposure (cm^2 units)
  - n_min [2]  -- likelihood has trouble with this few
  - lc_key [None] -- possible cache for light curve
sets:
  - fits, fluxes

WtLike (this class) -- no parameters (may add BB-specific ones) Implements: bb_view, plot_BB sets:

  - bb_flux  (only if bb_view invoked)

WtLike.bb_view[source]

WtLike.bb_view(p0=0.05, key=None, clear=False)

Return a view with the BB analysis applied

  • p0 -- false positive probability parameter

Its plot function will by default show an overplot on the parent's data points.

CellData.phase_view[source]

CellData.phase_view(period, nbins=25, reference='2008')

Return a "phase" view, in which the cell time binning is according to phase.

  • period -- 'year' | 'precession' | float
  • reference -- a UTC date for aligning the bins.

WtLike.reweighted_view[source]

WtLike.reweighted_view(other)

Return a view in which the weights have been modifed to account for a variable neighbor

  • other -- the WtLike BB view of the neighbor.
full = None
# code for the demo--this shouid be collapsed
@ipynb_doc
def wtlike_demo(clear=False):
    """
    ## Test/Demonstration with 3C 279
    
    > Note that this also demonstrates using the `ipynb_doc` decorator to have a single Jupyterlab cell generate a document
    
    {out1}
    First, the weekly light curve:
    {fig1}
    
    Replot the figure with an expanded scale to see position of a flare:
    {fig2}
    {out3}    {fig3}
    {out4}    {fig4}
    
    Table of BB fits
    {bb_table}
    
    This can be compared with Figure 4 from the [Kerr paper](https://arxiv.org/pdf/1910.00140.pdf)
    {kerr_fig4}
    """
    global full
    

    with capture('Setup 3C 279') as out1:
        full = WtLike('3C 279', clear=clear)
    
    fig1 = figure(
        full.plot(yscale='log', ylim=(0.2,20), figsize=(15,5), xlabel='MJD', fmt='.', fignum=1),
        caption='Full scale', width=600)  
    
    fig2 = figure(
        full.plot(  figsize=(15,5), xlabel='MJD', fmt='o', fignum=2,  xlim=(57100, 57300),),
        width=600)  
    
    with capture_hide('Define orbit-based subset around large flare at MJD 57189') as out3:
        orbit = full.view((57186, 57191, 0))
    fig3 = figure(
        orbit.plot(fmt='o', tzero=57186,   fignum=3 ),
            width=600)
    
    with capture_hide('Apply BB and overplot it with the cells on which it is based') as out4:
        bborbit = orbit.bb_view()
    fig4 = figure(
        bborbit.plot(fmt='o', tzero=57186,   fignum=4),
                width=600)
    
    bb_table = orbit.fluxes
    
    kerr_fig4 = image('kerr_fig4.png', width=600, caption=None)
    return locals()

if Config().valid:
    wtlike_demo( False)
/home/burnett/miniconda3-220301/envs/astro/lib/python3.9/site-packages/scipy/optimize/minpack.py:175: RuntimeWarning: The iteration is not making good progress, as measured by the 
  improvement from the last ten iterations.
  warnings.warn(msg, RuntimeWarning)
ipynb_docgen: Can't set width at the moment

Test/Demonstration with 3C 279

Note that this also demonstrates using the ipynb_doc decorator to have a single Jupyterlab cell generate a document

Setup 3C 279
SourceData:  4FGL J1256.1-0547: Restoring from cache with key "P88Y3243_data"
SourceData: Source 3C 279 with:
data: 191,313 photons from 2008-08-04 to 2022-05-26
exposure: 3,042,347 intervals, average effective area 2768 cm^2 for 90.8 Ms
rates: source 4.03e-07/s, background 3.58e-07/s, TS 183590.9
CellData.rebin: Bin photon data into 720 1-week bins from 54683.0 to 59723.0
LightCurve: select 707 cells for fitting with e>35 & n>2
First, the weekly light curve:

Figure 1
Figure 1. Full scale

Replot the figure with an expanded scale to see position of a flare:

Figure 2
Define orbit-based subset around large flare at MJD 57189
CellData.rebin: Bin photon data into 80 orbit-based bins from 57186.1 to 57191.0
LightCurve: select 62 cells for fitting with e>0 & n>2
Figure 3
Apply BB and overplot it with the cells on which it is based
Bayesian Blocks: partitioning 62 cells using LikelihoodFitness with penalty 5%
found 10 / 62 blocks.
LightCurve: Loaded 10 / 10 cells for fitting
Figure 4

Table of BB fits

t tw n e ts flux errors limit
57186.116 0.017 5 4.449 12.500 1.827 (-8.96e-01, 1.298) 4.762
57186.253 0.025 9 6.358 15.400 2.467 (-0.972, 1.25) 5.037
57186.385 0.026 9 6.391 16.200 2.636 (-0.999, 1.269) 5.217
57186.517 0.026 3 6.326 0.000 0.048 (-0.048, 0.744) 2.038
57186.650 0.026 5 6.311 3.200 1.103 (-0.711, 0.984) 3.258
57186.791 0.009 4 1.828 8.700 3.706 (-1.984, 2.971) 10.593
57187.177 0.021 46 5.783 286.000 18.845 (-2.762, 3.047) 24.330
57187.245 0.003 3 0.277 11.800 24.320 (-12.465, 18.51) 66.963
57187.312 0.027 56 6.740 361.600 19.926 (-2.63, 2.876) 25.059
57187.444 0.027 71 6.664 492.100 25.538 (-3.009, 3.257) 31.300
57187.576 0.027 70 6.608 478.000 25.414 (-3.014, 3.264) 31.191
57187.714 0.017 54 4.401 361.500 29.553 (-3.953, 4.328) 37.292
57187.829 0.002 4 0.246 23.500 38.692 (-16.917, 23.665) 90.771
57187.852 0.006 17 0.905 127.000 45.266 (-10.388, 12.211) 68.520
57187.963 0.006 12 1.063 65.500 26.111 (-7.304, 8.853) 43.427
... ... ... ... ... ... ... ...
57190.016 0.013 23 4.987 117.100 10.787 (-2.218, 2.549) 15.546
57190.085 0.016 29 6.470 163.100 10.569 (-1.936, 2.192) 14.605
57190.153 0.021 40 8.602 187.700 10.687 (-1.721, 1.912) 14.151
57190.221 0.024 20 9.648 59.200 4.364 (-1.052, 1.221) 6.664
57190.291 0.033 26 13.047 84.900 4.263 (-0.901, 1.026) 6.165
57190.358 0.032 24 12.731 75.100 3.852 (-0.867, 0.993) 5.702
57190.423 0.033 29 12.853 98.800 4.827 (-0.963, 1.09) 6.835
57190.490 0.032 18 12.598 50.700 2.769 (-0.74, 0.866) 4.412
57190.555 0.033 30 12.783 92.500 4.837 (-0.974, 1.101) 6.860
57190.622 0.032 20 12.530 61.100 3.162 (-0.799, 0.927) 4.907
57190.694 0.020 11 7.773 30.000 2.865 (-0.922, 1.141) 5.138
57190.763 0.016 11 6.325 36.600 3.741 (-1.165, 1.425) 6.548
57190.831 0.012 9 4.501 27.400 4.034 (-1.41, 1.79) 7.676
57190.898 0.009 3 3.350 7.700 1.925 (-1.036, 1.535) 5.455
57190.966 0.006 3 2.138 2.100 1.962 (-1.504, 2.32) 7.499

This can be compared with Figure 4 from the Kerr paper

Figure 5