-
Notifications
You must be signed in to change notification settings - Fork 84
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
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 3c7459c
add dummy functions
bendichter 01cbb6f
clean up
bendichter 1e4cad5
flake8
bendichter 739766d
* change name from dummy to mock
bendichter 93d9c16
format imports
bendichter 10c74fb
refactor name_generator
bendichter 3d0bb93
add mock for behavior and base
bendichter c085c3c
add mocks and mock tests
bendichter e73a336
Merge branch 'dev' into mock
bendichter 733e4aa
Update tests/unit/test_misc.py
bendichter 882192e
Update tests/unit/test_misc.py
bendichter 42e7d52
add mock.ogen.py
bendichter e05b4b1
Merge remote-tracking branch 'origin/dummy' into mock
bendichter 79182a0
flake8
bendichter c42a3cf
Merge branch 'dev' into dummy
bendichter d04ab17
delay name generation to within the mock functions
bendichter b66abd0
Merge remote-tracking branch 'origin/dummy' into mock
bendichter 7578d06
delay internal nd_types to within function
bendichter 4a327cc
flake8
bendichter f239002
flake8
bendichter df4da79
lazy creation of electrodes table
bendichter d4ed0df
add mock for file submodule and unit tests
bendichter 2282111
add mock subject to mock nwbfile
bendichter 3a3dccd
update mock_ElectrodeTable
bendichter fe1a3ad
add back group name
bendichter 1df145e
lazy generation of TimeSeries name
bendichter f7f253f
Update src/pynwb/testing/mock/ecephys.py
bendichter 4515f3d
Update src/pynwb/testing/mock/base.py
bendichter 5ef7b6f
Update src/pynwb/testing/mock/behavior.py
bendichter 38c1b35
Update src/pynwb/testing/mock/behavior.py
bendichter 78dbea7
Update src/pynwb/testing/mock/ecephys.py
bendichter 3fe6df8
Update src/pynwb/testing/mock/ecephys.py
bendichter b87f37b
Update src/pynwb/testing/mock/ecephys.py
bendichter c3174b3
Update src/pynwb/testing/mock/ecephys.py
bendichter ff1b343
Update src/pynwb/testing/mock/ecephys.py
bendichter d41a022
Update src/pynwb/testing/mock/ecephys.py
bendichter ff98303
Update src/pynwb/testing/mock/base.py
bendichter 521f188
Update src/pynwb/testing/mock/ecephys.py
bendichter a747e01
Update src/pynwb/testing/mock/ogen.py
bendichter b2afb77
Update src/pynwb/testing/mock/ophys.py
bendichter cd91b03
Update src/pynwb/testing/mock/ophys.py
bendichter 1efc278
Update src/pynwb/testing/mock/ophys.py
bendichter 9d4f3a6
Update src/pynwb/testing/mock/ophys.py
bendichter 98d7008
Update src/pynwb/testing/mock/ophys.py
bendichter be8ec33
Update src/pynwb/testing/mock/ogen.py
bendichter 48a947c
Update src/pynwb/testing/mock/ophys.py
bendichter b66468f
Update src/pynwb/testing/mock/ophys.py
bendichter d0a841f
Update src/pynwb/testing/mock/ophys.py
bendichter 1c74a29
Update src/pynwb/testing/mock/ophys.py
bendichter 1dee104
add init with docstring
bendichter bdca196
Merge remote-tracking branch 'origin/dummy' into mock
bendichter 1cabef1
fix mock_ElectrodeTable
bendichter 2751480
flake8
bendichter 54a2ad5
Merge branch 'dev' into dummy
rly 9db4b5a
Update src/pynwb/testing/mock/__init__.py
bendichter 6794b8c
Update CHANGELOG.md
bendichter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
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(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.