fmatoolbox 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fmatoolbox-0.2.0/src/fmatoolbox.egg-info → fmatoolbox-0.2.1}/PKG-INFO +1 -1
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/pyproject.toml +1 -1
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/data.py +16 -8
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/general.py +3 -2
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/plotting.py +16 -10
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/regions.py +1 -1
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1/src/fmatoolbox.egg-info}/PKG-INFO +1 -1
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/LICENSE +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/README.md +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/setup.cfg +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/__init__.py +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/analysis.py +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/exceptions.py +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/intervals.py +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/preprocess.py +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox/statistics.py +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox.egg-info/SOURCES.txt +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox.egg-info/dependency_links.txt +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox.egg-info/requires.txt +0 -0
- {fmatoolbox-0.2.0 → fmatoolbox-0.2.1}/src/fmatoolbox.egg-info/top_level.txt +0 -0
|
@@ -404,10 +404,12 @@ def saveEvent(session:str|PathLike[str], format:str, data, columns=None, name=No
|
|
|
404
404
|
|
|
405
405
|
Args:
|
|
406
406
|
session: path to session's .xml file, along which the event file will be created
|
|
407
|
-
format: format of event file,
|
|
407
|
+
format: format of event file, parsed as <subdirs>/<name>.<format>, where <subdirs> and <name> are optional, e.g.,
|
|
408
|
+
- 'sleep.npy' gives name='sleep', format='npy'
|
|
409
|
+
- 'units/firing.wake' gives subdirs='units', name='firing', format='wake'
|
|
410
|
+
accepted formats are:
|
|
408
411
|
- 'npy': DESCRIBE
|
|
409
412
|
- 'npz': DESCRIBE
|
|
410
|
-
- 'name.np#': shorthand for format='np#', name='name'
|
|
411
413
|
- a different str, to save the event as a text file named <basename>.<format>, prepending a metadata header
|
|
412
414
|
in this case, `data` must be an array whose columns represent different quantities; if 1d, interpreted as one column
|
|
413
415
|
data: array to save; for npz format, must be a dict of {'name': array}
|
|
@@ -422,23 +424,29 @@ def saveEvent(session:str|PathLike[str], format:str, data, columns=None, name=No
|
|
|
422
424
|
saveEvent(session, 'npz', {'onset':[1,2], 'offset':[1.5,3]}, name='sleep')
|
|
423
425
|
# or
|
|
424
426
|
saveEvent(session, 'sleep.npz', {'onset':[1,2], 'offset':[1.5,3]})
|
|
427
|
+
|
|
428
|
+
# save the same file in subdirectory 'new' within the session
|
|
429
|
+
saveEvent(session, 'new/sleep.npz', {'onset':[1,2], 'offset':[1.5,3]})
|
|
425
430
|
"""
|
|
426
431
|
|
|
427
432
|
# parse format
|
|
428
|
-
|
|
429
|
-
format =
|
|
430
|
-
if
|
|
433
|
+
subdirs, _, filename = format.rpartition('/')
|
|
434
|
+
name, dot, format = filename.rpartition('.')
|
|
435
|
+
if not dot:
|
|
436
|
+
name, format = '', filename
|
|
437
|
+
session = pathlib.Path(session)
|
|
438
|
+
froot = session.parent / subdirs / session.stem
|
|
431
439
|
|
|
432
440
|
if format == 'npy' or format == 'npz':
|
|
433
|
-
if name
|
|
441
|
+
if not name:
|
|
434
442
|
raise ValueError(f"'name' must be specified for {format} format")
|
|
435
|
-
fname =
|
|
443
|
+
fname = froot.with_suffix(f'.{name}.{format}')
|
|
436
444
|
np.save(fname, data) if format == 'npy' else np.savez(fname, **data)
|
|
437
445
|
|
|
438
446
|
else:
|
|
439
447
|
if columns is None:
|
|
440
448
|
raise ValueError("'columns' must be specified for text formats")
|
|
441
|
-
fname =
|
|
449
|
+
fname = froot.with_suffix(f'.{format}')
|
|
442
450
|
np.savetxt(fname, data, delimiter=',', header=f" columns: {', '.join(columns)}", comments="%")
|
|
443
451
|
|
|
444
452
|
return
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
""" General-purpose data processing for FMAToolbox """
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
|
+
import fmatoolbox.intervals
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
def unwhere(indices,shape=None):
|
|
@@ -50,7 +51,7 @@ def shuffleEvents(events, offset:float=None, n:int=None, group=None, fast:bool=N
|
|
|
50
51
|
if n is None: n = 1
|
|
51
52
|
if group is not None: group = np.asarray(group,dtype=int)
|
|
52
53
|
if intervals is not None:
|
|
53
|
-
events, valid = restrict(events,intervals,shift=True,s_ind=True)
|
|
54
|
+
events, valid = fmatoolbox.intervals.restrict(events,intervals,shift=True,s_ind=True)
|
|
54
55
|
offset = 0
|
|
55
56
|
if group is not None:
|
|
56
57
|
group = group[valid]
|
|
@@ -107,7 +108,7 @@ def shuffleEvents(events, offset:float=None, n:int=None, group=None, fast:bool=N
|
|
|
107
108
|
# unshift events back into intervals
|
|
108
109
|
if intervals is not None:
|
|
109
110
|
for i in range(n):
|
|
110
|
-
shuffled[:,:,i] = unshift(shuffled[:,:,i],intervals)
|
|
111
|
+
shuffled[:,:,i] = fmatoolbox.intervals.unshift(shuffled[:,:,i],intervals)
|
|
111
112
|
|
|
112
113
|
# restore shape
|
|
113
114
|
if n_dim == 1 and n == 1:
|
|
@@ -33,10 +33,10 @@ def adjustAxes(axs:Axes|Iterable[Axes], format:Literal['paper','poster']='paper'
|
|
|
33
33
|
lw = 0.6 if format == 'paper' else 2
|
|
34
34
|
ax_title_fs = 7 if format == 'paper' else 18
|
|
35
35
|
ax_label_fs = 7 if format == 'paper' else 18
|
|
36
|
-
ax_label_pad =
|
|
37
|
-
ax_tick_fs =
|
|
36
|
+
ax_label_pad = 1 if format == 'paper' else 1
|
|
37
|
+
ax_tick_fs = 5 if format == 'paper' else 14
|
|
38
38
|
ax_tick_l = 2 if format == 'paper' else 5
|
|
39
|
-
ax_tick_pad =
|
|
39
|
+
ax_tick_pad = 2 if format == 'paper' else 2
|
|
40
40
|
|
|
41
41
|
for ax in axs:
|
|
42
42
|
|
|
@@ -266,7 +266,8 @@ def plotColorMap(data:ArrayLike, vmin:float=None, vmax:float=None, zscore=None,
|
|
|
266
266
|
smooth float | (float,float) = None, standard deviation of gaussian kernel passed to ``scipy.ndimage.gaussian_filter`` (after zoom)
|
|
267
267
|
alpha float | (n,m) float = None, transparency mask for `data` (e.g., to show significance of pixels), values must be in [0,1]
|
|
268
268
|
x, y (:,) float, coordinates corresponding to columns and rows of `data`, defaults are range(m) and range(n)
|
|
269
|
-
aspect str | float | None, same behavior as aspect parameter of imshow
|
|
269
|
+
aspect str | float | None, same behavior as aspect parameter of imshow, 'auto' to keep axis aspect ration,
|
|
270
|
+
'preserve' to keep it even when a colorbar is drawn
|
|
270
271
|
bar str = None, if given, draw colorbar next to `ax` with label specified by `bar`, and return both `im` and `cb` objects
|
|
271
272
|
barticks (:,) float, if given, draw colorbar next to `ax` with ticks specified by `barticks`, and return both `im` and `cb` objects
|
|
272
273
|
ax matplotlib.axes.Axes = matplotlib.pyplot.gca(), axes to plot in
|
|
@@ -276,7 +277,10 @@ def plotColorMap(data:ArrayLike, vmin:float=None, vmax:float=None, zscore=None,
|
|
|
276
277
|
cb colorbar, optional
|
|
277
278
|
"""
|
|
278
279
|
|
|
279
|
-
data = np.array(data,ndmin=2)
|
|
280
|
+
data = np.array(data, ndmin=2)
|
|
281
|
+
if ax is None:
|
|
282
|
+
ax = plt.gca()
|
|
283
|
+
bb = ax.get_position()
|
|
280
284
|
|
|
281
285
|
# 1. z-score
|
|
282
286
|
if zscore is not None:
|
|
@@ -323,9 +327,9 @@ def plotColorMap(data:ArrayLike, vmin:float=None, vmax:float=None, zscore=None,
|
|
|
323
327
|
dy = 0.5
|
|
324
328
|
else:
|
|
325
329
|
dy = 0.5 if n_y == 1 else (y[-1] - y[0]) / (data.shape[0] - 1) / 2
|
|
326
|
-
if ax is None:
|
|
327
|
-
ax = plt.gca()
|
|
328
330
|
|
|
331
|
+
restore = aspect == 'preserve'
|
|
332
|
+
if restore: aspect = 'auto'
|
|
329
333
|
im = ax.imshow(data, aspect=aspect, vmin=vmin, vmax=vmax, origin='lower', extent=[x[0]-dx, x[-1]+dx, y[0]-dy, y[-1]+dy], **kwargs)
|
|
330
334
|
if alpha is not None:
|
|
331
335
|
im.set_alpha(alpha)
|
|
@@ -333,6 +337,8 @@ def plotColorMap(data:ArrayLike, vmin:float=None, vmax:float=None, zscore=None,
|
|
|
333
337
|
cb = plt.colorbar(im, label=bar, ticks=barticks, ax=ax)
|
|
334
338
|
cb.set_label(bar)
|
|
335
339
|
adjustAxes(cb.ax)
|
|
340
|
+
if restore:
|
|
341
|
+
ax.set_position(bb) # restore position (modified by plt.colorbar)
|
|
336
342
|
|
|
337
343
|
# plot peaks
|
|
338
344
|
if isinstance(sortby,str) and sortby == 'peak-show':
|
|
@@ -555,7 +561,7 @@ def boxPlot(data:ArrayLike|Sequence[ArrayLike], x:ArrayLike=None, mode:Literal['
|
|
|
555
561
|
for col in color:
|
|
556
562
|
r, g, b, a = mplc.to_rgba(col)
|
|
557
563
|
facecolor.append((r,g,b,a*0.5))
|
|
558
|
-
kwargs.setdefault('widths',
|
|
564
|
+
kwargs.setdefault('widths', 1)
|
|
559
565
|
vp = ax.violinplot(data_clean, positions=x, side='high', facecolor=facecolor, linecolor=color,
|
|
560
566
|
showmedians=True, showextrema=False, **kwargs)
|
|
561
567
|
out.append(vp)
|
|
@@ -656,7 +662,7 @@ def pBar(p:ArrayLike, x:ArrayLike=None, alpha:float=None, dy:float=None, draw:Se
|
|
|
656
662
|
def pHorzLine(p, t=None, dy=None, color:ColorType=None, ax:Axes=None, **kwargs):
|
|
657
663
|
"""draw a horizontal line indicating time points where time series passed a statistical test
|
|
658
664
|
|
|
659
|
-
|
|
665
|
+
Args:
|
|
660
666
|
p (t,c) bool, decision of a statistical test, t: number of time points, c: number of conditions
|
|
661
667
|
t (t,) float = range(n), time points
|
|
662
668
|
dy float, scale vertical distances between bars
|
|
@@ -695,7 +701,7 @@ def pHorzLine(p, t=None, dy=None, color:ColorType=None, ax:Axes=None, **kwargs):
|
|
|
695
701
|
|
|
696
702
|
def plotIntervals(intervals, color:ColorType='gray', alpha=0.3, label:str=None, ax:Axes=None, **plot_kwargs):
|
|
697
703
|
|
|
698
|
-
intervals = fmatoolbox.intervals.
|
|
704
|
+
intervals = fmatoolbox.intervals.consolidate(intervals)
|
|
699
705
|
if intervals.size == 0:
|
|
700
706
|
return
|
|
701
707
|
if ax is None:
|
|
@@ -574,7 +574,7 @@ class regions:
|
|
|
574
574
|
|
|
575
575
|
|
|
576
576
|
def avalanches(self, regs=None, when=None, thresh:float=None, bin_mode:Literal['fixed','isi']=None, window:float=None, step:int=None,
|
|
577
|
-
shift:bool=None, smooth:
|
|
577
|
+
shift:bool=None, smooth:float=None, norm:bool=None, return_fr:bool=None):
|
|
578
578
|
"""compute avalanches per region from population firing rate
|
|
579
579
|
|
|
580
580
|
arguments:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|