Skip to content

Instantly share code, notes, and snippets.

@winston-song
Last active April 21, 2020 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save winston-song/dd74f979f1d54828a2e2c45eebc9e71e to your computer and use it in GitHub Desktop.
Save winston-song/dd74f979f1d54828a2e2c45eebc9e71e to your computer and use it in GitHub Desktop.
Mn L3/L2 white line ratio using gussian component plus H-S step edge
# copyright, this is a modification basing on fit_Zr_whitelines.py https://gist.github.com/thomasaarholt/1098819b9c930a48b3efb48df76a5185. Any copyright should follow this original.
%matplotlib qt
import hyperspy.api as hs
import matplotlib.pyplot as plt
import numpy as np
ll_sum = hs.load('ll_sum.hspy')
s_sum = hs.load('s_sum.hspy')
s_sum.metadata.Acquisition_instrument.TEM.beam_energy=200
s_sum.metadata.Acquisition_instrument.TEM.convergence_angle=22.5
s_sum.metadata.Acquisition_instrument.TEM.Detector.EELS.collection_angle=37.9
s_Mn1 = s_sum.isig[600.:700.].remove_background(signal_range=(600.,630.), fast=False)
s_Mn1.plot()
def fit_Zr_L(sZr, ll=None):
"Returns the model only"
print("Will produce 10 progress bars")
mZr = sZr.create_model(ll = ll, GOS="Hartree-Slater", auto_add_edges=False)
mZr.fit_component(mZr["PowerLaw"], bounded=True, signal_range=[630.,660.], fit_independent=True, only_current=True)
mZr.assign_current_values_to_all()
mZr.fit_component(mZr["PowerLaw"], bounded=True, signal_range=[630.,660.], fit_independent=True, only_current=False)
#mZr["PowerLaw"].set_parameters_not_free()
Zr_L3 = hs.model.components1D.EELSCLEdge("Mn_L3", GOS="Hartree-Slater")
Zr_L2 = hs.model.components1D.EELSCLEdge("Mn_L2", GOS="Hartree-Slater")
Zr_L3_white = hs.model.components1D.Gaussian()
Zr_L3_white.name = "Mn_L3 line"
Zr_L3_white.centre.bmin = 640.0
Zr_L3_white.centre.bmax = 645.0
Zr_L3_white.A.bmin = 0
Zr_L3_white.sigma.bmax=3
mZr.append(Zr_L3_white)
mZr.fit_component(Zr_L3_white,fitter="leastsq", signal_range=[Zr_L3_white.centre.bmin-3.0, Zr_L3_white.centre.bmax+3.0], bounded=True,)
mZr.assign_current_values_to_all([Zr_L3_white])
mZr.fit_component(Zr_L3_white,fitter="leastsq", signal_range=[Zr_L3_white.centre.bmin-3.0, Zr_L3_white.centre.bmax+3.0], bounded=True, only_current=False)
mZr.append(Zr_L3)
Zr_L3.onset_energy.twin = Zr_L3_white.centre
mZr.fit_component(Zr_L3, bounded=True, signal_range=[636.,646.])
mZr.assign_current_values_to_all([Zr_L3])
mZr.fit_component(Zr_L3, bounded=True, signal_range=[636.,646.], only_current=False)
Zr_L2_white = hs.model.components1D.Gaussian()
Zr_L2_white.name = "Mn_L2 line"
Zr_L2_white.centre.bmin = 650.0
Zr_L2_white.centre.bmax = 655.0
Zr_L2_white.A.bmin = 0
Zr_L2_white.sigma.bmax=3
mZr.append(Zr_L2_white)
mZr.fit_component(Zr_L2_white, signal_range=[Zr_L2_white.centre.bmin-3.0, Zr_L2_white.centre.bmax+3.0], bounded=True,)
mZr.assign_current_values_to_all([Zr_L2_white])
mZr.fit_component(Zr_L2_white, signal_range=[Zr_L2_white.centre.bmin-3.0, Zr_L2_white.centre.bmax+3.0], bounded=True, only_current=False)
mZr.append(Zr_L2)
Zr_L2.onset_energy.twin = Zr_L2_white.centre
mZr.fit_component(Zr_L2, bounded=True, signal_range=[649., 659.])
mZr.assign_current_values_to_all([Zr_L2])
mZr.fit_component(Zr_L2, bounded=True, signal_range=[649., 659.], only_current=False)
mZr.fit_component(Zr_L2_white, signal_range=[Zr_L2_white.centre.bmin-3.0, Zr_L2_white.centre.bmax+3.0], bounded=True, only_current=False)
mZr.fit_component(Zr_L3, bounded=True, signal_range=[636.,646.], only_current=False)
mZr.fit_component(Zr_L3_white, signal_range=[Zr_L3_white.centre.bmin-3.0, Zr_L3_white.centre.bmax+3.0], bounded=True, only_current=False)
mZr.fit_component(Zr_L2, bounded=True, signal_range=[649., 659.], only_current=False)
mZr.fit_component(Zr_L2_white, signal_range=[Zr_L2_white.centre.bmin-3.0, Zr_L2_white.centre.bmax+3.0], bounded=True, only_current=False)
print("Finished fitting")
return mZr
sZr = s_Mn1
ll=ll_sum
model_Mn1 = fit_Zr_L(sZr, ll=None)
model_Mn1.plot(True)
@winston-song
Copy link
Author

winston-song commented Apr 21, 2020

Figure_EELS_Spectrum_Image_(high-loss)_after_Fourier-ratio_deconvolution_Signal

The plottted results look not quite clear to me, such as where is the H-S edge? and why the fitted gussian is not from the white line minimum, i.e. the green line should move down until the minimum point at ~648ev?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment