mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-06-08 18:01:11 +00:00
Add plotting (#64)
* Add verbosity statements * More verbosity * Save masses too * Add CDF new plot * Blank line * Fix RVS sampling bug * Add R200 conversion * Simplify plotting routines * Remove imoprt
This commit is contained in:
parent
7c2d7a86f5
commit
f1dbe6f03f
6 changed files with 123 additions and 12 deletions
|
@ -67,7 +67,7 @@ class RVSinsphere(BaseRVS):
|
|||
gen = numpy.random.default_rng(random_state)
|
||||
# Spherical
|
||||
r = gen.random(nsamples, dtype=dtype)**(1 / 3) * self.R
|
||||
theta = 2 * numpy.arcsin(gen.random(nsamples, dtype=dtype))
|
||||
theta = numpy.arccos(1 - 2 * gen.random(nsamples, dtype=dtype))
|
||||
phi = 2 * numpy.pi * gen.random(nsamples, dtype=dtype)
|
||||
# Cartesian
|
||||
x = r * numpy.sin(theta) * numpy.cos(phi)
|
||||
|
|
|
@ -27,4 +27,4 @@ from .readsim import (MmainReader, ParticleReader, halfwidth_mask, # noqa
|
|||
load_clump_particles, load_parent_particles, read_initcm)
|
||||
from .tpcf_summary import TPCFReader # noqa
|
||||
from .utils import (cartesian_to_radec, cols_to_structured, # noqa
|
||||
radec_to_cartesian, read_h5, real2redshift)
|
||||
radec_to_cartesian, read_h5, real2redshift, M200_to_R200)
|
||||
|
|
|
@ -484,6 +484,8 @@ class NPairsOverlap:
|
|||
|
||||
def __init__(self, cat0, catxs, paths, verbose=True):
|
||||
pairs = [None] * len(catxs)
|
||||
if verbose:
|
||||
print("Loading individual overlap objects...", flush=True)
|
||||
for i, catx in enumerate(tqdm(catxs) if verbose else catxs):
|
||||
pairs[i] = PairOverlap(cat0, catx, paths)
|
||||
|
||||
|
@ -506,6 +508,8 @@ class NPairsOverlap:
|
|||
summed_overlap : 2-dimensional array of shape `(nhalos, ncatxs)`
|
||||
"""
|
||||
out = [None] * len(self)
|
||||
if verbose:
|
||||
print("Calculating summed overlap...", flush=True)
|
||||
for i, pair in enumerate(tqdm(self.pairs) if verbose else self.pairs):
|
||||
out[i] = pair.summed_overlap(from_smoothed)
|
||||
return numpy.vstack(out).T
|
||||
|
@ -527,6 +531,8 @@ class NPairsOverlap:
|
|||
prob_nomatch : 2-dimensional array of shape `(nhalos, ncatxs)`
|
||||
"""
|
||||
out = [None] * len(self)
|
||||
if verbose:
|
||||
print("Calculating probability of no match...", flush=True)
|
||||
for i, pair in enumerate(tqdm(self.pairs) if verbose else self.pairs):
|
||||
out[i] = pair.prob_nomatch(from_smoothed)
|
||||
return numpy.vstack(out).T
|
||||
|
@ -568,6 +574,8 @@ class NPairsOverlap:
|
|||
Returned only if `return_full` is `True`.
|
||||
"""
|
||||
mus, stds = [None] * len(self), [None] * len(self)
|
||||
if verbose:
|
||||
print("Calculating counterpart masses...", flush=True)
|
||||
for i, pair in enumerate(tqdm(self.pairs) if verbose else self.pairs):
|
||||
mus[i], stds[i] = pair.counterpart_mass(
|
||||
from_smoothed=from_smoothed,
|
||||
|
|
|
@ -18,6 +18,7 @@ Various coordinate transformations.
|
|||
from os.path import isfile
|
||||
|
||||
import numpy
|
||||
from astropy import units
|
||||
from h5py import File
|
||||
|
||||
###############################################################################
|
||||
|
@ -135,6 +136,29 @@ def real2redshift(pos, vel, origin, box, in_box_units, periodic_wrap=True,
|
|||
return pos
|
||||
|
||||
|
||||
def M200_to_R200(M200, cosmo):
|
||||
r"""
|
||||
Convert :math:M_{200} to :math:`R_{200}`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
M200 : float
|
||||
:math:`M_{200}` in :math:`M_{\odot}`.
|
||||
cosmo : astropy cosmology object
|
||||
Cosmology.
|
||||
|
||||
Returns
|
||||
-------
|
||||
R200 : float
|
||||
:math:`R_{200}` in :math:`\mathrm{Mpc}`.
|
||||
"""
|
||||
Msun = 1.98847e30
|
||||
M200 = 1e14 * Msun * units.kg
|
||||
rhoc = cosmo.critical_density0
|
||||
R200 = (M200 / (4 * numpy.pi / 3 * 200 * rhoc))**(1. / 3)
|
||||
return R200.to(units.Mpc).value
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Array manipulation #
|
||||
###############################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue