Skip to content

Instantly share code, notes, and snippets.

View huangziwei's full-sized avatar

Ziwei Huang huangziwei

View GitHub Profile
import zipfile
zout = zipfile.ZipFile('nmf.zip', "w", zipfile.ZIP_DEFLATED) # <--- this is the change you need to make
zout.write('nmf.h5')
zout.close()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@huangziwei
huangziwei / csv_to_xlsx
Created August 20, 2018 12:53
convert *.csv to *.xlsx
soffice --headless --convert-to xlsx:"Calc MS Excel 2007 XML" *.csv --outdir <output folder>
@huangziwei
huangziwei / install_neuron.sh
Last active August 6, 2018 12:24
bashs script for installing NEURON simulator on docker/Ubuntu 16.04 with Python
#!/bin/bash
apt-get update
apt-get upgrade -y
apt-get install -y autoconf libtool libxext-dev libncurses5-dev bison flex apt-utils wget
cd $HOME
git clone https://github.com/nrnhines/nrn
cd nrn
./build.sh
./configure --prefix=`pwd` --with-nrnpython=/usr/bin/python3 --without-iv
@huangziwei
huangziwei / install_NEURON.sh
Created November 7, 2017 11:41
install NEURON with python3
#!/bin/bash
sudo apt-get update
sudo apt-get install -y libxext-dev libncurses5-dev autoconf libtool bison flex
cd ~
git clone https://github.com/nrnhines/nrn
cd nrn
./build.sh
./configure --prefix=`pwd` --with-nrnpython=python3 --without-iv
@huangziwei
huangziwei / unique_row.py
Created October 23, 2017 13:10
find unique_row in numpy.array
def unique_row(a):
b = np.ascontiguousarray(a).view(np.dtype((np.void, a.dtype.itemsize * a.shape[1])))
_, idx = np.unique(b, return_index=True)
unique_a = a[idx]
return unique_a
@huangziwei
huangziwei / port-r-func.py
Last active August 23, 2017 14:03
porting some some R functions to python
def lfactorial(n):
from scipy.special import gammaln
return gammaln(n+1)
def lchoose(n, k):
from scipy.special import gammaln
#!/bin/bash
git clone https://github.com/pyenv/pyenv .pyenv
echo 'export PYENV_ROOT="/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
exec $SHELL
pyenv install miniconda3-latest
pyenv shell miniconda3-latest
conda install numpy scipy jupyter matplotlib scikit-learn
@huangziwei
huangziwei / roi_func.py
Created May 9, 2017 12:41
some functions for roi detection
def load_h5_data(file_name):
with h5py.File(file_name,'r') as f:
return {key:f[key][:] for key in list(f.keys())}
def detect_soma_centroid(M):
"""
detect the coordinate of soma on stack image.
Return
@huangziwei
huangziwei / rois_rot.py
Created May 2, 2017 15:42
rotate coordinates of rois
def rotate_roi(d):
ang_deg = d['wParamsNum'][31] # ratoate angle (degree)
ang_rad = ang_deg * np.pi / 180 # ratoate angle (radian)
d_rois = d['ROIs']
d_rois_rot = scipy.ndimage.interpolation.rotate(d_rois, ang_deg)
(shift_x, shift_y) = 0.5 * (np.array(d_rois_rot.shape) - np.array(d_rois.shape))
(cx, cy) = 0.5 * np.array(d_rois.shape)