vferat/pycrostates

Read in ModK Data Structure

Closed this issue · 3 comments

Hello,

I am having an issue with the individual ModKs that I saved for each participant with the ModK.save('location') method. The data structure that I read back in with pycrostates.io.read_cluster('location') is completely different. There is no plot, rename_clusters, reorder_clusters, or cluster_centers in the structure. I seem to still be able to feed the ModKs into ModK.predict(ModK) to get the segmentation, but I cannot reorder or relabel anything. Is there a way for me to get this part of the ModK data structure back, or is there a different way to deal with it after it has been saved?
Note: this does not seem to be the case with Group ModKs, they retain the same data structure from the original.

Best,
Matt

One problem is that you save to a file called 'location' lacking the FIF extension.
In theory, the file is still readable anyway, but our reader expects the extension.

c.f. on toy data:

import numpy as np
import pytest
from mne.io import RawArray
from mne import create_info
from numpy.testing import assert_allclose

from pycrostates.cluster import ModKMeans
from pycrostates.io import read_cluster

raw = RawArray(np.random.randn(3, 100), create_info(3, 1000, "eeg"))
modK = ModKMeans(n_clusters=3, random_state=42)
modK.fit(raw)
modK.save("location")
modK.save("location.fif")

with pytest.raises(ValueError, match="File format is not supported"):
    modK2 = read_cluster("location")
modK3 = read_cluster("location.fif")
assert_allclose(modK3.cluster_centers_, modK.cluster_centers_)

Can you share more information and code snippet about what you are doing and what is failing?

Hi @mscheltienne I didn't actually use 'location' as the pathway, I am on a server and the pathway is long and mailable because I am running this on all participants in a loop. This is data from the Human Connectome Project. However, It seems the issue was with the server and not the code. I have been able to get them to fix it since. It was for some reason only reading in the plot portion of the fif.

OK, closing it that was fixed.