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)
| 776 | |
| 777 | |
| 778 | def 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 | |
| 822 | def _write_mri_config(fname, subject_from, subject_to, scale): |
no test coverage detected