From 77be87c8311de5ac4b88863cd4bf471f77d27e99 Mon Sep 17 00:00:00 2001 From: Georg Raiser Date: Tue, 14 Jan 2025 11:08:11 +0000 Subject: [PATCH] made a mess ... cleanup --- .../_scripts/_convert_brainwide_map.py | 46 ++----------------- .../_scripts/post_conversion_check_nwbfile.py | 12 ++--- 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/src/ibl_to_nwb/_scripts/_convert_brainwide_map.py b/src/ibl_to_nwb/_scripts/_convert_brainwide_map.py index c8daa27..1598666 100644 --- a/src/ibl_to_nwb/_scripts/_convert_brainwide_map.py +++ b/src/ibl_to_nwb/_scripts/_convert_brainwide_map.py @@ -6,6 +6,8 @@ import spikeglx +from ibl_to_nwb.helpers import create_symlinks + # if running on SDSC, use the OneSdsc, else normal if "USE_SDSC_ONE" in os.environ: print("using SDSC ONE") @@ -26,47 +28,6 @@ WheelInterface, ) -# def create_symlinks(source_dir, target_dir, remove_uuid=True): -# """replicates the tree under source_dir at target dir in the form of symlinks""" -# for root, dirs, files in os.walk(source_dir): -# for dir in dirs: -# folder = target_dir / (Path(root) / dir).relative_to(source_dir) -# folder.mkdir(parents=True, exist_ok=True) - -# for root, dirs, files in os.walk(source_dir): -# for file in files: -# source_file_path = Path(root) / file -# target_file_path = target_dir / source_file_path.relative_to(source_dir) -# if remove_uuid: -# parent, name = target_file_path.parent, target_file_path.name -# name_parts = name.split(".") -# name_parts.remove(name_parts[-2]) -# target_file_path = parent / ".".join(name_parts) -# if not target_file_path.exists(): -# target_file_path.symlink_to(source_file_path) - - -def create_symlinks(source_dir, target_dir, remove_uuid=True, filter=None): - """replicates the tree under source_dir at target dir in the form of symlinks""" - - for root, dirs, files in os.walk(source_dir): - for file in files: - source_file_path = Path(root) / file - if filter is not None: - if filter not in str(source_file_path): - continue - - target_file_path = target_dir / source_file_path.relative_to(source_dir) - target_file_path.parent.mkdir(parents=True, exist_ok=True) - - if remove_uuid: - parent, name = target_file_path.parent, target_file_path.name - name_parts = name.split(".") - name_parts.remove(name_parts[-2]) - target_file_path = parent / ".".join(name_parts) - if not target_file_path.exists(): - target_file_path.symlink_to(source_file_path) - def get_last_before(eid: str, one: ONE, revision: str): revisions = one.list_revisions(eid, revision="*") @@ -227,6 +188,7 @@ def convert(eid: str, one: ONE, data_interfaces: list, revision: str, mode: str) # cleanup if cleanup: if mode == "raw": + # find . -type l -exec unlink {} \;") os.system(f"find {session_scratch_folder} -type l -exec unlink {{}} \;") shutil.rmtree(session_scratch_folder) -# find . -type l -exec unlink {} \;") + diff --git a/src/ibl_to_nwb/_scripts/post_conversion_check_nwbfile.py b/src/ibl_to_nwb/_scripts/post_conversion_check_nwbfile.py index 1f1e490..02010da 100644 --- a/src/ibl_to_nwb/_scripts/post_conversion_check_nwbfile.py +++ b/src/ibl_to_nwb/_scripts/post_conversion_check_nwbfile.py @@ -15,9 +15,8 @@ from ibl_to_nwb.testing._consistency_checks import check_nwbfile_for_consistency, check_raw_nwbfile_for_consistency # nwbfile_path = sys.argv[1] -nwbfile_path = "/mnt/home/graiser/ibl_scratch/nwbfiles/sub-NR_0031/sub-NR_0031_ses-caa5dddc-9290-4e27-9f5e-575ba3598614_desc-raw_ecephys+image.nwb" -if "raw" in nwbfile_path: - raw = True +nwbfile_path = "/home/georg/ibl_scratch/nwbfiles/sub-NR_0031/sub-NR_0031_ses-caa5dddc-9290-4e27-9f5e-575ba3598614_desc-processed_behavior+ecephys.nwb" +mode = "raw" if "raw" in nwbfile_path else "processed" with NWBHDF5IO(path=nwbfile_path, mode="r") as io: nwbfile = io.read() @@ -47,9 +46,10 @@ # instantiate one one = ONE(**one_kwargs) -if raw: +if mode == 'raw': check_raw_nwbfile_for_consistency(one=one, nwbfile_path=nwbfile_path) -else: +if mode == 'processed': check_nwbfile_for_consistency(one=one, nwbfile_path=nwbfile_path) # %% -print("all checks passed") + +print(f"all checks passed, mode={mode}")