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 / PlotBrukerSpectrum.py
Created April 5, 2016 18:13
Plots a Bruker text spectrum from the command line.
#!/usr/bin/env python
# Created 2015, Zack Gainsforth
import sys
if (len(sys.argv) < 2) or (sys.argv[1] in ['-h', '--help', '-?']):
print "Usage is:\nPlotBrukerSpectrum.py filename.txt\nWhere filename.txt is the text output version of the spectrum output by Bruker's Esprit software."
quit()
import matplotlib.pyplot as plt
import numpy as np
@ZGainsforth
ZGainsforth / GetChunkFromTextFile.py
Last active October 23, 2016 06:23
Python function for getting data out of vast complicated heterogeneous log files such as produced by MELTS or VASP. You just give it the file name, start and stop strings, and it does all the footwork with regex. Can also automatically turn the chunk into a numpy array.
import numpy as np
import re
from StringIO import StringIO
def GetChunkFromTextFile(FileName, StartStr, StopStr, skip_header=0, skip_footer=0, LastHit=True, DataType='array'):
# DataType means we can extract the chunk and then turn it into:
# 1) Numpy table 'numpy'
# 2) return the raw text 'raw'
DataType = DataType.lower()
@ZGainsforth
ZGainsforth / 7z.txt
Created July 13, 2016 18:35
7z example
7z a -mx3 -mmt CoupledSubsOctTetB.7z CoupledSubsOctTetB
mx3 is fast compression, but not super fast.
mmt enables multithreading.
@ZGainsforth
ZGainsforth / fitykfuncs.txt
Last active April 18, 2017 07:00
fityk additional functions
fluoredge:
FluorEdge(height=~1, width=~1, center=~0, offset=avgy) = -height/pi*atan((x-center)/width)+offset
FluorEdge(height=avgy, width=~1, center=~0) = -height/pi*atan((x-center)/width)+(height/2)
@ZGainsforth
ZGainsforth / tar.txt
Created December 5, 2016 23:29
Taring files on linux
taring files on linux with exclusions.
tar --exclude='CHG*' --exclude='LOCPOT' --exclude='WAVECAR' -cvzf Tr900.IBRION2.tar.gz Tr900.IBRION2/
@ZGainsforth
ZGainsforth / MakeLatexTable.py
Created February 16, 2017 19:53
Read in stoichout files from stoichiometry fitter, process them and produce a LaTeX table for publication based on the data.
# coding: utf-8
# In[1]:
# Created 2017, Zack Gainsforth
get_ipython().magic('pylab qt')
import sys, os
import QuickPlot
import matplotlib.pylab as pylab
@ZGainsforth
ZGainsforth / BinArray.py
Created June 3, 2017 08:01
Bin a numpy array in python
def BinArray(S, bin=2):
Sbin = S.reshape((16, int(S.shape[1]/bin), bin, int(S.shape[2]/bin), bin)).sum(axis=4).sum(axis=2)
print('Binned Array Shape = ', Sbin.shape)
imshow(Sbin[Mg_K])
colorbar()
print('Al-K map mean: ', np.mean(Sbin[Al_K]), ', Al-K map max:', np.max(Sbin[Al_K]))
return Sbin
@ZGainsforth
ZGainsforth / BackgroundSubtractSulfideAndTaenite.ipynb
Last active June 23, 2017 18:22
Subtract background two backgrounds from a spectrum
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / BackgroundSubtractSpectra.ipynb
Last active July 12, 2017 18:57
Background subtract one background from a spectrum.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ZGainsforth
ZGainsforth / GetFluxSpectra.sh
Created June 29, 2017 22:36
Process a directory of TGCat Chandra spectra to produce flux spectra from MEG -1 and MEG +1
#!/bin/bash
# Load all the chandra data processing tools.
#ciao
# Note this script must already have run ciao
# For each subdirectory, run the sherpa script to extract flux spectra.
for onedir in $(ls -d */); do
cd $onedir
echo $onedir