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

Handle non-ptp datasets #53

Merged
merged 24 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4589405
Get timestamps and dios
edeno Oct 3, 2023
3d10039
Merge branch 'main' into non-ptp
edeno Oct 13, 2023
d1cb9d5
Add non-ptp code
edeno Oct 17, 2023
37df6bc
Merge branch 'main' into non-ptp
edeno Oct 17, 2023
45fcb07
Fix linting
edeno Oct 17, 2023
9bf8bb2
Fix arguments
edeno Oct 17, 2023
d78d371
Account for dio and systime being in seconds units
samuelbray32 Oct 18, 2023
961f920
Update add_position call in no ptp case to account for moved add_videos
samuelbray32 Oct 18, 2023
7d28243
Update add_position call in no ptp case to account for moved add_vide…
samuelbray32 Oct 18, 2023
8b9fb3e
Fix linting
edeno Oct 19, 2023
67a1a80
Remove original video timestamps since not using
edeno Oct 20, 2023
2f8b461
Use dio_camera_timestamps directly instead of inferring from mcu time…
edeno Oct 20, 2023
7703f0e
Remove duplicate timestamps, correct pause units, cleanup
samuelbray32 Oct 23, 2023
2e086be
Fix inference of systime from trodes timestamps
samuelbray32 Oct 23, 2023
ddc448f
Correct get_systime_from_trodes_timestamps for case when not i_start …
samuelbray32 Oct 24, 2023
422440e
Remove redundant restriction of session_df in add_intervals
samuelbray32 Oct 24, 2023
6862043
Change session_info name to be consistent with rest of codebase
samuelbray32 Oct 24, 2023
eb4f006
Find dio camera per epoch. Enables different camera for different epochs
samuelbray32 Oct 24, 2023
44f0b87
Re-order if statement to avoid error in non-ptp test
samuelbray32 Oct 24, 2023
4c518fc
Add test for non-ptp position conversion
samuelbray32 Oct 24, 2023
d076473
Fix non-ptp metadata for yaml validation after merge
samuelbray32 Oct 25, 2023
175cae6
Remove unused variable
edeno Oct 25, 2023
59f6fb7
Just set pause mid time to -1 if not found
edeno Oct 25, 2023
e8e25d2
Move dio_camera_timestamps_epoch = None for clarity
edeno Oct 25, 2023
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
36 changes: 23 additions & 13 deletions src/spikegadgets_to_nwb/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
from spikegadgets_to_nwb.convert_position import (
add_position,
add_associated_video_files,
find_camera_dio_channel,
)
from spikegadgets_to_nwb.convert_rec_header import (
add_header_device,
detect_ptp_from_header,
make_hw_channel_map,
make_ref_electrode_map,
read_header,
Expand Down Expand Up @@ -249,24 +251,32 @@ def _create_nwb(
add_analog_data(nwb_file, rec_filepaths, timestamps=rec_dci_timestamps)
logger.info("ADDING SAMPLE COUNTS")
add_sample_count(nwb_file, rec_dci)
logger.info("ADDING POSITION")
### add position ###
add_position(
nwb_file,
metadata,
session_df,
rec_header,
)

# add epochs
logger.info("ADDING EPOCHS")
add_epochs(
nwbfile=nwb_file,
file_info=session_df,
date=session[0],
animal=session[1],
session_df=session_df,
neo_io=rec_dci.neo_io,
)
logger.info("ADDING POSITION")
### add position ###
ptp_enabled = detect_ptp_from_header(rec_header)
if ptp_enabled:
add_position(
nwb_file,
metadata,
session_df,
)
else:
add_position(
nwb_file,
metadata,
session_df,
ptp_enabled=ptp_enabled,
rec_dci_timestamps=rec_dci_timestamps,
sample_count=nwb_file.processing["sample_count"]
.data_interfaces["sample_count"]
.data,
)

# write file
logger.info(f"WRITING: {output_dir}/{session[1]}{session[0]}.nwb")
Expand Down
16 changes: 8 additions & 8 deletions src/spikegadgets_to_nwb/convert_intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

def add_epochs(
nwbfile: NWBFile,
file_info: pd.DataFrame,
date: int,
animal: str,
session_df: pd.DataFrame,
neo_io: List[SpikeGadgetsRawIO],
):
"""add epochs to nwbfile
Expand All @@ -35,11 +33,13 @@ def add_epochs(
neo_io iterators for each rec file. Contains time information
"""
logger = logging.getLogger("convert")
session_info = file_info[(file_info.date == date) & (file_info.animal == animal)]
for epoch in set(session_info.epoch):
rec_file_list = session_info[
(session_info.epoch == epoch) & (session_info.file_extension == ".rec")
for epoch in set(session_df.epoch):
rec_file_list = session_df[
(session_df.epoch == epoch) & (session_df.file_extension == ".rec")
]
if len(rec_file_list) == 0:
logger.info(f"no rec files for epoch {epoch}, No epoch interval created")
continue
start_time = None
end_time = None
logger.info(list(rec_file_list.full_path))
Expand All @@ -58,7 +58,7 @@ def add_epochs(
)
else:
file_end_time = np.max(
io._get_systime_from_trodes_timestamps(n_time - 1, n_time)
io.get_systime_from_trodes_timestamps(n_time - 1, n_time)
)
if end_time is None or file_end_time > end_time:
end_time = float(file_end_time)
Expand Down
Loading