From 7725defc8642575439e456bb56e9bbe6fa4fb438 Mon Sep 17 00:00:00 2001 From: codycbakerphd Date: Thu, 14 Dec 2023 11:19:33 -0500 Subject: [PATCH] skip video if missing --- .../basevideointerface.py | 13 ++++++++----- .../markowitz_gillis_nature_2023/convert_dataset.py | 4 ++-- .../markowitz_gillis_nature_2023/convert_session.py | 4 +--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/basevideointerface.py b/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/basevideointerface.py index c8ad15e..41066ea 100644 --- a/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/basevideointerface.py +++ b/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/basevideointerface.py @@ -1,17 +1,17 @@ """Base class for converting raw video data.""" -from pynwb import NWBFile -from datetime import datetime -from pytz import timezone -import h5py +from pathlib import Path + import numpy as np import pandas as pd +from pynwb import NWBFile from neuroconv.datainterfaces import VideoInterface + from .basedattainterface import BaseDattaInterface from .utils import convert_timestamps_to_seconds class BaseVideoInterface(BaseDattaInterface): - """Base video interface for markowitz_gillis_nature_2023 conversion""" + """Base video interface for markowitz_gillis_nature_2023 conversion.""" def __init__( self, @@ -51,6 +51,9 @@ def align_timestamps(self, metadata: dict) -> np.ndarray: def add_to_nwbfile(self, nwbfile: NWBFile, metadata: dict) -> None: timestamps = self.align_timestamps(metadata=metadata) + if not Path(self.source_data["data_path"]).exists(): + return + video_interface = VideoInterface(file_paths=[self.source_data["data_path"]], verbose=True) video_interface.set_aligned_timestamps(aligned_timestamps=[timestamps]) video_interface.add_to_nwbfile( diff --git a/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_dataset.py b/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_dataset.py index 72ed2b4..57c89e0 100644 --- a/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_dataset.py +++ b/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_dataset.py @@ -101,7 +101,7 @@ def dataset_to_nwb( folder for folder in raw_dir_path.iterdir() if folder.is_dir() and folder.name not in skip_experiments and folder.name.startswith("_") - ][11:] + ] for experimental_folder in tqdm( iterable=experimental_folders, position=0, desc="Converting experiments...", leave=False ): @@ -157,7 +157,7 @@ def dataset_to_nwb( if __name__ == "__main__": - number_of_jobs = 2 + number_of_jobs = 1 processed_path = Path("E:/Datta/dopamine-reinforces-spontaneous-behavior") raw_dir_path = Path("E:/Datta") diff --git a/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_session.py b/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_session.py index be495f4..893e376 100644 --- a/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_session.py +++ b/src/datta_lab_to_nwb/markowitz_gillis_nature_2023/convert_session.py @@ -53,9 +53,7 @@ def session_to_nwb( session_id = f"{experiment_type}-{session_uuid}" nwbfile_path = output_dir_path / f"{session_id}.nwb" - if ( - nwbfile_path.parent.parent / "initial_nwbfiles" / nwbfile_path.name - ).exists() or nwbfile_path.exists(): # temporary + if nwbfile_path.exists(): return photometry_path = processed_path / "dlight_raw_data/dlight_photometry_processed_full.parquet"