Changeset 906

Show
Ignore:
Timestamp:
02/04/12 21:41:25 (16 months ago)
Author:
jjr8
Message:

* Added uniformLength parameter to Create Vectors tools.
* Added Create Vectors tools for HYCOM.

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

Legend:

Unmodified
Added
Removed
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/Aviso.py

    r899 r906  
    540540    def CreateVectorsAsArcGISFeatureClasses(cls, username, password, productName, temporalResolution, 
    541541                                            outputWorkspace, mode=u'add', featureClassNameExpressions=['%(Region)s', '%(DataSeries)s', '%(Satellites)s', '%(TemporalResolution)s', '%(Variable)s_uv_vectors', '%%Y', '%(DataSeries)s_%(Satellites)s_uv_vectors_%%Y%%j.shp'], 
    542                                             scaleFactor=500., 
     542                                            scaleFactor=500., uniformLength=False, 
    543543                                            rotationOffset=None, spatialExtent=None, linearUnit=u'Degrees', startDate=None, endDate=None, 
    544544                                            timeout=60, maxRetryTime=120, cacheDirectory=None): 
     
    575575                    queryableAttributeValues[u'Variable'] = queryableAttributeValues[u'Variable'].split('_')[0] 
    576576 
    577                     vectorShapefiles.append(ShapefileFromVectorComponentGrids(uSlices[i], vSlices[i], scaleFactor, queryableAttributes=queryableAttributes, queryableAttributeValues=queryableAttributeValues)) 
     577                    vectorShapefiles.append(ShapefileFromVectorComponentGrids(uSlices[i], vSlices[i], scaleFactor, uniformLength, queryableAttributes=queryableAttributes, queryableAttributeValues=queryableAttributeValues)) 
    578578 
    579579                # Import the ShapefileFromVectorComponentGrids into 
     
    21072107u"""Factor for scaling lines lengths. 
    21082108 
    2109 Use this parameter to scale the lines output by this tool to lengths 
    2110 that are visually appealing. If the lines are too short, they will 
    2111 resemble a grid of dots and you will not be able to discern the flow 
    2112 of the vector field. If the lines are too long, they will overlap each 
    2113 other and resemble a plate of spaghetti. 
     2109The length of each line is calculated by multiplying the magnitude of 
     2110the vector by this parameter. Use this parameter to scale the lines 
     2111output by this tool to lengths that are visually appealing. If the 
     2112lines are too short, they will resemble a grid of dots and you will 
     2113not be able to discern the flow of the vector field. If the lines are 
     2114too long, they will overlap each other and resemble a plate of 
     2115spaghetti. 
    21142116 
    21152117If the vectors all have about the same magnitude, then a good approach 
     
    21262128"""), 
    21272129    arcGISDisplayName=_(u'Scale factor'), 
     2130    arcGISCategory=_(u'Vector options')) 
     2131 
     2132AddArgumentMetadata(AvisoGriddedGeostrophicCurrents.CreateVectorsAsArcGISFeatureClasses, u'uniformLength', 
     2133    typeMetadata=BooleanTypeMetadata(), 
     2134    description=_( 
     2135u"""If False (the default) then the lengths of the lines are 
     2136determined by multiplying the magnitude of the vector by the Scale 
     2137Factor parameter. 
     2138 
     2139If True, all lines will have the same length, which will be determined 
     2140by multiplying the cell size of the Aviso grids (e.g. 37,000 meters) 
     2141by the the Scale Factor. Use this option when you want to the lines' 
     2142colors to indicate the magnitude of the vector, rather than the lines' 
     2143lengths. Start with a Scale Factor of 1 and increase it or decrease it 
     2144slightly to achieve the desired visual effect."""), 
     2145    arcGISDisplayName=_(u'Create all lines with the same length'), 
    21282146    arcGISCategory=_(u'Vector options')) 
    21292147 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/HYCOM.py

    r838 r906  
    720720 
    721721    @classmethod 
     722    def CreateCurrentVectorsAsArcGISFeatureClasses(cls, outputWorkspace, mode=u'add', featureClassNameExpressions=['uv_vectors', '%%Y', 'Depth_%(Depth)04.0fm', 'uv_vectors_%%%Y%%j_%(Depth)04.0fm.shp'], 
     723                                                   scaleFactor=4500, uniformLength=False, 
     724                                                   spatialExtent=None, linearUnit=u'Degrees', minDepth=None, maxDepth=None, startDate=None, endDate=None, 
     725                                                   timeout=600, maxRetryTime=None, cacheDirectory=None): 
     726        cls.__doc__.Obj.ValidateMethodInvocation() 
     727 
     728        # Create u and v component grids. 
     729 
     730        if startDate is not None: 
     731            startYear = startDate.year 
     732        else: 
     733            startYear = None 
     734        if endDate is not None: 
     735            endYear = endDate.year 
     736        else: 
     737            endYear = None 
     738         
     739        uGrid = HYCOMGOMl0044D(u'u', startYear=startYear, endYear=endYear, timeout=timeout, maxRetryTime=maxRetryTime, cacheDirectory=cacheDirectory) 
     740        try: 
     741            vGrid = HYCOMGOMl0044D(u'v', startYear=startYear, endYear=endYear, timeout=timeout, maxRetryTime=maxRetryTime, cacheDirectory=cacheDirectory) 
     742            try: 
     743                cls._LogWarning(_(u'The HYCOM OPeNDAP server often requires five to ten minutes to return the data required to create the first feature class. Please be patient. After the first one is created, the rest will go much faster. Because the first raster takes so long, the first status report may estimate an absurdly long time to completion. Please wait for the second status report, issued five minutes after the first one, for a better estimate. This tool cannot be cancelled until the first raster is created. If this tool fails with to a timeout error, increase the timeout value and try again.')) 
     744                 
     745                # If the caller requested a minimum depth that is 
     746                # within the range of the HYCOM layers, instantiate 
     747                # those grids. 
     748 
     749                from GeoEco.Datasets.Virtual import GridSliceCollection, SeafloorGrid 
     750 
     751                uSlices = [] 
     752                vSlices = [] 
     753 
     754                if minDepth is None or minDepth <= 5500.: 
     755                    clippedUGrid = cls._Clip(uGrid, spatialExtent, linearUnit, minDepth, maxDepth, startDate, endDate) 
     756                    uSlices.extend(GridSliceCollection(clippedUGrid, tQACoordType=u'center', zQACoordType=u'center').QueryDatasets()) 
     757 
     758                    clippedVGrid = cls._Clip(vGrid, spatialExtent, linearUnit, minDepth, maxDepth, startDate, endDate) 
     759                    vSlices.extend(GridSliceCollection(clippedVGrid, tQACoordType=u'center', zQACoordType=u'center').QueryDatasets()) 
     760 
     761                # If the caller requested a maximum depth that is 
     762                # greater than or equal to 20000., instantiate grids 
     763                # representing the values at the seafloor. 
     764 
     765                if minDepth == 20000. or maxDepth >= 20000.: 
     766                    clippedUGrid = cls._Clip(uGrid, spatialExtent, linearUnit, None, None, startDate, endDate) 
     767                    seafloorUGrid = SeafloorGrid(clippedUGrid, (QueryableAttribute(u'Depth', _(u'Depth'), FloatTypeMetadata()),), {u'Depth': 20000.}) 
     768                    uSlices.extend(GridSliceCollection(seafloorUGrid, tQACoordType=u'center').QueryDatasets()) 
     769 
     770                    clippedVGrid = cls._Clip(vGrid, spatialExtent, linearUnit, None, None, startDate, endDate) 
     771                    seafloorVGrid = SeafloorGrid(clippedVGrid, (QueryableAttribute(u'Depth', _(u'Depth'), FloatTypeMetadata()),), {u'Depth': 20000.}) 
     772                    vSlices.extend(GridSliceCollection(seafloorVGrid, tQACoordType=u'center').QueryDatasets()) 
     773 
     774                # Construct a list of 
     775                # ShapefileFromVectorComponentGrids from the slices. 
     776 
     777                from GeoEco.SpatialAnalysis.Lines import ShapefileFromVectorComponentGrids 
     778 
     779                queryableAttributes = tuple(uGrid.GetAllQueryableAttributes() + [QueryableAttribute(u'DateTime', _(u'Date'), DateTimeTypeMetadata()), QueryableAttribute(u'Depth', _(u'Depth'), FloatTypeMetadata())]) 
     780                vectorShapefiles = [] 
     781 
     782                for i in range(len(uSlices)): 
     783                    queryableAttributeValues = {} 
     784                    for qa in queryableAttributes: 
     785                        queryableAttributeValues[qa.Name] = uSlices[i].GetQueryableAttributeValue(qa.Name) 
     786 
     787                    vectorShapefiles.append(ShapefileFromVectorComponentGrids(uSlices[i], vSlices[i], scaleFactor, uniformLength, queryableAttributes=queryableAttributes, queryableAttributeValues=queryableAttributeValues)) 
     788 
     789                # Import the ShapefileFromVectorComponentGrids into 
     790                # the output workspace. 
     791 
     792                from GeoEco.Datasets.ArcGIS import ArcGISWorkspace, ArcGISTable 
     793 
     794                workspace = ArcGISWorkspace(outputWorkspace, ArcGISTable, pathCreationExpressions=featureClassNameExpressions, cacheTree=True, queryableAttributes=queryableAttributes) 
     795                workspace.ImportDatasets(vectorShapefiles, mode) 
     796 
     797                # Return successfully. 
     798                 
     799                return outputWorkspace 
     800 
     801            finally: 
     802                vGrid.Close() 
     803        finally: 
     804            uGrid.Close() 
     805 
     806    @classmethod 
    722807    def InterpolateAtArcGISPoints(cls, variableNames, 
    723808                                  points, valueFields, tField, zField=None, zValue=None, method=u'Nearest', where=None, noDataValue=None, 
     
    16551740 
    16561741    @classmethod 
     1742    def CreateCurrentVectorsAsArcGISFeatureClasses(cls, outputWorkspace, mode=u'add', featureClassNameExpressions=['uv_vectors', '%%Y', 'Depth_%(Depth)04.0fm', 'uv_vectors_%%%Y%%j_%(Depth)04.0fm.shp'], 
     1743                                                   scaleFactor=8900, uniformLength=False, 
     1744                                                   rotationOffset=None, extendYExtent=False, spatialExtent=None, linearUnit=u'Degrees', minDepth=None, maxDepth=None, startDate=None, endDate=None, 
     1745                                                   timeout=60, maxRetryTime=120, cacheDirectory=None): 
     1746        cls.__doc__.Obj.ValidateMethodInvocation() 
     1747 
     1748        # Create u and v component grids. 
     1749         
     1750        uGrid = HYCOMGLBa008Equatorial4D(u'u', extendYExtent=extendYExtent, timeout=timeout, maxRetryTime=maxRetryTime, cacheDirectory=cacheDirectory) 
     1751        try: 
     1752            vGrid = HYCOMGLBa008Equatorial4D(u'v', extendYExtent=extendYExtent, timeout=timeout, maxRetryTime=maxRetryTime, cacheDirectory=cacheDirectory) 
     1753            try: 
     1754                 
     1755                # If the caller requested a minimum depth that is 
     1756                # within the range of the HYCOM layers, instantiate 
     1757                # those grids. 
     1758 
     1759                from GeoEco.Datasets.Virtual import GridSliceCollection, SeafloorGrid 
     1760 
     1761                uSlices = [] 
     1762                vSlices = [] 
     1763 
     1764                if minDepth is None or minDepth <= 5500.: 
     1765                    clippedUGrid = cls._RotateAndClip(uGrid, rotationOffset, spatialExtent, linearUnit, minDepth, maxDepth, startDate, endDate) 
     1766                    uSlices.extend(GridSliceCollection(clippedUGrid, tQACoordType=u'center', zQACoordType=u'center').QueryDatasets()) 
     1767 
     1768                    clippedVGrid = cls._RotateAndClip(vGrid, rotationOffset, spatialExtent, linearUnit, minDepth, maxDepth, startDate, endDate) 
     1769                    vSlices.extend(GridSliceCollection(clippedVGrid, tQACoordType=u'center', zQACoordType=u'center').QueryDatasets()) 
     1770 
     1771                # If the caller requested a maximum depth that is 
     1772                # greater than or equal to 20000., instantiate grids 
     1773                # representing the values at the seafloor. 
     1774 
     1775                if minDepth == 20000. or maxDepth >= 20000.: 
     1776                    clippedUGrid = cls._RotateAndClip(uGrid, rotationOffset, spatialExtent, linearUnit, None, None, startDate, endDate) 
     1777                    seafloorUGrid = SeafloorGrid(clippedUGrid, (QueryableAttribute(u'Depth', _(u'Depth'), FloatTypeMetadata()),), {u'Depth': 20000.}) 
     1778                    uSlices.extend(GridSliceCollection(seafloorUGrid, tQACoordType=u'center').QueryDatasets()) 
     1779 
     1780                    clippedVGrid = cls._RotateAndClip(vGrid, rotationOffset, spatialExtent, linearUnit, None, None, startDate, endDate) 
     1781                    seafloorVGrid = SeafloorGrid(clippedVGrid, (QueryableAttribute(u'Depth', _(u'Depth'), FloatTypeMetadata()),), {u'Depth': 20000.}) 
     1782                    vSlices.extend(GridSliceCollection(seafloorVGrid, tQACoordType=u'center').QueryDatasets()) 
     1783 
     1784                # Construct a list of 
     1785                # ShapefileFromVectorComponentGrids from the slices. 
     1786 
     1787                from GeoEco.SpatialAnalysis.Lines import ShapefileFromVectorComponentGrids 
     1788 
     1789                queryableAttributes = tuple(uGrid.GetAllQueryableAttributes() + [QueryableAttribute(u'DateTime', _(u'Date'), DateTimeTypeMetadata()), QueryableAttribute(u'Depth', _(u'Depth'), FloatTypeMetadata())]) 
     1790                vectorShapefiles = [] 
     1791 
     1792                for i in range(len(uSlices)): 
     1793                    queryableAttributeValues = {} 
     1794                    for qa in queryableAttributes: 
     1795                        queryableAttributeValues[qa.Name] = uSlices[i].GetQueryableAttributeValue(qa.Name) 
     1796 
     1797                    vectorShapefiles.append(ShapefileFromVectorComponentGrids(uSlices[i], vSlices[i], scaleFactor, uniformLength, queryableAttributes=queryableAttributes, queryableAttributeValues=queryableAttributeValues)) 
     1798 
     1799                # Import the ShapefileFromVectorComponentGrids into 
     1800                # the output workspace. 
     1801 
     1802                from GeoEco.Datasets.ArcGIS import ArcGISWorkspace, ArcGISTable 
     1803 
     1804                workspace = ArcGISWorkspace(outputWorkspace, ArcGISTable, pathCreationExpressions=featureClassNameExpressions, cacheTree=True, queryableAttributes=queryableAttributes) 
     1805                workspace.ImportDatasets(vectorShapefiles, mode) 
     1806 
     1807                # Return successfully. 
     1808                 
     1809                return outputWorkspace 
     1810 
     1811            finally: 
     1812                vGrid.Close() 
     1813        finally: 
     1814            uGrid.Close() 
     1815 
     1816    @classmethod 
    16571817    def InterpolateAtArcGISPoints(cls, variableNames, 
    16581818                                  points, valueFields, tField, zField=None, zValue=None, method=u'Nearest', extendYExtent=False, where=None, noDataValue=None, 
     
    20692229    typeMetadata=EnvelopeTypeMetadata(canBeNone=True), 
    20702230    description=_( 
    2071 u"""Spatial extent of the output rasters, in the units specified by 
    2072 the Linear Units parameter. 
     2231u"""Spatial extent of the outputs, in the units specified by the 
     2232Linear Units parameter. 
    20732233 
    20742234If you do not specify a spatial extent, it will default to 
    2075 approximately 18 to 32 N, 98 to 76 W. The rasters can only be clipped 
     2235approximately 18 to 32 N, 98 to 76 W. The outputs can only be clipped 
    20762236in whole grid cells. The values you provide will be rounded off to the 
    20772237closest cell."""), 
     
    20942254    typeMetadata=DateTimeTypeMetadata(canBeNone=True), 
    20952255    description=_( 
    2096 u"""Start date for the rasters to create. 
    2097  
    2098 Rasters will be created for images that occur on or after the start 
     2256u"""Start date for the outputs to create. 
     2257 
     2258Outputs will be created for images that occur on or after the start 
    20992259date and on or before the end date. The HYCOM GOMl0.04 dataset 
    21002260provides a five-day forecast; its temporal extent ranges from 1 
     
    21092269    typeMetadata=DateTimeTypeMetadata(canBeNone=True), 
    21102270    description=_( 
    2111 u"""End date for the rasters to create. 
    2112  
    2113 Rasters will be created for images that occur on or after the start 
     2271u"""End date for the outputs to create. 
     2272 
     2273Outputs will be created for images that occur on or after the start 
    21142274date and on or before the end date. The HYCOM GOMl0.04 dataset 
    21152275provides a five-day forecast; its temporal extent ranges from 1 
     
    27452905    typeMetadata=FloatTypeMetadata(minValue=0.0, maxValue=20000.0, canBeNone=True), 
    27462906    description=_( 
    2747 u"""Minimum depth, in meters, for the rasters to create. 
    2748  
    2749 The value must be between 0 and 20000, inclusive. Rasters will be 
     2907u"""Minimum depth, in meters, for the outputs to create. 
     2908 
     2909The value must be between 0 and 20000, inclusive. Outputs will be 
    27502910created for images with depths that are greater than or equal to the 
    27512911minimum depth and less than or equal to the maximum depth. If you do 
     
    27552915seafloor. Use this value if you need an estimate of "bottom 
    27562916temperature" or the value of another variable at the seafloor. If this 
    2757 value is requested, an output raster will be created with a fake depth 
    2758 of 20000 meters. The cells of this raster will be assigned by stacking 
     2917value is requested, an output will be created with a fake depth of 
     291820000 meters. The cells of this output will be assigned by stacking 
    27592919all of the HYCOM depth layers and selecting the deepest cells that 
    27602920have data. Because HYCOM depth layers are spaced farther apart at 
     
    27622922location might be substantially shallower than the actual seafloor 
    27632923depth. Bear this in mind when considering the likely accuracy of the 
    2764 output raster."""), 
     2924output."""), 
    27652925    arcGISDisplayName=_(u'Minimum depth'), 
    27662926    arcGISCategory=_(u'Spatiotemporal extent')) 
     
    27692929    typeMetadata=FloatTypeMetadata(minValue=0.0, maxValue=20000.0, canBeNone=True), 
    27702930    description=_( 
    2771 u"""Maximum depth, in meters, for the rasters to create. 
    2772  
    2773 The value must be between 0 and 20000, inclusive. Rasters will be 
     2931u"""Maximum depth, in meters, for the outputs to create. 
     2932 
     2933The value must be between 0 and 20000, inclusive. Outputs will be 
    27742934created for images with depths that are greater than or equal to the 
    27752935minimum depth and less than or equal to the maximum depth. If you do 
     
    29153075 
    29163076CopyResultMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'updatedOutputWorkspace', HYCOMGOMl0044D.CreateClimatologicalArcGISRasters, u'updatedOutputWorkspace') 
     3077 
     3078# Public method: HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses 
     3079 
     3080AddMethodMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, 
     3081    shortDescription=_(u'Creates line feature classes representing the vectors of HYCOM GOMl0.04 currents.'), 
     3082    longDescription=_( 
     3083u"""The lines output by this tool are similar to those in a "quiver 
     3084plot". When displayed on a map, they can help visualize the direction 
     3085and speed of ocean currents. In ArcMap, select the "Arrow at End" 
     3086symbology. You may also want to reduce the line decoration (the arrow) 
     3087to a small size, such as 2.0. 
     3088 
     3089""") + _HYCOMGOMl004_LongDescription % {u'name': 'tool'} + _('\n\n**References**\n\n') + _HYCOMGOMl004_References, 
     3090    isExposedToPythonCallers=True, 
     3091    isExposedByCOM=True, 
     3092    isExposedAsArcGISTool=True, 
     3093    arcGISDisplayName=_(u'Create Current Vectors for HYCOM GOMl0.04'), 
     3094    arcGISToolCategory=_(u'Data Products\\HYCOM Consortium\\HYCOM + NCODA Gulf of Mexico 1/25 Degree Analysis (GLMl0.04)\\4D Variables'), 
     3095    dependencies=[ArcGISDependency(9, 1), PythonAggregatedModuleDependency('numpy')]) 
     3096 
     3097CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'cls', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'cls') 
     3098 
     3099AddArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'outputWorkspace', 
     3100    typeMetadata=ArcGISWorkspaceTypeMetadata(createParentDirectories=True), 
     3101    description=_( 
     3102u"""Directory or geodatabase to receive the feature classes. 
     3103 
     3104Unless you have a specific reason to store the feature classes in a 
     3105geodatabase, we recommend you store them in a directory because it 
     3106will be faster and allows them to be organized as a tree (of 
     3107shapefiles). If you do store the feature classes in a geodatabase, you 
     3108must change the Feature Class Name Expressions parameter; see below 
     3109for more information."""), 
     3110    arcGISDisplayName=_(u'Output workspace')) 
     3111 
     3112AddArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'mode', 
     3113    typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'Add', u'Replace'], makeLowercase=True), 
     3114    description=_( 
     3115u"""Overwrite mode, one of: 
     3116 
     3117* Add - create feature classes that do not exist and skip those that 
     3118  already exist. This is the default. 
     3119 
     3120* Replace - create feature classes that do not exist and overwrite 
     3121  those that already exist. 
     3122 
     3123The ArcGIS Overwrite Outputs geoprocessing setting has no effect on 
     3124this tool. If 'Replace' is selected the feature classes will be 
     3125overwritten, regardless of the ArcGIS Overwrite Outputs setting."""), 
     3126    arcGISDisplayName=_(u'Overwrite mode')) 
     3127 
     3128AddArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'featureClassNameExpressions', 
     3129    typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(), minLength=1), 
     3130    description=_( 
     3131u"""List of expressions specifying how the output feature classes 
     3132should be named. 
     3133 
     3134The default expression assumes the output workspace is a directory and 
     3135creates shapefiles in a tree structure with levels for the year and 
     3136depth. 
     3137 
     3138If the output workspace is a geodatabase, you should provide only one 
     3139or two expressions. If you provide one expression, it specifies the 
     3140feature class name. If you provide two, the first one specifies the 
     3141feature dataset name and the second specifies the feature class name. 
     3142 
     3143Each expression may contain any sequence of characters permitted by 
     3144the output workspace. Each expression may optionally contain one or 
     3145more of the following case-sensitive codes. The tool replaces the 
     3146codes with appropriate values when creating each feature class: 
     3147 
     3148* %(Depth)f - depth of the output feature class. The f may be preceded 
     3149  by Python's string formatting codes. Please see the Python 
     3150  documentation for more information. 
     3151 
     3152* %%Y - four-digit year of the output feature class. 
     3153 
     3154* %%m - two-digit month of the output feature class. 
     3155 
     3156* %%d - two-digit day of the month of the output feature class. 
     3157 
     3158* %%j - three-digit day of the year of the output feature class. 
     3159"""), 
     3160    arcGISDisplayName=_(u'Feature class name expressions')) 
     3161 
     3162AddArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'scaleFactor', 
     3163    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.0), 
     3164    description=_( 
     3165u"""Factor for scaling lines lengths. 
     3166 
     3167The length of each line is calculated by multiplying the magnitude of 
     3168the vector by this parameter. Use this parameter to scale the lines 
     3169output by this tool to lengths that are visually appealing. If the 
     3170lines are too short, they will resemble a grid of dots and you will 
     3171not be able to discern the flow of the vector field. If the lines are 
     3172too long, they will overlap each other and resemble a plate of 
     3173spaghetti. 
     3174 
     3175If the vectors all have about the same magnitude, then a good approach 
     3176is to scale the lines so that the longest one is about as long as the 
     3177raster cell size. But if there are a few very long vectors, then you 
     3178may prefer to scale the lines so that the average-length vector is as 
     3179long as the raster cell size. 
     3180 
     3181For HYCOM GOMl0.04 currents, the grid cell size is about 4500 m and 
     3182currents are given in m/s. So, if the maximum (or mean) velocity in 
     3183your region of interest is about 0.75 m/s: 
     3184 
     3185    scale factor = 4500 / 0.75 = 6000 
     3186"""), 
     3187    arcGISDisplayName=_(u'Scale factor'), 
     3188    arcGISCategory=_(u'Vector options')) 
     3189 
     3190AddArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'uniformLength', 
     3191    typeMetadata=BooleanTypeMetadata(), 
     3192    description=_( 
     3193u"""If False (the default) then the lengths of the lines are 
     3194determined by multiplying the magnitude of the vector by the Scale 
     3195Factor parameter. 
     3196 
     3197If True, all lines will have the same length, which will be determined 
     3198by multiplying the cell size of the HYCOM grids by the the Scale 
     3199Factor. Use this option when you want to the lines' colors to indicate 
     3200the magnitude of the vector, rather than the lines' lengths. Start 
     3201with a Scale Factor of 1 and increase it or decrease it slightly to 
     3202achieve the desired visual effect."""), 
     3203    arcGISDisplayName=_(u'Create all lines with the same length'), 
     3204    arcGISCategory=_(u'Vector options')) 
     3205 
     3206CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'spatialExtent', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'spatialExtent') 
     3207CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'linearUnit', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'linearUnit') 
     3208CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'minDepth', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'minDepth') 
     3209CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'maxDepth', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'maxDepth') 
     3210CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'startDate', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'startDate') 
     3211CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'endDate', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'endDate') 
     3212CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'timeout', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'timeout') 
     3213CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'maxRetryTime', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'maxRetryTime') 
     3214CopyArgumentMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'cacheDirectory', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'cacheDirectory') 
     3215 
     3216CopyResultMetadata(HYCOMGOMl0044D.CreateArcGISRasters, u'updatedOutputWorkspace', HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'updatedOutputWorkspace') 
    29173217 
    29183218# Public method: HYCOMGOMl0044D.InterpolateAtArcGISPoints 
     
    36163916    typeMetadata=DateTimeTypeMetadata(canBeNone=True), 
    36173917    description=_( 
    3618 u"""Start date for the rasters to create. 
    3619  
    3620 Rasters will be created for images that occur on or after the start 
     3918u"""Start date for the outputs to create. 
     3919 
     3920Outputs will be created for images that occur on or after the start 
    36213921date and on or before the end date. The HYCOM GOMa0.08 dataset 
    36223922provides a five-day forecast; its temporal extent ranges from 11 
     
    36313931    typeMetadata=DateTimeTypeMetadata(canBeNone=True), 
    36323932    description=_( 
    3633 u"""End date for the rasters to create. 
    3634  
    3635 Rasters will be created for images that occur on or after the start 
     3933u"""End date for the outputs to create. 
     3934 
     3935Outputs will be created for images that occur on or after the start 
    36363936date and on or before the end date. The HYCOM GLBa0.08 dataset 
    36373937provides a five-day forecast; its temporal extent ranges from 11 
     
    39084208CopyResultMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'updatedOutputWorkspace', HYCOMGLBa008Equatorial4D.CreateClimatologicalArcGISRasters, u'updatedOutputWorkspace') 
    39094209 
     4210# Public method: HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses 
     4211 
     4212AddMethodMetadata(HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, 
     4213    shortDescription=_(u'Creates line feature classes representing the current vectors for the equatorial (Mercator) region of the HYCOM GLBa0.08 dataset.'), 
     4214    longDescription=_( 
     4215u"""The lines output by this tool are similar to those in a "quiver 
     4216plot". When displayed on a map, they can help visualize the direction 
     4217and speed of ocean currents. In ArcMap, select the "Arrow at End" 
     4218symbology. You may also want to reduce the line decoration (the arrow) 
     4219to a small size, such as 2.0. 
     4220 
     4221""") + _HYCOMGLBa008Equatorial_LongDescription % {u'name': 'tool'} + _('\n\n**References**\n\n') + _HYCOMGLBa008Equatorial_References, 
     4222    isExposedToPythonCallers=True, 
     4223    isExposedByCOM=True, 
     4224    isExposedAsArcGISTool=True, 
     4225    arcGISDisplayName=_(u'Create Current Vectors for HYCOM GLBa0.08 Equatorial Region'), 
     4226    arcGISToolCategory=_(u'Data Products\\HYCOM Consortium\\HYCOM + NCODA Global 1/12 Degree Analysis (GLBa0.08)\\Equatorial Region (47 N to 66 S)\\4D Variables'), 
     4227    dependencies=[ArcGISDependency(9, 1), PythonAggregatedModuleDependency('numpy')]) 
     4228 
     4229CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'cls', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'cls') 
     4230 
     4231CopyArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'outputWorkspace', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'outputWorkspace') 
     4232CopyArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'mode', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'mode') 
     4233CopyArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'featureClassNameExpressions', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'featureClassNameExpressions') 
     4234 
     4235AddArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'scaleFactor', 
     4236    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.0), 
     4237    description=_( 
     4238u"""Factor for scaling lines lengths. 
     4239 
     4240The length of each line is calculated by multiplying the magnitude of 
     4241the vector by this parameter. Use this parameter to scale the lines 
     4242output by this tool to lengths that are visually appealing. If the 
     4243lines are too short, they will resemble a grid of dots and you will 
     4244not be able to discern the flow of the vector field. If the lines are 
     4245too long, they will overlap each other and resemble a plate of 
     4246spaghetti. 
     4247 
     4248If the vectors all have about the same magnitude, then a good approach 
     4249is to scale the lines so that the longest one is about as long as the 
     4250raster cell size. But if there are a few very long vectors, then you 
     4251may prefer to scale the lines so that the average-length vector is as 
     4252long as the raster cell size. 
     4253 
     4254For HYCOM GLBa0.08 currents, the grid cell size is about 8900 m and 
     4255currents are given in m/s. So, if the maximum (or mean) velocity in 
     4256your region of interest is about 0.75 m/s: 
     4257 
     4258    scale factor = 8900 / 0.75 = 11866.666666 
     4259"""), 
     4260    arcGISDisplayName=_(u'Scale factor'), 
     4261    arcGISCategory=_(u'Vector options')) 
     4262 
     4263CopyArgumentMetadata(HYCOMGOMl0044D.CreateCurrentVectorsAsArcGISFeatureClasses, u'uniformLength', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'uniformLength') 
     4264 
     4265CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'rotationOffset', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'rotationOffset') 
     4266CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'extendYExtent', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'extendYExtent') 
     4267CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'spatialExtent', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'spatialExtent') 
     4268CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'linearUnit', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'linearUnit') 
     4269CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'minDepth', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'minDepth') 
     4270CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'maxDepth', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'maxDepth') 
     4271CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'startDate', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'startDate') 
     4272CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'endDate', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'endDate') 
     4273CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'timeout', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'timeout') 
     4274CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'maxRetryTime', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'maxRetryTime') 
     4275CopyArgumentMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'cacheDirectory', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'cacheDirectory') 
     4276 
     4277CopyResultMetadata(HYCOMGLBa008Equatorial4D.CreateArcGISRasters, u'updatedOutputWorkspace', HYCOMGLBa008Equatorial4D.CreateCurrentVectorsAsArcGISFeatureClasses, u'updatedOutputWorkspace') 
     4278 
    39104279# Public method: HYCOMGLBa008Equatorial4D.InterpolateAtArcGISPoints 
    39114280 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/DataProducts/NOAA/OSCAR.py

    r862 r906  
    266266    @classmethod 
    267267    def CreateVectorsAsArcGISFeatureClasses(cls, outputWorkspace, mode=u'add', featureClassNameExpressions=['uv_vectors', '%%Y', 'uv_vectors_%%Y%%j.shp'], 
    268                                             scaleFactor=0.444, 
     268                                            scaleFactor=0.444, uniformLength=False, 
    269269                                            rotationOffset=None, spatialExtent=None, startDate=None, endDate=None, 
    270270                                            timeout=60, maxRetryTime=120, cacheDirectory=None): 
     
    300300                        queryableAttributeValues[qa.Name] = uSlices[i].GetQueryableAttributeValue(qa.Name) 
    301301 
    302                     vectorShapefiles.append(ShapefileFromVectorComponentGrids(uSlices[i], vSlices[i], scaleFactor, queryableAttributes=queryableAttributes, queryableAttributeValues=queryableAttributeValues)) 
     302                    vectorShapefiles.append(ShapefileFromVectorComponentGrids(uSlices[i], vSlices[i], scaleFactor, uniformLength, queryableAttributes=queryableAttributes, queryableAttributeValues=queryableAttributeValues)) 
    303303 
    304304                # Import the ShapefileFromVectorComponentGrids into 
     
    973973    arcGISCategory=_(u'Vector options')) 
    974974 
     975AddArgumentMetadata(OSCAR5DayThirdDegreeCurrents.CreateVectorsAsArcGISFeatureClasses, u'uniformLength', 
     976    typeMetadata=BooleanTypeMetadata(), 
     977    description=_( 
     978u"""If False (the default) then the lengths of the lines are 
     979determined by multiplying the magnitude of the vector by the Scale 
     980Factor parameter. 
     981 
     982If True, all lines will have the same length, which will be determined 
     983by multiplying the cell size of the OSCAR grids (i.e. 1/3 degree) by 
     984the the Scale Factor. Use this option when you want to the lines' 
     985colors to indicate the magnitude of the vector, rather than the lines' 
     986lengths. Start with a Scale Factor of 1 and increase it or decrease it 
     987slightly to achieve the desired visual effect."""), 
     988    arcGISDisplayName=_(u'Create all lines with the same length'), 
     989    arcGISCategory=_(u'Vector options')) 
     990 
    975991CopyArgumentMetadata(OSCAR5DayThirdDegreeCurrents.CreateArcGISRasters, u'rotationOffset', OSCAR5DayThirdDegreeCurrents.CreateVectorsAsArcGISFeatureClasses, u'rotationOffset') 
    976992CopyArgumentMetadata(OSCAR5DayThirdDegreeCurrents.CreateArcGISRasters, u'spatialExtent', OSCAR5DayThirdDegreeCurrents.CreateVectorsAsArcGISFeatureClasses, u'spatialExtent') 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/SpatialAnalysis/Lines.py

    r835 r906  
    3232 
    3333    @classmethod 
    34     def ShapefileFromVectorComponentGrids(cls, xGrid, yGrid, shapefile, scaleFactor, overwriteExisting=False): 
     34    def ShapefileFromVectorComponentGrids(cls, xGrid, yGrid, shapefile, scaleFactor, uniformLength, overwriteExisting=False): 
    3535        cls.__doc__.Obj.ValidateMethodInvocation() 
    3636 
     
    112112                '-s', repr(scaleFactor)] 
    113113 
     114        if uniformLength: 
     115            args.append('-u') 
     116 
    114117        oldLogInfoAsDebug = Logger.GetLogInfoAsDebug() 
    115118        Logger.SetLogInfoAsDebug(True) 
     
    139142 
    140143    @classmethod 
    141     def FromVectorComponentRasters(cls, xRaster, yRaster, lines, scaleFactor, overwriteExisting=False): 
     144    def FromVectorComponentRasters(cls, xRaster, yRaster, lines, scaleFactor, uniformLength=False, overwriteExisting=False): 
    142145        cls.__doc__.Obj.ValidateMethodInvocation() 
    143146        try: 
     
    153156 
    154157            if os.path.splitext(lines)[1].lower() == '.shp': 
    155                 Lines.ShapefileFromVectorComponentGrids(xGrid, yGrid, lines, scaleFactor, overwriteExisting=overwriteExisting) 
     158                Lines.ShapefileFromVectorComponentGrids(xGrid, yGrid, lines, scaleFactor, uniformLength, overwriteExisting=overwriteExisting) 
    156159 
    157160            # Otherwise, create a shapefile in a temporary directory and 
     
    163166 
    164167                shapefile = os.path.join(tempDir.Path, 'vectors.shp') 
    165                 Lines.ShapefileFromVectorComponentGrids(xGrid, yGrid, shapefile, scaleFactor) 
     168                Lines.ShapefileFromVectorComponentGrids(xGrid, yGrid, shapefile, scaleFactor, uniformLength) 
    166169 
    167170                gp = GeoprocessorManager.GetWrappedGeoprocessor() 
     
    190193    __doc__ = DynamicDocString() 
    191194 
    192     def __init__(self, xGrid, yGrid, scaleFactor, parentCollection=None, queryableAttributes=None, queryableAttributeValues=None): 
     195    def __init__(self, xGrid, yGrid, scaleFactor, uniformLength=False, parentCollection=None, queryableAttributes=None, queryableAttributeValues=None): 
    193196 
    194197        # Initialize our properties. 
     
    197200        self._YGrid = yGrid 
    198201        self._ScaleFactor = scaleFactor 
     202        self._UniformLength = uniformLength 
    199203        self._TempDir = None 
    200204        self._DisplayName = _(u'vectors for x components = %(dnx)s, y components = %(dny)s') % {u'dnx': xGrid, u'dny': yGrid} 
     
    229233            try: 
    230234                self._TempDir = self._CreateTempDirectory() 
    231                 Lines.ShapefileFromVectorComponentGrids(self._XGrid, self._YGrid, os.path.join(self._TempDir, 'Vectors.shp'), self._ScaleFactor) 
     235                Lines.ShapefileFromVectorComponentGrids(self._XGrid, self._YGrid, os.path.join(self._TempDir, 'Vectors.shp'), self._ScaleFactor, self._UniformLength) 
    232236            except: 
    233237                self._Close() 
     
    319323u"""Factor for scaling lines lengths. 
    320324 
    321 Use this parameter to scale the lines output by this tool to lengths 
    322 that are visually appealing. If the lines are too short, they will 
    323 resemble a grid of dots and you will not be able to discern the flow 
    324 of the vector field. If the lines are too long, they will overlap each 
    325 other and resemble a plate of spaghetti. 
     325The length of each line is calculated by multiplying the magnitude of 
     326the vector by this parameter. Use this parameter to scale the lines 
     327output by this tool to lengths that are visually appealing. If the 
     328lines are too short, they will resemble a grid of dots and you will 
     329not be able to discern the flow of the vector field. If the lines are 
     330too long, they will overlap each other and resemble a plate of 
     331spaghetti. 
    326332 
    327333If the vectors all have about the same magnitude, then a good approach 
     
    345351Use a scale factor of 1 to indicate that the lines should not be 
    346352scaled.""")) 
     353 
     354AddArgumentMetadata(Lines.ShapefileFromVectorComponentGrids, u'uniformLength', 
     355    typeMetadata=BooleanTypeMetadata(), 
     356    description=_( 
     357u"""If False (the default) then the lengths of the lines are 
     358determined by multiplying the magnitude of the vector by the Scale 
     359Factor parameter. 
     360 
     361If True, all lines will have the same length, which will be determined 
     362by multiplying the cell size of the input grids by the the Scale 
     363Factor. Use this option when you want to the lines' colors to indicate 
     364the magnitude of the vector, rather than the lines' lengths. Start 
     365with a Scale Factor of 1 and increase it or decrease it slightly to 
     366achieve the desired visual effect.""")) 
    347367 
    348368AddArgumentMetadata(Lines.ShapefileFromVectorComponentGrids, u'overwriteExisting', 
     
    430450    arcGISDisplayName=_(u'Scale factor')) 
    431451 
     452AddArgumentMetadata(ArcGISLines.FromVectorComponentRasters, u'uniformLength', 
     453    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.0), 
     454    description=Lines.ShapefileFromVectorComponentGrids.__doc__.Obj.Arguments[5].Description, 
     455    arcGISDisplayName=_(u'Create all lines with the same length')) 
     456 
    432457AddArgumentMetadata(ArcGISLines.FromVectorComponentRasters, u'overwriteExisting', 
    433458    typeMetadata=BooleanTypeMetadata(), 
     
    610635  right, 90 is up, -90 is down, and 180 is left. 
    611636""")], 
    612     constantParamNames=[u'scaleFactor'], 
     637    constantParamNames=[u'scaleFactor', u'uniformLength'], 
    613638    processListMethodName=u'FromVectorComponentRastersInList', 
    614639    processListMethodShortDescription=_(u'Given lists of rasters representing the x and y components of vector fields, such as the u and v rasters for ocean currents, this tool creates feature classes of lines representing the vectors, similar to a "quiver plot".'),