Skip to content
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

Add offline sessions to the conversion script #12

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/cai_lab_to_nwb/zaki_2024/zaki_2024_convert_all_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.

Expand All @@ -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_<nwbfile_name>.txt" # Add error file path here
futures.append(
executor.submit(
Expand Down Expand Up @@ -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"]
Expand All @@ -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,
)
Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -79,15 +83,15 @@ 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)))
elif verbose:
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))
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down