我有一个代码,可以让我的显微镜扫描样品:
pos = microscope.position
print("Current position: " + json.dumps(pos))
print("Homing")
pos['x'] = 0
pos['y'] = 0
pos['z'] = 0
# units in microns
xyStep = 10
xRange = 400
yRange = 400
zRange = 400
#zBase = maxPosition - micronToStep(zRange/2)
#zBase = -((30000 - 15000)/2)
zBase = -1000
saveData = {
"xyStep": xyStep,
"xRange": xRange,
"yRange": yRange,
"zRange": zRange,
"zBase": zBase,
"data": [[0] * ceil(xRange/xyStep) for i in range(ceil(yRange/xyStep))],
}
measurements = 1
pos = microscope.position
print("Current position: " + json.dumps(pos))
starting_pos = microscope.position
#figure(figsize=(20,5))
ix = 0
iy = 0
totalElapsed = 0
stepsTaken = 1
maxSteps = (xRange/xyStep) * (yRange/xyStep)
up = True
ix = 0
for x in range(-micronToStep(xRange/2), micronToStep(xRange/2) - micronToStep(xyStep), micronToStep(xyStep)):
iy = 0
for y in range(-micronToStep(yRange/2), micronToStep(yRange/2) - micronToStep(xyStep), micronToStep(xyStep)):
start = timer()
values = []
if (up):
pos = {}
pos['x'] = x + 7500 # declination
pos['y'] = y - 5500 # declination
pos['z'] = zBase - micronToStep(zRange/2)
pos['z2'] = zBase + micronToStep(zRange/2)
print("Scanning up to position:", pos)
values = microscope.measureZ(microscope, pos)
values = np.asarray(values)
thisTime = timer() - start
totalElapsed += thisTime
up = False
else:
pos = {}
pos['x'] = x + 7500 # declination
pos['y'] = y - 5500 # declination
pos['z'] = zBase + micronToStep(zRange/2)
pos['z2'] = zBase - micronToStep(zRange/2)
print("Scanning to position:", pos)
values = microscope.measureZ(microscope, pos)
values = np.asarray(values)
values = np.flip(values)
thisTime = timer() - start
totalElapsed += thisTime
up = True
print(pos)
saveData['data'][ix][iy] = values
iy += 1
timeLeft = (maxSteps - stepsTaken) * (totalElapsed / stepsTaken) / 60 / 60
print(">>>>>>>>>>>> Estimated time left: [" + str(timeLeft) + "hr], Per Scan: [" + str(totalElapsed / stepsTaken) + "s][" + str(thisTime) + "], Total Elapsed: [" + str(totalElapsed) + "s], Scans taken: [" + str(stepsTaken) + "] out of: [" + str(maxSteps) + "]")
stepsTaken += 1
pickle.dump(saveData, open('saveData.bin', 'wb'))
ix += 1
pickle.dump(saveData, open('saveData.bin', 'wb'))
它适用于xyStep = 10,但当我将此参数更改为xyStep = 1时,在打印扫描后:[200] I get an error:in line 149, saveData['data'][ix][iy] = values: IndexError: list assignment index out of range
。函数micronToStep的定义很简单:def micronToStep(v):返回循环((v * 1000)/62)。
我假设问题出在数组维度上。更准确地说,如果需要解决这个问题,我可以添加有关代码的更多信息。
如何纠正这一点?
2条答案
按热度按时间gj3fmq9x1#
saveData["data"]
是一个400 x 400的列表。你有这些循环:
在执行计算之后,这些回路上的实际范围条件为:
...它产生了略多于400次的迭代(我相信是402次)。因此,ix和iy最终会变得太大,并产生超出范围的误差。
yvgpqqbh2#
post中的代码开始于:“我有一个代码:“工程正确的情况下
并打印:
但是当xyStep = 1时它就停止工作了,而当xyStep = 0.9,xyStep = 0.8…等等。
原因是在xyStep = 1的情况下编写了略多于400次的迭代。如何更正条件以使程序在以下情况下工作
?