lib.survey_selection.window_function.WindowFunction

class lib.survey_selection.window_function.WindowFunction(x=None, y=None, proj=None, edges=None, attrs=None, **kwargs)

Bases: cosmopipe.lib.data_vector.data_vector.DataVector

Class representing a window function.

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). If DataVector, 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

Concatenate data vectors together.

copy

Return copy, including shallow-copy of each projection.

deepcopy

extend

Extend data vector with other.

from_state

Instantiate and initalize class with state dictionary.

get

Return BinnedProjection instance corresponding to proj.

get_edges

Return edges for kwargs selections.

get_header_txt

Dump header:

get_index

Return indices corresponding to input selections (including current view).

get_projs

Return projection names in data vector, after selections.

get_title_label

Return title, as module.class.

get_x

Return x-coordinate of the data vector.

get_y

Return y-coordinate of the data vector.

is_mpi_broadcast

is_mpi_gathered

is_mpi_root

is_mpi_scattered

load

Load class in numpy binary format from disk.

load_auto

Load data vector from disk.

load_txt

Load BinnedStatistic from disk.

log_critical

log_debug

log_error

log_info

log_warning

noview

Reset view.

plot

Plot data vector.

read_header_txt

Read and decode header.

read_title_label

Decode title line, splitting module.class into (module, class).

rebin

Rebin projection of name proj (list or single projection name).

reorder

Reorder deta_vector following index list indices.

save

Save class to disk.

save_auto

Write data vector to disk.

save_txt

Dump DataVector.

set

Add new BinnedProjection instance.

set_new_edges

Set new edges for projection of name proj (list or single projection name).

set_y

Set y-coordinates.

view

Set data vector view, i.e. ensemble of selections to apply.

Attributes

kwview

Current view selections.

logger

mpiattrs

MPI attributes

mpicomm

mpiroot

mpistate

projs

Return projection names in data vector.

size

Equivalent for __length__().

__add__(other)

Addition of two data vectors is defined as concatenation.

__call__(proj, *args, grid=True, default_zero=False)

Return projection proj of window function interpolated at input data points.

Parameters
  • proj (ProjectionName) – Projection name.

  • args (list) – List of coordinates where to interpolate window function.

  • grid (bool, default=True) – Whether input coordinates should be interpreted as a grid, in which case the output will be an array of shape (x1.size, x2.size, ...) with x1, x2 the input coordinates.

  • default_zero (bool, default=False) – If a given projection is not provided in window function, set to 0. Else an IndexError is raised.

Returns

toret – Interpolated values of window function.

Return type

array

classmethod concatenate(*others)

Concatenate data vectors together.

Parameters

others (list) – List of DataVector instances.

Returns

new

Return type

DataVector

Warning

attrs of returned data vector contains, for each key, the last value found in others attrs dictionaries.

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 BinnedProjection instance corresponding to proj.

Parameters
  • proj (ProjectionName, tuple, string, dict) – Projection name to search for.

  • permissive (bool, default=False) – If True, include projections which match input proj (in kwargs) for non-None attributes. For example ProjectionName(space=’power’,mode=’multipole’,proj=0) would match ell_0 (space not specified).

Returns

dataproj

Return type

BinnedProjection

get_edges(**kwargs)

Return edges for kwargs selections.

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 attrs using 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 obtain pk monopole between 0.1 and 0.2. pk.get_index(proj=(0,2)) will return indices to obtain pk monopole and quadrupole.

Parameters
  • permissive (bool) – If True, include projections which match input proj (in kwargs) for non-None attributes. For example ProjectionName(space=’power’,mode=’multipole’,proj=0) would match ell_0 (space not specified).

  • index_in_view (bool) – Whether to return index w.r.t. to current view.

  • kwargs (dict) – Dictionary of selections (i.e. list of proj and xlim).

Returns

indices – Tuple (if input selections are not lists), or list of tuples (proj, index) with index indices for projection of name proj.

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 for pk monopole between 0.1 and 0.2. pk.get_x(proj=(0,2)) will return wavenumbers for pk monopole and quadrupole.

Parameters
  • concatenate (bool, default=False) – Concatenate output x-coordinates?

  • kwargs (dict) – Dictionary of selections (i.e. list of proj and xlim).

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 in cls._registry, return instance of cls._registry[__class__] (instead of cls).

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), calls load()

  • 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 BinnedStatistic from disk.

Note

If previously saved using save_txt(), loading the DataVector only requires filename. In this case, the returned instance will be of the class that was used to create it (e.g. MockDataVector) - not necessarily DataVector.

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_rows lines, including comments.

  • max_rows (int, default=None) – Read max_rows lines of content after skip_rows lines. 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 attrs dictionary.

  • 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 attrs dictionary.

  • kwargs (dict) – Other arguments for BinnedProjection.load_txt().

Returns

data

Return type

DataVector

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, splitting module.class into (module, class). It loads module, then if class is in _registry, return corresponding class. Else return None.

rebin(proj, *args, **kwargs)

Rebin projection of name proj (list or single projection name). See BinnedStatistic.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), calls save()

  • 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 attrs using json, ignore errors.

Returns

lines – List of strings (lines).

Return type

list

set(data)

Add new BinnedProjection instance.

set_new_edges(proj, *args, **kwargs)

Set new edges for projection of name proj (list or single projection name). See BinnedStatistic.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 between 0.1 and 0.2.

Parameters
  • y (list, array) – y arrays for each projection.

  • concatenated (bool, default=True) – If True, y is a single array, which is split into the different projections given current view and kwargs.

  • 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 return pk monopole between 0.1 and 0.2.