Skip to content

Commit 894de55

Browse files
committed
add helper function to convert heatmap timeseries to postional data shape
1 parent 3e755f6 commit 894de55

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

fastplotlib/utils/functions.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,3 +477,38 @@ def subsample_array(
477477
slices = tuple(slices)
478478

479479
return np.asarray(arr[slices])
480+
481+
482+
def heatmap_to_positions(heatmap: np.ndarray, xvals: np.ndarray) -> np.ndarray:
483+
"""
484+
485+
Convert a heatmap of shape [n_rows, n_datapoints] to timeseries x-y data of shape [n_rows, n_datapoints, xy]
486+
487+
Parameters
488+
----------
489+
heatmap: np.ndarray, shape [n_rows, n_datapoints]
490+
timeseries data with a heatmap representation, where each column represents a timepoint.
491+
492+
xvals: np.ndarray, shape: [n_datapoints,]
493+
x-values for the columns in the heatmap
494+
495+
Returns
496+
-------
497+
np.ndarray, shape [n_rows, n_datapoints, 2]
498+
timeseries data where the xy data are explicitly stored for every row
499+
500+
"""
501+
if heatmap.ndim != 2:
502+
raise ValueError
503+
504+
if xvals.ndim != 1:
505+
raise ValueError
506+
507+
if xvals.size != heatmap.shape[1]:
508+
raise ValueError
509+
510+
ts = np.empty((*heatmap.shape, 2), dtype=np.float32)
511+
ts[..., 0] = xvals
512+
ts[..., 1] = heatmap
513+
514+
return ts

0 commit comments

Comments
 (0)