def textgriddf_converter(text_df):
    """Converts data into TimeIntervals

        For a given DataFrame this function converts the data into TimeIntervals

        Parameters
        ----------
        text_df : pandas.DataFrame
            Data related to an item

        Returns
        ----------
        pynwb.epoch.TimeIntervals

        """
    textgrid_sentences = TimeIntervals(
        name='sentences',
        description='desc'
    )

    textgrid_sentences.add_column('label', 'text of sentences')

    for i in text_df.index:
        textgrid_sentences.add_interval(label=text_df.iloc[i]['text'], start_time=float(text_df.iloc[i]['xmin']),
                                        stop_time=float(text_df.iloc[i]['xmax']))

    return textgrid_sentences
Exemple #2
0
class TestAlignMultiTraceTimeSeriesByTrials(unittest.TestCase):
    def setUp(self):
        data = np.random.rand(100, 10)
        timestamps = [0.0]
        for _ in range(data.shape[0]):
            timestamps.append(timestamps[-1] + 0.75 + 0.25 * np.random.rand())
        self.ts_rate = TimeSeries(
            name="test_timeseries_rate",
            data=data,
            unit="m",
            starting_time=0.0,
            rate=1.0,
        )
        self.ts_timestamps = TimeSeries(
            name="test_timeseries_timestamps",
            data=data,
            unit="m",
            timestamps=np.array(timestamps),
        )
        self.time_intervals = TimeIntervals(name="Test Time Interval")
        n_intervals = 10
        for start_time in np.linspace(0, 75, n_intervals + 1):
            if start_time < 75:
                stt = start_time + np.random.rand()
                spt = stt + 7 - np.random.rand()
                self.time_intervals.add_interval(start_time=stt, stop_time=spt)
        self.time_intervals.add_column(
            name="temp", description="desc", data=np.random.randint(2, size=n_intervals)
        )
        self.time_intervals.add_column(
            name="temp2",
            description="desc",
            data=np.random.randint(10, size=n_intervals),
        )

    def test_align_by_timestamps(self):
        amt = AlignMultiTraceTimeSeriesByTrialsVariable(
            time_series=self.ts_timestamps, trials=self.time_intervals
        )
        gas = amt.controls['gas']
        gas.group_dd.value = list(gas.categorical_columns.keys())[0]
        gas.group_sm.value = (gas.group_sm.options[0],)
        fig = amt.children[-1]
        assert len(fig.data)==len(gas.group_sm.value)

    def test_align_by_rate(self):
        amt = AlignMultiTraceTimeSeriesByTrialsConstant(
            time_series=self.ts_rate, trials=self.time_intervals
        )
        gas = amt.controls['gas']
        gas.group_dd.value = list(gas.categorical_columns)[0]
        gas.group_sm.value = (gas.group_sm.options[0],)
        fig = amt.children[-1]
        assert len(fig.data) == len(gas.group_sm.value)
Exemple #3
0
    def setUp(self):
        super().setUp()

        # add intervals to nwbfile
        ti1 = TimeIntervals(name='intervals',
                            description='experimental intervals')
        ti1.add_interval(start_time=0.0, stop_time=2.0)
        ti1.add_interval(start_time=2.0, stop_time=4.0)
        ti1.add_interval(start_time=4.0, stop_time=6.0)
        ti1.add_interval(start_time=6.0, stop_time=8.0)
        ti1.add_column(name='var1',
                       data=['a', 'b', 'a', 'b'],
                       description='no description')
        self.nwbfile.add_time_intervals(ti1)

        self.widget = ExtendedTimeIntervalSelector(
            input_data=self.nwbfile.units)
Exemple #4
0
class SpatialSeriesTrialsAlign(unittest.TestCase):
    def setUp(self) -> None:
        data = np.random.rand(100, 3)
        timestamps = [0.0]
        for _ in range(data.shape[0]):
            timestamps.append(timestamps[-1] + 0.75 + 0.25 * np.random.rand())
        self.spatial_series_rate = SpatialSeries(
            name="position_rate",
            data=data,
            starting_time=0.0,
            rate=1.0,
            reference_frame="starting gate",
        )
        self.spatial_series_ts = SpatialSeries(
            name="position_ts",
            data=data,
            timestamps=np.array(timestamps),
            reference_frame="starting gate",
        )
        self.time_intervals = TimeIntervals(name="Test Time Interval")
        n_intervals = 10
        for start_time in np.linspace(0, 75, n_intervals + 1):
            if start_time < 75:
                stt = start_time + np.random.rand()
                spt = stt + 7 - np.random.rand()
                self.time_intervals.add_interval(start_time=stt, stop_time=spt)
        self.time_intervals.add_column(name="temp",
                                       description="desc",
                                       data=np.random.randint(
                                           2, size=n_intervals))
        self.time_intervals.add_column(
            name="temp2",
            description="desc",
            data=np.random.randint(10, size=n_intervals),
        )

    def test_spatial_series_trials_align_rate(self):
        trial_align_spatial_series(self.spatial_series_rate,
                                   self.time_intervals)

    def test_spatial_series_trials_align_ts(self):
        trial_align_spatial_series(self.spatial_series_ts, self.time_intervals)
Exemple #5
0
####################
# Other time intervals
# ~~~~~~~~~~~~~~~~~~~~~~
# Both ``epochs`` and ``trials`` are of of data type :py:class:`~pynwb.epoch.TimeIntervals`, which is a type of
# ``DynamicTable`` for storing information about time intervals. ``"epochs"`` and ``"trials"``
# are the two default names for :py:class:`~pynwb.base.TimeIntervals` objects, but you can also add your own

from pynwb.epoch import TimeIntervals

sleep_stages = TimeIntervals(
    name="sleep_stages",
    description="intervals for each sleep stage as determined by EEG",
)

sleep_stages.add_column(name="stage", description="stage of sleep")
sleep_stages.add_column(name="confidence",
                        description="confidence in stage (0-1)")

sleep_stages.add_row(start_time=0.3, stop_time=0.5, stage=1, confidence=.5)
sleep_stages.add_row(start_time=0.7, stop_time=0.9, stage=2, confidence=.99)
sleep_stages.add_row(start_time=1.3, stop_time=3.0, stage=3, confidence=0.7)

nwbfile.add_time_intervals(sleep_stages)

####################
# .. _basic_units:
#
# Units
# ------
#