lib.samples.mesh.Mesh¶
- class lib.samples.mesh.Mesh(mesh, dims, edges=None, nodes=None, isdensity=True)¶
Bases:
cosmopipe.lib.utils.BaseClassClass that represents a mesh. TODO: decide what to do with MPI… scatter mesh? Gather mesh?
Initialize
Mesh.- Parameters
mesh (array) – Mesh array.
dims (list) – List of labels (one for each mesh dimension).
edges (list, default=None) – List of edges (one array for each mesh dimension). If
None, usenodesinstead. Mesh shape must be length of edges - 1 along each dimension.nodes (list, default=None) – List of mesh nodes (one array for each mesh dimension).
isdensity (bool, default=True) – Whether to normalize binned (weighted) samples by mesh volume (
True).
Methods
Return coordinates of maximum along axes
axesor dimensionsdims.Return mean coordinates along axes
axesor dimensionsdims.Return shallow copy of
self.Return deep copy.
Initialize mesh from samples.
Instantiate and initalize class with state dictionary.
Return axes (axes) corresponding to dimensions
dims.Return density threshold(s) corresponding to confidence level(s)
targets.Return density thresholds corresponding to n-sigmas confidence levels
sigmas.Integrate mesh along axes
axesor dimensionsdims.Interpolate mesh at provided points.
is_mpi_broadcastis_mpi_gatheredis_mpi_rootis_mpi_scatteredLoad class in numpy binary format from disk.
If different formats are possible, this method should between them based on file name extension.
log_criticallog_debuglog_errorlog_infolog_warningReturn mesh maximum value.
Return meshgrid of nodes along axes
axesor dimensionsdims.Return mesh extension along axes
axesor dimensionsdims.Save class to disk.
If different formats are possible, this method should between them based on file name extension.
Save mesh as ASCII file.
Return volume array along axes
axesor dimensionsdims.Return cell sizes along axes
axesor dimensionsdims.Attributes
loggerMPI attributes
mpicommmpirootmpistateReturn number of dimensions.
Return mesh shape.
- __add__(other)¶
Addition of two meshes.
- __call__(axes=None)¶
Return mesh reduced to axes
axesor dimensionsdims. Mesh is integrated along other dimensions.
- argmax(axes=None)¶
Return coordinates of maximum along axes
axesor dimensionsdims.
- argmean(axes=None)¶
Return mean coordinates along axes
axesor dimensionsdims.
- copy()¶
Return shallow copy of
self.
- deepcopy()¶
Return deep copy.
- classmethod from_samples(samples, weights=None, dims=None, bins=30, method='cic', bw_method='scott')¶
Initialize mesh from samples. TODO: scattered samples?
- Parameters
samples (array) – Array of positions, with coordinates along first axes.
weights (array, default=None) – Sample weights, defaults to 1.
dims (list) – List of labels (one for each mesh dimension).
bins (int, default=30) – Number of bins i.e. mesh nodes to use along each dimension.
method (string) –
Method to interpolate (weighted) samples on mesh, either:
’gaussian_kde’: Gaussian kernel density estimation, based on
scipy.stats.gaussian_kde’cic’ : Cloud-in-Cell assignment
’histo’ : simple binning.
bw_method (string, default='scott') – If
methodis'gaussian_kde', method to determine KDE bandwidth, seescipy.stats.gaussian_kde.
- Returns
mesh
- Return type
- classmethod from_state(state, mpiroot=0, mpicomm=None)¶
Instantiate and initalize class with state dictionary.
- get_axes(dims=None)¶
Return axes (axes) corresponding to dimensions
dims.
- get_levels(targets)¶
Return density threshold(s) corresponding to confidence level(s)
targets.
- get_sigmas(sigmas)¶
Return density thresholds corresponding to n-sigmas confidence levels
sigmas.- Parameters
sigmas (int, list, array) – Sigmas to get density thresholds for. If scalar, return thresholds up to (including)
sigmas.- Returns
levels – Density thresholds.
- Return type
array
- integrate(axes=None)¶
Integrate mesh along axes
axesor dimensionsdims.
- interpolate(points, method='linear')¶
Interpolate mesh at provided points.
- Parameters
points (array) – Array of points, with coordinates along last axis.
method (string) – Interpolation method, ‘linear’ or ‘nearest’ (see
scipy.interpolate.interpn())
- Returns
values – Mesh values at interpolated points.
- Return type
array
- classmethod load(filename, mpiroot=0, mpicomm=None)¶
Load class in numpy binary format from disk. If the loaded state contains
__class__and that exists incls._registry, return instance ofcls._registry[__class__](instead ofcls).
- load_auto(*args, **kwargs)¶
If different formats are possible, this method should between them based on file name extension.
- max()¶
Return mesh maximum value.
- mnodes(axes=None)¶
Return meshgrid of nodes along axes
axesor dimensionsdims.
- property mpiattrs¶
MPI attributes
- property ndim¶
Return number of dimensions.
- ranges(axes=None)¶
Return mesh extension along axes
axesor dimensionsdims.
- save(filename)¶
Save class to disk.
- save_auto(*args, **kwargs)¶
If different formats are possible, this method should between them based on file name extension.
- save_txt(filename, header='', fmt='%.8e', delimiter=' ', **kwargs)¶
Save mesh as ASCII file. TODO: needs major improvement, e.g. what about dimension names?
- Parameters
filename (string) – File name where to save mesh.
kwargs (dict) – Arguments for
numpy.savetxt().
- property shape¶
Return mesh shape.
- volume(axes=None)¶
Return volume array along axes
axesor dimensionsdims.
- widths(axes=None)¶
Return cell sizes along axes
axesor dimensionsdims.