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

add get_timestamps to TimeSeries #1741

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# PyNWB Changelog

## PyNWB 2.4.1 (July 26, 2023)
## PyNWB 2.5.0 (Upcoming)

### Bug fixes
### Enhancements and minor changes
- Add `TimeSeries.get_timestamps`. @bendichter [#1741](https://github.com/NeurodataWithoutBorders/pynwb/pull/1741)

## PyNWB 2.4.1 (July 26, 2023)
- Stop running validation tests as part of integration tests. They cause issues in CI and can be run separately. @rly [#1740](https://github.com/NeurodataWithoutBorders/pynwb/pull/1740)

## PyNWB 2.4.0 (July 23, 2023)
Expand Down
6 changes: 6 additions & 0 deletions src/pynwb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def __add_link(self, links_key, link):
def time_unit(self):
return self.__time_unit

def get_timestamps(self):
if self.fields.get('timestamps'):
return self.timestamps
else:
return np.arange(len(self.data)) / self.rate + self.starting_time


@register_class('Image', CORE_NAMESPACE)
class Image(NWBData):
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
TimeSeriesReference,
ImageReferences
)
from pynwb.testing.mock.base import mock_TimeSeries
from pynwb.testing import TestCase
from hdmf.data_utils import DataChunkIterator
from hdmf.backends.hdf5 import H5DataIO
from numpy.testing import assert_array_equal


class TestProcessingModule(TestCase):
Expand Down Expand Up @@ -386,6 +388,13 @@ def test_dimension_warning(self):
timestamps=[0.3, 0.4, 0.5, 0.6, 0.7, 0.8],
)

def test_get_timestamps(self):
time_series = mock_TimeSeries(data=[1, 2, 3], rate=40.0, starting_time=30.0)
assert_array_equal(time_series.get_timestamps(), [30, 30+1/40, 30+2/40])

time_series = mock_TimeSeries(data=[1, 2, 3], timestamps=[3, 4, 5], rate=None)
assert_array_equal(time_series.get_timestamps(), [3, 4, 5])


class TestImage(TestCase):
def test_init(self):
Expand Down