Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility function for porting from MNE-Python ICA labels/labels_score data structure to internals #81

Open
adam2392 opened this issue Jul 28, 2022 · 3 comments

Comments

@adam2392
Copy link
Member

IN #66 there's some repeated code for handling the conversion of MNE-Python's ICA internal data structures to labels on our end and vice versa. We should create a robust utility function to ensure bugs don't leak thru.

@mscheltienne
Copy link
Member

Can you precise this a bit? I'm not sure I'm following

@adam2392
Copy link
Member Author

It's mainly code like this in the GUI:

        for label, comp_list in labels2save.items():
            mne_label = ICLABEL_LABELS_TO_MNE[label]
            if mne_label not in self._ica.labels_:
                self._ica.labels_[mne_label] = comp_list
                continue
            for comp in comp_list:
                if comp not in self._ica.labels_[mne_label]:
                    self._ica.labels_[mne_label].append(comp)

and code like this in write_components_tsv

    # extract the component labels if they are present in the ICA instance
    if ica.labels_:
        for label, comps in ica.labels_.items():
            this_status = "good" if label == "brain" else "bad"
            if label in ICLABEL_LABELS_TO_MNE.values():
                for comp in comps:
                    status[comp] = this_status
                    ic_type[comp] = label

and we'll probably want to modify the ICA instance in place when running the automated models, so like in ICLabel:

    if inplace:
        from mne_icalabel.config import ICLABEL_LABELS_TO_MNE

        ica.labels_scores_ = labels_pred_proba
        argmax_labels = np.argmax(labels_pred_proba, axis=1)

        # add labels to the ICA instance
        for idx, (_, mne_label) in enumerate(ICLABEL_LABELS_TO_MNE.items()):
            auto_labels = argmax_labels.index[idx]
            if mne_label not in ica.labels_:
                ica.labels_[mne_label] = auto_labels
                continue
            for comp in auto_labels:
                if comp not in ica.labels_[mne_label]:
                    ica.labels_[mne_label].append(comp)

These I just wrote up for the sake of making it work, but prolly best to have a private API for interfacing the conversion between MNE and our ICA label semantics.

@mscheltienne
Copy link
Member

OK sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants