Skip to content

Commit df5666f

Browse files
committed
Rename 'patch' to 'concatenate'
1 parent bc58320 commit df5666f

File tree

5 files changed

+51
-51
lines changed

5 files changed

+51
-51
lines changed

neo/core/analogsignal.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def rectify(self, **kwargs):
660660

661661
return rectified_signal
662662

663-
def patch(self, other, overwrite=True, padding=False):
663+
def concatenate(self, other, overwrite=True, padding=False):
664664
'''
665665
Patch another signal to this one.
666666
@@ -670,7 +670,7 @@ def patch(self, other, overwrite=True, padding=False):
670670
have to overlap by one sample in time, i.e.
671671
self.t_stop == other.t_start
672672
Note: Only common array annotations common to
673-
both signals are attached to the patched signal.
673+
both signals are attached to the concatenated signal.
674674
675675
If the attributes of the two signal are not
676676
compatible, an Exception is raised.
@@ -727,16 +727,16 @@ def patch(self, other, overwrite=True, padding=False):
727727
if getattr(self, attr[0], None) != getattr(other, attr[0], None):
728728
# if attr[0] in ['t_start','t_stop']:
729729
# continue
730-
raise MergeError("Cannot patch these two signals as the %s differ." % attr[0])
730+
raise MergeError("Cannot concatenate these two signals as the %s differ." % attr[0])
731731

732732
if hasattr(self, "lazy_shape"):
733733
if hasattr(other, "lazy_shape"):
734734
if self.lazy_shape[-1] != other.lazy_shape[-1]:
735-
raise MergeError("Cannot patch signals as they contain"
735+
raise MergeError("Cannot concatenate signals as they contain"
736736
" different numbers of traces.")
737737
merged_lazy_shape = (self.lazy_shape[0] + other.lazy_shape[0], self.lazy_shape[-1])
738738
else:
739-
raise MergeError("Cannot patch a lazy object with a real object.")
739+
raise MergeError("Cannot concatenate a lazy object with a real object.")
740740

741741
# in case of non-overlapping signals consider padding
742742
if signal2.t_start > signal1.t_stop + signal1.sampling_period:
@@ -764,7 +764,7 @@ def patch(self, other, overwrite=True, padding=False):
764764
# in case of overlapping signals slice according to overwrite parameter
765765
elif signal2.t_start < signal1.t_stop + signal1.sampling_period:
766766
n_samples = int(((signal1.t_stop - signal2.t_start)*signal1.sampling_rate).simplified)
767-
logger.warning('Overwriting {} samples while patching signals.'.format(n_samples))
767+
logger.warning('Overwriting {} samples while concatenating signals.'.format(n_samples))
768768
if not overwrite: # removing samples second signal
769769
slice_t_start = signal1.t_stop + signal1.sampling_period
770770
signal2 = signal2.time_slice(slice_t_start, None)
@@ -773,7 +773,7 @@ def patch(self, other, overwrite=True, padding=False):
773773
signal1 = signal1.time_slice(None, slice_t_stop)
774774
else:
775775
assert signal2.t_start == signal1.t_stop + signal1.sampling_period, \
776-
"Cannot patch signals with non-overlapping times"
776+
"Cannot concatenate signals with non-overlapping times"
777777

778778
stack = np.vstack((signal1.magnitude, signal2.magnitude))
779779

neo/core/basesignal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ def time_slice(self, t_start, t_stop):
293293
NotImplementedError('Needs to be implemented for subclasses.')
294294

295295

296-
def patch(self, other):
296+
def concatenate(self, other):
297297
'''
298298
Patch another signal to this one.
299299
300300
The signal objects are concatenated vertically
301301
(row-wise, :func:`np.vstack`). Patching can be
302302
used to combine signals across segments.
303303
Note: Only array annotations common to
304-
both signals are attached to the patched signal.
304+
both signals are attached to the concatenated signal.
305305
306306
If the attributes of the two signal are not
307307
compatible, an Exception is raised.

neo/core/irregularlysampledsignal.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,15 +515,15 @@ def merge(self, other):
515515

516516
return signal
517517

518-
def patch(self, other):
518+
def concatenate(self, other):
519519
'''
520520
Patch another signal to this one.
521521
522522
The signal objects are concatenated vertically
523523
(row-wise, :func:`np.vstack`). Patching can be
524524
used to combine signals across segments.
525525
Note: Only array annotations common to
526-
both signals are attached to the patched signal.
526+
both signals are attached to the concatenated signal.
527527
528528
If the attributes of the two signal are not
529529
compatible, an Exception is raised.
@@ -550,16 +550,16 @@ def patch(self, other):
550550
for attr in self._necessary_attrs:
551551
if not (attr[0] in ['signal', 'times', 't_start', 't_stop', 'times']):
552552
if getattr(self, attr[0], None) != getattr(other, attr[0], None):
553-
raise MergeError("Cannot patch these two signals as the %s differ." % attr[0])
553+
raise MergeError("Cannot concatenate these two signals as the %s differ." % attr[0])
554554

555555
if hasattr(self, "lazy_shape"):
556556
if hasattr(other, "lazy_shape"):
557557
if self.lazy_shape[-1] != other.lazy_shape[-1]:
558-
raise MergeError("Cannot patch signals as they contain"
558+
raise MergeError("Cannot concatenate signals as they contain"
559559
" different numbers of traces.")
560560
merged_lazy_shape = (self.lazy_shape[0] + other.lazy_shape[0], self.lazy_shape[-1])
561561
else:
562-
raise MergeError("Cannot patch a lazy object with a real object.")
562+
raise MergeError("Cannot concatenate a lazy object with a real object.")
563563
if other.units != self.units:
564564
other = other.rescale(self.units)
565565

neo/test/coretest/test_analogsignal.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,104 +1563,104 @@ def test__merge(self):
15631563
assert_arrays_equal(mergeddata23, targdata23)
15641564
assert_arrays_equal(mergeddata24, targdata24)
15651565

1566-
def test_patch_simple(self):
1566+
def test_concatenate_simple(self):
15671567
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
15681568
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
15691569
t_start=signal1.t_stop + signal1.sampling_period)
15701570

1571-
result = signal1.patch(signal2)
1571+
result = signal1.concatenate(signal2)
15721572
assert_array_equal(np.arange(7).reshape((-1, 1)), result.magnitude)
15731573
for attr in signal1._necessary_attrs:
15741574
self.assertEqual(getattr(signal1, attr[0], None), getattr(result, attr[0], None))
15751575

1576-
def test_patch_inverse_signals(self):
1576+
def test_concatenate_inverse_signals(self):
15771577
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
15781578
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
15791579
t_start=signal1.t_stop + signal1.sampling_period)
15801580

1581-
result = signal2.patch(signal1)
1581+
result = signal2.concatenate(signal1)
15821582
assert_array_equal(np.arange(7).reshape((-1, 1)), result.magnitude)
15831583
for attr in signal1._necessary_attrs:
15841584
self.assertEqual(getattr(signal1, attr[0], None), getattr(result, attr[0], None))
15851585

1586-
def test_patch_no_overlap(self):
1586+
def test_concatenate_no_overlap(self):
15871587
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
15881588
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
15891589
t_start=10*pq.s + signal1.sampling_period)
15901590

15911591
with self.assertRaises(MergeError):
1592-
signal1.patch(signal2)
1592+
signal1.concatenate(signal2)
15931593

1594-
def test_patch_multi_trace(self):
1594+
def test_concatenate_multi_trace(self):
15951595
data1 = np.arange(4).reshape(2,2)
15961596
data2 = np.arange(4,8).reshape(2,2)
15971597
signal1 = AnalogSignal(data1*pq.V, sampling_rate=1*pq.Hz)
15981598
signal2 = AnalogSignal(data2*pq.V, sampling_rate=1*pq.Hz,
15991599
t_start=signal1.t_stop + signal1.sampling_period)
16001600

1601-
result = signal1.patch(signal2)
1601+
result = signal1.concatenate(signal2)
16021602
data_expected = np.array([[0,1],[2,3],[4,5],[6,7]])
16031603
assert_array_equal(data_expected, result.magnitude)
16041604
for attr in signal1._necessary_attrs:
16051605
self.assertEqual(getattr(signal1, attr[0], None), getattr(result, attr[0], None))
16061606

1607-
def test_patch_overwrite_true(self):
1607+
def test_concatenate_overwrite_true(self):
16081608
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
16091609
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
16101610
t_start=signal1.t_stop)
16111611

1612-
result = signal1.patch(signal2, overwrite=True)
1612+
result = signal1.concatenate(signal2, overwrite=True)
16131613
assert_array_equal(np.array([0,1,2,4,5,6]).reshape((-1, 1)), result.magnitude)
16141614

1615-
def test_patch_overwrite_false(self):
1615+
def test_concatenate_overwrite_false(self):
16161616
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
16171617
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
16181618
t_start=signal1.t_stop)
16191619

1620-
result = signal1.patch(signal2, overwrite=False)
1620+
result = signal1.concatenate(signal2, overwrite=False)
16211621
assert_array_equal(np.array([0,1,2,3,5,6]).reshape((-1, 1)), result.magnitude)
16221622

1623-
def test_patch_padding_False(self):
1623+
def test_concatenate_padding_False(self):
16241624
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
16251625
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
16261626
t_start=10*pq.s)
16271627

16281628
with self.assertRaises(MergeError):
1629-
result = signal1.patch(signal2, overwrite=False, padding=False)
1629+
result = signal1.concatenate(signal2, overwrite=False, padding=False)
16301630

1631-
def test_patch_padding_True(self):
1631+
def test_concatenate_padding_True(self):
16321632
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
16331633
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
16341634
t_start=signal1.t_stop + 3 * signal1.sampling_period)
16351635

1636-
result = signal1.patch(signal2, overwrite=False, padding=True)
1636+
result = signal1.concatenate(signal2, overwrite=False, padding=True)
16371637
assert_array_equal(np.array([0,1,2,3,np.NaN,np.NaN,np.NaN,4,5,6]).reshape((-1, 1)),
16381638
result.magnitude)
16391639

1640-
def test_patch_padding_quantity(self):
1640+
def test_concatenate_padding_quantity(self):
16411641
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
16421642
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
16431643
t_start=signal1.t_stop + 3 * signal1.sampling_period)
16441644

1645-
result = signal1.patch(signal2, overwrite=False, padding=-1*pq.mV)
1645+
result = signal1.concatenate(signal2, overwrite=False, padding=-1 * pq.mV)
16461646
assert_array_equal(np.array([0,1,2,3,-1e-3,-1e-3,-1e-3,4,5,6]).reshape((-1, 1)),
16471647
result.magnitude)
16481648

1649-
def test_patch_padding_invalid(self):
1649+
def test_concatenate_padding_invalid(self):
16501650
signal1 = AnalogSignal([0,1,2,3]*pq.V, sampling_rate=1*pq.Hz)
16511651
signal2 = AnalogSignal([4,5,6]*pq.V, sampling_rate=1*pq.Hz,
16521652
t_start=signal1.t_stop + 3 * signal1.sampling_period)
16531653

16541654
with self.assertRaises(ValueError):
1655-
result = signal1.patch(signal2, overwrite=False, padding=1)
1655+
result = signal1.concatenate(signal2, overwrite=False, padding=1)
16561656
with self.assertRaises(ValueError):
1657-
result = signal1.patch(signal2, overwrite=False, padding=[1])
1657+
result = signal1.concatenate(signal2, overwrite=False, padding=[1])
16581658
with self.assertRaises(ValueError):
1659-
result = signal1.patch(signal2, overwrite=False, padding='a')
1659+
result = signal1.concatenate(signal2, overwrite=False, padding='a')
16601660
with self.assertRaises(ValueError):
1661-
result = signal1.patch(signal2, overwrite=False, padding=np.array([1,2,3]))
1661+
result = signal1.concatenate(signal2, overwrite=False, padding=np.array([1, 2, 3]))
16621662

1663-
def test_patch_array_annotations(self):
1663+
def test_concatenate_array_annotations(self):
16641664
array_anno1 = {'first': ['a','b']}
16651665
array_anno2 = {'first': ['a','b'],
16661666
'second': ['c','d']}
@@ -1672,13 +1672,13 @@ def test_patch_array_annotations(self):
16721672
t_start=signal1.t_stop + signal1.sampling_period,
16731673
array_annotations=array_anno2)
16741674

1675-
result = signal1.patch(signal2)
1675+
result = signal1.concatenate(signal2)
16761676
assert_array_equal(array_anno1.keys(), result.array_annotations.keys())
16771677

16781678
for k in array_anno1.keys():
16791679
assert_array_equal(np.asarray(array_anno1[k]), result.array_annotations[k])
16801680

1681-
def test_patch_complex(self):
1681+
def test_concatenate_complex(self):
16821682
signal1 = self.signal1
16831683
assert_neo_object_is_compliant(self.signal1)
16841684

@@ -1687,13 +1687,13 @@ def test_patch_complex(self):
16871687
array_annotations=self.arr_ann1,
16881688
t_start=signal1.t_stop + signal1.sampling_period)
16891689

1690-
patched12 = self.signal1.patch(signal2)
1690+
concatenated12 = self.signal1.concatenate(signal2)
16911691

16921692
for attr in signal1._necessary_attrs:
1693-
self.assertEqual(getattr(signal1, attr[0], None), getattr(patched12, attr[0], None))
1693+
self.assertEqual(getattr(signal1, attr[0], None), getattr(concatenated12, attr[0], None))
16941694

16951695
assert_array_equal(np.vstack((signal1.magnitude, signal2.magnitude)),
1696-
patched12.magnitude)
1696+
concatenated12.magnitude)
16971697

16981698
class TestAnalogSignalFunctions(unittest.TestCase):
16991699
def test__pickle_1d(self):

neo/test/coretest/test_irregularysampledsignal.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -946,39 +946,39 @@ def test__merge(self):
946946
self.assertRaises(MergeError, signal1.merge, signal3)
947947

948948

949-
def test_patch_simple(self):
949+
def test_concatenate_simple(self):
950950
signal1 = IrregularlySampledSignal(signal=[0,1,2,3]*pq.s, times=[1,10,11,20]*pq.s)
951951
signal2 = IrregularlySampledSignal(signal=[4,5,6]*pq.s, times=[15,16,21]*pq.s)
952952

953-
result = signal1.patch(signal2)
953+
result = signal1.concatenate(signal2)
954954
assert_array_equal(np.array([0,1,2,4,5,3,6]).reshape((-1, 1)), result.magnitude)
955955
assert_array_equal(np.array([1,10,11,15,16,20,21]), result.times)
956956
for attr in signal1._necessary_attrs:
957957
if attr[0] == 'times':
958958
continue
959959
self.assertEqual(getattr(signal1, attr[0], None), getattr(result, attr[0], None))
960960

961-
def test_patch_no_overlap(self):
961+
def test_concatenate_no_overlap(self):
962962
signal1 = IrregularlySampledSignal(signal=[0,1,2,3]*pq.s, times=range(4)*pq.s)
963963
signal2 = IrregularlySampledSignal(signal=[4,5,6]*pq.s, times=range(4,7)*pq.s)
964964

965-
result = signal1.patch(signal2)
965+
result = signal1.concatenate(signal2)
966966
assert_array_equal(np.arange(7).reshape((-1, 1)), result.magnitude)
967967
assert_array_equal(np.arange(7), result.times)
968968

969-
def test_patch_multi_trace(self):
969+
def test_concatenate_multi_trace(self):
970970
data1 = np.arange(4).reshape(2,2)
971971
data2 = np.arange(4,8).reshape(2,2)
972972
n1 = len(data1)
973973
n2 = len(data2)
974974
signal1 = IrregularlySampledSignal(signal=data1*pq.s, times=range(n1)*pq.s)
975975
signal2 = IrregularlySampledSignal(signal=data2*pq.s, times=range(n1, n1+n2)*pq.s)
976976

977-
result = signal1.patch(signal2)
977+
result = signal1.concatenate(signal2)
978978
data_expected = np.array([[0,1],[2,3],[4,5],[6,7]])
979979
assert_array_equal(data_expected, result.magnitude)
980980

981-
def test_patch_array_annotations(self):
981+
def test_concatenate_array_annotations(self):
982982
array_anno1 = {'first': ['a','b']}
983983
array_anno2 = {'first': ['a','b'],
984984
'second': ['c','d']}
@@ -991,7 +991,7 @@ def test_patch_array_annotations(self):
991991
signal2 = IrregularlySampledSignal(signal=data2*pq.s, times=range(n1, n1+n2)*pq.s,
992992
array_annotations=array_anno2)
993993

994-
result = signal1.patch(signal2)
994+
result = signal1.concatenate(signal2)
995995
assert_array_equal(array_anno1.keys(), result.array_annotations.keys())
996996

997997
for k in array_anno1.keys():

0 commit comments

Comments
 (0)