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

EDF time slicing #15

Merged
merged 7 commits into from
Nov 14, 2024
Merged

EDF time slicing #15

merged 7 commits into from
Nov 14, 2024

Conversation

alessandratrapani
Copy link
Collaborator

Add an option for slicing edf data based on the time range of miniscope recording.

  1. Get Miniscope session start time (already in datetime format in the metadata.json)
  2. Get Miniscope relative timestamps and convert the first and the last timestamps in datetime format using the session start time
  3. Input these two timestamps in edf interface
  4. Get EDF recording start time in datetime format
  5. Convert EDF relative timestamps in datetime format using EDF recording start time
  6. Slice EDF data inside the time range identified by Miniscope recording start time and stop time in datetime format

Copy link
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bunch of comments and suggestions but feel free to ignore them. The only critical one to me is to clarify why the nwbfile.session_start_time is not used in the add_to_nwbfile method of the EDFSignals interface.

@@ -17,6 +18,101 @@
from neuroconv.utils import DeepDict, dict_deep_update


def get_session_start_time(folder_path: Union[str, Path]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we just pass the file path of the json directly instead of passing the folder and then locating it within? What do you think?

I know you are moving these functions only but is something to consider if you think that a small breaking change is worth avoiding the problem of a different file structure in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first design choice was to pass the file path actually. I don't remember why I changed my mind, probably to avoid to repeat pice of code. But if you also think passing the file_path is the correct way, I will change it back.

return session_start_time


def get_miniscope_timestamps(miniscope_folder_path: Union[str, Path]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here about the file_path vs folder_path?

@@ -205,36 +301,6 @@ def __init__(self, folder_path: DirectoryPath):

self.photon_series_type = "OnePhotonSeries"

def _get_session_start_time(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another, equally valid option, is to make these functions static or class methods of the class. This is more of taste and preference and depends on how do you want to organize your code.

# Shift when the first timestamp is negative
# TODO: Figure why, I copied from miniscope
# TODO: Figure why, I copied from Miniscope. Need to shift also session_start_time
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an answer to my why? or it was your why? The goal of this is to set the timestamps to start at 0, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was part od the TODO. If we saved the session start time from the metadata, and the timestamps refer to that date. When we shift the timestamps to zero we need to shift back the session start time as well. But I left it there as a comment because I am not sure how to handle this. I will open a follow up PR only on this

@@ -308,7 +366,7 @@ def add_to_nwbfile(
imaging_extractor.set_times(times=miniscope_timestamps)

device_metadata = metadata["Ophys"]["Device"][0]
# Cast to string because miniscope extension requires so
# Cast to string because Miniscope extension requires so
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gratzie!


def __init__(self, file_path: FilePath, verbose: bool = False):

def __init__(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be conversion options and not init arguments, as you might want to use run-time information (from other interfaces for example) to determine them.



def get_miniscope_folder_path(folder_path: Union[str, Path]):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great

def get_session_start_time(folder_path: Union[str, Path]):
"""
Retrieve the session start time from metadata in the specified folder.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also advice to name this get_{something}_start_time now that is not a method of the class or modify the docstring to make this clear.

Copy link
Collaborator Author

@alessandratrapani alessandratrapani Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed_ in get_recording_start_time

start_datetime_timestamp: datetime = None,
stop_datetime_timestamp: datetime = None,
verbose: bool = False,
):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if you add them here or in the conversion options (add_to_nwbfile) I think a docstring would be highly beneficial.

@alessandratrapani
Copy link
Collaborator Author

This is working good with your fix catalystneuro/neuroconv#1139
If it's ok with you I would merge this @h-mayorquin

@h-mayorquin h-mayorquin merged commit a4cf9d2 into main Nov 14, 2024
@h-mayorquin h-mayorquin deleted the edf_slicing branch November 14, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants