Ejemplo n.º 1
0
 def setUp(self):
     s = Spectrum(np.array([1.0, 2, 4, 7, 12, 7, 4, 2, 1]))
     m = create_model(s)
     self.model = m
     self.A = 38.022476979172588
     self.sigma = 1.4764966133859543
     self.centre = 4.0000000002462945
Ejemplo n.º 2
0
 def setUp(self):
     s = hs.signals.Spectrum([1])
     s.axes_manager[0].scale = 0.1
     m = hs.create_model(s)
     m.append(hs.components.Offset())
     m[0].offset.value = 1
     self.m = m
Ejemplo n.º 3
0
 def setUp(self):
     s = hs.signals.Spectrum(np.empty((10)))
     s.axes_manager[0].scale = 0.01
     m = hs.create_model(s)
     m.append(hs.components.Offset())
     m[0].offset.value = 10
     self.m = m
Ejemplo n.º 4
0
 def setUp(self):
     s = Spectrum(np.array([1.0, 2, 4, 7, 12, 7, 4, 2, 1]))
     m = create_model(s)
     self.model = m
     self.A = 38.022476979172588
     self.sigma = 1.4764966133859543
     self.centre = 4.0000000002462945
Ejemplo n.º 5
0
 def setUp(self):
     self.m = hs.create_model(hs.signals.Spectrum(
         np.arange(10).reshape(2, 5)))
     self.comps = [hs.components.Offset(), hs.components.Offset()]
     self.m.extend(self.comps)
     for c in self.comps:
         c.offset.value = 2
     self.m.assign_current_values_to_all()
Ejemplo n.º 6
0
 def setUp(self):
     s = hs.signals.Spectrum(np.empty((1024)))
     s.axes_manager[0].offset = -5
     s.axes_manager[0].scale = 0.01
     m = hs.create_model(s)
     m.append(hs.components.Polynomial(order=2))
     m[0].coefficients.value = (0.5, 2, 3)
     self.m = m
Ejemplo n.º 7
0
 def setUp(self):
     s = hs.signals.Spectrum(np.empty((1024)))
     s.axes_manager[0].offset = 100
     s.axes_manager[0].scale = 0.01
     m = hs.create_model(s)
     m.append(hs.components.PowerLaw())
     m[0].A.value = 10
     m[0].r.value = 4
     self.m = m
Ejemplo n.º 8
0
 def setUp(self):
     s = hs.signals.Spectrum(np.empty((1024)))
     s.axes_manager[0].offset = -5
     s.axes_manager[0].scale = 0.01
     m = hs.create_model(s)
     m.append(hs.components.Gaussian())
     m[0].sigma.value = 0.5
     m[0].centre.value = 1
     m[0].A.value = 2
     self.m = m
Ejemplo n.º 9
0
 def setUp(self):
     np.random.seed(1)
     s = hs.signals.SpectrumSimulation(np.arange(10, 100, 0.1))
     s.metadata.set_item("Signal.Noise_properties.variance",
                         hs.signals.Spectrum(np.arange(10, 100, 0.01)))
     s.axes_manager[0].scale = 0.1
     s.axes_manager[0].offset = 10
     s.add_poissonian_noise()
     m = hs.create_model(s)
     m.append(hs.components.Polynomial(1))
     self.m = m
Ejemplo n.º 10
0
 def setUp(self):
     s = hs.signals.EELSSpectrum(np.ones(200))
     s.set_microscope_parameters(100, 10, 10)
     s.axes_manager[-1].offset = 150
     CE = hs.utils.material.elements.C.Atomic_properties.Binding_energies.K.onset_energy_eV
     BE = hs.utils.material.elements.B.Atomic_properties.Binding_energies.K.onset_energy_eV
     s.isig[BE:] += 1
     s.isig[CE:] += 1
     s.add_elements(("Be", "B", "C"))
     self.m = hs.create_model(s, auto_background=False)
     self.m.append(hs.components.Offset())
Ejemplo n.º 11
0
 def setUp(self):
     g = Gaussian()
     g.A.value = 10000.0
     g.centre.value = 5000.0
     g.sigma.value = 500.0
     axis = np.arange(10000)
     s = Spectrum(g.function(axis))
     m = create_model(s)
     self.model = m
     self.g = g
     self.axis = axis
     self.rtol = 0.00
Ejemplo n.º 12
0
 def setUp(self):
     g1 = Gaussian()
     g2 = Gaussian()
     g3 = Gaussian()
     s = Spectrum(np.arange(1000).reshape(10, 10, 10))
     m = create_model(s)
     m.append(g1)
     m.append(g2)
     m.append(g3)
     self.g1 = g1
     self.g2 = g2
     self.g3 = g3
     self.model = m
Ejemplo n.º 13
0
 def setUp(self):
     g1 = Gaussian()
     g2 = Gaussian()
     g3 = Gaussian()
     s = Spectrum(np.arange(10))
     m = create_model(s)
     m.append(g1)
     m.append(g2)
     m.append(g3)
     self.g1 = g1
     self.g2 = g2
     self.g3 = g3
     self.model = m
Ejemplo n.º 14
0
 def setUp(self):
     np.random.seed(1)
     s = hs.signals.Spectrum(
         np.random.normal(
             scale=2,
             size=10000)).get_histogram()
     s.metadata.Signal.binned = True
     g = hs.components.Gaussian()
     m = hs.create_model(s)
     m.append(g)
     g.sigma.value = 1
     g.centre.value = 0.5
     g.A.value = 1e3
     self.m = m
Ejemplo n.º 15
0
 def setUp(self):
     g = Gaussian()
     g.A.value = 10000.0
     g.centre.value = 5000.0
     g.sigma.value = 500.0
     axis = np.arange(10000)
     s = Spectrum(g.function(axis))
     m = create_model(s)
     self.A = g.A.value
     self.centre = g.centre.value
     self.sigma = g.sigma.value
     self.model = m
     self.g = g
     self.axis = axis
     self.rtol = 0.00
Ejemplo n.º 16
0
 def setUp(self):
     variance = hs.signals.SpectrumSimulation(
         np.arange(
             100, 300).reshape(
             (2, 100)))
     s = variance.deepcopy()
     np.random.seed(1)
     std = 10
     s.add_gaussian_noise(std)
     s.add_poissonian_noise()
     s.metadata.set_item("Signal.Noise_properties.variance",
                         variance + std ** 2)
     m = hs.create_model(s)
     m.append(hs.components.Polynomial(order=1))
     self.s = s
     self.m = m
Ejemplo n.º 17
0
 def setUp(self):
     s = hs.signals.Spectrum(np.empty((2, 200)))
     s.axes_manager[-1].offset = 1
     s.data[:] = 2 * s.axes_manager[-1].axis ** (-3)
     m = hs.create_model(s)
     m.append(hs.components.PowerLaw())
     m[0].A.value = 2
     m[0].r.value = 2
     m.store_current_values()
     m.axes_manager.indices = (1,)
     m[0].r.value = 100
     m[0].A.value = 2
     m.store_current_values()
     m[0].A.free = False
     self.m = m
     m.axes_manager.indices = (0,)
     m[0].A.value = 100
Ejemplo n.º 18
0
    def setUp(self):
        gs1 = Gaussian()
        gs1.A.value = 10000.0
        gs1.centre.value = 5000.0
        gs1.sigma.value = 500.0

        gs2 = Gaussian()
        gs2.A.value = 60000.0
        gs2.centre.value = 2000.0
        gs2.sigma.value = 300.0

        gs3 = Gaussian()
        gs3.A.value = 20000.0
        gs3.centre.value = 6000.0
        gs3.sigma.value = 100.0

        axis = np.arange(10000)
        total_signal = (gs1.function(axis) +
                        gs2.function(axis) +
                        gs3.function(axis))

        s = Spectrum(total_signal)
        m = create_model(s)

        g1 = Gaussian()
        g2 = Gaussian()
        g3 = Gaussian()
        m.append(g1)
        m.append(g2)
        m.append(g3)

        self.model = m
        self.gs1 = gs1
        self.gs2 = gs2
        self.gs3 = gs3
        self.g1 = g1
        self.g2 = g2
        self.g3 = g3
        self.axis = axis
        self.rtol = 0.01
Ejemplo n.º 19
0
    def setUp(self):
        gs1 = Gaussian()
        gs1.A.value = 10000.0
        gs1.centre.value = 5000.0
        gs1.sigma.value = 500.0

        gs2 = Gaussian()
        gs2.A.value = 60000.0
        gs2.centre.value = 2000.0
        gs2.sigma.value = 300.0

        gs3 = Gaussian()
        gs3.A.value = 20000.0
        gs3.centre.value = 6000.0
        gs3.sigma.value = 100.0

        axis = np.arange(10000)
        total_signal = (gs1.function(axis) + gs2.function(axis) +
                        gs3.function(axis))

        s = Spectrum(total_signal)
        m = create_model(s)

        g1 = Gaussian()
        g2 = Gaussian()
        g3 = Gaussian()
        m.append(g1)
        m.append(g2)
        m.append(g3)

        self.model = m
        self.gs1 = gs1
        self.gs2 = gs2
        self.gs3 = gs3
        self.g1 = g1
        self.g2 = g2
        self.g3 = g3
        self.axis = axis
        self.rtol = 0.01
Ejemplo n.º 20
0
 def setUp(self):
     s = hs.signals.Spectrum(np.empty(1))
     m = hs.create_model(s)
     self.model = m
Ejemplo n.º 21
0
 def setUp(self):
     s = Spectrum(np.empty(1))
     m = create_model(s)
     self.model = m
Ejemplo n.º 22
0
 def setUp(self):
     self.m = hs.create_model(hs.signals.Spectrum(
         np.arange(10).reshape(2, 5)))
     self.comps = [hs.components.Offset(), hs.components.Offset()]
     self.m.extend(self.comps)
Ejemplo n.º 23
0
 def setUp(self):
     self.m = hs.create_model(hs.signals.Spectrum(np.arange(10)))
     self.o = hs.components.Offset()
     self.m.append(self.o)
Ejemplo n.º 24
0
 def setUp(self):
     s = hs.signals.SpectrumSimulation(np.ones(100))
     m = hs.create_model(s)
     m.append(hs.components.Offset())
     self.s = s
     self.m = m
Ejemplo n.º 25
0
""" Loads hyperspy as a regular python library, loads spectrums from files, does curve fitting, and plotting the model and original spectrum to a png file"""

import hyperspy.hspy as hspy
import matplotlib.pyplot as plt

coreLossSpectrumFileName = "coreloss_spectrum.msa"
lowlossSpectrumFileName = "lowloss_spectrum.msa"

s = hspy.load(coreLossSpectrumFileName).to_EELS()
s.add_elements(("Mn", "O"))
s.set_microscope_parameters(
    beam_energy=300,
    convergence_angle=24.6,
    collection_angle=13.6)

ll = hspy.load(lowlossSpectrumFileName).to_EELS()

m = hspy.create_model(s, ll=ll)
m.enable_fine_structure()
m.multifit(kind="smart")
m.plot()

plt.savefig("model_original_spectrum_plot.png")
Ejemplo n.º 26
0
 def setUp(self):
     s = hs.signals.EELSSpectrum(np.empty(200))
     s.set_microscope_parameters(100, 10, 10)
     s.axes_manager[-1].offset = 150
     s.add_elements(("B", "C"))
     self.m = hs.create_model(s)
Ejemplo n.º 27
0
 def setUp(self):
     s = hs.signals.EELSSpectrum(np.empty(200))
     s.set_microscope_parameters(100, 10, 10)
     s.axes_manager[-1].offset = 150
     s.add_elements(("B", "C"))
     self.m = hs.create_model(s)
Ejemplo n.º 28
0
 def setUp(self):
     s = Spectrum(np.empty(1))
     m = create_model(s)
     self.model = m
Ejemplo n.º 29
0
""" Loads hyperspy as a regular python library, loads spectrums from files, does curve fitting, and plotting the model and original spectrum to a png file"""

import hyperspy.hspy as hspy
import matplotlib.pyplot as plt

coreLossSpectrumFileName = "coreloss_spectrum.msa"
lowlossSpectrumFileName = "lowloss_spectrum.msa"

s = hspy.load(coreLossSpectrumFileName).to_EELS()
s.add_elements(("Mn", "O"))
s.set_microscope_parameters(beam_energy=300,
                            convergence_angle=24.6,
                            collection_angle=13.6)

ll = hspy.load(lowlossSpectrumFileName).to_EELS()

m = hspy.create_model(s, ll=ll)
m.enable_fine_structure()
m.multifit(kind="smart")
m.plot()

plt.savefig("model_original_spectrum_plot.png")