root/MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Exploratory.py @ 947

Revision 947, 42.9 KB (checked in by jjr8, 14 months ago)

Fixed #538: When emf is selected as the output format, Fit GLM, Fit GAM, Plot ROC, and other tools fail with ValueError?: The file C:\Temp\GeoEcoTemp?_Matt\tmphgchvj\output_term01.png, specified for the sourceFile parameter, does not exist. Please specify an existing file.

Line 
1# Exploratory.py - Provides methods for exploratory statistics.
2#
3# Copyright (C) 2007 Jason J. Roberts and Ben D. Best
4#
5# This program is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License
7# as published by the Free Software Foundation; either version 2
8# of the License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License (available in the file LICENSE.TXT)
14# for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
20import os.path
21import re
22import sys
23
24from GeoEco.DatabaseAccess.ArcGIS import ArcGIS91DatabaseConnection
25from GeoEco.DataManagement.Directories import TemporaryDirectory
26from GeoEco.DataManagement.Files import File
27from GeoEco.DynamicDocString import DynamicDocString
28from GeoEco.Internationalization import _
29from GeoEco.Logging import Logger
30from GeoEco.R import R
31
32
33class RExploratoryPlots(object):
34    __doc__ = DynamicDocString()
35
36    @classmethod
37    def ScatterplotMatrixForArcGISTable(cls, table, fields=None, transforms=None, where=None, diagonal=u'Histogram', lower=u'Smooth', upper=u'Correlation',
38                                        xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None,
39                                        outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False):
40        cls.__doc__.Obj.ValidateMethodInvocation()
41
42        # Perform additional validation.
43
44        if outputFile is not None and not outputFile.lower().endswith('.png') and not outputFile.lower().endswith('.emf'):
45            Logger.RaiseException(ValueError(_(u'The output file %(f)s has an invalid extension. It must have the extension .png or .emf.') % {u'f': outputFile}))
46
47        # If the caller requested emf format for the plot file,
48        # convert the width and height from thousands of an inch to
49        # inches.
50
51        if outputFile is not None and outputFile.lower().endswith(u'.emf'):
52            width = width / 1000
53            height = height / 1000
54
55        # Load the data frame into a temporary data frame.
56       
57        r = R.GetInterpreter()
58        transformsName = R.GetUniqueVariableName()
59        dataFrameName = R.GetUniqueVariableName()
60        R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName)
61
62        # Create the plot.
63       
64        try:
65            if r('length(%s)' % dataFrameName) <= 0:
66                if where is not None:
67                    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}))
68                else:
69                    Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table}))
70
71            if transforms is not None and len(transforms) > 0:
72                if len(transforms) > len(fields):
73                    transforms = transforms[:len(fields)]
74                r[transformsName] = dict(zip(fields[:len(transforms)], transforms))
75            else:
76                r('%s <- NULL' % transformsName)
77
78            R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ScatterplotMatrixForDataframe.r'), False)
79            if outputFile is None:
80                r('ScatterplotMatrix(%s, transforms=%s, .diag="%s", lower="%s", upper="%s")' % (dataFrameName, transformsName, str(diagonal), str(lower), str(upper)))
81            else:
82                tempDir = TemporaryDirectory()
83                tempOutputFile = os.path.join(tempDir.Path, u'plot' + os.path.splitext(outputFile)[1])
84                Logger.Info(_(u'Writing plot to %(file)s...') % {u'file': outputFile})
85                r('ScatterplotMatrixToFile("%s", %s, transforms=%s, .diag="%s", lower="%s", upper="%s", res=%f, width=%f, height=%f, pointsize=%f, bg="%s")' % (tempOutputFile.replace(u'\\', u'/'), dataFrameName, transformsName, str(diagonal), str(lower), str(upper), res, width, height, pointSize, bg))
86                File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting)
87
88        # Delete the data frame.
89       
90        finally:
91            r('if (exists("%s")) rm("%s")' % (transformsName, transformsName))
92            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName))
93
94    @classmethod
95    def DensityHistogramForArcGISField(cls, table, densityField, transform=None, categoryField=None, where=None, legend=None,
96                                       outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False):
97        cls.__doc__.Obj.ValidateMethodInvocation()
98
99        # Perform additional validation.
100
101        if outputFile is not None and not outputFile.lower().endswith('.png') and not outputFile.lower().endswith('.emf'):
102            Logger.RaiseException(ValueError(_(u'The output file %(f)s has an invalid extension. It must have the extension .png or .emf.') % {u'f': outputFile}))
103
104        # If the caller requested emf format for the plot file,
105        # convert the width and height from thousands of an inch to
106        # inches.
107
108        if outputFile is not None and outputFile.lower().endswith(u'.emf'):
109            width = width / 1000
110            height = height / 1000
111
112        # Load the data frame into a temporary variable.
113       
114        r = R.GetInterpreter()
115        dataFrameName = R.GetUniqueVariableName()
116        if categoryField is None:
117            R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=[densityField])
118        else:
119            R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=[densityField, categoryField])
120
121        # Create the plot.
122       
123        try:
124            if r('length(%s)' % dataFrameName) <= 0:
125                if where is not None:
126                    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}))
127                else:
128                    Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table}))
129           
130            R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'DensityHistogramForDataframe.r'), False)
131
132            if transform is None:
133                transform = 'NULL'
134            else:
135                transform = '"' + transform.replace('"', '\\"') + '"'
136
137            if categoryField is None:
138                categoryField = 'NULL'
139            else:
140                categoryField = '"' + categoryField + '"'
141
142            if legend is None:
143                legend = 'NULL'
144            else:
145                legend = '"' + legend + '"'
146           
147            if outputFile is None:
148                r('DensityHistogram(%s, densityField="%s", transform=%s, categoryField=%s, .legend=%s)' % (dataFrameName, densityField, transform, categoryField, legend))
149            else:
150                tempDir = TemporaryDirectory()
151                tempOutputFile = os.path.join(tempDir.Path, u'plot' + os.path.splitext(outputFile)[1])
152                Logger.Info(_(u'Writing density plot to %(file)s...') % {u'file': outputFile})
153                r('DensityHistogramToFile("%s", %s, densityField="%s", transform=%s, categoryField=%s, .legend=%s, res=%f, width=%f, height=%f, pointsize=%f, bg="%s")' % (tempOutputFile.replace(u'\\', u'/'), dataFrameName, densityField, transform, categoryField, legend, res, width, height, pointSize, bg))
154                File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting)
155
156        # Delete the data frame.
157       
158        finally:
159            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName))
160
161    @classmethod
162    def DensityHistogramForArcGISPointsCoordinates(cls, pointFeatures, coordinate, coordinateName=None, transform=None, categoryField=None, where=None, legend=None,
163                                                   outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False):
164        cls.__doc__.Obj.ValidateMethodInvocation()
165
166        # Perform additional validation.
167
168        if outputFile is not None and not outputFile.lower().endswith('.png') and not outputFile.lower().endswith('.emf'):
169            Logger.RaiseException(ValueError(_(u'The output file %(f)s has an invalid extension. It must have the extension .png or .emf.') % {u'f': outputFile}))
170
171        # If the caller requested emf format for the plot file,
172        # convert the width and height from thousands of an inch to
173        # inches.
174
175        if outputFile is not None and outputFile.lower().endswith(u'.emf'):
176            width = width / 1000
177            height = height / 1000
178
179        # Load the data frame into a temporary variable.
180
181        if coordinateName is None:
182            coordinateName = coordinate
183           
184        if coordinate == u'x':
185            xColumnName = coordinateName
186        else:
187            xColumnName = None
188           
189        if coordinate == u'y':
190            yColumnName = coordinateName
191        else:
192            yColumnName = None
193           
194        if coordinate == u'z':
195            zColumnName = coordinateName
196        else:
197            zColumnName = None
198           
199        if coordinate == u'm':
200            mColumnName = coordinateName
201        else:
202            mColumnName = None
203       
204        r = R.GetInterpreter()
205        dataFrameName = R.GetUniqueVariableName()
206        if categoryField is None:
207            R.LoadDataFrameFromArcGISTable(pointFeatures, dataFrameName, where=where, fields=[], xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName)
208        else:
209            R.LoadDataFrameFromArcGISTable(pointFeatures, dataFrameName, where=where, fields=[categoryField], xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName)
210
211        # Create the plot.
212       
213        try:
214            if r('length(%s)' % dataFrameName) <= 0:
215                if where is not None:
216                    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}))
217                else:
218                    Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table}))
219           
220            R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'DensityHistogramForDataframe.r'), False)
221
222            if transform is None:
223                transform = 'NULL'
224            else:
225                transform = '"' + transform.replace('"', '\\"') + '"'
226
227            if categoryField is None:
228                categoryField = 'NULL'
229            else:
230                categoryField = '"' + categoryField + '"'
231
232            if legend is None:
233                legend = 'NULL'
234            else:
235                legend = '"' + legend + '"'
236
237            if outputFile is None:
238                r('DensityHistogram(%s, densityField="%s", transform=%s, categoryField=%s, .legend=%s)' % (dataFrameName, coordinateName, transform, categoryField, legend))
239            else:
240                tempDir = TemporaryDirectory()
241                tempOutputFile = os.path.join(tempDir.Path, u'plot' + os.path.splitext(outputFile)[1])
242                Logger.Info(_(u'Writing density plot to %(file)s...') % {u'file': outputFile})
243                r('DensityHistogramToFile("%s", %s, densityField="%s", transform=%s, categoryField=%s, .legend=%s, res=%f, width=%f, height=%f, pointsize=%f, bg="%s")' % (tempOutputFile.replace(u'\\', u'/'), dataFrameName, coordinateName, transform, categoryField, legend, res, width, height, pointSize, bg))
244                File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting)
245
246        # Delete the data frame.
247       
248        finally:
249            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName))
250
251    @classmethod
252    def ClevelandPlotForArcGISTable(cls, table, fields=None, transforms=None, orderByField=None, where=None,
253                                    xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None,
254                                    outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False):
255        cls.__doc__.Obj.ValidateMethodInvocation()
256
257        # If the caller requested emf format for the plot file,
258        # convert the width and height from thousands of an inch to
259        # inches.
260
261        if outputFile is not None and outputFile.lower().endswith(u'.emf'):
262            width = width / 1000
263            height = height / 1000
264
265        # Load the data frame into a temporary data frame.
266
267        if orderByField is not None:
268            if fields is None:
269                fields = []
270            if orderByField not in fields:
271                fields.append(orderByField)
272       
273        r = R.GetInterpreter()
274        transformsName = R.GetUniqueVariableName()
275        dataFrameName = R.GetUniqueVariableName()
276        R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName)
277
278        # Create the plot.
279       
280        try:
281            if r('length(%s)' % dataFrameName) <= 0:
282                if where is not None:
283                    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}))
284                else:
285                    Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table}))
286
287            if transforms is not None and len(transforms) > 0:
288                if len(transforms) > len(fields):
289                    transforms = transforms[:len(fields)]
290                r[transformsName] = dict(zip(fields[:len(transforms)], transforms))
291            else:
292                r('%s <- NULL' % transformsName)
293
294            if orderByField is not None:
295                r('%s <- %s[order(%s$%s),]' % (dataFrameName, dataFrameName, dataFrameName, orderByField))
296
297            R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ClevelandPlotForDataframe.r'), False)
298            if outputFile is None:
299                r('ClevelandPlot(%s, transforms=%s)' % (dataFrameName, transformsName))
300            else:
301                Logger.Info(_(u'Writing plot to %(file)s...') % {u'file': outputFile})
302                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))
303
304        # Delete the data frame.
305       
306        finally:
307            r('if (exists("%s")) rm("%s")' % (transformsName, transformsName))
308            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName))
309
310
311###############################################################################
312# Metadata: module
313###############################################################################
314
315from GeoEco.ArcGIS import ArcGISDependency
316from GeoEco.DatabaseAccess.ArcGIS import ArcGIS91SelectCursor
317from GeoEco.Dependencies import PythonModuleDependency
318from GeoEco.R import RDependency
319from GeoEco.Metadata import *
320from GeoEco.Types import *
321
322AddModuleMetadata(shortDescription=_(u'Provides methods for exploratory statistics.'))
323
324###############################################################################
325# Metadata: RExploratoryPlots class
326###############################################################################
327
328AddClassMetadata(RExploratoryPlots,
329    shortDescription=_(u'Provides methods for creating exploratory statistical plots using R.'),
330    isExposedAsCOMServer=True,
331    comIID=u'{0F60EA9E-42BB-4696-B8BA-092FA6965374}',
332    comCLSID=u'{F8EF1F8A-7231-449C-AC22-711517E3C542}')
333
334# Public method: RExploratoryPlots.ScatterplotMatrixForArcGISTable
335
336AddMethodMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable,
337    shortDescription=_(u'Creates a matrix of scatterplots for a table using the R pairs function.'),
338    isExposedToPythonCallers=True,
339    isExposedByCOM=True,
340    isExposedAsArcGISTool=True,
341    arcGISDisplayName=_(u'Scatterplot Matrix for Table'),
342    arcGISToolCategory=_(u'Statistics\\Explore Data'),
343    dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)])
344
345AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls',
346    typeMetadata=ClassOrClassInstanceTypeMetadata(cls=RExploratoryPlots),
347    description=_(u'%s class or an instance of it.') % RExploratoryPlots.__name__)
348
349AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table',
350    typeMetadata=ArcGISTableViewTypeMetadata(mustExist=True),
351    description=_(
352u"""Table, table view, feature class, or feature layer for which the
353plot should be generated."""),
354    arcGISDisplayName=_(u'Table'))
355
356AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields',
357    typeMetadata=ListTypeMetadata(ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE']), canBeNone=True),
358    description=_(
359u"""Fields of the table to include in the plot.
360
361You may only specify fields with the data types SHORT, LONG, FLOAT,
362DOUBLE, TEXT, or DATE. If you do not provide a list of fields, all of
363the fields having those data types will be included in the matrix.
364
365The ArcGIS LONG value -2147483648 cannot be loaded into R because it
366is used internally by R to represent the special value NA ("not
367available"). If one of the fields contains this integer value, an
368error will be reported."""),
369    arcGISParameterDependencies=[u'table'],
370    arcGISDisplayName=_(u'Fields'))
371
372AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms',
373    typeMetadata=ListTypeMetadata(elementType=UnicodeStringTypeMetadata(minLength=1), canBeNone=True),
374    description=_(
375u"""Transformations to perform on the fields before creating the plot.
376
377Use this parameter when the distribution of one or more fields is too
378skewed to yield an informative plot. This parameter is a list where
379each entry corresponds to a field. Each entry is an R expression that
380operates on the vector d that represents the original values of that
381field. For example, the following expressions perform natural
382logarithm, base 10 logarithm, square root, and cube root transforms,
383respectively::
384
385    log(d)
386    log10(d)
387    d^(1/2)
388    d^(1/3)
389
390The expression may be as complicated as you want, so long as it
391conforms to R syntax, operates only on the variable d, and yields a
392vector of the same length as the input data. For example, if the input
393data represent water depth expressed as a negative number (e.g. -100
394is 100 meters below the surface), and you want to transform the data
395using a base 10 logarithm, you must first take the absolute value of
396depth::
397
398    log10(abs(d))
399
400When you do not want to transform a field but are forced to provide a
401value, simply use d as the expression. For example, if you want to
402plot three fields--Depth, SST, and Chlorophyll--and want to log10
403transform just Depth and Chlorophyll, provide these expressions::
404
405    log10(d)
406    d
407    log10(d)
408
409Alternatively, you could reorder the fields to be Depth, Chlorophyll,
410SST and then just provide two expressions, omitting the one for SST::
411
412    log10(d)
413    log10(d)
414"""),
415    arcGISDisplayName=_(u'Transforms'))
416
417AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where',
418    typeMetadata=SQLWhereClauseTypeMetadata(canBeNone=True),
419    description=ArcGIS91SelectCursor.__init__.__doc__.Obj.GetArgumentByName(u'where').Description,
420    arcGISParameterDependencies=[u'table'],
421    arcGISDisplayName=_(u'Where clause'))
422
423AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'diagonal',
424    typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'Name', u'Histogram'], makeLowercase=True),
425    description=_(
426u"""Type of plot to display in the diagonal panels:
427
428* Name - display the name of the variable.
429
430* Histogram - display the name of the variable and histogram of its
431  values.
432"""),
433    arcGISDisplayName=_(u'Diagonal panels'),
434    arcGISCategory=_(u'Formatting options'))
435
436AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'lower',
437    typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'Scatterplot', u'Smooth', u'Correlation', u'Correlation (Kendall)', u'Correlation (Spearman)'], makeLowercase=True),
438    description=_(
439u"""Type of plot to produce in the panels below the diagonal:
440
441* Scatterplot - display a scatterplot of the two variables.
442
443* Smooth - display a scatterplot of the two variables and line fitted
444  using the LOWESS smoother.
445
446* Correlation - display Pearson's correlation coefficent for the two
447  variables.
448
449* Correlation (Kendall) - display Kendall's rank correlation
450  coefficent (Kendall's tau) for the two variables.
451
452* Correlation (Spearman) - display Spearman's rank correlation
453  coefficent (rho) for the two variables.
454"""),
455    arcGISDisplayName=_(u'Lower panels'),
456    arcGISCategory=_(u'Formatting options'))
457
458AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'upper',
459    typeMetadata=RExploratoryPlots.ScatterplotMatrixForArcGISTable.__doc__.Obj.GetArgumentByName(u'lower').Type,
460    description=RExploratoryPlots.ScatterplotMatrixForArcGISTable.__doc__.Obj.GetArgumentByName(u'lower').Description,
461    arcGISDisplayName=_(u'Upper panels'),
462    arcGISCategory=_(u'Formatting options'))
463
464AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName',
465    typeMetadata=ArcGISFieldTypeMetadata(canBeNone=True),
466    description=_(
467u"""Variable name to use in plot for the X coordinates of point
468features. If the table is a point feature class or layer, the X
469coordinates will be extracted from the points and appear in the plot
470using the name provided for this parameter."""),
471    arcGISDisplayName=_(u'Name to use for X coordinates of points'),
472    arcGISCategory=_(u'Point feature options'))
473
474AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName',
475    typeMetadata=ArcGISFieldTypeMetadata(canBeNone=True, mustBeDifferentThanArguments=[u'xColumnName']),
476    description=_(
477u"""Variable name to use in the plot for the Y coordinates of point
478features. If the table is a point feature class or layer, the Y
479coordinates will be extracted from the points and appear in the plot
480using the name provided for this parameter."""),
481    arcGISDisplayName=_(u'Name to use for Y coordinates of points'),
482    arcGISCategory=_(u'Point feature options'))
483
484AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName',
485    typeMetadata=ArcGISFieldTypeMetadata(canBeNone=True, mustBeDifferentThanArguments=[u'xColumnName', u'yColumnName']),
486    description=_(
487u"""Variable name to use in the plot for the Z coordinates of point
488features. If the table is a point feature class or layer that has Z
489coordinates, the coordinates will be extracted from the points and
490appear in the plot using the name provided for this parameter."""),
491    arcGISDisplayName=_(u'Name to use for Z coordinates of points'),
492    arcGISCategory=_(u'Point feature options'))
493
494AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName',
495    typeMetadata=ArcGISFieldTypeMetadata(canBeNone=True, mustBeDifferentThanArguments=[u'xColumnName', u'yColumnName', u'zColumnName']),
496    description=_(
497u"""Variable name to use in the plot for the measure values of point
498features. If the table is a point feature class or layer that has
499measure values, the values will be extracted from the points and
500appear in the plot using the name provided for this parameter."""),
501    arcGISDisplayName=_(u'Name to use for M values of points'),
502    arcGISCategory=_(u'Point feature options'))
503
504AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile',
505    typeMetadata=FileTypeMetadata(canBeNone=True, mustBeDifferentThanArguments=[u'table'], deleteIfParameterIsTrue=u'overwriteExisting', createParentDirectories=True),
506    description=_(
507u"""File to create for the plot. If this parameter is specified, the
508plot will be written to the file rather than displayed on the screen.
509
510The file must have one of the following two extensions, which
511determines the format that will be used:
512
513* .emf - Windows enhanced metafile (EMF) format. This is a vector
514  format that may be printed and resized without any pixelation and is
515  therefore suitable for use in printable documents that recognize
516  this format (e.g. Microsoft Word or Microsoft Visio).
517
518* .png - Portable network graphics (PNG) format. This is a compressed,
519  lossless, highly portable raster format suitable for use in web
520  pages or other locations where a raster format is desired. Most
521  scientific journals accept PNG; they typically request that files
522  have a resolution of at least 1000 DPI.
523"""),
524    direction=u'Output',
525    arcGISDisplayName=_(u'Output file'),
526    arcGISCategory=_(u'Output file options'))
527
528AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res',
529    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.),
530    description=_(
531u"""Resolution of the output plot file, in dots per inch (DPI), when
532it is in PNG format. The default is set to a high value (1000) because
533this is the minimum resolution typically required by scientific
534journals that accept figures in PNG format.
535
536This parameter is ignored for EMF format because it is a vector
537format."""),
538    arcGISDisplayName=_(u'Plot resolution, in DPI'),
539    arcGISCategory=_(u'Output file options'))
540
541AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width',
542    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.),
543    description=_(
544u"""Plot file width in thousandths of inches (for EMF format; e.g. the
545value 3000 is 3 inches) or pixels (for PNG format)."""),
546    arcGISDisplayName=_(u'Plot width'),
547    arcGISCategory=_(u'Output file options'))
548
549AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height',
550    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.),
551    description=_(
552u"""Plot file height in thousandths of inches (for EMF format; e.g. the
553value 3000 is 3 inches) or pixels (for PNG format)."""),
554    arcGISDisplayName=_(u'Plot height'),
555    arcGISCategory=_(u'Output file options'))
556
557AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize',
558    typeMetadata=FloatTypeMetadata(minValue=1.0),
559    description=_(
560u"""The default pointsize of text in the output plot file."""),
561    arcGISDisplayName=_(u'Default pointsize of text'),
562    arcGISCategory=_(u'Output file options'))
563
564AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg',
565    typeMetadata=UnicodeStringTypeMetadata(),
566    description=_(
567u"""Background color when the output plot file is in PNG format. The
568color must be a valid name in R's color palette, or "transparent" if
569there is no background color. This parameter is ignored for EMF
570format."""),
571    arcGISDisplayName=_(u'Plot background color'),
572    arcGISCategory=_(u'Output file options'))
573
574AddArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting',
575    typeMetadata=BooleanTypeMetadata(),
576    description=_(
577u"""If True, the output file will be overwritten, if it exists. If
578False, a ValueError will be raised if the output file exists."""),
579    initializeToArcGISGeoprocessorVariable=u'OverwriteOutput')
580
581# Public method: RExploratoryPlots.DensityHistogramForArcGISField
582
583AddMethodMetadata(RExploratoryPlots.DensityHistogramForArcGISField,
584    shortDescription=_(u'Creates a density histogram for a field of a table.'),
585    isExposedToPythonCallers=True,
586    isExposedByCOM=True,
587    isExposedAsArcGISTool=True,
588    arcGISDisplayName=_(u'Density Histogram for Field'),
589    arcGISToolCategory=_(u'Statistics\\Explore Data'),
590    dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)])
591
592CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.DensityHistogramForArcGISField, u'cls')
593CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.DensityHistogramForArcGISField, u'table')
594
595AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'densityField',
596    typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'DATE']),
597    description=_(
598u"""Field for which a density histogram should be created.
599
600The field must have the data type SHORT, LONG, FLOAT, DOUBLE, or DATE.
601NULL values will not be included in the histogram."""),
602    arcGISParameterDependencies=[u'table'],
603    arcGISDisplayName=_(u'Density field'))
604
605AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'transform',
606    typeMetadata=UnicodeStringTypeMetadata(canBeNone=True, minLength=1),
607    description=_(
608u"""Transformation to perform before plotting the density histogram.
609
610Use this parameter when the distribution of the original data is too
611skewed to yield an informative plot. This parameter must be an R
612expression that operates on the vector d that represents the original
613values. For example, the following expressions perform natural
614logarithm, base 10 logarithm, square root, and cube root transforms,
615respectively::
616
617    log(d)
618    log10(d)
619    d^(1/2)
620    d^(1/3)
621
622The expression may be as complicated as you want, so long as it
623conforms to R syntax, operates only on the variable d, and yields a
624vector of the same length as the input data. For example, if the input
625data represent water depth expressed as a negative number (e.g. -100
626is 100 meters below the surface), and you want to transform the data
627using a base 10 logarithm, you must first take the absolute value of
628depth::
629
630    log10(abs(d))
631"""),
632    arcGISDisplayName=_(u'Transform'))
633
634AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'categoryField',
635    typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True),
636    description=_(
637u"""Field specifying categories for the data.
638
639A separate histogram line will be plotted for each category, allowing
640you to compare the distribution of data between categories. For
641example, in an ecology study, if you wanted to compare the
642distribution at locations where a species was present to locations
643where it was absent, you could specify the "IsPresent" field as the
644category field (1 = species present, 0 = species absent).
645
646The field must have the data type SHORT, LONG, FLOAT, DOUBLE, TEXT, or
647DATE. Rows with NULL values for this field will not be included in the
648histogram.
649
650A maximum of six categories is allowed. If this field contains more
651than six unique values, an error will be reported. You can reduce the
652number of categories by specifying a Where Clause that restricts the
653rows that are processed to those having the six or fewer category
654values you are most interested in."""),
655    arcGISParameterDependencies=[u'table'],
656    arcGISDisplayName=_(u'Category field'))
657
658CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.DensityHistogramForArcGISField, u'where')
659
660AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'legend',
661    typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'bottom', u'bottomleft', u'bottomright', u'center', u'left', u'right', u'top', u'topleft', u'topright'], canBeNone=True, makeLowercase=True),
662    description=_(
663u"""Position of the plot's legend. If this parameter is omitted, no
664legend will be drawn."""),
665    arcGISDisplayName=_(u'Legend'))
666
667CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.DensityHistogramForArcGISField, u'outputFile')
668CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.DensityHistogramForArcGISField, u'res')
669CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.DensityHistogramForArcGISField, u'width')
670CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.DensityHistogramForArcGISField, u'height')
671CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.DensityHistogramForArcGISField, u'pointSize')
672CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.DensityHistogramForArcGISField, u'bg')
673CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.DensityHistogramForArcGISField, u'overwriteExisting')
674
675# Public method: RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates
676
677AddMethodMetadata(RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates,
678    shortDescription=_(u'Creates a density histogram for one of the coordinates of a point feature class or layer.'),
679    isExposedToPythonCallers=True,
680    isExposedByCOM=True,
681    isExposedAsArcGISTool=True,
682    arcGISDisplayName=_(u'Density Histogram for Point Coordinate'),
683    arcGISToolCategory=_(u'Statistics\\Explore Data'),
684    dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)])
685
686CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'cls', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'cls')
687
688AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'pointFeatures',
689    typeMetadata=ArcGISFeatureLayerTypeMetadata(mustExist=True, allowedShapeTypes=[u'Point']),
690    description=_(
691u"""Point feature class or layer for which the plot should be
692generated."""),
693    arcGISDisplayName=_(u'Point features'))
694
695AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'coordinate',
696    typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'x', u'y', u'z', u'm'], makeLowercase=True),
697    description=_(
698u"""Point coordinate for which a density histogram should be plotted:
699
700* x - the x coordinate
701
702* y - the y coordinate
703
704* z - the z coordinate
705
706* m - the measure value
707
708An error will be reported if you specify z or m and the point features
709do not have z coordinates or measure values."""),
710    arcGISDisplayName=_(u'Coordinate to plot'))
711
712AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'coordinateName',
713    typeMetadata=UnicodeStringTypeMetadata(canBeNone=True),
714    description=_(
715u"""Name to display for the coordinate (e.g. "Longitude"). If you do
716not specify a name, "x", "y", "z", or "m" will be used."""),
717    arcGISDisplayName=_(u'Name to display for the coordinate'))
718
719CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'transform', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'transform')
720
721AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'categoryField',
722    typeMetadata=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'categoryField').Type,
723    description=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'categoryField').Description,
724    arcGISParameterDependencies=[u'pointFeatures'],
725    arcGISDisplayName=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'categoryField').ArcGISDisplayName)
726
727AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'where',
728    typeMetadata=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'where').Type,
729    description=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'where').Description,
730    arcGISParameterDependencies=[u'pointFeatures'],
731    arcGISDisplayName=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'where').ArcGISDisplayName)
732
733CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'legend', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'legend')
734
735AddArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'outputFile',
736    typeMetadata=FileTypeMetadata(canBeNone=True, mustBeDifferentThanArguments=[u'pointFeatures'], deleteIfParameterIsTrue=u'overwriteExisting', createParentDirectories=True),
737    description=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'outputFile').Description,
738    direction=u'Output',
739    arcGISDisplayName=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'outputFile').ArcGISDisplayName,
740    arcGISCategory=RExploratoryPlots.DensityHistogramForArcGISField.__doc__.Obj.GetArgumentByName(u'outputFile').ArcGISCategory)
741
742CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'res', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'res')
743CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'width', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'width')
744CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'height', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'height')
745CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'pointSize', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'pointSize')
746CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'bg', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'bg')
747CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'overwriteExisting', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'overwriteExisting')
748
749# Public method: RExploratoryPlots.ClevelandPlotForArcGISTable
750
751AddMethodMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable,
752    shortDescription=_(u'Creates a multi-panel Cleveland dotplot for a table.'),
753    longDescription=_(
754u"""Cleveland dotplots (Cleveland 1993) are typically used to explore
755the distributions of values in a table and detect possible outliers.
756Each dotplot shows the row number of the record vs. the value of a
757field. Points that appear far to the left or right are extreme values
758of that field and may be statistical outliers that should be
759investigated and possibly removed prior to further analysis of the
760data.
761
762For advice on how to use Cleveland dotplots, please see Zuur et al.
763(2009).
764
765**References:**
766
767Cleveland, W.S. (1993) Visualizing Data. Hobart Press, Summit, NJ.
768
769Zuur, A.F., Ineo, E.N., Elphick, C.S. (2009) A protocol for data
770exploration to avoid common statistical problems. Methods in Ecology &
771Evolution 1: 3-14."""),
772    isExposedToPythonCallers=True,
773    isExposedByCOM=True,
774    isExposedAsArcGISTool=True,
775    arcGISDisplayName=_(u'Cleveland Plot for Table'),
776    arcGISToolCategory=_(u'Statistics\\Explore Data'),
777    dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)])
778
779CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.ClevelandPlotForArcGISTable, u'cls')
780CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.ClevelandPlotForArcGISTable, u'table')
781CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields', RExploratoryPlots.ClevelandPlotForArcGISTable, u'fields')
782CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms', RExploratoryPlots.ClevelandPlotForArcGISTable, u'transforms')
783
784AddArgumentMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, u'orderByField',
785    typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True),
786    description=_(
787u"""Field specifying how the data will be ordered on the y axis of the
788plots.
789
790This parameter is optional and provided to enhance readability when
791the plotted fields' values correlate with another field. For example,
792if the weight and size of an animal correlate with the animal's age,
793you could order the plots by age and the weight and size points would
794cluster around a trend line rather than being randomly dispersed. This
795may aid in the visual identification of possible outliers."""),
796    arcGISParameterDependencies=[u'table'],
797    arcGISDisplayName=_(u'Order by field'))
798
799CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.ClevelandPlotForArcGISTable, u'where')
800
801CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'xColumnName')
802CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'yColumnName')
803CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'zColumnName')
804CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'mColumnName')
805
806CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.ClevelandPlotForArcGISTable, u'outputFile')
807CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.ClevelandPlotForArcGISTable, u'res')
808CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.ClevelandPlotForArcGISTable, u'width')
809CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.ClevelandPlotForArcGISTable, u'height')
810CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.ClevelandPlotForArcGISTable, u'pointSize')
811CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.ClevelandPlotForArcGISTable, u'bg')
812CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.ClevelandPlotForArcGISTable, u'overwriteExisting')
813
814###############################################################################
815# Names exported by this module
816###############################################################################
817
818__all__ = ['RExploratoryPlots']
Note: See TracBrowser for help on using the browser.