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 / Quant Bruker spx.ipynb
Last active March 13, 2024 09:24
Read in a Bruker spx spectrum and do basic TEM quantification to get area under the peaks.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / ExtractSpectrumFromBruker.py
Created March 4, 2022 09:04
Script to manually extract spectra out of a bruker bcf file by using a mask image. Written by Michael and Roger.
#1/5/2022 Michael Ofengenden & Roger Yu & A LOT A LOT of help from Zack Gainsforth
import sys, os
import hyperspy.api as hs
import numpy as np
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
import tifffile as tif
import skimage
from skimage.transform import resize
@ZGainsforth
ZGainsforth / DrawSpec.py
Created November 8, 2021 22:33
Draw a spectrum and compare it against another. Using streamlit enable rescaling, shifting and gaussian convolution of spectra.
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
import os, sys
from scipy.ndimage.filters import gaussian_filter1d
from scipy.interpolate import interp1d
def ConvolveGaussian(Eraw, Iraw, Sigma):
E = np.linspace(Eraw[0], Eraw[-1], 10000)
dE = E[1] - E[0]
@ZGainsforth
ZGainsforth / PlotIR.py
Last active March 13, 2024 09:23
A quick way to plot some IR spectra extracted from a NanoIR stack.
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import medfilt, convolve
from scipy.signal.windows import gaussian
import os, sys
SpectraPath = os.path.join(".")
SpectraFiles = {
"Top Crystal" : os.path.join(SpectraPath, "Top Crystal.txt"),
@ZGainsforth
ZGainsforth / BackgroundSubtractBrukerSpectra.ipynb
Created August 12, 2021 22:36
Subtract the elements from one Bruker quant from another after normalizing one element. Useful for getting the composition of an inclusion or one phase out of a mixed phase where the other phase is known.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / Decomposition on FTIR map.ipynb
Created May 17, 2023 16:57
PCA, ICA, NMF on an FTIR map
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / PlotSPA.ipynb
Created January 27, 2023 02:45
Read Omnic spa files and plot them.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / Eigenenergies from Wannier90.ipynb
Created August 17, 2020 21:00
Read a Wannier90 hr.dat output file and get eigenenergies.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / Compile QE.txt
Last active August 11, 2023 19:02
How to compile quantum espresso on mac or linux.
How to compile quantum espresso on mac or linux.
Disable anaconda during compilation.
On mac install macports version of gnu compilers: gcc-7 and gfortran-7
On linux install gnu compilers.
Install blas, fftw, mpich.
On OS X macports won't overwrite clang. Stupid, but just put the macports compilers earlier in the path.