Skip to content

Instantly share code, notes, and snippets.

View d-v-b's full-sized avatar
💭
status

Davis Bennett d-v-b

💭
status
  • Independent software engineer
  • Würzburg, Germany
  • 12:10 (UTC +02:00)
View GitHub Profile
def projFigure(vol, limits, plDims=[16,10,5], zscale=5, colors='gray',title=None):
x,y,z = plDims
grid = (y+z,x+z)
zRat = zscale*(float(y)/z)
plt.figure(figsize=grid[-1::-1])
# plot the x-y view (top-down)
ax1 = plt.subplot2grid(grid,(0,0),rowspan=y,colspan=x)
plt.imshow(vol.max(0) + vol.min(0),clim=limits,cmap=colors,origin='leftcorner',interpolation='Nearest')
from numpy import where,array,meshgrid, vstack
from matplotlib.path import Path
def getInteriorPoints(coords):
"""
Given a list of pairs of points which define a polygon, return a list of pairs of points interior to the polygon
"""
bounds = array(coords).astype('int')
bMax = bounds.max(0)
Done saving /tier2/ahrens/davis/data/spark/20150217/7dpf_gfap_gc6f_misha_omr_photo_20150217_202934/mat/mxProj_z_2-9
15/02/25 20:20:50 ERROR TaskSchedulerImpl: Lost executor 0 on h05u09.int.janelia.org: remote Akka client disassociated
15/02/25 20:20:50 ERROR SparkDeploySchedulerBackend: Asked to remove non-existent executor 0
15/02/25 20:20:50 ERROR SparkDeploySchedulerBackend: Asked to remove non-existent executor 0
15/02/25 20:21:36 ERROR TaskSchedulerImpl: Lost executor 1 on h07u27.int.janelia.org: remote Akka client disassociated
15/02/25 20:21:36 ERROR SparkDeploySchedulerBackend: Asked to remove non-existent executor 1
15/02/25 20:21:36 ERROR SparkDeploySchedulerBackend: Asked to remove non-existent executor 1
15/02/25 20:34:20 ERROR TaskSetManager: Task 10634 in stage 56.0 failed 4 times; aborting job
---------------------------------------------------------------------------
Py4JJavaError Traceback (most recent call last)
@d-v-b
d-v-b / compression_decompression.py
Created August 8, 2015 22:04
compression and decompression
def bz2compress(raw_fname, wipe=False, overwrite=False):
"""
:param raw_fname: string, full path of file to be compressed
:param wipe: bool, optional. If set to True, raw file will be deleted after compression. Defaults to False.
:param overwrite: bool, optional. If set to True, overwrites file sharing name of output file. Defaults to False
:return:
"""
import bz2
import os
@d-v-b
d-v-b / all_mpl_cmaps.py
Created October 3, 2015 21:36
plot an image with all matplotlib cmaps
# test all matplotlib colormaps for a given image
# the image to plot
toPlot = vol[-1]
fName = '/Users/bennettd/Dropbox/media/imag/all_mpl_cmaps.png'
cmaps = 'Spectral, summer, coolwarm, Wistia_r, pink_r, Set1, Set2, Set3, brg_r, Dark2, prism, PuOr_r, afmhot_r, terrain_r, PuBuGn_r, RdPu, gist_ncar_r, gist_yarg_r, Dark2_r, YlGnBu, RdYlBu, hot_r, gist_rainbow_r, gist_stern, PuBu_r, cool_r, cool, gray, copper_r, Greens_r, GnBu, gist_ncar, spring_r, gist_rainbow, gist_heat_r, Wistia, OrRd_r, CMRmap, bone, gist_stern_r, RdYlGn, Pastel2_r, spring, terrain, YlOrRd_r, Set2_r, winter_r, PuBu, RdGy_r, spectral, rainbow, flag_r, jet_r, RdPu_r, gist_yarg, BuGn, Paired_r, hsv_r, bwr, cubehelix, Greens, PRGn, gist_heat, spectral_r, Paired, hsv, Oranges_r, prism_r, Pastel2, Pastel1_r, Pastel1, gray_r, jet, Spectral_r, gnuplot2_r, gist_earth, YlGnBu_r, copper, gist_earth_r, Set3_r, OrRd, gnuplot_r, ocean_r, brg, gnuplot2, PuRd_r, bone_r, BuPu, Oranges, RdYlGn_r, PiYG, CMRmap_r, YlGn, binary_r, gist_gray_r, Accent, BuPu_r,
@d-v-b
d-v-b / gist:b12e7f820c00ae8807c3
Created November 14, 2015 19:47
dff in thunder
# from thunder/rdds/timeseries.py
# found at https://github.com/thunder-project/thunder/blob/b15ba0a38642312d597a98643cf3514e2d46b69d/thunder/rdds/timeseries.py
def normalize(self, baseline='percentile', window=None, perc=20):
"""
Normalize each time series by subtracting and dividing by a baseline.
Baseline can be derived from a global mean or percentile,
or a smoothed percentile estimated within a rolling window.
Parameters
----------
@d-v-b
d-v-b / gist:59312d23e054bbd0c32a
Created November 14, 2015 19:47
dff in thunder
# from thunder/rdds/timeseries.py
# found at https://github.com/thunder-project/thunder/blob/b15ba0a38642312d597a98643cf3514e2d46b69d/thunder/rdds/timeseries.py
def normalize(self, baseline='percentile', window=None, perc=20):
"""
Normalize each time series by subtracting and dividing by a baseline.
Baseline can be derived from a global mean or percentile,
or a smoothed percentile estimated within a rolling window.
Parameters
----------
# Convert a list of (k,v) pairs into an array
def kvp_to_array(dims, data, ind=0, baseline=0):
vol = np.zeros(dims,dtype=data[0][1].dtype) + np.array(baseline).astype(data[0][1].dtype)
for k,v in data:
# check if data contains a single value or an iterable
if hasattr(v,'__iter__'):
vol[k] = v[ind]
else:
vol[k] = v
import matplotlib.pyplot as plt
from ipywidgets import interact
%matplotlib inline
def browse_images(im):
n = len(im)
def view_image(i):
plt.figure()
plt.imshow(im[i])
plt.show()
%%html
<script>
var code_show=true; //true -> hide code at first
function code_toggle() {
$('div.prompt').hide(); // always hide prompt
if (code_show){
$('div.input').hide();
} else {