mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-06-08 18:01:11 +00:00
Better plots (#73)
* Edits paths of saved files * Add upper threshold options * Add upper threshold options * add latex_float option * Add weighted stats * add new plot
This commit is contained in:
parent
de7def61d5
commit
fbf9c2a4b7
5 changed files with 225 additions and 39 deletions
|
@ -17,8 +17,7 @@ from csiborgtools import clustering, field, fits, match, read # noqa
|
|||
# Arguments to csiborgtools.read.Paths.
|
||||
paths_glamdring = {"srcdir": "/mnt/extraspace/hdesmond/",
|
||||
"postdir": "/mnt/extraspace/rstiskalek/CSiBORG/",
|
||||
"BORG_dir": "/mnt/extraspace/rstiskalek/BORG/",
|
||||
"BORG_final_density": "/users/hdesmond/BORG_final/",
|
||||
"borg_dir": "/users/hdesmond/BORG_final/",
|
||||
"quijote_dir": "/mnt/extraspace/rstiskalek/Quijote",
|
||||
}
|
||||
|
||||
|
|
|
@ -19,12 +19,14 @@ from .knn_summary import kNNCDFReader # noqa
|
|||
from .nearest_neighbour_summary import NearestNeighbourReader # noqa
|
||||
from .obs import (SDSS, MCXCClusters, PlanckClusters, TwoMPPGalaxies, # noqa
|
||||
TwoMPPGroups)
|
||||
from .overlap_summary import weighted_stats # noqa
|
||||
from .overlap_summary import (NPairsOverlap, PairOverlap, # noqa
|
||||
binned_resample_mean, get_cross_sims)
|
||||
binned_resample_mean, get_cross_sims) # noqa
|
||||
from .paths import Paths # noqa
|
||||
from .pk_summary import PKReader # noqa
|
||||
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, M200_to_R200)
|
||||
from .utils import (M200_to_R200, cartesian_to_radec, # noqa
|
||||
cols_to_structured, radec_to_cartesian, read_h5,
|
||||
real2redshift)
|
||||
|
|
|
@ -19,7 +19,7 @@ from functools import lru_cache
|
|||
from os.path import isfile
|
||||
|
||||
import numpy
|
||||
from tqdm import tqdm
|
||||
from tqdm import tqdm, trange
|
||||
|
||||
###############################################################################
|
||||
# Overlap of two simulations #
|
||||
|
@ -293,7 +293,6 @@ class PairOverlap:
|
|||
|
||||
if norm_kind is not None:
|
||||
dist[i] /= norm[i]
|
||||
|
||||
return numpy.array(dist, dtype=object)
|
||||
|
||||
def mass_ratio(self, mass_kind="totpartmass", in_log=True, in_abs=True):
|
||||
|
@ -406,7 +405,7 @@ class PairOverlap:
|
|||
vals = self.cat0(par)
|
||||
out = [None] * len(self)
|
||||
for i, ind in enumerate(self["match_indxs"]):
|
||||
out[i] = numpy.ones(ind.size) * vals[i]
|
||||
out[i] = numpy.ones(len(ind)) * vals[i]
|
||||
return numpy.array(out, dtype=object)
|
||||
|
||||
def cat0(self, key=None, index=None):
|
||||
|
@ -459,6 +458,43 @@ class PairOverlap:
|
|||
return self["match_indxs"].size
|
||||
|
||||
|
||||
def weighted_stats(x, weights, min_weight=0, verbose=False):
|
||||
"""
|
||||
Calculate the weighted mean and standard deviation of `x` using `weights`
|
||||
for each array of `x`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
x : array of arrays
|
||||
Array of arrays of values to calculate the weighted mean and standard
|
||||
deviation for.
|
||||
weights : array of arrays
|
||||
Array of arrays of weights to use for the calculation.
|
||||
min_weight : float, optional
|
||||
Minimum weight required for a value to be included in the calculation.
|
||||
verbose : bool, optional
|
||||
Verbosity flag.
|
||||
|
||||
Returns
|
||||
-------
|
||||
stat : 2-dimensional array of shape `(len(x), 2)`
|
||||
The first column is the weighted mean and the second column is the
|
||||
weighted standard deviation.
|
||||
"""
|
||||
out = numpy.full((x.size, 2), numpy.nan, dtype=numpy.float32)
|
||||
|
||||
for i in trange(len(x)) if verbose else range(len(x)):
|
||||
x_, w_ = numpy.asarray(x[i]), numpy.asarray(weights[i])
|
||||
mask = w_ > min_weight
|
||||
x_ = x_[mask]
|
||||
w_ = w_[mask]
|
||||
if len(w_) == 0:
|
||||
continue
|
||||
out[i, 0] = numpy.average(x_, weights=w_)
|
||||
out[i, 1] = numpy.average((x_ - out[i, 0])**2, weights=w_)**0.5
|
||||
return out
|
||||
|
||||
|
||||
###############################################################################
|
||||
# Overlap of many pairs of simulations. #
|
||||
###############################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue