In [1]:
%matplotlib qt4
import numpy as np
import hyperspy.api as hs
import matplotlib.pyplot as plt

Doc-string examples for EDS

Loading signal examples


In [2]:
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.plot(True)


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [3]:
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.plot()


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [4]:
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s.plot(True)


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

eds


In [5]:
#Sum()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.sum(0).data


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Out[5]:
array([1000279])

In [6]:
#rebin()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
print(s)
print(s.rebin([512]))


<EDSSEMSpectrum, title: EDS SEM Signal1D, dimensions: (|1024)>
<EDSSEMSpectrum, title: EDS SEM Signal1D, dimensions: (|512)>
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [7]:
#set_elements()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
print(s.metadata.Sample.elements)
s.set_elements(['Al'])
print(s.metadata.Sample.elements)


['Al' 'C' 'Cu' 'Mn' 'Zr']
['Al']
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [8]:
#add_elements()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
print(s.metadata.Sample.elements)
s.add_elements(['Ar'])
print(s.metadata.Sample.elements)


['Al' 'C' 'Cu' 'Mn' 'Zr']
['Al', 'Ar', 'C', 'Cu', 'Mn', 'Zr']
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [9]:
#set_lines()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.add_lines()
print(s.metadata.Sample.xray_lines)
s.set_lines(['Cu_Ka'])
print(s.metadata.Sample.xray_lines)


Al_Ka line added,
C_Ka line added,
Cu_La line added,
Mn_La line added,
Zr_La line added,
['Al_Ka', 'C_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
Cu_Ka line added,
Al_Ka line added,
C_Ka line added,
Mn_La line added,
Zr_La line added,
Cu_Ka line added,
['Al_Ka', 'C_Ka', 'Cu_Ka', 'Mn_La', 'Zr_La']
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [10]:
#add_lines()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.add_lines()
print(s.metadata.Sample.xray_lines)
        



s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.set_microscope_parameters(beam_energy=30)
s.add_lines()
print(s.metadata.Sample.xray_lines)
        

s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.add_lines()
print(s.metadata.Sample.xray_lines)
s.add_lines(['Cu_Ka'])
print(s.metadata.Sample.xray_lines)


Al_Ka line added,
C_Ka line added,
Cu_La line added,
Mn_La line added,
Zr_La line added,
['Al_Ka', 'C_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
Al_Ka line added,
C_Ka line added,
Cu_Ka line added,
Mn_Ka line added,
Zr_La line added,
['Al_Ka', 'C_Ka', 'Cu_Ka', 'Mn_Ka', 'Zr_La']
Al_Ka line added,
C_Ka line added,
Cu_La line added,
Mn_La line added,
Zr_La line added,
['Al_Ka', 'C_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
Cu_Ka line added,
['Al_Ka', 'C_Ka', 'Cu_Ka', 'Cu_La', 'Mn_La', 'Zr_La']
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [3]:
#get_lines_intensity()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.get_lines_intensity(['Mn_Ka'], plot_result=True)


Mn_Ka at 5.8987 keV : Intensity = 52773.00
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Out[3]:
[<EDSSEMSpectrum, title: X-ray line intensity of EDS SEM Signal1D: Mn_Ka at 5.90 keV, dimensions: (|1)>]

In [4]:
#get_lines_intensity()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.plot(['Mn_Ka'], integration_windows=2.1)
s.get_lines_intensity(['Mn_Ka'],
integration_windows=2.1, plot_result=True)


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Mn_Ka at 5.8987 keV : Intensity = 53597.00
/home/to266/anaconda3/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Out[4]:
[<EDSSEMSpectrum, title: X-ray line intensity of EDS SEM Signal1D: Mn_Ka at 5.90 keV, dimensions: (|1)>]

In [6]:
#get_lines_intensity()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.change_dtype('float')
s.set_elements(['Mn'])
s.set_lines(['Mn_Ka'])
bw = s.estimate_background_windows()
s.plot(background_windows=bw)
s.get_lines_intensity(background_windows=bw, plot_result=True)


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
/home/to266/anaconda3/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Mn_Ka line added,
Mn_Ka at 5.8987 keV : Intensity = 46716.00
Out[6]:
[<EDSSEMSpectrum, title: X-ray line intensity of EDS SEM Signal1D: Mn_Ka at 5.90 keV, dimensions: (|1)>]

In [7]:
#estimate_integration_windows()
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s.add_lines()
iw = s.estimate_integration_windows()
s.plot(integration_windows=iw)
s.get_lines_intensity(integration_windows=iw, plot_result=True)


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Fe_Ka line added,
Pt_La line added,
Fe_Ka at 6.4039 keV : Intensity = 3710.00
Pt_La at 9.4421 keV : Intensity = 15872.00
/home/to266/anaconda3/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Out[7]:
[<EDSTEMSpectrum, title: X-ray line intensity of EDS TEM Signal1D: Fe_Ka at 6.40 keV, dimensions: (|1)>,
 <EDSTEMSpectrum, title: X-ray line intensity of EDS TEM Signal1D: Pt_La at 9.44 keV, dimensions: (|1)>]

In [9]:
#estimate_background_windows()
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s.change_dtype('float')
s.add_lines()
bw = s.estimate_background_windows(line_width=[5.0, 2.0])
s.plot(background_windows=bw)
s.get_lines_intensity(background_windows=bw, plot_result=True)


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Fe_Ka line added,
Pt_La line added,
/home/to266/anaconda3/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Fe_Ka at 6.4039 keV : Intensity = 2754.00
Pt_La at 9.4421 keV : Intensity = 15090.00
Out[9]:
[<EDSTEMSpectrum, title: X-ray line intensity of EDS TEM Signal1D: Fe_Ka at 6.40 keV, dimensions: (|1)>,
 <EDSTEMSpectrum, title: X-ray line intensity of EDS TEM Signal1D: Pt_La at 9.44 keV, dimensions: (|1)>]

In [10]:
#get_take_off()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.get_take_off_angle()


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Out[10]:
37.0

In [11]:
#get_take_off()
s.set_microscope_parameters(tilt_stage=20.)
s.get_take_off_angle()


Out[11]:
57.00000000000001

In [12]:
#plot()
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.plot()


s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.plot(True)


s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s.add_lines()
bw = s.estimate_background_windows()
s.plot(background_windows=bw)
        

s = hs.datasets.example_signals.EDS_SEM_Spectrum()
s.plot(['Mn_Ka'], integration_windows='auto')


s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s.add_lines()
bw = s.estimate_background_windows()
s.plot(background_windows=bw, integration_windows=2.1)


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Fe_Ka line added,
Pt_La line added,
/home/to266/anaconda3/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Fe_Ka line added,
Pt_La line added,

eds_sem


In [13]:
#get_calibration_from
ref = hs.datasets.example_signals.EDS_SEM_Spectrum()
s = hs.signals.EDSSEMSpectrum(
hs.datasets.example_signals.EDS_SEM_Spectrum().data)
print(s.axes_manager[0].scale)
s.get_calibration_from(ref)
print(s.axes_manager[0].scale)


1.0
0.01
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [14]:
#set_micro
s = hs.datasets.example_signals.EDS_SEM_Spectrum()
print('Default value %s eV' %
s.metadata.Acquisition_instrument.
SEM.Detector.EDS.energy_resolution_MnKa)
s.set_microscope_parameters(energy_resolution_MnKa=135.)
print('Now set to %s eV' %
s.metadata.Acquisition_instrument.
SEM.Detector.EDS.energy_resolution_MnKa)


Default value 130.0 eV
Now set to 135.0 eV
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [15]:
#set_micro
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
print(s.metadata.Acquisition_instrument.
TEM.Detector.EDS.energy_resolution_MnKa)
s.set_microscope_parameters(energy_resolution_MnKa=135.)
print(s.metadata.Acquisition_instrument.
TEM.Detector.EDS.energy_resolution_MnKa)


133.312296
135.0
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

eds_tem


In [16]:
#get_calibration_from
ref = hs.datasets.example_signals.EDS_TEM_Spectrum()
s = hs.signals.EDSTEMSpectrum(
hs.datasets.example_signals.EDS_TEM_Spectrum().data)
print(s.axes_manager[0].scale)
s.get_calibration_from(ref)
print(s.axes_manager[0].scale)


1.0
0.020028
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)

In [4]:
#quant
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s.change_dtype('float')
s.add_lines()
kfactors = [1.450226, 5.075602] #For Fe Ka and Pt La
bw = s.estimate_background_windows(line_width=[5.0, 2.0])
s.plot(background_windows=bw)
intensities = s.get_lines_intensity(background_windows=bw)
res = s.quantification(intensities, kfactors, plot_result=True,
composition_units='atomic')


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
Fe_Ka line added,
Pt_La line added,
/home/to266/anaconda3/lib/python3.5/site-packages/matplotlib/__init__.py:892: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))
Fe (Fe_Ka): Composition = 15.41 atomic percent
Pt (Pt_La): Composition = 84.59 atomic percent

In [5]:
res[0].axes_manager.signal_size


Out[5]:
1

In [7]:
# Simulate a spectrum image with vacuum region
import numpy as np
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s_vac = hs.signals.BaseSignal(np.ones_like(s.data, dtype=float))*0.005
s_vac.add_poissonian_noise()
si = hs.stack([s]*3 + [s_vac])
si.vacuum_mask().data


/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
/home/to266/dev/hyperspy/hyperspy/signals.py:126: VisibleDeprecationWarning: The Signal class will be deprecated from version 1.0.0 and replaced with BaseSignal
  VisibleDeprecationWarning)
Out[7]:
array([False, False, False,  True], dtype=bool)

In [8]:
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
si = hs.stack([s]*3)
si.change_dtype(float)
si.decomposition()


Scaling the data to normalize the (presumably) Poissonian noise

Performing decomposition analysis
Auto transposing the data
Undoing data pre-treatments
/home/to266/dev/hyperspy/hyperspy/signals.py:54: VisibleDeprecationWarning: The Signal1D class will be deprecated from version 1.0.0 and replaced with Signal1D
  VisibleDeprecationWarning)
/home/to266/dev/hyperspy/hyperspy/signals.py:126: VisibleDeprecationWarning: The Signal class will be deprecated from version 1.0.0 and replaced with BaseSignal
  VisibleDeprecationWarning)

utils.eds


In [9]:
# Electron range in pure Copper at 30 kV in micron
hs.eds.electron_range('Cu', 30.)


Out[9]:
2.8766744984001607

In [10]:
# X-ray range of Cu Ka in pure Copper at 30 kV in micron
hs.eds.xray_range('Cu_Ka', 30.)


Out[10]:
1.9361716759499248

In [11]:
# X-ray range of Cu Ka in pure Carbon at 30kV in micron
hs.eds.xray_range('Cu_Ka', 30., hs.material.elements.C.
Physical_properties.density_gcm3)


Out[11]:
7.6418811280855454