diff --git a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_all_sessions.py b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_all_sessions.py index 67306be..b2e382e 100644 --- a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_all_sessions.py +++ b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_all_sessions.py @@ -7,7 +7,7 @@ import traceback from tqdm import tqdm -from zaki_2024_convert_conditioning_session import session_to_nwb +from zaki_2024_convert_session import session_to_nwb def dataset_to_nwb( @@ -16,6 +16,7 @@ def dataset_to_nwb( output_dir_path: Union[str, Path], max_workers: int = 1, verbose: bool = True, + stub_test: bool = False, ): """Convert the entire dataset to NWB. @@ -41,6 +42,7 @@ def dataset_to_nwb( for session_to_nwb_kwargs in session_to_nwb_kwargs_per_session: session_to_nwb_kwargs["output_dir_path"] = output_dir_path session_to_nwb_kwargs["verbose"] = verbose + session_to_nwb_kwargs["stub_test"] = stub_test exception_file_path = data_dir_path / f"ERROR_.txt" # Add error file path here futures.append( executor.submit( @@ -101,8 +103,7 @@ def get_session_to_nwb_kwargs_per_session( session_times_file_path = data_dir_path / "Ca_EEG_Experiment" / subject_id / (subject_id + "_SessionTimes.csv") if session_times_file_path.is_file(): session_times_df = pd.read_csv(session_times_file_path) - tasks = [task for task in session_times_df["Session"] if "Offline" not in task] - for task in tasks: + for task in session_times_df["Session"]: session_id = subject_id + "_" + task session_row = session_times_df[session_times_df["Session"] == task].iloc[0] date_str = session_row["Date"] @@ -112,7 +113,6 @@ def get_session_to_nwb_kwargs_per_session( data_dir_path=data_dir_path, subject_id=subject_id, session_id=session_id, - stub_test=True, date_str=date_str, time_str=time_str, ) @@ -130,10 +130,11 @@ def get_session_to_nwb_kwargs_per_session( output_dir_path = Path("D:/cai_lab_conversion_nwb/") max_workers = 1 verbose = True - + stub_test = True dataset_to_nwb( data_dir_path=data_dir_path, output_dir_path=output_dir_path, max_workers=max_workers, verbose=verbose, + stub_test=stub_test, ) diff --git a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_conditioning_session.py b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_session.py similarity index 84% rename from src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_conditioning_session.py rename to src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_session.py index f8bbd0f..0d4d75a 100644 --- a/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_conditioning_session.py +++ b/src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_session.py @@ -51,10 +51,14 @@ def session_to_nwb( source_data = dict() conversion_options = dict() - experiment_dir_path = data_dir_path / "Ca_EEG_Experiment" / subject_id / (subject_id + "_Sessions") + if "Offline" in session_id: + offline_day = session_id.split("Session")[0] + experiment_dir_path = data_dir_path / "Ca_EEG_Experiment" / subject_id / (subject_id + "_Offline") / offline_day + else: + experiment_dir_path = data_dir_path / "Ca_EEG_Experiment" / subject_id / (subject_id + "_Sessions") / session_id # Add Imaging - folder_path = experiment_dir_path / session_id / date_str / time_str + folder_path = experiment_dir_path / date_str / time_str miniscope_folder_path = get_miniscope_folder_path(folder_path) if miniscope_folder_path is not None: source_data.update(dict(MiniscopeImaging=dict(folder_path=miniscope_folder_path))) @@ -79,7 +83,7 @@ def session_to_nwb( print("No motion corrected data found at {}".format(motion_corrected_video)) # Add Behavioral Video - video_file_path = experiment_dir_path / session_id / (session_id + ".wmv") + video_file_path = experiment_dir_path / (session_id + ".wmv") if video_file_path.is_file(): source_data.update(dict(Video=dict(file_paths=[video_file_path]))) conversion_options.update(dict(Video=dict(stub_test=stub_test))) @@ -87,7 +91,7 @@ def session_to_nwb( print("No behavioral video found at {}".format(video_file_path)) # Add Freezing Analysis output - freezing_output_file_path = experiment_dir_path / session_id / (session_id + "_FreezingOutput.csv") + freezing_output_file_path = experiment_dir_path / (session_id + "_FreezingOutput.csv") if freezing_output_file_path.is_file(): source_data.update( dict(FreezingBehavior=dict(file_path=freezing_output_file_path, video_sampling_frequency=30.0)) @@ -106,6 +110,17 @@ def session_to_nwb( elif verbose: print("No .edf file found at {}".format(edf_file_path)) + # Add Sleep Classification output + sleep_classification_file_path = ( + data_dir_path / "Ca_EEG_Sleep" / subject_id / "AlignedSleep" / (session_id + "_AlignedSleep.csv") + ) + if sleep_classification_file_path.is_file(): + source_data.update( + dict(SleepClassification=dict(file_path=sleep_classification_file_path, video_sampling_frequency=30.0)) + ) + elif verbose: + print("No sleep classification output csv file found at {}".format(sleep_classification_file_path)) + converter = Zaki2024NWBConverter(source_data=source_data) # Add datetime to conversion @@ -144,7 +159,7 @@ def session_to_nwb( # Parameters for conversion data_dir_path = Path("D:/") subject_id = "Ca_EEG3-4" - task = "NeutralExposure" + task = "OfflineDay1Session1" session_id = subject_id + "_" + task output_dir_path = Path("D:/cai_lab_conversion_nwb/") stub_test = True