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 mock neurodata objects #1454

Merged
merged 57 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
45e2882
add dummy data for ecephys
bendichter Apr 15, 2022
3c7459c
add dummy functions
bendichter Apr 15, 2022
01cbb6f
clean up
bendichter Apr 15, 2022
1e4cad5
flake8
bendichter Apr 15, 2022
739766d
* change name from dummy to mock
bendichter Apr 19, 2022
93d9c16
format imports
bendichter Apr 19, 2022
10c74fb
refactor name_generator
bendichter May 13, 2022
3d0bb93
add mock for behavior and base
bendichter Aug 24, 2022
c085c3c
add mocks and mock tests
bendichter Aug 24, 2022
e73a336
Merge branch 'dev' into mock
bendichter Aug 24, 2022
733e4aa
Update tests/unit/test_misc.py
bendichter Aug 24, 2022
882192e
Update tests/unit/test_misc.py
bendichter Aug 24, 2022
42e7d52
add mock.ogen.py
bendichter Aug 24, 2022
e05b4b1
Merge remote-tracking branch 'origin/dummy' into mock
bendichter Aug 24, 2022
79182a0
flake8
bendichter Aug 24, 2022
c42a3cf
Merge branch 'dev' into dummy
bendichter Aug 30, 2022
d04ab17
delay name generation to within the mock functions
bendichter Aug 30, 2022
b66abd0
Merge remote-tracking branch 'origin/dummy' into mock
bendichter Aug 30, 2022
7578d06
delay internal nd_types to within function
bendichter Aug 30, 2022
4a327cc
flake8
bendichter Aug 30, 2022
f239002
flake8
bendichter Aug 30, 2022
df4da79
lazy creation of electrodes table
bendichter Aug 30, 2022
d4ed0df
add mock for file submodule and unit tests
bendichter Aug 30, 2022
2282111
add mock subject to mock nwbfile
bendichter Aug 30, 2022
3a3dccd
update mock_ElectrodeTable
bendichter Aug 30, 2022
fe1a3ad
add back group name
bendichter Aug 30, 2022
1df145e
lazy generation of TimeSeries name
bendichter Aug 31, 2022
f7f253f
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
4515f3d
Update src/pynwb/testing/mock/base.py
bendichter Aug 31, 2022
5ef7b6f
Update src/pynwb/testing/mock/behavior.py
bendichter Aug 31, 2022
38c1b35
Update src/pynwb/testing/mock/behavior.py
bendichter Aug 31, 2022
78dbea7
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
3fe6df8
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
b87f37b
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
c3174b3
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
ff1b343
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
d41a022
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
ff98303
Update src/pynwb/testing/mock/base.py
bendichter Aug 31, 2022
521f188
Update src/pynwb/testing/mock/ecephys.py
bendichter Aug 31, 2022
a747e01
Update src/pynwb/testing/mock/ogen.py
bendichter Aug 31, 2022
b2afb77
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
cd91b03
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
1efc278
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
9d4f3a6
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
98d7008
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
be8ec33
Update src/pynwb/testing/mock/ogen.py
bendichter Aug 31, 2022
48a947c
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
b66468f
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
d0a841f
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
1c74a29
Update src/pynwb/testing/mock/ophys.py
bendichter Aug 31, 2022
1dee104
add init with docstring
bendichter Aug 31, 2022
bdca196
Merge remote-tracking branch 'origin/dummy' into mock
bendichter Aug 31, 2022
1cabef1
fix mock_ElectrodeTable
bendichter Aug 31, 2022
2751480
flake8
bendichter Aug 31, 2022
54a2ad5
Merge branch 'dev' into dummy
rly Sep 6, 2022
9db4b5a
Update src/pynwb/testing/mock/__init__.py
bendichter Sep 16, 2022
6794b8c
Update CHANGELOG.md
bendichter Sep 16, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
[#1550](https://github.com/NeurodataWithoutBorders/pynwb/pull/1550)
- Enhanced docs for ``LabMetaData`` to clarify its usage. @oruebel
[#1546](https://github.com/NeurodataWithoutBorders/pynwb/pull/1546)
- Add testing/mock, which provides mock neurodata objects for testing. @bendichter
[#1454](https://github.com/NeurodataWithoutBorders/pynwb/pull/1454)

## PyNWB 2.1.0 (July 6, 2022)

Expand Down
9 changes: 9 additions & 0 deletions src/pynwb/testing/mock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
The mock module provides mock instances of common neurodata types which can be used to write
tests for downstream libraries. For instance, to write an RoiResponseSeries, you need a
PlaneSegmentation, which requires an ImagingPlane, which in turn requires an
OpticalChannel and a Device, all of which need to be populated with reasonable mock
data. This library streamlines the process of creating mock objects by generating the
required prerequisites for this object on-the-fly and automatically using reasonable
defaults. Any of these default objects and parameters can be overridden.
"""
36 changes: 36 additions & 0 deletions src/pynwb/testing/mock/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np

from ...base import TimeSeries
from .utils import name_generator


def mock_TimeSeries(
name=None,
data=None,
unit="volts",
resolution=-1.0,
conversion=1.0,
timestamps=None,
starting_time=None,
rate=10.0,
comments="no comments",
description="no description",
control=None,
control_description=None,
continuity=None,
):
return TimeSeries(
name=name or name_generator("TimeSeries"),
data=data if data is not None else np.array([1, 2, 3, 4]),
unit=unit,
resolution=resolution,
conversion=conversion,
timestamps=timestamps,
starting_time=starting_time,
rate=rate,
comments=comments,
description=description,
control=control,
control_description=control_description,
continuity=continuity,
)
61 changes: 61 additions & 0 deletions src/pynwb/testing/mock/behavior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import numpy as np

from ...behavior import (
PupilTracking,
Position,
SpatialSeries,
CompassDirection,
)
from .utils import name_generator
from .base import mock_TimeSeries


def mock_SpatialSeries(
name=None,
data=None,
reference_frame="lower left is (0, 0)",
unit="meters",
conversion=1.0,
resolution=-1.0,
timestamps=None,
starting_time=None,
rate=10.0,
comments="no comments",
description="no description",
control=None,
control_description=None,
):
return SpatialSeries(
name=name or name_generator("SpatialSeries"),
data=data if data is not None else np.array([1, 2, 3, 4]),
reference_frame=reference_frame,
unit=unit,
conversion=conversion,
resolution=resolution,
timestamps=timestamps,
starting_time=starting_time,
rate=rate,
comments=comments,
description=description,
control=control,
control_description=control_description,
)


def mock_Position(
name=None, spatial_series=None,
):
return Position(name=name or name_generator("Position"), spatial_series=spatial_series or [mock_SpatialSeries()])


def mock_PupilTracking(
name=None, time_series=None,
):
return PupilTracking(name=name or name_generator("PupilTracking"), time_series=time_series or [mock_TimeSeries()])


def mock_CompassDirection(name=None, spatial_series=None):
return CompassDirection(
name=name or name_generator("CompassDirection"),
spatial_series=spatial_series or [mock_SpatialSeries(unit="radians")],
)
15 changes: 15 additions & 0 deletions src/pynwb/testing/mock/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from ...device import Device

from .utils import name_generator


def mock_Device(
name=None,
description="description",
manufacturer=None,
):
return Device(
name=name or name_generator("Device"),
description=description,
manufacturer=manufacturer,
)
78 changes: 78 additions & 0 deletions src/pynwb/testing/mock/ecephys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import numpy as np

from hdmf.common.table import DynamicTableRegion

from ...file import ElectrodeTable
from ...ecephys import ElectricalSeries, ElectrodeGroup, SpikeEventSeries
from .device import mock_Device
from .utils import name_generator


def mock_ElectrodeGroup(
name=None,
description="description",
location="location",
device=None,
position=None,
):
return ElectrodeGroup(
name=name or name_generator("ElectrodeGroup"),
description=description,
location=location,
device=device or mock_Device(),
position=position,
)


def mock_ElectrodeTable(n_rows=5, group=None):
table = ElectrodeTable()
group = group if group is not None else mock_ElectrodeGroup()
for i in range(n_rows):
table.add_row(
location="CA1",
group=group,
group_name=group.name,
)
return table


def mock_electrodes(n_electrodes=5, table=mock_ElectrodeTable(n_rows=5)):
return DynamicTableRegion(
"electrodes", list(range(n_electrodes)), "the first and third electrodes", table
)


def mock_ElectricalSeries(
name=None,
description="description",
data=None,
rate=30000.0,
timestamps=None,
electrodes=None,
filtering="filtering",
):
return ElectricalSeries(
name=name or name_generator("ElectricalSeries"),
description=description,
data=data if data is not None else np.ones((10, 5)),
rate=rate,
timestamps=timestamps,
electrodes=electrodes or mock_electrodes(),
filtering=filtering,
)


def mock_SpikeEventSeries(
name=None,
description="description",
data=None,
timestamps=np.arange(10).astype(float),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
timestamps=np.arange(10).astype(float),
timestamps=None,

electrodes=None,
):
return SpikeEventSeries(
name=name or name_generator("SpikeEventSeries"),
description=description,
data=data if data is not None else np.ones((10, 5)),
timestamps=timestamps if timestamps is not None else np.arange(10).astype(float),
electrodes=electrodes if electrodes is not None else mock_electrodes(),
)
36 changes: 36 additions & 0 deletions src/pynwb/testing/mock/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from uuid import uuid4
from datetime import datetime

from ...file import NWBFile, Subject
from .utils import name_generator


def mock_NWBFile(
session_description='session_description',
identifier=None,
session_start_time=datetime(1970, 1, 1),
subject=None,
**kwargs
):
return NWBFile(
session_description=session_description,
identifier=identifier or uuid4(),
session_start_time=session_start_time,
subject=subject or mock_Subject(),
**kwargs
)


def mock_Subject(
age="P50D",
description="this is a mock mouse.",
sex="F",
subject_id=None,
):

return Subject(
age=age,
description=description,
sex=sex,
subject_id=subject_id or name_generator("subject"),
)
52 changes: 52 additions & 0 deletions src/pynwb/testing/mock/ogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np

from ...ogen import OptogeneticStimulusSite, OptogeneticSeries

from .device import mock_Device
from .utils import name_generator


def mock_OptogeneticStimulusSite(
name=None,
device=None,
description="optogenetic stimulus site",
excitation_lambda=500.,
location="part of the brain",
):
return OptogeneticStimulusSite(
name=name or name_generator("OptogeneticStimulusSite"),
device=device or mock_Device(),
description=description,
excitation_lambda=excitation_lambda,
location=location
)


def mock_OptogeneticSeries(
name=None,
data=None,
site=None,
resolution=-1.0,
conversion=1.0,
timestamps=None,
starting_time=None,
rate=10.0,
comments="no comments",
description="no description",
control=None,
control_description=None,
):
return OptogeneticSeries(
name=name or name_generator("OptogeneticSeries"),
data=data if data is not None else np.array([1, 2, 3, 4]),
site=site or mock_OptogeneticStimulusSite(),
resolution=resolution,
conversion=conversion,
timestamps=timestamps,
starting_time=starting_time,
rate=rate,
comments=comments,
description=description,
control=control,
control_description=control_description,
)
Loading