Changeset 812
- Timestamp:
- 07/04/11 14:34:11 (23 months ago)
- Location:
- MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics
- Files:
-
- 4 modified
-
DensityHistogramForDataframe.r (modified) (1 diff)
-
Exploratory.py (modified) (8 diffs)
-
Modeling.py (modified) (16 diffs)
-
ScatterplotMatrixForDataframe.r (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/DensityHistogramForDataframe.r
r339 r812 59 59 xlab <- densityField 60 60 } 61 62 if (is.null(categoryField)) 63 plot(densities[[1]], type="l", main=paste(densityField,"distribution"), xlab=xlab, ylab="Density", ylim=ylim, xlim=xlim) 64 else 65 { 66 plot(densities[[1]], type="l", main=paste(densityField,"distribution by", categoryField), xlab=xlab, ylab="Density", ylim=ylim, xlim=xlim) 67 if (length(densities) > 1) 68 for (i in 2:length(densities)) 69 lines(densities[[i]], lty=i) 70 if (!is.null(.legend)) 71 legend(x=.legend, legend=categories, lty=1:length(categories), title=categoryField) 72 } 61 62 oldMargins <- par("mar") 63 par(mar=c(5,4.5,1,1)+0.1) 64 65 tryCatch({ 66 if (is.null(categoryField)) 67 plot(densities[[1]], type="l", main="", xlab=xlab, ylab="Density", ylim=ylim, xlim=xlim) 68 else 69 { 70 plot(densities[[1]], type="l", main="", xlab=xlab, ylab="Density", ylim=ylim, xlim=xlim) 71 if (length(densities) > 1) 72 for (i in 2:length(densities)) 73 lines(densities[[i]], lty=i) 74 if (!is.null(.legend)) 75 legend(x=.legend, legend=categories, lty=1:length(categories), title=categoryField) 76 } 77 }, finally=par(mar=oldMargins)) 73 78 } 74 79 75 DensityHistogramToFile <- function(filename, df, densityField, transform=NULL, categoryField=NULL, .legend=NULL, width=480, height=480, pointsize=12.0, bg="white")80 DensityHistogramToFile <- function(filename, df, densityField, transform=NULL, categoryField=NULL, .legend=NULL, res=1000.0, width=3000.0, height=3000.0, pointsize=12.0, bg="white") 76 81 { 77 png(filename=filename, width=width, height=height, pointsize=pointsize, bg=bg) 82 if (tolower(substr(filename, nchar(filename) - 3, nchar(filename))) == ".emf") 83 win.metafile(filename, width=width, height=height, pointsize=pointsize) 84 else 85 png(filename, res=res, width=width, height=height, pointsize=pointsize, bg=bg) 86 78 87 tryCatch(DensityHistogram(df, densityField, transform, categoryField, .legend), finally=dev.off()) 79 88 } -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Exploratory.py
r810 r812 40 40 cls.__doc__.Obj.ValidateMethodInvocation() 41 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 42 47 # Load the data frame into a temporary data frame. 43 48 … … 70 75 tempOutputFile = os.path.join(tempDir.Path, u'plot.png') 71 76 Logger.Info(_(u'Writing scatterplot matrix to %(file)s...') % {u'file': outputFile}) 72 r('ScatterplotMatrixToFile("%s", %s, transforms=%s, .diag="%s", lower="%s", upper="%s", width=%i, height=%i, pointsize=%f, bg="%s")' % (tempOutputFile.replace(u'\\', u'/'), dataFrameName, transformsName, str(diagonal), str(lower), str(upper), width, height, pointSize, bg))77 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)) 73 78 File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting) 74 79 … … 83 88 outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 84 89 cls.__doc__.Obj.ValidateMethodInvocation() 90 91 # Perform additional validation. 92 93 if outputFile is not None and not outputFile.lower().endswith('.png') and not outputFile.lower().endswith('.emf'): 94 Logger.RaiseException(ValueError(_(u'The output file %(f)s has an invalid extension. It must have the extension .png or .emf.') % {u'f': outputFile})) 85 95 86 96 # Load the data frame into a temporary variable. … … 125 135 tempOutputFile = os.path.join(tempDir.Path, u'plot.png') 126 136 Logger.Info(_(u'Writing density plot to %(file)s...') % {u'file': outputFile}) 127 r('DensityHistogramToFile("%s", %s, densityField="%s", transform=%s, categoryField=%s, .legend=%s, width=%i, height=%i, pointsize=%f, bg="%s")' % (tempOutputFile.replace(u'\\', u'/'), dataFrameName, densityField, transform, categoryField, legend, width, height, pointSize, bg))137 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)) 128 138 File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting) 129 139 … … 137 147 outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 138 148 cls.__doc__.Obj.ValidateMethodInvocation() 149 150 # Perform additional validation. 151 152 if outputFile is not None and not outputFile.lower().endswith('.png') and not outputFile.lower().endswith('.emf'): 153 Logger.RaiseException(ValueError(_(u'The output file %(f)s has an invalid extension. It must have the extension .png or .emf.') % {u'f': outputFile})) 139 154 140 155 # Load the data frame into a temporary variable. … … 202 217 tempOutputFile = os.path.join(tempDir.Path, u'plot.png') 203 218 Logger.Info(_(u'Writing density plot to %(file)s...') % {u'file': outputFile}) 204 r('DensityHistogramToFile("%s", %s, densityField="%s", transform=%s, categoryField=%s, .legend=%s, width=%i, height=%i, pointsize=%f, bg="%s")' % (tempOutputFile.replace(u'\\', u'/'), dataFrameName, coordinateName, transform, categoryField, legend, width, height, pointSize, bg))219 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)) 205 220 File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting) 206 221 … … 210 225 r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) 211 226 212 @classmethod 213 def ClevelandPlotForArcGISTable(cls, table, fields=None, transforms=None, orderByField=None, where=None, 214 xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, 215 outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 216 cls.__doc__.Obj.ValidateMethodInvocation() 217 218 # Load the data frame into a temporary data frame. 219 220 r = R.GetInterpreter() 221 transformsName = R.GetUniqueVariableName() 222 dataFrameName = R.GetUniqueVariableName() 223 R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName) 224 225 # Create the plot. 226 227 try: 228 if r('length(%s)' % dataFrameName) <= 0: 229 if where is not None: 230 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})) 231 else: 232 Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table})) 233 234 if transforms is not None and len(transforms) > 0: 235 if len(transforms) > len(fields): 236 transforms = transforms[:len(fields)] 237 r[transformsName] = dict(zip(fields[:len(transforms)], transforms)) 238 else: 239 r('%s <- NULL' % transformsName) 240 241 R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ClevelandPlotForDataframe.r'), False) 242 if outputFile is None: 243 r('ScatterplotMatrix(%s, transforms=%s, .diag="%s", lower="%s", upper="%s")' % (dataFrameName, transformsName, str(diagonal), str(lower), str(upper))) 244 else: 245 tempDir = TemporaryDirectory() 246 tempOutputFile = os.path.join(tempDir.Path, u'plot.png') 247 Logger.Info(_(u'Writing scatterplot matrix to %(file)s...') % {u'file': outputFile}) 248 r('ScatterplotMatrixToFile("%s", %s, transforms=%s, .diag="%s", lower="%s", upper="%s", width=%i, height=%i, pointsize=%f, bg="%s")' % (tempOutputFile.replace(u'\\', u'/'), dataFrameName, transformsName, str(diagonal), str(lower), str(upper), width, height, pointSize, bg)) 249 File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting) 250 251 # Delete the data frame. 252 253 finally: 254 r('if (exists("%s")) rm("%s")' % (transformsName, transformsName)) 255 r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) 227 ## @classmethod 228 ## def ClevelandPlotForArcGISTable(cls, table, fields=None, transforms=None, orderByField=None, where=None, 229 ## xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, 230 ## outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 231 ## cls.__doc__.Obj.ValidateMethodInvocation() 232 ## 233 ## # Load the data frame into a temporary data frame. 234 ## 235 ## r = R.GetInterpreter() 236 ## transformsName = R.GetUniqueVariableName() 237 ## dataFrameName = R.GetUniqueVariableName() 238 ## R.LoadDataFrameFromArcGISTable(table, dataFrameName, where=where, fields=fields, xColumnName=xColumnName, yColumnName=yColumnName, zColumnName=zColumnName, mColumnName=mColumnName) 239 ## 240 ## # Create the plot. 241 ## 242 ## try: 243 ## if r('length(%s)' % dataFrameName) <= 0: 244 ## if where is not None: 245 ## Logger.RaiseException(ValueError(_(u'The where clause "%(where)s" did not select any rows from the table %(table)s.') % {u'table': table, u'where': where})) 246 ## else: 247 ## Logger.RaiseException(ValueError(_(u'The table %(table)s is empty.') % {u'table': table})) 248 ## 249 ## if transforms is not None and len(transforms) > 0: 250 ## if len(transforms) > len(fields): 251 ## transforms = transforms[:len(fields)] 252 ## r[transformsName] = dict(zip(fields[:len(transforms)], transforms)) 253 ## else: 254 ## r('%s <- NULL' % transformsName) 255 ## 256 ## # TODO: Sort 257 ## 258 ## r('library(lattice)') 259 ## #r('foobar <<- cbind(%s$wincrd, %s$tarsus)' % (dataFrameName, dataFrameName)) 260 ## r('zz <- VADeaths') 261 ## r('dotplot(zz)') 262 ## 263 #### R.EvaluateFile(os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), 'ClevelandPlotForDataframe.r'), False) 264 #### if outputFile is None: 265 #### r('ClevelandPlot(%s, transforms=%s)' % (dataFrameName, transformsName)) 266 #### else: 267 #### Logger.Info(_(u'Writing scatterplot matrix to %(file)s...') % {u'file': outputFile}) 268 #### r('ClevelandPlotToFile("%s", %s, transforms=%s, res=%f, width=%f, height=%f, pointSize=%f, bg="%s")' % (outputFile.replace(u'\\', u'/'), dataFrameName, transformsName, str(diagonal), str(lower), str(upper), res, width, height, pointSize, bg)) 269 ## 270 ## # Delete the data frame. 271 ## 272 ## finally: 273 ## r('if (exists("%s")) rm("%s")' % (transformsName, transformsName)) 274 ## r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) 256 275 257 276 … … 688 707 CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'overwriteExisting', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'overwriteExisting') 689 708 690 # Public method: RExploratoryPlots.ClevelandPlotForArcGISTable 691 692 AddMethodMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, 693 shortDescription=_(u'Creates a multi-panel Cleveland dotplot for a table.'), 694 longDescription=_( 695 u"""Cleveland dotplots (Cleveland 1993) are typically used to detect 696 possible outliers. Each dotplot shows the row number of the record vs. 697 the value of a field. Points that appear far to the left or right are 698 extreme values of that field and may be statistical outliers that 699 should be investigated and possibly removed prior to further analysis 700 of the data. 701 702 For advice on how to use Cleveland dotplots, please see Zuur et al. 703 (2009). 704 705 **References:** 706 707 Cleveland, W.S. (1993) Visualizing Data. Hobart Press, Summit, NJ. 708 709 Zuur, A.F., Ineo, E.N., Elphick, C.S. (2009) A protocol for data 710 exploration to avoid common statistical problems. Methods in Ecology & 711 Evolution 1: 3-14."""), 712 isExposedToPythonCallers=True, 713 isExposedByCOM=True, 714 isExposedAsArcGISTool=True, 715 arcGISDisplayName=_(u'Cleveland Plot for Table'), 716 arcGISToolCategory=_(u'Statistics\\Explore Data'), 717 dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)]) 718 719 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.ClevelandPlotForArcGISTable, u'cls') 720 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.ClevelandPlotForArcGISTable, u'table') 721 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields', RExploratoryPlots.ClevelandPlotForArcGISTable, u'fields') 722 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms', RExploratoryPlots.ClevelandPlotForArcGISTable, u'transforms') 723 724 AddArgumentMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, u'orderByField', 725 typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True), 726 description=_( 727 u"""Field specifying how the data will be ordered on the y axis of the 728 plots. 729 730 This parameter is optional and provided to enhance the readability of 731 the plots when the plotted field values follow a natural trend 732 according to some other field's value. For example, the weight and 733 size of an animal might increase with the animal's age. In that case, 734 you could order the plots of weight and size by age and the points 735 would cluster around a trend line rather than being randomly 736 dispersed, which might aid in the visual identification of possible 737 outliers."""), 738 arcGISParameterDependencies=[u'table'], 739 arcGISDisplayName=_(u'Order by field')) 740 741 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.ClevelandPlotForArcGISTable, u'where') 742 743 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'xColumnName') 744 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'yColumnName') 745 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'zColumnName') 746 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'mColumnName') 747 748 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.ClevelandPlotForArcGISTable, u'outputFile') 749 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.ClevelandPlotForArcGISTable, u'res') 750 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.ClevelandPlotForArcGISTable, u'width') 751 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.ClevelandPlotForArcGISTable, u'height') 752 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.ClevelandPlotForArcGISTable, u'pointSize') 753 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.ClevelandPlotForArcGISTable, u'bg') 754 CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.ClevelandPlotForArcGISTable, u'overwriteExisting') 709 ### Public method: RExploratoryPlots.ClevelandPlotForArcGISTable 710 ## 711 ##AddMethodMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, 712 ## shortDescription=_(u'Creates a multi-panel Cleveland dotplot for a table.'), 713 ## longDescription=_( 714 ##u"""Cleveland dotplots (Cleveland 1993) are typically used to detect 715 ##possible outliers. Each dotplot shows the row number of the record vs. 716 ##the value of a field. Points that appear far to the left or right are 717 ##extreme values of that field and may be statistical outliers that 718 ##should be investigated and possibly removed prior to further analysis 719 ##of the data. 720 ## 721 ##For advice on how to use Cleveland dotplots, please see Zuur et al. 722 ##(2009). 723 ## 724 ##**References:** 725 ## 726 ##Cleveland, W.S. (1993) Visualizing Data. Hobart Press, Summit, NJ. 727 ## 728 ##Zuur, A.F., Ineo, E.N., Elphick, C.S. (2009) A protocol for data 729 ##exploration to avoid common statistical problems. Methods in Ecology & 730 ##Evolution 1: 3-14."""), 731 ## isExposedToPythonCallers=True, 732 ## isExposedByCOM=True, 733 ## isExposedAsArcGISTool=True, 734 ## arcGISDisplayName=_(u'Cleveland Plot for Table'), 735 ## arcGISToolCategory=_(u'Statistics\\Explore Data'), 736 ## dependencies=[ArcGISDependency(9, 1), RDependency(2, 5, 0)]) 737 ## 738 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'cls', RExploratoryPlots.ClevelandPlotForArcGISTable, u'cls') 739 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'table', RExploratoryPlots.ClevelandPlotForArcGISTable, u'table') 740 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'fields', RExploratoryPlots.ClevelandPlotForArcGISTable, u'fields') 741 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'transforms', RExploratoryPlots.ClevelandPlotForArcGISTable, u'transforms') 742 ## 743 ##AddArgumentMetadata(RExploratoryPlots.ClevelandPlotForArcGISTable, u'orderByField', 744 ## typeMetadata=ArcGISFieldTypeMetadata(mustExist=True, allowedFieldTypes=[u'SHORT', u'LONG', u'FLOAT', u'DOUBLE', u'TEXT', u'DATE'], canBeNone=True), 745 ## description=_( 746 ##u"""Field specifying how the data will be ordered on the y axis of the 747 ##plots. 748 ## 749 ##This parameter is optional and provided to enhance readability when 750 ##the plotted fields' values correlate with another field. For example, 751 ##if the weight and size of an animal correlate with the animal's age, 752 ##you could order the plots by age and the weight and size points would 753 ##cluster around a trend line rather than being randomly dispersed. This 754 ##may aid in the visual identification of possible outliers."""), 755 ## arcGISParameterDependencies=[u'table'], 756 ## arcGISDisplayName=_(u'Order by field')) 757 ## 758 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'where', RExploratoryPlots.ClevelandPlotForArcGISTable, u'where') 759 ## 760 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'xColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'xColumnName') 761 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'yColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'yColumnName') 762 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'zColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'zColumnName') 763 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'mColumnName', RExploratoryPlots.ClevelandPlotForArcGISTable, u'mColumnName') 764 ## 765 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'outputFile', RExploratoryPlots.ClevelandPlotForArcGISTable, u'outputFile') 766 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'res', RExploratoryPlots.ClevelandPlotForArcGISTable, u'res') 767 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'width', RExploratoryPlots.ClevelandPlotForArcGISTable, u'width') 768 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'height', RExploratoryPlots.ClevelandPlotForArcGISTable, u'height') 769 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'pointSize', RExploratoryPlots.ClevelandPlotForArcGISTable, u'pointSize') 770 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'bg', RExploratoryPlots.ClevelandPlotForArcGISTable, u'bg') 771 ##CopyArgumentMetadata(RExploratoryPlots.ScatterplotMatrixForArcGISTable, u'overwriteExisting', RExploratoryPlots.ClevelandPlotForArcGISTable, u'overwriteExisting') 755 772 756 773 ############################################################################### -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Modeling.py
r808 r812 40 40 41 41 @classmethod 42 def FitToArcGISTable(cls, inputTable, outputModelFile, formula, family=u'gaussian', where=None, link=None, variance=None, xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, selectionMethod=None, logSelectionDetails=True, writeSummaryFile=True, writeDiagnosticPlots=True, numDiagLabels=3, diagLabelField=None, writeTermPlots=True, residuals=False, xAxis=True, commonScale=True, width=480, height=480, pointSize=12.0, bg=u'white', overwriteExisting=False): 42 def FitToArcGISTable(cls, inputTable, outputModelFile, formula, 43 family=u'gaussian', where=None, link=None, variance=None, 44 xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, 45 selectionMethod=None, logSelectionDetails=True, 46 writeSummaryFile=True, writeDiagnosticPlots=True, numDiagLabels=3, diagLabelField=None, writeTermPlots=True, residuals=False, xAxis=True, commonScale=True, plotFileFormat=u'png', res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', 47 overwriteExisting=False): 43 48 cls.__doc__.Obj.ValidateMethodInvocation() 44 49 … … 113 118 114 119 @classmethod 115 def FitToArcGISTable(cls, inputTable, outputModelFile, formula, family=u'gaussian', rPackage=u'mgcv', where=None, link=None, variance=None, xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, selectionMethod=None, logSelectionDetails=True, writeSummaryFile=True, writeDiagnosticPlots=True, writeTermPlots=True, residuals=False, xAxis=True, commonScale=True, width=480, height=480, pointSize=12.0, bg=u'white', overwriteExisting=False): 120 def FitToArcGISTable(cls, inputTable, outputModelFile, formula, family=u'gaussian', rPackage=u'mgcv', 121 where=None, link=None, variance=None, 122 xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, 123 selectionMethod=None, logSelectionDetails=True, \ 124 writeSummaryFile=True, writeDiagnosticPlots=True, writeTermPlots=True, residuals=False, xAxis=True, commonScale=True, plotFileFormat=u'png', res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', 125 overwriteExisting=False): 116 126 cls.__doc__.Obj.ValidateMethodInvocation() 117 127 … … 378 388 379 389 @classmethod 380 def FitToArcGISTable(cls, inputTable, outputModelFile, fixedFormula, randomFormula=None, where=None, method=u'REML', correlationStructure=None, correlationFormula=None, range_=None, nugget=None, metric=None, fixed=False, xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, writeSummaryFile=True, plotFileFormat=u'png', res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 390 def FitToArcGISTable(cls, inputTable, outputModelFile, fixedFormula, randomFormula=None, 391 where=None, method=u'REML', correlationStructure=None, correlationFormula=None, range_=None, nugget=None, metric=None, fixed=False, 392 xColumnName=None, yColumnName=None, zColumnName=None, mColumnName=None, 393 writeSummaryFile=True, plotFileFormat=u'png', res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', 394 overwriteExisting=False): 381 395 cls.__doc__.Obj.ValidateMethodInvocation() 382 396 … … 429 443 430 444 @classmethod 431 def PlotPerformanceOfBinaryClassificationModel(cls, inputModelFile, measure1, measure2=None, summaryStats=None, title=None, evaluationDataTable=None, where=None, outputPlotFile=None, width=480, height=480, pointSize=12.0, bg=u'white', overwriteExisting=False): 445 def PlotPerformanceOfBinaryClassificationModel(cls, inputModelFile, measure1, measure2=None, summaryStats=None, title=None, 446 evaluationDataTable=None, where=None, 447 outputPlotFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', 448 overwriteExisting=False): 432 449 cls.__doc__.Obj.ValidateMethodInvocation() 433 450 … … 522 539 523 540 @classmethod 524 def PlotROCOfBinaryClassificationModel(cls, inputModelFile, cutoff=u'Automatic', cutoffValue=None, colorize=True, title=None, evaluationDataTable=None, where=None, outputSummaryFile=None, outputPlotFile=None, width=480, height=480, pointSize=12.0, bg=u'white', overwriteExisting=False): 541 def PlotROCOfBinaryClassificationModel(cls, inputModelFile, cutoff=u'Automatic', cutoffValue=None, colorize=True, title=None, 542 evaluationDataTable=None, where=None, 543 outputSummaryFile=None, outputPlotFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', 544 overwriteExisting=False): 525 545 cls.__doc__.Obj.ValidateMethodInvocation() 526 546 … … 1924 1944 arcGISCategory=_(u'Additional output options')) 1925 1945 1946 AddArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', 1947 typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'emf', u'png'], makeLowercase=True), 1948 description=_( 1949 u"""Plot file format, one of: 1950 1951 * emf - Windows enhanced metafile (EMF) format. This is a vector 1952 format that may be printed and resized without any pixelation and is 1953 therefore suitable for use in printable documents that recognize 1954 this format (e.g. Microsoft Word or Microsoft Visio). 1955 1956 * png - Portable network graphics (PNG) format. This is a compressed, 1957 lossless, highly portable raster format suitable for use in web 1958 pages or other locations where a raster format is desired. Most 1959 scientific journals accept PNG; they typically request that files 1960 have a resolution of at least 1000 DPI. 1961 """), 1962 arcGISDisplayName=_(u'Plot file format'), 1963 arcGISCategory=_(u'Additional output options')) 1964 1965 AddArgumentMetadata(GLM.FitToArcGISTable, u'res', 1966 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 1967 description=_( 1968 u"""PNG plot file resolution, in dots per inch (DPI). The default is 1969 set to a high value (1000) because this is the minimum resolution 1970 typically required by scientific journals that accept figures in PNG 1971 format. 1972 1973 This parameter is ignored for EMF format because it is a vector 1974 format."""), 1975 arcGISDisplayName=_(u'Plot resolution, in DPI'), 1976 arcGISCategory=_(u'Additional output options')) 1977 1926 1978 AddArgumentMetadata(GLM.FitToArcGISTable, u'width', 1927 typeMetadata=IntegerTypeMetadata(minValue=1), 1928 description=_( 1929 u"""Width of output plots, in pixels."""), 1979 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 1980 description=_( 1981 u"""Plot file width in inches (for EMF format) or pixels (for PNG 1982 format)."""), 1930 1983 arcGISDisplayName=_(u'Plot width'), 1931 1984 arcGISCategory=_(u'Additional output options')) 1932 1985 1933 1986 AddArgumentMetadata(GLM.FitToArcGISTable, u'height', 1934 typeMetadata=IntegerTypeMetadata(minValue=1), 1935 description=_( 1936 u"""Height of output plots, in pixels."""), 1987 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 1988 description=_( 1989 u"""Plot file width in inches (for EMF format) or pixels (for PNG 1990 format)."""), 1937 1991 arcGISDisplayName=_(u'Plot height'), 1938 1992 arcGISCategory=_(u'Additional output options')) … … 1941 1995 typeMetadata=FloatTypeMetadata(minValue=1.0), 1942 1996 description=_( 1943 u"""The default pointsize of text in output plots, interpreted at 72 1944 dpi, so one point is approximately one pixel."""), 1997 u"""The default pointsize of plotted text."""), 1945 1998 arcGISDisplayName=_(u'Default pointsize of plotted text'), 1946 1999 arcGISCategory=_(u'Additional output options')) … … 1949 2002 typeMetadata=UnicodeStringTypeMetadata(), 1950 2003 description=_( 1951 u""" Background color for output plots. The color must be a valid name1952 in R's color palette, or "transparent" if there is no background 1953 color."""),2004 u"""PNG plot file background color. The color must be a valid name in 2005 R's color palette, or "transparent" if there is no background color. 2006 This parameter is ignored if the plot format file is EMF."""), 1954 2007 arcGISDisplayName=_(u'Plot background color'), 1955 2008 arcGISCategory=_(u'Additional output options')) … … 2393 2446 CopyArgumentMetadata(GLM.FitToArcGISTable, u'xAxis', GAM.FitToArcGISTable, u'xAxis') 2394 2447 CopyArgumentMetadata(GLM.FitToArcGISTable, u'commonScale', GAM.FitToArcGISTable, u'commonScale') 2448 CopyArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', GAM.FitToArcGISTable, u'plotFileFormat') 2449 CopyArgumentMetadata(GLM.FitToArcGISTable, u'res', GAM.FitToArcGISTable, u'res') 2395 2450 CopyArgumentMetadata(GLM.FitToArcGISTable, u'width', GAM.FitToArcGISTable, u'width') 2396 2451 CopyArgumentMetadata(GLM.FitToArcGISTable, u'height', GAM.FitToArcGISTable, u'height') … … 2882 2937 arcGISCategory=_(u'Additional output options')) 2883 2938 2884 AddArgumentMetadata(TreeModel.FitToArcGISTable, u'plotFileFormat', 2885 typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'emf', u'png'], makeLowercase=True), 2886 description=_( 2887 u"""File format for plots, one of: 2888 2889 * emf - Windows enhanced metafile format. This is a vector format 2890 that may be printed and resized without any pixelation and is 2891 therefore suitable for use in printable documents that recognize 2892 this format (e.g. Microsoft Word or Microsoft Visio). 2893 2894 * png - Portable network graphics (PNG) format. This is a compressed, 2895 lossless, highly portable raster format suitable for use in web 2896 pages or other locations where a raster format is desired. Most 2897 scientific journals accept PNG; they typically request that files 2898 have a resolution of at least 1000 DPI. 2899 """), 2900 arcGISDisplayName=_(u'Plot file format'), 2901 arcGISCategory=_(u'Additional output options')) 2902 2903 AddArgumentMetadata(TreeModel.FitToArcGISTable, u'res', 2904 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 2905 description=_( 2906 u"""Resolution of plots in PNG format, in dots per inch (DPI). The 2907 default is set to a high value (1000) because this is the minimum 2908 resolution typically required by scientific journals that accept 2909 figures in PNG format. 2910 2911 This parameter does not apply to Windows enhanced metafile format 2912 because it is a vector format."""), 2913 arcGISDisplayName=_(u'Plot resolution, in DPI'), 2914 arcGISCategory=_(u'Additional output options')) 2915 2916 AddArgumentMetadata(TreeModel.FitToArcGISTable, u'width', 2917 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 2918 description=_( 2919 u"""Width of output plots in inches (for EMF format) or pixels (for 2920 PNG format)."""), 2921 arcGISDisplayName=_(u'Plot width'), 2922 arcGISCategory=_(u'Additional output options')) 2923 2924 AddArgumentMetadata(TreeModel.FitToArcGISTable, u'height', 2925 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 2926 description=_( 2927 u"""Height of output plots in inches (for EMF format) or pixels (for 2928 PNG format)."""), 2929 arcGISDisplayName=_(u'Plot height'), 2930 arcGISCategory=_(u'Additional output options')) 2939 CopyArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', TreeModel.FitToArcGISTable, u'plotFileFormat') 2940 CopyArgumentMetadata(GLM.FitToArcGISTable, u'res', TreeModel.FitToArcGISTable, u'res') 2941 CopyArgumentMetadata(GLM.FitToArcGISTable, u'width', TreeModel.FitToArcGISTable, u'width') 2942 CopyArgumentMetadata(GLM.FitToArcGISTable, u'height', TreeModel.FitToArcGISTable, u'height') 2931 2943 2932 2944 AddArgumentMetadata(TreeModel.FitToArcGISTable, u'pointSize', … … 2934 2946 description=_( 2935 2947 u"""The default pointsize of text in diagnostic plots (the size of the 2936 text in tree plots is controlled by a different parameter). For PNG 2937 format, this is interpreted at 72 dpi, so one point is approximately 2938 one pixel."""), 2948 text in tree plots is controlled by a different parameter)."""), 2939 2949 arcGISDisplayName=_(u'Default pointsize of text in diagnostic plots'), 2940 2950 arcGISCategory=_(u'Additional output options')) 2941 2951 2942 AddArgumentMetadata(TreeModel.FitToArcGISTable, u'bg', 2943 typeMetadata=UnicodeStringTypeMetadata(), 2944 description=_( 2945 u"""Background color for png output plots. The color must be a valid 2946 name in R's color palette, or "transparent" if there is no background 2947 color. This parameter is ignored if the output format is emf."""), 2948 arcGISDisplayName=_(u'Plot background color'), 2949 arcGISCategory=_(u'Additional output options')) 2952 CopyArgumentMetadata(GLM.FitToArcGISTable, u'bg', TreeModel.FitToArcGISTable, u'bg') 2950 2953 2951 2954 AddArgumentMetadata(TreeModel.FitToArcGISTable, u'treePlotType', … … 3434 3437 arcGISCategory=_(u'Additional output options')) 3435 3438 3436 CopyArgumentMetadata( TreeModel.FitToArcGISTable, u'plotFileFormat', LinearMixedModel.FitToArcGISTable, u'plotFileFormat')3437 CopyArgumentMetadata( TreeModel.FitToArcGISTable, u'res', LinearMixedModel.FitToArcGISTable, u'res')3438 CopyArgumentMetadata( TreeModel.FitToArcGISTable, u'width', LinearMixedModel.FitToArcGISTable, u'width')3439 CopyArgumentMetadata( TreeModel.FitToArcGISTable, u'height', LinearMixedModel.FitToArcGISTable, u'height')3440 CopyArgumentMetadata( TreeModel.FitToArcGISTable, u'pointSize', LinearMixedModel.FitToArcGISTable, u'pointSize')3441 CopyArgumentMetadata( TreeModel.FitToArcGISTable, u'bg', LinearMixedModel.FitToArcGISTable, u'bg')3439 CopyArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', LinearMixedModel.FitToArcGISTable, u'plotFileFormat') 3440 CopyArgumentMetadata(GLM.FitToArcGISTable, u'res', LinearMixedModel.FitToArcGISTable, u'res') 3441 CopyArgumentMetadata(GLM.FitToArcGISTable, u'width', LinearMixedModel.FitToArcGISTable, u'width') 3442 CopyArgumentMetadata(GLM.FitToArcGISTable, u'height', LinearMixedModel.FitToArcGISTable, u'height') 3443 CopyArgumentMetadata(GLM.FitToArcGISTable, u'pointSize', LinearMixedModel.FitToArcGISTable, u'pointSize') 3444 CopyArgumentMetadata(GLM.FitToArcGISTable, u'bg', LinearMixedModel.FitToArcGISTable, u'bg') 3442 3445 3443 3446 CopyArgumentMetadata(GLM.FitToArcGISTable, u'overwriteExisting', LinearMixedModel.FitToArcGISTable, u'overwriteExisting') … … 3740 3743 typeMetadata=FileTypeMetadata(canBeNone=True, mustBeDifferentThanArguments=[u'inputModelFile'], deleteIfParameterIsTrue=u'overwriteExisting', createParentDirectories=True), 3741 3744 description=_( 3742 u"""Portable Network Graphics (PNG) file to create for the plot. It is 3743 suggested that you name your output file with a .png extension, so it 3744 can be displayed properly by other programs. 3745 3746 If you specify an output file, it will be written using R's png 3747 graphics device. An interactive window will not be displayed on the 3748 screen."""), 3745 u"""File to create for the plot. If this parameter is specified, the 3746 plot will be written to the file rather than displayed on the screen. 3747 3748 The file must have one of the following two extensions, which 3749 determines the format that will be used: 3750 3751 * .emf - Windows enhanced metafile (EMF) format. This is a vector 3752 format that may be printed and resized without any pixelation and is 3753 therefore suitable for use in printable documents that recognize 3754 this format (e.g. Microsoft Word or Microsoft Visio). 3755 3756 * .png - Portable network graphics (PNG) format. This is a compressed, 3757 lossless, highly portable raster format suitable for use in web 3758 pages or other locations where a raster format is desired. Most 3759 scientific journals accept PNG; they typically request that files 3760 have a resolution of at least 1000 DPI. 3761 """), 3749 3762 direction=u'Output', 3750 arcGISDisplayName=_(u'Output PNGfile'),3763 arcGISDisplayName=_(u'Output file'), 3751 3764 arcGISCategory=_(u'Output file options')) 3752 3765 3766 AddArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'res', 3767 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 3768 description=_( 3769 u"""PNG plot file resolution, in dots per inch (DPI). The default is 3770 set to a high value (1000) because this is the minimum resolution 3771 typically required by scientific journals that accept figures in PNG 3772 format. 3773 3774 This parameter is ignored for EMF format because it is a vector 3775 format."""), 3776 arcGISDisplayName=_(u'Plot resolution, in DPI'), 3777 arcGISCategory=_(u'Output file options')) 3778 3753 3779 AddArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'width', 3754 typeMetadata=IntegerTypeMetadata(minValue=1), 3755 description=_( 3756 u"""Width of the output PNG file, in pixels."""), 3780 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 3781 description=_( 3782 u"""Plot file width in inches (for EMF format) or pixels (for PNG 3783 format)."""), 3757 3784 arcGISDisplayName=_(u'Plot width'), 3758 3785 arcGISCategory=_(u'Output file options')) 3759 3786 3760 3787 AddArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'height', 3761 typeMetadata=IntegerTypeMetadata(minValue=1), 3762 description=_( 3763 u"""Height of the output PNG file, in pixels."""), 3788 typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 3789 description=_( 3790 u"""Plot file width in inches (for EMF format) or pixels (for PNG 3791 format)."""), 3764 3792 arcGISDisplayName=_(u'Plot height'), 3765 3793 arcGISCategory=_(u'Output file options')) … … 3768 3796 typeMetadata=FloatTypeMetadata(minValue=1.0), 3769 3797 description=_( 3770 u"""The default pointsize of text in the output PNG file, interpreted 3771 at 72 dpi, so one point is approximately one pixel."""), 3798 u"""The default pointsize of plotted text."""), 3772 3799 arcGISDisplayName=_(u'Default pointsize of plotted text'), 3773 3800 arcGISCategory=_(u'Output file options')) … … 3776 3803 typeMetadata=UnicodeStringTypeMetadata(), 3777 3804 description=_( 3778 u""" Background color for the output PNG file. The color must be a3779 valid name in R's color palette, or "transparent" if there is no 3780 background color."""),3805 u"""PNG plot file background color. The color must be a valid name in 3806 R's color palette, or "transparent" if there is no background color. 3807 This parameter is ignored if the plot format file is EMF."""), 3781 3808 arcGISDisplayName=_(u'Plot background color'), 3782 3809 arcGISCategory=_(u'Output file options')) … … 3880 3907 3881 3908 CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'outputPlotFile', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'outputPlotFile') 3909 CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'res', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'res') 3882 3910 CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'width', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'width') 3883 3911 CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'height', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'height') -
MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/ScatterplotMatrixForDataframe.r
r339 r812 84 84 } 85 85 86 ScatterplotMatrixToFile <- function(filename, df, transforms=NULL, .diag=NULL, lower=NULL, upper=NULL, width=480, height=480, pointsize=12.0, bg="white")86 ScatterplotMatrixToFile <- function(filename, df, transforms=NULL, .diag=NULL, lower=NULL, upper=NULL, res=1000.0, width=3000.0, height=3000.0, pointsize=12.0, bg="white") 87 87 { 88 png(filename=filename, width=width, height=height, pointsize=pointsize, bg=bg) 88 if (tolower(substr(filename, nchar(filename) - 3, nchar(filename))) == ".emf") 89 win.metafile(filename, width=width, height=height, pointsize=pointsize) 90 else 91 png(filename, res=res, width=width, height=height, pointsize=pointsize, bg=bg) 92 89 93 tryCatch(ScatterplotMatrix(df, transforms, .diag, lower, upper), finally=dev.off()) 90 94 }
