Skip to content

Commit

Permalink
Merge pull request #1586 from NeuralEnsemble/black-formatting
Browse files Browse the repository at this point in the history
Black formatting
  • Loading branch information
zm711 authored Oct 20, 2024
2 parents b17979a + 2f007e0 commit 8e180f4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
42 changes: 23 additions & 19 deletions neo/core/spiketrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ def normalize_times_array(times, units=None, dtype=None, copy=None):
"""

if copy is not None:
raise ValueError(
"`copy` is now deprecated in Neo due to removal in NumPy 2.0 and will be removed in 0.15.0."
)

raise ValueError("`copy` is now deprecated in Neo due to removal in NumPy 2.0 and will be removed in 0.15.0.")

if dtype is None:
if not hasattr(times, "dtype"):
dtype = float
Expand All @@ -218,14 +216,20 @@ def normalize_times_array(times, units=None, dtype=None, copy=None):
units = None # units will be taken from times, avoids copying
else:
raise ValueError("cannot rescale and return view")


# check to make sure the units are time
# this approach is orders of magnitude faster than comparing the
# reference dimensionality
if len(dim) != 1 or list(dim.values())[0] != 1 or not isinstance(list(dim.keys())[0], pq.UnitTime):
ValueError(f"Units have dimensions {dim.simplified}, not [time]")
return pq.Quantity(times, units=units, dtype=dtype,), dim
return (
pq.Quantity(
times,
units=units,
dtype=dtype,
),
dim,
)


class SpikeTrain(DataObject):
Expand Down Expand Up @@ -807,19 +811,19 @@ def time_shift(self, t_shift):
t_stop = self.t_stop + t_shift
t_start = self.t_start + t_shift
new_st = SpikeTrain(
times=times,
t_stop=t_stop,
units=self.unit,
sampling_rate=self.sampling_rate,
t_start=t_start,
waveforms=self.waveforms,
left_sweep=self.left_sweep,
name=self.name,
file_origin=self.file_origin,
description=self.description,
array_annotations=deepcopy(self.array_annotations),
**self.annotations,
)
times=times,
t_stop=t_stop,
units=self.unit,
sampling_rate=self.sampling_rate,
t_start=t_start,
waveforms=self.waveforms,
left_sweep=self.left_sweep,
name=self.name,
file_origin=self.file_origin,
description=self.description,
array_annotations=deepcopy(self.array_annotations),
**self.annotations,
)

# Here we can safely copy the array annotations since we know that
# the length of the SpikeTrain does not change.
Expand Down
2 changes: 1 addition & 1 deletion neo/rawio/plexonrawio.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _parse_header(self):

upper_byte_of_5_byte_timestamp = int(bl_header["UpperByteOf5ByteTimestamp"])
bl_header_timestamp = int(bl_header["TimeStamp"])
self._last_timestamps = upper_byte_of_5_byte_timestamp * 2**32 + bl_header_timestamp
self._last_timestamps = upper_byte_of_5_byte_timestamp * 2**32 + bl_header_timestamp

# ... and finalize them in self._data_blocks
# for a faster access depending on type (1, 4, 5)
Expand Down
2 changes: 1 addition & 1 deletion neo/test/coretest/test_analogsignal.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def test__create_inconsistent_sampling_rate_and_period_ValueError(self):
data = np.arange(10.0) * pq.mV
self.assertRaises(ValueError, AnalogSignal, data, sampling_rate=1 * pq.kHz, sampling_period=5 * pq.s)


def test__create_with_additional_argument(self):
signal = AnalogSignal(
[1, 2, 3], units="mV", sampling_rate=1 * pq.kHz, file_origin="crack.txt", ratname="Nicolas"
Expand Down Expand Up @@ -1762,6 +1761,7 @@ def test__pickle_2d(self):
fobj.close()
os.remove("./pickle")


class TestAnalogSignalSampling(unittest.TestCase):
def test___get_sampling_rate__period_none_rate_none_ValueError(self):
sampling_rate = None
Expand Down
11 changes: 2 additions & 9 deletions neo/test/coretest/test_spiketrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ def test__create_from_list_no_start_stop_units(self):
self.result_spike_check(train1, st_out, t_start_out, t_stop_out, dtype, units)
self.result_spike_check(train2, st_out, t_start_out, t_stop_out, dtype, units)


def test__create_from_array(self):
times = np.arange(10)
t_start = 0.0 * pq.s
Expand Down Expand Up @@ -297,7 +296,6 @@ def test__create_from_array_no_start_stop_units_with_dtype(self):
self.result_spike_check(train1, st_out, t_start_out, t_stop_out, dtype, units)
self.result_spike_check(train2, st_out, t_start_out, t_stop_out, dtype, units)


def test__create_from_quantity_array(self):
times = np.arange(10) * pq.ms
t_start = 0.0 * pq.s
Expand Down Expand Up @@ -328,7 +326,6 @@ def test__create_from_quantity_array_with_dtype(self):
self.result_spike_check(train1, st_out, t_start_out, t_stop_out, dtype, units)
self.result_spike_check(train2, st_out, t_start_out, t_stop_out, dtype, units)


def test__create_from_quantity_array_no_start_stop_units(self):
times = np.arange(10) * pq.ms
t_start = 0.0
Expand Down Expand Up @@ -359,7 +356,6 @@ def test__create_from_quantity_array_no_start_stop_units_with_dtype(self):
self.result_spike_check(train1, st_out, t_start_out, t_stop_out, dtype, units)
self.result_spike_check(train2, st_out, t_start_out, t_stop_out, dtype, units)


def test__create_from_list_without_units_should_raise_ValueError(self):
times = range(10)
t_start = 0.0 * pq.s
Expand Down Expand Up @@ -1229,7 +1225,7 @@ def test_correct_times(self):
self.assertIsInstance(result.array_annotations, ArrayDict)

def test_rescaling_units(self):
train3 = self.train1.duplicate_with_new_data(signal=(self.train1.times.magnitude/1000) * pq.millisecond)
train3 = self.train1.duplicate_with_new_data(signal=(self.train1.times.magnitude / 1000) * pq.millisecond)
train3.segment = self.train1.segment
train3.array_annotate(**self.arr_ann1)
# Array annotations merge warning was already tested, can be ignored now
Expand Down Expand Up @@ -1495,7 +1491,6 @@ def test_array_annotations(self):

class TestChanging(unittest.TestCase):


# now we test default behavior here so change false to None
def test_change_with_default(self):
# Changing spike train also changes data, because it is a view
Expand Down Expand Up @@ -1524,7 +1519,6 @@ def test_change_and_rescale_true(self):
data = [3, 4, 5] * pq.s
self.assertRaises(ValueError, SpikeTrain, data, units="ms", t_stop=10000)


def test_change_and_data_not_quantity(self):
# Changing spike train also changes data, because it is a view
# Data source is array
Expand All @@ -1542,7 +1536,6 @@ def test__dtype_change(self):
data = np.array([3, 4, 5])
self.assertRaises(ValueError, SpikeTrain, data, units="sec", t_stop=101, dtype=np.float64)


def test_changing_slice_changes_original_spiketrain(self):
# If we slice a spiketrain and then change the slice, the
# original spiketrain should change.
Expand Down Expand Up @@ -1848,7 +1841,7 @@ def test__pretty(self):


class TestMiscellaneous(unittest.TestCase):

def test_as_array(self):
data = np.arange(10.0)
st = SpikeTrain(data, t_stop=10.0, units="ms")
Expand Down

0 comments on commit 8e180f4

Please sign in to comment.