-
Notifications
You must be signed in to change notification settings - Fork 7
Inclusion config #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Inclusion config #243
Changes from 2 commits
00adacb
be1ae4d
b4a3845
0d8cabd
e57e52b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1701,18 +1701,18 @@ def load_audio_filestems_to_remove(publish_config_dir: Path) -> t.List[str]: | |||||||||||||||||||||||||||||||||||||||||
| return data | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||
| def load_sensitive_audio_tasks(deidentify_config_dir: Path) -> t.List[str]: | ||||||||||||||||||||||||||||||||||||||||||
| def load_audio_tasks_to_include(deidentify_config_dir: Path) -> t.List[str]: | ||||||||||||||||||||||||||||||||||||||||||
| """Load list of audio tasks that are sensitive from JSON file.""" | ||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_tasks_path = deidentify_config_dir / "sensitive_audio_tasks.json" | ||||||||||||||||||||||||||||||||||||||||||
| if not sensitive_audio_tasks_path.exists(): | ||||||||||||||||||||||||||||||||||||||||||
| audio_tasks_to_include_path = deidentify_config_dir / "audio_tasks_to_include.json" | ||||||||||||||||||||||||||||||||||||||||||
| if not audio_tasks_to_include_path.exists(): | ||||||||||||||||||||||||||||||||||||||||||
| # If file doesn't exist, raise an error | ||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError(f"Sensitive audio tasks file {sensitive_audio_tasks_path} does not exist.") | ||||||||||||||||||||||||||||||||||||||||||
| raise FileNotFoundError(f"Sensitive audio tasks file {audio_tasks_to_include_path} does not exist.") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| with open(sensitive_audio_tasks_path, 'r') as f: | ||||||||||||||||||||||||||||||||||||||||||
| with open(audio_tasks_to_include_path, 'r') as f: | ||||||||||||||||||||||||||||||||||||||||||
| data = json.load(f) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if not isinstance(data, list): | ||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Sensitive audio tasks file {sensitive_audio_tasks_path} should contain a list of audio task names.") | ||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Sensitive audio tasks file {audio_tasks_to_include_path} should contain a list of audio task names.") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return data | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1741,7 +1741,8 @@ def deidentify(self, outdir: t.Union[str, Path], deidentify_config_dir: Path, sk | |||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remap = BIDSDataset.load_remap_id_list(deidentify_config_dir) | ||||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remove = BIDSDataset.load_participant_ids_to_remove(deidentify_config_dir) | ||||||||||||||||||||||||||||||||||||||||||
| audio_filestems_to_remove = BIDSDataset.load_audio_filestems_to_remove(deidentify_config_dir) | ||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_tasks = BIDSDataset.load_sensitive_audio_tasks(deidentify_config_dir) | ||||||||||||||||||||||||||||||||||||||||||
| #sensitive_audio_tasks = BIDSDataset.load_sensitive_audio_tasks(deidentify_config_dir) | ||||||||||||||||||||||||||||||||||||||||||
| audio_tasks_to_include = BIDSDataset.load_audio_tasks_to_include(deidentify_config_dir) | ||||||||||||||||||||||||||||||||||||||||||
Evan8456 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
| participant_session_id_to_remap = BIDSDataset.map_sequential_session_ids(self.data_path) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Allow users to specify filestems either in the original ID space (pre-deidentify) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1784,7 +1785,7 @@ def deidentify(self, outdir: t.Union[str, Path], deidentify_config_dir: Path, sk | |||||||||||||||||||||||||||||||||||||||||
| outdir, | ||||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remove, | ||||||||||||||||||||||||||||||||||||||||||
| audio_filestems_to_remove, | ||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_tasks, | ||||||||||||||||||||||||||||||||||||||||||
| audio_tasks_to_include, | ||||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remap, | ||||||||||||||||||||||||||||||||||||||||||
| participant_session_id_to_remap, | ||||||||||||||||||||||||||||||||||||||||||
| max_workers=max_workers, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1799,7 +1800,7 @@ def deidentify(self, outdir: t.Union[str, Path], deidentify_config_dir: Path, sk | |||||||||||||||||||||||||||||||||||||||||
| outdir, | ||||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remove, | ||||||||||||||||||||||||||||||||||||||||||
| audio_filestems_to_remove, | ||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_tasks, | ||||||||||||||||||||||||||||||||||||||||||
| audio_tasks_to_include, | ||||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remap, | ||||||||||||||||||||||||||||||||||||||||||
| participant_session_id_to_remap, | ||||||||||||||||||||||||||||||||||||||||||
| max_workers=max_workers, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1843,7 +1844,6 @@ def _apply_exclusion_list_to_filepaths( | |||||||||||||||||||||||||||||||||||||||||
| exclusion = set(exclusion_list) | ||||||||||||||||||||||||||||||||||||||||||
| if len(exclusion) == 0: | ||||||||||||||||||||||||||||||||||||||||||
| return paths | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def _canonical_recording_stem(stem: str) -> str: | ||||||||||||||||||||||||||||||||||||||||||
| """Canonicalize a BIDS-like recording stem for matching. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1894,6 +1894,29 @@ def _canonical_recording_stem(stem: str) -> str: | |||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| return paths | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||
| def _grab_filepaths_list_to_include( | ||||||||||||||||||||||||||||||||||||||||||
| paths: t.List[Path], | ||||||||||||||||||||||||||||||||||||||||||
| inclusion_list: t.List[str], | ||||||||||||||||||||||||||||||||||||||||||
| ) -> t.List[Path]: | ||||||||||||||||||||||||||||||||||||||||||
| """Grabs filepaths based on overlap with a specified inclusion list.""" | ||||||||||||||||||||||||||||||||||||||||||
| n = len(paths) | ||||||||||||||||||||||||||||||||||||||||||
| inclusion = set(inclusion_list) | ||||||||||||||||||||||||||||||||||||||||||
| if len(inclusion) == 0: | ||||||||||||||||||||||||||||||||||||||||||
| return paths | ||||||||||||||||||||||||||||||||||||||||||
Evan8456 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| new_paths = [] | ||||||||||||||||||||||||||||||||||||||||||
| for file in paths: | ||||||||||||||||||||||||||||||||||||||||||
| for incl in inclusion_list: | ||||||||||||||||||||||||||||||||||||||||||
| if normalize_task_label(incl) in normalize_task_label(file.stem): | ||||||||||||||||||||||||||||||||||||||||||
| new_paths.append(file) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
1902
to
1911
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation has a couple of issues:
I suggest refactoring this part to be more efficient and to prevent adding duplicate paths.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added an early
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't do the efficient things it mentions but u do solve the possible error |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if len(new_paths) < n: | ||||||||||||||||||||||||||||||||||||||||||
| _LOGGER.info( | ||||||||||||||||||||||||||||||||||||||||||
| f"Removed {n - len(new_paths)} records due to not being part of inclusion list: {inclusion_list}." | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| return new_paths | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @staticmethod | ||||||||||||||||||||||||||||||||||||||||||
| def _expand_filestems_for_deidentification( | ||||||||||||||||||||||||||||||||||||||||||
| filestems: t.Iterable[str], | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1996,7 +2019,7 @@ def _deidentify_audio_files( | |||||||||||||||||||||||||||||||||||||||||
| outdir: Path, | ||||||||||||||||||||||||||||||||||||||||||
| exclude_participant_ids: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| exclude_audio_filestems: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_task_list: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| audio_tasks_to_include_list: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remap: t.Dict[str, str] = {}, | ||||||||||||||||||||||||||||||||||||||||||
| participant_session_id_to_remap: t.Dict[str, str] = {}, | ||||||||||||||||||||||||||||||||||||||||||
| max_workers: int = 16, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2041,9 +2064,9 @@ def _deidentify_audio_files( | |||||||||||||||||||||||||||||||||||||||||
| audio_paths, exclusion_list=['audio-check'], exclusion_type='filestem_contains' | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_task_list = [f"task-{normalize_task_label(task)}" for task in sensitive_audio_task_list] | ||||||||||||||||||||||||||||||||||||||||||
| audio_paths = BIDSDataset._apply_exclusion_list_to_filepaths( | ||||||||||||||||||||||||||||||||||||||||||
| audio_paths, exclusion_list=sensitive_audio_task_list, exclusion_type='filestem_contains' | ||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_task_list = [f"task-{normalize_task_label(task)}" for task in audio_tasks_to_include_list] | ||||||||||||||||||||||||||||||||||||||||||
| audio_paths = BIDSDataset._grab_filepaths_list_to_include( | ||||||||||||||||||||||||||||||||||||||||||
| audio_paths, inclusion_list=sensitive_audio_task_list | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
Evan8456 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _LOGGER.info(f"Copying {len(audio_paths)} recordings.") | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2085,7 +2108,7 @@ def _deidentify_feature_files( | |||||||||||||||||||||||||||||||||||||||||
| outdir: Path, | ||||||||||||||||||||||||||||||||||||||||||
| exclude_participant_ids: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| exclude_audio_filestems: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| sensitive_audio_task_list: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| audio_tasks_to_include_list: t.List[str] = [], | ||||||||||||||||||||||||||||||||||||||||||
| participant_ids_to_remap: t.Dict[str, str] = {}, | ||||||||||||||||||||||||||||||||||||||||||
| participant_session_id_to_remap: t.Dict[str, str] = {}, | ||||||||||||||||||||||||||||||||||||||||||
| max_workers: int = 16, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2130,7 +2153,7 @@ def _deidentify_feature_files( | |||||||||||||||||||||||||||||||||||||||||
| paths, exclusion_list=['audio-check'], exclusion_type='filestem_contains' | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| sensitive_task_labels = {normalize_task_label(t) for t in sensitive_audio_task_list} | ||||||||||||||||||||||||||||||||||||||||||
| audio_task_labels = {normalize_task_label(t) for t in audio_tasks_to_include_list} | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| _LOGGER.info(f"Copying {len(paths)} feature files.") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2157,7 +2180,7 @@ def process_feature_file(features_path): | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # if it is not sensitive and we want to keep features, move all features over | ||||||||||||||||||||||||||||||||||||||||||
Evan8456 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
| task_name = BIDSDataset._extract_task_name_from_path(features_path) | ||||||||||||||||||||||||||||||||||||||||||
| if normalize_task_label(task_name) not in sensitive_task_labels: | ||||||||||||||||||||||||||||||||||||||||||
| if normalize_task_label(task_name) in audio_task_labels: | ||||||||||||||||||||||||||||||||||||||||||
| shutil.copy(features_path, output_path) | ||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||
| features = torch.load(features_path, weights_only=False, map_location=torch.device('cpu')) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.