Dictionary-like object holding a projection vector. Projection vectors are stored in a list in ``inst.info["projs"]``. Each projection vector has 5 keys: ``active``, ``data``, ``desc``, ``explained_var``, ``kind``. .. warning:: This class is generally not meant to be instantiated
| 36 | |
| 37 | |
| 38 | class Projection(dict): |
| 39 | """Dictionary-like object holding a projection vector. |
| 40 | |
| 41 | Projection vectors are stored in a list in ``inst.info["projs"]``. Each projection |
| 42 | vector has 5 keys: ``active``, ``data``, ``desc``, ``explained_var``, ``kind``. |
| 43 | |
| 44 | .. warning:: This class is generally not meant to be instantiated |
| 45 | directly, use ``compute_proj_*`` functions instead. |
| 46 | |
| 47 | Parameters |
| 48 | ---------- |
| 49 | data : dict |
| 50 | The data dictionary. |
| 51 | desc : str |
| 52 | The projector description. |
| 53 | kind : int |
| 54 | The projector kind. |
| 55 | active : bool |
| 56 | Whether or not the projector has been applied. |
| 57 | explained_var : float | None |
| 58 | The proportion of explained variance. |
| 59 | """ |
| 60 | |
| 61 | def __init__( |
| 62 | self, |
| 63 | *, |
| 64 | data, |
| 65 | desc="", |
| 66 | kind=FIFF.FIFFV_PROJ_ITEM_FIELD, |
| 67 | active=False, |
| 68 | explained_var=None, |
| 69 | ): |
| 70 | super().__init__( |
| 71 | desc=desc, kind=kind, active=active, data=data, explained_var=explained_var |
| 72 | ) |
| 73 | |
| 74 | def __repr__(self): # noqa: D105 |
| 75 | s = str(self["desc"]) |
| 76 | s += f", active : {self['active']}" |
| 77 | s += f", n_channels : {len(self['data']['col_names'])}" |
| 78 | if self["explained_var"] is not None: |
| 79 | s += f", exp. var : {self['explained_var'] * 100:0.2f}%" |
| 80 | return f"<Projection | {s}>" |
| 81 | |
| 82 | # speed up info copy by taking advantage of mutability |
| 83 | def __deepcopy__(self, memodict): |
| 84 | """Make a deepcopy.""" |
| 85 | cls = self.__class__ |
| 86 | result = cls.__new__(cls) |
| 87 | for k, v in self.items(): |
| 88 | if k == "data": |
| 89 | v = v.copy() |
| 90 | v["data"] = v["data"].copy() |
| 91 | result[k] = v |
| 92 | else: |
| 93 | result[k] = v # kind, active, desc, explained_var immutable |
| 94 | return result |
| 95 |
no outgoing calls