Skip to content

Commit

Permalink
made a mess ... cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
grg2rsr committed Jan 14, 2025
1 parent cc144fc commit 77be87c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 48 deletions.
46 changes: 4 additions & 42 deletions src/ibl_to_nwb/_scripts/_convert_brainwide_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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="*")
Expand Down Expand Up @@ -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 {} \;")

12 changes: 6 additions & 6 deletions src/ibl_to_nwb/_scripts/post_conversion_check_nwbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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}")

0 comments on commit 77be87c

Please sign in to comment.