Skip to content
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
2 changes: 1 addition & 1 deletion ipfx/bin/make_stimulus_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def make_stimulus_ontology(stims):
scode = stim['stimulus_code']

# code tags
m = re.search("(.*)\d{6}$", scode)
m = re.search(r"(.*)\d{6}$", scode)
if m:
code_name, = m.groups()
tags.add((CODE, code_name, scode))
Expand Down
2 changes: 1 addition & 1 deletion ipfx/dataset/ephys_nwb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def get_clamp_mode(self,sweep_number):

def get_spike_times(self, sweep_number):
spikes = self.nwb.get_processing_module('spikes')
sweep_spikes = spikes.get_data_interface(f"Sweep_{sweep_number}")
sweep_spikes = spikes.get(f"Sweep_{sweep_number}")
return sweep_spikes.timestamps

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion ipfx/nwb_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def append_spike_times(input_nwb_path: PathLike,
unit='seconds',
data=wrapped_spike_times,
name=f"Sweep_{sweep_num}")
spike_module.add_data_interface(ts)
spike_module.add(ts)

nwbfile.add_processing_module(spike_module)

Expand Down
9 changes: 6 additions & 3 deletions ipfx/time_series_utils.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ def calculate_dvdt(v, t, filter=None):
dv = np.diff(v)

dt = np.diff(t)
dvdt = 1e-3 * dv / dt # in V/s = mV/ms

# some data sources, such as neuron, occasionally report
# some data sources, such as neuron, occasionally report
# duplicate timestamps, so we require that dt is not 0
return dvdt[np.fabs(dt) > sys.float_info.epsilon]
mask = np.fabs(dt) > sys.float_info.epsilon

dvdt = 1e-3 * dv[mask] / dt[mask] # in V/s = mV/ms

return dvdt


def has_fixed_dt(t):
Expand Down
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ markers =
requires_inhouse_data: require inhouse data

filterwarnings =
error
ignore:add_child is deprecated. Set the parent attribute instead.:DeprecationWarning
ignore::marshmallow.warnings.RemovedInMarshmallow4Warning
ignore::marshmallow.warnings.ChangedInMarshmallow4Warning
ignore:scipy.misc is deprecated and will be removed in 2.0.0
ignore:.*behaviour will change in pandas 3.0!.*:FutureWarning
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pillow
pyabf
pynwb==3.1.2
pyYAML
python-dateutil
ruamel.yaml<0.18.0
scipy
simplejson
Expand Down
5 changes: 4 additions & 1 deletion tests/attach_metadata/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import pytest
from ipfx.utilities import inject_sweep_table

from dateutil.tz import tzlocal

class CliRunner:

def __init__(
Expand Down Expand Up @@ -54,7 +56,7 @@ def simple_nwb(base_path):
nwbfile = pynwb.NWBFile(
session_description="test session",
identifier='test session',
session_start_time=datetime.now()
session_start_time=datetime.now(tzlocal())
)

inject_sweep_table(nwbfile)
Expand Down Expand Up @@ -149,6 +151,7 @@ def test_cli_nwb2(cli_runner):
[1, 2, 3]
)

@pytest.mark.filterwarnings("ignore:.*Use of icephys_filtering is deprecated and will be removed in PyNWB 4.0. Use the IntracellularElectrode.filtering field instead")
def test_cli_mies(cli_runner):
in_nwb_path = os.path.join(cli_runner.tmpdir, "input.nwb")
out_nwb_path = os.path.join(cli_runner.tmpdir, "meta.nwb")
Expand Down
8 changes: 6 additions & 2 deletions tests/attach_metadata/test_nwb2_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pynwb
import h5py

from dateutil.tz import tzlocal
from ipfx.attach_metadata.sink import nwb2_sink
from ipfx.utilities import inject_sweep_table

Expand All @@ -24,7 +25,7 @@ def nwbfile():
_nwbfile = pynwb.NWBFile(
session_description="test session",
identifier='test session',
session_start_time=datetime.now()
session_start_time=datetime.now(tzlocal())
)
dev = pynwb.device.Device(name="my_device")
_nwbfile.add_device(dev)
Expand Down Expand Up @@ -78,6 +79,8 @@ def test_get_subject(nwbfile, set_none):
assert nwbfile.subject.subject_id == "foo"


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
@pytest.mark.filterwarnings("ignore:.*It is recommended that NWB files using the HDF5 backend use the '.nwb' extension.")
def test_serialize(tmpdir_factory, nwbfile):
out_path = os.path.join(
str(tmpdir_factory.mktemp("test_serialize")),
Expand All @@ -88,7 +91,6 @@ def test_serialize(tmpdir_factory, nwbfile):
sink._data = io.BytesIO()
sink._h5_file = h5py.File(sink._data, "w")
sink._nwb_io = pynwb.NWBHDF5IO(
path=sink._h5_file.filename,
mode="w",
file=sink._h5_file
)
Expand All @@ -101,6 +103,7 @@ def test_serialize(tmpdir_factory, nwbfile):
assert obt.identifier == "test session"


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_roundtrip(tmpdir_factory, nwbfile):
tmpdir = str(tmpdir_factory.mktemp("test_serialize"))
first_path = os.path.join(tmpdir, "first.nwb")
Expand Down Expand Up @@ -135,6 +138,7 @@ def test_roundtrip(tmpdir_factory, nwbfile):
"Mus musculus"
],
])
@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_register(
tmpdir_factory, nwbfile, name, value, sweep_id, getter, expected
):
Expand Down
11 changes: 9 additions & 2 deletions tests/dataset/test_ephys_nwb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pynwb.icephys import CurrentClampStimulusSeries, CurrentClampSeries
import numpy as np
from ipfx.utilities import inject_sweep_table
from dateutil.tz import tzlocal

from dictdiffer import diff

Expand All @@ -28,8 +29,8 @@ def nwbfile_to_test():
nwbfile = pynwb.NWBFile(
session_description="test nwb data",
identifier='test session',
session_start_time=datetime.datetime.now(),
file_create_date=datetime.datetime.now()
session_start_time=datetime.datetime.now(tzlocal()),
file_create_date=datetime.datetime.now(tzlocal())
)

device = nwbfile.create_device(name='electrode_0')
Expand Down Expand Up @@ -102,14 +103,17 @@ def nwb_data(tmp_nwb_path):
return EphysNWBData(nwb_file=tmp_nwb_path, ontology=ontology)


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_stimulus_unit(nwb_data):
assert nwb_data.get_stimulus_unit(sweep_number=4) == "Amps"


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_stimulus_code(nwb_data):
assert nwb_data.get_stimulus_code(sweep_number=4) == "STIMULUS_CODE"


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_sweep_data(nwb_data):

expected = {
Expand All @@ -124,6 +128,7 @@ def test_get_sweep_data(nwb_data):
assert list(diff(expected, obtained, tolerance=0.001)) == []


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_sweep_attrs(nwb_data):

expected = {
Expand All @@ -140,12 +145,14 @@ def test_get_sweep_attrs(nwb_data):
print(expected)
assert expected == obtained

@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_clamp_mode(nwb_data):

attrs = nwb_data.get_sweep_attrs(4);

assert attrs['clamp_mode'] == "CurrentClamp"

@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_full_recording_date(nwb_data):
assert nwb_data.get_full_recording_date() == nwb_data.nwb.session_start_time

4 changes: 4 additions & 0 deletions tests/dataset/test_hbg_nwb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ def hbg_nwb_data(tmp_nwb_path):
return HBGNWBData(nwb_file=tmp_nwb_path, ontology=ontology)


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_create_hbg(hbg_nwb_data):
assert isinstance(hbg_nwb_data,HBGNWBData)


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_sweep_metadata(hbg_nwb_data):

expected = {
Expand All @@ -48,6 +50,8 @@ def test_get_sweep_metadata(hbg_nwb_data):
obtained = hbg_nwb_data.get_sweep_metadata(sweep_number=4)
assert expected == obtained


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_stimulus_code_ext(hbg_nwb_data):

expected = 'STIMULUS_CODE'
Expand Down
2 changes: 2 additions & 0 deletions tests/dataset/test_mies_nwb_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def get_value(self, key, sweep_num, default):
ontology=ontology)


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_create_mies(mies_nwb_data):
assert isinstance(mies_nwb_data, MIESNWBData)


@pytest.mark.filterwarnings("ignore:.*Value with data type int64 is being converted to data type uint64.*")
def test_get_sweep_metadata(mies_nwb_data):

expected = {
Expand Down
8 changes: 5 additions & 3 deletions tests/test_append_nwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pynwb
import numpy as np

from dateutil.tz import tzlocal

from ipfx.nwb_append import append_spike_times


Expand All @@ -11,8 +13,8 @@ def make_skeleton_nwb2_file(nwb2_file_name):
nwbfile = pynwb.NWBFile(
session_description='test icephys',
identifier='session_uuid',
session_start_time=datetime.datetime.now(),
file_create_date=datetime.datetime.now()
session_start_time=datetime.datetime.now(tzlocal()),
file_create_date=datetime.datetime.now(tzlocal())
)

device = nwbfile.create_device(name='electrode_0')
Expand Down Expand Up @@ -49,5 +51,5 @@ def test_embed_spike_times_into_nwb(tmpdir_factory):

spikes = nwbfile.get_processing_module('spikes')
for sweep_num, spike_times in sweep_spike_times.items():
sweep_spikes = spikes.get_data_interface(f"Sweep_{sweep_num}").timestamps
sweep_spikes = spikes.get(f"Sweep_{sweep_num}").timestamps
assert np.allclose(sweep_spikes, spike_times)
2 changes: 1 addition & 1 deletion tests/test_ephys_extractor.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_extractors_no_values():
SpikeFeatureExtractor()
SpikeTrainFeatureExtractor(start=0, end=0)


@pytest.mark.filterwarnings("ignore:.*encountered in divide:RuntimeWarning")
def test_extractor_wrong_inputs(spike_test_pair):
data = spike_test_pair

Expand Down
1 change: 1 addition & 0 deletions tests/test_mies_nwb_pipeline_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def rebase(new_base: str, path: str, mkdir: bool = False) -> str:

@pytest.mark.slow
@pytest.mark.parametrize('input_json,output_json', test_specimens_params)
@pytest.mark.filterwarnings("ignore:.*Use of icephys_filtering is deprecated and will be removed in PyNWB 4.0. Use the IntracellularElectrode.filtering field instead")
def test_mies_nwb_pipeline_output(input_json, output_json, tmpdir_factory):
"""
Runs pipeline, saves to a json file and compares to the existing pipeline output.
Expand Down