Skip to content

Commit 60646ad

Browse files
committed
treewide: Allow to inject a SweepTable
The SweepTable was the first icephys table for grouping different patch clamp series together, see NeurodataWithoutBorders/pynwb@21f91920 (Add a SweepTable for icephys data, 2018-11-02) for pynwb 0.6.0. This was superseeded by the icephys metadata tables introduced in pynwb 2.0.0 and finally removed in 3.0.0. While migrating to the icephys metadata tables is on the list [1], we don't want to do this here now. So let's add a nasty hack for injecting a sweep table. [1]: AllenInstitute/IPNWB#47
1 parent 99f8e36 commit 60646ad

File tree

6 files changed

+25
-1
lines changed

6 files changed

+25
-1
lines changed

ipfx/utilities.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from ipfx.stimulus import StimulusOntology
77
from ipfx.dataset.ephys_data_set import EphysDataSet
88

9+
from pynwb.icephys import SweepTable
10+
import pynwb
911

1012
def drop_failed_sweeps(
1113
dataset: EphysDataSet,
@@ -41,3 +43,12 @@ def drop_failed_sweeps(
4143

4244
dataset.sweep_info = sweep_features
4345

46+
def inject_sweep_table(nwbfile: pynwb.NWBFile):
47+
"""
48+
Allows us to keep using the SweepTable which can not be constructed anymore in pynwb 3.0.
49+
"""
50+
51+
sweep_table = SweepTable.__new__(SweepTable, parent=nwbfile, in_construct_mode=True)
52+
sweep_table.__init__(name='sweep_table')
53+
sweep_table._in_construct_mode = False
54+
nwbfile.sweep_table = sweep_table

ipfx/x_to_nwb/ABFConverter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from ipfx.x_to_nwb.conversion_utils import PLACEHOLDER, V_CLAMP_MODE, I_CLAMP_MODE, I0_CLAMP_MODE, \
2222
parseUnit, getStimulusSeriesClass, getAcquiredSeriesClass, createSeriesName, convertDataset, \
2323
getPackageInfo, createCycleID
24+
from ipfx.utilities import inject_sweep_table
2425

2526
log = logging.getLogger(__name__)
2627

@@ -78,6 +79,8 @@ def __init__(self, inFileOrFolder, outFile, outputFeedbackChannel, compression=T
7879
electrodes = self._createElectrodes(device)
7980
nwbFile.add_icephys_electrode(electrodes)
8081

82+
inject_sweep_table(nwbfile)
83+
8184
for i in self._createStimulusSeries(electrodes):
8285
nwbFile.add_stimulus(i, use_sweep_table=True)
8386

ipfx/x_to_nwb/DatConverter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ipfx.x_to_nwb.conversion_utils import PLACEHOLDER, V_CLAMP_MODE, I_CLAMP_MODE, \
1717
parseUnit, getStimulusSeriesClass, getAcquiredSeriesClass, createSeriesName, convertDataset, \
1818
getPackageInfo, getStimulusRecordIndex, createCycleID, clampModeToString
19+
from ipfx.utilities import inject_sweep_table
1920

2021
log = logging.getLogger(__name__)
2122

@@ -70,6 +71,8 @@ def generateList(multipleGroupsPerFile, pul):
7071
electrodes = self._createElectrodes(device)
7172
nwbFile.add_icephys_electrode(electrodes)
7273

74+
inject_sweep_table(nwbfile)
75+
7376
for i in self._createAcquiredSeries(electrodes, elem):
7477
nwbFile.add_acquisition(i, use_sweep_table=True)
7578

tests/attach_metadata/test_cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pynwb
1313
import numpy as np
1414
import pytest
15-
15+
from ipfx.utilities import inject_sweep_table
1616

1717
class CliRunner:
1818

@@ -56,6 +56,9 @@ def simple_nwb(base_path):
5656
identifier='test session',
5757
session_start_time=datetime.now()
5858
)
59+
60+
inject_sweep_table(nwbfile)
61+
5962
nwbfile.add_acquisition(
6063
pynwb.TimeSeries(
6164
name="a timeseries",

tests/attach_metadata/test_nwb2_sink.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import h5py
1717

1818
from ipfx.attach_metadata.sink import nwb2_sink
19+
from ipfx.utilities import inject_sweep_table
1920

2021

2122
@pytest.fixture
@@ -42,6 +43,7 @@ def nwbfile():
4243
electrode=ice,
4344
sweep_number=12
4445
)
46+
inject_sweep_table(_nwbfile)
4547
_nwbfile.add_acquisition(series, use_sweep_table=True)
4648
_nwbfile.subject = pynwb.file.Subject()
4749

tests/dataset/test_ephys_nwb_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pynwb
77
from pynwb.icephys import CurrentClampStimulusSeries, CurrentClampSeries
88
import numpy as np
9+
from ipfx.utilities import inject_sweep_table
910

1011
from dictdiffer import diff
1112

@@ -58,6 +59,7 @@ def nwbfile_to_test():
5859
**stimulus_meta_data
5960
)
6061

62+
inject_sweep_table(nwbfile)
6163
nwbfile.add_stimulus(stimulus_series, use_sweep_table=True)
6264

6365
response_data = [1, 2, 3, 4, 5]

0 commit comments

Comments
 (0)