Changeset 398
- Timestamp:
- 05/29/09 16:57:17 (4 years ago)
- Location:
- MGET/Branches/Jason/PythonPackage/src/GeoEco
- Files:
-
- 2 modified
-
DataManagement/ArcGISRasters.py (modified) (1 diff)
-
Statistics/Modeling.py (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
MGET/Branches/Jason/PythonPackage/src/GeoEco/DataManagement/ArcGISRasters.py
r380 r398 1441 1441 description=_( 1442 1442 u"""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."""), 1443 will be found. At the time of this writing, the ArcGIS 9.3 1444 documentation specified that any of the following strings would be 1445 accepted: ALL, BMP, GIF, GRID, IMG, JP2, JPG, PNG, TIFF. 1446 1447 This parameter requires ArcGIS 9.3 or later."""), 1449 1448 arcGISDisplayName=_(u'Raster type'), 1450 arcGISCategory=_(u'Search options')) 1449 arcGISCategory=_(u'Search options'), 1450 dependencies=[ArcGISDependency(9, 3)]) 1451 1451 1452 1452 AddArgumentMetadata(ArcGISRaster.Find, u'basePath', -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Modeling.py
r397 r398 103 103 104 104 @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): 106 106 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) 108 108 109 109 class GAM(object): … … 173 173 174 174 @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): 176 176 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) 178 178 179 179 @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): 181 181 cls.__doc__.Obj.ValidateMethodInvocation() 182 182 … … 188 188 if raster in inputPredictorRastersLower: 189 189 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 EnvelopeTypeMetadata192 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.')))202 190 203 191 # Load the fitted model. … … 234 222 tempDir = TemporaryDirectory() 235 223 236 _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, coordinateSystem, extent, cellSize, resamplingTechniques)224 _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, templateRaster, resamplingTechniques) 237 225 238 226 # Do the prediction. The prediction rasters are … … 268 256 tempOutputRaster = os.path.join(tempDir.Path, u'output%i' % i) 269 257 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 271 259 if buildPyramids: 272 260 gp.BuildPyramids_Management(tempOutputRaster) … … 762 750 return dataFrameName, xColumnParam, yColumnParam, zColumnParam, mColumnParam, coordinateSystemParam, familyParam 763 751 764 def _PredictFromArcGISRasters(modelType, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, coordinateSystem, extent, cellSize, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting):752 def _PredictFromArcGISRasters(modelType, inputModelFile, inputPredictorRasters, variableNames, outputResponseRaster, templateRaster, resamplingTechniques, ignoreOutOfRangeValues, outputErrorRaster, outputBinaryResponseRaster, cutoff, buildPyramids, overwriteExisting): 765 753 766 754 # 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})) 767 762 768 763 if outputResponseRaster.lower() in map(unicode.lower, inputPredictorRasters): … … 772 767 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})) 773 768 774 from GeoEco.Types import EnvelopeTypeMetadata775 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 786 769 if outputBinaryResponseRaster is not None and cutoff is None: 787 770 Logger.RaiseException(ValueError(_(u'To create a binary response raster, you must also supply a value for the Cutoff parameter.'))) 788 771 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 789 782 # Load the fitted model. 790 783 791 784 r = R.GetInterpreter() 792 gp = GeoprocessorManager.GetWrappedGeoprocessor()793 785 794 786 r('load("%s")' % inputModelFile.replace('\\', '\\\\')) … … 876 868 # First prepare the input rasters for the prediction. 877 869 878 _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, coordinateSystem, extent, cellSize, resamplingTechniques)870 _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, templateRaster, resamplingTechniques) 879 871 880 872 # Do the prediction. The prediction rasters are … … 953 945 r('if (exists("fam20985982305")) rm("fam20985982305", pos=globalenv())') 954 946 955 def _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, coordinateSystem, extent, cellSize, resamplingTechniques):947 def _PreparePredictorRasters(r, gp, tempDir, variableNames, inputPredictorRasters, templateRaster, resamplingTechniques): 956 948 957 949 # Build a dictionary that maps predictor variable names in … … 1623 1615 in the model formula, it will be ignored. 1624 1616 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 1617 All of the predictor rasters must have a coordinate system defined. 1618 They must all share the same datum. If you also specify the Template 1619 Raster For Outputs parameter, they must have the datum of the template 1620 raster. If you do not specify that parameter, the first predictor 1621 raster will be used as the template raster. 1622 1623 The predictor rasters need not have the same coordinate system, 1624 extent, or cell size as the template raster. If these characteristics 1625 differ from the template raster, this tool will automatically project 1626 and clip the predictor rasters to conform to the template raster. The 1627 predictor rasters must be able to be projected to the template 1632 1628 raster's coordinate system without requiring the specification of a 1633 1629 geographic transformation. An error will be reported if a geographic … … 1635 1631 predictor rasters manually before providing them to this tool. 1636 1632 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."""), 1633 By default, floating point predictor rasters will be projected using 1634 bilinear interpolation and integer predictor rasters will be projected 1635 using nearest neighbor assignment. Bilinear interpolation is 1636 appropriate for continuous variables such as sea surface temperature, 1637 while nearest neighbor is appropriate for categorical variables such 1638 as bottom substrate type. If these defaults are not appropriate for 1639 your predictors, specify different algorithms using the Resampling 1640 Techniques for Predictor Rasters parameter."""), 1644 1641 arcGISDisplayName=_(u'Input predictor rasters')) 1645 1642 … … 1666 1663 arcGISDisplayName=_(u'Output response raster')) 1667 1664 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')) 1665 AddArgumentMetadata(GLM.PredictFromArcGISRasters, u'templateRaster', 1666 typeMetadata=ArcGISRasterTypeMetadata(mustExist=True, mustBeDifferentThanArguments=[u'inputModelFile', u'outputResponseRaster'], canBeNone=True), 1667 description=_( 1668 u"""Template raster that defines the coordinate system, extent, and 1669 cell size of the output rasters produced by this tool. 1670 1671 If you do not specify a template raster, the first predictor raster 1672 will be used instead. 1673 1674 All predictor rasters must share the same datum as the template 1675 raster. The predictor rasters need not have the same coordinate 1676 system, extent, or cell size as the template raster. If these 1677 characteristics differ from the template raster, this tool will 1678 automatically project and clip the predictor rasters to conform to the 1679 template raster. Please see the documentation for the Input Predictor 1680 Rasters parameter for more information."""), 1681 arcGISDisplayName=_(u'Template raster for outputs')) 1704 1682 1705 1683 AddArgumentMetadata(GLM.PredictFromArcGISRasters, u'resamplingTechniques', … … 2042 2020 CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'variableNames', GAM.PredictFromArcGISRasters, u'variableNames') 2043 2021 CopyArgumentMetadata(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') 2022 CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'templateRaster', GAM.PredictFromArcGISRasters, u'templateRaster') 2047 2023 CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'resamplingTechniques', GAM.PredictFromArcGISRasters, u'resamplingTechniques') 2048 2024 CopyArgumentMetadata(GLM.PredictFromArcGISRasters, u'ignoreOutOfRangeValues', GAM.PredictFromArcGISRasters, u'ignoreOutOfRangeValues') … … 2115 2091 arcGISDisplayName=_(u'Output probability rasters')) 2116 2092 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') 2093 CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'templateRaster', GAM.BayesPredictFromArcGISRasters, u'templateRaster') 2120 2094 CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'resamplingTechniques', GAM.BayesPredictFromArcGISRasters, u'resamplingTechniques') 2121 2095 CopyArgumentMetadata(GAM.PredictFromArcGISRasters, u'ignoreOutOfRangeValues', GAM.BayesPredictFromArcGISRasters, u'ignoreOutOfRangeValues')
