Changeset 818

Show
Ignore:
Timestamp:
07/15/11 14:12:55 (22 months ago)
Author:
jjr8
Message:

Final changes to FEET for MGET 0.8a27, and other changes relating to modeling for Portugal workshop.

Location:
MGET/Branches/Jason/PythonPackage/src/GeoEco
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/DataManagement/ArcGISRasters.py

    r718 r818  
    14841484                # our callers. 
    14851485 
    1486                 noDataValue = int(b.GetNoDataValue())       # On ArcGIS 9.1 sp2, gp.Describe(tempRasterPath).NoDataValue crashes Python, so we use this instead 
     1486                noDataValue = b.GetNoDataValue()       # On ArcGIS 9.1 sp2, gp.Describe(tempRasterPath).NoDataValue crashes Python, so we use this instead 
    14871487                 
    14881488                if gp.Describe(tempRasterPath).IsInteger: 
     1489                    if noDataValue is not None: 
     1490                        noDataValue = int(noDataValue) 
     1491                         
    14891492                    minValue = int(b.GetMinimum()) 
    14901493                    maxValue = int(b.GetMaximum()) 
     
    16111614         
    16121615        if projectedCoordinateSystem is not None: 
    1613             outputRaster = tempfile.mktemp(dir=tempDir) 
     1616            outputRaster = None 
     1617            while outputRaster is None or '-' in outputRaster:      # Python mktemp can generate a name that includes a - character, which is illegal in ArcInfo Binary Grid names. 
     1618                outputRaster = tempfile.mktemp(dir=tempDir) 
     1619                 
    16141620            Logger.Debug(_(u'Projecting...')) 
    16151621            if geographicTransformation is not None or registrationPoint is not None: 
     
    16171623            else: 
    16181624                gp.ProjectRaster_Management(inputRaster, outputRaster, projectedCoordinateSystem, resamplingTechnique, projectedCellSize) 
     1625 
    16191626            inputRaster = outputRaster 
    16201627 
     
    16221629 
    16231630        if clippingDataset is not None or clippingRectangle is not None: 
    1624             outputRaster = tempfile.mktemp(dir=tempDir) 
     1631            outputRaster = None 
     1632            while outputRaster is None or '-' in outputRaster:      # Python mktemp can generate a name that includes a - character, which is illegal in ArcInfo Binary Grid names. 
     1633                outputRaster = tempfile.mktemp(dir=tempDir) 
     1634 
    16251635            Logger.Debug(_(u'Clipping...')) 
    16261636 
     
    16641674             
    16651675            Logger.Debug(_(u'Executing map algebra...')) 
    1666             outputRaster = tempfile.mktemp(dir=tempDir) 
     1676 
     1677            outputRaster = None 
     1678            while outputRaster is None or '-' in outputRaster:      # Python mktemp can generate a name that includes a - character, which is illegal in ArcInfo Binary Grid names. 
     1679                outputRaster = tempfile.mktemp(dir=tempDir) 
     1680 
    16671681            gp.SingleOutputMapAlgebra_sa(mapAlgebraExpressionToExecute, outputRaster) 
    16681682            gp.RefreshCatalog(tempDir) 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/FisheryAnalysis/FEET.py

    r808 r818  
    363363 
    364364                    if bathymetryRasterType is not None: 
    365                         if cursor.GetValue(minDepthField) is not None and cursor.GetValue(minDepthField) < 0 or cursor.GetValue(maxDepthField) is not None and cursor.GetValue(maxDepthField) < 0: 
     365                        if minDepthField is not None and cursor.GetValue(minDepthField) is not None and cursor.GetValue(minDepthField) < 0 or maxDepthField is not None and cursor.GetValue(maxDepthField) is not None and cursor.GetValue(maxDepthField) < 0: 
    366366                            outerLimitFCs.append(cls._ConstrainByRasterValues(tempGDB, _(u'bathymetry'), 'Bathymetry', rowNum, fisheryID, cursor, maxDepthField, minDepthField, geographicFishingZoneLayer, bathymetryRasterType == u'fishery-specific rasters', bathymetryRaster, bathymetryRasterField, simplifyBathymetry, projectedCS, projectedFeatureCache, rasterConstraintCache)) 
    367367                        else: 
     
    773773            if oldGPExtent is None: 
    774774                oldGPExtent = u'' 
    775             gp.Extent = geographicFishingZoneLayer 
     775 
     776            from GeoEco.Types import EnvelopeTypeMetadata 
     777 
     778            left, bottom, right, top = EnvelopeTypeMetadata.ParseFromArcGISString(gp.Describe(projectedFZ).Extent) 
     779            rasterCellSize = gp.Describe(raster).MeanCellWidth 
     780            left -= rasterCellSize 
     781            bottom -= rasterCellSize 
     782            right += rasterCellSize 
     783            top += rasterCellSize 
     784             
     785            gp.Extent = '%r %r %r %r' % (left, bottom, right, top) 
    776786             
    777787            try: 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Exploratory.py

    r812 r818  
    225225            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) 
    226226 
    227 ##    @classmethod 
    228 ##    def ClevelandPlotForArcGISTable(cls, table, fields=None, transforms=None, orderByField=None, where=None, 
    229 ##                                    xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, 
    230 ##                                    outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 
    231 ##        cls.__doc__.Obj.ValidateMethodInvocation() 
    232 ## 
    233 ##        # Load the data frame into a temporary data frame. 
    234 ##         
    235 ##        r = R.GetInterpreter() 
    236 ##        transformsName = R.GetUniqueVariableName() 
    237 ##        dataFrameName = R.GetUniqueVariableName() 
    238 ##        R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName) 
    239 ## 
    240 ##        # Create the plot. 
    241 ##         
    242 ##        try: 
    243 ##            if r('length(%s)' % dataFrameName) <= 0: 
    244 ##                if where is not None: 
    245 ##                    Logger.RaiseException(ValueError(_(u'The where clause "%(where)s" did not select any rows from the table %(table)s.') % {u'table': table, u'where': where})) 
    246 ##                else: 
    247 ##                    Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table})) 
    248 ## 
    249 ##            if transforms is not None and len(transforms) > 0: 
    250 ##                if len(transforms) > len(fields): 
    251 ##                    transforms = transforms[:len(fields)] 
    252 ##                r[transformsName] = dict(zip(fields[:len(transforms)], transforms)) 
    253 ##            else: 
    254 ##                r('%s <- NULL' % transformsName) 
    255 ## 
    256 ##            # TODO: Sort 
    257 ## 
    258 ##            r('library(lattice)') 
    259 ##            #r('foobar <<- cbind(%s$wincrd, %s$tarsus)' % (dataFrameName, dataFrameName)) 
    260 ##            r('zz <- VADeaths') 
    261 ##            r('dotplot(zz)') 
    262 ## 
    263 ####            R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ClevelandPlotForDataframe.r'), False) 
    264 ####            if outputFile is None: 
    265 ####                r('ClevelandPlot(%s, transforms=%s)' % (dataFrameName, transformsName)) 
    266 ####            else: 
    267 ####                Logger.Info(_(u'Writing scatterplot matrix to %(file)s...') % {u'file': outputFile}) 
    268 ####                r('ClevelandPlotToFile("%s", %s, transforms=%s, res=%f, width=%f, height=%f, pointSize=%f, bg="%s")' % (outputFile.replace(u'\\', u'/'), dataFrameName, transformsName, str(diagonal), str(lower), str(upper), res, width, height, pointSize, bg)) 
    269 ## 
    270 ##        # Delete the data frame. 
    271 ##         
    272 ##        finally: 
    273 ##            r('if (exists("%s")) rm("%s")' % (transformsName, transformsName)) 
    274 ##            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) 
     227    @classmethod 
     228    def ClevelandPlotForArcGISTable(cls, table, fields=None, transforms=None, orderByField=None, where=None, 
     229                                    xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, 
     230                                    outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 
     231        cls.__doc__.Obj.ValidateMethodInvocation() 
     232 
     233        # Load the data frame into a temporary data frame. 
     234 
     235        if orderByField is not None: 
     236            if fields is None: 
     237                fields = [] 
     238            if orderByField not in fields: 
     239                fields.append(orderByField) 
     240         
     241        r = R.GetInterpreter() 
     242        transformsName = R.GetUniqueVariableName() 
     243        dataFrameName = R.GetUniqueVariableName() 
     244        R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName) 
     245 
     246        # Create the plot. 
     247         
     248        try: 
     249            if r('length(%s)' % dataFrameName) <= 0: 
     250                if where is not None: 
     251                    Logger.RaiseException(ValueError(_(u'The where clause "%(where)s" did not select any rows from the table %(table)s.') % {u'table': table, u'where': where})) 
     252                else: 
     253                    Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table})) 
     254 
     255            if transforms is not None and len(transforms) > 0: 
     256                if len(transforms) > len(fields): 
     257                    transforms = transforms[:len(fields)] 
     258                r[transformsName] = dict(zip(fields[:len(transforms)], transforms)) 
     259            else: 
     260                r('%s <- NULL' % transformsName) 
     261 
     262            if orderByField is not None: 
     263                r('%s <- %s[order(%s$%s),]' % (dataFrameName, dataFrameName, dataFrameName, orderByField)) 
     264 
     265            R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ClevelandPlotForDataframe.r'), False) 
     266            if outputFile is None: 
     267                r('ClevelandPlot(%s, transforms=%s)' % (dataFrameName, transformsName)) 
     268            else: 
     269                Logger.Info(_(u'Writing scatterplot matrix to %(file)s...') % {u'file': outputFile}) 
     270                r('ClevelandPlotToFile("%s", %s, transforms=%s, res=%f, width=%f, height=%f, pointSize=%f, bg="%s")' % (outputFile.replace(u'\\', u'/'), dataFrameName, transformsName, res, width, height, pointSize, bg)) 
     271 
     272        # Delete the data frame. 
     273         
     274        finally: 
     275            r('if (exists("%s")) rm("%s")' % (transformsName, transformsName)) 
     276            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) 
    275277 
    276278 
     
    519521    description=_( 
    520522u"""The default pointsize of text in the output plot file."""), 
    521     arcGISDisplayName=_(u'Default pointsize of text in diagnostic plots'), 
     523    arcGISDisplayName=_(u'Default pointsize of text'), 
    522524    arcGISCategory=_(u'Output file options')) 
    523525 
     
    707709CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'overwriteExisting', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'overwriteExisting') 
    708710 
    709 ### Public method: RExploratoryPlots.ClevelandPlotForArcGISTable 
    710 ## 
    711 ##AddMethodMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, 
    712 ##    shortDescription=_(u'Creates a multi-panel Cleveland dotplot for a table.'), 
    713 ##    longDescription=_( 
    714 ##u"""Cleveland dotplots (Cleveland 1993) are typically used to detect 
    715 ##possible outliers. Each dotplot shows the row number of the record vs. 
    716 ##the value of a field. Points that appear far to the left or right are 
    717 ##extreme values of that field and may be statistical outliers that 
    718 ##should be investigated and possibly removed prior to further analysis 
    719 ##of the data. 
    720 ## 
    721 ##For advice on how to use Cleveland dotplots, please see Zuur et al. 
    722 ##(2009). 
    723 ## 
    724 ##**References:** 
    725 ## 
    726 ##Cleveland, W.S. (1993) Visualizing Data. Hobart Press, Summit, NJ. 
    727 ## 
    728 ##Zuur, A.F., Ineo, E.N., Elphick, C.S. (2009) A protocol for data 
    729 ##exploration to avoid common statistical problems. Methods in Ecology & 
    730 ##Evolution 1: 3-14."""), 
    731 ##    isExposedToPythonCallers=True, 
    732 ##    isExposedByCOM=True, 
    733 ##    isExposedAsArcGISTool=True, 
    734 ##    arcGISDisplayName=_(u'Cleveland Plot for Table'), 
    735 ##    arcGISToolCategory=_(u'Statistics\\Explore Data'), 
    736 ##    dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)]) 
    737 ## 
    738 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.ClevelandPlotForArcGISTable, u'cls') 
    739 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.ClevelandPlotForArcGISTable, u'table') 
    740 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields', RExploratoryPlots.ClevelandPlotForArcGISTable, u'fields') 
    741 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms', RExploratoryPlots.ClevelandPlotForArcGISTable, u'transforms') 
    742 ## 
    743 ##AddArgumentMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, u'orderByField', 
    744 ##    typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True), 
    745 ##    description=_( 
    746 ##u"""Field specifying how the data will be ordered on the y axis of the 
    747 ##plots. 
    748 ## 
    749 ##This parameter is optional and provided to enhance readability when 
    750 ##the plotted fields' values correlate with another field. For example, 
    751 ##if the weight and size of an animal correlate with the animal's age, 
    752 ##you could order the plots by age and the weight and size points would 
    753 ##cluster around a trend line rather than being randomly dispersed. This 
    754 ##may aid in the visual identification of possible outliers."""), 
    755 ##    arcGISParameterDependencies=[u'table'], 
    756 ##    arcGISDisplayName=_(u'Order by field')) 
    757 ## 
    758 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.ClevelandPlotForArcGISTable, u'where') 
    759 ## 
    760 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'xColumnName') 
    761 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'yColumnName') 
    762 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'zColumnName') 
    763 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'mColumnName') 
    764 ## 
    765 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.ClevelandPlotForArcGISTable, u'outputFile') 
    766 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.ClevelandPlotForArcGISTable, u'res') 
    767 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.ClevelandPlotForArcGISTable, u'width') 
    768 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.ClevelandPlotForArcGISTable, u'height') 
    769 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.ClevelandPlotForArcGISTable, u'pointSize') 
    770 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.ClevelandPlotForArcGISTable, u'bg') 
    771 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.ClevelandPlotForArcGISTable, u'overwriteExisting') 
     711# Public method: RExploratoryPlots.ClevelandPlotForArcGISTable 
     712 
     713AddMethodMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, 
     714    shortDescription=_(u'Creates a multi-panel Cleveland dotplot for a table.'), 
     715    longDescription=_( 
     716u"""Cleveland dotplots (Cleveland 1993) are typically used to explore 
     717the distributions of values in a table and detect possible outliers. 
     718Each dotplot shows the row number of the record vs. the value of a 
     719field. Points that appear far to the left or right are extreme values 
     720of that field and may be statistical outliers that should be 
     721investigated and possibly removed prior to further analysis of the 
     722data. 
     723 
     724For advice on how to use Cleveland dotplots, please see Zuur et al. 
     725(2009). 
     726 
     727**References:** 
     728 
     729Cleveland, W.S. (1993) Visualizing Data. Hobart Press, Summit, NJ. 
     730 
     731Zuur, A.F., Ineo, E.N., Elphick, C.S. (2009) A protocol for data 
     732exploration to avoid common statistical problems. Methods in Ecology & 
     733Evolution 1: 3-14."""), 
     734    isExposedToPythonCallers=True, 
     735    isExposedByCOM=True, 
     736    isExposedAsArcGISTool=True, 
     737    arcGISDisplayName=_(u'Cleveland Plot for Table'), 
     738    arcGISToolCategory=_(u'Statistics\\Explore Data'), 
     739    dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)]) 
     740 
     741CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.ClevelandPlotForArcGISTable, u'cls') 
     742CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.ClevelandPlotForArcGISTable, u'table') 
     743CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields', RExploratoryPlots.ClevelandPlotForArcGISTable, u'fields') 
     744CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms', RExploratoryPlots.ClevelandPlotForArcGISTable, u'transforms') 
     745 
     746AddArgumentMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, u'orderByField', 
     747    typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True), 
     748    description=_( 
     749u"""Field specifying how the data will be ordered on the y axis of the 
     750plots. 
     751 
     752This parameter is optional and provided to enhance readability when 
     753the plotted fields' values correlate with another field. For example, 
     754if the weight and size of an animal correlate with the animal's age, 
     755you could order the plots by age and the weight and size points would 
     756cluster around a trend line rather than being randomly dispersed. This 
     757may aid in the visual identification of possible outliers."""), 
     758    arcGISParameterDependencies=[u'table'], 
     759    arcGISDisplayName=_(u'Order by field')) 
     760 
     761CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.ClevelandPlotForArcGISTable, u'where') 
     762 
     763CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'xColumnName') 
     764CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'yColumnName') 
     765CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'zColumnName') 
     766CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'mColumnName') 
     767 
     768CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.ClevelandPlotForArcGISTable, u'outputFile') 
     769CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.ClevelandPlotForArcGISTable, u'res') 
     770CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.ClevelandPlotForArcGISTable, u'width') 
     771CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.ClevelandPlotForArcGISTable, u'height') 
     772CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.ClevelandPlotForArcGISTable, u'pointSize') 
     773CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.ClevelandPlotForArcGISTable, u'bg') 
     774CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.ClevelandPlotForArcGISTable, u'overwriteExisting') 
    772775 
    773776###############################################################################