A transform. Parameters ---------- fro : str | int The starting coordinate frame. See notes for valid coordinate frames. to : str | int The ending coordinate frame. See notes for valid coordinate frames. trans : array of shape (4, 4) | None The transforma
| 93 | |
| 94 | |
| 95 | class Transform(dict): |
| 96 | """A transform. |
| 97 | |
| 98 | Parameters |
| 99 | ---------- |
| 100 | fro : str | int |
| 101 | The starting coordinate frame. See notes for valid coordinate frames. |
| 102 | to : str | int |
| 103 | The ending coordinate frame. See notes for valid coordinate frames. |
| 104 | trans : array of shape (4, 4) | None |
| 105 | The transformation matrix. If None, an identity matrix will be |
| 106 | used. |
| 107 | |
| 108 | Notes |
| 109 | ----- |
| 110 | Valid coordinate frames are ``'meg'``, ``'mri'``, ``'mri_voxel'``, |
| 111 | ``'head'``, ``'mri_tal'``, ``'ras'``, ``'fs_tal'``, ``'ctf_head'``, |
| 112 | ``'ctf_meg'``, ``'unknown'``. |
| 113 | """ |
| 114 | |
| 115 | def __init__(self, fro, to, trans=None): |
| 116 | super().__init__() |
| 117 | # we could add some better sanity checks here |
| 118 | fro = _to_const(fro) |
| 119 | to = _to_const(to) |
| 120 | trans = np.eye(4) if trans is None else np.asarray(trans, np.float64) |
| 121 | if trans.shape != (4, 4): |
| 122 | raise ValueError(f"Transformation must be shape (4, 4) not {trans.shape}") |
| 123 | self["from"] = fro |
| 124 | self["to"] = to |
| 125 | self["trans"] = trans |
| 126 | |
| 127 | def __repr__(self): # noqa: D105 |
| 128 | with np.printoptions(suppress=True): # suppress scientific notation |
| 129 | return "<Transform | {fro}->{to}>\n{trans}".format( |
| 130 | fro=_coord_frame_name(self["from"]), |
| 131 | to=_coord_frame_name(self["to"]), |
| 132 | trans=self["trans"], |
| 133 | ) |
| 134 | |
| 135 | def __eq__(self, other, rtol=0.0, atol=0.0): |
| 136 | """Check for equality. |
| 137 | |
| 138 | Parameter |
| 139 | --------- |
| 140 | other : instance of Transform |
| 141 | The other transform. |
| 142 | rtol : float |
| 143 | Relative tolerance. |
| 144 | atol : float |
| 145 | Absolute tolerance. |
| 146 | |
| 147 | Returns |
| 148 | ------- |
| 149 | eq : bool |
| 150 | True if the transforms are equal. |
| 151 | """ |
| 152 | return ( |
no outgoing calls