Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 894de55

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

1 file changed

+35Lines changed: 35 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎fastplotlib/utils/functions.py‎

Copy file name to clipboardExpand all lines: fastplotlib/utils/functions.py
+35Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.