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

Function scale_labels

mne/coreg.py:950–1017  ·  view source on GitHub ↗

r"""Scale labels to match a brain that was previously created by scaling. Parameters ---------- subject_to : str Name of the scaled MRI subject (the destination brain). pattern : str | None Pattern for finding the labels relative to the label directory in the

(
    subject_to,
    pattern=None,
    overwrite=False,
    subject_from=None,
    *,
    scale=None,
    subjects_dir=None,
    verbose=None,
)

Source from the content-addressed store, hash-verified

948
949@verbose
950def scale_labels(
951 subject_to,
952 pattern=None,
953 overwrite=False,
954 subject_from=None,
955 *,
956 scale=None,
957 subjects_dir=None,
958 verbose=None,
959):
960 r"""Scale labels to match a brain that was previously created by scaling.
961
962 Parameters
963 ----------
964 subject_to : str
965 Name of the scaled MRI subject (the destination brain).
966 pattern : str | None
967 Pattern for finding the labels relative to the label directory in the
968 MRI subject directory (e.g., "lh.BA3a.label" will scale
969 "fsaverage/label/lh.BA3a.label"; "aparc/\*.label" will find all labels
970 in the "fsaverage/label/aparc" directory). With None, scale all labels.
971 overwrite : bool
972 Overwrite any label file that already exists for subject_to (otherwise
973 existing labels are skipped).
974 subject_from : None | str
975 Name of the original MRI subject (the brain that was scaled to create
976 subject_to). If None, the value is read from subject_to's cfg file.
977 scale : None | float | array_like, shape = (3,)
978 Scaling parameter. If None, the value is read from subject_to's cfg
979 file.
980 subjects_dir : None | path-like
981 Override the ``SUBJECTS_DIR`` environment variable.
982 %(verbose)s
983 """
984 subjects_dir, subject_from, scale, _ = _scale_params(
985 subject_to, subject_from, scale, subjects_dir
986 )
987
988 # find labels
989 paths = _find_label_paths(subject_from, pattern, subjects_dir)
990 if not paths:
991 return
992
993 subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
994 src_root = subjects_dir / subject_from / "label"
995 dst_root = subjects_dir / subject_to / "label"
996
997 # scale labels
998 for fname in paths:
999 dst = dst_root / fname
1000 if not overwrite and dst.exists():
1001 continue
1002
1003 if not dst.parent.exists():
1004 os.makedirs(dst.parent)
1005
1006 src = src_root / fname
1007 l_old = read_label(src)

Callers 2

test_scale_mriFunction · 0.90
scale_mriFunction · 0.85

Calls 6

saveMethod · 0.95
_scale_paramsFunction · 0.85
_find_label_pathsFunction · 0.85
get_subjects_dirFunction · 0.85
read_labelFunction · 0.85
LabelClass · 0.85

Tested by 1

test_scale_mriFunction · 0.72