def FillSurveys(self): self.AS=AllSurveys(self.ODB) FullName=self.AS.GetCombo() for fn in FullName: item=QListWidgetItem(fn) self.AvailSurveys.addItem(item) self.AvailSurveys.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)
class Ui_Dialog(object): def __init__(self,Dialog,ODB,OUTmdb): self.setupUi(Dialog) self.inMDB=ODB self.resultODB=OUTmdb self.OUTmdb=self.resultODB.ODB self.ODB=self.inMDB.ODB self.FillSurveys() self.FillTranChar() self.MakeConnect() self.DefaultSettings() def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(692, 769) font = QtGui.QFont() font.setPointSize(12) Dialog.setFont(font) self.AllSurveys = QtGui.QCheckBox(Dialog) self.AllSurveys.setGeometry(QtCore.QRect(30, 224, 141, 41)) self.AllSurveys.setStyleSheet(_fromUtf8("font: 12pt \"MS Shell Dlg 2\";")) self.AllSurveys.setObjectName(_fromUtf8("AllSurveys")) self.label = QtGui.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(30, 4, 241, 31)) self.label.setObjectName(_fromUtf8("label")) self.label_2 = QtGui.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(290, 4, 241, 31)) self.label_2.setObjectName(_fromUtf8("label_2")) self.groupBox_2 = QtGui.QGroupBox(Dialog) self.groupBox_2.setGeometry(QtCore.QRect(20, 284, 131, 241)) font = QtGui.QFont() font.setPointSize(8) self.groupBox_2.setFont(font) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.USB50 = QtGui.QRadioButton(self.groupBox_2) self.USB50.setGeometry(QtCore.QRect(30, 210, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB50.setFont(font) self.USB50.setAutoExclusive(False) self.USB50.setObjectName(_fromUtf8("USB50")) self.NumberBootstrapLabel = QtGui.QLabel(Dialog) self.NumberBootstrapLabel.setGeometry(QtCore.QRect(430, 290, 131, 41)) self.NumberBootstrapLabel.setWordWrap(True) self.NumberBootstrapLabel.setObjectName(_fromUtf8("NumberBootstrapLabel")) self.NumberBootstrap = QtGui.QPlainTextEdit(Dialog) self.NumberBootstrap.setGeometry(QtCore.QRect(320, 290, 101, 31)) self.NumberBootstrap.setObjectName(_fromUtf8("NumberBootstrap")) self.RandomSeed = QtGui.QPlainTextEdit(Dialog) self.RandomSeed.setGeometry(QtCore.QRect(320, 340, 101, 31)) self.RandomSeed.setObjectName(_fromUtf8("RandomSeed")) self.RandomSeedLabel = QtGui.QLabel(Dialog) self.RandomSeedLabel.setGeometry(QtCore.QRect(430, 340, 131, 31)) self.RandomSeedLabel.setObjectName(_fromUtf8("RandomSeedLabel")) self.USB89 = QtGui.QRadioButton(Dialog) self.USB89.setGeometry(QtCore.QRect(51, 431, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB89.setFont(font) self.USB89.setAutoExclusive(False) self.USB89.setObjectName(_fromUtf8("USB89")) self.USB69 = QtGui.QRadioButton(Dialog) self.USB69.setGeometry(QtCore.QRect(51, 460, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB69.setFont(font) self.USB69.setAutoExclusive(False) self.USB69.setObjectName(_fromUtf8("USB69")) self.USB99 = QtGui.QRadioButton(Dialog) self.USB99.setGeometry(QtCore.QRect(51, 402, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB99.setFont(font) self.USB99.setAutoExclusive(False) self.USB99.setObjectName(_fromUtf8("USB99")) self.USB1000 = QtGui.QRadioButton(Dialog) self.USB1000.setGeometry(QtCore.QRect(51, 315, 59, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB1000.setFont(font) self.USB1000.setAutoExclusive(False) self.USB1000.setObjectName(_fromUtf8("USB1000")) self.USB140 = QtGui.QRadioButton(Dialog) self.USB140.setGeometry(QtCore.QRect(51, 344, 51, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB140.setFont(font) self.USB140.setAutoExclusive(False) self.USB140.setObjectName(_fromUtf8("USB140")) self.USB119 = QtGui.QRadioButton(Dialog) self.USB119.setGeometry(QtCore.QRect(51, 373, 51, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB119.setFont(font) self.USB119.setAutoExclusive(False) self.USB119.setObjectName(_fromUtf8("USB119")) self.AvailSurveys = QtGui.QListWidget(Dialog) self.AvailSurveys.setGeometry(QtCore.QRect(21, 35, 256, 192)) self.AvailSurveys.setObjectName(_fromUtf8("AvailSurveys")) self.TransectCharacteristics = QtGui.QListWidget(Dialog) self.TransectCharacteristics.setGeometry(QtCore.QRect(320, 35, 256, 111)) self.TransectCharacteristics.setObjectName(_fromUtf8("TransectCharacteristics")) self.DoCalcs = QtGui.QPushButton(Dialog) self.DoCalcs.setGeometry(QtCore.QRect(190, 440, 91, 41)) self.DoCalcs.setObjectName(_fromUtf8("DoCalcs")) self.QuitBttn = QtGui.QPushButton(Dialog) self.QuitBttn.setGeometry(QtCore.QRect(320, 440, 91, 41)) self.QuitBttn.setObjectName(_fromUtf8("QuitBttn")) self.MinDepthLabel = QtGui.QLabel(Dialog) self.MinDepthLabel.setGeometry(QtCore.QRect(430, 180, 131, 31)) self.MinDepthLabel.setWordWrap(True) self.MinDepthLabel.setObjectName(_fromUtf8("MinDepthLabel")) self.MinDepth = QtGui.QPlainTextEdit(Dialog) self.MinDepth.setGeometry(QtCore.QRect(320, 180, 101, 31)) self.MinDepth.setObjectName(_fromUtf8("MinDepth")) self.MaxDepth = QtGui.QPlainTextEdit(Dialog) self.MaxDepth.setGeometry(QtCore.QRect(320, 230, 101, 31)) self.MaxDepth.setObjectName(_fromUtf8("MaxDepth")) self.MaxDepthLabel = QtGui.QLabel(Dialog) self.MaxDepthLabel.setGeometry(QtCore.QRect(430, 230, 131, 31)) self.MaxDepthLabel.setWordWrap(True) self.MaxDepthLabel.setObjectName(_fromUtf8("MaxDepthLabel")) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle(_translate("Dialog", "Red Sea Urchin Analysis Program", None)) self.AllSurveys.setText(_translate("Dialog", "Do All Surveys?", None)) self.label.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:9pt;\">Data to Analyze [Source] [Year] [Location]:</span></p></body></html>", None)) self.label_2.setText(_translate("Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:9pt;\">Analyze by:</span></p></body></html>", None)) self.groupBox_2.setTitle(_translate("Dialog", "Upper Size Bounds (mm)", None)) self.USB50.setToolTip(_translate("Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB50.setText(_translate("Dialog", "50", None)) self.NumberBootstrapLabel.setText(_translate("Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Number of Bootstrap Repititions</span></p></body></html>", None)) self.RandomSeedLabel.setText(_translate("Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Random Seed</span></p></body></html>", None)) self.USB89.setToolTip(_translate("Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB89.setText(_translate("Dialog", "89", None)) self.USB69.setToolTip(_translate("Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB69.setText(_translate("Dialog", "69", None)) self.USB99.setToolTip(_translate("Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB99.setText(_translate("Dialog", "99", None)) self.USB1000.setToolTip(_translate("Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB1000.setText(_translate("Dialog", "1000", None)) self.USB140.setToolTip(_translate("Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB140.setText(_translate("Dialog", "140", None)) self.USB119.setToolTip(_translate("Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB119.setText(_translate("Dialog", "119", None)) self.DoCalcs.setText(_translate("Dialog", "Do\n" "Calculations", None)) self.QuitBttn.setText(_translate("Dialog", "Quit", None)) self.MinDepthLabel.setText(_translate("Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Minimum Depth (m)</span></p></body></html>", None)) self.MaxDepthLabel.setText(_translate("Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Maximum Depth (m)</span></p></body></html>", None)) def FillSurveys(self): self.AS=AllSurveys(self.ODB) FullName=self.AS.GetCombo() for fn in FullName: item=QListWidgetItem(fn) self.AvailSurveys.addItem(item) self.AvailSurveys.setSelectionMode(QtGui.QAbstractItemView.MultiSelection) def FillTranChar(self): for fieldname in ['SurveyTitle','Location','SiteNum','Year','StatArea','SubArea','InBed']: item=QListWidgetItem(fieldname) self.TransectCharacteristics.addItem(item) self.TransectCharacteristics.setSelectionMode(QtGui.QAbstractItemView.MultiSelection) def MakeConnect(self): self.DoCalcs.clicked.connect(self.Calculations) self.QuitBttn.clicked.connect(self.QuitCalcs) self.AllSurveys.stateChanged.connect(self.DoAllSurveys) self.TransectCharacteristics.itemSelectionChanged.connect(self.CoordStatAreaSubArea) def Calculations(self): print ('Calculations Started') seed(int(self.RandomSeed.document().toPlainText())) self.GetSelectedSurveys() self.GetSelectedTranChar() self.GetSelectedUppSizeBound() self.TranClassChar=MetaTransectClass(self.ODB,\ self.SelectedSurveys,\ self.SelectedTranchar ) self.PrepOUTmdb() dictSelectedSurveys=self.SelectedSurveystoDict() CopyMDB(self.ODB, self.OUTmdb ,dictSelectedSurveys) CB=[99,95,90,75,50] nboot=int(self.NumberBootstrap.document().toPlainText()) for i in range(self.TranClassChar.nclass): FTC=self.TranClassChar.FormatTranClass(i) print('\n') if FTC['SurveyTitle']!='Combined': print('SurveyTitle: ',FTC['SurveyTitle' ]) if FTC['Location' ]!='Combined': print('Location: ',FTC['Location' ]) if FTC['Year' ]!=MinInt: print('Year: ',FTC['Year' ]) if FTC['Site' ]!=MinInt: print('Site: ',FTC['Site' ]) if FTC['StatArea' ]!=MinInt: print('StatArea: ',FTC['StatArea'] ) if FTC['SubArea' ]!=MinInt: print('SubArea: ',FTC['SubArea' ] ) print(len(self.TranClassChar.key[i]), ' transects') tc=transectclass(self.ODB,self.TranClassChar.key[i],self.TranClassChar.Allo[i],QueryFunc,\ SizeBound=self.UppSizeBnd,\ MinDepth=float(self.MinDepth.document().toPlainText()),\ MaxDepth=float(self.MaxDepth.document().toPlainText())) CurDeterm=tc.GetFormatEstVal() CurCB=tc.GetPctCB(CB,nboot=nboot) #Transect Classes self.OUTmdb.ADDTo_TranChar(FTC['SurveyTitle'],FTC['Location'],FTC['SiteNum'],FTC['Year'],FTC['StatArea'],FTC['SubArea'],FTC['InBed'],FTC['NumTran'],\ tc.GetSurveyedArea(),tc.GetNumSurveyedQuadInDepthRange()) tck=self.OUTmdb.GetTranCharKey(FTC['SurveyTitle'],FTC['Location'],FTC['SiteNum'],FTC['Year'],FTC['StatArea'],FTC['SubArea'],FTC['InBed']) tc.WriteTransectResults(self.OUTmdb,tck) #The confidence bounds if (CurCB!=None): for cbResult in CurCB: CBval=cbResult['CB'] SN=list(filter(lambda x:x!='CB', cbResult.keys())) for sn in SN: CurSize=cbResult[sn] SK=self.OUTmdb.GetSizeRangeKey(CurSize['SizeLimit'][-1]) self.OUTmdb.ADDTo_ConfInterval(\ tck,SK,\ CBval,\ CurSize['linear']['Pop'][0], CurSize['linear']['Pop'][1], \ CurSize['spatial']['Pop'][0], CurSize['spatial']['Pop'][1], \ CurSize['linear']['Bmass'][0], CurSize['linear']['Bmass'][1], \ CurSize['spatial']['Bmass'][0], CurSize['spatial']['Bmass'][1]) #The estimated values for sn in CurDeterm.keys(): CurSize=CurDeterm[sn] SK=self.OUTmdb.GetSizeRangeKey(CurSize['SizeLimit'][-1]) self.OUTmdb.ADDTo_EstDens(\ CurSize['linear']['Pop'],CurSize['spatial']['Pop'],\ CurSize['linear']['Bmass'],CurSize['spatial']['Bmass'],\ TranCharKey=tck,SizeKey=SK) print('\ndone MainWindow Line 274') def GetSelectedUppSizeBound(self): self.UppSizeBnd=[] if self.USB50.isChecked() :self.UppSizeBnd+=[50 ] if self.USB69.isChecked() :self.UppSizeBnd+=[69 ] if self.USB89.isChecked() :self.UppSizeBnd+=[89 ] if self.USB99.isChecked() :self.UppSizeBnd+=[99 ] if self.USB119.isChecked():self.UppSizeBnd+=[119] if self.USB140.isChecked():self.UppSizeBnd+=[140] self.UppSizeBnd+=[inf] def GetSelectedTranChar(self): self.SelectedTranchar=[] for index in range(self.TransectCharacteristics.count()): if self.TransectCharacteristics.item(index).isSelected(): self.SelectedTranchar+=[self.TransectCharacteristics.item(index).text()] def GetSelectedSurveys(self): self.SelectedSurveys=[] year=self.AS.GetYear() survey=self.AS.GetSurvey() for index in range(self.AvailSurveys.count()): if self.AvailSurveys.item(index).isSelected(): self.SelectedSurveys+=[[survey[index],year[index]]] def DoAllSurveys(self): if self.AllSurveys.isChecked(): for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(True) else: for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(False) def CoordStatAreaSubArea(self): '''Make sure statarea and subarea are coherent''' #Update list of selected transect-characteristics self.GetSelectedTranChar() #if subarea is selected, force statarea to be selected if ('SubArea' in self.SelectedTranchar) and not('StatArea' in self.SelectedTranchar) : for index in range(self.TransectCharacteristics.count()): if self.TransectCharacteristics.item(index).text()=='StatArea': self.TransectCharacteristics.item(index).setSelected(True) self.GetSelectedTranChar() def QuitCalcs(self): print ('No Calculations') sys.exit(app.exec_()) def DefaultSettings(self): self.NumberBootstrap.insertPlainText('10000') self.RandomSeed.insertPlainText('756') self.MinDepth.insertPlainText('-1000') self.MaxDepth.insertPlainText('1000') self.USB1000.setDisabled(True) self.USB1000.setChecked(True) self.USB89.setChecked(True) def PrepOUTmdb(self): '''Put information into output. Not the stats - just the metadata''' self.OUTmdb.ADDTo_Analysis(int(self.NumberBootstrap.document().toPlainText()),\ int(self.RandomSeed.document().toPlainText()),\ float(self.MinDepth.document().toPlainText()),\ float(self.MaxDepth.document().toPlainText())) self.OUTmdb.ADDTo_SizeRange(0,self.UppSizeBnd[0]) for x in range(1,len(self.UppSizeBnd)): self.OUTmdb.SizeRangeKey.Increment() self.OUTmdb.ADDTo_SizeRange(1+self.UppSizeBnd[x-1],self.UppSizeBnd[x] ) for sy in self.SelectedSurveys: self.OUTmdb.ADDTo_SurveyUsed(sy[0],sy[1]) def SelectedSurveystoDict(self): '''Convert self.SelectedSurveys as a list of dictionaries''' if isinstance(self.SelectedSurveys[0],dict): return(self.SelectedSurveys) result=[{'Location':t[0], 'Year':t[1]} for t in self.SelectedSurveys] return(result)
class SCmain(QMainWindow, Ui_MainWindow): def __init__(self, ODB, OUTmdb, parent=None): self.inMDB = ODB self.resultODB = OUTmdb QMainWindow.__init__(self, parent) self.setupUi(self) self.MakeConnect() self.OUTmdb = self.resultODB.ODB self.ODB = self.inMDB.ODB self.FillSurveys() self.FillTranChar() self.MakeConnect() self.DefaultSettings() def FillSurveys(self): self.AS = AllSurveys(self.ODB) FullName = self.AS.GetCombo() for fn in FullName: item = QListWidgetItem(fn) self.AvailSurveys.addItem(item) self.AvailSurveys.setSelectionMode( QtGui.QAbstractItemView.MultiSelection) def FillTranChar(self): for fieldname in ['Project', 'Site', 'Year', 'StatArea', 'SubArea']: item = QListWidgetItem(fieldname) self.TransectCharacteristics.addItem(item) self.TransectCharacteristics.setSelectionMode( QtGui.QAbstractItemView.MultiSelection) def MakeConnect(self): self.DoCalcs.clicked.connect(self.Calculations) self.QuitBttn.clicked.connect(self.QuitCalcs) self.AllSurveys.stateChanged.connect(self.DoAllSurveys) def Calculations(self): #Do nothing unless some surveys are selected if self.AvailSurveys.count() == 0: return seed(int(self.RandomSeed.document().toPlainText())) try: self.GetSelectedSurveys() except: self.QuitCalcs() #copy stubs of input tables to the output file. dictSelectedSurveys = self.SelectedSurveystoDict() CopyMDB(self.ODB, self.OUTmdb, dictSelectedSurveys) print('\nCalculations Started') self.GetSelectedTranChar() self.TranClassChar=MetaTransectClass(self.ODB,\ self.SelectedSurveys,\ self.SelectedTranchar) CB = [99, 95, 90, 75, 50] self.Comments = self.RunComments.document().toPlainText() self.nboot = int(self.NumberBootstrap.document().toPlainText()) self.seed = int(self.RandomSeed.document().toPlainText()) self.LeastDepth = float(self.MinDepth.document().toPlainText()) self.MostDepth = float(self.MaxDepth.document().toPlainText()) self.SourceMeanWeight = 'LogBook' if self.MarketSample.isChecked(): self.SourceMeanWeight = 'MarketSample' if self.Biodata.isChecked(): self.SourceMeanWeight = 'Biodata' self.species = 'californicus' import californicusQueryFunc as QueryFunc if self.miniata.isChecked(): self.species = 'miniata' import miniataQueryFunc as QueryFunc if self.pallida.isChecked(): self.species = 'pallida' import pallidaQueryFunc as QueryFunc AlloSource = QueryFunc.AlloEqn() self.PrepOUTmdb() SiteCB = [] SiteEst = [] for i in range(self.TranClassChar.nclass): FMT = self.TranClassChar.FormatTranClass(i) print('\n') if FMT['Project'] != 'Combined': print('Project: ', FMT['Project']) if FMT['Site'] != MinInt: print('Site: ', FMT['Site']) if FMT['Year'] != MinInt: print('Year: ', FMT['Year']) if FMT['StatArea'] != MinInt: print('StatArea: ', FMT['StatArea']) if FMT['SubArea'] != MinInt: print('SubArea: ', FMT['SubArea']) print('Reading Data') CTC = CukeTransectclass(self.ODB, i, self.TranClassChar, AlloSource, QueryFunc, MinDepth=self.LeastDepth, MaxDepth=self.MostDepth) print('NumTran: ', len(CTC.IndexTranUse)) self.OUTmdb.ADDTo_TranChar(FMT['Project'],FMT['Site'],FMT['Year'],FMT['StatArea'],FMT['SubArea'],FMT['NumTran'],\ CTC.GetSurveyedArea()) print('Writing results for individual transects') CTC.WriteTransectResults(self.OUTmdb, FMT) print('Writing estimated values') SiteEst += [ CTC.WriteSiteResults(self.OUTmdb, FMT, self.SourceMeanWeight) ] print('Calculating confidence bounds') SiteCB += [ CTC.WriteSiteCB(self.OUTmdb, FMT, nboot=self.nboot, CB=CB) ] self.OUTmdb.TranCharKey.Increment() print('\nCombined') if self.TranClassChar.nclass > 1: self.WriteOverall(SiteEst, SiteCB, CB) else: FMT = self.TranClassChar.FormatTranClass(0) dummy = CompositeAsTransectclass(CTC, SiteCB[0]['SampPopDensity']) dummy.WriteCB(self.OUTmdb, FMT, CB=CB) dummy.WriteResults(self.OUTmdb, FMT, self.SourceMeanWeight) print('\ndone MainWindow Line 147') return def WriteOverall(self, SiteEst, SiteCB, CB, nlevel=100): nsite = len(SiteCB) #Estimated Values EstPop = sum(list(map(lambda x: x['EstPop'], SiteEst))) EstBma = sum(list(map(lambda x: x['EstBma'], SiteEst))) CL = sum(list(map(lambda x: x['CL'], SiteEst))) PopDens = EstPop / CL BmaDens = EstBma / CL self.OUTmdb.ADDTo_Results_Overall(PopDens, EstPop, BmaDens, EstBma) #Confidence Bounds CBoverall = CalcOverallStats(SiteCB, newq=None, randomize=True, CB=CB, nlevel=nlevel) if nsite == 1: CBoverall['PopDensCB'] = Naive_CB(SiteEst[0]['PopDens'], CB=CB) CBoverall['BmaDens'] = Naive_CB(SiteEst[0]['BmaDens'], CB=CB) for i in range(len(CB)): self.OUTmdb.ADDTo_Results_OverallConfBounds(CB[i],\ CBoverall['PopDensCB'][i][0], CBoverall['PopDensCB'][i][1],\ CBoverall['TotaPopCB'][i][0], CBoverall['TotaPopCB'][i][1],\ CBoverall['BmaDensCB'][i][0], CBoverall['BmaDensCB'][i][1],\ CBoverall['TotaBmaCB'][i][0], CBoverall['TotaBmaCB'][i][1]) def GetSelectedTranChar(self): self.SelectedTranchar = [] for index in range(self.TransectCharacteristics.count()): if self.TransectCharacteristics.item(index).isSelected(): self.SelectedTranchar += [ self.TransectCharacteristics.item(index).text() ] def GetSelectedSurveys(self): self.SelectedSurveys = [] year = self.AS.GetYear() survey = self.AS.GetSurvey() for index in range(self.AvailSurveys.count()): if self.AvailSurveys.item(index).isSelected(): self.SelectedSurveys += [[survey[index], year[index]]] def DoAllSurveys(self): if self.AllSurveys.isChecked(): for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(True) else: for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(False) def QuitCalcs(self): print('\nBye Bye') os._exit(0) quit() sys.exit(app.exec_()) def DefaultSettings(self): self.NumberBootstrap.insertPlainText('10000') self.RandomSeed.insertPlainText('756') self.MinDepth.insertPlainText('-1000') self.MaxDepth.insertPlainText('1000') self.californicus.setChecked(True) self.MarketSample.setChecked(True) def PrepOUTmdb(self): '''Put information into output. Not the stats - just the metadata''' self.OUTmdb.ADDTo_Results_Header(self.Comments, self.species, str(self.nboot), str(self.seed), str(self.LeastDepth), str(self.MostDepth)) for ss in self.SelectedSurveys: self.OUTmdb.ADDTo_SurveyUsed(ss[0], str(ss[1])) def SelectedSurveystoDict(self): '''Convert self.SelectedSurveys as a list of dictionaries''' if isinstance(self.SelectedSurveys[0], dict): return (self.SelectedSurveys) result = [{ 'Project': t[0], 'Year': t[1] } for t in self.SelectedSurveys] return (result)
class Ui_Dialog(object): def __init__(self, Dialog, ODB, OUTmdb): self.setupUi(Dialog) self.inMDB = ODB self.resultODB = OUTmdb self.OUTmdb = self.resultODB.ODB self.ODB = self.inMDB.ODB #pdb.set_trace() self.FillSurveys() self.FillTranChar() self.MakeConnect() self.DefaultSettings() def setupUi(self, Dialog): Dialog.setObjectName(_fromUtf8("Dialog")) Dialog.resize(692, 769) font = QtGui.QFont() font.setPointSize(12) #pdb.set_trace() Dialog.setFont(font) self.AllSurveys = QtGui.QCheckBox(Dialog) self.AllSurveys.setGeometry(QtCore.QRect(30, 224, 141, 41)) self.AllSurveys.setStyleSheet( _fromUtf8("font: 12pt \"MS Shell Dlg 2\";")) self.AllSurveys.setObjectName(_fromUtf8("AllSurveys")) self.label = QtGui.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(30, 4, 241, 31)) self.label.setObjectName(_fromUtf8("label")) self.label_2 = QtGui.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(290, 4, 241, 31)) self.label_2.setObjectName(_fromUtf8("label_2")) self.CalculateAllometric = QtGui.QCheckBox(Dialog) self.CalculateAllometric.setGeometry(QtCore.QRect(320, 160, 241, 61)) self.CalculateAllometric.setStyleSheet( _fromUtf8("font: 12pt \"MS Shell Dlg 2\";")) self.CalculateAllometric.setObjectName( _fromUtf8("CalculateAllometric")) self.label_4 = QtGui.QLabel(Dialog) self.label_4.setGeometry(QtCore.QRect(320, 440, 321, 61)) self.label_4.setWordWrap(True) self.label_4.setObjectName(_fromUtf8("label_4")) self.intcpt = QtGui.QPlainTextEdit(Dialog) self.intcpt.setGeometry(QtCore.QRect(320, 230, 191, 31)) self.intcpt.setObjectName(_fromUtf8("intcpt")) self.intcptLabel = QtGui.QLabel(Dialog) self.intcptLabel.setGeometry(QtCore.QRect(520, 230, 131, 31)) self.intcptLabel.setObjectName(_fromUtf8("intcptLabel")) self.sdintcptLabel = QtGui.QLabel(Dialog) self.sdintcptLabel.setGeometry(QtCore.QRect(520, 270, 131, 31)) self.sdintcptLabel.setObjectName(_fromUtf8("sdintcptLabel")) self.sdintcpt = QtGui.QPlainTextEdit(Dialog) self.sdintcpt.setGeometry(QtCore.QRect(320, 270, 191, 31)) self.sdintcpt.setObjectName(_fromUtf8("sdintcpt")) self.sigmabetaLabel = QtGui.QLabel(Dialog) self.sigmabetaLabel.setGeometry(QtCore.QRect(520, 350, 131, 31)) self.sigmabetaLabel.setObjectName(_fromUtf8("sigmabetaLabel")) self.mubetaLabel = QtGui.QLabel(Dialog) self.mubetaLabel.setGeometry(QtCore.QRect(520, 310, 131, 31)) self.mubetaLabel.setObjectName(_fromUtf8("mubetaLabel")) self.sigmabeta = QtGui.QPlainTextEdit(Dialog) self.sigmabeta.setGeometry(QtCore.QRect(320, 350, 191, 31)) self.sigmabeta.setObjectName(_fromUtf8("sigmabeta")) self.mubeta = QtGui.QPlainTextEdit(Dialog) self.mubeta.setGeometry(QtCore.QRect(320, 310, 191, 31)) self.mubeta.setObjectName(_fromUtf8("mubeta")) self.sigmaepsilon = QtGui.QPlainTextEdit(Dialog) self.sigmaepsilon.setGeometry(QtCore.QRect(320, 390, 191, 31)) self.sigmaepsilon.setObjectName(_fromUtf8("sigmaepsilon")) self.sigmaepsilonLabel = QtGui.QLabel(Dialog) self.sigmaepsilonLabel.setGeometry(QtCore.QRect(520, 390, 131, 31)) self.sigmaepsilonLabel.setObjectName(_fromUtf8("sigmaepsilonLabel")) self.groupBox_2 = QtGui.QGroupBox(Dialog) self.groupBox_2.setGeometry(QtCore.QRect(20, 284, 131, 201)) font = QtGui.QFont() font.setPointSize(8) self.groupBox_2.setFont(font) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.NumberBootstrapLabel = QtGui.QLabel(Dialog) self.NumberBootstrapLabel.setGeometry(QtCore.QRect(130, 560, 131, 41)) self.NumberBootstrapLabel.setWordWrap(True) self.NumberBootstrapLabel.setObjectName( _fromUtf8("NumberBootstrapLabel")) self.NumberBootstrap = QtGui.QPlainTextEdit(Dialog) self.NumberBootstrap.setGeometry(QtCore.QRect(20, 560, 101, 31)) self.NumberBootstrap.setObjectName(_fromUtf8("NumberBootstrap")) self.RandomSeed = QtGui.QPlainTextEdit(Dialog) self.RandomSeed.setGeometry(QtCore.QRect(310, 560, 101, 31)) self.RandomSeed.setObjectName(_fromUtf8("RandomSeed")) self.RandomSeedLabel = QtGui.QLabel(Dialog) self.RandomSeedLabel.setGeometry(QtCore.QRect(420, 560, 131, 31)) self.RandomSeedLabel.setObjectName(_fromUtf8("RandomSeedLabel")) self.USB39 = QtGui.QRadioButton(Dialog) self.USB39.setGeometry(QtCore.QRect(51, 431, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB39.setFont(font) self.USB39.setAutoExclusive(False) self.USB39.setObjectName(_fromUtf8("USB39")) self.USB24 = QtGui.QRadioButton(Dialog) self.USB24.setGeometry(QtCore.QRect(51, 460, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB24.setFont(font) self.USB24.setAutoExclusive(False) self.USB24.setObjectName(_fromUtf8("USB24")) self.USB54 = QtGui.QRadioButton(Dialog) self.USB54.setGeometry(QtCore.QRect(51, 402, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB54.setFont(font) self.USB54.setAutoExclusive(False) self.USB54.setObjectName(_fromUtf8("USB54")) self.USB1000 = QtGui.QRadioButton(Dialog) self.USB1000.setGeometry(QtCore.QRect(51, 315, 59, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB1000.setFont(font) self.USB1000.setAutoExclusive(False) self.USB1000.setObjectName(_fromUtf8("USB1000")) self.USB84 = QtGui.QRadioButton(Dialog) self.USB84.setGeometry(QtCore.QRect(51, 344, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB84.setFont(font) self.USB84.setAutoExclusive(False) self.USB84.setObjectName(_fromUtf8("USB84")) self.USB69 = QtGui.QRadioButton(Dialog) self.USB69.setGeometry(QtCore.QRect(51, 373, 41, 23)) font = QtGui.QFont() font.setPointSize(12) self.USB69.setFont(font) self.USB69.setAutoExclusive(False) self.USB69.setObjectName(_fromUtf8("USB69")) self.AvailSurveys = QtGui.QListWidget(Dialog) self.AvailSurveys.setGeometry(QtCore.QRect(21, 35, 256, 192)) self.AvailSurveys.setObjectName(_fromUtf8("AvailSurveys")) self.TransectCharacteristics = QtGui.QListWidget(Dialog) self.TransectCharacteristics.setGeometry( QtCore.QRect(320, 35, 256, 101)) self.TransectCharacteristics.setObjectName( _fromUtf8("TransectCharacteristics")) self.DoCalcs = QtGui.QPushButton(Dialog) self.DoCalcs.setGeometry(QtCore.QRect(190, 610, 91, 41)) self.DoCalcs.setObjectName(_fromUtf8("DoCalcs")) self.QuitBttn = QtGui.QPushButton(Dialog) self.QuitBttn.setGeometry(QtCore.QRect(320, 610, 91, 41)) self.QuitBttn.setObjectName(_fromUtf8("QuitBttn")) self.MinDepthLabel = QtGui.QLabel(Dialog) self.MinDepthLabel.setGeometry(QtCore.QRect(130, 510, 131, 31)) self.MinDepthLabel.setWordWrap(True) self.MinDepthLabel.setObjectName(_fromUtf8("MinDepthLabel")) self.MinDepth = QtGui.QPlainTextEdit(Dialog) self.MinDepth.setGeometry(QtCore.QRect(20, 510, 101, 31)) self.MinDepth.setObjectName(_fromUtf8("MinDepth")) self.MaxDepth = QtGui.QPlainTextEdit(Dialog) self.MaxDepth.setGeometry(QtCore.QRect(310, 510, 101, 31)) self.MaxDepth.setObjectName(_fromUtf8("MaxDepth")) self.MaxDepthLabel = QtGui.QLabel(Dialog) self.MaxDepthLabel.setGeometry(QtCore.QRect(420, 510, 131, 31)) self.MaxDepthLabel.setWordWrap(True) self.MaxDepthLabel.setObjectName(_fromUtf8("MaxDepthLabel")) self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog) def retranslateUi(self, Dialog): Dialog.setWindowTitle( _translate("Dialog", "Green Sea Urchin Analysis Program", None)) self.AllSurveys.setText(_translate("Dialog", "Do All Surveys?", None)) self.label.setText( _translate( "Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt;\">Survey</span></p></body></html>", None)) self.label_2.setText( _translate( "Dialog", "<html><head/><body><p align=\"center\"><span style=\" font-size:12pt;\">Transect Characteristics</span></p></body></html>", None)) self.CalculateAllometric.setText( _translate( "Dialog", "Attempt to Estimate\n" "Allometric Relationship\n" "from Data?", None)) self.label_4.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:8pt;\">W=exp(alpha+beta*log(L)+epsilon)</span></p><p><span style=\" font-size:8pt;\">log(alpha)~N(mu</span><span style=\" font-size:8pt; vertical-align:sub;\">alpha</span><span style=\" font-size:8pt;\">,sigma</span><span style=\" font-size:8pt; vertical-align:sub;\">alpha</span><span style=\" font-size:8pt; vertical-align:super;\">2</span><span style=\" font-size:8pt;\">) beta~N(mu</span><span style=\" font-size:8pt; vertical-align:sub;\">beta</span><span style=\" font-size:8pt;\">,sigma</span><span style=\" font-size:8pt; vertical-align:sub;\">beta</span><span style=\" font-size:8pt; vertical-align:super;\">2</span><span style=\" font-size:8pt;\">) epsilon~N(0,sigma</span><span style=\" font-size:8pt; vertical-align:sub;\">epsilon</span><span style=\" font-size:8pt; vertical-align:super;\">2</span><span style=\" font-size:8pt;\">)</span></p></body></html>", None)) self.intcptLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:12pt;\">mu</span><span style=\" font-size:12pt; vertical-align:sub;\">alpha</span></p></body></html>", None)) self.sdintcptLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:12pt;\">sigma</span><span style=\" font-size:12pt; vertical-align:sub;\">alpha</span></p></body></html>", None)) self.sigmabetaLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:12pt;\">sigma</span><span style=\" font-size:12pt; vertical-align:sub;\">beta</span></p></body></html>", None)) self.mubetaLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:12pt;\">mu</span><span style=\" font-size:12pt; vertical-align:sub;\">beta</span></p></body></html>", None)) self.sigmaepsilonLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:12pt;\">sigma</span><span style=\" font-size:12pt; vertical-align:sub;\">epsilon</span></p></body></html>", None)) self.groupBox_2.setTitle( _translate("Dialog", "Upper Size Bounds (mm)", None)) self.NumberBootstrapLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Number of Bootstrap Repititions</span></p></body></html>", None)) self.RandomSeedLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Random Seed</span></p></body></html>", None)) self.USB39.setToolTip( _translate( "Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB39.setText(_translate("Dialog", "39", None)) self.USB24.setToolTip( _translate( "Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB24.setText(_translate("Dialog", "24", None)) self.USB54.setToolTip( _translate( "Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB54.setText(_translate("Dialog", "54", None)) self.USB1000.setToolTip( _translate( "Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB1000.setText(_translate("Dialog", "1000", None)) self.USB84.setToolTip( _translate( "Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB84.setText(_translate("Dialog", "84", None)) self.USB69.setToolTip( _translate( "Dialog", "<html><head/><body><p align=\"right\"><span style=\" font-size:12pt;\"><br/></span></p></body></html>", None)) self.USB69.setText(_translate("Dialog", "69", None)) self.DoCalcs.setText(_translate("Dialog", "Do\n" "Calculations", None)) self.QuitBttn.setText(_translate("Dialog", "Quit", None)) self.MinDepthLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Minimum Depth (m)</span></p></body></html>", None)) self.MaxDepthLabel.setText( _translate( "Dialog", "<html><head/><body><p><span style=\" font-size:10pt;\">Maximum Depth (m)</span></p></body></html>", None)) def FillSurveys(self): self.AS = AllSurveys(self.ODB) FullName = self.AS.GetCombo() for fn in FullName: item = QListWidgetItem(fn) self.AvailSurveys.addItem(item) self.AvailSurveys.setSelectionMode( QtGui.QAbstractItemView.MultiSelection) def FillTranChar(self): for fieldname in [ 'SurveyTitle', 'SubSampleLocation', 'Year', 'StatArea', 'SubArea' ]: item = QListWidgetItem(fieldname) self.TransectCharacteristics.addItem(item) #pdb.set_trace() self.TransectCharacteristics.setSelectionMode( QtGui.QAbstractItemView.MultiSelection) def MakeConnect(self): #pdb.set_trace() self.DoCalcs.clicked.connect(self.Calculations) self.QuitBttn.clicked.connect(self.QuitCalcs) self.AllSurveys.stateChanged.connect(self.DoAllSurveys) self.TransectCharacteristics.itemSelectionChanged.connect( self.CoordStatAreaSubArea) def Calculations(self): print('\nCalculations Started') seed(int(self.RandomSeed.document().toPlainText())) self.GetSelectedSurveys() self.GetSelectedTranChar() self.GetSelectedUppSizeBound() self.CalcAllometric = self.CalculateAllometric.isChecked() self.GetAlloParam() self.TranClassChar=MetaTransectClass(self.ODB,\ self.SelectedSurveys,\ self.SelectedTranchar,\ CalcAllo=self.CalcAllometric, DefaultAllo=AlloEqn(intcpt=self.AlloParam['intcpt'],\ sdintcpt=self.AlloParam['sdintcpt'],\ mnbeta=self.AlloParam['mubeta'],\ sdbeta=self.AlloParam['sigmabeta'],\ sigmawithin=self.AlloParam['sigmaepsilon'])) self.PrepOUTmdb() dictSelectedSurveys = self.SelectedSurveystoDict() CopyMDB(self.ODB, self.OUTmdb, dictSelectedSurveys) CB = [99, 95, 90, 75, 50] nboot = int(self.NumberBootstrap.document().toPlainText()) for i in range(self.TranClassChar.nclass): FTC = self.TranClassChar.FormatTranClass(i) if self.TranClassChar.TranClass != [[]]: print('\nSurveyTitle: ', FTC['SurveyTitle']) print('SubSampleLocation: ', FTC['SubSampleLocation']) if FTC['Year'] != MinInt: print('Year: ', FTC['Year']) if FTC['StatArea'] != MinInt: print('StatArea: ', FTC['StatArea']) if FTC['SubArea'] != MinInt: print('SubArea: ', FTC['SubArea']) print(len(self.TranClassChar.key[i]), ' transects') tc=transectclass(self.ODB,self.TranClassChar.key[i],self.TranClassChar.Allo[i],QueryFunc,\ SizeBound=self.UppSizeBnd,\ MinDepth=float(self.MinDepth.document().toPlainText()),\ MaxDepth=float(self.MaxDepth.document().toPlainText())) CurDeterm = tc.GetFormatEstVal() CurCB = tc.GetPctCB(CB, nboot=nboot) #Transect Classes self.OUTmdb.ADDTo_TranChar(FTC['SurveyTitle'],FTC['SubSampleLocation'],FTC['Year'],FTC['StatArea'],FTC['SubArea'],FTC['InBed'],FTC['NumTran'],\ tc.GetSurveyedArea(),\ tc.GetNumSurveyedQuadInDepthRange(), tc.AlloSource.intcpt,tc.AlloSource.sdintcpt,\ tc.AlloSource.mnbeta,tc.AlloSource.sdbeta, tc.AlloSource.sigmawithin) tck = self.OUTmdb.GetTranCharKey(FTC['SurveyTitle'], FTC['SubSampleLocation'], FTC['Year'], FTC['StatArea'], FTC['SubArea'], FTC['InBed']) tc.WriteTransectResults(self.OUTmdb, tck) #The confidence bounds for cbResult in CurCB: CBval = cbResult['CB'] SN = list(filter(lambda x: x != 'CB', cbResult.keys())) for sn in SN: CurSize = cbResult[sn] SK = self.OUTmdb.GetSizeRangeKey(CurSize['SizeLimit'][-1]) self.OUTmdb.ADDTo_ConfInterval(\ tck,SK,\ CBval,\ CurSize['linear']['Pop'][0], CurSize['linear']['Pop'][1], \ CurSize['spatial']['Pop'][0], CurSize['spatial']['Pop'][1], \ CurSize['linear']['Bmass'][0], CurSize['linear']['Bmass'][1], \ CurSize['spatial']['Bmass'][0], CurSize['spatial']['Bmass'][1]) #The estimated values for sn in CurDeterm.keys(): CurSize = CurDeterm[sn] SK = self.OUTmdb.GetSizeRangeKey(CurSize['SizeLimit'][-1]) self.OUTmdb.ADDTo_EstDens(\ CurSize['linear']['Pop'],CurSize['spatial']['Pop'],\ CurSize['linear']['Bmass'],CurSize['spatial']['Bmass'],\ TranCharKey=tck,SizeKey=SK) print('\ndone MainWindow Line 274') def GetAlloParam(self): #pdb.set_trace() self.AlloParam = {} try: self.AlloParam['intcpt'] = float( self.intcpt.document().toPlainText()) except: print('MainWindow 267,type(self.intcpt.document().toPlainText() )', type(self.intcpt.document().toPlainText()), self.intcpt.document().toPlainText()) self.AlloParam['intcpt'] = None try: self.AlloParam['sdintcpt'] = float( self.sdintcpt.document().toPlainText()) except: self.AlloParam['sdintcpt'] = None try: self.AlloParam['mubeta'] = float( self.mubeta.document().toPlainText()) except: self.AlloParam['mubeta'] = None try: self.AlloParam['sigmabeta'] = float( self.sigmabeta.document().toPlainText()) except: self.AlloParam['sigmabeta'] = None try: self.AlloParam['sigmaepsilon'] = float( self.sigmaepsilon.document().toPlainText()) except: self.AlloParam['sigmaepsilon'] = None def GetSelectedUppSizeBound(self): self.UppSizeBnd = [] if self.USB24.isChecked(): self.UppSizeBnd += [24] if self.USB39.isChecked(): self.UppSizeBnd += [39] if self.USB54.isChecked(): self.UppSizeBnd += [54] if self.USB69.isChecked(): self.UppSizeBnd += [69] if self.USB84.isChecked(): self.UppSizeBnd += [84] self.UppSizeBnd += [inf] def GetSelectedTranChar(self): self.SelectedTranchar = [] for index in range(self.TransectCharacteristics.count()): if self.TransectCharacteristics.item(index).isSelected(): self.SelectedTranchar += [ self.TransectCharacteristics.item(index).text() ] def GetSelectedSurveys(self): self.SelectedSurveys = [] year = self.AS.GetYear() survey = self.AS.GetSurvey() for index in range(self.AvailSurveys.count()): if self.AvailSurveys.item(index).isSelected(): self.SelectedSurveys += [[survey[index], year[index]]] def DoAllSurveys(self): if self.AllSurveys.isChecked(): for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(True) else: for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(False) def CoordStatAreaSubArea(self): '''Make sure statarea and subarea are coherent''' #Update list of selected transect-characteristics self.GetSelectedTranChar() #if subarea is selected, force statarea to be selected if ('SubArea' in self.SelectedTranchar ) and not ('StatArea' in self.SelectedTranchar): for index in range(self.TransectCharacteristics.count()): if self.TransectCharacteristics.item( index).text() == 'StatArea': self.TransectCharacteristics.item(index).setSelected(True) self.GetSelectedTranChar() def QuitCalcs(self): print('No Calculations') sys.exit(app.exec_()) def DefaultSettings(self): self.intcpt.insertPlainText('-6.8664802585167077') self.sdintcpt.insertPlainText('0.034723646241811214') self.mubeta.insertPlainText('2.7276732805478963') self.sigmabeta.insertPlainText('0.0088232364135380891') self.sigmaepsilon.insertPlainText('0.15967472910118682') self.NumberBootstrap.insertPlainText('10000') self.RandomSeed.insertPlainText('756') self.MinDepth.insertPlainText('-1000') self.MaxDepth.insertPlainText('1000') self.CalculateAllometric.setChecked(True) self.USB1000.setDisabled(True) self.USB1000.setChecked(True) self.USB54.setChecked(True) self.USB24.autoExclusive = False def PrepOUTmdb(self): '''Put information into output. Not the stats - just the metadata''' self.OUTmdb.ADDTo_Analysis(int(self.NumberBootstrap.document().toPlainText()),\ int(self.RandomSeed.document().toPlainText()),\ float(self.MinDepth.document().toPlainText()),\ float(self.MaxDepth.document().toPlainText())) self.OUTmdb.ADDTo_SizeRange(0, self.UppSizeBnd[0]) for x in range(1, len(self.UppSizeBnd)): self.OUTmdb.SizeRangeKey.Increment() self.OUTmdb.ADDTo_SizeRange(1 + self.UppSizeBnd[x - 1], self.UppSizeBnd[x]) for sy in self.SelectedSurveys: self.OUTmdb.ADDTo_SurveyUsed(sy[0], sy[1]) def SelectedSurveystoDict(self): '''Convert self.SelectedSurveys as a list of dictionaries''' if isinstance(self.SelectedSurveys[0], dict): return (self.SelectedSurveys) result = [{ 'SurveyTitle': t[0], 'Year': t[1] } for t in self.SelectedSurveys] return (result)
class GeoduckMain(QMainWindow, GeoduckDialog): def __init__(self, ODB, OUTmdb, parent=None): self.inMDB = ODB self.resultODB = OUTmdb QMainWindow.__init__(self, parent) self.setupUi(self) self.MakeConnect() self.OUTmdb = self.resultODB.ODB self.ODB = self.inMDB.ODB self.FillSurveys() self.DefaultSettings() self.setFocus() def MakeConnect(self): self.DoCalcs.clicked.connect(self.Calculations) self.QuitBttn.clicked.connect(self.QuitCalcs) self.AllSurveys.stateChanged.connect(self.DoAllSurveys) def FillSurveys(self): self.AS = AllSurveys(self.ODB) FullName = self.AS.GetCombo() for fn in FullName: item = QListWidgetItem(fn) self.AvailSurveys.addItem(item) self.AvailSurveys.setSelectionMode(QAbstractItemView.MultiSelection) def DefaultSettings(self): self.NumberBootstrap.insertPlainText('10000') self.RandomSeed.insertPlainText('756') self.MinDepth.insertPlainText('3') self.MaxDepth.insertPlainText('1000') def Calculations(self): #Do nothing unless some surveys are selected if self.AvailSurveys.count() == 0: return try: self.GetSelectedSurveys() except: self.QuitCalcs() print('\nCalculations Started') self.TranClassChar=MetaTransectClass(self.ODB,\ self.SelectedSurveys) CB = [99, 95, 90, 75, 50] self.Comments = self.RunComments.document().toPlainText() self.nboot = int(self.NumberBootstrap.document().toPlainText()) self.seed = int(self.RandomSeed.document().toPlainText()) self.LeastDepth = float(self.MinDepth.document().toPlainText()) self.MostDepth = float(self.MaxDepth.document().toPlainText()) AlloSource = QueryFunc.AlloEqn() SiteSamp = [] SiteEst = [] SampSite = [] TranClass = [] #Beginning of run 2 ### #Results based on LOBF as a basis for esitmating site-area print('\nResults based on Line Of Best Fit') self.OUTmdb.AnalysisKey.Increment() SiteSamp2 = [] for i in range(self.TranClassChar.nclass): print("\nSurvey: ", self.TranClassChar.GetChar(i, 'SurveyTitle')) print("Year: ", self.TranClassChar.GetChar(i, 'Year')) print("Site:", self.TranClassChar.GetChar(i, 'SurveySite')) #Random seeds will be manually gernerated for each sample of transects curseed = self.seed + i * self.nboot print('Reading Data') CTC=GDuckTransectclass(self.ODB,i,self.TranClassChar,AlloSource,QueryFunc,\ MinDepth=self.LeastDepth,MaxDepth=self.MostDepth,\ OnlyOnBed=False,curseed=curseed) TranClass += [CTC] SiteEst += [{ 'ntransect': CTC.ntransect, 'MeanWeight': CTC.MeanWeight, 'SiteSize': CTC.SiteSize }] SiteEst[i]['Area'] = SiteEst[i]['SiteSize'].GetEstArea( Digitized=False) SiteEst[i]['PopDens'] = CTC.GetAvgAbundance() SiteEst[i]['Pop'] = SiteEst[i]['Area'] * SiteEst[i]['PopDens'] SiteEst[i]['BiomassDens'] = CTC.GetAvgAbundance( ) * CTC.MeanWeight.EstMeanWeight SiteEst[i][ 'Biomass'] = SiteEst[i]['Area'] * SiteEst[i]['BiomassDens'] print("Number of Transects: ", CTC.ntransect) print('Writing results for individual transects') SiteSize = CTC.SiteSize MeanWeight = CTC.MeanWeight CTC.WriteTransectResults(self.OUTmdb, RemoveOffBed=False) SiteSize = CTC.SiteSize MeanWeight = CTC.MeanWeight self.OUTmdb.ADDTo_Results_Site( CTC.site, SiteSize.LOBF, SiteSize.GetMeanTranLen().mu, SiteSize.GetEstArea(Digitized=False), SiteSize.GetSEEstArea(Digitized=False), MeanWeight.EstMeanWeight / 1000, MeanWeight.MeanWeightSE / 1000, MeanWeight.MeanWeightSource, CTC.ntransect, CTC.GetAvgAbundance(), CTC.GetAvgAbundance() * SiteSize.LOBFarea.mu, CTC.GetAvgAbundance() * CTC.MeanWeight.EstMeanWeight, CTC.GetAvgAbundance() * CTC.MeanWeight.EstMeanWeight * SiteSize.LOBFarea.mu, self.TranClassChar.AnalyzeSite[i]) print('Calculating Confidence Bounds') Area = CTC.SiteSize.GetRandomArea(n=self.nboot, RunNumber=2) SiteSamp2+=[CTC. WriteSiteCB(self.OUTmdb,nboot=self.nboot,\ CB=CB,RunNumber=2) ] print('\nCombined') #Reduce datasets to sites that should be combined into overall results SiteEst, SiteSamp2 = SelectGood(self.TranClassChar.AnalyzeSite, SiteEst), SelectGood( self.TranClassChar.AnalyzeSite, SiteSamp2) self.WriteOverall(SiteEst, SiteSamp2, CB) SurveyArea = sum(list(map(lambda x: x['Area'], SiteEst))) ntransect = sum(list(map(lambda x: x['ntransect'], SiteEst))) self.OUTmdb.ADDTo_Results_Header(self.TranClassChar,2,self.Comments,SurveyArea,\ ntransect,self.nboot,self.seed, self.LeastDepth,self.MostDepth ) #End of run 2 ################ #Beginning of run number 4 ################# dummy = self.OUTmdb.AnalysisKey.GetValue( IncrementFirst=True) #increment key for sets of analyses SiteEst = [] for i in range(self.TranClassChar.nclass): print('\n') print("Survey: ", self.TranClassChar.GetChar(i, 'SurveyTitle')) print("Year: ", self.TranClassChar.GetChar(i, 'Year')) print("Site:", self.TranClassChar.GetChar(i, 'SurveySite')) print('Reading Data') CTC = TranClass[i] CTC.ReduceToOnBed() #CTC.SiteSize is corrected here print("Number of Transects: ", CTC.ntransect) print('Writing results for individual transects') CTC.WriteTransectResults(self.OUTmdb, RemoveOffBed=False) print('Number of transects onbed: ', CTC.ntransect) SiteSize = CTC.SiteSize MeanWeight = CTC.MeanWeight #Use Digitized Area print('Writing estimated values - digitized area') #Later change could use the expectation value for Area. #Area=SiteSize.DigitizedArea.mu Area = SiteSize.GetEstArea(Digitized=True) PopDens = CTC.GetAvgAbundance() Pop = PopDens * Area BmaDens = PopDens * CTC.MeanWeight.EstMeanWeight Bma = Pop * CTC.MeanWeight.EstMeanWeight if CTC.ntransect <= 0: PopDens = MinInt Pop = MinInt BmaDens = MinInt * 1000 Bma = MinInt * 1000000 ###Area=SiteSize.GetDigitizedArea().mu if Area < 0: Pop = MinInt Bma = MinInt * 1000000 self.OUTmdb.ADDTo_Results_Site( CTC.site, 0, # LOBF is irrelevent for run#4 SiteSize.GetMeanTranLen().mu, Area, SiteSize.GetSEEstArea(Digitized=True), MeanWeight.EstMeanWeight / 1000, MeanWeight.MeanWeightSE / 1000, MeanWeight.MeanWeightSource, CTC.ntransect, PopDens, Pop, BmaDens, Bma, self.TranClassChar.AnalyzeSite[i]) SiteEst+=[{'PopDens':PopDens,\ 'Pop':Pop,\ 'BiomassDens':BmaDens, 'Biomass':Bma, 'Area':Area,\ 'ntransect':CTC.ntransect,'MeanWeight':CTC.MeanWeight,'SiteSize':CTC.SiteSize}] print('Calculating Confidence Bounds') SiteSamp += [ CTC.WriteSiteCB(self.OUTmdb, nboot=self.nboot, CB=CB, RunNumber=4, Area=None) ] print('\nCombined') #Reduce datasets to sites that should be combined into overall results SiteEst, SiteSamp2 = SelectGood(self.TranClassChar.AnalyzeSite, SiteEst), SelectGood( self.TranClassChar.AnalyzeSite, SiteSamp2) self.WriteOverall(SiteEst, SiteSamp, CB) SurveyArea = sum(list(map(lambda x: x['Area'], SiteEst))) ntransect = sum(list(map(lambda x: x['ntransect'], SiteEst))) self.OUTmdb.ADDTo_Results_Header(self.TranClassChar,4,self.Comments,SurveyArea,\ ntransect,self.nboot,self.seed, self.LeastDepth,self.MostDepth ) #End of run 4 ############### dictSelectedSurveys = self.SelectedSurveystoDict() CopyMDB(self.ODB, self.OUTmdb, dictSelectedSurveys) print('\nResults are in ', self.OUTmdb.OUTmdbName) return def WriteOverall(self, SiteEst, SiteSamp, CB): nsite = len(SiteSamp) #Deterministic Estimates MinArea = min(list(map(lambda x: ValorMax(x['Area']), SiteEst))) if MinArea < 0: #There is an undefined area EstPop = MinInt EstBma = MinInt * 1000000 Area = MinInt PopDens = MinInt BmaDens = MinInt * 1000 else: EstPop = sum(list(map(lambda x: x['Pop'], SiteEst))) EstBma = sum(list(map(lambda x: x['Biomass'], SiteEst))) Area = sum(list(map(lambda x: x['Area'], SiteEst))) PopDens = EstPop / Area BmaDens = EstBma / Area self.OUTmdb.ADDTo_Results_Overall(PopDens, EstPop, BmaDens, EstBma) #Confidence Bounds CBoverall = CombineSites(SiteSamp, CB) for i in range(len(CB)): self.OUTmdb.ADDTo_Results_OverallConfBounds(CB[i],\ CBoverall['PopDens'][i][1], CBoverall['PopDens'][i][2],\ CBoverall['SitePop'][i][1], CBoverall['SitePop'][i][2],\ CBoverall['BioDens'][i][1], CBoverall['BioDens'][i][2],\ CBoverall['SiteBioM'][i][1], CBoverall['SiteBioM'][i][2]) def GetSelectedSurveys(self): self.SelectedSurveys = [] year = self.AS.GetYear() survey = self.AS.GetSurvey() for index in range(self.AvailSurveys.count()): if self.AvailSurveys.item(index).isSelected(): self.SelectedSurveys += [[survey[index], year[index]]] def DoAllSurveys(self): if self.AllSurveys.isChecked(): for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(True) else: for index in range(self.AvailSurveys.count()): self.AvailSurveys.item(index).setSelected(False) def QuitCalcs(self): print('\nBye Bye') os._exit(0) quit() sys.exit(app.exec_()) def PrepOUTmdb(self): '''Put information into output. Not the stats - just the metadata''' RunNumber = -1 for ss in self.SelectedSurveys: self.OUTmdb.ADDTo_SurveyUsed(ss[0], str(ss[1])) def SelectedSurveystoDict(self): '''Convert self.SelectedSurveys as a list of dictionaries''' if isinstance(self.SelectedSurveys[0], dict): return (self.SelectedSurveys) result = [{ 'SurveyTitle': t[0], 'Year': t[1] } for t in self.SelectedSurveys] return (result)