Skip to content

Instantly share code, notes, and snippets.

View ZGainsforth's full-sized avatar

Zack Gainsforth ZGainsforth

  • University of California at Berkeley
  • Los Angeles, CA, USA
View GitHub Profile
@ZGainsforth
ZGainsforth / EELSFuncs.py
Last active September 7, 2017 23:20
Remove outlier data points from an EELS spectrum by doing a LOWESS fit and then keeping only spots within a specific median sigma.
%pylab inline
import hyperspy.api as hs
from statsmodels.nonparametric.smoothers_lowess import lowess
def DespikeEELS(spec, m=3., interp_outliers=True):
# Make a copy of the data
E = spec.axes_manager[0].axis.copy()
I = spec.data.copy()
# Lowess smooth.
@ZGainsforth
ZGainsforth / Extract EDS tomo data.ipynb
Last active June 20, 2018 19:20
Quick and dirty way to read EDS info out from an EDS tilt series of Bruker stacks and place the maps into tilt stacks for tomographic reconstruction.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / MakeRGBFromMaps.py
Last active November 8, 2017 03:26
Make an RGB from three hyperspy maps.
from skimage.exposure import rescale_intensity, equalize_hist
def MakeRGBFromMaps(R,G,B, bits=16):
MaxPixelVal = (2**bits)-1
# Make a Signal2D from the three images and copy over the metadata.
x = hs.stack([R,G,B])
x = hs.signals.Signal2D(x).T
x.metadata = R.metadata
x.original_metadata = R.original_metadata
@ZGainsforth
ZGainsforth / Plot Bruker Stack.ipynb
Last active April 13, 2022 03:29
Read a Bruker bcf file into hyperspy, browse, plot maps of the elements, and make RGBs.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / .vimrc
Last active February 6, 2019 05:08
.vimrc file
" Vundle install
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
@ZGainsforth
ZGainsforth / 2bin.py
Created April 19, 2018 22:36
Bin a 3D npy array for tomography
import numpy as np
import sys
if len(sys.argv) < 3:
print('Command line format:\npython 2bin.py stackin.npy stackout.npy')
sys.exit()
s = np.load(sys.argv[1])
if len(s.shape) != 3:
print('Input npy stack needs to have a shape like (x, y, frames).')
@ZGainsforth
ZGainsforth / .tmux.conf
Last active May 24, 2018 03:24
tmux configuration file.
#.tmux.conf
# Make mouse useful in copy mode
set -g mode-mouse on
set -g mouse-select-window on
set -g mouse-select-pane on
set -g mouse-resize-pane on
@ZGainsforth
ZGainsforth / tmuxme
Created May 10, 2018 04:39
A shell script to get a useful tmux triple screen
#!/bin/bash
tmux new-session -d -s ZackG
tmux new-window -t ZackG:1 -n 'lrc'
tmux send-keys "watch 'sacct --format JobID,jobname%20,NCPUS,State,Submit,AveRSS,CPUTime,Elapsed,TimeLimit,NodeList | tac'" C-m
tmux split-window -h -t lrc
tmux select-pane -t 0
tmux split-window -v -t lrc
tmux select-pane -t 2
tmux attach-session -t ZackG
@ZGainsforth
ZGainsforth / EELS ZLP and core loss single spectra as OD analysis.ipynb
Created July 18, 2018 07:07
Read EELS core loss, align to ZLP, deconvolve, plot, save.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.