Text#

Time Intervals#

class TimeIntervalsInterface(file_path: Annotated[pathlib.Path, PathType(path_type='file')], read_kwargs: Optional[dict] = None, verbose: bool = False)[source]#

Bases: BaseDataInterface

Abstract Interface for time intervals.

Initialize the TimeIntervalsInterface.

Parameters
  • file_path (FilePath) – The path to the file containing time intervals data.

  • read_kwargs (dict, optional) – Additional arguments for reading the file, by default None.

  • verbose (bool, default: False)

keywords: tuple[str] = ('table', 'trials', 'epochs', 'time intervals')#
get_metadata() dict[source]#

Child DataInterface classes should override this to match their metadata.

Returns

The metadata dictionary containing basic NWBFile metadata.

Return type

DeepDict

get_metadata_schema() dict[source]#

Get the metadata schema for the time intervals.

Returns

The schema dictionary for time intervals metadata.

Return type

dict

get_original_timestamps(column: str) ndarray[source]#

Get the original timestamps for a given column.

Parameters

column (str) – The name of the column containing timestamps.

Returns

The original timestamps from the specified column.

Return type

np.ndarray

Raises

ValueError – If the column name does not end with ‘_time’.

get_timestamps(column: str) ndarray[source]#

Get the current timestamps for a given column.

Parameters

column (str) – The name of the column containing timestamps.

Returns

The current timestamps from the specified column.

Return type

np.ndarray

Raises

ValueError – If the column name does not end with ‘_time’.

set_aligned_starting_time(aligned_starting_time: float)[source]#

Align the starting time by shifting all timestamps by the given value.

Parameters

aligned_starting_time (float) – The aligned starting time to shift all timestamps by.

set_aligned_timestamps(aligned_timestamps: ndarray, column: str, interpolate_other_columns: bool = False)[source]#

Set aligned timestamps for the given column and optionally interpolate other columns.

Parameters
  • aligned_timestamps (np.ndarray) – The aligned timestamps to set for the given column.

  • column (str) – The name of the column to update with the aligned timestamps.

  • interpolate_other_columns (bool, optional) – If True, interpolate the timestamps in other columns, by default False.

Raises

ValueError – If the column name does not end with ‘_time’.

align_by_interpolation(unaligned_timestamps: ndarray, aligned_timestamps: ndarray, column: str)[source]#

Align timestamps using linear interpolation.

Parameters
  • unaligned_timestamps (np.ndarray) – The original unaligned timestamps that map to the aligned timestamps.

  • aligned_timestamps (np.ndarray) – The target aligned timestamps corresponding to the unaligned timestamps.

  • column (str) – The name of the column containing the timestamps to be aligned.

add_to_nwbfile(nwbfile: NWBFile, metadata: Optional[dict] = None, tag: str = 'trials', column_name_mapping: dict[str, str] = None, column_descriptions: dict[str, str] = None) NWBFile[source]#

Run the NWB conversion for the instantiated data interface.

Parameters
  • nwbfile (NWBFile, optional) – An in-memory NWBFile object to write to the location.

  • metadata (dict, optional) – Metadata dictionary with information used to create the NWBFile when one does not exist or overwrite=True.

  • tag (str, default: “trials”)

  • column_name_mapping (dict, optional) – If passed, rename subset of columns from key to value.

  • column_descriptions (dict, optional) – Keys are the names of the columns (after renaming) and values are the descriptions. If not passed, the names of the columns are used as descriptions.

CSV#

class CsvTimeIntervalsInterface(file_path: Annotated[pathlib.Path, PathType(path_type='file')], read_kwargs: Optional[dict] = None, verbose: bool = False)[source]#

Bases: TimeIntervalsInterface

Interface for adding data from a .csv file as a TimeIntervals object.

Initialize the TimeIntervalsInterface.

Parameters
  • file_path (FilePath) – The path to the file containing time intervals data.

  • read_kwargs (dict, optional) – Additional arguments for reading the file, by default None.

  • verbose (bool, default: False)

display_name: Union[str, None] = 'CSV time interval table'#
associated_suffixes: tuple[str] = ('.csv',)#
info: Union[str, None] = 'Interface for writing a time intervals table from a comma separated value (CSV) file.'#

Excel#

class ExcelTimeIntervalsInterface(file_path: Annotated[pathlib.Path, PathType(path_type='file')], read_kwargs: Optional[dict] = None, verbose: bool = False)[source]#

Bases: TimeIntervalsInterface

Interface for adding data from an Excel file to NWB as a TimeIntervals object.

Parameters
  • file_path (FilePath)

  • read_kwargs (dict, optional) – Passed to pandas.read_excel()

  • verbose (bool, default: False)

display_name: Union[str, None] = 'Excel time interval table'#
associated_suffixes: tuple[str] = ('.xlsx', '.xls', '.xlsm')#
info: Union[str, None] = 'Interface for writing a time intervals table from an excel file.'#