Format the dig points nicely.
(dig, enforce_order=False)
| 33 | |
| 34 | |
| 35 | def _format_dig_points(dig, enforce_order=False): |
| 36 | """Format the dig points nicely.""" |
| 37 | if enforce_order and dig is not None: |
| 38 | # reorder points based on type: |
| 39 | # Fiducials/HPI, EEG, extra (headshape) |
| 40 | fids_digpoints = [] |
| 41 | hpi_digpoints = [] |
| 42 | eeg_digpoints = [] |
| 43 | extra_digpoints = [] |
| 44 | head_digpoints = [] |
| 45 | |
| 46 | # use a heap to enforce order on FIDS, EEG, Extra |
| 47 | for idx, digpoint in enumerate(dig): |
| 48 | ident = digpoint["ident"] |
| 49 | kind = digpoint["kind"] |
| 50 | |
| 51 | # push onto heap based on 'ident' (for the order) for |
| 52 | # each of the possible DigPoint 'kind's |
| 53 | # keep track of 'idx' in case of any clashes in |
| 54 | # the 'ident' variable, which can occur when |
| 55 | # user passes in DigMontage + DigMontage |
| 56 | if kind == FIFF.FIFFV_POINT_CARDINAL: |
| 57 | heapq.heappush(fids_digpoints, (ident, idx, digpoint)) |
| 58 | elif kind == FIFF.FIFFV_POINT_HPI: |
| 59 | heapq.heappush(hpi_digpoints, (ident, idx, digpoint)) |
| 60 | elif kind == FIFF.FIFFV_POINT_EEG: |
| 61 | heapq.heappush(eeg_digpoints, (ident, idx, digpoint)) |
| 62 | elif kind == FIFF.FIFFV_POINT_EXTRA: |
| 63 | heapq.heappush(extra_digpoints, (ident, idx, digpoint)) |
| 64 | elif kind == FIFF.FIFFV_POINT_HEAD: |
| 65 | heapq.heappush(head_digpoints, (ident, idx, digpoint)) |
| 66 | |
| 67 | # now recreate dig based on sorted order |
| 68 | fids_digpoints.sort(), hpi_digpoints.sort() |
| 69 | eeg_digpoints.sort() |
| 70 | extra_digpoints.sort(), head_digpoints.sort() |
| 71 | new_dig = [] |
| 72 | for idx, d in enumerate( |
| 73 | fids_digpoints |
| 74 | + hpi_digpoints |
| 75 | + extra_digpoints |
| 76 | + eeg_digpoints |
| 77 | + head_digpoints |
| 78 | ): |
| 79 | new_dig.append(d[-1]) |
| 80 | dig = new_dig |
| 81 | |
| 82 | return [DigPoint(d) for d in dig] if dig is not None else dig |
| 83 | |
| 84 | |
| 85 | def _get_dig_eeg(dig): |