def OnAddRangeSelection(self, event): """ Select dissimilarity matrix cells meeting specified user criteria. """ if str(self.lblMatrixFilename.GetLabelText()) == '<No file loaded>': wx.MessageBox("Please load dissimilarity matrix.", "Dissimilarity matrix not found") return # get user criteria if isNumber(self.txtLessThanValue.GetValue()): lessThanValue = float(self.txtLessThanValue.GetValue()) else: wx.MessageBox("Selection criteria must be numeric.", "Invalid selection criteria") return if isNumber(self.txtGreaterThanValue.GetValue()): greaterThanValue = float(self.txtGreaterThanValue.GetValue()) else: wx.MessageBox("Selection criteria must be numeric.", "Invalid selection criteria") return bSelectUpper = self.chkSelectFromUpperTriangleByRange.IsChecked() bSelectLower = self.chkSelectFromLowerTriangleByRange.IsChecked() # select cells meeting user criteria for i in xrange(0, len(self.index)): for j in xrange(i+1, len(self.index)): if bSelectUpper and self.matrix[i][j] <= lessThanValue and self.matrix[i][j] >= greaterThanValue: self.dissMatrix.SelectBlock(i, j+1, i, j+1, True) if bSelectLower and self.matrix[j][i] <= lessThanValue and self.matrix[j][i] >= greaterThanValue: self.dissMatrix.SelectBlock(j, i+1, j, i+1, True)
def __init__(self, parent=None): DerivedDataCalculatorLayout.__init__ ( self, parent ) self.SetIcon(wx.Icon(GenGIS.mainWindow.GetExeDir() + "images/CrazyEye.ico", wx.BITMAP_TYPE_ICO)) # check required data has been loaded if GenGIS.layerTree.GetNumMapLayers() == 0 or GenGIS.layerTree.GetNumLocationSetLayers() == 0 or GenGIS.layerTree.GetNumSequenceLayers() == 0: wx.MessageBox("This plugin requires map, location, and sequence data to be loaded.", "Additional data required.") self.Close() return # populate unique sequence id combobox for field in GenGIS.layerTree.GetSequenceLayer(0).GetController().GetMetadataFields(): self.cboUniqueSeqIdField.Append(field) self.cboUniqueSeqIdField.SetSelection(0) # populate sequence count comboxbox with 'likely' numeric fields for field in GenGIS.layerTree.GetSequenceLayer(0).GetController().GetMetadataFields(): # check if field is numeric for first sequence value = GenGIS.layerTree.GetSequenceLayer(0).GetController().GetData()[field] if isNumber(value): self.cboSeqCountField.Append(field) if self.cboSeqCountField.GetCount() >= 1: self.cboSeqCountField.SetSelection(0) else: self.cboSeqCountField.Append('<No numeric data>') self.cboSeqCountField.SetStringSelection('<No numeric data>') self.btnUniqueSeqs.Disable() self.btnTotalSeqs.Disable() self.btnNormalizeUniqueSeqs.Disable() # resize frame to fit widgets self.Fit()
def SortFields(self, layers, field): values = [] self.locData = {} for layer in layers: if not layer.GetController().IsActive(): continue data = layer.GetController().GetData()[field] if self.isSequence: id = layer.GetController().GetSiteId() else: id = layer.GetController().GetId() layerNum = self.locationMap[id] if layerNum in self.locData.keys(): self.locData[layerNum].append(data) else: self.locData[layerNum] = [data] values.append(data) # a flag for whether or not sorting should be descending or ascending if self.sort: ascend = True else: ascend = False # Since the fields are unicode values, this sorts them numericaly if applicable, or alphabetically if re.search(r"(\d+/\d+/\d+)", data): values = self.SortDates(values, ascend) elif dh.isNumber(data): values = sorted(set(values), key=lambda val: float(val), reverse=ascend) else: values = sorted(set(values), reverse=ascend) return values
def SortFields( self, layers, field): values = [] self.locData = {} for layer in layers: if not layer.GetController().IsActive(): continue data = layer.GetController().GetData()[field] if self.isSequence: id = layer.GetController().GetSiteId() else: id = layer.GetController().GetId() layerNum = self.locationMap[id] if layerNum in self.locData.keys(): self.locData[layerNum].append(data) else: self.locData[layerNum] = [data] values.append(data) # a flag for whether or not sorting should be descending or ascending if self.sort: ascend = True else: ascend = False # Since the fields are unicode values, this sorts them numericaly if applicable, or alphabetically if re.search(r'(\d+/\d+/\d+)',data): values = self.SortDates( values , ascend) elif( dh.isNumber(data) ): values = sorted( set(values), key = lambda val: float(val), reverse= ascend ) else: values = sorted( set(values), reverse = ascend ) return values
def __init__(self, parent=None): BetaDiversityLayout.__init__(self, parent) self.SetIcon( wx.Icon(GenGIS.mainWindow.GetExeDir() + "images/CrazyEye.ico", wx.BITMAP_TYPE_ICO)) self.graphicalElementIds = [] # check required data has been loaded if GenGIS.layerTree.GetNumMapLayers( ) == 0 or GenGIS.layerTree.GetNumLocationSetLayers( ) == 0 or GenGIS.layerTree.GetNumSequenceLayers() == 0: wx.MessageBox( "This plugin requires map, location, and sequence data to be loaded.", "Additional data required.") self.Close() return # set measure combobox self.betaDiversityMeasures = BetaDiversityMeasures() for measure in self.betaDiversityMeasures.measures: self.cboMeasure.Append(measure) self.cboMeasure.SetSelection(0) # set category field combobox seqLayerController = GenGIS.layerTree.GetSequenceLayer( 0).GetController() fields = seqLayerController.GetData().keys() for field in fields: if field.lower() != 'siteid' and field.lower() != 'site id': self.cboCategoryField.Append(field) self.cboCategoryField.SetSelection(0) # set count field combobox numericFields = ['<none>'] for field in sorted(fields): bNumeric = True for i in xrange(0, GenGIS.layerTree.GetNumSequenceLayers()): if isNumber( GenGIS.layerTree.GetSequenceLayer( i).GetController().GetData()[field]) == False: bNumeric = False break if bNumeric: numericFields.append(field) for field in numericFields: self.cboCountField.Append(field) self.cboCountField.SetSelection(0) self.UpdateInfo() self.results = None self.newickStr = None
def __init__(self, parent=None): BetaDiversityLayout.__init__(self, parent) self.SetIcon(wx.Icon(GenGIS.mainWindow.GetExeDir() + "images/CrazyEye.ico", wx.BITMAP_TYPE_ICO)) self.graphicalElementIds = [] # check required data has been loaded if ( GenGIS.layerTree.GetNumMapLayers() == 0 or GenGIS.layerTree.GetNumLocationSetLayers() == 0 or GenGIS.layerTree.GetNumSequenceLayers() == 0 ): wx.MessageBox( "This plugin requires map, location, and sequence data to be loaded.", "Additional data required." ) self.Close() return # set measure combobox self.betaDiversityMeasures = BetaDiversityMeasures() for measure in self.betaDiversityMeasures.measures: self.cboMeasure.Append(measure) self.cboMeasure.SetSelection(0) # set category field combobox seqLayerController = GenGIS.layerTree.GetSequenceLayer(0).GetController() fields = seqLayerController.GetData().keys() for field in fields: if field.lower() != "siteid" and field.lower() != "site id": self.cboCategoryField.Append(field) self.cboCategoryField.SetSelection(0) # set count field combobox numericFields = ["<none>"] for field in sorted(fields): bNumeric = True for i in xrange(0, GenGIS.layerTree.GetNumSequenceLayers()): if isNumber(GenGIS.layerTree.GetSequenceLayer(i).GetController().GetData()[field]) == False: bNumeric = False break if bNumeric: numericFields.append(field) for field in numericFields: self.cboCountField.Append(field) self.cboCountField.SetSelection(0) self.UpdateInfo() self.results = None self.newickStr = None
def OnDataChange( self, event ): # isSequence self.m_StartChoice.Clear() self.m_StopChoice.Clear() field = self.m_DataChoice.GetStringSelection() #if there are sequence layers if GenGIS.layerTree.GetNumSequenceLayers() > 0: #if field is in sequences or locations if field in GenGIS.layerTree.GetSequenceLayer(0).GetController().GetData().keys(): self.isSequence = True # layers = GenGIS.layerTree.GetSequenceLayers() layers = dh.GetNonNullSequences( field ) else: self.isSequence = False # layers = GenGIS.layerTree.GetLocationLayers() layers = dh.GetNonNullLocations( field ) else: self.isSequence = False # layers = GenGIS.layerTree.GetLocationLayers() layers = dh.GetNonNullLocations( field ) values = self.SortFields( layers, field ) for value in values: self.m_StartChoice.Append(value) self.m_StopChoice.Append(value) self.m_StartChoice.SetSelection(0) self.m_StopChoice.SetSelection( len(values)-1 ) # Update the size of steps startData = self.m_StartChoice.GetStringSelection() stopData = self.m_StopChoice.GetStringSelection() steps = self.m_StepsCtrl.GetValue() #Compute Deltas to display to the user. For use with Binning if self.IsDate( startData,stopData ): startData = dateutil.parser.parse(startData) stopData = dateutil.parser.parse(stopData) if self.sort: Delta = ( startData - stopData ) /steps else: Delta = ( stopData - startData ) / steps elif dh.isNumber(startData): Delta = ( float(stopData) - float(startData) ) / float(steps) else: Delta = math.ceil( self.m_StartChoice.GetCount() / float(steps) ) self.m_StepSizeTextCtrl.SetValue( str(Delta) ) self.m_BinStartCtrl.SetValue( str( abs(Delta/2) ) ) self.m_BinEndCtrl.SetValue( str( abs(Delta/2) ) )
def OnDataChange(self, event): # isSequence self.m_StartChoice.Clear() self.m_StopChoice.Clear() field = self.m_DataChoice.GetStringSelection() # if there are sequence layers if GenGIS.layerTree.GetNumSequenceLayers() > 0: # if field is in sequences or locations if field in GenGIS.layerTree.GetSequenceLayer(0).GetController().GetData().keys(): self.isSequence = True # layers = GenGIS.layerTree.GetSequenceLayers() layers = dh.GetNonNullSequences(field) else: self.isSequence = False # layers = GenGIS.layerTree.GetLocationLayers() layers = dh.GetNonNullLocations(field) else: self.isSequence = False # layers = GenGIS.layerTree.GetLocationLayers() layers = dh.GetNonNullLocations(field) values = self.SortFields(layers, field) for value in values: self.m_StartChoice.Append(value) self.m_StopChoice.Append(value) self.m_StartChoice.SetSelection(0) self.m_StopChoice.SetSelection(len(values) - 1) # Update the size of steps startData = self.m_StartChoice.GetStringSelection() stopData = self.m_StopChoice.GetStringSelection() steps = self.m_StepsCtrl.GetValue() # Compute Deltas to display to the user. For use with Binning if self.IsDate(startData, stopData): startData = dateutil.parser.parse(startData) stopData = dateutil.parser.parse(stopData) if self.sort: Delta = (startData - stopData) / steps else: Delta = (stopData - startData) / steps elif dh.isNumber(startData): Delta = (float(stopData) - float(startData)) / float(steps) else: Delta = math.ceil(self.m_StartChoice.GetCount() / float(steps)) self.m_StepSizeTextCtrl.SetValue(str(Delta)) self.m_BinStartCtrl.SetValue(str(abs(Delta / 2))) self.m_BinEndCtrl.SetValue(str(abs(Delta / 2)))
def OnAddRangeSelection(self, event): """ Select dissimilarity matrix cells meeting specified user criteria. """ if str(self.lblMatrixFilename.GetLabelText()) == '<No file loaded>': wx.MessageBox("Please load dissimilarity matrix.", "Dissimilarity matrix not found") return # get user criteria if isNumber(self.txtLessThanValue.GetValue()): lessThanValue = float(self.txtLessThanValue.GetValue()) else: wx.MessageBox("Selection criteria must be numeric.", "Invalid selection criteria") return if isNumber(self.txtGreaterThanValue.GetValue()): greaterThanValue = float(self.txtGreaterThanValue.GetValue()) else: wx.MessageBox("Selection criteria must be numeric.", "Invalid selection criteria") return bSelectUpper = self.chkSelectFromUpperTriangleByRange.IsChecked() bSelectLower = self.chkSelectFromLowerTriangleByRange.IsChecked() # select cells meeting user criteria for i in xrange(0, len(self.index)): for j in xrange(i + 1, len(self.index)): if bSelectUpper and self.matrix[i][ j] <= lessThanValue and self.matrix[i][ j] >= greaterThanValue: self.dissMatrix.SelectBlock(i, j + 1, i, j + 1, True) if bSelectLower and self.matrix[j][ i] <= lessThanValue and self.matrix[j][ i] >= greaterThanValue: self.dissMatrix.SelectBlock(j, i + 1, j, i + 1, True)
def ShowSpread( self, startData, stopData, field, isDate ): #returns all the location in a location set if( self.isSequence ): # locData = GenGIS.layerTree.GetSequenceLayers() locData = dh.GetNonNullSequences( field ) else: # locData = GenGIS.layerTree.GetLocationLayers() locData = dh.GetNonNullLocations( field ) GenGIS.viewport.Refresh() # set initial visual properties of all location sites for i in xrange(0, len(locData)): if self.isSequence: id = locData[i].GetController().GetSiteId() index = self.locationMap[id] loc = GenGIS.layerTree.GetLocationLayer(index) if self.ColourIntensity: loc.GetController().SetColour( GenGIS.Colour(1.0, 0.5, 0) ) loc.GetController().SetSize(4.0) # Set initial state self.StartingState[loc.GetName()] = loc.GetController().IsActive() else: if self.ColourIntensity: locData[i].GetController().SetColour(GenGIS.Colour(1.0, 0.5, 0)) locData[i].GetController().SetSize(4.0) # Set Initial State # print "ID: ",locData[i].GetName()," State: ",locData[i].GetController().IsActive() self.StartingState[locData[i].GetName()] = locData[i].GetController().IsActive() locData[i].GetController().SetActive(False) GenGIS.viewport.Refresh() # label for showing current date # Don't really like the labels anymore # self.label.SetScreenPosition(GenGIS.Point3D(40.0, 300.0, 1.0)) # self.label.SetRenderingStyle(GenGIS.LABEL_RENDERING_STYLE.PERSPECTIVE) # GenGIS.graphics.AddLabel(self.label) if isDate: self.DisplayTemporal( locData, field, startData, stopData ) elif dh.isNumber(startData): self.DisplayNumeric( locData, startData, stopData ) else: self.DisplayText( locData, startData, stopData )
def ShowSpread(self, startData, stopData, field, isDate): # returns all the location in a location set if self.isSequence: # locData = GenGIS.layerTree.GetSequenceLayers() locData = dh.GetNonNullSequences(field) else: # locData = GenGIS.layerTree.GetLocationLayers() locData = dh.GetNonNullLocations(field) GenGIS.viewport.Refresh() # set initial visual properties of all location sites for i in xrange(0, len(locData)): if self.isSequence: id = locData[i].GetController().GetSiteId() index = self.locationMap[id] loc = GenGIS.layerTree.GetLocationLayer(index) if self.ColourIntensity: loc.GetController().SetColour(GenGIS.Colour(1.0, 0.5, 0)) loc.GetController().SetSize(4.0) # Set initial state self.StartingState[loc.GetName()] = loc.GetController().IsActive() else: if self.ColourIntensity: locData[i].GetController().SetColour(GenGIS.Colour(1.0, 0.5, 0)) locData[i].GetController().SetSize(4.0) # Set Initial State # print "ID: ",locData[i].GetName()," State: ",locData[i].GetController().IsActive() self.StartingState[locData[i].GetName()] = locData[i].GetController().IsActive() locData[i].GetController().SetActive(False) GenGIS.viewport.Refresh() # label for showing current date # Don't really like the labels anymore # self.label.SetScreenPosition(GenGIS.Point3D(40.0, 300.0, 1.0)) # self.label.SetRenderingStyle(GenGIS.LABEL_RENDERING_STYLE.PERSPECTIVE) # GenGIS.graphics.AddLabel(self.label) if isDate: self.DisplayTemporal(locData, field, startData, stopData) elif dh.isNumber(startData): self.DisplayNumeric(locData, startData, stopData) else: self.DisplayText(locData, startData, stopData)
def OnPlot(self, event): if len(self.selectedCols) != 1: wx.MessageBox("Select one (and only one) column to plot!") return if hasattr(self,'rca'): metric=self.table.GetColLabelValue(self.selectedCols[0]) if isNumber(self.userScaleFactor.GetValue()): userScaleFactor = float(self.userScaleFactor.GetValue()) else: wx.MessageBox("Scale factor must be numeric.", "Invalid scale factor") return #Update the viewport using the metric selected by user self.rca.ViewportPlot(metric,userScaleFactor) else: wx.MessageBox("Please 'Run' this plugin before attempting to update the plot!") return
def __init__(self, parent=None): DerivedDataCalculatorLayout.__init__(self, parent) self.SetIcon( wx.Icon(GenGIS.mainWindow.GetExeDir() + "images/CrazyEye.ico", wx.BITMAP_TYPE_ICO)) # check required data has been loaded if GenGIS.layerTree.GetNumMapLayers( ) == 0 or GenGIS.layerTree.GetNumLocationSetLayers( ) == 0 or GenGIS.layerTree.GetNumSequenceLayers() == 0: wx.MessageBox( "This plugin requires map, location, and sequence data to be loaded.", "Additional data required.") self.Close() return # populate unique sequence id combobox for field in GenGIS.layerTree.GetSequenceLayer( 0).GetController().GetMetadataFields(): self.cboUniqueSeqIdField.Append(field) self.cboUniqueSeqIdField.SetSelection(0) # populate sequence count comboxbox with 'likely' numeric fields for field in GenGIS.layerTree.GetSequenceLayer( 0).GetController().GetMetadataFields(): # check if field is numeric for first sequence value = GenGIS.layerTree.GetSequenceLayer( 0).GetController().GetData()[field] if isNumber(value): self.cboSeqCountField.Append(field) if self.cboSeqCountField.GetCount() >= 1: self.cboSeqCountField.SetSelection(0) else: self.cboSeqCountField.Append('<No numeric data>') self.cboSeqCountField.SetStringSelection('<No numeric data>') self.btnUniqueSeqs.Disable() self.btnTotalSeqs.Disable() self.btnNormalizeUniqueSeqs.Disable() # resize frame to fit widgets self.Fit()
def OnPlot(self, event): if len(self.selectedCols) != 1: wx.MessageBox("Select one (and only one) column to plot!") return if hasattr(self, 'rca'): metric = self.table.GetColLabelValue(self.selectedCols[0]) if isNumber(self.userScaleFactor.GetValue()): userScaleFactor = float(self.userScaleFactor.GetValue()) else: wx.MessageBox("Scale factor must be numeric.", "Invalid scale factor") return #Update the viewport using the metric selected by user self.rca.ViewportPlot(metric, userScaleFactor) else: wx.MessageBox( "Please 'Run' this plugin before attempting to update the plot!" ) return
def ViewportPlot(self): terrainController = GenGIS.layerTree.GetMapLayer(0).GetController() # remove previously plotted lines for id in self.graphicalElementIds: GenGIS.graphics.RemoveLine(id) self.graphicalElementIds = [] # get data to plot plotType = self.cboViewportPlot.GetStringSelection() if plotType == 'x data': data = self.x elif plotType == 'y data': data = self.y # bail if data can't be plotted if data == None: GenGIS.viewport.Refresh() return # desired plot attributes lineWidth = self.spinLineWidth.GetValue() if isNumber(self.txtScaleFactor.GetValue()): userScaleFactor = float(self.txtScaleFactor.GetValue()) else: wx.MessageBox("Scale factor must be numeric.", "Invalid scale factor") return # calculate scale factor maxValue = max(max(data), abs(min(data))) if maxValue != 0: scaleFactor = (0.2 * terrainController.GetWidth()) / maxValue else: scaleFactor = 0 scaleFactor *= userScaleFactor # get min and max values for mapping colours if min(data) < 0 and max(data) > 0: # have both negative and positive values so map negative values to # first half of map and positive values to the second half of the map maxValue = max(max(data), -min(data)) minValue = -maxValue else: # all data is either negative or positive so just map over the full colour map minValue = min(data) maxValue = max(data) # plot data activeLocLayers = GenGIS.layerTree.GetLocationSetLayer( 0).GetAllActiveLocationLayers() for i in xrange(0, len(activeLocLayers)): locLayer = activeLocLayers[i] geoCoord = GenGIS.GeoCoord(locLayer.GetController().GetLongitude(), locLayer.GetController().GetLatitude()) pos = GenGIS.Point3D() terrainController.GeoToGrid(geoCoord, pos) colour = self.colourMap.GetInterpolatedColour( data[i], minValue, maxValue) endPos = GenGIS.Point3D(pos.x, scaleFactor * abs(data[i]), pos.z) line = GenGIS.VisualLine(colour, lineWidth, GenGIS.LINE_STYLE.SOLID, GenGIS.Line3D(pos, endPos)) lineId = GenGIS.graphics.AddLine(line) self.graphicalElementIds.append(lineId) GenGIS.viewport.Refresh()
def __init__(self, parent=None): AlphaDiversityVisualizerLayout.__init__ ( self, parent ) self.SetIcon(wx.Icon(GenGIS.mainWindow.GetExeDir() + "images/CrazyEye.ico", wx.BITMAP_TYPE_ICO)) # initialize member variables self.graphicalLines = [] self.graphicalMarkers = [] self.selectedRows = [] self.regressionResults = {} # check required data has been loaded if GenGIS.layerTree.GetNumMapLayers() == 0 or GenGIS.layerTree.GetNumLocationSetLayers() == 0 or GenGIS.layerTree.GetNumSequenceLayers() == 0: wx.MessageBox("This plugin requires map and location data to be loaded.", "Additional data required.") self.Close() return # initialize table self.table.Freeze() self.table.SetSelectionMode(wx.grid.Grid.wxGridSelectRows) self.table.EnableScrolling(True, True) self.table.EnableDragRowSize(True) self.table.SetRowLabelSize(0) # set field (column) labels locationSetLayer = GenGIS.layerTree.GetLocationSetLayer(0) self.table.DeleteCols(0, self.table.GetNumberCols()); self.table.AppendCols(6) self.table.SetColLabelValue(0, 'Field') self.table.SetColLabelValue(1, 'R-Squared Value') self.table.SetColLabelValue(2, 'P-Value') self.table.SetColLabelValue(3, 'Standard Error') self.table.SetColLabelValue(4, 'Slope') self.table.SetColLabelValue(5, 'Intercept') # set site ids in first column locationSetLayer = GenGIS.layerTree.GetLocationSetLayer(0) numericFields = locationSetLayer.GetController().GetNumericMetadataFields(True) self.table.DeleteRows(0, self.table.GetNumberRows()); self.table.AppendRows(len(numericFields)) for i in xrange(0, len(numericFields)): self.table.SetCellValue(i, 0, numericFields[i]) self.table.AutoSizeColumns() self.table.Update() self.table.Thaw() # set measure combobox self.AlphaDiversityMeasures = AlphaDiversityMeasures() for measure in self.AlphaDiversityMeasures.measures: self.cboMeasure.Append(measure) self.cboMeasure.SetSelection(0) # set category field combobox seqLayerController = GenGIS.layerTree.GetSequenceLayer(0).GetController() fields = seqLayerController.GetData().keys() for field in fields: if field.lower() != 'siteid' and field.lower() != 'site id': self.cboCategoryField.Append(field) self.cboCategoryField.SetSelection(0) # set count field combobox numericFields = ['<none>'] for field in sorted(fields): bNumeric = True for i in xrange(0, GenGIS.layerTree.GetNumSequenceLayers()): if isNumber(GenGIS.layerTree.GetSequenceLayer(i).GetController().GetData()[field]) == False: bNumeric = False break if bNumeric: numericFields.append(field) for field in numericFields: self.cboCountField.Append(field) self.cboCountField.SetSelection(0) # set colour map combobox continuousColourMapNames = GenGIS.colourMapManager.GetColourMapContinuousNames() for name in continuousColourMapNames: self.cboColourMap.Append(name) self.cboColourMap.SetSelection(self.cboColourMap.FindString('Diverging (Blue-White-Red)')) # Set colour map comboboxes (dots) for name in continuousColourMapNames: self.cboColourMapDot.Append(name) self.cboColourMapDot.SetSelection(self.cboColourMapDot.FindString('Diverging (Blue-White-Red)')) # initialize plot self.plot = ScatterPlot(self.pnlPlot) self.plot.DrawEmptyPlot() self.UpdateInfo()
def ViewportPlot(self): terrainController = GenGIS.layerTree.GetMapLayer(0).GetController() # remove previously plotted lines for id in self.graphicalElementIds: GenGIS.graphics.RemoveLine(id) self.graphicalElementIds = [] # get data to plot plotType = self.cboViewportPlot.GetStringSelection() if plotType == 'x data': data = self.x elif plotType == 'y data': data = self.y # bail if data can't be plotted if data == None: GenGIS.viewport.Refresh() return # desired plot attributes lineWidth = self.spinLineWidth.GetValue() if isNumber(self.txtScaleFactor.GetValue()): userScaleFactor = float(self.txtScaleFactor.GetValue()) else: wx.MessageBox("Scale factor must be numeric.", "Invalid scale factor") return # calculate scale factor maxValue = max(max(data), abs(min(data))) if maxValue != 0: scaleFactor = (0.2 * terrainController.GetWidth()) / maxValue else: scaleFactor = 0 scaleFactor *= userScaleFactor # get min and max values for mapping colours if min(data) < 0 and max(data) > 0: # have both negative and positive values so map negative values to # first half of map and positive values to the second half of the map maxValue = max(max(data), -min(data)) minValue = -maxValue else: # all data is either negative or positive so just map over the full colour map minValue = min(data) maxValue = max(data) # plot data activeLocLayers = GenGIS.layerTree.GetLocationSetLayer(0).GetAllActiveLocationLayers() for i in xrange(0, len(activeLocLayers)): locLayer = activeLocLayers[i] geoCoord = GenGIS.GeoCoord(locLayer.GetController().GetLongitude(), locLayer.GetController().GetLatitude()) pos = GenGIS.Point3D() terrainController.GeoToGrid(geoCoord, pos) colour = self.colourMap.GetInterpolatedColour(data[i], minValue, maxValue) endPos = GenGIS.Point3D(pos.x, scaleFactor * abs(data[i]), pos.z) line = GenGIS.VisualLine(colour, lineWidth, GenGIS.LINE_STYLE.SOLID, GenGIS.Line3D(pos, endPos)) lineId = GenGIS.graphics.AddLine(line) self.graphicalElementIds.append(lineId) GenGIS.viewport.Refresh()
def __init__(self, parent=None): AlphaDiversityVisualizerLayout.__init__(self, parent) self.SetIcon( wx.Icon(GenGIS.mainWindow.GetExeDir() + "images/CrazyEye.ico", wx.BITMAP_TYPE_ICO)) # initialize member variables self.graphicalLines = [] self.graphicalMarkers = [] self.selectedRows = [] self.regressionResults = {} # check required data has been loaded if GenGIS.layerTree.GetNumMapLayers( ) == 0 or GenGIS.layerTree.GetNumLocationSetLayers( ) == 0 or GenGIS.layerTree.GetNumSequenceLayers() == 0: wx.MessageBox( "This plugin requires map, location and sequence data to be loaded.", "Additional data required.") self.Close() return # initialize table self.table.Freeze() self.table.SetSelectionMode(wx.grid.Grid.wxGridSelectRows) self.table.EnableScrolling(True, True) self.table.EnableDragRowSize(True) self.table.SetRowLabelSize(0) # set field (column) labels locationSetLayer = GenGIS.layerTree.GetLocationSetLayer(0) self.table.DeleteCols(0, self.table.GetNumberCols()) self.table.AppendCols(6) self.table.SetColLabelValue(0, 'Field') self.table.SetColLabelValue(1, 'R-Squared Value') self.table.SetColLabelValue(2, 'P-Value') self.table.SetColLabelValue(3, 'Standard Error') self.table.SetColLabelValue(4, 'Slope') self.table.SetColLabelValue(5, 'Intercept') # set site ids in first column locationSetLayer = GenGIS.layerTree.GetLocationSetLayer(0) numericFields = locationSetLayer.GetController( ).GetNumericMetadataFields(True) self.table.DeleteRows(0, self.table.GetNumberRows()) self.table.AppendRows(len(numericFields)) for i in xrange(0, len(numericFields)): self.table.SetCellValue(i, 0, numericFields[i]) self.table.AutoSizeColumns() self.table.Update() self.table.Thaw() # set measure combobox self.AlphaDiversityMeasures = AlphaDiversityMeasures() for measure in self.AlphaDiversityMeasures.measures: self.cboMeasure.Append(measure) self.cboMeasure.SetSelection(0) # set category field combobox seqLayerController = GenGIS.layerTree.GetSequenceLayer( 0).GetController() fields = seqLayerController.GetData().keys() for field in fields: if field.lower() != 'siteid' and field.lower() != 'site id': self.cboCategoryField.Append(field) self.cboCategoryField.SetSelection(0) # set count field combobox numericFields = ['<none>'] for field in sorted(fields): bNumeric = True for i in xrange(0, GenGIS.layerTree.GetNumSequenceLayers()): if isNumber( GenGIS.layerTree.GetSequenceLayer( i).GetController().GetData()[field]) == False: bNumeric = False break if bNumeric: numericFields.append(field) for field in numericFields: self.cboCountField.Append(field) self.cboCountField.SetSelection(0) # set colour map combobox continuousColourMapNames = GenGIS.colourMapManager.GetColourMapContinuousNames( ) for name in continuousColourMapNames: self.cboColourMap.Append(name) self.cboColourMap.SetSelection( self.cboColourMap.FindString('Diverging (Blue-White-Red)')) # Set colour map comboboxes (dots) for name in continuousColourMapNames: self.cboColourMapDot.Append(name) self.cboColourMapDot.SetSelection( self.cboColourMapDot.FindString('Diverging (Blue-White-Red)')) # initialize plot self.plot = ScatterPlot(self.pnlPlot) self.plot.DrawEmptyPlot() self.UpdateInfo()