From b5fefe41969bd4c8514c663670f15f6cd242e5e4 Mon Sep 17 00:00:00 2001 From: Richard Stiskalek Date: Sat, 29 Apr 2023 14:38:21 +0100 Subject: [PATCH] Update init matching procedure (#50) * pep8 * fix convention * Update script * enforce optimisation boundaries to be finite * Update TODO * Remove sky matching * FIx a small bug * fix bug * Remove import * Add halo fitted quantities * Update nbs * update README * Add load_initial comments * Rename nbs * Delete nb * Update imports * Rename function * Update matcher * Add overlap paths * Update the matching script * Update verbosity * Add verbosity flags * Simplify make_bckg_delta * bug fix * fix bug * lala * la * Add overlap paths * Update limit * pep8 * Some pep8 stuff * pep8 * Minor corrections * Update paths * Add number of particles check * Fix bug * pep8 comments --- csiborgtools/match/match.py | 27 +++++++++++---------------- csiborgtools/read/overlap_summary.py | 14 +++++++------- scripts/pre_initmatch.py | 5 ++++- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/csiborgtools/match/match.py b/csiborgtools/match/match.py index 70a6f83..126ac5f 100644 --- a/csiborgtools/match/match.py +++ b/csiborgtools/match/match.py @@ -115,9 +115,9 @@ class RealisationsMatcher: Parameters ---------- - cat0 : :py:class:`csiborgtools.read.ClumpsCatalogue` + cat0 : :py:class:`csiborgtools.read.HaloCatalogue` Halo catalogue of the reference simulation. - catx : :py:class:`csiborgtools.read.ClumpsCatalogue` + catx : :py:class:`csiborgtools.read.HaloCatalogue` Halo catalogue of the cross simulation. halos0_archive : `NpzFile` object Archive of halos' particles of the reference simulation, keys must @@ -198,10 +198,8 @@ class RealisationsMatcher: except KeyError: halox = halosx_archive[str(kf)] minsx, maxsx = get_halolims( - halox, - ncells=self.overlapper.inv_clength, - nshift=self.overlapper.nshift, - ) + halox, ncells=self.overlapper.inv_clength, + nshift=self.overlapper.nshift) for p in ("x", "y", "z"): halox[p] = self.overlapper.pos2cell(halox[p]) cross_halos[kf] = halox @@ -768,9 +766,8 @@ def calculate_overlap(delta1, delta2, cellmins, delta_bckg): @jit(nopython=True) -def calculate_overlap_indxs( - delta1, delta2, cellmins, delta_bckg, nonzero, mass1, mass2 -): +def calculate_overlap_indxs(delta1, delta2, cellmins, delta_bckg, nonzero, + mass1, mass2): r""" Overlap between two clumps whose density fields are evaluated on the same grid and `nonzero1` enumerates the non-zero cells of `delta1. This is @@ -841,15 +838,14 @@ def dist_centmass(clump): Center of mass coordinates. """ # CM along each dimension - cmx, cmy, cmz = [ - numpy.average(clump[p], weights=clump["M"]) for p in ("x", "y", "z") - ] + cmx, cmy, cmz = [numpy.average(clump[p], weights=clump["M"]) + for p in ("x", "y", "z")] # Particle distance from the CM dist = numpy.sqrt( numpy.square(clump["x"] - cmx) + numpy.square(clump["y"] - cmy) + numpy.square(clump["z"] - cmz) - ) + ) return dist, numpy.asarray([cmx, cmy, cmz]) @@ -876,9 +872,8 @@ def dist_percentile(dist, qs, distmax=0.075): return x -def radius_neighbours( - knn, X, radiusX, radiusKNN, nmult=1.0, enforce_int32=False, verbose=True -): +def radius_neighbours(knn, X, radiusX, radiusKNN, nmult=1.0, + enforce_int32=False, verbose=True): """ Find all neigbours of a trained KNN model whose center of mass separation is less than `nmult` times the sum of their respective radii. diff --git a/csiborgtools/read/overlap_summary.py b/csiborgtools/read/overlap_summary.py index ea07911..a34a872 100644 --- a/csiborgtools/read/overlap_summary.py +++ b/csiborgtools/read/overlap_summary.py @@ -27,12 +27,12 @@ class PairOverlap: Parameters ---------- - cat0, catx: :py:class:`csiborgtools.read.ClumpsCatalogue` - Halo catalogues corresponding to the reference and cross - simulations. - fskel : str, optional - Path to the overlap. By default `None`, i.e. - `/mnt/extraspace/rstiskalek/csiborg/overlap/cross_{}_{}.npz`. + cat0 : :py:class:`csiborgtools.read.HaloCatalogue` + Halo catalogue corresponding to the reference simulation. + catx : :py:class:`csiborgtools.read.HaloCatalogue` + Halo catalogue corresponding to the cross simulation. + paths : py:class`csiborgtools.read.CSiBORGPaths` + CSiBORG paths object. min_mass : float, optional Minimum :math:`M_{\rm tot} / M_\odot` mass in the reference catalogue. By default no threshold. @@ -44,7 +44,7 @@ class PairOverlap: _catx = None _data = None - def __init__(self, cat0, catx, fskel=None, min_mass=None, max_dist=None): + def __init__(self, cat0, catx, paths, min_mass=None, max_dist=None): self._cat0 = cat0 self._catx = catx diff --git a/scripts/pre_initmatch.py b/scripts/pre_initmatch.py index 72bacee..4f98fa3 100644 --- a/scripts/pre_initmatch.py +++ b/scripts/pre_initmatch.py @@ -93,7 +93,7 @@ for i, nsim in enumerate(paths.get_ics(tonew=True)): # the end save these. cat = csiborgtools.read.ClumpsCatalogue(nsim, paths, load_fitted=False, rawdata=True) - parent_ids = cat["index"][cat.ismain][:500] + parent_ids = cat["index"][cat.ismain] jobs = csiborgtools.fits.split_jobs(parent_ids.size, nproc)[rank] for i in tqdm(jobs) if verbose else jobs: clid = parent_ids[i] @@ -101,6 +101,9 @@ for i, nsim in enumerate(paths.get_ics(tonew=True)): mmain_mask = numpy.isin(clump_ids, mmain_indxs, assume_unique=True) mmain_particles = part0[mmain_mask] + # If the number of particles is too small, we skip this halo. + if mmain_particles.size < 100: + continue raddist, cmpos = csiborgtools.match.dist_centmass(mmain_particles) patchsize = csiborgtools.match.dist_percentile(raddist, [99],