def compare_epoch_mtag(self, epoch, mtag): self.assertEqual(mtag.type, "neo.epoch") self.compare_attr(epoch, mtag) pos = mtag.positions posquant = create_quantity(pos[:], pos.unit) ext = mtag.extents extquant = create_quantity(ext[:], ext.unit) np.testing.assert_almost_equal(epoch.as_quantity(), posquant) np.testing.assert_almost_equal(epoch.durations, extquant) for neol, nixl in zip(epoch.labels, mtag.positions.dimensions[0].labels): # Dirty. Should find the root cause instead if isinstance(neol, bytes): neol = neol.decode() if isinstance(nixl, bytes): nixl = nixl.decode() self.assertEqual(neol, nixl)
def compare_spiketrain_mtag(self, spiketrain, mtag): self.assertEqual(mtag.type, "neo.spiketrain") self.compare_attr(spiketrain, mtag) pos = mtag.positions posquant = create_quantity(pos[:], pos.unit) np.testing.assert_almost_equal(spiketrain.as_quantity(), posquant) if len(mtag.features): neowfs = spiketrain.waveforms nixwfs = mtag.features[0].data self.assertEqual(np.shape(neowfs), np.shape(nixwfs)) for nixwf, neowf in zip(nixwfs, neowfs): for nixrow, neorow in zip(nixwf, neowf): for nixv, neov in zip(nixrow, neorow): self.assertEqual(create_quantity(nixv, nixwfs.unit), neov) self.assertEqual(nixwfs.dimensions[0].dimension_type, nix.DimensionType.Set) self.assertEqual(nixwfs.dimensions[1].dimension_type, nix.DimensionType.Set) self.assertEqual(nixwfs.dimensions[2].dimension_type, nix.DimensionType.Sample)
def compare_signal_dalist(self, neosig, nixdalist): """ Check if a Neo Analog or IrregularlySampledSignal matches a list of NIX DataArrays. :param neosig: Neo Analog or IrregularlySampledSignal :param nixdalist: List of DataArrays """ nixmd = nixdalist[0].metadata self.assertTrue(all(nixmd == da.metadata for da in nixdalist)) neounit = neosig.units for sig, da in zip(np.transpose(neosig), sorted(nixdalist, key=lambda d: d.name)): self.compare_attr(neosig, da) daquant = create_quantity(da[:], da.unit) np.testing.assert_almost_equal(sig, daquant) nixunit = create_quantity(1, da.unit) self.assertEqual(neounit, nixunit) timedim = da.dimensions[0] if isinstance(neosig, AnalogSignal): self.assertEqual(timedim.dimension_type, nix.DimensionType.Sample) neosp = neosig.sampling_period nixsp = create_quantity(timedim.sampling_interval, timedim.unit) self.assertEqual(neosp, nixsp) tsunit = timedim.unit if "t_start.units" in da.metadata.props: tsunit = da.metadata["t_start.units"] neots = neosig.t_start nixts = create_quantity(timedim.offset, tsunit) self.assertEqual(neots, nixts) elif isinstance(neosig, IrregularlySampledSignal): self.assertEqual(timedim.dimension_type, nix.DimensionType.Range) np.testing.assert_almost_equal(neosig.times.magnitude, timedim.ticks) self.assertEqual(timedim.unit, units_to_string(neosig.times.units))
def compare_event_mtag(self, event, mtag): self.assertEqual(mtag.type, "neo.event") self.compare_attr(event, mtag) pos = mtag.positions posquant = create_quantity(pos[:], pos.unit) np.testing.assert_almost_equal(event.as_quantity(), posquant) for neol, nixl in zip(event.labels, mtag.positions.dimensions[0].labels): # Dirty. Should find the root cause instead # Only happens in 3.2 if isinstance(neol, bytes): neol = neol.decode() if isinstance(nixl, bytes): nixl = nixl.decode() self.assertEqual(neol, nixl)