Commit f1fcb2d7 authored by Josef Brandt's avatar Josef Brandt

Autofocus Option selectable by checkbox in WITecCom

parent d6102fea
......@@ -18,3 +18,9 @@ external/build/
ramancom/renishawcom.py
ramancom/renishawtesting.py
*.exp
*.lib
*.obj
......@@ -53,6 +53,8 @@ class WITecCOM(RamanBase):
hostname = gethostname()
self.IBUCSAccess = win32com.client.DispatchEx(self.CLSID, machine=hostname,
clsctx=pythoncom.CLSCTX_REMOTE_SERVER)
self.advancedInterface = False
self.doAutoFocus = False
def connect(self):
if not self.IBUCSAccess.RequestWriteAccess(True):
......@@ -167,9 +169,8 @@ class WITecCOM(RamanBase):
try:
self.getAdvancedCOMFeatures(IBUCSCore)
self.advancedInterface = True
print('using advanced WITec features!')
self.doAutoFocus = False
except pythoncom.com_error:
print('not using advanced WITec features!')
self.advancedInterface = False
self.connected = True
......@@ -202,8 +203,8 @@ class WITecCOM(RamanBase):
except ModuleNotFoundError:
from advancedWITec import AdvancedWITecSpectra
self.advSpec = AdvancedWITecSpectra()
self.ramanParameters.append(RamanSettingParam('Autofocus', 'checkBox', default=True))
if 'Autofocus' not in [param.name for param in self.ramanParameters]:
self.ramanParameters.append(RamanSettingParam('Autofocus', 'checkBox', default=False))
def getBrightness(self):
assert self.connected
......@@ -342,6 +343,7 @@ class WITecCOM(RamanBase):
if not self.advancedInterface:
self.triggerTimeSeriesMeasurement(num)
else:
if self.doAutoFocus:
self.doSpectralAutoFocus()
self.acquireSilentSpectrum(num)
......@@ -378,6 +380,9 @@ class WITecCOM(RamanBase):
def initateSilentSpectrumAcquisition(self, ramanSettings):
self.advSpec.setDatasetPath(ramanSettings['path'])
self.doAutoFocus = ramanSettings['Autofocus']
self.advSpec.createTmpSpecFolder()
state = self.BeamPathState.GetValue()
if state == 'Video':
......
......@@ -99,33 +99,13 @@ class RamanScanUI(QtWidgets.QWidget):
hbox = QtWidgets.QHBoxLayout()
self.params = []
for param in self.ramanctrl.ramanParameters:
if param.dtype == 'int':
self.params.append(QtWidgets.QSpinBox())
self.params[-1].setMinimum(param.minVal)
self.params[-1].setMaximum(param.maxVal)
self.params[-1].setValue(param.value)
if param.dtype == 'double':
self.params.append(QtWidgets.QDoubleSpinBox())
self.params[-1].setMinimum(param.minVal)
self.params[-1].setMaximum(param.maxVal)
self.params[-1].setValue(param.value)
if param.dtype == 'combobox':
self.params.append(QtWidgets.QComboBox())
self.params[-1].addItems([str(i) for i in param.valList])
self.group2 = QtWidgets.QGroupBox("Raman settings", self)
grid2 = QtWidgets.QFormLayout()
for index, param in enumerate(self.params):
param.setMinimumWidth(70)
grid2.addRow(QtWidgets.QLabel(self.ramanctrl.ramanParameters[index].name), param)
self.paramsGroup = QtWidgets.QGroupBox("Raman settings")
self.paramsLayout = QtWidgets.QFormLayout()
self.prun = QtWidgets.QPushButton("Raman scan", self)
self.prun.released.connect(self.run)
grid2.addRow(self.prun)
self.group2.setLayout(grid2)
self.paramsGroup.setLayout(self.paramsLayout)
self.updateRamanParameters()
self.pexit = QtWidgets.QPushButton("Cancel", self)
self.pexit.released.connect(self.stopScan)
......@@ -139,7 +119,7 @@ class RamanScanUI(QtWidgets.QWidget):
hbox.addStretch()
hbox.addWidget(self.pexit)
vbox.addWidget(self.group2)
vbox.addWidget(self.paramsGroup)
vbox.addLayout(hbox)
vbox.addWidget(self.progresstime)
vbox.addWidget(self.progressbar)
......@@ -148,6 +128,42 @@ class RamanScanUI(QtWidgets.QWidget):
self.setWindowTitle("Raman Scan")
self.setVisible(False)
def updateRamanParameters(self):
"""
Update the raman parameters in the layout
:return:
"""
for index in reversed(range(self.paramsLayout.count())):
widget = self.paramsLayout.itemAt(index).widget()
self.paramsLayout.removeWidget(widget)
widget.setParent(None)
self.params = []
for param in self.ramanctrl.ramanParameters:
if param.dtype == 'int':
self.params.append(QtWidgets.QSpinBox())
self.params[-1].setMinimum(param.minVal)
self.params[-1].setMaximum(param.maxVal)
self.params[-1].setValue(param.value)
if param.dtype == 'double':
self.params.append(QtWidgets.QDoubleSpinBox())
self.params[-1].setMinimum(param.minVal)
self.params[-1].setMaximum(param.maxVal)
self.params[-1].setValue(param.value)
if param.dtype == 'combobox':
self.params.append(QtWidgets.QComboBox())
self.params[-1].addItems([str(i) for i in param.valList])
if param.dtype== 'checkBox':
self.params.append(QtWidgets.QCheckBox())
self.params[-1].setChecked(param.value)
for index, param in enumerate(self.params):
param.setMinimumWidth(70)
self.paramsLayout.addRow(QtWidgets.QLabel(self.ramanctrl.ramanParameters[index].name), param)
self.paramsLayout.addRow(self.prun)
self.paramsGroup.setLayout(self.paramsLayout)
def makeGetFnameLambda(self, msg, path, fileType, btn):
return lambda : self.getFName(msg, path, fileType, btn)
......@@ -247,7 +263,7 @@ class RamanScanUI(QtWidgets.QWidget):
else:
self.view.highLightRamanIndex(0)
self.view.blockUI()
self.group2.setEnabled(False)
self.paramsGroup.setEnabled(False)
self.progresstime.setEnabled(True)
self.progressbar.setEnabled(True)
self.progressbar.setRange(0, len(scanpoints))
......
......@@ -220,6 +220,7 @@ class SampleView(QtWidgets.QGraphicsView):
elif mode == "RamanScan":
self.removeSeedPointMarkers()
self.ramanwidget.resetDataset(self.dataset)
self.ramanwidget.updateRamanParameters()
self.ramanwidget.setVisible(True)
#show legend:
......@@ -350,9 +351,9 @@ class SampleView(QtWidgets.QGraphicsView):
p0 = self.mapToScene(event.pos())
self.moveStageToPosition(p0)
# elif self.mode=="ParticleDetection":
# p0 = self.mapToScene(event.pos())
# self.detectionwidget.setImageCenter([p0.x(), p0.y()])
elif self.mode=="ParticleDetection":
p0 = self.mapToScene(event.pos())
self.detectionwidget.setImageCenter([p0.x(), p0.y()])
else:
p0 = self.mapToScene(event.pos())
......
......@@ -110,7 +110,7 @@ class Segmentation(object):
Parameter("maxholebrightness", float, self.detectParams['maxholebrightness'], 0, 1, 2, 0.02, helptext="Close holes brighter than..", show = True),
Parameter("minparticlearea", int, self.detectParams['minparticlearea'], 1, 1000, 0, 50, helptext="Min. particle pixel area", show=False),
Parameter("enableMaxArea", np.bool, self.detectParams['enableMaxArea'], helptext="enable filtering for maximal pixel area", show=False, linkedParameter='maxparticlearea'),
Parameter("maxparticlearea", int, self.detectParams['maxparticlearea'], 10, 1E9, 0, 50, helptext="Max. particle pixel area", show=True),
Parameter("maxparticlearea", int, self.detectParams['maxparticlearea'], 10, 1E9, 0, 50, helptext="Max. particle pixel area", show=False),
Parameter("minparticledistance", int, self.detectParams['minparticledistance'], 5, 1000, 0, 5, helptext="Min. distance between particles", show=False),
Parameter("measurefrac", float, self.detectParams['measurefrac'], 0, 1, 2, stepsize = 0.05, helptext="measure fraction of particles", show=False),
Parameter("closeBackground", np.bool, self.detectParams['closeBackground'], helptext="close holes in sure background", show=False),
......@@ -253,11 +253,15 @@ class Segmentation(object):
for label in range(1, n):
area = stats[label, cv2.CC_STAT_AREA]
if self.minparticlearea < area < maxArea:
print(f'processing {label} of {n} compontents')
up = stats[label, cv2.CC_STAT_TOP]
left = stats[label, cv2.CC_STAT_LEFT]
width = stats[label, cv2.CC_STAT_WIDTH]
height = stats[label, cv2.CC_STAT_HEIGHT]
# if width > 25000 or height > 25000:
if False:
print(f'skipping{label} of {n} compontents, too large: {width} x {height} pixel!!!')
else:
print(f'processing {label} of {n} compontents, {width} x {height} pixel')
subthresh = np.uint8(255 * (labels[up:(up+height), left:(left+width)] == label))
subdist = cv2.distanceTransform(subthresh, cv2.DIST_L2, 3)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment