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 / ReadSPA.py
Last active March 13, 2024 09:23
Read an SPA file from Omnic
# Created 2015, Zack Gainsforth
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import struct
from numpy.fft import fft, fftfreq
def LoadSPAInterferogram(FileName):
# Open the SPA file.
@ZGainsforth
ZGainsforth / main.py
Created September 11, 2015 20:33
PyQt boilerplate
import sys
from PyQt4 import QtGui
from mainwindow import Ui_MainWindow

class Main(QtGui.QMainWindow):
 def __init__(self):
 QtGui.QMainWindow.__init__(self)
 self.ui = Ui_MainWindow()
 self.ui.setupUi(self)

if __name__ == '__main__':
 app = QtGui.QApplication(sys.argv)
 window = Main()
 window.show()
 sys.exit(app.exec_())

@ZGainsforth
ZGainsforth / MakeLRGB.py
Last active February 26, 2020 23:33
Combine an RGB and a luminance image to make an LRGB
# Created 2015, Zack Gainsforth
import matplotlib.pyplot as plt
import numpy as np
from skimage import filters
from skimage.transform import resize
import os, sys
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
import tifffile as tif
@ZGainsforth
ZGainsforth / raise_window.py
Last active February 11, 2016 00:27
Plot matplotlib figures to the foreground.
# Call this just before plt.show()
def raise_window(figname=None):
if figname: plt.figure(figname)
cfm = plt.get_current_fig_manager()
cfm.window.activateWindow()
cfm.window.raise_()
@ZGainsforth
ZGainsforth / PlotUFGTernary.py
Last active February 2, 2016 19:53
Example plotting ternary diagrams in python using image files as source data.
from matplotlib import pyplot
import ternary
import numpy as np
## Boundary and Gridlines
scale = 100
figure, tax = ternary.figure(scale=scale)
# Draw Boundary and Gridlines
tax.boundary(linewidth=2.0)
@ZGainsforth
ZGainsforth / TxtToTif.py
Created January 27, 2016 00:16
IPython script for converting text images to tif images.
%pylab
import tifffile
import glob
f = glob.glob(‘*.tsv’)
for x in f:
n = genfromtxt(x).astype('float32')
tifffile.imsave(x+'.tif', n)
@ZGainsforth
ZGainsforth / CBEDThicknessMeasure.py
Created February 25, 2016 17:43
Get crystal thickness from a 2-beam CBED measurement in a TEM.
# Created 2016, Zack Gainsforth
from __future__ import division
import matplotlib
#matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
import numpy as np
def CBEDThicknessMeasure(lam, d0, r0, dr):
# CBEDThicknessMeasure(lam, d0, r0, dr]
@ZGainsforth
ZGainsforth / FFTSee.ijm
Created March 7, 2016 19:21
ImageJ macro to convert specific FFT peaks to their real space location.
setBackgroundColor(0, 0, 0);
run("Clear Outside");
run("Inverse FFT");
run("Bin...", "x=16 y=16 bin=Max");
run("Enhance Contrast", "saturated=0.35");
@ZGainsforth
ZGainsforth / PhysicsBasics.py
Created March 11, 2016 20:36
Basic constants, functions and values for physics
from __future__ import division
__author__ = 'Zack Gainsforth'
__copyright__ = 'Copyright 2016, Zack Gainsforth'
__email__ = '[email protected]'
#numpy.set_printoptions(threshold=numpy.nan) # Makes arrays print fully when they are large.
from collections import OrderedDict
# Planck's constant [eV-s]
@ZGainsforth
ZGainsforth / ShowLastPos.py
Last active July 20, 2022 23:31
Make plt.show remember the last figure position and plot like last time.
import matplotlib
import matplotlib.pyplot as plt
from numpy import *
import pickle
def ShowLastPosSingleFig(plt):
# Call plt.show but pickles the plot position on window close. When called a second time
# it loads the figure to the last position. So matplotlib now remembers figure positions!
# This version works for QT and WX backends.