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

Function read_mri_cfg

mne/coreg.py:778–819  ·  view source on GitHub ↗

Read information from the cfg file of a scaled MRI brain. Parameters ---------- subject : str Name of the scaled MRI subject. subjects_dir : None | path-like Override the ``SUBJECTS_DIR`` environment variable. Returns ------- cfg : dict Dictionar

(subject, subjects_dir=None)

Source from the content-addressed store, hash-verified

776
777
778def read_mri_cfg(subject, subjects_dir=None):
779 """Read information from the cfg file of a scaled MRI brain.
780
781 Parameters
782 ----------
783 subject : str
784 Name of the scaled MRI subject.
785 subjects_dir : None | path-like
786 Override the ``SUBJECTS_DIR`` environment variable.
787
788 Returns
789 -------
790 cfg : dict
791 Dictionary with entries from the MRI's cfg file.
792 """
793 subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
794 fname = subjects_dir / subject / "MRI scaling parameters.cfg"
795
796 if not fname.exists():
797 raise OSError(
798 f"{subject!r} does not seem to be a scaled mri subject: {fname!r} does not"
799 "exist."
800 )
801
802 logger.info(f"Reading MRI cfg file {fname}")
803 config = configparser.RawConfigParser()
804 config.read(fname)
805 n_params = config.getint("MRI Scaling", "n_params")
806 if n_params == 1:
807 scale = config.getfloat("MRI Scaling", "scale")
808 elif n_params == 3:
809 scale_str = config.get("MRI Scaling", "scale")
810 scale = np.array([float(s) for s in scale_str.split()])
811 else:
812 raise ValueError(f"Invalid n_params value in MRI cfg: {n_params}")
813
814 out = {
815 "subject_from": config.get("MRI Scaling", "subject_from"),
816 "n_params": n_params,
817 "scale": scale,
818 }
819 return out
820
821
822def _write_mri_config(fname, subject_from, subject_to, scale):

Callers 2

_scale_paramsFunction · 0.85
head_to_mriFunction · 0.85

Calls 4

get_subjects_dirFunction · 0.85
infoMethod · 0.80
readMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected