lib.data_vector.data_vector.DataVector¶
- class lib.data_vector.data_vector.DataVector(x=None, y=None, proj=None, edges=None, attrs=None, **kwargs)¶
Bases:
cosmopipe.lib.utils.BaseClassClass representing a data vector, as a collection of
BinnedProjection, e.g. power spectrumm multipoles, wedges, etc. One can also store heterogenous quantities, e.g. power spectrum, correlation function, higher order…- data¶
Dictionary of
BinnedProjectioninstances.- Type
dict
- attrs¶
Dictionary of other attributes.
- Type
dict
Initialize data vector.
- Parameters
x (DataVector, BinnedProjection, list, array) – If list of arrays, x-coordinates for all projections. If single array, is repeated for each projection. If (list of)
BinnedProjection: set these projection(s). IfDataVector, is (shallow) copied.y (list, default=None) – y-coordinates for all projections. If
None, no y-coordinates set.proj (list, default=None) – List of (inputs for) projection names
ProjectionName.edges (list, default=None) – If
None, no edges set.attrs (dict) – Dictionary of other attributes.
kwargs (dict) – Other arguments for
BinnedProjection(same for all of them).
Methods
Concatenate data vectors together.
Return copy, including shallow-copy of each projection.
deepcopyExtend data vector with
other.Instantiate and initalize class with state dictionary.
Return
BinnedProjectioninstance corresponding toproj.Return edges for
kwargsselections.Dump header:
Return indices corresponding to input selections (including current view).
Return projection names in data vector, after selections.
Return title, as
module.class.Return x-coordinate of the data vector.
Return y-coordinate of the data vector.
is_mpi_broadcastis_mpi_gatheredis_mpi_rootis_mpi_scatteredLoad class in numpy binary format from disk.
Load data vector from disk.
Load
BinnedStatisticfrom disk.log_criticallog_debuglog_errorlog_infolog_warningReset view.
Plot data vector.
Read and decode header.
Decode title
line, splittingmodule.classinto (module,class).Rebin projection of name
proj(list or single projection name).Reorder deta_vector following index list
indices.Save class to disk.
Write data vector to disk.
Dump
DataVector.Add new
BinnedProjectioninstance.Set new edges for projection of name
proj(list or single projection name).Set y-coordinates.
Set data vector view, i.e. ensemble of selections to apply.
Attributes
Current view selections.
loggerMPI attributes
mpicommmpirootmpistateReturn projection names in data vector.
Equivalent for
__length__().- __add__(other)¶
Addition of two data vectors is defined as concatenation.
- classmethod concatenate(*others)¶
Concatenate data vectors together.
- Parameters
others (list) – List of
DataVectorinstances.- Returns
new
- Return type
- copy(copy_proj=False)¶
Return copy, including shallow-copy of each projection.
- extend(other)¶
Extend data vector with
other.
- classmethod from_state(state, mpiroot=0, mpicomm=None)¶
Instantiate and initalize class with state dictionary.
- get(proj, permissive=False)¶
Return
BinnedProjectioninstance corresponding toproj.- Parameters
proj (ProjectionName, tuple, string, dict) – Projection name to search for.
permissive (bool, default=False) – If
True, include projections which match inputproj(inkwargs) for non-Noneattributes. For example ProjectionName(space=’power’,mode=’multipole’,proj=0) would matchell_0(spacenot specified).
- Returns
dataproj
- Return type
- get_edges(**kwargs)¶
Return edges for
kwargsselections.
- get_header_txt(comments='#', ignore_json_errors=True)¶
Dump header:
items in
attrs_kwargs_view(current view selections)
- 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
- get_index(permissive=True, index_in_view=False, **kwargs)¶
Return indices corresponding to input selections (including current view).
Example
pk.get_index(xlim=(0.1,0.2),proj=0)will return index to obtainpkmonopole between0.1and0.2.pk.get_index(proj=(0,2))will return indices to obtainpkmonopole and quadrupole.- Parameters
permissive (bool) – If
True, include projections which match inputproj(inkwargs) for non-Noneattributes. For example ProjectionName(space=’power’,mode=’multipole’,proj=0) would matchell_0(spacenot specified).index_in_view (bool) – Whether to return index w.r.t. to current view.
kwargs (dict) – Dictionary of selections (i.e. list of
projandxlim).
- Returns
indices – Tuple (if input selections are not lists), or list of tuples
(proj, index)withindexindices for projection of nameproj.- Return type
tuple, list
- get_projs(**kwargs)¶
Return projection names in data vector, after selections.
- classmethod get_title_label()¶
Return title, as
module.class.
- get_x(concatenate=False, **kwargs)¶
Return x-coordinate of the data vector.
Example
pk.get_x(xlim=(0.1,0.2),proj=0)will return wavenumbers forpkmonopole between0.1and0.2.pk.get_x(proj=(0,2))will return wavenumbers forpkmonopole and quadrupole.- Parameters
concatenate (bool, default=False) – Concatenate output x-coordinates?
kwargs (dict) – Dictionary of selections (i.e. list of
projandxlim).
Warning
Output x-coordinates must be of same dimensionality to be concatenated!
- get_y(concatenate=True, **kwargs)¶
Return y-coordinate of the data vector. Same as
get_x(), but for the y-coordinate (which is by definition of 1 dimension for all projections).
- property kwview¶
Current view selections.
- 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).
- classmethod load_auto(filename, *args, **kwargs)¶
Load data vector from disk.
Note
Returned data vector, if saved with a
DataVector-inherited class, will be an instance of that class.- Parameters
filename (string) – File name of data vector. If ends with ‘.txt’, calls
load_txt()Else (numpy binary format), callsload()args (list) – Arguments for load function.
kwargs (dict) – Other arguments for load function.
- classmethod load_txt(filename, comments='#', usecols=None, skip_rows=0, max_rows=None, mapping_header=None, columns=None, mapping_proj=None, attrs=None, **kwargs)¶
Load
BinnedStatisticfrom disk.Note
If previously saved using
save_txt(), loading theDataVectoronly requiresfilename. In this case, the returned instance will be of the class that was used to create it (e.g.MockDataVector) - not necessarilyDataVector.- 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. If
None, reads all columns.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.columns (list, default=None) – column names corresponding to
usecols. Columns ‘x’ and ‘y’ are used as x- and y-coordinates.mapping_proj (dict, list, default=None) – Dictionary holding a mapping from column name to projection specifier (e.g. ‘ell_0’, [‘muwedge’, [0.0,0.2]], or with a name, e.g.: ‘ELG_ell_0’, [‘ELG’,’muwedge’,[0.0,0.2]]). It can also be a list corresponding to input columns (skipping the first - x).”
attrs (dict, default=None) – Attributes to save in the
attrsdictionary.kwargs (dict) – Other arguments for
BinnedProjection.load_txt().
- Returns
data
- Return type
- property mpiattrs¶
MPI attributes
- noview()¶
Reset view.
- plot(style=None, **kwargs_style)¶
Plot data vector. See
plotting.DataPlotStyle.
- property projs¶
Return projection names in data vector.
- 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(proj, *args, **kwargs)¶
Rebin projection of name
proj(list or single projection name). SeeBinnedStatistic.rebin()for other arguments.
- reorder(indices)¶
Reorder deta_vector following index list
indices.
- save(filename)¶
Save class to disk.
- save_auto(filename, *args, **kwargs)¶
Write data vector to disk.
- Parameters
filename (string) – File name of data vector. If ends with ‘.txt’, calls
save_txt()Else (numpy binary format), callssave()args (list) – Arguments for save function.
kwargs (dict) – Other arguments for save function.
- save_txt(filename, comments='#', fmt='.18e', ignore_json_errors=True)¶
Dump
DataVector.- Parameters
filename (string, default=None) – ASCII file name where to save data vector. 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(data)¶
Add new
BinnedProjectioninstance.
- set_new_edges(proj, *args, **kwargs)¶
Set new edges for projection of name
proj(list or single projection name). SeeBinnedStatistic.set_new_edges()for other arguments.
- set_y(y, concatenated=True, **kwargs)¶
Set y-coordinates.
Example
pk.view(xlim=(0.1,0.2)).set_y(y)will set y between0.1and0.2.- Parameters
y (list, array) – y arrays for each projection.
concatenated (bool, default=True) – If
True,yis a single array, which is split into the different projections given current view andkwargs.kwargs (dict) – Arguments for
get_index()
- property size¶
Equivalent for
__length__().
- view(**kwargs)¶
Set data vector view, i.e. ensemble of selections to apply. This will apply to output of
get_methods.Example
pk.view(xlim=(0.1,0.2)).get_y(proj=0)will returnpkmonopole between0.1and0.2.