mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-07-12 00:53:02 +00:00
Gaussian smoothing of density fields (#33)
* Simplify smoothing support and looping over nonzero * Simplify comments * add now() * add cat length * add smoothed calculation * add smoothing * Add sorting * Edit what is ignored * Move notebooks * Add nonsymmetric smoothed overlap * Update NB * Add support for reading in the smoothed overlap * Switch to the true overlap definition * Reader of the true overlap * rem occups * Import moved to a class * Move definition * Edit submission script * Update to account for the new definition * backup nb * Switch back to properly initialising arrays * Fix addition bug * Update NB * Fix little bug * Update nb
This commit is contained in:
parent
9b524db617
commit
5dd8c668fa
13 changed files with 10587 additions and 441 deletions
|
@ -12,14 +12,12 @@
|
|||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
"""
|
||||
Script to test running the CSiBORG realisations matcher.
|
||||
"""
|
||||
import numpy
|
||||
from argparse import ArgumentParser
|
||||
from distutils.util import strtobool
|
||||
from datetime import datetime
|
||||
"""A script to calculate overlap between two CSiBORG realisations."""
|
||||
from os.path import join
|
||||
from argparse import ArgumentParser
|
||||
from datetime import datetime
|
||||
import numpy
|
||||
from scipy.ndimage import gaussian_filter
|
||||
try:
|
||||
import csiborgtools
|
||||
except ModuleNotFoundError:
|
||||
|
@ -33,26 +31,59 @@ parser = ArgumentParser()
|
|||
parser.add_argument("--nsim0", type=int)
|
||||
parser.add_argument("--nsimx", type=int)
|
||||
parser.add_argument("--nmult", type=float)
|
||||
parser.add_argument("--overlap", type=lambda x: bool(strtobool(x)))
|
||||
parser.add_argument("--sigma", type=float)
|
||||
args = parser.parse_args()
|
||||
|
||||
# File paths
|
||||
fout = join(
|
||||
utils.dumpdir, "overlap", "cross_{}_{}.npz".format(args.nsim0, args.nsimx))
|
||||
fout = join(utils.dumpdir, "overlap",
|
||||
"cross_{}_{}.npz".format(args.nsim0, args.nsimx))
|
||||
smooth_kwargs = {"sigma": args.sigma, "mode": "constant", "cval": 0.0}
|
||||
overlapper = csiborgtools.match.ParticleOverlap()
|
||||
|
||||
print("{}: loading catalogues.".format(datetime.now()), flush=True)
|
||||
# Load catalogues
|
||||
print("{}: loading catalogues {} and {}."
|
||||
.format(datetime.now(), args.nsim0, args.nsimx), flush=True)
|
||||
cat0 = csiborgtools.read.HaloCatalogue(args.nsim0)
|
||||
catx = csiborgtools.read.HaloCatalogue(args.nsimx)
|
||||
|
||||
matcher = csiborgtools.match.RealisationsMatcher()
|
||||
|
||||
print("{}: loading simulation {} and converting positions to cell numbers."
|
||||
.format(datetime.now(), args.nsim0), flush=True)
|
||||
with open(cat0.paths.clump0_path(args.nsim0), "rb") as f:
|
||||
clumps0 = numpy.load(f, allow_pickle=True)
|
||||
overlapper.clumps_pos2cell(clumps0)
|
||||
print("{}: loading simulation {} and converting positions to cell numbers."
|
||||
.format(datetime.now(), args.nsimx), flush=True)
|
||||
with open(catx.paths.clump0_path(args.nsimx), 'rb') as f:
|
||||
clumpsx = numpy.load(f, allow_pickle=True)
|
||||
overlapper.clumps_pos2cell(clumpsx)
|
||||
|
||||
|
||||
print("{}: generating the background density fields.".format(datetime.now()),
|
||||
flush=True)
|
||||
delta_bckg = overlapper.make_bckg_delta(clumps0)
|
||||
delta_bckg = overlapper.make_bckg_delta(clumpsx, delta=delta_bckg)
|
||||
|
||||
|
||||
print("{}: crossing the simulations.".format(datetime.now()), flush=True)
|
||||
ref_indxs, cross_indxs, match_indxs, overlap = matcher.cross(
|
||||
cat0, catx, overlap=args.overlap)
|
||||
matcher = csiborgtools.match.RealisationsMatcher()
|
||||
ref_indxs, cross_indxs, match_indxs, ngp_overlap = matcher.cross(
|
||||
cat0, catx, clumps0, clumpsx, delta_bckg)
|
||||
|
||||
|
||||
print("{}: smoothing the background field.".format(datetime.now()), flush=True)
|
||||
gaussian_filter(delta_bckg, output=delta_bckg, **smooth_kwargs)
|
||||
|
||||
|
||||
print("{}: calculating smoothed overlaps.".format(datetime.now()), flush=True)
|
||||
smoothed_overlap = matcher.smoothed_cross(clumps0, clumpsx, delta_bckg,
|
||||
ref_indxs, cross_indxs, match_indxs,
|
||||
smooth_kwargs)
|
||||
|
||||
# Dump the result
|
||||
print("Saving results to `{}`.".format(fout), flush=True)
|
||||
with open(fout, "wb") as f:
|
||||
numpy.savez(fout, ref_indxs=ref_indxs, cross_indxs=cross_indxs,
|
||||
match_indxs=match_indxs, overlap=overlap)
|
||||
|
||||
match_indxs=match_indxs, ngp_overlap=ngp_overlap,
|
||||
smoothed_overlap=smoothed_overlap, sigma=args.sigma)
|
||||
print("All finished.", flush=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue