Create an electrode definition, transform coords if necessary.
(ch, t=None)
| 208 | |
| 209 | |
| 210 | def _create_eeg_el(ch, t=None): |
| 211 | """Create an electrode definition, transform coords if necessary.""" |
| 212 | if ch["kind"] != FIFF.FIFFV_EEG_CH: |
| 213 | raise RuntimeError( |
| 214 | f"{ch['ch_name']} is not an EEG channel. Cannot create an electrode " |
| 215 | "definition." |
| 216 | ) |
| 217 | if t is None: |
| 218 | t = Transform("head", "head") # identity, no change |
| 219 | if t.from_str != "head": |
| 220 | raise RuntimeError("Inappropriate coordinate transformation") |
| 221 | |
| 222 | r0ex = _loc_to_eeg_loc(ch["loc"]) |
| 223 | if r0ex.shape[1] == 1: # no reference |
| 224 | w = np.array([1.0]) |
| 225 | else: # has reference |
| 226 | w = np.array([1.0, -1.0]) |
| 227 | |
| 228 | # Optional coordinate transformation |
| 229 | r0ex = apply_trans(t["trans"], r0ex.T) |
| 230 | |
| 231 | # The electrode location |
| 232 | cosmag = r0ex.copy() |
| 233 | _normalize_vectors(cosmag) |
| 234 | res = dict( |
| 235 | chname=ch["ch_name"], |
| 236 | coil_class=FWD.COILC_EEG, |
| 237 | w=w, |
| 238 | accuracy=_accuracy_dict["normal"], |
| 239 | type=ch["coil_type"], |
| 240 | coord_frame=t["to"], |
| 241 | rmag=r0ex, |
| 242 | cosmag=cosmag, |
| 243 | ) |
| 244 | return res |
| 245 | |
| 246 | |
| 247 | def _create_meg_coils(chs, acc, t=None, coilset=None, do_es=False): |
no test coverage detected