Skip to content

Instantly share code, notes, and snippets.

@ZGainsforth
Created August 14, 2021 02:49
Show Gist options
  • Save ZGainsforth/5bc18b88f2d66437de41887716108d63 to your computer and use it in GitHub Desktop.
Save ZGainsforth/5bc18b88f2d66437de41887716108d63 to your computer and use it in GitHub Desktop.
A simple script to plot some STXM spectra for comparison.
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import medfilt, convolve
from scipy.signal.windows import gaussian
import os, sys
STXMPath = os.path.join("..", "210628", "NS_210628066 Fe-L", "Spectra")
PtychoPath = os.path.join("..", "210629", "NS_210629000 - Fe-L ptycho", "Spectra Abs")
SpectraFiles = {"3+ inclusion (ptycho)": os.path.join(PtychoPath, "3+ inclusion.txt"),
"Kosmo1 CPX (STXM)": os.path.join(STXMPath, "Top CPX.txt"),
"Kosmo2 CPX (ptycho)": os.path.join(PtychoPath, "Bottom KosmoCPX.txt"),
"OPX1 (STXM)": os.path.join(STXMPath, "OPX.txt"),
"OPX1 rim (ptycho)": os.path.join(PtychoPath, "OPX rim.txt"),
"Fe-rich CPX (STXM)": os.path.join(STXMPath, "Fe-rich.txt"),
"K-rich (STXM)": os.path.join(STXMPath, "K-rich.txt"),
"Sulfide (STXM)": os.path.join(STXMPath, "Sulfide.txt")}
SpectraColors = {"3+ inclusion (ptycho)": "black",
"Kosmo1 CPX (STXM)": "darkturquoise",
"Kosmo2 CPX (ptycho)": "teal",
"OPX1 (STXM)": "limegreen",
"OPX1 rim (ptycho)": "forestgreen",
"Fe-rich CPX (STXM)": "firebrick",
"K-rich (STXM)": "royalblue",
"Sulfide (STXM)": "gold"}
Spectra = dict()
for Name, FileName in SpectraFiles.items():
Spectra[Name] = np.genfromtxt(FileName)
def NormMe(I):
I -= np.min(I)
I /= np.max(I)
return I
def SubtractPreEdge(S):
MaxInd = np.argmin(np.abs(S[:,0]-703.0))
Pline = np.polyfit(S[:MaxInd,0], S[:MaxInd,1], 1)
Bkg = Pline[0]*S[:,0] + Pline[1]
S[:,1] -= Bkg
return S
def Preprocess(S):
S[:,1] = NormMe(S[:,1])
S = SubtractPreEdge(S)
# k = gaussian(9, 2)
# print(k)
# S[:,1] = convolve(S[:,1], k, mode='same')
# S[:,1] = medfilt(S[:,1], [0.25, 0.5, 0.25])
return S
plt.figure()
Offset = 0
for Name, S in Spectra.items():
Sprime = Preprocess(S)
plt.plot(S[:,0], Sprime[:,1]+Offset, label=Name, color=SpectraColors[Name])
Offset -= 0.5
plt.xlabel("eV")
plt.ylabel("OD (arb)")
plt.xlim(695,730)
plt.legend(bbox_to_anchor=(1,0.5))
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment