Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing some bugs during the test run #54

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions frbpoppy/beam_dists.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_beam_props(model, fwhm):
elif model == 'chime-frb':
pixel_scale = 0.05 # Degrees per pixel [deg]
x_range = 2. # Use 2 deg for CHIME main beam East-West range
beam_array = beam_array[:, 800-20*x_range:800+20*x_range]
beam_array = beam_array[:, 800-20*int(x_range):800+20*int(x_range)]
beam_size = 120*2*x_range # [sq deg]
elif model == 'gaussian':
pixel_scale = fwhm / 95 # Degrees per pixel [deg]
Expand Down Expand Up @@ -179,8 +179,10 @@ def int_pro_random(shape=(1, 1), pattern='perfect', fwhm=2, max_offset=None,
#y_offset = ne.evaluate("(ran_y-b_y) * pixel_scale")

offset = go.separation(0, 0, x_offset, y_offset)

return int_pro, offset, x_offset, y_offset
if pattern == 'chime-frb':
return int_pro, offset, x_offset, y_offset
else:
return int_pro, offset

else:
raise ValueError(f'Beam pattern "{pattern}" not recognised')
Expand Down
31 changes: 19 additions & 12 deletions frbpoppy/number_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ def __init__(self,
def sloped_dist(self, n_gen=1):
"""Draw from a sloped distribution to create a logNlogS slope."""

rand = rng.random(n_gen, dtype=np.float32)
vol_co = (self.maxi * rand)**(1/self.power) # [Gpc]
vol_co = (self.maxi*np.random.random(n_gen))**(1/self.power)
#rand = rng.random(n_gen, dtype=np.float32)
#vol_co = (self.maxi * rand)**(1/self.power) # [Gpc]
#vol_co = ne.evaluate("(maxi*rand)**(1/power)", global_dict=vars(self)) # [Gpc]
d = self.dt(vol_co=vol_co)
z = d[0]
Expand All @@ -82,8 +83,9 @@ def from_vol_co(self, n_gen=1):

Can be influenced by changing alpha.
"""
rand = rng.random(n_gen, dtype=np.float32)
vol_co = self.vol_co_max * rand # [Gpc]
vol_co = self.vol_co_max*np.random.random(n_gen)
#rand = rng.random(n_gen, dtype=np.float32)
#vol_co = self.vol_co_max * rand # [Gpc]
#vol_co = ne.evaluate("vol_co_max*rand", global_dict=vars(self)) # [Gpc]
d = self.dt(vol_co=vol_co)
z = d[0]
Expand All @@ -98,8 +100,9 @@ def from_sfr(self, n_gen=1):
Follows Madau & Dickinson (2014), eq. 15. For more info see
https://arxiv.org/pdf/1403.0007.pdf
"""
rand = rng.random(n_gen, dtype=np.float32)
sampling = self.cdf_sfr_max * rand # [Gpc]
sampling = np.random.uniform(0., self.cdf_sfr_max, size=n_gen)
#rand = rng.random(n_gen, dtype=np.float32)
#sampling = self.cdf_sfr_max * rand # [Gpc]
#sampling = ne.evaluate("cdf_sfr_max*rand", global_dict=vars(self)) # [Gpc]
d = self.dt(cdf_sfr=sampling)
z = d[0]
Expand All @@ -115,23 +118,26 @@ def from_delayed_sfr(self, n_gen=1):
https://arxiv.org/pdf/1403.0007.pdf
"""

rand = rng.random(n_gen, dtype=np.float32)
#rand = rng.random(n_gen, dtype=np.float32)

d_list = [0.1, 0.5, 1]
delay_time = min(d_list, key=lambda x:abs(x-self.delay_time))
if delay_time != self.delay_time:
print('Generate cosmic population with delay time', delay_time, 'Gyr instead')

if delay_time == 0.1:
sampling = self.cdf_dsfr0d1_max * rand
sampling = np.random.uniform(0., self.cdf_dsfr0d1_max, size=n_gen)
#sampling = self.cdf_dsfr0d1_max * rand
#sampling = ne.evaluate("cdf_dsfr0d1_max*rand", global_dict=vars(self))
d = self.dt(cdf_dsfr0d1=sampling)
elif delay_time == 0.5:
sampling = self.cdf_dsfr0d5_max * rand
sampling = np.random.uniform(0., self.cdf_dsfr0d5_max, size=n_gen)
#sampling = self.cdf_dsfr0d5_max * rand
#sampling = ne.evaluate("cdf_dsfr0d5_max*rand", global_dict=vars(self))
d = self.dt(cdf_dsfr0d5=sampling)
elif delay_time == 1:
sampling = self.cdf_dsfr1_max * rand
sampling = np.random.uniform(0., self.cdf_dsfr1_max, size=n_gen)
#sampling = self.cdf_dsfr1_max * rand
#sampling = ne.evaluate("cdf_dsfr1_max*rand", global_dict=vars(self))
d = self.dt(cdf_dsfr1=sampling)

Expand All @@ -146,8 +152,9 @@ def from_smd(self, n_gen=1):
Follows Madau & Dickinson (2014), eq. 2 & 15. For more info see
https://arxiv.org/pdf/1403.0007.pdf
"""
rand = rng.random(n_gen, dtype=np.float32)
sampling = self.cdf_smd_max * rand
sampling = np.random.uniform(0., self.cdf_smd_max, size=n_gen)
#rand = rng.random(n_gen, dtype=np.float32)
#sampling = self.cdf_smd_max * rand
#sampling = ne.evaluate("cdf_smd_max*rand", global_dict=vars(self))
d = self.dt(cdf_smd=sampling)
z = d[0]
Expand Down
37 changes: 25 additions & 12 deletions frbpoppy/precalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ def __init__(self, test=False):
def set_file_name(self):
"""Determine filename."""
uni_mods = os.path.join(paths.models(), 'universe/')
#self.file_name = uni_mods + 'dm_mw.db'
self.file_name = uni_mods + 'dm_mw_ne2001_1d.npy'
self.file_name = uni_mods + 'dm_mw_ne2001.npy'
if self.test:
uni_mods = os.path.join(paths.models(), 'universe/')
self.file_name = uni_mods + 'test_dm_mw_ne2001_1d.npy'
self.file_name = uni_mods + 'test_dm_mw_ne2001.npy'

def create_table(self, parallel=True):
"""Create a lookup table for dispersion measure."""
Expand All @@ -74,7 +73,6 @@ def create_table(self, parallel=True):
start = time.time()
for gl in gls:
for gb in gbs:
print(gl, gb)
if gl in DM_MW_Table:
DM_MW_Table[gl].update({gb: go.ne2001_dist_to_dm(dist, gl, gb)})
else:
Expand All @@ -94,8 +92,16 @@ def lookup(self, gal, gab):

"""
# Load dm table
dm_mw_table_1d = np.load(self.file_name, allow_pickle=True)

dm_mw_table = np.load(self.file_name, allow_pickle=True)
dm_mw_table = dict(enumerate(dm_mw_table.flatten()))[0]

coor_index = range(0, 361*181)
dm_mw_table_1d = []
for i in range(-180, 181):
for j in range(-90, 91):
dm_mw_table_1d.append(dm_mw_table[i][j])
#dm_mw_table_1d = dict(zip(coor_index, dm_mw_table_1d))
dm_mw_table_1d = np.stack((np.array(coor_index), np.array(dm_mw_table_1d)), axis=-1)
# Round values
gal = np.round(gal)
gab = np.round(gab)
Expand Down Expand Up @@ -144,11 +150,10 @@ def __init__(self, test=False):
def set_file_name(self):
"""Determine filename."""
uni_mods = os.path.join(paths.models(), 'universe/')
#self.file_name = uni_mods + 'dm_mw.db'
self.file_name = uni_mods + 'dm_mw_ymw16_1d.npy'
self.file_name = uni_mods + 'dm_mw_ymw16.npy'
if self.test:
uni_mods = os.path.join(paths.models(), 'universe/')
self.file_name = uni_mods + 'test_dm_mw_ymw16_1d.npy'
self.file_name = uni_mods + 'test_dm_mw_ymw16.npy'

def create_table(self, parallel=True):
"""Create a lookup table for dispersion measure."""
Expand All @@ -164,7 +169,6 @@ def create_table(self, parallel=True):
start = time.time()
for gl in gls:
for gb in gbs:
print(gl, gb)
if gl in DM_MW_Table:
DM_MW_Table[gl].update({gb: go.ymw16_dist_to_dm(dist, gl, gb)})
else:
Expand All @@ -185,8 +189,17 @@ def lookup(self, gal, gab):

"""
# Load dm table
dm_mw_table_1d = np.load(self.file_name, allow_pickle=True)

dm_mw_table = np.load(self.file_name, allow_pickle=True)
dm_mw_table = dict(enumerate(dm_mw_table.flatten()))[0]

coor_index = range(0, 361*181)
dm_mw_table_1d = []
for i in range(-180, 181):
for j in range(-90, 91):
dm_mw_table_1d.append(dm_mw_table[i][j])
#dm_mw_table_1d = dict(zip(coor_index, dm_mw_table_1d))
dm_mw_table_1d = np.stack((np.array(coor_index), np.array(dm_mw_table_1d)), axis=-1)

gal = np.round(gal)
gab = np.round(gab)
index = (gal - (-180))*181 + (gab - (-90))
Expand Down