diff --git a/ipfx/bin/make_stimulus_ontology.py b/ipfx/bin/make_stimulus_ontology.py index 8f3c734b..6ba43ebf 100755 --- a/ipfx/bin/make_stimulus_ontology.py +++ b/ipfx/bin/make_stimulus_ontology.py @@ -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)) diff --git a/ipfx/dataset/ephys_nwb_data.py b/ipfx/dataset/ephys_nwb_data.py index aa373f58..388ccc9b 100644 --- a/ipfx/dataset/ephys_nwb_data.py +++ b/ipfx/dataset/ephys_nwb_data.py @@ -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 diff --git a/ipfx/nwb_append.py b/ipfx/nwb_append.py index 32a52af9..f8bada40 100644 --- a/ipfx/nwb_append.py +++ b/ipfx/nwb_append.py @@ -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) diff --git a/ipfx/time_series_utils.py b/ipfx/time_series_utils.py old mode 100644 new mode 100755 index 6c3ae8be..bb290ae1 --- a/ipfx/time_series_utils.py +++ b/ipfx/time_series_utils.py @@ -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): diff --git a/pytest.ini b/pytest.ini index 626d70ba..a68d124f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -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 diff --git a/requirements.txt b/requirements.txt index a6e90e15..73620e56 100755 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ pillow pyabf pynwb==3.1.2 pyYAML +python-dateutil ruamel.yaml<0.18.0 scipy simplejson diff --git a/tests/attach_metadata/test_cli.py b/tests/attach_metadata/test_cli.py index 2c025def..e1116abd 100644 --- a/tests/attach_metadata/test_cli.py +++ b/tests/attach_metadata/test_cli.py @@ -14,6 +14,8 @@ import pytest from ipfx.utilities import inject_sweep_table +from dateutil.tz import tzlocal + class CliRunner: def __init__( @@ -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) @@ -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") diff --git a/tests/attach_metadata/test_nwb2_sink.py b/tests/attach_metadata/test_nwb2_sink.py index 1df7a1e6..592ef200 100644 --- a/tests/attach_metadata/test_nwb2_sink.py +++ b/tests/attach_metadata/test_nwb2_sink.py @@ -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 @@ -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) @@ -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")), @@ -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 ) @@ -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") @@ -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 ): diff --git a/tests/dataset/test_ephys_nwb_data.py b/tests/dataset/test_ephys_nwb_data.py index 0b0d046d..195f6b4f 100644 --- a/tests/dataset/test_ephys_nwb_data.py +++ b/tests/dataset/test_ephys_nwb_data.py @@ -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 @@ -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') @@ -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 = { @@ -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 = { @@ -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 diff --git a/tests/dataset/test_hbg_nwb_data.py b/tests/dataset/test_hbg_nwb_data.py index 97473629..0eaff806 100644 --- a/tests/dataset/test_hbg_nwb_data.py +++ b/tests/dataset/test_hbg_nwb_data.py @@ -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 = { @@ -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' diff --git a/tests/dataset/test_mies_nwb_data.py b/tests/dataset/test_mies_nwb_data.py index c76fc949..c46151a0 100644 --- a/tests/dataset/test_mies_nwb_data.py +++ b/tests/dataset/test_mies_nwb_data.py @@ -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 = { diff --git a/tests/test_append_nwb.py b/tests/test_append_nwb.py index 73ae5ba6..3a889db4 100644 --- a/tests/test_append_nwb.py +++ b/tests/test_append_nwb.py @@ -3,6 +3,8 @@ import pynwb import numpy as np +from dateutil.tz import tzlocal + from ipfx.nwb_append import append_spike_times @@ -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') @@ -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) diff --git a/tests/test_ephys_extractor.py b/tests/test_ephys_extractor.py old mode 100644 new mode 100755 index 080f3529..97ef5f39 --- a/tests/test_ephys_extractor.py +++ b/tests/test_ephys_extractor.py @@ -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 diff --git a/tests/test_mies_nwb_pipeline_output.py b/tests/test_mies_nwb_pipeline_output.py index d2122ceb..952736f3 100755 --- a/tests/test_mies_nwb_pipeline_output.py +++ b/tests/test_mies_nwb_pipeline_output.py @@ -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.