Changeset 398

Show
Ignore:
Timestamp:
05/29/09 16:57:17 (4 years ago)
Author:
jjr8
Message:

Checkin of unfinished code so that I can rebuild the Arc 9.3 toolbox for testing purposes.

Location:
MGET/Branches/Jason/PythonPackage/src/GeoEco
Files:
2 modified

Legend:

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

    r380 r398  
    14411441    description=_( 
    14421442u"""Type of rasters to find. If provided, only rasters of this type 
    1443 will be found. Please see the documentation for the ArcGIS 
    1444 geoprocessor's ListRasters function for more information. At the time 
    1445 of this writing, the ArcGIS 9.2 documentation specified that any of 
    1446 the following strings would be accepted: All, ADRG, BIL, BIP, BSQ, 
    1447 BMP, CADRG, CIB, ERS, GIF, GIS, GRID, STACK, IMG, JPEG, LAN, SID, SDE, 
    1448 TIFF, RAW, PNG, NITF."""), 
     1443will be found. At the time of this writing, the ArcGIS 9.3 
     1444documentation specified that any of the following strings would be 
     1445accepted: ALL, BMP, GIF, GRID, IMG, JP2, JPG, PNG, TIFF. 
     1446 
     1447This parameter requires ArcGIS 9.3 or later."""), 
    14491448    arcGISDisplayName=_(u'Raster type'), 
    1450     arcGISCategory=_(u'Search options')) 
     1449    arcGISCategory=_(u'Search options'), 
     1450    dependencies=[ArcGISDependency(9, 3)]) 
    14511451 
    14521452AddArgumentMetadata(ArcGISRaster.Find, u'basePath', 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Modeling.py

    r397 r398  
    103103 
    104104    @classmethod 
    105     def PredictFromArcGISRasters(cls, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, coordinateSystem, extent, cellSize, resamplingTechniques=None, ignoreOutOfRangeValues=True, outputErrorRaster=None, outputBinaryResponseRaster=None, cutoff=None, buildPyramids=False, overwriteExisting=False): 
     105    def PredictFromArcGISRasters(cls, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, templateRaster=None, resamplingTechniques=None, ignoreOutOfRangeValues=True, outputErrorRaster=None, outputBinaryResponseRaster=None, cutoff=None, buildPyramids=False, overwriteExisting=False): 
    106106        cls.__doc__.Obj.ValidateMethodInvocation() 
    107         _PredictFromArcGISRasters('glm', inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, coordinateSystem, extent, cellSize, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting) 
     107        _PredictFromArcGISRasters('glm', inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, templateRaster, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting) 
    108108 
    109109class GAM(object): 
     
    173173 
    174174    @classmethod 
    175     def PredictFromArcGISRasters(cls, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, coordinateSystem, extent, cellSize, resamplingTechniques=None, ignoreOutOfRangeValues=True, outputErrorRaster=None, outputBinaryResponseRaster=None, cutoff=None, buildPyramids=False, overwriteExisting=False): 
     175    def PredictFromArcGISRasters(cls, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, templateRaster=None, resamplingTechniques=None, ignoreOutOfRangeValues=True, outputErrorRaster=None, outputBinaryResponseRaster=None, cutoff=None, buildPyramids=False, overwriteExisting=False): 
    176176        cls.__doc__.Obj.ValidateMethodInvocation() 
    177         _PredictFromArcGISRasters('gam', inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, coordinateSystem, extent, cellSize, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting) 
     177        _PredictFromArcGISRasters('gam', inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, templateRaster, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting) 
    178178 
    179179    @classmethod 
    180     def BayesPredictFromArcGISRasters(cls, inputModelFile, inputPredictorRasters, variableNames, thresholds, outputProbabilityRasters, coordinateSystem, extent, cellSize, resamplingTechniques=None, ignoreOutOfRangeValues=True, samples=1000, chunks=100, buildPyramids=False, overwriteExisting=False): 
     180    def BayesPredictFromArcGISRasters(cls, inputModelFile, inputPredictorRasters, variableNames, thresholds, outputProbabilityRasters, templateRaster=None, resamplingTechniques=None, ignoreOutOfRangeValues=True, samples=1000, chunks=100, buildPyramids=False, overwriteExisting=False): 
    181181        cls.__doc__.Obj.ValidateMethodInvocation() 
    182182 
     
    188188            if raster in inputPredictorRastersLower: 
    189189                Logger.RaiseException(ValueError(_(u'The output raster %(out)s also appears in the list of input predictor rasters. This is not allowed. Please specify a different output raster or remove it from the list of input predictor rasters.') % {u'out': outputProbabilityRasters[i]})) 
    190  
    191         from GeoEco.Types import EnvelopeTypeMetadata 
    192         left, bottom, right, top = EnvelopeTypeMetadata.ParseCoordinatesFromString(extent) 
    193  
    194         if right - left <= 0: 
    195             Logger.RaiseException(ValueError(_(u'The horizontal extent must be greater than zero.'))) 
    196  
    197         if top - bottom <= 0: 
    198             Logger.RaiseException(ValueError(_(u'The vertical extent must be greater than zero.'))) 
    199  
    200         if cellSize <= 0: 
    201             Logger.RaiseException(ValueError(_(u'The cell size must be greater than zero.'))) 
    202190 
    203191        # Load the fitted model. 
     
    234222            tempDir = TemporaryDirectory() 
    235223 
    236             _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, coordinateSystem, extent, cellSize, resamplingTechniques) 
     224            _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, templateRaster, resamplingTechniques) 
    237225 
    238226            # Do the prediction. The prediction rasters are 
     
    268256                tempOutputRaster = os.path.join(tempDir.Path, u'output%i' % i) 
    269257                gp.ASCIIToRaster_Conversion(os.path.join(tempDir.Path, u'temp_output%i.txt' % i), tempOutputRaster, u'FLOAT') 
    270                 gp.DefineProjection_management(tempOutputRaster, coordinateSystem) 
     258                gp.DefineProjection_management(tempOutputRaster, coordinateSystem)          # TODO: Fix this 
    271259                if buildPyramids: 
    272260                    gp.BuildPyramids_Management(tempOutputRaster) 
     
    762750    return dataFrameName, xColumnParam, yColumnParam, zColumnParam, mColumnParam, coordinateSystemParam, familyParam 
    763751 
    764 def _PredictFromArcGISRasters(modelType, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, coordinateSystem, extent, cellSize, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting): 
     752def _PredictFromArcGISRasters(modelType, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, templateRaster, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting): 
    765753 
    766754    # Perform additional parameter validation. 
     755 
     756    gp = GeoprocessorManager.GetWrappedGeoprocessor() 
     757 
     758    for raster in inputPredictorRasters: 
     759        d = gp.Describe(raster) 
     760        if d.SpatialReference.Name is None or d.SpatialReference.Name.lower() == u'unknown': 
     761            Logger.RaiseException(ValueError(_(u'The predictor raster %(raster)s does not have a coordinate system defined. Please define the coordinate system for this raster and try again. (Use the ArcGIS Define Projection tool.)') % {u'raster': raster})) 
    767762 
    768763    if outputResponseRaster.lower() in map(unicode.lower, inputPredictorRasters): 
     
    772767        Logger.RaiseException(ValueError(_(u'The output standard error raster %(out)s also appears in the list of input predictor rasters. This is not allowed. Please specify a different output standard error raster or remove it from the list of input predictor rasters.') % {u'out': outputResponseRaster})) 
    773768 
    774     from GeoEco.Types import EnvelopeTypeMetadata 
    775     left, bottom, right, top = EnvelopeTypeMetadata.ParseCoordinatesFromString(extent) 
    776  
    777     if right - left <= 0: 
    778         Logger.RaiseException(ValueError(_(u'The horizontal extent must be greater than zero.'))) 
    779  
    780     if top - bottom <= 0: 
    781         Logger.RaiseException(ValueError(_(u'The vertical extent must be greater than zero.'))) 
    782  
    783     if cellSize <= 0: 
    784         Logger.RaiseException(ValueError(_(u'The cell size must be greater than zero.'))) 
    785  
    786769    if outputBinaryResponseRaster is not None and cutoff is None: 
    787770        Logger.RaiseException(ValueError(_(u'To create a binary response raster, you must also supply a value for the Cutoff parameter.'))) 
    788771 
     772    # Look up the coordinate system, cell size, and extent of the 
     773    # template raster. 
     774 
     775    if templateRaster is None: 
     776        templateRaster = inputPredictorRasters[0] 
     777    else: 
     778        d = gp.Describe(templateRaster) 
     779        if d.SpatialReference.Name is None or d.SpatialReference.Name.lower() == u'unknown': 
     780            Logger.RaiseException(ValueError(_(u'The template raster %(raster)s does not have a coordinate system defined. Please define the coordinate system for this raster and try again. (Use the ArcGIS Define Projection tool.)') % {u'raster': templateRaster})) 
     781 
    789782    # Load the fitted model. 
    790783 
    791784    r = R.GetInterpreter() 
    792     gp = GeoprocessorManager.GetWrappedGeoprocessor() 
    793785 
    794786    r('load("%s")' % inputModelFile.replace('\\', '\\\\')) 
     
    876868            # First prepare the input rasters for the prediction. 
    877869 
    878             _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, coordinateSystem, extent, cellSize, resamplingTechniques) 
     870            _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, templateRaster, resamplingTechniques) 
    879871 
    880872            # Do the prediction. The prediction rasters are 
     
    953945        r('if (exists("fam20985982305")) rm("fam20985982305", pos=globalenv())') 
    954946 
    955 def _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, coordinateSystem, extent, cellSize, resamplingTechniques): 
     947def _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, templateRaster, resamplingTechniques): 
    956948 
    957949    # Build a dictionary that maps predictor variable names in 
     
    16231615in the model formula, it will be ignored. 
    16241616 
    1625 All of the predictor rasters must use the same datum, but they need 
    1626 not have the same coordinate system, extent, or cell size. If these 
    1627 characteristics differ from those you specify below for the output 
    1628 raster, this tool will automatically project and clip them prior to 
    1629 performing the prediction. 
    1630  
    1631 The predictor rasters must be able to be projected to the output 
     1617All of the predictor rasters must have a coordinate system defined. 
     1618They must all share the same datum. If you also specify the Template 
     1619Raster For Outputs parameter, they must have the datum of the template 
     1620raster. If you do not specify that parameter, the first predictor 
     1621raster will be used as the template raster. 
     1622 
     1623The predictor rasters need not have the same coordinate system, 
     1624extent, or cell size as the template raster. If these characteristics 
     1625differ from the template raster, this tool will automatically project 
     1626and clip the predictor rasters to conform to the template raster. The 
     1627predictor rasters must be able to be projected to the template 
    16321628raster's coordinate system without requiring the specification of a 
    16331629geographic transformation. An error will be reported if a geographic 
     
    16351631predictor rasters manually before providing them to this tool. 
    16361632 
    1637 By default, the bilinear interpolation resampling technique will be 
    1638 used to project the predictor rasters. You can specify different 
    1639 resampling techniques using the Resampling Techniques for Predictor 
    1640 Rasters parameter. Bilinear interpolation is appropriate for 
    1641 continuous variables such as sea surface temperature but not for 
    1642 categorical variables such as bottom substrate type. For categorical 
    1643 variables, you should specify the nearest neighbor technique."""), 
     1633By default, floating point predictor rasters will be projected using 
     1634bilinear interpolation and integer predictor rasters will be projected 
     1635using nearest neighbor assignment. Bilinear interpolation is 
     1636appropriate for continuous variables such as sea surface temperature, 
     1637while nearest neighbor is appropriate for categorical variables such 
     1638as bottom substrate type. If these defaults are not appropriate for 
     1639your predictors, specify different algorithms using the Resampling 
     1640Techniques for Predictor Rasters parameter."""), 
    16441641    arcGISDisplayName=_(u'Input predictor rasters')) 
    16451642 
     
    16661663    arcGISDisplayName=_(u'Output response raster')) 
    16671664 
    1668 AddArgumentMetadata(GLM.PredictFromArcGISRasters, u'coordinateSystem', 
    1669     typeMetadata=CoordinateSystemTypeMetadata(), 
    1670     description=_( 
    1671 u"""Coordinate system for the output rasters. 
    1672  
    1673 This coordinate system must use the same datum as the input predictor 
    1674 rasters but may use a different projection, so long as the input 
    1675 rasters can be projected to it without requiring the specification of 
    1676 a geographic transformation."""), 
    1677     arcGISDisplayName=_(u'Coordinate system')) 
    1678  
    1679 AddArgumentMetadata(GLM.PredictFromArcGISRasters, u'extent', 
    1680     typeMetadata=EnvelopeTypeMetadata(), 
    1681     description=_( 
    1682 u"""Extent for the output rasters, in the units of the output rasters' 
    1683 coordinate system."""), 
    1684     arcGISDisplayName=_(u'Extent')) 
    1685  
    1686 AddArgumentMetadata(GLM.PredictFromArcGISRasters, u'cellSize', 
    1687     typeMetadata=FloatTypeMetadata(minValue=0.0), 
    1688     description=_( 
    1689 u"""Cell size for the output rasters, in the units of the output 
    1690 rasters' coordinate system. 
    1691  
    1692 The selection of the output cell size should be a carefully considered 
    1693 decision. If all of the input predictor rasters have the same cell 
    1694 size, that size is an obvious choice. If the rasters have different 
    1695 cell sizes, the cell size of the coarsest raster (the one with the 
    1696 largest cell size) is a common choice. Please consult the scientific 
    1697 literature for further advice. 
    1698  
    1699 Input predictor rasters that do not have this cell size will be 
    1700 automatically projected using the ArcGIS Project Raster geoprocessing 
    1701 tool, as described in the documentation for the Input Predictor 
    1702 Rasters parameter."""), 
    1703     arcGISDisplayName=_(u'Cell size')) 
     1665AddArgumentMetadata(GLM.PredictFromArcGISRasters, u'templateRaster', 
     1666    typeMetadata=ArcGISRasterTypeMetadata(mustExist=True, mustBeDifferentThanArguments=[u'inputModelFile', u'outputResponseRaster'], canBeNone=True), 
     1667    description=_( 
     1668u"""Template raster that defines the coordinate system, extent, and 
     1669cell size of the output rasters produced by this tool. 
     1670 
     1671If you do not specify a template raster, the first predictor raster 
     1672will be used instead. 
     1673 
     1674All predictor rasters must share the same datum as the template 
     1675raster. The predictor rasters need not have the same coordinate 
     1676system, extent, or cell size as the template raster. If these 
     1677characteristics differ from the template raster, this tool will 
     1678automatically project and clip the predictor rasters to conform to the 
     1679template raster. Please see the documentation for the Input Predictor 
     1680Rasters parameter for more information."""), 
     1681    arcGISDisplayName=_(u'Template raster for outputs')) 
    17041682 
    17051683AddArgumentMetadata(GLM.PredictFromArcGISRasters, u'resamplingTechniques', 
     
    20422020CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'variableNames', GAM.PredictFromArcGISRasters, u'variableNames') 
    20432021CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'outputResponseRaster', GAM.PredictFromArcGISRasters, u'outputResponseRaster') 
    2044 CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'coordinateSystem', GAM.PredictFromArcGISRasters, u'coordinateSystem') 
    2045 CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'extent', GAM.PredictFromArcGISRasters, u'extent') 
    2046 CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'cellSize', GAM.PredictFromArcGISRasters, u'cellSize') 
     2022CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'templateRaster', GAM.PredictFromArcGISRasters, u'templateRaster') 
    20472023CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'resamplingTechniques', GAM.PredictFromArcGISRasters, u'resamplingTechniques') 
    20482024CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'ignoreOutOfRangeValues', GAM.PredictFromArcGISRasters, u'ignoreOutOfRangeValues') 
     
    21152091    arcGISDisplayName=_(u'Output probability rasters')) 
    21162092 
    2117 CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'coordinateSystem', GAM.BayesPredictFromArcGISRasters, u'coordinateSystem') 
    2118 CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'extent', GAM.BayesPredictFromArcGISRasters, u'extent') 
    2119 CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'cellSize', GAM.BayesPredictFromArcGISRasters, u'cellSize') 
     2093CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'templateRaster', GAM.BayesPredictFromArcGISRasters, u'templateRaster') 
    21202094CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'resamplingTechniques', GAM.BayesPredictFromArcGISRasters, u'resamplingTechniques') 
    21212095CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'ignoreOutOfRangeValues', GAM.BayesPredictFromArcGISRasters, u'ignoreOutOfRangeValues')