forked from ColinTalbert/sahm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SahmOutputViewer.py
793 lines (668 loc) · 37.7 KB
/
SahmOutputViewer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
###############################################################################
##
## Copyright (C) 2010-2012, USGS Fort Collins Science Center.
## All rights reserved.
## Contact: talbertc@usgs.gov
##
## This file is part of the Software for Assisted Habitat Modeling package
## for VisTrails.
##
## "Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are met:
##
## - Redistributions of source code must retain the above copyright notice,
## this list of conditions and the following disclaimer.
## - Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
## - Neither the name of the University of Utah nor the names of its
## contributors may be used to endorse or promote products derived from
## this software without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
## OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
## Although this program has been used by the U.S. Geological Survey (USGS),
## no warranty, expressed or implied, is made by the USGS or the
## U.S. Government as to the accuracy and functioning of the program and
## related program material nor shall the fact of distribution constitute
## any such warranty, and no responsibility is assumed by the USGS
## in connection therewith.
##
## Any use of trade, firm, or product names is for descriptive purposes only
## and does not imply endorsement by the U.S. Government.
###############################################################################
################################################################################
# ImageViewer widgets/toolbar implementation
################################################################################
from PyQt4 import QtCore, QtGui
from core.system import systemType
if systemType in ['Microsoft', 'Windows']:
from PyQt4 import QAxContainer
from core.modules.vistrails_module import Module
from packages.spreadsheet.basic_widgets import SpreadsheetCell, CellLocation
from packages.spreadsheet.spreadsheet_cell import QCellWidget, QCellToolBar
from packages.spreadsheet.spreadsheet_controller import spreadsheetController
from sahm_picklists import ModelOutputType
import utils
from core.packagemanager import get_package_manager
import os
import itertools
import GenerateModuleDoc as GenModDoc
doc_file = os.path.abspath(os.path.join(os.path.dirname(__file__), "documentation.xml"))
GenModDoc.load_documentation(doc_file)
################################################################################
class SAHMModelOutputViewerCell(SpreadsheetCell):
"""
"""
__doc__ = GenModDoc.construct_module_doc('SAHMModelOutputViewerCell')
_input_ports = [("row", "(edu.utah.sci.vistrails.basic:Integer)"),
("column", "(edu.utah.sci.vistrails.basic:Integer)"),
('ModelWorkspace', '(edu.utah.sci.vistrails.basic:Directory)'),
('InitialModelOutputDisplay', '(gov.usgs.sahm:ModelOutputType:Other)', {'defaults':"['AUC']"})
]
@classmethod
def provide_input_port_documentation(cls, port_name):
return utils.construct_port_msg(cls, port_name, 'in')
@classmethod
def provide_output_port_documentation(cls, port_name):
return utils.construct_port_msg(cls, port_name, 'out')
def findFile(self, modelDir, suffix):
try:
files = os.listdir(modelDir)
for f in files:
if f.endswith(suffix):
return os.path.join(modelDir, f)
except:
return "Couldn't find file"
return "Couldn't find file"
def compute(self):
""" compute() -> None
Dispatch the display event to the spreadsheet with images and labels
"""
if self.hasInputFromPort("ModelWorkspace") and \
utils.checkIfModelFinished(self.getInputFromPort("ModelWorkspace").name):
window = spreadsheetController.findSpreadsheetWindow()
model_workspace = self.getInputFromPort("ModelWorkspace").name
model_dir_full = os.path.normcase(model_workspace)
model_dir = os.path.split(model_dir_full)[1]
model_name = model_dir[:model_dir.index('_')]
auc_graph_path = self.findFile(model_dir_full, '_modelEvalPlot.jpg')#os.path.join(model_dir_full, model_name + '_modelEvalPlot.jpg')
if os.path.exists(auc_graph_path):
auc_graph = window.file_pool.make_local_copy(auc_graph_path)
text_output_path = self.findFile(model_dir_full, '_output.txt')#os.path.join(model_dir_full, model_name + '_output.txt')
if os.path.exists(text_output_path):
text_output = window.file_pool.make_local_copy(text_output_path)
response_directory = os.path.join(model_dir_full,'responseCurves')
if os.path.exists(response_directory):
responseCurveFiles = os.listdir(response_directory)
response_curves = []
for response_curve in responseCurveFiles:
if response_curve != "Thumbs.db": #Windows grief
response_curves.append(os.path.join(response_directory, response_curve))
else:
response_curves = []
calibration_graph_path = self.findFile(model_dir_full, '_CalibrationPlot.jpg')#os.path.join(model_dir_full, model_name + '_CalibrationPlot.jpg')
if os.path.exists(calibration_graph_path):
calibration_graph = window.file_pool.make_local_copy(calibration_graph_path)
confusion_graph_path = self.findFile(model_dir_full, '.confusion.matrix.jpg')#os.path.join(model_dir_full, model_name + '.confusion.matrix.jpg')
if os.path.exists(confusion_graph_path):
confusion_graph = window.file_pool.make_local_copy(confusion_graph_path)
residuals_graph_path = self.findFile(model_dir_full, '.resid.plot.jpg')#os.path.join(model_dir_full, model_name + '.resid.plot.jpg')
if os.path.exists(residuals_graph_path):
residuals_graph = window.file_pool.make_local_copy(residuals_graph_path)
variable_imp_path = self.findFile(model_dir_full, '_variable.importance.jpg')#os.path.join(model_dir_full, model_name + '_variable.importance.jpg')
if os.path.exists(variable_imp_path):
variable_graph = window.file_pool.make_local_copy(variable_imp_path)
model_label = model_dir.capitalize().replace('output', 'Output')
if self.hasInputFromPort("row"):
if not self.location:
self.location = CellLocation()
self.location.row = self.getInputFromPort('row') - 1
if self.hasInputFromPort("column"):
if not self.location:
self.location = CellLocation()
self.location.col = self.getInputFromPort('column') - 1
if self.hasInputFromPort('InitialModelOutputDisplay'):
initial_display = self.getInputFromPort('InitialModelOutputDisplay')
else:
initial_display = 'AUC'
self.cellWidget = self.displayAndWait(SAHMOutputViewerCellWidget, (auc_graph,
text_output,
response_curves,
calibration_graph,
confusion_graph,
residuals_graph,
variable_graph,
model_label,
initial_display))
else:
fileValue = None
class SAHMOutputViewerCellWidget(QCellWidget):
"""
SAHMOutputViewerCellWidget is the widget that will display the various
non spatial outputs from a model run
"""
def __init__(self, parent=None):
QCellWidget.__init__(self, parent)
self.sync_changes = "all"
centralLayout = QtGui.QVBoxLayout()
self.setLayout(centralLayout)
centralLayout.setMargin(0)
centralLayout.setSpacing(0)
# self.setAnimationEnabled(True)
self.Frame = QtGui.QFrame()
self.ui = Ui_Frame()
self.ui.setupUi(self.Frame)
# #add scenes to our graphicViews
# self.gs_prob_map = QtGui.QGraphicsScene()
# self.ui.gv_prob_map.setScene(self.gs_prob_map)
# self.gs_prob_map.wheelEvent = self.wheel_event_prob
self.gs_crv_graph = QtGui.QGraphicsScene()
self.ui.gv_crv.setScene(self.gs_crv_graph)
QtCore.QObject.connect(self.ui.crv_combobox, QtCore.SIGNAL("currentIndexChanged(QString)"), self.changeResponseCurve)
# self.ui.crv_combobox.currentIndexChanged = self.changeResponseCurve
self.gs_crv_graph.wheelEvent = self.wheel_event_crv
self.gs_auc_graph = QtGui.QGraphicsScene()
self.ui.gv_auc.setScene(self.gs_auc_graph)
self.gs_auc_graph.wheelEvent = self.wheel_event_auc
# self.gs_response_graph = QtGui.QGraphicsScene()
# self.ui.gv_response.setScene(self.gs_response_graph)
# self.gs_response_graph.wheelEvent = self.wheel_event_response
self.gs_calibration_graph = QtGui.QGraphicsScene()
self.ui.gv_calibration.setScene(self.gs_calibration_graph)
self.gs_calibration_graph.wheelEvent = self.wheel_event_calibration
self.gs_confusion_graph = QtGui.QGraphicsScene()
self.ui.gv_confusion.setScene(self.gs_confusion_graph)
self.gs_confusion_graph.wheelEvent = self.wheel_event_confusion
self.gs_residuals_graph = QtGui.QGraphicsScene()
self.ui.gv_residuals.setScene(self.gs_residuals_graph)
self.gs_residuals_graph.wheelEvent = self.wheel_event_residuals
self.gs_variable_graph = QtGui.QGraphicsScene()
self.ui.gv_variable.setScene(self.gs_variable_graph)
self.gs_variable_graph.wheelEvent = self.wheel_event_variable
#add in ie browsers for the text and response
if systemType in ['Microsoft', 'Windows']:
self.text_browser = QAxContainer.QAxWidget(self)
self.text_browser.setFocusPolicy(QtCore.Qt.StrongFocus)
self.text_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}")
self.ui.text_output_layout.addWidget(self.text_browser)
else:
self.text_browser = None
self.text_urlSrc = None
# layout = QtGui.QVBoxLayout()
# self.response_frame = QtGui.QFrame(self)
# self.response_graph = QtGui.QGraphicsScene()
# self.ui.gv_response.setScene(self.response_graph)
# self.response_graph.wheelEvent = self.wheel_event_response
# self.response_browser = QAxContainer.QAxWidget(self)
# self.response_browser.setFocusPolicy(QtCore.Qt.StrongFocus)
# self.response_browser.setControl("{8856F961-340A-11D0-A96B-00C04FD705A2}")
# self.ui.response_curves_layout.addWidget(self.response_browser)
# self.response_urlSrc = None
self.connect(self.ui.tabWidget,QtCore.SIGNAL('currentChanged(int)'), self.tabChanged)
self.layout().addWidget(self.Frame)
def changeResponseCurve(self, event):
active_cells = self.get_active_cells()
for cell in active_cells:
try:
responseCurve = [rc for rc in cell.response_curves if os.path.splitext(os.path.split(rc)[1])[0]==event][0]
pixmap_crv = QtGui.QPixmap(responseCurve)
max_size = self.getMaxSize(cell.ui.gv_crv)
scaled_pixmap_crv = pixmap_crv.scaled(max_size, max_size,
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
cell.images['crv_graph'] = [pixmap_crv,
scaled_pixmap_crv,
cell.gs_crv_graph,
cell.ui.gv_crv,
max_size]
cell.ui.crv_combobox.blockSignals(True)
curIndex = [i for i in range(cell.ui.crv_combobox.count()) if cell.ui.crv_combobox.itemText(i)==event][0]
cell.ui.crv_combobox.setCurrentIndex(curIndex)
cell.ui.crv_combobox.blockSignals(False)
except IndexError:
cell.images['crv_graph'] = [QtGui.QPixmap(),
QtGui.QPixmap(),
cell.gs_crv_graph,
cell.ui.gv_crv,
100]
cell.ui.crv_combobox.blockSignals(True)
cell.ui.crv_combobox.setCurrentIndex(-1)
cell.ui.crv_combobox.blockSignals(False)
cell.view_current()
def tabChanged(self):
active_cells = self.get_active_cells()
for cell in active_cells:
cell.ui.tabWidget.setCurrentIndex(self.ui.tabWidget.currentIndex())
def updateContents(self, inputPorts):
""" updateContents(inputPorts: tuple) -> None
Update the widget contents based on the input data
"""
(auc_graph, text_output, self.response_curves, calibration_graph, confusion_graph,
residuals_graph, variable_graph, model_label, inital_display) = inputPorts
self.images = {}
if auc_graph:
pixmap = QtGui.QPixmap(auc_graph.name)
max_size = self.getMaxSize(self.ui.gv_auc)
scaled_pixmap = pixmap.scaled(max_size, max_size,
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
self.images['auc_graph'] = [pixmap,
scaled_pixmap,
self.gs_auc_graph,
self.ui.gv_auc,
max_size]
# if response_curves:
# for response_curve in response_curves:
# shortName = os.path.split(response_curve)[1]
# shortName = os.path.splitext(shortName)[0]
## if shortName != "Thumbs":
## self.ui.response_combobox.addItem(shortName)
#
# pixmap_response = QtGui.QPixmap(response_curves[0])
# max_size = self.getMaxSize(self.ui.gv_response)
# scaled_pixmap_response = pixmap_response.scaled(max_size, max_size,
# QtCore.Qt.KeepAspectRatio,
# QtCore.Qt.SmoothTransformation)
#
# self.images['response_graph'] = [pixmap_response,
# scaled_pixmap_response,
# self.gs_response_graph,
# self.ui.gv_response,
# max_size]
self.ui.crv_combobox.clear()
curindex = 0
if self.response_curves:
for response_curve in self.response_curves:
shortName = os.path.split(response_curve)[1]
shortName = os.path.splitext(shortName)[0]
if shortName != "Thumbs":
self.ui.crv_combobox.addItem(shortName)
if shortName == "all_response_curves":
all_curves_index = curindex
curindex += 1
try:
self.ui.crv_combobox.setCurrentIndex(all_curves_index)
except:
pass
if calibration_graph:
pixmap_cal = QtGui.QPixmap(calibration_graph.name)
max_size = self.getMaxSize(self.ui.gv_calibration)
scaled_pixmap_cal = pixmap_cal.scaled(max_size, max_size,
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
self.images['calibration_graph'] = [pixmap_cal,
scaled_pixmap_cal,
self.gs_calibration_graph,
self.ui.gv_calibration,
max_size]
if confusion_graph:
pixmap_con = QtGui.QPixmap(confusion_graph.name)
max_size = self.getMaxSize(self.ui.gv_confusion)
scaled_pixmap_con = pixmap_con.scaled(max_size, max_size,
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
self.images['confusion_graph'] = [pixmap_con,
scaled_pixmap_con,
self.gs_confusion_graph,
self.ui.gv_confusion,
max_size]
if residuals_graph:
pixmap_res = QtGui.QPixmap(residuals_graph.name)
max_size = self.getMaxSize(self.ui.gv_residuals)
scaled_pixmap_res = pixmap_res.scaled(max_size, max_size,
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
self.images['residuals_graph'] = [pixmap_res,
scaled_pixmap_res,
self.gs_residuals_graph,
self.ui.gv_residuals,
max_size]
if variable_graph:
pixmap_res = QtGui.QPixmap(variable_graph.name)
max_size = self.getMaxSize(self.ui.gv_variable)
scaled_pixmap_res = pixmap_res.scaled(max_size, max_size,
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation)
self.images['variable_graph'] = [pixmap_res,
scaled_pixmap_res,
self.gs_variable_graph,
self.ui.gv_variable,
max_size]
self.text_urlSrc = QtCore.QUrl.fromLocalFile(text_output.name)
if self.text_browser is not None:
if self.text_urlSrc!=None:
self.text_browser.dynamicCall('Navigate(const QString&)', self.text_urlSrc.toString())
else:
self.text_browser.dynamicCall('Navigate(const QString&)', QtCore.QString('about:blank'))
choices = ['Text', 'Response Curves', 'AUC', 'Calibration', 'Confusion', 'Residuals','Variable Importance']
selected_index = choices.index(inital_display)
self.ui.tabWidget.setCurrentIndex(selected_index)
self.view_current()
#QCellWidget.updateContents(self, inputPorts)
def getMaxSize(self, view):
return self.Frame.size().width() - 10
# if view.size().width() <= view.size().height():
# return view.size().width() * 0.95
# else:
# return view.size().height() * 0.95
def view_current(self):
for k,v in self.images.iteritems():
size_img = v[1].size()
wth, hgt = QtCore.QSize.width(size_img), QtCore.QSize.height(size_img)
v[2].clear()
v[2].setSceneRect(0, 0, wth, hgt)
v[2].addPixmap(v[1])
QtCore.QCoreApplication.processEvents()
def wheel_event_prob(self, event):
self.wheel_event(event, 'prob_map', QtCore.Qt.FastTransformation)
def wheel_event_auc(self, event):
self.wheel_event(event, 'auc_graph', QtCore.Qt.SmoothTransformation)
def wheel_event_crv(self, event):
self.wheel_event(event, 'crv_graph', QtCore.Qt.SmoothTransformation)
def wheel_event_calibration(self, event):
self.wheel_event(event, 'calibration_graph', QtCore.Qt.SmoothTransformation)
def wheel_event_confusion(self, event):
self.wheel_event(event, 'confusion_graph', QtCore.Qt.SmoothTransformation)
def wheel_event_residuals(self, event):
self.wheel_event(event, 'residuals_graph', QtCore.Qt.SmoothTransformation)
def wheel_event_variable(self, event):
self.wheel_event(event, 'variable_graph', QtCore.Qt.SmoothTransformation)
def wheel_event (self, event, id, transform):
numDegrees = event.delta() / 8
numSteps = numDegrees / 15.0
# self.zoom(numSteps, self.images[id], transform)
# event.accept()
active_cells = self.get_active_cells()
for cell in active_cells:
# if cell != self:
cell.zoom(numSteps, cell.images[id], transform)
cell.view_current()
def zoom(self, step, images, transform):
zoom_step = 0.06
images[2].clear()
w = images[1].size().width()
h = images[1].size().height()
w, h = w * (1 + zoom_step*step), h * (1 + zoom_step*step)
images[1] = images[0].scaled(w, h,
QtCore.Qt.KeepAspectRatio,
transform)
def saveToPNG(self, filename):
""" saveToPNG(filename: str) -> bool
Save the current widget contents to an image file
"""
pixmap = QtGui.QPixmap(self.Frame.size())
painter = QtGui.QPainter(pixmap)
self.Frame.render(painter)
painter.end()
if pixmap and (not pixmap.isNull()):
return pixmap.save(filename)
return False
def saveToPDF(self, filename):
""" saveToPDF(filename: str) -> bool
Save the current widget contents to a pdf file
"""
printer = QtGui.QPrinter()
printer.setOutputFormat(QtGui.QPrinter.PdfFormat)
printer.setOutputFileName(filename)
painter = QtGui.QPainter()
painter.begin(printer)
rect = painter.viewport()
pixmap = self.label.pixmap()
size = pixmap.size()
size.scale(rect.size(), QtCore.Qt.KeepAspectRatio)
painter.setViewport(rect.x(), rect.y(), size.width(), size.height())
painter.setWindow(pixmap.rect())
painter.drawPixmap(0, 0, pixmap)
painter.end()
def findSheetTabWidget(self):
""" findSheetTabWidget() -> QTabWidget
Find and return the sheet tab widget
"""
p = self.parent()
while p:
if hasattr(p, 'isSheetTabWidget'):
if p.isSheetTabWidget()==True:
return p
p = p.parent()
return None
def getSAHMOutputsInCellList(self, sheet, cells):
""" Get the list of SAHM output viewers
inside a list of (row, column) cells.
"""
SAHMspatials = []
for (row, col) in cells:
cell = sheet.getCell(row, col)
if hasattr(cell, 'gs_auc_graph'):
SAHMspatials.append(cell)
return SAHMspatials
def getSelectedCellWidgets(self):
sheet = self.findSheetTabWidget()
if sheet:
selected_cells = sheet.getSelectedLocations()
return self.getSAHMOutputsInCellList(sheet, selected_cells)
return []
def get_allCellWidgets(self):
sheet = self.findSheetTabWidget()
if sheet:
all_cells = list(itertools.product(range(sheet.getDimension()[0]), range(sheet.getDimension()[1])))
return self.getSAHMOutputsInCellList(sheet, all_cells)
return []
def get_active_cells(self):
if self.sync_changes == "all":
return self.get_allCellWidgets()
elif self.sync_changes == "sel":
return self.getSelectedCellWidgets()
else:
return [self]
class ImageViewerFitToCellAction(QtGui.QAction):
"""
ImageViewerFitToCellAction is the action to stretch the image to
fit inside a cell
"""
def __init__(self, parent=None):
""" ImageViewerFitToCellAction(parent: QWidget)
-> ImageViewerFitToCellAction
Setup the image, status tip, etc. of the action
"""
QtGui.QAction.__init__(self,
QtGui.QIcon(":/images/fittocell.png"),
"&Fit To Cell",
parent)
self.setStatusTip("Scale image content to fit cell frame")
self.setCheckable(True)
self.setChecked(True)
def toggledSlot(self, checked):
""" toggledSlot(checked: boolean) -> None
Execute the action when the button is toggled
"""
cellWidget = self.toolBar.getSnappedWidget()
cellWidget.label.setScaledContents(checked)
self.toolBar.slider.updateStatus((self.toolBar.sheet,
self.toolBar.row,
self.toolBar.col,
cellWidget))
def updateStatus(self, info):
""" updateStatus(info: tuple) -> None
Updates the status of the button based on the input info
"""
(sheet, row, col, cellWidget) = info
self.setChecked(cellWidget.label.hasScaledContents())
class ImageViewerSaveAction(QtGui.QAction):
"""
ImageViewerSaveAction is the action to save the image to file
"""
def __init__(self, parent=None):
""" ImageViewerSaveAction(parent: QWidget) -> ImageViewerSaveAction
Setup the image, status tip, etc. of the action
"""
QtGui.QAction.__init__(self,
QtGui.QIcon(":/images/save.png"),
"&Save image as...",
parent)
self.setStatusTip("Save image to file")
def triggeredSlot(self, checked=False):
""" toggledSlot(checked: boolean) -> None
Execute the action when the button is clicked
"""
cellWidget = self.toolBar.getSnappedWidget()
if not cellWidget.label.pixmap() or cellWidget.label.pixmap().isNull():
return
fn = QtGui.QFileDialog.getSaveFileName(None, "Save image as...",
"screenshot.png",
"Images (*.png);;PDF files (*.pdf)")
if not fn:
return
if fn.endsWith(QtCore.QString("png"), QtCore.Qt.CaseInsensitive):
cellWidget.label.pixmap().toImage().save(fn, "png")
elif fn.endsWith(QtCore.QString("pdf"), QtCore.Qt.CaseInsensitive):
cellWidget.saveToPDF(str(fn))
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName(_fromUtf8("Frame"))
Frame.resize(546, 402)
Frame.setWindowTitle(QtGui.QApplication.translate("Frame", "Frame", None, QtGui.QApplication.UnicodeUTF8))
Frame.setFrameShape(QtGui.QFrame.StyledPanel)
Frame.setFrameShadow(QtGui.QFrame.Raised)
self.horizontalLayout = QtGui.QHBoxLayout(Frame)
self.horizontalLayout.setSpacing(0)
self.horizontalLayout.setMargin(0)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.tabWidget = QtGui.QTabWidget(Frame)
self.tabWidget.setEnabled(True)
self.tabWidget.setTabPosition(QtGui.QTabWidget.North)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.text_output = QtGui.QWidget()
self.text_output.setObjectName(_fromUtf8("text_output"))
self.text_output_layout = QtGui.QHBoxLayout(self.text_output)
self.text_output_layout.setSpacing(0)
self.text_output_layout.setMargin(0)
self.text_output_layout.setObjectName(_fromUtf8("text_output_layout"))
self.tabWidget.addTab(self.text_output, _fromUtf8(""))
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.text_output), QtGui.QApplication.translate("Frame", "Textual model output ", None, QtGui.QApplication.UnicodeUTF8))
# self.response_curves = QtGui.QWidget()
# self.response_curves.setObjectName(_fromUtf8("response_curves"))
# self.response_curves_layout = QtGui.QHBoxLayout(self.response_curves)
# self.response_curves_layout.setSpacing(0)
# self.response_curves_layout.setMargin(0)
# self.response_curves_layout.setObjectName(_fromUtf8("response_curves_layout"))
## self.response_combobox = QtGui.QComboBox(self.response_curves)
## self.response_curves_layout.addWidget(self.response_combobox)
# self.gv_response = QtGui.QGraphicsView(self.response_curves)
# self.gv_response.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
# self.gv_response.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
# self.gv_response.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
# self.gv_response.setObjectName(_fromUtf8("gv_response"))
# self.response_curves_layout.addWidget(self.gv_response)
# self.tabWidget.addTab(self.response_curves, _fromUtf8(""))
# self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.response_curves), QtGui.QApplication.translate("Frame", "Response curves", None, QtGui.QApplication.UnicodeUTF8))
self.crv = QtGui.QWidget()
self.crv.setObjectName(_fromUtf8("crv"))
self.horizontalLayout_4crv = QtGui.QVBoxLayout(self.crv)
self.horizontalLayout_4crv.setSpacing(0)
self.horizontalLayout_4crv.setMargin(0)
self.horizontalLayout_4crv.setObjectName(_fromUtf8("horizontalLayout_4crv"))
self.crv_combobox = QtGui.QComboBox(self.crv)
self.horizontalLayout_4crv.addWidget(self.crv_combobox)
self.gv_crv = QtGui.QGraphicsView(self.crv)
self.gv_crv.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
self.gv_crv.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_crv.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_crv.setObjectName(_fromUtf8("gv_crv"))
self.horizontalLayout_4crv.addWidget(self.gv_crv)
self.tabWidget.addTab(self.crv, _fromUtf8(""))
self.auc = QtGui.QWidget()
self.auc.setObjectName(_fromUtf8("auc"))
self.horizontalLayout_4 = QtGui.QHBoxLayout(self.auc)
self.horizontalLayout_4.setSpacing(0)
self.horizontalLayout_4.setMargin(0)
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
self.gv_auc = QtGui.QGraphicsView(self.auc)
self.gv_auc.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
self.gv_auc.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_auc.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_auc.setObjectName(_fromUtf8("gv_auc"))
self.horizontalLayout_4.addWidget(self.gv_auc)
self.tabWidget.addTab(self.auc, _fromUtf8(""))
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.auc), QtGui.QApplication.translate("Frame", "Area under the curve (AUC)", None, QtGui.QApplication.UnicodeUTF8))
self.calibration = QtGui.QWidget()
self.calibration.setObjectName(_fromUtf8("calibration"))
self.horizontalLayout_5 = QtGui.QHBoxLayout(self.calibration)
self.horizontalLayout_5.setSpacing(0)
self.horizontalLayout_5.setMargin(0)
self.horizontalLayout_5.setObjectName(_fromUtf8("horizontalLayout_5"))
self.gv_calibration = QtGui.QGraphicsView(self.calibration)
self.gv_calibration.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
self.gv_calibration.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_calibration.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_calibration.setObjectName(_fromUtf8("gv_calibration"))
self.horizontalLayout_5.addWidget(self.gv_calibration)
self.tabWidget.addTab(self.calibration, _fromUtf8(""))
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.calibration), QtGui.QApplication.translate("Frame", "Calibration plot", None, QtGui.QApplication.UnicodeUTF8))
self.confusion = QtGui.QWidget()
self.confusion.setObjectName(_fromUtf8("confusion"))
self.horizontalLayout_6 = QtGui.QHBoxLayout(self.confusion)
self.horizontalLayout_6.setSpacing(0)
self.horizontalLayout_6.setMargin(0)
self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6"))
self.gv_confusion = QtGui.QGraphicsView(self.confusion)
self.gv_confusion.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
self.gv_confusion.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_confusion.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_confusion.setObjectName(_fromUtf8("gv_confusion"))
self.horizontalLayout_6.addWidget(self.gv_confusion)
self.tabWidget.addTab(self.confusion, _fromUtf8(""))
self.tabWidget.setTabToolTip(self.tabWidget.indexOf(self.confusion), QtGui.QApplication.translate("Frame", "Confusion matrix", None, QtGui.QApplication.UnicodeUTF8))
self.residuals = QtGui.QWidget()
self.residuals.setObjectName(_fromUtf8("residuals"))
self.horizontalLayout_7 = QtGui.QHBoxLayout(self.residuals)
self.horizontalLayout_7.setSpacing(0)
self.horizontalLayout_7.setMargin(0)
self.horizontalLayout_7.setObjectName(_fromUtf8("horizontalLayout_7"))
self.gv_residuals = QtGui.QGraphicsView(self.residuals)
self.gv_residuals.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
self.gv_residuals.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_residuals.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_residuals.setObjectName(_fromUtf8("gv_residuals"))
self.horizontalLayout_7.addWidget(self.gv_residuals)
self.tabWidget.addTab(self.residuals, _fromUtf8(""))
self.variable = QtGui.QWidget()
self.variable.setObjectName(_fromUtf8("variable"))
self.horizontalLayout_7 = QtGui.QHBoxLayout(self.variable)
self.horizontalLayout_7.setSpacing(0)
self.horizontalLayout_7.setMargin(0)
self.horizontalLayout_7.setObjectName(_fromUtf8("horizontalLayout_7"))
self.gv_variable = QtGui.QGraphicsView(self.variable)
self.gv_variable.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
self.gv_variable.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_variable.setResizeAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
self.gv_variable.setObjectName(_fromUtf8("gv_variable"))
self.horizontalLayout_7.addWidget(self.gv_variable)
self.tabWidget.addTab(self.variable, _fromUtf8(""))
self.horizontalLayout.addWidget(self.tabWidget)
self.retranslateUi(Frame)
self.tabWidget.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.text_output), QtGui.QApplication.translate("Frame", "Text Results", None, QtGui.QApplication.UnicodeUTF8))
# self.tabWidget.setTabText(self.tabWidget.indexOf(self.response_curves), QtGui.QApplication.translate("Frame", "Response", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.crv), QtGui.QApplication.translate("Frame", "Response Curves", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.auc), QtGui.QApplication.translate("Frame", "AUC", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.calibration), QtGui.QApplication.translate("Frame", "Calibration", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.confusion), QtGui.QApplication.translate("Frame", "Confusion", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.residuals), QtGui.QApplication.translate("Frame", "Residuals", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.variable), QtGui.QApplication.translate("Frame", "Variable Importance", None, QtGui.QApplication.UnicodeUTF8))