Skip to content

Commit 42e098c

Browse files
authored
Refactor: reduce the read-in loop in sts_line (#6148)
1 parent 3170cbe commit 42e098c

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

tools/stm/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
start_points = [0, 0, 8]
6060
end_points = [2, 0, 8]
6161
distance = np.linalg.norm(np.array(end_points) - np.array(start_points))
62-
biases, points, dIdV_map = stm.line_sts(biasstart, biasend, biasstep, start_points, end_points, 50)
62+
biases, points, current, dIdV_map = stm.line_sts(biasstart, biasend, biasstep, start_points, end_points, 50)
6363

6464
plt.figure(figsize=(10, 6), dpi=150)
6565

tools/stm/stm.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ def linescan(self, bias, current, p1, p2, npoints=50, z0=None):
156156
def pointcurrent(self, bias, x, y, z):
157157
"""Current for a single x, y, z position for a given bias."""
158158

159-
self.read_ldos(bias)
160-
161159
nx = self.ldos.shape[0]
162160
ny = self.ldos.shape[1]
163161
nz = self.ldos.shape[2]
@@ -193,6 +191,7 @@ def sts(self, x, y, z, bias0, bias1, biasstep):
193191

194192
for b in np.arange(len(biases)):
195193
print(b, biases[b])
194+
self.read_ldos(biases[b])
196195
current[b] = self.pointcurrent(biases[b], x, y, z)
197196

198197
dIdV = np.gradient(current, biasstep)
@@ -209,14 +208,21 @@ def line_sts(self, bias0, bias1, biasstep, p1, p2, npoints=50):
209208
d = p2 - p1
210209
s = np.dot(d, d)**0.5
211210
biases = np.arange(bias0, bias1 + biasstep, biasstep)
211+
current = np.zeros((npoints, len(biases)))
212212

213-
dIdV = np.zeros((npoints, len(biases)))
213+
for b in np.arange(len(biases)):
214+
print(b, biases[b])
215+
self.read_ldos(biases[b])
216+
217+
for i in range(npoints):
218+
x, y, z = p1 + i * d / (npoints - 1)
219+
current[i, b] = self.pointcurrent(biases[b], x, y, z)
214220

221+
dIdV = np.zeros((npoints, len(biases)))
215222
for i in range(npoints):
216-
x, y, z = p1 + i * d / (npoints - 1)
217-
biases, current, dIdV[i, :] = self.sts(x, y, z, bias0, bias1, biasstep)
223+
dIdV[i, :] = np.gradient(current[i, :], biasstep)
218224

219-
return biases, np.linspace(0, s, npoints), dIdV
225+
return biases, np.linspace(0, s, npoints), current, dIdV
220226

221227

222228
def find_current(self, ldos, z):

0 commit comments

Comments
 (0)