From 28c83ede5769f64b7a96e041ca8578730dbab8c2 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Tue, 7 Jun 2022 16:08:12 -0400 Subject: [PATCH] WiP(idea): memoize get_study_sessions result TODOs: - [ ] add support for memoizing not just on a single path but on muliple in fscacher - ideally would need also to support looking for files in other options since here we have heuristic which would point to a file but it makes things more complicated --- heudiconv/main.py | 4 ++-- heudiconv/parser.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/heudiconv/main.py b/heudiconv/main.py index 5c6f37d5..29465760 100644 --- a/heudiconv/main.py +++ b/heudiconv/main.py @@ -83,7 +83,7 @@ def process_extra_commands(outdir, command, files, dicom_dir_template, heuristic_ls = getattr(heuristic, 'ls', None) for f in files: study_sessions = get_study_sessions( - dicom_dir_template, [f], heuristic, outdir, + [f], dicom_dir_template, heuristic, outdir, session, subjs, grouping=grouping) print(f) for study_session, sequences in study_sessions.items(): @@ -324,7 +324,7 @@ def workflow(*, dicom_dir_template=None, files=None, subjs=None, heuristic = load_heuristic(heuristic) - study_sessions = get_study_sessions(dicom_dir_template, files, + study_sessions = get_study_sessions(files, dicom_dir_template, heuristic, outdir, session, subjs, grouping=grouping) diff --git a/heudiconv/parser.py b/heudiconv/parser.py index 3db1fc2c..89e3b8a7 100644 --- a/heudiconv/parser.py +++ b/heudiconv/parser.py @@ -113,8 +113,18 @@ def get_extracted_dicoms(fl): return sessions.items() +from fscacher import PersistentCache +from ._version import __version__ -def get_study_sessions(dicom_dir_template, files_opt, heuristic, outdir, +study_sessions_cache = PersistentCache( + name="heudiconv-study-sessions", + tokens=[__version__], + envvar="HEUDICONV_CACHE", +) + + +@study_sessions_cache.memoize_paths +def get_study_sessions(files_opt, dicom_dir_template, heuristic, outdir, session, sids, grouping='studyUID'): """Given options from cmdline sort files or dicom seqinfos into study_sessions which put together files for a single session of a subject