@@ -117,6 +117,20 @@ def __setitem__(self, key, value):
117
117
except IndexError :
118
118
raise IndexError
119
119
120
+ def __getattr__ (self , name ):
121
+ """Allow numpy functions to be attached as attributes of Tsd objects"""
122
+ if hasattr (np , name ):
123
+ np_func = getattr (np , name )
124
+
125
+ def method (* args , ** kwargs ):
126
+ return np_func (self , * args , ** kwargs )
127
+
128
+ return method
129
+
130
+ raise AttributeError (
131
+ "Time series object does not have the attribute {}" .format (name )
132
+ )
133
+
120
134
@property
121
135
def d (self ):
122
136
return self .values
@@ -178,8 +192,6 @@ def __array_ufunc__(self, ufunc, method, *args, **kwargs):
178
192
179
193
def __array_function__ (self , func , types , args , kwargs ):
180
194
if func in [
181
- np .hstack ,
182
- np .dstack ,
183
195
np .sort ,
184
196
np .lexsort ,
185
197
np .sort_complex ,
@@ -194,12 +206,8 @@ def __array_function__(self, func, types, args, kwargs):
194
206
if func in [np .split , np .array_split , np .dsplit , np .hsplit , np .vsplit ]:
195
207
return _split_tsd (func , * args , ** kwargs )
196
208
197
- if func in [np .vstack , np .concatenate ]:
198
- if func == np .concatenate :
199
- if "axis" in kwargs :
200
- if kwargs ["axis" ] != 0 :
201
- return NotImplemented
202
- return _concatenate_tsd (func , * args )
209
+ if func in [np .concatenate , np .vstack , np .hstack , np .dstack ]:
210
+ return _concatenate_tsd (func , * args , ** kwargs )
203
211
204
212
new_args = []
205
213
for a in args :
@@ -655,7 +663,7 @@ def save(self, filename):
655
663
filtered them. You can save the filtered channels as a npz to avoid
656
664
reprocessing it.
657
665
658
- You can load the object with numpy.load . Keys are 't', 'd', 'start', 'end', 'type'
666
+ You can load the object with `nap.load_file` . Keys are 't', 'd', 'start', 'end', 'type'
659
667
and 'columns' for columns names.
660
668
661
669
Parameters
@@ -670,21 +678,9 @@ def save(self, filename):
670
678
>>> tsdtensor = nap.TsdTensor(t=np.array([0., 1.]), d = np.zeros((2,3,4)))
671
679
>>> tsdtensor.save("my_path/my_tsdtensor.npz")
672
680
673
- Here I can retrieve my data with numpy directly:
674
-
675
- >>> file = np.load("my_path/my_tsdtensor.npz")
676
- >>> print(list(file.keys()))
677
- ['t', 'd', 'start', 'end', ''type']
678
- >>> print(file['t'])
679
- [0. 1.]
680
-
681
- It is then easy to recreate the TsdTensor object.
682
- >>> time_support = nap.IntervalSet(file['start'], file['end'])
683
- >>> nap.TsdTensor(t=file['t'], d=file['d'], time_support=time_support)
684
- Time (s)
685
- 0.0 [[[0.0 ...]]]
686
- 1.0 [[[0.0 ...]]]
681
+ To load you file, you can use the `nap.load_file` function :
687
682
683
+ >>> tsdtensor = nap.load_file("my_path/my_tsdtensor.npz")
688
684
689
685
Raises
690
686
------
@@ -911,7 +907,7 @@ def save(self, filename):
911
907
filtered them. You can save the filtered channels as a npz to avoid
912
908
reprocessing it.
913
909
914
- You can load the object with numpy.load . Keys are 't', 'd', 'start', 'end', 'type'
910
+ You can load the object with `nap.load_file` . Keys are 't', 'd', 'start', 'end', 'type'
915
911
and 'columns' for columns names.
916
912
917
913
Parameters
@@ -926,17 +922,10 @@ def save(self, filename):
926
922
>>> tsdframe = nap.TsdFrame(t=np.array([0., 1.]), d = np.array([[2, 3],[4,5]]), columns=['a', 'b'])
927
923
>>> tsdframe.save("my_path/my_tsdframe.npz")
928
924
929
- Here I can retrieve my data with numpy directly:
930
-
931
- >>> file = np.load("my_path/my_tsdframe.npz")
932
- >>> print(list(file.keys()))
933
- ['t', 'd', 'start', 'end', 'columns', 'type']
934
- >>> print(file['t'])
935
- [0. 1.]
925
+ To load you file, you can use the `nap.load_file` function :
936
926
937
- It is then easy to recreate the Tsd object.
938
- >>> time_support = nap.IntervalSet(file['start'], file['end'])
939
- >>> nap.TsdFrame(t=file['t'], d=file['d'], time_support=time_support, columns=file['columns'])
927
+ >>> tsdframe = nap.load_file("my_path/my_tsdframe.npz")
928
+ >>> tsdframe
940
929
a b
941
930
Time (s)
942
931
0.0 2 3
@@ -1208,6 +1197,7 @@ def to_tsgroup(self):
1208
1197
TsGroup
1209
1198
Grouped timestamps
1210
1199
1200
+
1211
1201
"""
1212
1202
ts_group = importlib .import_module (".ts_group" , "pynapple.core" )
1213
1203
t = self .index .values
@@ -1218,7 +1208,9 @@ def to_tsgroup(self):
1218
1208
for k in idx :
1219
1209
group [k ] = Ts (t = t [d == k ], time_support = self .time_support )
1220
1210
1221
- return ts_group .TsGroup (group , time_support = self .time_support )
1211
+ return ts_group .TsGroup (
1212
+ group , time_support = self .time_support , bypass_check = True
1213
+ )
1222
1214
1223
1215
def save (self , filename ):
1224
1216
"""
@@ -1230,7 +1222,7 @@ def save(self, filename):
1230
1222
filtered it. You can save the filtered channel as a npz to avoid
1231
1223
reprocessing it.
1232
1224
1233
- You can load the object with numpy.load . Keys are 't', 'd', 'start', 'end' and 'type'.
1225
+ You can load the object with `nap.load_file` . Keys are 't', 'd', 'start', 'end' and 'type'.
1234
1226
See the example below.
1235
1227
1236
1228
Parameters
@@ -1245,17 +1237,10 @@ def save(self, filename):
1245
1237
>>> tsd = nap.Tsd(t=np.array([0., 1.]), d = np.array([2, 3]))
1246
1238
>>> tsd.save("my_path/my_tsd.npz")
1247
1239
1248
- Here I can retrieve my data with numpy directly :
1240
+ To load you file, you can use the `nap.load_file` function :
1249
1241
1250
- >>> file = np.load("my_path/my_tsd.npz")
1251
- >>> print(list(file.keys()))
1252
- ['t', 'd', 'start', 'end', 'type']
1253
- >>> print(file['t'])
1254
- [0. 1.]
1255
-
1256
- It is then easy to recreate the Tsd object.
1257
- >>> time_support = nap.IntervalSet(file['start'], file['end'])
1258
- >>> nap.Tsd(t=file['t'], d=file['d'], time_support=time_support)
1242
+ >>> tsd = nap.load_file("my_path/my_tsd.npz")
1243
+ >>> tsd
1259
1244
Time (s)
1260
1245
0.0 2
1261
1246
1.0 3
@@ -1524,7 +1509,7 @@ def save(self, filename):
1524
1509
The main purpose of this function is to save small/medium sized timestamps
1525
1510
object.
1526
1511
1527
- You can load the object with numpy.load . Keys are 't', 'start' and 'end' and 'type'.
1512
+ You can load the object with `nap.load_file` . Keys are 't', 'start' and 'end' and 'type'.
1528
1513
See the example below.
1529
1514
1530
1515
Parameters
@@ -1539,23 +1524,15 @@ def save(self, filename):
1539
1524
>>> ts = nap.Ts(t=np.array([0., 1., 1.5]))
1540
1525
>>> ts.save("my_path/my_ts.npz")
1541
1526
1542
- Here I can retrieve my data with numpy directly:
1543
-
1544
- >>> file = np.load("my_path/my_ts.npz")
1545
- >>> print(list(file.keys()))
1546
- ['t', 'start', 'end', 'type']
1547
- >>> print(file['t'])
1548
- [0. 1. 1.5]
1527
+ To load you file, you can use the `nap.load_file` function :
1549
1528
1550
- It is then easy to recreate the Tsd object.
1551
- >>> time_support = nap.IntervalSet(file['start'], file['end'])
1552
- >>> nap.Ts(t=file['t'], time_support=time_support)
1529
+ >>> ts = nap.load_file("my_path/my_ts.npz")
1530
+ >>> ts
1553
1531
Time (s)
1554
1532
0.0
1555
1533
1.0
1556
1534
1.5
1557
1535
1558
-
1559
1536
Raises
1560
1537
------
1561
1538
RuntimeError
0 commit comments