Skip to content

Instantly share code, notes, and snippets.

Created Feb 15, 2019
What would you like to do?
Heatmaps with Dask, Holoviews and Datashader
import time
import datashader as ds
import pandas as pd
import numpy as np
import holoviews as hv
from holoviews import opts
from colorcet import fire
from datashader import transfer_functions as tf
from dask import dataframe as dd
import multiprocessing
from holoviews.operation.datashader import datashade, shade, dynspread, rasterize
from holoviews.operation import decimate
from holoviews import opts
print("Loading data..")
df = pd.read_csv('./data/DANIO_RERIO.tsv', sep='\t', header=0, index_col=0, error_bad_lines=False)
print("Data loaded..")
print("Converted to Dask..")
dask_df = dd.from_pandas(df, npartitions=multiprocessing.cpu_count()).persist()
print("To Dask Array..")
da = dask_df.to_dask_array(True).persist()
# Output resolution. Bokeh doesn't like very much more than this, try matplotlib
x_size = 1000
y_size = 1000
num_genes, num_samples = df.shape
print("To Image..")
img = hv.Image((np.arange(num_samples), np.arange(num_genes), da))
rasterized_img = rasterize(img, width=x_size, height=y_size)
rasterized_img.opts(width=x_size, height=y_size, cmap='viridis', logz=True)
# You have two options, bokeh requires selenium and phantomjs for png export, if you have those you can do
#, 'test.png')
# or you could use the matplotlib backend using
#, 'test.png', backend='matplotlib'), "rasterized" + str(time.time()) + ".png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment