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
582761bd
Commit
582761bd
authored
Sep 02, 2019
by
JosefBrandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modularization of analysisview, DocStrings
parent
07883df1
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
948 additions
and
429 deletions
+948
-429
.gitignore
.gitignore
+2
-0
__main__.py
__main__.py
+1
-1
analysis/analysisplots.py
analysis/analysisplots.py
+168
-54
analysis/analysisview.py
analysis/analysisview.py
+176
-279
analysis/analysiswidgets.py
analysis/analysiswidgets.py
+331
-0
analysis/particleCharacterization.py
analysis/particleCharacterization.py
+29
-4
analysis/particleClassification/colorClassification.py
analysis/particleClassification/colorClassification.py
+6
-6
analysis/particleContainer.py
analysis/particleContainer.py
+7
-3
analysis/particleEditor.py
analysis/particleEditor.py
+2
-2
analysis/sqlexport.py
analysis/sqlexport.py
+4
-3
dataset.py
dataset.py
+3
-17
legacyConvert.py
legacyConvert.py
+3
-2
ramanscanui.py
ramanscanui.py
+1
-1
sampleview.py
sampleview.py
+185
-53
segmentation.py
segmentation.py
+1
-1
viewitems.py
viewitems.py
+29
-3
No files found.
.gitignore
View file @
582761bd
...
...
@@ -10,3 +10,5 @@ analysis/database_config\.txt
*.c
external/build/
.idea/
__main__.py
View file @
582761bd
...
...
@@ -135,7 +135,7 @@ class GEPARDMainWindow(QtWidgets.QMainWindow):
self
.
openAct
.
setShortcut
(
"Ctrl+O"
)
self
.
openAct
.
triggered
.
connect
(
self
.
open
)
self
.
importAct
=
QtWidgets
.
QAction
(
"&Import Project..."
,
self
)
self
.
importAct
=
QtWidgets
.
QAction
(
"&Import
Zeiss
Project..."
,
self
)
self
.
importAct
.
setShortcut
(
"Ctrl+I"
)
self
.
importAct
.
triggered
.
connect
(
self
.
importProject
)
...
...
analysis/analysisplots.py
View file @
582761bd
...
...
@@ -23,9 +23,168 @@ from PyQt5 import QtWidgets, QtGui, QtCore
from
matplotlib.backends.backend_qt5agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.figure
import
Figure
from
matplotlib.backends.backend_qt5agg
import
NavigationToolbar2QT
as
NavigationToolbar
import
numpy
as
np
from
.colorlegend
import
getColorFromNameWithSeed
class
ParticleIndicator
(
QtWidgets
.
QPushButton
):
class
SizeHistogramPlot
(
QtWidgets
.
QGroupBox
):
def
__init__
(
self
,
dataset
):
super
(
SizeHistogramPlot
,
self
).
__init__
()
self
.
dataset
=
dataset
self
.
minX
=
3
self
.
maxX
=
1E4
self
.
fontsize
=
15
layout
=
QtWidgets
.
QHBoxLayout
()
self
.
setLayout
(
layout
)
self
.
sizeHistogramCanvas
=
FigureCanvas
(
Figure
())
self
.
sizeHist_ax
=
self
.
sizeHistogramCanvas
.
figure
.
subplots
()
self
.
sizeHist_ax
.
axis
(
'off'
)
self
.
sizeHistogramCanvas
.
figure
.
subplots_adjust
(
left
=
0.1
,
top
=
0.93
,
bottom
=
0.15
,
right
=
0.995
)
histNavigation
=
NavigationToolbar
(
self
.
sizeHistogramCanvas
,
self
)
histNavigation
.
setOrientation
(
QtCore
.
Qt
.
Vertical
)
histNavigation
.
setFixedWidth
(
50
)
layout
.
addWidget
(
histNavigation
)
layout
.
addWidget
(
self
.
sizeHistogramCanvas
)
def
drawHistograms
(
self
,
listOfHistograms
):
if
type
(
listOfHistograms
)
!=
list
:
assert
type
(
listOfHistograms
)
==
SizeHistogramData
listOfHistograms
=
[
listOfHistograms
]
self
.
resetPlotFormat
()
self
.
adjustPlotLimits
(
listOfHistograms
)
for
histData
in
listOfHistograms
:
self
.
drawHistogram
(
histData
)
self
.
drawLegend
()
self
.
sizeHistogramCanvas
.
draw
()
def
resetPlotFormat
(
self
):
self
.
sizeHist_ax
.
clear
()
self
.
sizeHist_ax
.
axis
(
'on'
)
self
.
sizeHist_ax
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
labelsize
=
self
.
fontsize
)
self
.
sizeHist_ax
.
set_xlabel
(
'Size (µm)'
,
fontsize
=
self
.
fontsize
)
self
.
sizeHist_ax
.
set_ylabel
(
'Number'
,
fontsize
=
self
.
fontsize
)
self
.
sizeHist_ax
.
set_title
(
'Size Distribution'
,
fontsize
=
self
.
fontsize
)
def
adjustPlotLimits
(
self
,
listOfHistograms
):
xmin
,
xmax
=
None
,
None
for
histData
in
listOfHistograms
:
if
xmin
is
None
:
xmin
=
np
.
clip
(
10
**
histData
.
minSizeExponent
,
self
.
minX
,
self
.
maxX
)
xmax
=
np
.
clip
(
10
**
histData
.
maxSizeExponent
,
self
.
minX
,
self
.
maxX
)
else
:
currentXMin
=
np
.
clip
(
10
**
histData
.
minSizeExponent
,
self
.
minX
,
self
.
maxX
)
currentXMax
=
np
.
clip
(
10
**
histData
.
maxSizeExponent
,
self
.
minX
,
self
.
maxX
)
xmin
=
min
(
xmin
,
currentXMin
)
xmax
=
max
(
xmax
,
currentXMax
)
self
.
sizeHist_ax
.
set_xlim
(
xmin
,
xmax
)
def
drawHistogram
(
self
,
histData
):
label
=
histData
.
label
x_values
=
histData
.
sizeHist_binCenters
y_values
=
histData
.
sizeHist_abundancies
color
=
getColorFromNameWithSeed
(
label
,
self
.
dataset
.
colorSeed
,
base255
=
False
)
self
.
sizeHist_ax
.
semilogx
(
x_values
,
y_values
,
label
=
label
,
color
=
color
)
def
drawLegend
(
self
):
self
.
sizeHist_ax
.
legend
(
prop
=
{
'size'
:
self
.
fontsize
})
class
SizeHistogramData
(
object
):
def
__init__
(
self
,
label
,
listOfSizes
):
self
.
label
=
label
self
.
listOfSizes
=
listOfSizes
self
.
minSizeExponent
=
0.1
self
.
maxSizeExponent
=
3
self
.
numBins
=
20
self
.
sizeHist_binCenters
=
None
self
.
sizeHist_abundancies
=
None
self
.
createSizeHistogramData
()
def
createSizeHistogramData
(
self
):
assert
self
.
listOfSizes
is
not
None
bins
=
np
.
logspace
(
self
.
minSizeExponent
,
self
.
maxSizeExponent
,
self
.
numBins
)
self
.
sizeHist_abundancies
,
binEdges
=
np
.
histogram
(
self
.
listOfSizes
,
bins
)
self
.
sizeHist_binCenters
=
self
.
getBinCenters
(
binEdges
)
def
getBinCenters
(
self
,
binEdges
):
binCenters
=
[]
for
i
in
range
(
self
.
numBins
-
1
):
currentCenter
=
np
.
mean
((
binEdges
[
i
],
binEdges
[
i
+
1
]))
binCenters
.
append
(
currentCenter
)
return
binCenters
class
TypeHistogramPlot
(
QtWidgets
.
QScrollArea
):
indexClicked
=
QtCore
.
pyqtSignal
(
int
)
def
__init__
(
self
,
dataset
):
super
(
TypeHistogramPlot
,
self
).
__init__
()
self
.
dataset
=
dataset
self
.
view
=
QtWidgets
.
QWidget
(
self
)
self
.
view
.
setCursor
(
QtGui
.
QCursor
(
QtCore
.
Qt
.
WhatsThisCursor
))
self
.
view
.
setMinimumWidth
(
250
)
group
=
QtWidgets
.
QGroupBox
(
'Polymer Type Distribution'
,
self
.
view
)
self
.
indicatorbox
=
QtWidgets
.
QVBoxLayout
()
self
.
indicatorbox
.
setContentsMargins
(
5
,
5
,
5
,
5
)
group
.
setLayout
(
self
.
indicatorbox
)
hbox
=
QtWidgets
.
QHBoxLayout
()
hbox
.
addWidget
(
group
)
self
.
view
.
setLayout
(
hbox
)
self
.
setWidgetResizable
(
True
)
self
.
setWidget
(
self
.
view
)
self
.
setAlignment
(
QtCore
.
Qt
.
AlignHCenter
)
self
.
abundancyIndicators
=
[]
def
updateTypeHistogram
(
self
,
typeHistogram
):
self
.
resetPlot
()
colorList
=
[]
abundancyList
=
[]
labelList
=
[]
for
polymType
in
typeHistogram
:
text
=
f
'
{
typeHistogram
[
polymType
]
}
x
{
polymType
}
'
labelList
.
append
(
text
)
abundancyList
.
append
(
typeHistogram
[
polymType
])
curColor
=
getColorFromNameWithSeed
(
polymType
,
self
.
dataset
.
colorSeed
)
colorList
.
append
(
QtGui
.
QColor
(
*
curColor
))
types
=
list
(
zip
(
abundancyList
,
labelList
,
colorList
))
numtotal
=
sum
(
abundancyList
)
for
index
,
entry
in
enumerate
(
types
):
num
,
text
,
color
=
entry
indicator
=
AbundancyIndicator
(
num
,
numtotal
,
color
,
text
)
self
.
indicatorbox
.
addWidget
(
indicator
)
indicator
.
clicked
.
connect
(
self
.
_getIndexFunction
(
index
))
self
.
abundancyIndicators
.
append
(
indicator
)
self
.
indicatorbox
.
addStretch
()
self
.
view
.
update
()
def
resetPlot
(
self
):
for
indicator
in
self
.
abundancyIndicators
:
self
.
indicatorbox
.
removeWidget
(
indicator
)
indicator
.
setParent
(
None
)
indicator
.
destroy
()
self
.
indicatorbox
.
takeAt
(
0
)
self
.
abundancyIndicators
=
[]
def
_getIndexFunction
(
self
,
index
):
return
lambda
:
self
.
indexClicked
.
emit
(
index
)
class
AbundancyIndicator
(
QtWidgets
.
QPushButton
):
def
__init__
(
self
,
number
,
numtotal
,
color
,
text
,
parent
=
None
):
super
().
__init__
(
parent
)
self
.
number
=
number
...
...
@@ -61,54 +220,12 @@ class ParticleIndicator(QtWidgets.QPushButton):
qp
.
end
()
class
TypeHistogramView
(
QtWidgets
.
QScrollArea
):
indexClicked
=
QtCore
.
pyqtSignal
(
int
)
def
__init__
(
self
,
parent
=
None
):
super
().
__init__
(
parent
)
self
.
view
=
QtWidgets
.
QWidget
(
self
)
self
.
view
.
setCursor
(
QtGui
.
QCursor
(
QtCore
.
Qt
.
WhatsThisCursor
))
self
.
view
.
setMinimumWidth
(
250
)
group
=
QtWidgets
.
QGroupBox
(
'Polymer Type Distribution'
,
self
.
view
)
self
.
indicatorbox
=
QtWidgets
.
QVBoxLayout
()
self
.
indicatorbox
.
setContentsMargins
(
5
,
5
,
5
,
5
)
group
.
setLayout
(
self
.
indicatorbox
)
hbox
=
QtWidgets
.
QHBoxLayout
()
hbox
.
addWidget
(
group
)
self
.
view
.
setLayout
(
hbox
)
self
.
setWidgetResizable
(
True
)
self
.
setWidget
(
self
.
view
)
self
.
setAlignment
(
QtCore
.
Qt
.
AlignHCenter
)
self
.
widgets
=
[]
def
updateTypeHistogram
(
self
,
types
):
for
pi
in
self
.
widgets
:
self
.
indicatorbox
.
removeWidget
(
pi
)
pi
.
setParent
(
None
)
pi
.
destroy
()
self
.
indicatorbox
.
takeAt
(
0
)
self
.
widgets
=
[]
numtotal
=
sum
([
num
for
num
,
text
,
color
in
types
])
def
getIndexFunction
(
index
):
return
lambda
:
self
.
indexClicked
.
emit
(
index
)
for
index
,
entry
in
enumerate
(
types
):
num
,
text
,
color
=
entry
pi
=
ParticleIndicator
(
num
,
numtotal
,
color
,
text
)
self
.
indicatorbox
.
addWidget
(
pi
)
pi
.
clicked
.
connect
(
getIndexFunction
(
index
))
self
.
widgets
.
append
(
pi
)
self
.
indicatorbox
.
addStretch
()
self
.
view
.
update
()
class
SpectraPlot
(
QtWidgets
.
QGroupBox
):
def
__init__
(
self
,
dataset
):
super
(
SpectraPlot
,
self
).
__init__
()
self
.
dataset
=
dataset
self
.
spectra
=
None
self
.
fontsize
=
15
layout
=
QtWidgets
.
QHBoxLayout
()
self
.
canvas
=
FigureCanvas
(
Figure
())
...
...
@@ -131,14 +248,14 @@ class SpectraPlot(QtWidgets.QGroupBox):
#draw Sample Spectrum
self
.
spec_axis
.
axis
(
"on"
)
self
.
spec_axis
.
clear
()
self
.
spec_axis
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
labelsize
=
15
)
self
.
spec_axis
.
set_xlabel
(
'Wavenumber (cm-1)'
,
fontsize
=
15
)
self
.
spec_axis
.
set_ylabel
(
'Counts'
,
fontsize
=
15
)
self
.
spec_axis
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
labelsize
=
self
.
fontsize
)
self
.
spec_axis
.
set_xlabel
(
'Wavenumber (cm-1)'
,
fontsize
=
self
.
fontsize
)
self
.
spec_axis
.
set_ylabel
(
'Counts'
,
fontsize
=
self
.
fontsize
)
if
self
.
spectra
is
not
None
:
specInfo
=
f
'ScanPoint Number
{
specIndex
+
1
}
, with assignment
{
assignment
}
(hqi =
{
hqi
}
)'
self
.
spec_axis
.
plot
(
self
.
spectra
[:,
0
],
self
.
spectra
[:,
specIndex
+
1
])
self
.
spec_axis
.
set_title
(
specInfo
,
fontsize
=
13
)
self
.
spec_axis
.
set_title
(
specInfo
,
fontsize
=
self
.
fontsize
)
self
.
spec_axis
.
set_xbound
(
100
,
(
3400
if
self
.
spectra
[
-
1
,
0
]
>
3400
else
self
.
spectra
[
-
1
,
0
]))
wavenumber_diff
=
list
(
self
.
spectra
[:,
0
]
-
100
)
...
...
@@ -152,13 +269,10 @@ class SpectraPlot(QtWidgets.QGroupBox):
def
updateReferenceSpectrum
(
self
,
ref_wavenumber
,
ref_intensity
):
#draw Reference
self
.
reference_axis
.
clear
()
self
.
reference_axis
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
labelsize
=
15
)
self
.
reference_axis
.
tick_params
(
axis
=
'both'
,
which
=
'both'
,
labelsize
=
self
.
fontsize
)
self
.
reference_axis
.
plot
(
ref_wavenumber
,
ref_intensity
,
color
=
'r'
)
self
.
reference_axis
.
set_ylabel
(
'Ref. Intensity'
,
fontsize
=
15
,
color
=
'r'
)
self
.
reference_axis
.
set_ylabel
(
'Ref. Intensity'
,
fontsize
=
self
.
fontsize
,
color
=
'r'
)
self
.
reference_axis
.
tick_params
(
'y'
,
colors
=
'r'
)
self
.
reference_axis
.
set_xbound
(
100
,
(
3400
if
self
.
spectra
[
-
1
,
0
]
>
3400
else
self
.
spectra
[
-
1
,
0
]))
self
.
canvas
.
draw
()
\ No newline at end of file
\ No newline at end of file
analysis/analysisview.py
View file @
582761bd
...
...
@@ -21,19 +21,14 @@ If not, see <https://www.gnu.org/licenses/>.
"""
from
PyQt5
import
QtCore
,
QtGui
,
QtWidgets
import
numpy
as
np
import
sys
import
time
from
matplotlib.backends.backend_qt5agg
import
FigureCanvasQTAgg
as
FigureCanvas
from
matplotlib.figure
import
Figure
from
matplotlib.backends.backend_qt5agg
import
NavigationToolbar2QT
as
NavigationToolbar
from
.excelexport
import
ExpExcelDialog
from
.analysisplots
import
TypeHistogramView
,
SpectraPlot
from
.
import
analysisplots
from
.
import
analysiswidgets
from
.loadresults
import
LoadTrueMatchResults
from
.database
import
DataBaseWindow
from
.colorlegend
import
getColorFromNameWithSeed
from
.particleCharacterization
import
updateStatsOfParticlesIfNotManuallyEdited
try
:
from
.sqlexport
import
SQLExport
...
...
@@ -56,33 +51,18 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
particleContainer
=
dataset
.
particleContainer
self
.
importWindow
=
None
self
.
polymerCheckBoxes
=
[]
self
.
lastSelectedCheckBoxNames
=
[]
self
.
findcoloredParticlesWindow
=
None
self
.
currentParticleIndex
=
0
self
.
currentSpectrumIndex
=
0
self
.
typeHistogramPlot
=
TypeHistogramView
(
self
)
self
.
sizeHistogramCanvas
=
FigureCanvas
(
Figure
())
sizeHistGroup
=
QtWidgets
.
QGroupBox
()
sizeHistLayout
=
QtWidgets
.
QHBoxLayout
()
self
.
sizeHist_ax
=
self
.
sizeHistogramCanvas
.
figure
.
subplots
()
self
.
sizeHist_ax
.
axis
(
'off'
)
self
.
sizeHistogramCanvas
.
figure
.
subplots_adjust
(
left
=
0.1
,
top
=
0.93
,
bottom
=
0.15
,
right
=
0.995
)
histNavigation
=
NavigationToolbar
(
self
.
sizeHistogramCanvas
,
self
)
histNavigation
.
setOrientation
(
QtCore
.
Qt
.
Vertical
)
histNavigation
.
setFixedWidth
(
50
)
sizeHistLayout
.
addWidget
(
histNavigation
)
sizeHistLayout
.
addWidget
(
self
.
sizeHistogramCanvas
)
sizeHistGroup
.
setLayout
(
sizeHistLayout
)
self
.
specPlot
=
SpectraPlot
(
self
.
dataset
)
self
.
typeHistogramPlot
=
analysisplots
.
TypeHistogramPlot
(
self
.
dataset
)
self
.
sizeHistogramPlot
=
analysisplots
.
SizeHistogramPlot
(
self
.
dataset
)
self
.
specPlot
=
analysisplots
.
SpectraPlot
(
self
.
dataset
)
splitter1
=
QtWidgets
.
QSplitter
(
QtCore
.
Qt
.
Vertical
)
splitter1
.
addWidget
(
self
.
specPlot
)
splitter1
.
addWidget
(
sizeHist
Group
)
splitter1
.
addWidget
(
self
.
sizeHist
ogramPlot
)
splitter2
=
QtWidgets
.
QSplitter
(
QtCore
.
Qt
.
Horizontal
)
splitter2
.
addWidget
(
splitter1
)
splitter2
.
addWidget
(
self
.
typeHistogramPlot
)
...
...
@@ -103,51 +83,13 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
referenceLayout
.
addStretch
()
referenceGroup
.
setLayout
(
referenceLayout
)
self
.
navigationGroup
=
QtWidgets
.
QGroupBox
(
'Navigate through polymers'
)
self
.
navigationGroup
.
setDisabled
(
True
)
navigationLayout
=
QtWidgets
.
QHBoxLayout
()
self
.
specNumberSelector
=
QtWidgets
.
QSpinBox
()
self
.
specNumberSelector
.
setMinimumWidth
(
100
)
self
.
specNumberSelector
.
setMinimum
(
1
)
numSpectra
=
self
.
particleContainer
.
getNumberOfMeasurements
()
self
.
specNumberSelector
.
setMaximum
(
numSpectra
)
self
.
jumpToSpecBtn
=
QtWidgets
.
QPushButton
(
'Jump To Spectrum of Number:'
)
self
.
jumpToSpecBtn
.
released
.
connect
(
self
.
jumpToIndicatedSpectrum
)
self
.
typeSelectorCombo
=
QtWidgets
.
QComboBox
()
self
.
typeSelectorCombo
.
setMinimumWidth
(
150
)
self
.
typeSelectorCombo
.
currentIndexChanged
.
connect
(
self
.
setTypeSelector
)
self
.
particleSelector
=
QtWidgets
.
QSpinBox
()
self
.
particleSelector
.
valueChanged
.
connect
(
self
.
setParticleSelector
)
self
.
particleNumberLabel
=
QtWidgets
.
QLabel
(
'of xx particles; '
)
self
.
spectrumSelector
=
QtWidgets
.
QSpinBox
()
self
.
spectrumSelector
.
valueChanged
.
connect
(
self
.
setSpecSelector
)
self
.
spectrumNumberLabel
=
QtWidgets
.
QLabel
(
'of xx spectra'
)
for
spinbox
in
[
self
.
particleSelector
,
self
.
spectrumSelector
]:
spinbox
.
setMinimum
(
1
)
spinbox
.
setSingleStep
(
1
)
spinbox
.
setValue
(
1
)
navigationLayout
.
addWidget
(
self
.
jumpToSpecBtn
)
navigationLayout
.
addWidget
(
self
.
specNumberSelector
)
navigationLayout
.
addWidget
(
QtWidgets
.
QLabel
(
'Select Polymer Type:'
))
navigationLayout
.
addWidget
(
self
.
typeSelectorCombo
)
navigationLayout
.
addStretch
()
navigationLayout
.
addWidget
(
QtWidgets
.
QLabel
(
'Select Particle'
))
navigationLayout
.
addWidget
(
self
.
particleSelector
)
navigationLayout
.
addWidget
(
self
.
particleNumberLabel
)
navigationLayout
.
addStretch
()
navigationLayout
.
addWidget
(
QtWidgets
.
QLabel
(
'Select Spectrum'
))
navigationLayout
.
addWidget
(
self
.
spectrumSelector
)
navigationLayout
.
addWidget
(
self
.
spectrumNumberLabel
)
self
.
navigationGroup
.
setLayout
(
navigationLayout
)
self
.
navigationToolbar
=
analysiswidgets
.
PolymerNavigationToolbar
(
self
.
particleContainer
)
self
.
navigationToolbar
.
WidgetsUpdated
.
connect
(
self
.
updateFromNavigationToolbar
)
self
.
navigationToolbar
.
JumpToIndicatedSpec
.
connect
(
self
.
jumpToIndicatedSpectrum
)
self
.
viewparent
.
ParticleOfIndexSelected
.
connect
(
self
.
navigationToolbar
.
setWidgetsToNewParticleIndex
)
topLayout
=
QtWidgets
.
QHBoxLayout
()
topLayout
.
addWidget
(
self
.
navigation
Group
)
topLayout
.
addWidget
(
self
.
navigation
Toolbar
)
topLayout
.
addWidget
(
referenceGroup
)
viewLayout
=
QtWidgets
.
QVBoxLayout
()
...
...
@@ -175,29 +117,12 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
optionsGroup
.
setLayout
(
optionsLayout
)
self
.
optionsGroup
.
setMinimumWidth
(
175
)
self
.
resultScrollarea
=
QtWidgets
.
QScrollArea
(
self
)
self
.
resultScrollarea
.
setFixedWidth
(
250
)
self
.
resultScrollarea
.
setWidgetResizable
(
True
)
widget
=
QtWidgets
.
QWidget
()
self
.
resultScrollarea
.
setWidget
(
widget
)
self
.
layout_SArea
=
QtWidgets
.
QVBoxLayout
(
widget
)
self
.
resultCheckBoxes
=
QtWidgets
.
QGroupBox
(
'Display Polymer Types:'
)
self
.
resultCheckBoxesLayout
=
QtWidgets
.
QVBoxLayout
()
self
.
showTotalSelector
=
QtWidgets
.
QCheckBox
(
'Show Total Distribution'
)
self
.
showTotalSelector
.
setChecked
(
True
)
self
.
showTotalSelector
.
setDisabled
(
True
)
self
.
resultCheckBoxesLayout
.
addWidget
(
self
.
showTotalSelector
)
self
.
resultCheckBoxesLayout
.
addStretch
()
self
.
resultCheckBoxes
.
setLayout
(
self
.
resultCheckBoxesLayout
)
self
.
layout_SArea
.
addWidget
(
self
.
resultCheckBoxes
)
self
.
resultCheckBoxes
=
analysiswidgets
.
PolymerTypeCheckboxes
()
self
.
resultCheckBoxes
.
PolymerCheckBoxToggled
.
connect
(
self
.
updatedPlotsAndContoursSelectively
)
self
.
menuLayout
=
QtWidgets
.
QVBoxLayout
()
self
.
menuLayout
.
addWidget
(
self
.
optionsGroup
)
self
.
menuLayout
.
addWidget
(
self
.
result
Scrollarea
)
self
.
menuLayout
.
addWidget
(
self
.
result
CheckBoxes
)
self
.
layout
.
addLayout
(
self
.
menuLayout
)
self
.
layout
.
addLayout
(
viewLayout
)
...
...
@@ -205,10 +130,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
createActions
()
self
.
createMenus
()
self
.
applyHQIThresholdToResults
()
self
.
createHistogramData
()
self
.
initializeSpecPlot
()
self
.
setTypeSelector
()
self
.
updateHistogramsAndContours
()
self
.
navigationToolbar
.
updateWidgets
()
def
createActions
(
self
):
self
.
loadTrueMatchAct
=
QtWidgets
.
QAction
(
"Load &TrueMatch Results"
,
self
)
...
...
@@ -217,9 +140,15 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
loadSpectraAct
=
QtWidgets
.
QAction
(
"Load &Spectra"
,
self
)
self
.
loadSpectraAct
.
triggered
.
connect
(
self
.
initializeSpecPlot
)
self
.
databaseAct
=
QtWidgets
.
QAction
(
"&Manage
D
atabase"
,
self
)
self
.
databaseAct
=
QtWidgets
.
QAction
(
"&Manage
reference spectra d
atabase
s
"
,
self
)
self
.
databaseAct
.
triggered
.
connect
(
self
.
launchDBManager
)
self
.
findColorParticlesAct
=
QtWidgets
.
QAction
(
"Navigate throuch &colored, not unknown particles"
,
self
)
self
.
findColorParticlesAct
.
triggered
.
connect
(
self
.
launchColoredParticleWindow
)
self
.
recalculateParticleStatsAct
=
QtWidgets
.
QAction
(
"&Recalculated particle stats"
,
self
)
self
.
recalculateParticleStatsAct
.
triggered
.
connect
(
self
.
recalculateParticleStats
)
self
.
expExcelAct
=
QtWidgets
.
QAction
(
"Export &Excel List"
,
self
)
self
.
expExcelAct
.
setDisabled
(
True
)
self
.
expExcelAct
.
triggered
.
connect
(
self
.
exportToExcel
)
...
...
@@ -231,6 +160,10 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
getAndActivateActionsFromGepardMain
()
def
getAndActivateActionsFromGepardMain
(
self
):
"""
For user convenience, the actions from the Gepard main window are also added to the menubar of the analysis window.
:return:
"""
gepard
=
self
.
viewparent
.
imparent
self
.
noOverlayAct
=
gepard
.
noOverlayAct
...
...
@@ -241,7 +174,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
transpAct
.
triggered
.
connect
(
self
.
updateContourColors
)
self
.
hideLabelAct
=
gepard
.
hideLabelAct
self
.
hideLabelAct
.
triggered
.
connect
(
self
.
show
_hide_la
be
l
s
)
self
.
hideLabelAct
.
triggered
.
connect
(
self
.
show
OrHideSpecNum
be
r
s
)
self
.
darkenAct
=
gepard
.
darkenAct
self
.
darkenAct
.
triggered
.
connect
(
self
.
darkenBackground
)
...
...
@@ -264,7 +197,7 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
overlayActGroup
=
QtWidgets
.
QActionGroup
(
self
.
dispMenu
)
self
.
overlayActGroup
.
setExclusive
(
True
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
updateContourColors
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
update
Histogram
sAndContours
)
self
.
overlayActGroup
.
triggered
.
connect
(
self
.
update
Plot
sAndContours
)
for
act
in
[
self
.
noOverlayAct
,
self
.
selOverlayAct
,
self
.
fullOverlayAct
]:
self
.
dispMenu
.
addAction
(
act
)
...
...
@@ -275,6 +208,8 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
toolMenu
=
QtWidgets
.
QMenu
(
"&Tools"
)
self
.
toolMenu
.
addAction
(
self
.
databaseAct
)
self
.
toolMenu
.
addAction
(
self
.
findColorParticlesAct
)
self
.
toolMenu
.
addAction
(
self
.
recalculateParticleStatsAct
)
self
.
exportMenu
=
QtWidgets
.
QMenu
(
"&Export"
,
self
)
self
.
exportMenu
.
addAction
(
self
.
expExcelAct
)
...
...
@@ -285,16 +220,48 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
self
.
menuBar
().
addMenu
(
self
.
toolMenu
)
self
.
menuBar
().
addMenu
(
self
.
exportMenu
)
def
keyPressEvent
(
self
,
event
):
if
event
.
key
()
in
[
QtCore
.
Qt
.
Key_Return
,
QtCore
.
Qt
.
Key_Enter
]:
self
.
jumpToIndicatedSpectrum
()
def
launchDBManager
(
self
):
"""
The Database Manager is launched for editing and creating databases with reference spectra
:return:
"""
if
self
.
dbWin
.
isHidden
():
self
.
dbWin
.
show
()
def
launchColoredParticleWindow
(
self
):
"""
Likely just a temporary function to find colored particles, as the color classification is still not perfect.
The module finds not unknown particles that were assigned to a color and the user can confirm or change the respective colors.
:return:
"""
if
self
.
findcoloredParticlesWindow
is
not
None
:
del
self
.
findcoloredParticlesWindow
self
.
findcoloredParticlesWindow
=
analysiswidgets
.
FindColoredParticleWindow
(
self
)
self
.
findcoloredParticlesWindow
.
ParticleOfIndexSelected
.
connect
(
self
.
navigationToolbar
.
setWidgetsToNewParticleIndex
)
def
recalculateParticleStats
(
self
):
"""
recalculate all particle colors, if not already manually set
"""
self
.
setDisabled
(
True
)
self
.
viewparent
.
blockUI
()
reply
=
QtWidgets
.
QMessageBox
.
question
(
self
,
'Recalculate stats'
,
"Do you want recalculate stats of all particles?
\n
This might take a while.."
,
QtWidgets
.
QMessageBox
.
Yes
|
QtWidgets
.
QMessageBox
.
No
,
QtWidgets
.
QMessageBox
.
No
)
if
reply
==
QtWidgets
.
QMessageBox
.
Yes
:
updateStatsOfParticlesIfNotManuallyEdited
(
self
.
particleContainer
)
self
.
updatedPlotsAndContoursSelectively
()
QtWidgets
.
QMessageBox
.
about
(
self
,
'Done'
,
'Recalculation is finished'
)
self
.
viewparent
.
unblockUI
()
self
.
setDisabled
(
False
)
def
populateRefSelector
(
self
):
#delete all present entries:
"""
The Combobox for selecting references is updated to the currently selected database
:return:
"""
self
.
refSelector
.
clear
()
if
self
.
dbWin
.
activeDatabase
is
None
:
...
...
@@ -312,144 +279,79 @@ class ParticleAnalysis(QtWidgets.QMainWindow):
@
QtCore
.
pyqtSlot
()
def
applyHQIThresholdToResults
(
self
):
"""
The in the hqiSpinBox indicated value is applied to all spectra in the dataset.
All plots are updated, as the assignment of each particle can have changed.
:return:
"""
hqi
=
self
.
hqiSpinBox
.
value
()
self
.
particleContainer
.
applyHQITresholdToParticles
(
hqi
)
self
.
dataset
.
resultParams
[
'minHQI'
]
=
hqi
self
.
dataset
.
save
()
self
.
createHistogramData
()
self
.
updateHistogramsAndContours
()
def
updateHistogramsAndContours
(
self
):
self
.
createHistogramData
()
t0
=
time
.
time
()
self
.
updateWidgetContents
()
self
.
updatePlotsAndContours
()
def
updatePlotsAndContours
(
self
):
"""
All plots are updated, the colors of the contourItems in the sampleview are updated
:return:
"""
self
.
updateTypeHistogram
()
print
(
'update type hist: {} ms'
.
format
(
round
((
time
.
time
()
-
t0
)
*
1000
)))
t0
=
time
.
time
()
self
.
updateSizeHistogram
()
print
(
'update size hist: {} ms'
.
format
(
round
((
time
.
time
()
-
t0
)
*
1000
)))
t0
=
time
.
time
()
self
.
updateContourColors
()
print
(
'update contours: {} ms'
.
format
(
round
((
time
.
time
()
-
t0
)
*
1000
)))
t0
=
time
.
time
()
self
.
updateLegend
()
print
(
'update legend: {} ms'
.
format
(
round
((
time
.
time
()
-
t0
)
*
1000
)))
self
.
dataset
.
save
()
def
createHistogramData
(
self
):
self
.
lastSelectedCheckBoxNames
=
self
.
getSelectedPolymers
()
###Handle Checkboxes for all polymers...
self
.
menuLayout
.
removeWidget
(
self
.
resultScrollarea
)
for
i
in
[
self
.
resultCheckBoxes
,
self
.
resultCheckBoxesLayout
,
self
.
resultScrollarea
,
self
.
layout_SArea
]:
i
.
setParent
(
None
)
del
i
for
i
in
self
.
polymerCheckBoxes
:
#remove present boxlabels
i
.
setParent
(
None
)