Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
GEPARD
GEPARD
Commits
f0ab34e7
Commit
f0ab34e7
authored
Jul 11, 2019
by
JosefBrandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Particle Reassignment works
parent
b8f6f661
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
341 additions
and
344 deletions
+341
-344
analysis/analysisview.py
analysis/analysisview.py
+1
-0
analysis/particleInfo.py
analysis/particleInfo.py
+10
-1
analysis/particleeditor.py
analysis/particleeditor.py
+169
-134
external/__init__.py
external/__init__.py
+0
-0
ramancom/__init__.py
ramancom/__init__.py
+0
-0
sampleview.py
sampleview.py
+19
-64
viewitems.py
viewitems.py
+142
-145
No files found.
analysis/analysisview.py
View file @
f0ab34e7
...
@@ -399,6 +399,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
...
@@ -399,6 +399,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
t0
=
time
.
time
()
t0
=
time
.
time
()
self
.
updateLegend
()
self
.
updateLegend
()
print
(
'update legend:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
print
(
'update legend:'
,
round
((
time
.
time
()
-
t0
)
*
1000
))
self
.
dataset
.
save
()
def
initializeSpecPlot
(
self
):
def
initializeSpecPlot
(
self
):
self
.
specPlot
.
loadSpectraAndInitializeSpecPlot
()
self
.
specPlot
.
loadSpectraAndInitializeSpecPlot
()
...
...
analysis/particleInfo.py
View file @
f0ab34e7
...
@@ -94,7 +94,7 @@ class ParticleContainer(object):
...
@@ -94,7 +94,7 @@ class ParticleContainer(object):
meas
.
setAssignment
(
assignmentList
[
scanIndex
])
meas
.
setAssignment
(
assignmentList
[
scanIndex
])
indicesOfTransferredAssignments
[
scanIndex
]
=
scanIndex
indicesOfTransferredAssignments
[
scanIndex
]
=
scanIndex
assert
not
None
in
indicesOfTransferredAssignments
assert
not
None
in
indicesOfTransferredAssignments
def
applyHQIListToParticleMeasurements
(
self
,
hqiList
):
def
applyHQIListToParticleMeasurements
(
self
,
hqiList
):
'''HQI-List is list of spectra hqis in order of spectra indices'''
'''HQI-List is list of spectra hqis in order of spectra indices'''
indicesOfTransferredHQIs
=
[
None
]
*
len
(
hqiList
)
indicesOfTransferredHQIs
=
[
None
]
*
len
(
hqiList
)
...
@@ -105,6 +105,10 @@ class ParticleContainer(object):
...
@@ -105,6 +105,10 @@ class ParticleContainer(object):
indicesOfTransferredHQIs
[
scanIndex
]
=
scanIndex
indicesOfTransferredHQIs
[
scanIndex
]
=
scanIndex
assert
not
None
in
indicesOfTransferredHQIs
assert
not
None
in
indicesOfTransferredHQIs
def
reassignParticleToAssignment
(
self
,
particleIndex
,
newAssignment
):
particle
=
self
.
getParticleOfIndex
(
particleIndex
)
particle
.
setAllSpectraToNewAssignment
(
newAssignment
)
def
getParticleOfIndex
(
self
,
index
):
def
getParticleOfIndex
(
self
,
index
):
particle
=
self
.
particles
[
index
]
particle
=
self
.
particles
[
index
]
assert
particle
.
index
==
index
,
f
'particle.index (
{
particle
.
index
}
) does match requested index in particleList (
{
index
}
)'
assert
particle
.
index
==
index
,
f
'particle.index (
{
particle
.
index
}
) does match requested index in particleList (
{
index
}
)'
...
@@ -236,6 +240,11 @@ class Particle(object):
...
@@ -236,6 +240,11 @@ class Particle(object):
self
.
measurements
[
indexOfMeasurment
].
pixelcoord_x
=
x
self
.
measurements
[
indexOfMeasurment
].
pixelcoord_x
=
x
self
.
measurements
[
indexOfMeasurment
].
pixelcoord_y
=
y
self
.
measurements
[
indexOfMeasurment
].
pixelcoord_y
=
y
def
setAllSpectraToNewAssignment
(
self
,
newAssignment
):
for
meas
in
self
.
measurements
:
meas
.
setAssignment
(
newAssignment
)
meas
.
setHQI
(
100
)
def
getParticleAssignment
(
self
):
def
getParticleAssignment
(
self
):
return
self
.
getMeasAssignmentWithHighestHQI
()
#probably another method could be more suitable...
return
self
.
getMeasAssignmentWithHighestHQI
()
#probably another method could be more suitable...
...
...
analysis/particleeditor.py
View file @
f0ab34e7
...
@@ -27,133 +27,189 @@ If not, see <https://www.gnu.org/licenses/>.
...
@@ -27,133 +27,189 @@ If not, see <https://www.gnu.org/licenses/>.
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
from
PyQt5
import
QtWidgets
from
PyQt5
import
QtWidgets
,
QtCore
class
ParticleEditor
(
object
):
class
ParticleContextMenu
(
QtWidgets
.
QMenu
):
def
__init__
(
self
,
particleContainer
,
parent
):
combineParticlesSignal
=
QtCore
.
pyqtSignal
(
list
,
str
)
reassignParticlesSignal
=
QtCore
.
pyqtSignal
(
list
,
str
)
def
__init__
(
self
,
sampleView
):
super
(
ParticleContextMenu
,
self
).
__init__
()
self
.
sampleView
=
sampleView
self
.
selectedParticleIndices
=
self
.
sampleView
.
selectedParticleIndices
self
.
particleContainer
=
self
.
sampleView
.
dataset
.
particleContainer
def
executeAtScreenPos
(
self
,
screenPos
):
self
.
combineActs
=
[]
self
.
combineMenu
=
QtWidgets
.
QMenu
(
"Combine Particles into"
)
assignments
=
[]
for
particleIndex
in
self
.
selectedParticleIndices
:
assignment
=
self
.
particleContainer
.
getParticleAssignmentByIndex
(
particleIndex
)
assignments
.
append
(
assignment
)
for
assignment
in
np
.
unique
(
assignments
):
self
.
combineActs
.
append
(
self
.
combineMenu
.
addAction
(
assignment
))
self
.
combineActs
.
append
(
self
.
combineMenu
.
addAction
(
"other"
))
self
.
reassignActs
=
[]
self
.
reassignMenu
=
QtWidgets
.
QMenu
(
"Reassign particle(s) into"
)
for
polymType
in
self
.
particleContainer
.
getUniquePolymers
():
self
.
reassignActs
.
append
(
self
.
reassignMenu
.
addAction
(
polymType
))
self
.
reassignActs
.
append
(
self
.
reassignMenu
.
addAction
(
"other"
))
numParticles
=
len
(
self
.
selectedParticleIndices
)
if
numParticles
==
0
:
self
.
reassignMenu
.
setDisabled
(
True
)
self
.
combineMenu
.
setDisabled
(
True
)
elif
numParticles
==
1
:
self
.
combineMenu
.
setDisabled
(
True
)
self
.
addMenu
(
self
.
combineMenu
)
self
.
addMenu
(
self
.
reassignMenu
)
action
=
self
.
exec_
(
screenPos
)
if
action
in
self
.
combineActs
:
newAssignment
=
action
.
text
()
self
.
combineParticlesSignal
.
emit
(
self
.
selectedParticleIndices
,
newAssignment
)
elif
action
in
self
.
reassignActs
:
newAssignment
=
action
.
text
()
self
.
reassignParticlesSignal
.
emit
(
self
.
selectedParticleIndices
,
newAssignment
)
class
ParticleEditor
(
QtCore
.
QObject
):
particlesWereEdited
=
QtCore
.
pyqtSignal
()
def
__init__
(
self
,
sampleView
,
particleContainer
):
super
(
ParticleEditor
,
self
).
__init__
()
self
.
particleContainer
=
particleContainer
self
.
particleContainer
=
particleContainer
self
.
parent
=
parent
#the assigned analysis widget
self
.
sampleView
=
sampleView
#the assigned analysis widget
self
.
backupFreq
=
3
#save a backup every n actions
self
.
backupFreq
=
3
#save a backup every n actions
self
.
neverBackedUp
=
True
self
.
neverBackedUp
=
True
self
.
actionCounter
=
0
self
.
actionCounter
=
0
def
connectToSignals
(
self
,
contextMenu
):
contextMenu
.
combineParticlesSignal
.
connect
(
self
.
combineParticles
)
contextMenu
.
reassignParticlesSignal
.
connect
(
self
.
reassignParticles
)
def
createSafetyBackup
(
self
):
def
createSafetyBackup
(
self
):
self
.
actionCounter
+=
1
self
.
actionCounter
+=
1
if
self
.
actionCounter
==
self
.
backupFreq
-
1
or
self
.
neverBackedUp
:
if
self
.
actionCounter
==
self
.
backupFreq
-
1
or
self
.
neverBackedUp
:
backupname
=
self
.
parent
.
dataset
.
saveBackup
()
backupname
=
self
.
sampleView
.
dataset
.
saveBackup
()
print
(
'backing up as'
,
backupname
)
print
(
'backing up as'
,
backupname
)
self
.
neverBackedUp
=
False
self
.
neverBackedUp
=
False
self
.
actionCounter
=
0
self
.
actionCounter
=
0
def
getNewEntry
(
self
):
def
getNewEntry
(
self
):
text
,
okClicked
=
QtWidgets
.
QInputDialog
.
getText
(
self
.
parent
.
parent
,
"Custom assignment"
,
"Enter new assignment"
)
text
,
okClicked
=
QtWidgets
.
QInputDialog
.
getText
(
QtWidgets
.
QWidget
()
,
"Custom assignment"
,
"Enter new assignment"
)
if
okClicked
and
text
!=
''
:
if
okClicked
and
text
!=
''
:
return
text
return
text
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
combineParticles
(
self
,
contourIndices
,
new_assignment
):
def
combineParticles
(
self
,
contourIndices
,
new_assignment
):
if
new_assignment
==
'other'
:
print
(
contourIndices
,
new_assignment
)
new_assignment
=
self
.
getNewEntry
()
if
new_assignment
is
None
:
#
if new_assignment
== 'other'
:
return
#
new_assignment = self.getNewEntry()
#
if new_assignment is None:
contourIndices
=
sorted
(
contourIndices
)
#we want to keep the contour with lowest index
#
return
#get contours:
#
contour
s
=
self
.
particleContainer
.
getParticleContoursByIndex
(
contourIndices
)
#
contour
Indices = sorted(contourIndices) #we want to keep the contour with lowest index
#
contours = [self.datastats.dataset.particlecontours[i] for i in contourIndices]
#
#get contours:
cnt
=
np
.
vstack
(
tuple
(
contours
))
#combine contous
#
c
o
nt
ours = self.particleContainer.getParticleContoursByIndex(contourIndices)
##
contours = [self.datastats.dataset.particlecontours[i] for i in contourIndices]
#draw
contou
r
s
#
cnt = np.vstack(tuple(contours)) #combine
contous
xmin
,
xmax
=
cnt
[:,
0
,:][:,
0
].
min
(),
cnt
[:,
0
,:][:,
0
].
max
()
#
ymin
,
ymax
=
cnt
[:,
0
,:][:,
1
].
min
(),
cnt
[:,
0
,:][:,
1
].
max
()
#
#draw
c
o
nt
ours
#
xmin, xmax = cnt[:,0,:][:, 0].min(), cnt[:,0,:][:, 0].max()
padding
=
2
#pixel in each direction
#
ymin, ymax = cnt[:,0,:][:, 1].min(), cnt[:,0,:][:, 1].max()
rangex
=
int
(
np
.
round
((
xmax
-
xmin
)
+
2
*
padding
))
#
rangey
=
int
(
np
.
round
((
ymax
-
ymin
)
+
2
*
padding
))
#
padding = 2 #pixel in each direction
# rangex = int(np.round((xmax-xmin)+2*padding))
img
=
np
.
zeros
((
rangey
,
rangex
))
#
rangey = int(np.round((ymax-ymin)+2*padding
))
for
i
in
contourIndices
:
#
curCnt
=
self
.
particleContainer
.
getParticleContoursByIndex
(
i
).
copy
(
)
#
img = np.zeros((rangey, rangex)
)
#
curCnt = self.datastats.dataset.particlecontours[i].copy()
#
for i in contourIndices:
for
i
in
range
(
len
(
curCnt
)):
#
curCnt = self.particleContainer.getParticleContoursByIndex(i).copy()
curCnt
[
i
][
0
][
0
]
-=
xmin
-
padding
##
curCnt
= self.datastats.dataset.particlecontours[i].copy()
curCnt
[
i
][
0
][
1
]
-=
ymin
-
padding
#
for i in range(len(curCnt)):
#
curCnt[i][0][0] -= xmin-padding
cv2
.
drawContours
(
img
,
[
curCnt
],
-
1
,
1
,
-
1
)
#
curCnt[i][0][1] -= ymin-padding
cv2
.
drawContours
(
img
,
[
curCnt
],
-
1
,
1
,
1
)
#
#
cv2.drawContours(img, [curCnt], -1, 1, -1)
img
=
np
.
uint8
(
cv2
.
morphologyEx
(
img
,
cv2
.
MORPH_CLOSE
,
np
.
ones
((
3
,
3
)))
)
#
cv2.drawContours(img, [curCnt], -1, 1, 1
)
#
i
f
cv2
.
__version__
>
'3.5'
:
#
i
mg = np.uint8(cv2.morphologyEx(img, cv2.MORPH_CLOSE, np.ones((3, 3))))
contours
,
hierarchy
=
cv2
.
findContours
(
img
,
cv2
.
RETR_CCOMP
,
cv2
.
CHAIN_APPROX_NONE
)
#
else
:
#
if cv2.__version__ > '3.5'
:
temp
,
contours
,
hierarchy
=
cv2
.
findContours
(
img
,
cv2
.
RETR_CCOMP
,
cv2
.
CHAIN_APPROX_NONE
)
#
contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
# else:
if
len
(
contours
)
>
1
:
#
temp, contours, hierarchy = cv2.findContours(img, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
QtWidgets
.
QMessageBox
.
critical
(
self
.
parent
,
'ERROR!'
,
#
'Particle contours are not connected and cannot be combined!'
)
# if len(contours)>1:
return
#
QtWidgets.QMessageBox.critical(self.parent, 'ERROR!',
#
'Particle contours are not connected and cannot be combined!')
newContour
=
contours
[
0
]
#
return
stats
=
self
.
characterizeParticle
(
newContour
)
#
# newContour = contours[0]
for
i
in
range
(
le
n
(
newContour
)
):
#
stats = self.characterizePartic
le(newContour)
newContour
[
i
][
0
][
0
]
+=
xmin
-
padding
#dateContours()
newContour
[
i
][
0
][
1
]
+=
ymin
-
padding
#
for i in range(len(newContour)):
#
newContour[i][0][0] += xmin-padding
print
(
'merging contours:'
,
contourIndices
)
#
newContour[i][0][1] += ymin-padding
self
.
createSafetyBackup
()
#
#
print('merging contours:', contourIndices)
#
#check, if dataset contains (already modified) particle2spectra, otherwise create new.
#
self.createSafetyBackup()
#
if self.datastats.dataset.particles2spectra is None: #create default assignment
#
#
print('recreating
particle
s
2spectra
from within edit particles...')
#
#
#check, if dataset contains (already modified)
particle2spectra
, otherwise create new.
#
sortindices =
self.datastats.dataset.
ramanscansortindex
#
#
if
self.datastats.dataset.
particles2spectra is None: #create default assignment
#
self.datastats.dataset.particles2spectra = [[int(np.where(sortindices == i)[0])] for i in range(len(sortindices))]
#
#
print('recreating particles2spectra from within edit particles...')
##
sortindices = self.datastats.dataset.ramanscansortindex
#Contour indices are the same as the original particlestats, which are contained in the dataset.
##
self.datastats.dataset.particles2spectra = [[int(np.where(sortindices == i)[0])] for i in range(len(sortindices))]
#We have to modify that and reload in the analysisview
#
#
first, overwrite first index with new particlestats
#
#
Contour indices are the same as the original particlestats, which are contained in the dataset.
self
.
datastats
.
dataset
.
particlestats
[
contourIndices
[
0
]]
=
stats
#
#We have to modify that and reload in the analysisview
#
#first, overwrite first index with new particlestats
#now, delete the rest...
#
self.datastats.dataset.particlestats[contourIndices[0]] = stats
self
.
datastats
.
dataset
.
particlestats
=
[
i
for
ind
,
i
in
enumerate
(
self
.
datastats
.
dataset
.
particlestats
)
if
ind
not
in
contourIndices
[
1
:]]
#
#
#now, delete the rest...
#same with the contours
#
self.datastats.dataset.particlestats = [i for ind, i in enumerate(self.datastats.dataset.particlestats) if ind not in contourIndices[1:]]
self
.
datastats
.
dataset
.
particlecontours
[
contourIndices
[
0
]]
=
newContour
#
self
.
datastats
.
dataset
.
particlecontours
=
[
i
for
ind
,
i
in
enumerate
(
self
.
datastats
.
dataset
.
particlecontours
)
if
ind
not
in
contourIndices
[
1
:]]
#
#same with the contours
#
self.datastats.dataset.particlecontours[contourIndices[0]] = newContour
#update particle2spectra_list
#
self.datastats.dataset.particlecontours = [i for ind, i in enumerate(self.datastats.dataset.particlecontours) if ind not in contourIndices[1:]]
#what is the current particle index??
#
specIndices
=
[]
#
#update particle2spectra_list
#
other spectra indices:
#
#
what is the current particle index??
for
index
in
contour
Indices
:
#
spec
Indices
= []
specIndices
.
append
(
self
.
datastats
.
particles2
spectra
[
ind
ex
])
#
#other
spectra
ind
ices:
#
for index in contourIndices:
#flatten index list (in case, that a nested list was created...
)
#
specIndices.append(self.datastats.particles2spectra[index]
)
specIndices
=
list
(
np
.
concatenate
(
specIndices
))
#
for
i
in
specIndices
:
#
#flatten index list (in case, that a nested list was created...)
s
elf
.
datastats
.
spectraResults
[
i
]
=
new_assignment
#
s
pecIndices = list(np.concatenate(specIndices))
self
.
datastats
.
hqis
[
i
]
=
100
#avoid sorting them out again by hqi-filter...
#
for i in specIndices:
print
(
f
'spectrum
{
i
}
of particle
{
contourIndices
[
0
]
}
is now
{
new_assignment
}
'
)
#
self.datastats.spectraResults[i] =
new_assignment
#
self.datastats.hqis[i] = 100 #avoid sorting them out again by hqi-filter...
#modify particles2spectra..
#
print(f'spectrum {i} of particle{contourIndices[0]} is now {new_assignment}')
self
.
datastats
.
dataset
.
particles2spectra
[
contourIndices
[
0
]]
=
specIndices
#
for
index
in
reversed
(
contourIndices
[
1
:]):
#
#modify particles2spectra..
print
(
'removing index from particles2spectra:'
,
index
)
#
self.datastats.dataset.particles2spectra[contourIndices[0]] = specIndices
del
self
.
datastats
.
dataset
.
particles2spectra
[
index
]
#
for index in reversed(contourIndices[1:]):
# print('removing index from particles2spectra:', index)
#update contours in sampleview
#
del self.datastats.dataset.particles2spectra[index]
self
.
parent
.
parent
.
contouritem
.
resetContours
(
self
.
datastats
.
dataset
.
particlecontours
)
#
self
.
parent
.
loadParticleData
()
#
#update contours in sampleview
#save data
#
self.parent.parent.contouritem.resetContours(self.datastats.dataset.particlecontours)
minHQI
=
self
.
parent
.
hqiSpinBox
.
value
()
#
self.parent.
loadParticleData
()
compHQI
=
self
.
parent
.
compHqiSpinBox
.
value
()
#
#save data
if
not
self
.
datastats
.
saveAnalysisResults
(
minHQI
,
compHQI
):
#
minHQI = self.parent.hqiSpinBox.value()
QtWidgets
.
QMessageBox
.
warning
(
self
.
parent
,
'Error!'
,
#
compHQI = self.parent.compHqiSpinBox.value()
'Data inconsistency after saving!'
,
QtWidgets
.
QMessageBox
.
Ok
,
# if not self.datastats.saveAnalysisResults(minHQI, compHQI):
QtWidgets
.
QMessageBox
.
Ok
)
#
QtWidgets.QMessageBox.
warning(self.parent, 'Error!',
#
'Data inconsistency after saving!', QtWidgets.QMessageBox.Ok,
#
QtWidgets.QMessageBox.Ok)
@
QtCore
.
pyqtSlot
(
list
,
str
)
def
reassignParticles
(
self
,
contourindices
,
new_assignment
):
def
reassignParticles
(
self
,
contourindices
,
new_assignment
):
if
new_assignment
==
'other'
:
if
new_assignment
==
'other'
:
new_assignment
=
self
.
getNewEntry
()
new_assignment
=
self
.
getNewEntry
()
...
@@ -163,31 +219,10 @@ class ParticleEditor(object):
...
@@ -163,31 +219,10 @@ class ParticleEditor(object):
self
.
createSafetyBackup
()
self
.
createSafetyBackup
()
print
(
f
'reassigning indices
{
contourindices
}
into
{
new_assignment
}
'
)
print
(
f
'reassigning indices
{
contourindices
}
into
{
new_assignment
}
'
)
for
partIndex
in
contourindices
:
for
partIndex
in
contourindices
:
for
specIndex
in
self
.
datastats
.
particles2spectra
[
partIndex
]:
self
.
particleContainer
.
reassignParticleToAssignment
(
partIndex
,
new_assignment
)
self
.
datastats
.
currentPolymers
[
specIndex
]
=
new_assignment
self
.
datastats
.
spectraResults
[
specIndex
]
=
new_assignment
self
.
datastats
.
hqis
[
specIndex
]
=
100
#update contours in sampleview
self
.
particlesWereEdited
.
emit
()
self
.
parent
.
parent
.
contouritem
.
resetContours
(
self
.
datastats
.
dataset
.
particlecontours
)
self
.
parent
.
loadParticleData
()
#save data
minHQI
=
self
.
parent
.
hqiSpinBox
.
value
()
compHQI
=
self
.
parent
.
compHqiSpinBox
.
value
()
if
not
self
.
datastats
.
saveAnalysisResults
(
minHQI
,
compHQI
):
QtWidgets
.
QMessageBox
.
warning
(
self
.
parent
,
'Error!'
,
'Data inconsistency after saving!'
,
QtWidgets
.
QMessageBox
.
Ok
,
QtWidgets
.
QMessageBox
.
Ok
)
def
deleteParticles
(
self
):
self
.
createSafetyBackup
()
pass
def
splitParticles
(
self
):
self
.
createSafetyBackup
()
pass
def
characterizeParticle
(
self
,
contours
):
def
characterizeParticle
(
self
,
contours
):
##characterize particle
##characterize particle
longellipse
,
shortellipse
=
np
.
nan
,
np
.
nan
longellipse
,
shortellipse
=
np
.
nan
,
np
.
nan
...
...
external/__init__.py
deleted
100644 → 0
View file @
b8f6f661
ramancom/__init__.py
deleted
100644 → 0
View file @
b8f6f661
sampleview.py
View file @
f0ab34e7
...
@@ -21,6 +21,8 @@ If not, see <https://www.gnu.org/licenses/>.
...
@@ -21,6 +21,8 @@ If not, see <https://www.gnu.org/licenses/>.
from
PyQt5
import
QtCore
,
QtGui
,
QtWidgets
from
PyQt5
import
QtCore
,
QtGui
,
QtWidgets
import
numpy
as
np
import
numpy
as
np
import
os
import
os
import
cv2
from
dataset
import
DataSet
,
loadData
from
dataset
import
DataSet
,
loadData
from
ramancom.ramancontrol
import
RamanControl
,
simulatedRaman
from
ramancom.ramancontrol
import
RamanControl
,
simulatedRaman
from
opticalscan
import
OpticalScan
from
opticalscan
import
OpticalScan
...
@@ -31,8 +33,9 @@ from zeissimporter import ZeissImporter
...
@@ -31,8 +33,9 @@ from zeissimporter import ZeissImporter
from
viewitems
import
FitPosIndicator
,
Node
,
Edge
,
ScanIndicator
,
RamanScanIndicator
,
SegmentationContour
from
viewitems
import
FitPosIndicator
,
Node
,
Edge
,
ScanIndicator
,
RamanScanIndicator
,
SegmentationContour
from
analysis.colorlegend
import
getColorFromNameWithSeed
from
analysis.colorlegend
import
getColorFromNameWithSeed
from
helperfunctions
import
polygoncovering
,
cv2imread_fix
from
helperfunctions
import
polygoncovering
,
cv2imread_fix
import
cv2
from
ramancom.configRaman
import
RamanConfigWin
from
ramancom.configRaman
import
RamanConfigWin
from
analysis.particleeditor
import
ParticleEditor
class
SampleView
(
QtWidgets
.
QGraphicsView
):
class
SampleView
(
QtWidgets
.
QGraphicsView
):
ScalingChanged
=
QtCore
.
pyqtSignal
(
float
)
ScalingChanged
=
QtCore
.
pyqtSignal
(
float
)
...
@@ -71,6 +74,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -71,6 +74,7 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
drag
=
None
self
.
drag
=
None
self
.
mode
=
None
self
.
mode
=
None
self
.
dataset
=
None
self
.
dataset
=
None
self
.
particleEditor
=
None
self
.
fititems
=
[]
self
.
fititems
=
[]
self
.
boundaryitems
=
[[],[]]
self
.
boundaryitems
=
[[],[]]
self
.
scanitems
=
[]
self
.
scanitems
=
[]
...
@@ -78,7 +82,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -78,7 +82,7 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
imgdata
=
None
self
.
imgdata
=
None
self
.
isblocked
=
False
self
.
isblocked
=
False
self
.
contourItems
=
[]
self
.
contourItems
=
[]
self
.
selected
Contour
s
=
[]
self
.
selected
ParticleIndice
s
=
[]
self
.
detectionwidget
=
None
self
.
detectionwidget
=
None
self
.
ramanwidget
=
RamanScanUI
(
self
.
ramanctrl
,
None
,
self
.
logpath
,
self
)
self
.
ramanwidget
=
RamanScanUI
(
self
.
ramanctrl
,
None
,
self
.
logpath
,
self
)
...
@@ -90,10 +94,6 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -90,10 +94,6 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
setMinimumSize
(
600
,
600
)
self
.
setMinimumSize
(
600
,
600
)
self
.
darkenPixmap
=
False
self
.
darkenPixmap
=
False
self
.
microscopeMode
=
None
self
.
microscopeMode
=
None
# self.coordTestMode = False
def
takeScreenshot
(
self
):
def
takeScreenshot
(
self
):
#TODO:
#TODO:
...
@@ -146,7 +146,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -146,7 +146,7 @@ class SampleView(QtWidgets.QGraphicsView):
def
saveDataSet
(
self
):
def
saveDataSet
(
self
):
if
self
.
dataset
is
not
None
:
if
self
.
dataset
is
not
None
:
self
.
dataset
.
save
()
self
.
dataset
.
save
()
@
QtCore
.
pyqtSlot
()
@
QtCore
.
pyqtSlot
()
def
zoomIn
(
self
):
def
zoomIn
(
self
):
self
.
scaleImage
(
1.25
)
self
.
scaleImage
(
1.25
)
...
@@ -163,7 +163,6 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -163,7 +163,6 @@ class SampleView(QtWidgets.QGraphicsView):
@
QtCore
.
pyqtSlot
()
@
QtCore
.
pyqtSlot
()
def
fitToWindow
(
self
):
def
fitToWindow
(
self
):
# print("fitting to Window")
brect
=
self
.
item
.
sceneBoundingRect
()
brect
=
self
.
item
.
sceneBoundingRect
()
self
.
fitInView
(
0
,
0
,
brect
.
width
(),
brect
.
height
(),
QtCore
.
Qt
.
KeepAspectRatio
)
self
.
fitInView
(
0
,
0
,
brect
.
width
(),
brect
.
height
(),
QtCore
.
Qt
.
KeepAspectRatio
)
self
.
scaleFactor
=
self
.
transform
().
m11
()
self
.
scaleFactor
=
self
.
transform
().
m11
()
...
@@ -178,7 +177,6 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -178,7 +177,6 @@ class SampleView(QtWidgets.QGraphicsView):
self
.
detectionwidget
.
close
()
self
.
detectionwidget
.
close
()
self
.
detectionwidget
.
destroy
()
self
.
detectionwidget
.
destroy
()
self
.
ramanwidget
.
setVisible
(
False
)
self
.
ramanwidget
.
setVisible
(
False
)
# self.contouritem.resetContours([])
self
.
updateParticleContours
()
self
.
updateParticleContours
()
self
.
mode
=
mode
self
.
mode
=
mode
self
.
loadPixmap
(
self
.
microscopeMode
)
self
.
loadPixmap
(
self
.
microscopeMode
)
...
@@ -204,6 +202,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -204,6 +202,7 @@ class SampleView(QtWidgets.QGraphicsView):
print
(
'creating new analysiswidget'
)
print
(
'creating new analysiswidget'
)
self
.
analysiswidget
=
ParticleAnalysis
(
self
.
dataset
,
self
)
self
.
analysiswidget
=
ParticleAnalysis
(
self
.
dataset
,
self
)
self
.
analysiswidget
.
showMaximized
()
self
.
analysiswidget
.
showMaximized
()
self
.
particleEditor
.
particlesWereEdited
.
connect
(
self
.
analysiswidget
.
updateDisplays
)
else
:
else
:
print
(
'show maximized already exisiting analysiswidget'
)
print
(
'show maximized already exisiting analysiswidget'
)
self
.
analysiswidget
.
showMaximized
()
self
.
analysiswidget
.
showMaximized
()
...
@@ -229,16 +228,10 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -229,16 +228,10 @@ class SampleView(QtWidgets.QGraphicsView):
widget
.
destroy
()
widget
.
destroy
()
del
widget
del
widget
# self.contouritem.resetContours()
self
.
updateParticleContours
()
self
.
updateParticleContours
()
# if self.dataset is not None:
# del self.dataset
# self.scene().removeItem(self.contouritem)
# del self.contouritem
# self.contouritem = SegmentationContours(self)
# self.scene().addItem(self.contouritem)
self
.
dataset
=
loadData
(
fname
)
self
.
dataset
=
loadData
(
fname
)
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
setMicroscopeMode
()
self
.
setMicroscopeMode
()
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imgdata
=
None
self
.
imgdata
=
None
...
@@ -257,6 +250,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -257,6 +250,7 @@ class SampleView(QtWidgets.QGraphicsView):
if
self
.
dataset
is
not
None
:
if
self
.
dataset
is
not
None
:
self
.
dataset
.
save
()
self
.
dataset
.
save
()
self
.
dataset
=
DataSet
(
fname
,
newProject
=
True
)
self
.
dataset
=
DataSet
(
fname
,
newProject
=
True
)
self
.
particleEditor
=
ParticleEditor
(
self
,
self
.
dataset
.
particleContainer
)
self
.
setMicroscopeMode
()
self
.
setMicroscopeMode
()
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imparent
.
setWindowTitle
(
self
.
dataset
.
name
+
(
" SIMULATION"
if
simulatedRaman
else
""
))
self
.
imgdata
=
None
self
.
imgdata
=
None
...
@@ -296,7 +290,7 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -296,7 +290,7 @@ class SampleView(QtWidgets.QGraphicsView):
maxmode
=
"ParticleDetection"
maxmode
=
"ParticleDetection"
if
len
(
self
.
dataset
.
ramanpoints
)
>
0
:
if
len
(
self
.
dataset
.
ramanpoints
)
>
0
:
maxmode
=
"RamanScan"
maxmode
=
"RamanScan"
if
self
.
dataset
.
ramanscandone
:
#uncomment!!
if
self
.
dataset
.
ramanscandone
:
maxmode
=
"ParticleAnalysis"
maxmode
=
"ParticleAnalysis"
return
maxmode
return
maxmode
...
@@ -357,12 +351,12 @@ class SampleView(QtWidgets.QGraphicsView):
...
@@ -357,12 +351,12 @@ class SampleView(QtWidgets.QGraphicsView):
def
addContourToSelection
(
cnt
):
def
addContourToSelection
(
cnt
):
cnt
.
isSelected
=
True
cnt
.
isSelected
=
True
cnt
.
update
()
cnt
.
update
()
self
.
selected
Contour
s
.
append
(
cnt
.
particleIndex
)
self
.
selected
ParticleIndice
s
.
append
(
cnt
.
particleIndex
)
def
removeContourFromSelection
(
cnt
):
def
removeContourFromSelection
(
cnt
):
cnt
.
isSelected
=
False
cnt
.
isSelected
=
False
cnt
.
update
()
cnt
.
update
()
self
.
selected
Contour
s
.
remove
(
cnt
.
particleIndex
)
self
.
selected
ParticleIndice
s
.
remove
(
cnt
.
particleIndex
)