Skip to content

Commit

Permalink
rename columns and use start times from next trial
Browse files Browse the repository at this point in the history
  • Loading branch information
bendichter committed Dec 14, 2022
1 parent a6e2655 commit a15b9ce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/neuroconv/datainterfaces/text/timeintervalsinterface.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
from abc import abstractmethod

from typing import Dict, Optional

import numpy as np
import pandas as pd
from pynwb import NWBFile
from pynwb.epoch import TimeIntervals

from ...basedatainterface import BaseDataInterface
from ...utils.types import FilePathType, Optional
from ...utils.types import FilePathType
from ...tools.nwb_helpers import make_or_load_nwbfile


def convert_df_to_time_intervals(df, name, description=None):
def convert_df_to_time_intervals(
df: pd.DataFrame,
name: str,
description: Optional[str] = None,
column_name_mapping: Dict[str, str] = None,
):
if column_name_mapping is not None:
df.rename(columns=column_name_mapping, inplace=True)
if description is None:
description = name
time_intervals = TimeIntervals(name, description)
if "start_time" not in df:
raise ValueError(f"df must contain a column named 'start_time'. Existing columns: {df.columns.to_list()}")
if "stop_time" not in df:
df["stop_time"] = np.nan
df["stop_time"] = np.r_[df["start_time"][1:].to_numpy(), np.nan]
for col in df:
if col not in ("start_time", "stop_time"):
time_intervals.add_column(col, col)
Expand Down

0 comments on commit a15b9ce

Please sign in to comment.