lib.data_vector.projection.ProjectionNameCollection

class lib.data_vector.projection.ProjectionNameCollection(items=None)

Bases: cosmopipe.lib.utils.BaseOrderedCollection

Class describing a collection of projections.

Note

When adding a projection equal to another already in the collection, the latter will be replaced by the former. Insertion order is conserved.

Initialize BaseOrderedCollection.

Parameters

items (list, object, BaseOrderedCollection) – List of elements to add to the collection. If not list, interpreted as single element. If BaseOrderedCollection instance, update __dict__.

Methods

clear

Empty collection.

concatenate

Concatenate input collections.

copy

Return shallow copy of self.

deepcopy

extend

Extend collection with other.

from_state

Instantiate and initalize class with state dictionary.

get

Return proj instance in self corresponding to ProjectionName proj.

group_by

Group ProjectionName by similar attributes.

index

Return index of ProjectionName proj.

is_mpi_broadcast

is_mpi_gathered

is_mpi_root

is_mpi_scattered

load

Load class in numpy binary format from disk.

load_auto

If different formats are possible, this method should between them based on file name extension.

log_critical

log_debug

log_error

log_info

log_warning

reorder

Reorder collection following index list indices.

save

Save class to disk.

save_auto

If different formats are possible, this method should between them based on file name extension.

select

Return new collection, after selection of items whose attribute match input values.

set

Set item in collection.

unique

Return list of unique attribute key of collection items.

Attributes

logger

mpiattrs

MPI attributes

mpicomm

mpiroot

mpistate

__add__(other)

Addition of two collections is defined as concatenation.

clear()

Empty collection.

classmethod concatenate(*others)

Concatenate input collections. Unique items only are kept.

copy()

Return shallow copy of self.

extend(other)

Extend collection with other. Unique items only are kept.

classmethod from_state(state, mpiroot=0, mpicomm=None)

Instantiate and initalize class with state dictionary.

get(proj, ignore_none=True)

Return proj instance in self corresponding to ProjectionName proj.

Parameters
  • proj (string, tuple, dict) – Arguments to initialize ProjectionName.

  • ignore_none (bool, default=False) – When comparing ProjectionName instances, ignore None (unspecified) attributes.

Returns

proj – If ignore_none is True, return list of all matching projections. Else return ProjectionName instance matching proj.

Return type

ProjectionName, list

group_by(include=None, exclude=None)

Group ProjectionName by similar attributes.

Example

collection.group_by(include=['space']) will group projections by space. collection.group_by(excluding=['mode']) will group projections ignoring differences in mode.

Parameters
  • include (list, default=None) – List of ProjectionName attributes to form a group.

  • exclude (list, default=None) – List of ProjectionName attributes to ignore when forming a group.

Returns

toret – Dictionary of proj: collection, with proj the ProjectionName instance with attributes common to all projections in ProjectionNameCollection collection.

Return type

dict

index(proj, ignore_none=False)

Return index of ProjectionName proj.

Parameters
  • proj (string, tuple, dict) – Arguments to initialize ProjectionName.

  • ignore_none (bool, default=False) – When comparing ProjectionName instances, ignore None (unspecified) attributes.

Returns

index – If ignore_none is True, return list of all matches. Else return index of proj.

Return type

int, list

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).

load_auto(*args, **kwargs)

If different formats are possible, this method should between them based on file name extension.

property mpiattrs

MPI attributes

reorder(indices)

Reorder collection following index list indices.

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.

select(*args, **kwargs)

Return new collection, after selection of items whose attribute match input values:

collection.select(name1=value1,name2=value2)

returns collection of items whose attributes name1 and name2` are value1, value2, respectively. Also:

collection.select(dict(name1=value1,name2=value2),dict(name2=value3))

returns collection of items whose attributes name1 and name2` are value1, value2, respectively or attribute name2 is value3.

set(item)

Set item in collection. If already in collection (following criteria defined in item.__eq__), replace this stored item by the input one. Else, append item to collection.

unique(key)

Return list of unique attribute key of collection items.