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 / NanoIRCSVToStack.py
Last active October 5, 2021 19:08
Convert NanoIR stack of CSV files into a TIFF stack including background subtraction.
import numpy as np
# from skimage.external.tifffile import imsave
from skimage.io import imsave
import os
import matplotlib.pyplot as plt
# The start and end cm-1 values of the stack as well as the number of images. To know these look inside the ais file exported from the stack acquisition.
Startcm = 1300
Stopcm = 1372
Stepscm =13
#!/bin/zsh
source loadmyorca
orca Fe.inp | tee Fe.out
orca_mapspc Fe.out SOCABS -eV -x0700 -x1740 -n500 -w0.5
# streamlit run DrawSpec.py
@ZGainsforth
ZGainsforth / Quantum Espresso Troubleshooting.md
Last active October 3, 2020 00:38
Quantum Espresso Troubleshooting

Convergence going the wrong way

  • Check unit cell shape.
  • Check bohr vs angstrom units.
  • Are ecutwfc, ecutrho too low?
  • Not enough kpoints?
  • Reduce mixing beta.
  • Try cg instead of david convergence algorithm.

XSPECTRA Pre-calculation checklist

  • smearing in case excited state closes the band gap?
@ZGainsforth
ZGainsforth / ExtractPtychoData.py
Last active August 24, 2020 19:49
Find all the cxi images in a directory (ptycho images) and extract tifs for the absorption and dispersion images.
import h5py as h5
import glob2 as glob
from imageio import imsave
import numpy as np
import os
import plotly.express as px
import streamlit as st
def ExtractOnePtychoImage(FileName):
d = h5.File(FileName, 'r')
@ZGainsforth
ZGainsforth / Eigenenergies from Wannier90.ipynb
Created August 17, 2020 21:00
Read a Wannier90 hr.dat output file and get eigenenergies.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / MakeKMeansPhases.py
Created August 15, 2020 04:45
Segment a 3D cube (EDS tomography) into phases using KMeans.
import numpy as np
from genfire.fileio import readMRC, writeMRC
from sklearn.cluster import KMeans
Els = ['Fe', 'Mg', 'S', 'O', 'Si']
Cubes = []
for El in Els:
ThisCube = readMRC(El+'_reconstruction_cropped.mrc')
# ThisCube -= np.min(ThisCube)
@ZGainsforth
ZGainsforth / GitCommands.md
Last active July 19, 2022 18:36
Common Git commands

Force pull

git fetch --all

git reset --hard origin/master

Remote settings

git remote -v # Verbose display of the remote.

@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.
@ZGainsforth
ZGainsforth / Fit Bruker kfactors from map.ipynb
Last active May 15, 2020 20:57
Using an EDS map of a standard, calculate k-factors from it by fitting the slopes of element ratios.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / DaskMinimum.py
Created May 7, 2020 21:49
A moderately simple Dask minimum template which includes sending a large chunk of input data to clients, sending code to clients, and putting together a multidimensional output from the results.
import numpy as np
import matplotlib.pyplot as plt
from dask.distributed import Client, wait, as_completed
# We are going to use dask to produce a 2D output based on 3D input data that is relatively large and must be distributed in advance.
# For dask to work we need the "hard work" to be in a single function call.
def CalcOneElement(x, y, Full):
print(f'{y} of {Full.shape[1]}, {x} of {Full.shape[2]}', end='\r')