Prepare photons and exposure, given a source

This module defines the function load_source_data.

Depends on module Exposure for SC data

sc_data_selection[source]

sc_data_selection(config, source, sc_data)

Return a DataFrame with the S/C data for the source direction, wtih cos theta and zenith cuts

columns:

  • start, stop, livetime -- from the FT2 info
  • cos_theta -- angle between bore and direction
  • exp -- the exposure: effective area at angle weighted by a default spectral function, times livetime

load_source_data[source]

load_source_data(config, source, week_range=None, key='', clear=False)

Generate photon and exposure tables specific to the source.

  • week_range [None] -- if None, select all weeks
  • key [''] -- key to use for cache, construct from name if not set
  • clear [False]

For the given source returns a tuple of

  • photons
  • exposure
  • the key

Cache update

If the most recent week has been changed, load it and replace only the most recent part in the cache.

Develop/test with Geminga

Test multiprocessing

from wtlike.sources import PointSource
from wtlike.config import Timer
config=Config(); 
if config.valid:
    test_weeks = (11,60)
    source =PointSource('Geminga', config=config) 
    with Timer() as t1:
        config.pool_size=processes=4
        sd1 = load_source_data(config, source, week_range=test_weeks, key=None )
    print(t1)
    with Timer() as t2:
        config.pool_size=1
        sd2 = load_source_data(config, source, week_range=test_weeks, key=None )
    print(t2)
    print(f'Timing ratio using {processes} proceses: {t2.elapsed/t1.elapsed:.2f}')
    assert( len(sd1[0])==len(sd2[0]) ), 'Fail multiprocessing test'
SourceData:  4FGL J0633.9+1746
	Processing 50 week files week_011.pkl - week_060.pkl , using 4 processes ..................................................

elapsed time: 19.8s (0.3 min)
SourceData:  4FGL J0633.9+1746
	Processing 50 week files week_011.pkl - week_060.pkl 

..................................................elapsed time: 57.6s (1.0 min)
Timing ratio using 4 proceses: 2.90

Test with a Geminga week

Look at the ratio of Geminga exposures vs. $\cos\theta$.