Skip to content

Commit 16d9728

Browse files
authored
Merge pull request #41 from abacusorg/fix-origin
Fix origin
2 parents 52d73c0 + 6ebf773 commit 16d9728

14 files changed

Lines changed: 101 additions & 76 deletions

abacusnbody/data/compaso_halo_catalog.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def __init__(self, path, cleaned=True, subsamples=False, convert_units=True, unp
421421
if halo_lc == None:
422422
halo_lc = self.is_path_halo_lc(path)
423423
if verbose and halo_lc:
424-
print('Detected halo light cone catalog')
424+
print('Detected halo light cone catalog.')
425425
self.halo_lc = halo_lc
426426

427427
# If loading halo light cones, turn off cleaning and bit unpacking because done already
@@ -820,6 +820,8 @@ def _read_halo_info(self, halo_fns, fields, cleaned_fns=None, cleaned_fields=Non
820820
print(f'{len(fields)} halo catalog fields ({len(cleaned_fields)} cleaned) requested. '
821821
f'Reading {len(raw_dependencies)} fields from disk. '
822822
f'Computing {len(extra_fields)} intermediate fields.')
823+
if self.halo_lc:
824+
print('\nFor more information on the halo light cone catalog fields, see https://abacussummit.readthedocs.io/en/latest/data-products.html#halo-light-cone-catalogs')
823825

824826
self.halos = Table(cols, copy=False)
825827
self.halos.meta.update(self.header)
@@ -969,9 +971,26 @@ def _sigmav_loader(m,raw,halos):
969971
pat = re.compile(r'SO(?:_L2max)?(?:_central_density)')
970972
self.halo_field_loaders[pat] = lambda m,raw,halos: raw[m[0]]
971973

972-
# Halo light cone catalog specific fields
973-
pat = re.compile(r'index_halo|origin|pos_avg|pos_interp|vel_avg|vel_interp|redshift_interp|N_interp')
974+
# loader for halo light cone catalog specific fields
975+
pat = re.compile(r'index_halo|pos_avg|vel_avg|redshift_interp|N_interp')
974976
self.halo_field_loaders[pat] = lambda m,raw,halos: raw[m[0]]
977+
978+
# loader for halo light cone catalog field `origin`
979+
pat = re.compile(r'origin')
980+
self.halo_field_loaders[pat] = lambda m,raw,halos: raw[m[0]]%3
981+
982+
# loader for halo light cone catalog fields: interpolated position and velocity
983+
pat = re.compile(r'(?P<pv>pos|vel)_interp')
984+
def lc_interp_loader(m, raw, halos):
985+
columns = {}
986+
interped = (raw['origin'] // 3).astype(bool)
987+
if m[0] == 'pos_interp' or 'pos_interp' in halos.colnames:
988+
columns['pos_interp'] = np.where(interped[:, None], raw['pos_avg'], raw['pos_interp'])
989+
if m[0] == 'vel_interp' or 'vel_interp' in halos.colnames:
990+
columns['vel_interp'] = np.where(interped[:, None], raw['vel_avg'], raw['vel_interp'])
991+
return columns
992+
993+
self.halo_field_loaders[pat] = lc_interp_loader
975994

976995
# eigvecs loader
977996
pat = re.compile(r'(?P<rnv>sigma(?:r|n|v)_eigenvecs)(?P<which>Min|Mid|Maj)(?P<com>_(?:L2)?com)')
@@ -1722,3 +1741,4 @@ def unpack_euler16(bin_this):
17221741
('sigmavtan_L2com', np.float32),
17231742
('rvcirc_max_L2com', np.float32),
17241743
], align=True)
1744+

abacusnbody/hod/prepare_sim.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import multiprocessing
2727
from multiprocessing import Pool
2828

29-
from sklearn.neighbors import KDTree
29+
from scipy.spatial import cKDTree
30+
3031

3132
DEFAULTS = {}
3233
DEFAULTS['path2config'] = 'config/abacus_hod.yaml'
@@ -298,7 +299,7 @@ def prepare_slab(i, savedir, simdir, simname, z_mock, tracer_flags, MT, want_ran
298299
if randpos.shape[0] > 0:
299300
# random points on the edges
300301
rand_N = randpos.shape[0]
301-
randpos_tree = KDTree(randpos) # TODO: needs to be periodic, fix bug
302+
randpos_tree = KDTree(randpos)
302303
randinds_inner = randpos_tree.query_radius(allpos[index_bounds], r = halos['r98_L2com'][index_bounds])
303304
randinds_outer = randpos_tree.query_radius(allpos[index_bounds], r = rad_outer)
304305
rand_norm = np.zeros(len(index_bounds))
@@ -308,9 +309,17 @@ def prepare_slab(i, savedir, simdir, simname, z_mock, tracer_flags, MT, want_ran
308309
else:
309310
rand_norm = np.ones(len(index_bounds))
310311

311-
allpos_tree = KDTree(allpos)
312-
allinds_inner = allpos_tree.query_radius(allpos, r = halos['r98_L2com'])
313-
allinds_outer = allpos_tree.query_radius(allpos, r = rad_outer)
312+
if halo_lc:
313+
# periodicity not needed for halo light cones
314+
allpos_tree = cKDTree(allpos)
315+
allinds_inner = allpos_tree.query_ball_point(allpos, r = halos['r98_L2com'])
316+
allinds_outer = allpos_tree.query_ball_point(allpos, r = rad_outer)
317+
else:
318+
# note that periodicity exists only in y and z directions
319+
tmp = allpos+Lbox/2.
320+
allpos_tree = cKDTree(tmp, boxsize=Lbox) # needs to be within 0 and Lbox for periodicity
321+
allinds_inner = allpos_tree.query_ball_point(tmp, r = halos['r98_L2com'])
322+
allinds_outer = allpos_tree.query_ball_point(tmp, r = rad_outer)
314323
print("computing m stacks")
315324
Menv = np.array([np.sum(allmasses[allinds_outer[ind]]) - np.sum(allmasses[allinds_inner[ind]]) \
316325
for ind in np.arange(len(halos))])

tests/data_mocks_summit_new/Mini_N64_L32/z0.000/galaxies_rsd/ELGs.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# %ECSV 1.0
1+
# %ECSV 0.9
22
# ---
33
# datatype:
44
# - {name: x, datatype: float64}

tests/data_mocks_summit_new/Mini_N64_L32/z0.000/galaxies_rsd/LRGs.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# %ECSV 1.0
1+
# %ECSV 0.9
22
# ---
33
# datatype:
44
# - {name: x, datatype: float64}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)