Skip to content

Instantly share code, notes, and snippets.

View KedoKudo's full-sized avatar

Chen Zhang KedoKudo

View GitHub Profile
@KedoKudo
KedoKudo / install_petsc.sh
Created January 28, 2020 19:07
installation script of PETSC for DAMASK on MacOSX
#!/bin/bash
echo "Build PTESC from scratch (for Mac OS)"
echo "-----"
echo "note:"
echo " require customized HDF5 (run '>> ./install_HDF5.sh ')"
echo " require open-mpi from hombrew(run '>> brew install openmpi')"
echo " require cmake from hombrew(run '>> brew install cmake ')"
echo " use system python (2.7) for the configure step"
echo
@KedoKudo
KedoKudo / install_HDF5.sh
Created January 28, 2020 19:06
Install script of HDF5 for DAMASK on MacOSX
#!/bin/bash
echo "Build HDF5 from scratch (for Mac OS)"
echo "-----"
echo "note:"
echo " require open-mpi from hombrew(run '>> brew install openmpi')"
echo
PREFIX=$HOME/opt
VERSION=1.10.5
import net.imglib2.img.display.imagej.*;
import org.janelia.saalfeldlab.n5.*;
import org.janelia.saalfeldlab.n5.hdf5.*;
import org.janelia.saalfeldlab.n5.imglib2.*;
n5 = new N5HDF5Reader("/Users/chenzhang/tmp/tomoproc_test/ss304.h5");
img = N5Utils.open(n5, "/exchange/data");
ImageJFunctions.show(img);
@KedoKudo
KedoKudo / ipywidgets_demo.py
Created July 25, 2019 22:29
ipywidgets_demo.py
import ipywidgets as widgets
# dynamic view of proj
@widgets.interact(n=(0, proj.shape[0]-1), cmap=['gray', 'jet'], vmin=(0,65535), vmax=(0,65535))
def peekimg(n, cmap, vmin=0, vmax=20000, showcnr=True):
fig, axes = plt.subplots(figsize=(10,10))
img = proj[n,:,:]
axes.imshow(img, cmap=cmap, vmin=vmin, vmax=vmax)
if showcnr:
#perform histogram equalization with numpy, without explicitly computing the histogram
#im is a numpy array, of any dimension
im2 = numpy.sort(im.ravel()).searchsorted(im)
@KedoKudo
KedoKudo / singleton.py
Created February 10, 2017 15:22
easy singleton in python
# use class attributes to link all instance as one
class Borg:
__shared_states = {}
def __init__(self):
self.__dict__ = self.__shared_states
@KedoKudo
KedoKudo / demo_threading.py
Created February 9, 2017 22:31
simple demo for using threading in python
import threading
def myfunc(x):
return x**2
t1 = threading.Thread(traget=myfunc, args=range(10))
t1.start()
@KedoKudo
KedoKudo / constant.py
Last active February 9, 2017 18:44
python constant def
class _const:
class ConstError(TypeError):
pass
class ConstCaseError(ConstError):
pass
def __setattr__(self, name, value):
if self.__dict__.has_key(name):
raise self.ConstError, "can't change constant"
@KedoKudo
KedoKudo / gist:9242084e56eed90af8f1f18b233f0992
Created January 3, 2017 16:10
clean mac index file from git repository
# FROM the mighty stackoverflow
# remove any existing files from the repo, skipping over ones not in repo
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
# specify a global exclusion list
git config --global core.excludesfile ~/.gitignore
# adding .DS_Store to that list
echo .DS_Store >> ~/.gitignore
@KedoKudo
KedoKudo / kmeans.pyx
Last active August 29, 2015 14:26 — forked from dwf/kmeans.pyx
Parallelized k-means in Cython.
"""
Parallelized k-means module.
By David Warde-Farley, February 2012. Licensed under the 3-clause BSD.
"""
cimport cython
from cython.parallel import prange
import numpy as np
cimport numpy as np
from numpy.random import normal