Skip to content

Commit

Permalink
Merge pull request #53 from FRBs/x_chime
Browse files Browse the repository at this point in the history
Bug fixes to make CHIME grids work
  • Loading branch information
profxj authored Jul 19, 2024
2 parents 691baed + 99aed43 commit 807c26b
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 15 deletions.
330 changes: 330 additions & 0 deletions docs/nb/CHIME_pzDM.ipynb

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions zdm/beams.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# collection of functions to handle telescope beam effects
from pkg_resources import resource_filename
from importlib.resources import files
import os
import numpy as np
import matplotlib.pyplot as plt
import scipy.constants as constants

from IPython import embed

# Path to survey data
beams_path = os.path.join(resource_filename('zdm', 'data'), 'BeamData')

def gauss_beam(thresh=1e-3,nbins=10,freq=1.4e9,D=64,sigma=None):
'''initialises a Gaussian beam
Expand Down Expand Up @@ -46,7 +47,8 @@ def load_beam(prefix):
which the calculation has been performed.
"""
basedir=beams_path
basedir = os.path.join(files('zdm'), 'data', 'BeamData')
#basedir=beams_path
logb=np.load(os.path.join(basedir,prefix+'_bins.npy'))
# standard, gets best beam estimates: no truncation
omega_b=np.load(os.path.join(basedir,prefix+'_hist.npy'))
Expand Down
27 changes: 15 additions & 12 deletions zdm/chime/grids.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#import utilities as ute
#import states as st

from zdm.craco import loading
from zdm import loading
from zdm import repeat_grid as rep
from zdm import misc_functions
from zdm import beams
Expand Down Expand Up @@ -56,55 +56,58 @@ def load(Nbin:int=6, make_plots:bool=False):
# loads survey data
sdir = os.path.join(resources.files('zdm'),
'data', 'Surveys','CHIME/')
print(sdir)

# loads beam data
bdir='Nbounds'+str(Nbin)+'/'
beams.beams_path = os.path.join(resources.files('zdm'),'data',
'BeamData', 'CHIME',bdir)

#bounds = np.load(beams.beams_path+'bounds.npy')
#solids = np.load(beams.beams_path+'solids.npy')


# Loops through CHIME declination bins
for ibin in np.arange(Nbin):
name = "CHIME_decbin_"+str(ibin)+"_of_"+str(Nbin)
s,g = loading.survey_and_grid(survey_name=name,NFRB=None,sdir=sdir)#,init_state=state)
ss,rgs = loading.surveys_and_grids(survey_names=[name],sdir=sdir,repeaters=True)#,init_state=state)
s = ss[0]
rg = rgs[0]
print("Loaded dec bin ",ibin)

# The below is specific to CHIME data. For CRAFT and other
# FRB surveys, do not use "bmethod=2", and you will have to
# enter the time per field and Nfields manually.
# Also, for other surveys, you do not need to iterate over
# declination bins!
rg = rep.repeat_Grid(g,Tfield=s.TOBS,Nfields=1,MC=False,opdir=None,bmethod=2)
# rg = rep.repeat_Grid(g,Tfield=s.TOBS,Nfields=1,MC=False,opdir=None,bmethod=2)
print("Loaded repeat grid")

if ibin==0:
all_rates = g.rates
all_rates = rg.rates
all_singles = rg.exact_singles
all_reps = rg.exact_reps
else:
all_rates = all_rates + g.rates
all_rates = all_rates + rg.rates
all_singles = all_singles + rg.exact_singles
all_reps = all_reps + rg.exact_reps

if make_plots:
misc_functions.plot_grid_2(all_rates,g.zvals,g.dmvals,
misc_functions.plot_grid_2(all_rates,rg.zvals,rg.dmvals,
name=opdir+'all_CHIME_FRBs.pdf',norm=3,log=True,
label='$\\log_{10} p({\\rm DM}_{\\rm EG},z)$ [a.u.]',
project=False,Aconts=[0.01,0.1,0.5],
zmax=3.0,DMmax=3000)

misc_functions.plot_grid_2(all_reps,g.zvals,g.dmvals,
misc_functions.plot_grid_2(all_reps,rg.zvals,rg.dmvals,
name=opdir+'repeating_CHIME_FRBs.pdf',norm=3,log=True,
label='$\\log_{10} p({\\rm DM}_{\\rm EG},z)$ [a.u.]',
project=False,Aconts=[0.01,0.1,0.5],
zmax=1.0,DMmax=1000)

misc_functions.plot_grid_2(all_singles,g.zvals,g.dmvals,
misc_functions.plot_grid_2(all_singles,rg.zvals,rg.dmvals,
name=opdir+'single_CHIME_FRBs.pdf',norm=3,log=True,
label='$\\log_{10} p({\\rm DM}_{\\rm EG},z)$ [a.u.]',
project=False,Aconts=[0.01,0.1,0.5],
zmax=3.0,DMmax=3000)

return g.dmvals, g.zvals, all_rates, all_singles, all_reps
return rg.dmvals, rg.zvals, all_rates, all_singles, all_reps

load()
17 changes: 17 additions & 0 deletions zdm/tests/test_chime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
File to test CHIME
"""

import os
import pytest

from pkg_resources import resource_filename
import pandas

from zdm.tests import tstutils

from zdm.chime import grids

def test_run():
dmvals, zvals, all_rates, all_singles, all_reps = grids.load()

0 comments on commit 807c26b

Please sign in to comment.