Created
November 8, 2021 22:33
-
-
Save ZGainsforth/9c3f67fdd748129cc11f372c179d3339 to your computer and use it in GitHub Desktop.
Draw a spectrum and compare it against another. Using streamlit enable rescaling, shifting and gaussian convolution of spectra.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
Iinterp = interp1d(Eraw, Iraw)(E) | |
SigmaPx = Sigma / 2.3548 / dE | |
ISmooth = gaussian_filter1d(Iinterp, SigmaPx) | |
return E, ISmooth | |
s = np.genfromtxt(f'{sys.argv[1]}.out.socabs.dat') | |
# a = np.genfromtxt('Fe.out.socabs.dat') | |
a = np.genfromtxt('Ferrocene_experimental.csv', delimiter=',') | |
a[:,1] -= np.min(a[:,1]) | |
a[:,1] /= np.max(a[:,1]) | |
a[:,1] *= np.max(s[:,1]) | |
scalefac = st.slider('Multiply theory energy axis by:', 0.95, 1.05, 1.00, 0.0001) | |
addfac = st.slider('Add eV to theory energy axis by:', -40.0, 40.0, 10.7, 0.1) | |
sigmafac = st.slider('Convolve spectra with Gaussian (sigma eV):', 1.0, 3.0, 0.0, 0.1) | |
if sigmafac > 0: | |
Estandard, Istandard = ConvolveGaussian(a[:,0], a[:,1], sigmafac) | |
E, Iiso = ConvolveGaussian(s[:,0], s[:,1], sigmafac) | |
E, Ix = ConvolveGaussian(s[:,0], s[:,1], sigmafac) | |
E, Iy = ConvolveGaussian(s[:,0], s[:,1], sigmafac) | |
E, Iz = ConvolveGaussian(s[:,0], s[:,1], sigmafac) | |
else: | |
Estandard, Istandard = a[:,0], a[:,1] | |
E, Iiso, Ix, Iy, Iz = s[:,0], s[:,1], s[:,2], s[:,3], s[:,4] | |
fig = plt.figure() | |
# plt.plot(a[:,0], a[:,1], label='Fe (theory)') | |
# plt.plot(s[:,0]*scalefac+addfac, s[:,1], label='DFT/ROCIS isotropic') | |
# plt.plot(s[:,0]*scalefac+addfac, s[:,2], label='DFT/ROCIS x') | |
# plt.plot(s[:,0]*scalefac+addfac, s[:,3], label='DFT/ROCIS y') | |
# plt.plot(s[:,0]*scalefac+addfac, s[:,4], label='DFT/ROCIS z') | |
plt.plot(Estandard, Istandard, label=f'Ferrocene experimental\n$\sigma$ = {sigmafac}') | |
plt.plot(E*scalefac+addfac, Iiso, label=f'DFT/ROCIS isotropic\nShift = {addfac:+0.1f} eV\n$\sigma$ = {sigmafac}') | |
# plt.xlim(700,730) | |
plt.xlabel('eV') | |
plt.ylabel('A.U') | |
plt.legend() | |
plt.savefig(f'{sys.argv[1]} comparison.png', dpi=300) | |
st.write(fig) | |
if st.button("rerun"): | |
st.experimental_rerun() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment