MCPcopy
hub / github.com/mne-tools/mne-python / read_source_estimate

Function read_source_estimate

mne/source_estimate.py:243–396  ·  view source on GitHub ↗

Read a source estimate object. Parameters ---------- fname : path-like Path to (a) source-estimate file(s). subject : str | None Name of the subject the source estimate(s) is (are) from. It is good practice to set this attribute to avoid combining inc

(fname, subject=None)

Source from the content-addressed store, hash-verified

241
242
243def read_source_estimate(fname, subject=None):
244 """Read a source estimate object.
245
246 Parameters
247 ----------
248 fname : path-like
249 Path to (a) source-estimate file(s).
250 subject : str | None
251 Name of the subject the source estimate(s) is (are) from.
252 It is good practice to set this attribute to avoid combining
253 incompatible labels and SourceEstimates (e.g., ones from other
254 subjects). Note that due to file specification limitations, the
255 subject name isn't saved to or loaded from files written to disk.
256
257 Returns
258 -------
259 stc : SourceEstimate | VectorSourceEstimate | VolSourceEstimate | MixedSourceEstimate
260 The source estimate object loaded from file.
261
262 Notes
263 -----
264 - for volume source estimates, ``fname`` should provide the path to a
265 single file named ``'*-vl.stc``` or ``'*-vol.stc'``
266 - for surface source estimates, ``fname`` should either provide the
267 path to the file corresponding to a single hemisphere (``'*-lh.stc'``,
268 ``'*-rh.stc'``) or only specify the asterisk part in these patterns. In
269 any case, the function expects files for both hemisphere with names
270 following this pattern.
271 - for vector surface source estimates, only HDF5 files are supported.
272 - for mixed source estimates, only HDF5 files are supported.
273 - for single time point ``.w`` files, ``fname`` should follow the same
274 pattern as for surface estimates, except that files are named
275 ``'*-lh.w'`` and ``'*-rh.w'``.
276 """ # noqa: E501
277 fname_arg = fname
278
279 # expand `~` without checking whether the file actually exists – we'll
280 # take care of that later, as it's complicated by the different suffixes
281 # STC files can have
282 fname = str(_check_fname(fname=fname, overwrite="read", must_exist=False))
283
284 # make sure corresponding file(s) can be found
285 ftype = None
286 if op.exists(fname):
287 if fname.endswith(("-vl.stc", "-vol.stc", "-vl.w", "-vol.w")):
288 ftype = "volume"
289 elif fname.endswith(".stc"):
290 ftype = "surface"
291 if fname.endswith(("-lh.stc", "-rh.stc")):
292 fname = fname[:-7]
293 else:
294 err = (
295 f"Invalid .stc filename: {fname!r}; needs to end with "
296 "hemisphere tag ('...-lh.stc' or '...-rh.stc')"
297 )
298 raise OSError(err)
299 elif fname.endswith(".w"):
300 ftype = "w"

Callers 15

test_xhemi_morphFunction · 0.90
test_morph_stc_denseFunction · 0.90
test_morph_stc_sparseFunction · 0.90
test_sensitivity_mapsFunction · 0.90
test_labels_to_stcFunction · 0.90
test_stc_to_labelFunction · 0.90

Calls 5

_check_fnameFunction · 0.85
_read_stcFunction · 0.85
_read_wFunction · 0.85
_import_h5io_funcsFunction · 0.85
copyMethod · 0.45

Tested by 15

test_xhemi_morphFunction · 0.72
test_morph_stc_denseFunction · 0.72
test_morph_stc_sparseFunction · 0.72
test_sensitivity_mapsFunction · 0.72
test_labels_to_stcFunction · 0.72
test_stc_to_labelFunction · 0.72