Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
total_control_app
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martin Drechsler
total_control_app
Commits
07ac6e35
Commit
07ac6e35
authored
Apr 21, 2019
by
Martin Drechsler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some changes, queue added but only dto dummy andor
parent
25631830
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
224 additions
and
242 deletions
+224
-242
cameraGui.py
cameraGui.py
+95
-81
cameraParameterTree.py
cameraParameterTree.py
+53
-93
dummyAndor.py
dummyAndor.py
+41
-33
zylaCameraWorker.py
zylaCameraWorker.py
+35
-35
No files found.
cameraGui.py
View file @
07ac6e35
...
@@ -12,160 +12,174 @@ from pyqtgraph.Qt import QtGui, QtCore
...
@@ -12,160 +12,174 @@ from pyqtgraph.Qt import QtGui, QtCore
from
pyqtgraph
import
dockarea
from
pyqtgraph
import
dockarea
import
pyqtgraph
as
pg
import
pyqtgraph
as
pg
from
zylaCameraWorker
import
CameraWorker
from
zylaCameraWorker
import
CameraWorker
from
cameraParameterTree
import
CameraParameterTree
import
sys
import
sys
import
numpy
as
np
import
numpy
as
np
class
GuiMainWindow
(
QMainWindow
):
class
GuiMainWindow
(
QMainWindow
):
def
__init__
(
self
):
def
__init__
(
self
):
super
()
.
__init__
()
super
()
.
__init__
()
# self.__init__
#self.__init__
self
.
counter
=
0
self
.
counter
=
0
self
.
frames_checker_timer
=
QtCore
.
QTimer
()
self
.
frames_checker_timer
=
QtCore
.
QTimer
()
self
.
initUI
()
self
.
initUI
()
def
initUI
(
self
):
def
initUI
(
self
):
self
.
win
=
QtGui
.
QMainWindow
()
self
.
win
=
QtGui
.
QMainWindow
()
self
.
win
.
setWindowTitle
(
'Toy GUI'
)
self
.
win
.
setWindowTitle
(
"Toy GUI"
)
self
.
win
.
resize
(
1000
,
500
)
self
.
win
.
resize
(
1000
,
500
)
self
.
area
=
dockarea
.
DockArea
()
self
.
area
=
dockarea
.
DockArea
()
self
.
win
.
setCentralWidget
(
self
.
area
)
self
.
win
.
setCentralWidget
(
self
.
area
)
self
.
cw
=
QtGui
.
QWidget
()
self
.
cw
=
QtGui
.
QWidget
()
self
.
win
.
show
()
self
.
win
.
show
()
self
.
d1
=
dockarea
.
Dock
(
"Zyla Camera View"
)
self
.
d1
=
dockarea
.
Dock
(
"Zyla Camera Control"
)
self
.
d2
=
dockarea
.
Dock
(
"Zyla Camera Analysis"
)
self
.
d2
=
dockarea
.
Dock
(
"Zyla Camera Analysis"
)
self
.
d3
=
dockarea
.
Dock
(
"Zyla Camera Control"
)
self
.
area
.
addDock
(
self
.
d1
)
self
.
d4
=
dockarea
.
Dock
(
"Measurement and saving"
)
self
.
area
.
addDock
(
self
.
d2
,
'left'
,
self
.
d1
)
self
.
area
.
addDock
(
self
.
d1
)
self
.
area
.
addDock
(
self
.
d2
,
"left"
,
self
.
d1
)
self
.
area
.
addDock
(
self
.
d3
,
"right"
,
self
.
d1
)
self
.
area
.
addDock
(
self
.
d4
,
"bottom"
,
self
.
d3
)
## button spinbox and label
## button spinbox and label
self
.
cameraButton
=
QPushButton
(
'Acquisition'
)
self
.
cameraButton
=
QPushButton
(
"Start Acquisition"
)
self
.
d1
.
addWidget
(
self
.
cameraButton
)
self
.
isCameraAcquiring
=
False
self
.
sb
=
pg
.
SpinBox
(
min
=
0
)
self
.
d3
.
addWidget
(
self
.
cameraButton
)
self
.
d1
.
addWidget
(
self
.
sb
)
self
.
label
=
QLabel
(
"Counter of frames"
)
self
.
label
=
QLabel
(
'nada'
)
self
.
d1
.
addWidget
(
self
.
label
)
self
.
d1
.
addWidget
(
self
.
label
)
#layouts and viewboxes
self
.
param_tree
=
CameraParameterTree
()
self
.
d3
.
addWidget
(
self
.
param_tree
.
t
)
# layouts and viewboxes
self
.
ImageLayout
=
pg
.
GraphicsLayoutWidget
()
self
.
ImageLayout
=
pg
.
GraphicsLayoutWidget
()
self
.
view
=
self
.
ImageLayout
.
addViewBox
()
self
.
view
=
self
.
ImageLayout
.
addViewBox
()
self
.
AnalysisLayout
=
pg
.
GraphicsLayoutWidget
()
self
.
AnalysisLayout
=
pg
.
GraphicsLayoutWidget
()
#image layout
# image layout
self
.
img
=
pg
.
ImageItem
(
border
=
'w'
)
self
.
img
=
pg
.
ImageItem
(
border
=
"w"
)
self
.
imv
=
pg
.
ImageView
(
imageItem
=
self
.
img
,
view
=
self
.
view
)
self
.
imv
=
pg
.
ImageView
(
imageItem
=
self
.
img
,
view
=
self
.
view
)
self
.
imv
.
ui
.
roiBtn
.
setText
(
'Useless'
)
self
.
d1
.
addWidget
(
self
.
imv
)
self
.
d1
.
addWidget
(
self
.
imv
)
#analysis layout
#
analysis layout
self
.
d2
.
addWidget
(
self
.
AnalysisLayout
)
self
.
d2
.
addWidget
(
self
.
AnalysisLayout
)
self
.
p
=
self
.
AnalysisLayout
.
addPlot
(
row
=
0
,
col
=
0
,
title
=
"Time plot"
)
self
.
p
=
self
.
AnalysisLayout
.
addPlot
(
row
=
0
,
col
=
0
,
title
=
"Time plot"
)
self
.
p
.
setRange
(
QtCore
.
QRectF
(
0
,
0
,
50
,
255
))
self
.
p
.
setRange
(
QtCore
.
QRectF
(
0
,
0
,
50
,
255
))
self
.
p
.
setAutoPan
(
y
=
True
)
self
.
p
.
setAutoPan
(
y
=
True
)
#self.p.setRange(xRange = (0, 10), yRange = (0, 255))
# self.p.setRange(xRange = (0, 10), yRange = (0, 255))
self
.
curve
=
self
.
p
.
plot
(
pen
=
'y'
)
self
.
curve
=
self
.
p
.
plot
(
pen
=
"y"
)
## rOI
## rOI
self
.
rois
=
[]
self
.
rois
=
[]
self
.
rois
.
append
(
pg
.
TestROI
([
0
,
0
],
[
10
,
10
],
pen
=
(
0
,
9
)))
self
.
rois
.
append
(
pg
.
TestROI
([
0
,
0
],
[
10
,
10
],
pen
=
(
0
,
9
)))
for
r
in
self
.
rois
:
for
r
in
self
.
rois
:
self
.
view
.
addItem
(
r
)
self
.
view
.
addItem
(
r
)
#r.sigRegionChanged.connect(self.updateRoi)
#
r.sigRegionChanged.connect(self.updateRoi)
self
.
ROIdata
=
np
.
zeros
(
100
)
self
.
ROIdata
=
np
.
zeros
(
100
0
)
self
.
iROIdata
=
0
self
.
iROIdata
=
0
self
.
_initialize_image
()
self
.
_initialize_image
()
def
make_connections
(
self
,
backend
):
def
make_connections
(
self
,
backend
):
##backend connections
##backend connections
backend
.
imageReadySignal
.
connect
(
self
.
updateImage
)
backend
.
imageReadySignal
.
connect
(
self
.
updateImage
)
##internal connections
##internal connections
self
.
frames_checker_timer
.
timeout
.
connect
(
self
.
frame_counter
)
self
.
frames_checker_timer
.
timeout
.
connect
(
self
.
frame_counter
)
self
.
cameraButton
.
clicked
.
connect
(
lambda
x
=
backend
.
isCameraAcquiring
:
self
.
camera_button_pressed
(
x
))
self
.
cameraButton
.
clicked
.
connect
(
self
.
camera_button_pressed
def
camera_button_pressed
(
self
,
isCameraAcquiring
):
)
if
isCameraAcquiring
:
def
camera_button_pressed
(
self
):
if
self
.
isCameraAcquiring
:
self
.
frames_checker_timer
.
stop
()
self
.
frames_checker_timer
.
stop
()
self
.
cameraButton
.
setText
(
'Start Acquisition'
)
self
.
isCameraAcquiring
=
False
else
:
else
:
self
.
cameraButton
.
setText
(
'Stop Acquisition'
)
self
.
frame_index
=
0
self
.
frame_index
=
0
self
.
previous_frame_index
=
0
self
.
previous_frame_index
=
0
self
.
frames_checker_timer
.
start
(
1000
)
self
.
frames_checker_timer
.
start
(
1000
)
self
.
isCameraAcquiring
=
True
def
_initialize_image
(
self
):
def
_initialize_image
(
self
):
## lock the aspect ratio so pixels are always square
## lock the aspect ratio so pixels are always square
self
.
view
.
setAspectLocked
(
True
)
self
.
view
.
setAspectLocked
(
True
)
self
.
view
.
addItem
(
self
.
img
)
self
.
view
.
addItem
(
self
.
img
)
self
.
frame_index
=
0
self
.
frame_index
=
0
self
.
previous_frame_index
=
0
self
.
previous_frame_index
=
0
self
.
frames_checker_timer
.
start
(
1000
)
self
.
frames_checker_timer
.
start
(
1000
)
def
updateRois
(
self
):
def
updateRois
(
self
):
for
roi
in
self
.
rois
:
for
roi
in
self
.
rois
:
self
.
lastRoi
=
roi
self
.
lastRoi
=
roi
roiSlice
=
roi
.
getArrayRegion
(
self
.
img
.
image
,
img
=
self
.
img
)
roiSlice
=
roi
.
getArrayRegion
(
self
.
img
.
image
,
img
=
self
.
img
)
self
.
newData
=
np
.
mean
(
roiSlice
)
self
.
newData
=
np
.
mean
(
roiSlice
)
self
.
ROIdata
[
self
.
iROIdata
]
=
self
.
newData
self
.
ROIdata
[
self
.
iROIdata
]
=
self
.
newData
self
.
iROIdata
=
np
.
mod
(
self
.
frame_index
+
1
,
len
(
self
.
ROIdata
))
self
.
iROIdata
=
np
.
mod
(
self
.
frame_index
+
1
,
len
(
self
.
ROIdata
))
self
.
curve
.
setData
(
self
.
ROIdata
)
self
.
curve
.
setData
(
self
.
ROIdata
)
@
QtCore
.
pyqtSlot
(
np
.
ndarray
,
int
)
@
QtCore
.
pyqtSlot
(
np
.
ndarray
,
int
)
def
updateImage
(
self
,
image
,
acq_index
):
def
updateImage
(
self
,
image
,
acq_index
):
if
self
.
frame_index
is
not
0
and
not
self
.
frame_index
==
acq_index
:
if
self
.
frame_index
is
not
0
and
not
self
.
frame_index
==
acq_index
:
print
(
'Dephasing in camera gui has occured: while frame index is
%
i, the acq index is
%
i'
%
(
self
.
frame_index
,
acq_index
))
print
(
"Dephasing in camera gui has occured: while frame index is
%
i, the acq index is
%
i"
#n = 1024
%
(
self
.
frame_index
,
acq_index
)
)
# n = 1024
self
.
img
.
setImage
(
image
)
self
.
img
.
setImage
(
image
)
self
.
updateRois
()
self
.
updateRois
()
self
.
frame_index
=
self
.
frame_index
+
1
self
.
frame_index
=
self
.
frame_index
+
1
def
frame_counter
(
self
):
def
frame_counter
(
self
):
self
.
counter
=
self
.
counter
+
1
self
.
counter
=
self
.
counter
+
1
self
.
label
.
setText
(
'Frames in last second: '
+
str
(
self
.
frame_index
-
self
.
previous_frame_index
)
+
' '
+
'Seconds since start: '
+
str
(
self
.
counter
))
self
.
label
.
setText
(
"Frames in last second: "
+
str
(
self
.
frame_index
-
self
.
previous_frame_index
)
+
" "
+
"Seconds since start: "
+
str
(
self
.
counter
)
)
self
.
previous_frame_index
=
self
.
frame_index
self
.
previous_frame_index
=
self
.
frame_index
def
__del__
(
self
):
def
__del__
(
self
):
print
(
'chau gui'
)
print
(
"chau gui"
)
###############################################################################
###############################################################################
if
__name__
==
'__main__'
:
if
__name__
==
"__main__"
:
app
=
QtGui
.
QApplication
([])
app
=
QtGui
.
QApplication
([])
myGuiMainWIndow
=
GuiMainWindow
()
myGuiMainWIndow
=
GuiMainWindow
()
cameraWorker
=
CameraWorker
()
cameraWorker
=
CameraWorker
()
cameraWorker
.
make_connections
(
myGuiMainWIndow
)
cameraWorker
.
make_connections
(
myGuiMainWIndow
)
myGuiMainWIndow
.
make_connections
(
cameraWorker
)
myGuiMainWIndow
.
make_connections
(
cameraWorker
)
cameraThread
=
QtCore
.
QThread
()
cameraThread
=
QtCore
.
QThread
()
cameraWorker
.
moveToThread
(
cameraThread
)
cameraWorker
.
moveToThread
(
cameraThread
)
cameraThread
.
start
()
cameraThread
.
start
()
sys
.
exit
(
app
.
exec_
())
sys
.
exit
(
app
.
exec_
())
\ No newline at end of file
cameraParameterTree.py
View file @
07ac6e35
...
@@ -22,18 +22,19 @@ app = QtGui.QApplication([])
...
@@ -22,18 +22,19 @@ app = QtGui.QApplication([])
class
BasicAcquisitonParameters
(
pTypes
.
GroupParameter
):
class
BasicAcquisitonParameters
(
pTypes
.
GroupParameter
):
def
__init__
(
self
,
**
opts
):
def
__init__
(
self
,
**
opts
):
pTypes
.
GroupParameter
.
__init__
(
self
,
**
opts
)
super
()
.
__init__
(
**
opts
)
self
.
addChild
({
'name'
:
'Camera name'
,
'type'
:
'str'
,
'value'
:
' '
,
'readonly'
:
True
})
self
.
addChild
({
'name'
:
'Acquisition mode'
,
'type'
:
'list'
,
'values'
:
[
'acq1'
,
'acq2'
]})
self
.
addChild
({
'name'
:
'Acquisition mode'
,
'type'
:
'list'
,
'values'
:
[
'acq1'
,
'acq2'
]})
self
.
addChild
({
'name'
:
'Pixel Binning'
,
'type'
:
'list'
,
'values'
:
[
'1x1'
,
'2x2'
,
'4x4'
,
'8x8'
]})
self
.
addChild
({
'name'
:
'Pixel Binning'
,
'type'
:
'list'
,
'values'
:
[
'1x1'
,
'2x2'
,
'4x4'
,
'8x8'
]})
self
.
addChild
({
'name'
:
'Image Area'
,
'type'
:
'list'
,
'values'
:
[
'2048x2048'
,
'1024x1024'
,
'512x512'
,
'256x256'
],
'readonly'
:
True
})
self
.
addChild
({
'name'
:
'Image Area'
,
'type'
:
'list'
,
'values'
:
[
'2048x2048'
,
'1024x1024'
,
'512x512'
,
'256x256'
],
'readonly'
:
True
})
self
.
addChild
({
'name'
:
'Exposure Time'
,
'type'
:
'float'
,
'value'
:
.1
,
'suffix'
:
's'
,
'siPrefix'
:
True
,
'step'
:
0.05
})
self
.
addChild
({
'name'
:
'Exposure Time'
,
'type'
:
'float'
,
'value'
:
.1
,
'suffix'
:
's'
,
'siPrefix'
:
True
,
'step'
:
0.05
})
self
.
addChild
({
'name'
:
'Frame Rate'
,
'type'
:
'float'
,
'value'
:
10
})
self
.
addChild
({
'name'
:
'Frame Rate'
,
'type'
:
'float'
,
'value'
:
10
,
'readonly'
:
True
})
#exposure time and frame rate connected because they are the inverse of each other
#exposure time and frame rate connected because they are the inverse of each other
#later, they should be set so that the framerate is the maximum possible value given an exposure time
self
.
exposureTimeWidget
=
self
.
param
(
'Exposure Time'
)
self
.
exposureTimeWidget
=
self
.
param
(
'Exposure Time'
)
self
.
frameRateWidget
=
self
.
param
(
'Frame Rate'
)
self
.
frameRateWidget
=
self
.
param
(
'Frame Rate'
)
self
.
exposureTimeWidget
.
sigValueChanged
.
connect
(
self
.
expTimeChanged
)
self
.
exposureTimeWidget
.
sigValueChanged
.
connect
(
self
.
expTimeChanged
)
...
@@ -41,9 +42,7 @@ class BasicAcquisitonParameters(pTypes.GroupParameter):
...
@@ -41,9 +42,7 @@ class BasicAcquisitonParameters(pTypes.GroupParameter):
#set image area according to binning
#set image area according to binning
self
.
param
(
'Pixel Binning'
)
.
sigValueChanged
.
connect
(
self
.
binningChanged
)
self
.
param
(
'Pixel Binning'
)
.
sigValueChanged
.
connect
(
self
.
binningChanged
)
def
expTimeChanged
(
self
):
def
expTimeChanged
(
self
):
self
.
frameRateWidget
.
setValue
(
1.0
/
self
.
exposureTimeWidget
.
value
(),
blockSignal
=
self
.
frameRateChanged
)
self
.
frameRateWidget
.
setValue
(
1.0
/
self
.
exposureTimeWidget
.
value
(),
blockSignal
=
self
.
frameRateChanged
)
...
@@ -62,100 +61,61 @@ class BasicAcquisitonParameters(pTypes.GroupParameter):
...
@@ -62,100 +61,61 @@ class BasicAcquisitonParameters(pTypes.GroupParameter):
self
.
param
(
'Image Area'
)
.
setValue
(
'256x256'
)
self
.
param
(
'Image Area'
)
.
setValue
(
'256x256'
)
class
BasicActionParameters
(
pTypes
.
GroupParameter
):
params
=
[
def
__init__
(
self
,
**
opts
):
BasicAcquisitonParameters
(
name
=
'Basic acq parameters'
),
super
()
.
__init__
(
**
opts
)
{
'name'
:
'Basic parameter data types'
,
'type'
:
'group'
,
'children'
:
[
self
.
addChild
({
'name'
:
'Save State'
,
'type'
:
'action'
})
{
'name'
:
'Integer'
,
'type'
:
'int'
,
'value'
:
10
},
self
.
addChild
({
'name'
:
'Restore State'
,
'type'
:
'action'
})
{
'name'
:
'Float'
,
'type'
:
'float'
,
'value'
:
10.5
,
'step'
:
0.1
},
{
'name'
:
'String'
,
'type'
:
'str'
,
'value'
:
"hi"
},
{
'name'
:
'List'
,
'type'
:
'list'
,
'values'
:
[
1
,
2
,
3
],
'value'
:
2
},
{
'name'
:
'Named List'
,
'type'
:
'list'
,
'values'
:
{
"one"
:
1
,
"two"
:
"twosies"
,
"three"
:
[
3
,
3
,
3
]},
'value'
:
2
},
{
'name'
:
'Boolean'
,
'type'
:
'bool'
,
'value'
:
True
,
'tip'
:
"This is a checkbox"
},
{
'name'
:
'Color'
,
'type'
:
'color'
,
'value'
:
"FF0"
,
'tip'
:
"This is a color button"
},
{
'name'
:
'Gradient'
,
'type'
:
'colormap'
},
{
'name'
:
'Subgroup'
,
'type'
:
'group'
,
'children'
:
[
{
'name'
:
'Sub-param 1'
,
'type'
:
'int'
,
'value'
:
10
},
{
'name'
:
'Sub-param 2'
,
'type'
:
'float'
,
'value'
:
1.2e6
},
]},
{
'name'
:
'Text Parameter'
,
'type'
:
'text'
,
'value'
:
'Some text...'
},
{
'name'
:
'Action Parameter'
,
'type'
:
'action'
},
]},
{
'name'
:
'Numerical Parameter Options'
,
'type'
:
'group'
,
'children'
:
[
{
'name'
:
'Units + SI prefix'
,
'type'
:
'float'
,
'value'
:
1.2e-6
,
'step'
:
1e-6
,
'siPrefix'
:
True
,
'suffix'
:
'V'
},
{
'name'
:
'Limits (min=7;max=15)'
,
'type'
:
'int'
,
'value'
:
11
,
'limits'
:
(
7
,
15
),
'default'
:
-
6
},
{
'name'
:
'DEC stepping'
,
'type'
:
'float'
,
'value'
:
1.2e6
,
'dec'
:
True
,
'step'
:
1
,
'siPrefix'
:
True
,
'suffix'
:
'Hz'
},
]},
{
'name'
:
'Save/Restore functionality'
,
'type'
:
'group'
,
'children'
:
[
{
'name'
:
'Save State'
,
'type'
:
'action'
},
{
'name'
:
'Restore State'
,
'type'
:
'action'
,
'children'
:
[
{
'name'
:
'Add missing items'
,
'type'
:
'bool'
,
'value'
:
True
},
{
'name'
:
'Remove extra items'
,
'type'
:
'bool'
,
'value'
:
True
},
]},
]},
{
'name'
:
'Extra Parameter Options'
,
'type'
:
'group'
,
'children'
:
[
{
'name'
:
'Read-only'
,
'type'
:
'float'
,
'value'
:
1.2e6
,
'siPrefix'
:
True
,
'suffix'
:
'Hz'
,
'readonly'
:
True
},
{
'name'
:
'Renamable'
,
'type'
:
'float'
,
'value'
:
1.2e6
,
'siPrefix'
:
True
,
'suffix'
:
'Hz'
,
'renamable'
:
True
},
{
'name'
:
'Removable'
,
'type'
:
'float'
,
'value'
:
1.2e6
,
'siPrefix'
:
True
,
'suffix'
:
'Hz'
,
'removable'
:
True
},
]}
]
## Create tree of Parameter objects
p
=
Parameter
.
create
(
name
=
'params'
,
type
=
'group'
,
children
=
params
)
## If anything changes in the tree, print a message
def
change
(
param
,
changes
):
print
(
"tree changes:"
)
for
param
,
change
,
data
in
changes
:
path
=
p
.
childPath
(
param
)
if
path
is
not
None
:
childName
=
'.'
.
join
(
path
)
else
:
childName
=
param
.
name
()
print
(
' parameter:
%
s'
%
childName
)
print
(
' change:
%
s'
%
change
)
print
(
' data:
%
s'
%
str
(
data
))
print
(
' ----------'
)
p
.
sigTreeStateChanged
.
connect
(
change
)
class
CameraParameterTree
(
ParameterTree
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
params
=
[
BasicAcquisitonParameters
(
name
=
'Basic acq parameters'
),
BasicActionParameters
(
name
=
'Save/Restore functionality'
)
]
self
.
p
=
Parameter
.
create
(
name
=
'params'
,
type
=
'group'
,
children
=
self
.
params
)
def
save
():
self
.
p
.
sigTreeStateChanged
.
connect
(
self
.
change
)
global
state
self
.
p
.
param
(
'Save/Restore functionality'
,
'Save State'
)
.
sigActivated
.
connect
(
self
.
save
)
state
=
p
.
saveState
()
self
.
p
.
param
(
'Save/Restore functionality'
,
'Restore State'
)
.
sigActivated
.
connect
(
self
.
restore
)
self
.
t
=
ParameterTree
()
self
.
t
.
setParameters
(
self
.
p
,
showTop
=
False
)
self
.
t
.
setWindowTitle
(
'Parameter Tree'
)
def
restore
():
def
change
(
self
,
param
,
changes
):
global
state
print
(
"tree changes:"
)
add
=
p
[
'Save/Restore functionality'
,
'Restore State'
,
'Add missing items'
]
for
param
,
change
,
data
in
changes
:
rem
=
p
[
'Save/Restore functionality'
,
'Restore State'
,
'Remove extra items'
]
path
=
self
.
p
.
childPath
(
param
)
p
.
restoreState
(
state
,
addChildren
=
add
,
removeChildren
=
rem
)
if
path
is
not
None
:
p
.
param
(
'Save/Restore functionality'
,
'Save State'
)
.
sigActivated
.
connect
(
save
)
childName
=
'.'
.
join
(
path
)
p
.
param
(
'Save/Restore functionality'
,
'Restore State'
)
.
sigActivated
.
connect
(
restore
)
else
:
childName
=
param
.
name
()
print
(
' parameter:
%
s'
%
childName
)
## Create two ParameterTree widgets, both accessing the same data
print
(
' change:
%
s'
%
change
)
t
=
ParameterTree
()
print
(
' data:
%
s'
%
str
(
data
))
t
.
setParameters
(
p
,
showTop
=
False
)
print
(
' ----------'
)
t
.
setWindowTitle
(
'Parameter Tree'
)
def
save
(
self
):
win
=
QtGui
.
QWidget
()
self
.
state
=
self
.
p
.
saveState
()
layout
=
QtGui
.
QGridLayout
()
win
.
setLayout
(
layout
)
def
restore
(
self
):
layout
.
addWidget
(
QtGui
.
QLabel
(
"Explanation of parameter tree."
),
0
,
0
,
1
,
2
)
self
.
p
.
restoreState
(
self
.
state
)
layout
.
addWidget
(
t
)
win
.
show
()
win
.
resize
(
400
,
800
)
## test save/restore
s
=
p
.
saveState
()
p
.
restoreState
(
s
)
## Start Qt event loop unless running in interactive mode or using pyside.
## Start Qt event loop unless running in interactive mode or using pyside.
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
import
sys
import
sys
param_tree
=
CameraParameterTree
()
win
=
QtGui
.
QWidget
()
layout
=
QtGui
.
QGridLayout
()
win
.
setLayout
(
layout
)
layout
.
addWidget
(
QtGui
.
QLabel
(
"Explanation of parameter tree."
),
0
,
0
,
1
,
2
)
layout
.
addWidget
(
param_tree
.
t
)
win
.
show
()
win
.
resize
(
400
,
800
)
if
(
sys
.
flags
.
interactive
!=
1
)
or
not
hasattr
(
QtCore
,
'PYQT_VERSION'
):
if
(
sys
.
flags
.
interactive
!=
1
)
or
not
hasattr
(
QtCore
,
'PYQT_VERSION'
):
QtGui
.
QApplication
.
instance
()
.
exec_
()
QtGui
.
QApplication
.
instance
()
.
exec_
()
dummyAndor.py
View file @
07ac6e35
...
@@ -9,75 +9,83 @@ import numpy as np
...
@@ -9,75 +9,83 @@ import numpy as np
from
PyQt5
import
QtCore
from
PyQt5
import
QtCore
import
time
import
time
import
threading
import
threading
from
queue
import
Queue
class
Helper_messager
(
QtCore
.
QObject
):
class
Helper_messager
(
QtCore
.
QObject
):
imageAquiredSignal
=
QtCore
.
pyqtSignal
(
int
)
imageAquiredSignal
=
QtCore
.
pyqtSignal
(
int
)
class
AndorZyla
():
class
AndorZyla
:
def
__init__
(
self
,
num
):
def
__init__
(
self
,
num
):
self
.
ExposureTime
=
AndorFeats
()
self
.
ExposureTime
=
AndorFeats
()
self
.
FrameRate
=
AndorFeats
()
self
.
FrameRate
=
AndorFeats
()
self
.
CameraAcquiring
=
AndorFeats
()
self
.
CameraAcquiring
=
AndorFeats
()
self
.
Binning
=
AndorFeats
()
self
.
ImageArea
=
AndorFeats
()
self
.
CameraName
=
'Dummy'
self
.
acq_queue
=
Queue
(
maxsize
=
5
)
self
.
helper
=
Helper_messager
()
self
.
helper
=
Helper_messager
()
self
.
current_image
=
None
self
.
current_image
=
None
self
.
CameraAcquiring
.
setValue
(
False
)
self
.
CameraAcquiring
.
setValue
(
False
)
self
.
acq_index_i
=
0
self
.
acq_index_i
=
0
self
.
ExposureTime
.
setValue
(
0.5
)
self
.
FrameRate
.
setValue
(
10
)
self
.
Binning
.
setValue
(
'1x1'
)
self
.
ImageArea
.
setValue
(
50
)
def
Init
(
self
):
def
Init
(
self
):
print
(
'Dummy camera initialized'
)
print
(
"Dummy camera initialized"
)
def
live_acquisition_loop
(
self
):
def
live_acquisition_loop
(
self
):
t
=
threading
.
currentThread
()
t
=
threading
.
currentThread
()
while
getattr
(
t
,
"do_run"
,
True
):
while
getattr
(
t
,
"do_run"
,
True
):
time
.
sleep
(
self
.
ExposureTime
.
getValue
())
self
.
current_image
=
self
.
_twoD_gaussian
()
self
.
current_image
=
self
.
_twoD_gaussian
()
self
.
acq_queue
.
put
(
self
.
current_image
)
self
.
helper
.
imageAquiredSignal
.
emit
(
self
.
acq_index_i
)
self
.
helper
.
imageAquiredSignal
.
emit
(
self
.
acq_index_i
)
self
.
acq_index_i
=
self
.
acq_index_i
+
1
self
.
acq_index_i
=
self
.
acq_index_i
+
1
print
(
'stopping acq loop thread'
)
time
.
sleep
(
self
.
ExposureTime
.
getValue
()
)
print
(
"stopping acq loop thread"
)
def
live_acquisition_configure
(
self
):
def
live_acquisition_configure
(
self
):
self
.
acq_index_i
=
0
self
.
acq_index_i
=
0
def
AcquisitionStart
(
self
):
def
AcquisitionStart
(
self
):
self
.
CameraAcquiring
.
setValue
(
True
)
self
.
CameraAcquiring
.
setValue
(
True
)
def
AcquisitionStop
(
self
):
def
AcquisitionStop
(
self
):
self
.
CameraAcquiring
.
setValue
(
False
)
self
.
CameraAcquiring
.
setValue
(
False
)
def
_flush
(
self
):
def
_flush
(
self
):
pass
pass
def
_twoD_gaussian
(
self
,
lim
=
10
,
sigma
=
1
,
x0
=
0
,
y0
=
0
):
N
=
self
.
ImageArea
.
getValue
()
def
_twoD_gaussian
(
self
,
lim
=
10
,
N
=
100
,
sigma
=
1
,
x0
=
0
,
y0
=
0
):
x
,
y
=
np
.
meshgrid
(
np
.
linspace
(
-
lim
,
lim
,
N
),
np
.
linspace
(
-
lim
,
lim
,
N
))
x
,
y
=
np
.
meshgrid
(
np
.
linspace
(
-
lim
,
lim
,
N
),
np
.
linspace
(
-
lim
,
lim
,
N
))
d
=
np
.
sqrt
((
x
-
x0
)
**
2
+
(
y
-
y0
)
**
2
)
d
=
np
.
sqrt
((
x
-
x0
)
**
2
+
(
y
-
y0
)
**
2
)
g
=
np
.
exp
(
-
((
d
)
**
2
/
(
2.0
*
sigma
**
2
)))
g
=
np
.
exp
(
-
(
(
d
)
**
2
/
(
2.0
*
sigma
**
2
)
)
)
noise
=
np
.
random
.
rand
(
N
,
N
)
noise
=
np
.
random
.
rand
(
N
,
N
)
return
(
g
+
noise
)
time
.
sleep
(
self
.
ExposureTime
.
getValue
())
return
g
+
noise
class
AndorFeats
():
class
AndorFeats
:
def
__init__
(
self
):
def
__init__
(
self
):
self
.
value
=
None
self
.
value
=
None
def
getValue
(
self
):
def
getValue
(
self
):
return
self
.
value
return
self
.
value
def
setValue
(
self
,
val
):
def
setValue
(
self
,
val
):
self
.
value
=
val
self
.
value
=
val
def
_twoD_gaussian
(
self
,
lim
=
10
,
N
=
100
,
sigma
=
1
,
x0
=
0
,
y0
=
0
):
x
,
y
=
np
.
meshgrid
(
np
.
linspace
(
-
lim
,
lim
,
N
),
np
.
linspace
(
-
lim
,
lim
,
N
))
d
=
np
.
sqrt
((
x
-
x0
)
**
2
+
(
y
-
y0
)
**
2
)
def
_twoD_gaussian
(
self
,
lim
=
10
,
N
=
100
,
sigma
=
1
,
x0
=
0
,
y0
=
0
):
g
=
np
.
exp
(
-
((
d
)
**
2
/
(
2.0
*
sigma
**
2
)))
x
,
y
=
np
.
meshgrid
(
np
.
linspace
(
-
lim
,
lim
,
N
),
np
.
linspace
(
-
lim
,
lim
,
N
))
d
=
np
.
sqrt
((
x
-
x0
)
**
2
+
(
y
-
y0
)
**
2
)
g
=
np
.
exp
(
-
(
(
d
)
**
2
/
(
2.0
*
sigma
**
2
)
)
)
noise
=
np
.
random
.
rand
(
N
,
N
)
noise
=
np
.
random
.
rand
(
N
,
N
)
return
(
g
+
noise
)
return
g
+
noise
\ No newline at end of file
zylaCameraWorker.py
View file @
07ac6e35
...
@@ -10,7 +10,8 @@ Created on Thu Apr 4 11:10:20 2019
...
@@ -10,7 +10,8 @@ Created on Thu Apr 4 11:10:20 2019
import
numpy
as
np
import
numpy
as
np
from
PyQt5
import
QtCore
from
PyQt5
import
QtCore
#from drivers.andorzyla import AndorZyla
# from drivers.andorzyla import AndorZyla
from
dummyAndor
import
AndorZyla
from
dummyAndor
import
AndorZyla
import
threading
import
threading
...
@@ -18,55 +19,43 @@ import threading
...
@@ -18,55 +19,43 @@ import threading
class
CameraWorker
(
QtCore
.
QObject
):
class
CameraWorker
(
QtCore
.
QObject
):
imageReadySignal
=
QtCore
.
pyqtSignal
(
np
.
ndarray
,
int
)
imageReadySignal
=
QtCore
.
pyqtSignal
(
np
.
ndarray
,
int
)
def
__init__
(
self
):
super
()
.
__init__
()
def
__init__
(
self
):
super
(
CameraWorker
,
self
)
.
__init__
()
self
.
cam
=
AndorZyla
(
0
)
self
.
cam
=
AndorZyla
(
0
)
self
.
cam
.
Init
()
self
.
cam
.
Init
()
self
.
cam
.
ExposureTime
.
setValue
(
.1
)
#self.cam.ExposureTime.setValue(0.1)
print
(
"camera worker initialized"
)
self
.
isCameraAcquiring
=
False
print
(
'camera worker initialized'
)
def
make_connections
(
self
,
frontend
):
def
make_connections
(
self
,
frontend
):
#frontend connections
# frontend connections
frontend
.
cameraButton
.
clicked
.
connect
(
self
.
run
)
params
=
frontend
.
param_tree
.
p
frontend
.
sb
.
valueChanged
.
connect
(
lambda
x
=
frontend
.
sb
.
value
():
self
.
cam
.
ExposureTime
.
setValue
(
x
))
frontend
.
cameraButton
.
clicked
.
connect
(
lambda
:
self
.
run
(
params
))
# internal connections
#internal connections
self
.
cam
.
helper
.
imageAquiredSignal
.
connect
(
self
.
new_image_acquired
)
self
.
cam
.
helper
.
imageAquiredSignal
.
connect
(
self
.
new_image_acquired
)
def
__del__
(
self
):
def
__del__
(
self
):
print
(
'adios camera worker'
)
print
(
"adios camera worker"
)
#@QtCore.pyqtSlot()
@
QtCore
.
pyqtSlot
()
def
run
(
self
,
params
):
def
run
(
self
):
if
self
.
cam
.
CameraAcquiring
.
getValue
():
if
self
.
cam
.
CameraAcquiring
.
getValue
():
self
.
_stop_acquisition_loop
()
self
.
_stop_acquisition_loop
()
self
.
isCameraAcquiring
=
False
print
(
"acquisition now stopping"
)
print
(
'acquisition now stopping'
)
else
:
else
:
self
.
_configure_acq_parameters
(
params
)
self
.
_start_acquisition_loop
()
self
.
_start_acquisition_loop
()
self
.
acq_thread
=
threading
.
Thread
(
target
=
self
.
cam
.
live_acquisition_loop
)
self
.
acq_thread
=
threading
.
Thread
(
target
=
self
.
cam
.
live_acquisition_loop
)
self
.
acq_thread
.
start
()
self
.
acq_thread
.
start
()
print
(
'acquisiting now starting'
)
print
(
"acquisiting now starting"
)
self
.
isCameraAcquiring
=
True
def
_start_acquisition_loop
(
self
):
def
_start_acquisition_loop
(
self
):
self
.
cam
.
live_acquisition_configure
()
self
.
cam
.
live_acquisition_configure
()
self
.
cam
.
AcquisitionStart
()
self
.
cam
.
AcquisitionStart
()
print
(
'frame rate: '
,
self
.
cam
.
FrameRate
.
getValue
())
print
(
"frame rate: "
,
self
.
cam
.
FrameRate
.
getValue
())
print
(
'Exp time: '
,
self
.
cam
.
ExposureTime
.
getValue
())
print
(
"Exp time: "
,
self
.
cam
.
ExposureTime
.
getValue
())
def
_stop_acquisition_loop
(
self
):
def
_stop_acquisition_loop
(
self
):
self
.
acq_thread
.
do_run
=
False
self
.
acq_thread
.
do_run
=
False
self
.
acq_thread
.
join
()
self
.
acq_thread
.
join
()
...
@@ -74,8 +63,19 @@ class CameraWorker(QtCore.QObject):
...
@@ -74,8 +63,19 @@ class CameraWorker(QtCore.QObject):
self
.
cam
.
_flush
()
self
.
cam
.
_flush
()
def
_configure_acq_parameters
(
self
,
params
):
print
(
'Acq parameters: '
)
for
p
in
params
.
children
()[
0
]
.
children
():
print
(
p
.
name
(),
p
.
value
())
params
.
child
(
'Basic acq parameters'
)
.
child
(
'Camera name'
)
.
setValue
(
self
.
cam
.
CameraName
)
self
.
cam
.
ExposureTime
.
setValue
(
params
.
child
(
'Basic acq parameters'
)
.
child
(
'Exposure Time'
)
.
value
()
)
@
QtCore
.
pyqtSlot
(
int
)
@
QtCore
.
pyqtSlot
(
int
)
def
new_image_acquired
(
self
,
acq_index
):
def
new_image_acquired
(
self
,
acq_index
):
self
.
imageReadySignal
.
emit
(
self
.
cam
.
current_image
,
acq_index
)
self
.
imageReadySignal
.
emit
(
self
.
cam
.
acq_queue
.
get
(),
acq_index
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment