lib.data_vector.binned_statistic.BinnedStatistic¶
- class lib.data_vector.binned_statistic.BinnedStatistic(data=None, edges=None, dims=None, attrs=None)¶
Bases:
cosmopipe.lib.utils.BaseClassClass representing a binned statistic, similar to https://github.com/bccp/nbodykit/blob/master/nbodykit/binned_statistic.py.
- data¶
Dictionary of data arrays, of same shape.
- Type
dict
- edges¶
Dictionary of edges.
- Type
dict
- dims¶
List of dimension names.
- Type
list
- attrs¶
Dictionary of other attributes.
- Type
dict
Initialize
BinnedStatistic.- Parameters
data (dict, default=None) – Dictionary of data arrays, of same shape. Defaults to empty dictionary.
edges (dict, list, default=None) – Dictionary of edges, or list of edges corresponding to
dims. IfNone, no edges considered.dims (list, default=None) – List of dimension names. If
None, defaults toedgesdictionary keys.attrs (dict, default=None) – Dictionary of other attributes.
Methods
Average binned data along dimensions
dims.Return shallow copy of
self.deepcopyInstantiate and initalize class with state dictionary.
Dump header:
Return title, as
module.class.Has specified edges?
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.
Load
BinnedStatisticfrom disk.log_criticallog_debuglog_errorlog_infolog_warningRead and decode header.
Decode title
line, splittingmodule.classinto (module,class).Rebin data by factor
factors.Save class to disk.
If different formats are possible, this method should between them based on file name extension.
Dump
BinnedStatistic.Interpolate binned data within new edges.
Squeeze binned data along dimensions
dims.Attributes
Entries in
data.loggerMPI attributes
mpicommmpirootmpistateNumber of dimensions of binned data.
Shape of binned data; if
edges, return tuple of length of edges - 1, else shape of first array indataTotal size of binned data, i.e. product of length over all dimensions.
- average(dims=None, weights=None, columns_to_sum=None)¶
Average binned data along dimensions
dims. This is equivalent torebin()with factors corresponding to lengths along dimensionsdims, followed bysqueeze()along those dimensions.
- copy()¶
Return shallow copy of
self.
- classmethod from_state(state, mpiroot=0, mpicomm=None)¶
Instantiate and initalize class with state dictionary.
- get_header_txt(comments='#', ignore_json_errors=True)¶
Dump header:
- Parameters
comments (string, default='#') – String to be prepended to the header lines.
ignore_json_errors (bool, default=True) – When trying to dump
attrsusing json, ignore errors.
- Returns
header – List of strings (lines).
- Return type
list
- classmethod get_title_label()¶
Return title, as
module.class.
- has_edges()¶
Has specified edges?
- 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.
- classmethod load_txt(filename, comments='#', usecols=None, skip_rows=0, max_rows=None, mapping_header=None, pattern_header=None, attrs=None, **kwargs)¶
Load
BinnedStatisticfrom disk.Note
If previously saved using
save_txt(), loading theBinnedStatisticonly requiresfilename. In this case, the returned instance will be of the class that was used to create it (e.g.BinnedProjectionbelow) - not necessarilyBinnedStatistic.- Parameters
filename (string) – File name to read in.
comments (string, default='#') – Characters used to indicate the start of a comment.
usecols (list, default=None) – Which columns to read, with 0 being the first.
skip_rows (int, default=0) – Skip the first
skip_rowslines, including comments.max_rows (int, default=None) – Read
max_rows linesof content afterskip_rowslines. The default is to read all the lines.mapping_header (dict, default=None) – Dictionary holding key:regex mapping or (regex, type) to provide the type. The corresponding values, read in the header, will be saved in the
attrsdictionary.pattern_header (string, default=None) – A regex pattern for header with groups corresponding to key, value to add into the
attrsdictionary.attrs (dict, default=None) – Attributes to save in the
attrsdictionary.kwargs (dict) – Arguments for
__init__()(other thandataandattrs).
- Returns
data
- Return type
- property mpiattrs¶
MPI attributes
- property ndim¶
Number of dimensions of binned data.
- classmethod read_header_txt(file, comments='#', mapping_header=None, pattern_header=None, ignore_json_errors=True)¶
Read and decode header.
- Parameters
file (list, iterator) – List of lines.
comments (string, default='#') – Characters used to indicate the start of a header line.
mapping_header (dict, default=None) – Dictionary holding key:regex mapping or (regex, type) to provide the type. Type can be unspecified (or
None), in which case decoded will be tried with json, a string corresponding to__builtins__, or a callable.pattern_header (string, default=None) – A regex pattern with groups corresponding to key:value.
ignore_json_errors (bool, default=True) – When trying to decode header values using json, ignore errors.
- Returns
attrs
- Return type
dict
- classmethod read_title_label(line)¶
Decode title
line, splittingmodule.classinto (module,class). It loadsmodule, then ifclassis in_registry, return corresponding class. Else returnNone.
- rebin(factors, dims=None, weights=None, columns_to_sum=None)¶
Rebin data by factor
factors.- Parameters
factors (dict, list) – dim: rebinning factor mapping. If list, should contain rebinning factor for each
dimofdims.dims (list, default=None) – List of dimension names. Defaults to
dims.weights (array, default=None) – Array of weights (of shape
shape). IfNone, defaults to 1.columns_to_sum (list) – List of columns to sum, i.e. to not renormalize after rebinning.
- 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=None, fmt='.18e', comments='#', ignore_json_errors=True)¶
Dump
BinnedStatistic.- Parameters
filename (string, default=None) – ASCII file name where to save binned data. If
None, do not write on disk.fmt (string, default='.18e') – Floating point format.
comments (string, default='#') – String that will be prepended to the header lines.
ignore_json_errors (bool, default=True) – When trying to dump
attrsusing json, ignore errors.
- Returns
lines – List of strings (lines).
- Return type
list
- set_new_edges(edges, dims=None, weights=None, columns_to_sum=None)¶
Interpolate binned data within new edges. Perform linear interpolation if
edgesare not a simple concatenation of currentedges.- Parameters
edges (dict, list) – New dim: edges mapping. If list, should contain edges for each
dimofdims.dims (list, default=None) – List of dimension names. Defaults to
dims.weights (array, default=None) – Array of weights (of shape
shape). IfNone, defaults to 1.columns_to_sum (list) – List of columns to sum, i.e. to not renormalize after rebinning.
Warning
Requires
edgesto be set.
- property shape¶
Shape of binned data; if
edges, return tuple of length of edges - 1, else shape of first array indata
- property size¶
Total size of binned data, i.e. product of length over all dimensions.