-
Notifications
You must be signed in to change notification settings - Fork 206
/
pes_see.py
159 lines (139 loc) · 5.16 KB
/
pes_see.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# -*- coding: utf-8 -*-
# Copyright 2007-2016 The HyperSpy developers
#
# This file is part of HyperSpy.
#
# HyperSpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# HyperSpy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with HyperSpy. If not, see <http://www.gnu.org/licenses/>.
import numpy as np
from hyperspy.component import Component
from .gaussian import Gaussian
sqrt2pi = np.sqrt(2 * np.pi)
class SEE(Component):
"""Secondary electron emission component for Photoemission Spectroscopy
Attributes
----------
A : float
Phi : float
B : float
sigma : float
Resolution parameter.
"""
def __init__(self, A=1., Phi=1., B=0., sigma=0):
Component.__init__(self, ('A', 'Phi', 'B', 'sigma'))
self.A.value, self.Phi.value, self.B.value, self.sigma.value = \
A, Phi, B, sigma
self._position = self.Phi
# Boundaries
self.A.bmin = 0.
self.A.bmax = None
self.convolved = True
# Gradients
self.A.grad = self.grad_A
self.Phi.grad = self.grad_Phi
self.B.grad = self.grad_B
self.sigma.grad = self.grad_sigma
# Resolution functions
self.gaussian = Gaussian()
self.gaussian.origin.free, self.gaussian.A.free = False, False
self.gaussian.sigma.free = True
self.gaussian.A.value = 1.
def __repr__(self):
return 'SEE'
def function(self, x):
"""
"""
if self.sigma.value:
self.gaussian.sigma.value = self.sigma.value
self.gaussian.origin.value = (x[-1] + x[0]) / 2
return np.convolve(
self.gaussian.function(x),
np.where(
x > self.Phi.value,
self.A.value * (
x - self.Phi.value) / (
x - self.Phi.value + self.B.value) ** 4,
0),
'same')
else:
return np.where(x > self.Phi.value, self.A.value *
(x -
self.Phi.value) /
(x -
self.Phi.value +
self.B.value) ** 4, 0)
def grad_A(self, x):
"""
"""
if self.sigma.value:
self.gaussian.sigma.value = self.sigma.value
self.gaussian.origin.value = (x[-1] + x[0]) / 2
return np.convolve(
self.gaussian.function(x),
np.where(
x > self.Phi.value,
(x - self.Phi.value) /
(x - self.Phi.value + self.B.value) ** 4, 0),
'same')
else:
return np.where(x > self.Phi.value, (x - self.Phi.value) /
(x - self.Phi.value + self.B.value) ** 4, 0)
def grad_sigma(self, x):
"""
"""
self.gaussian.sigma.value = self.sigma.value
self.gaussian.origin.value = (x[-1] + x[0]) / 2
return np.convolve(
self.gaussian.grad_sigma(x),
np.where(
x > self.Phi.value,
self.A.value * (x - self.Phi.value) /
(x - self.Phi.value + self.B.value) ** 4, 0),
'same')
def grad_Phi(self, x):
"""
"""
if self.sigma.value:
self.gaussian.sigma.value = self.sigma.value
self.gaussian.origin.value = (x[-1] + x[0]) / 2
return np.convolve(
self.gaussian.function(x),
np.where(
x > self.Phi.value,
(4 * (x - self.Phi.value) * self.A.value) /
(self.B.value + x - self.Phi.value) ** 5 -
self.A.value / (self.B.value + x - self.Phi.value) ** 4,
0),
'same')
else:
return np.where(
x > self.Phi.value,
(4 * (x - self.Phi.value) * self.A.value) /
(self.B.value + x - self.Phi.value) ** 5 -
self.A.value / (self.B.value + x - self.Phi.value) ** 4, 0)
def grad_B(self, x):
if self.sigma.value:
self.gaussian.sigma.value = self.sigma.value
self.gaussian.origin.value = (x[-1] + x[0]) / 2
return np.convolve(
self.gaussian.function(x),
np.where(
x > self.Phi.value,
-(4 * (x - self.Phi.value) * self.A.value) /
(self.B.value + x - self.Phi.value) ** 5, 0),
'same')
else:
return np.where(
x > self.Phi.value,
-(4 * (x - self.Phi.value) * self.A.value) /
(self.B.value + x - self.Phi.value) ** 5, 0)