Changeset 812

Show
Ignore:
Timestamp:
07/04/11 14:34:11 (23 months ago)
Author:
jjr8
Message:

Working on #468: MGET Statistics tools that create plots should produce publication-quality figures

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

Legend:

Unmodified
Added
Removed
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/DensityHistogramForDataframe.r

    r339 r812  
    5959        xlab <- densityField 
    6060    } 
    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)) 
    7378} 
    7479 
    75 DensityHistogramToFile <- function(filename, df, densityField, transform=NULL, categoryField=NULL, .legend=NULL, width=480, height=480, pointsize=12.0, bg="white") 
     80DensityHistogramToFile <- function(filename, df, densityField, transform=NULL, categoryField=NULL, .legend=NULL, res=1000.0, width=3000.0, height=3000.0, pointsize=12.0, bg="white") 
    7681{ 
    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 
    7887    tryCatch(DensityHistogram(df, densityField, transform, categoryField, .legend), finally=dev.off()) 
    7988} 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Exploratory.py

    r810 r812  
    4040        cls.__doc__.Obj.ValidateMethodInvocation() 
    4141 
     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 
    4247        # Load the data frame into a temporary data frame. 
    4348         
     
    7075                tempOutputFile = os.path.join(tempDir.Path, u'plot.png') 
    7176                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)) 
    7378                File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting) 
    7479 
     
    8388                                       outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 
    8489        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})) 
    8595 
    8696        # Load the data frame into a temporary variable. 
     
    125135                tempOutputFile = os.path.join(tempDir.Path, u'plot.png') 
    126136                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)) 
    128138                File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting) 
    129139 
     
    137147                                                   outputFile=None, res=1000., width=3000., height=3000., pointSize=10.0, bg=u'white', overwriteExisting=False): 
    138148        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})) 
    139154 
    140155        # Load the data frame into a temporary variable. 
     
    202217                tempOutputFile = os.path.join(tempDir.Path, u'plot.png') 
    203218                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)) 
    205220                File.MoveSilent(tempOutputFile, outputFile, overwriteExisting=overwriteExisting) 
    206221 
     
    210225            r('if (exists("%s")) rm("%s")' % (dataFrameName, dataFrameName)) 
    211226 
    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)) 
    256275 
    257276 
     
    688707CopyArgumentMetadata(RExploratoryPlots.DensityHistogramForArcGISField, u'overwriteExisting', RExploratoryPlots.DensityHistogramForArcGISPointsCoordinates, u'overwriteExisting') 
    689708 
    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') 
    755772 
    756773############################################################################### 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/Modeling.py

    r808 r812  
    4040 
    4141    @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): 
    4348        cls.__doc__.Obj.ValidateMethodInvocation() 
    4449 
     
    113118 
    114119    @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): 
    116126        cls.__doc__.Obj.ValidateMethodInvocation() 
    117127 
     
    378388 
    379389    @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): 
    381395        cls.__doc__.Obj.ValidateMethodInvocation() 
    382396 
     
    429443 
    430444    @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): 
    432449        cls.__doc__.Obj.ValidateMethodInvocation() 
    433450 
     
    522539 
    523540    @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): 
    525545        cls.__doc__.Obj.ValidateMethodInvocation() 
    526546 
     
    19241944    arcGISCategory=_(u'Additional output options')) 
    19251945 
     1946AddArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', 
     1947    typeMetadata=UnicodeStringTypeMetadata(allowedValues=[u'emf', u'png'], makeLowercase=True), 
     1948    description=_( 
     1949u"""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 
     1965AddArgumentMetadata(GLM.FitToArcGISTable, u'res', 
     1966    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 
     1967    description=_( 
     1968u"""PNG plot file resolution, in dots per inch (DPI). The default is 
     1969set to a high value (1000) because this is the minimum resolution 
     1970typically required by scientific journals that accept figures in PNG 
     1971format. 
     1972 
     1973This parameter is ignored for EMF format because it is a vector 
     1974format."""), 
     1975    arcGISDisplayName=_(u'Plot resolution, in DPI'), 
     1976    arcGISCategory=_(u'Additional output options')) 
     1977 
    19261978AddArgumentMetadata(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=_( 
     1981u"""Plot file width in inches (for EMF format) or pixels (for PNG 
     1982format)."""), 
    19301983    arcGISDisplayName=_(u'Plot width'), 
    19311984    arcGISCategory=_(u'Additional output options')) 
    19321985 
    19331986AddArgumentMetadata(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=_( 
     1989u"""Plot file width in inches (for EMF format) or pixels (for PNG 
     1990format)."""), 
    19371991    arcGISDisplayName=_(u'Plot height'), 
    19381992    arcGISCategory=_(u'Additional output options')) 
     
    19411995    typeMetadata=FloatTypeMetadata(minValue=1.0), 
    19421996    description=_( 
    1943 u"""The default pointsize of text in output plots, interpreted at 72 
    1944 dpi, so one point is approximately one pixel."""), 
     1997u"""The default pointsize of plotted text."""), 
    19451998    arcGISDisplayName=_(u'Default pointsize of plotted text'), 
    19461999    arcGISCategory=_(u'Additional output options')) 
     
    19492002    typeMetadata=UnicodeStringTypeMetadata(), 
    19502003    description=_( 
    1951 u"""Background color for output plots. The color must be a valid name 
    1952 in R's color palette, or "transparent" if there is no background 
    1953 color."""), 
     2004u"""PNG plot file background color. The color must be a valid name in 
     2005R's color palette, or "transparent" if there is no background color. 
     2006This parameter is ignored if the plot format file is EMF."""), 
    19542007    arcGISDisplayName=_(u'Plot background color'), 
    19552008    arcGISCategory=_(u'Additional output options')) 
     
    23932446CopyArgumentMetadata(GLM.FitToArcGISTable, u'xAxis', GAM.FitToArcGISTable, u'xAxis') 
    23942447CopyArgumentMetadata(GLM.FitToArcGISTable, u'commonScale', GAM.FitToArcGISTable, u'commonScale') 
     2448CopyArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', GAM.FitToArcGISTable, u'plotFileFormat') 
     2449CopyArgumentMetadata(GLM.FitToArcGISTable, u'res', GAM.FitToArcGISTable, u'res') 
    23952450CopyArgumentMetadata(GLM.FitToArcGISTable, u'width', GAM.FitToArcGISTable, u'width') 
    23962451CopyArgumentMetadata(GLM.FitToArcGISTable, u'height', GAM.FitToArcGISTable, u'height') 
     
    28822937    arcGISCategory=_(u'Additional output options')) 
    28832938 
    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')) 
     2939CopyArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', TreeModel.FitToArcGISTable, u'plotFileFormat') 
     2940CopyArgumentMetadata(GLM.FitToArcGISTable, u'res', TreeModel.FitToArcGISTable, u'res') 
     2941CopyArgumentMetadata(GLM.FitToArcGISTable, u'width', TreeModel.FitToArcGISTable, u'width') 
     2942CopyArgumentMetadata(GLM.FitToArcGISTable, u'height', TreeModel.FitToArcGISTable, u'height') 
    29312943 
    29322944AddArgumentMetadata(TreeModel.FitToArcGISTable, u'pointSize', 
     
    29342946    description=_( 
    29352947u"""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."""), 
     2948text in tree plots is controlled by a different parameter)."""), 
    29392949    arcGISDisplayName=_(u'Default pointsize of text in diagnostic plots'), 
    29402950    arcGISCategory=_(u'Additional output options')) 
    29412951 
    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')) 
     2952CopyArgumentMetadata(GLM.FitToArcGISTable, u'bg', TreeModel.FitToArcGISTable, u'bg') 
    29502953 
    29512954AddArgumentMetadata(TreeModel.FitToArcGISTable, u'treePlotType', 
     
    34343437    arcGISCategory=_(u'Additional output options')) 
    34353438 
    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') 
     3439CopyArgumentMetadata(GLM.FitToArcGISTable, u'plotFileFormat', LinearMixedModel.FitToArcGISTable, u'plotFileFormat') 
     3440CopyArgumentMetadata(GLM.FitToArcGISTable, u'res', LinearMixedModel.FitToArcGISTable, u'res') 
     3441CopyArgumentMetadata(GLM.FitToArcGISTable, u'width', LinearMixedModel.FitToArcGISTable, u'width') 
     3442CopyArgumentMetadata(GLM.FitToArcGISTable, u'height', LinearMixedModel.FitToArcGISTable, u'height') 
     3443CopyArgumentMetadata(GLM.FitToArcGISTable, u'pointSize', LinearMixedModel.FitToArcGISTable, u'pointSize') 
     3444CopyArgumentMetadata(GLM.FitToArcGISTable, u'bg', LinearMixedModel.FitToArcGISTable, u'bg') 
    34423445 
    34433446CopyArgumentMetadata(GLM.FitToArcGISTable, u'overwriteExisting', LinearMixedModel.FitToArcGISTable, u'overwriteExisting') 
     
    37403743    typeMetadata=FileTypeMetadata(canBeNone=True, mustBeDifferentThanArguments=[u'inputModelFile'], deleteIfParameterIsTrue=u'overwriteExisting', createParentDirectories=True), 
    37413744    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."""), 
     3745u"""File to create for the plot. If this parameter is specified, the 
     3746plot will be written to the file rather than displayed on the screen. 
     3747 
     3748The file must have one of the following two extensions, which 
     3749determines 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"""), 
    37493762    direction=u'Output', 
    3750     arcGISDisplayName=_(u'Output PNG file'), 
     3763    arcGISDisplayName=_(u'Output file'), 
    37513764    arcGISCategory=_(u'Output file options')) 
    37523765 
     3766AddArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'res', 
     3767    typeMetadata=FloatTypeMetadata(mustBeGreaterThan=0.), 
     3768    description=_( 
     3769u"""PNG plot file resolution, in dots per inch (DPI). The default is 
     3770set to a high value (1000) because this is the minimum resolution 
     3771typically required by scientific journals that accept figures in PNG 
     3772format. 
     3773 
     3774This parameter is ignored for EMF format because it is a vector 
     3775format."""), 
     3776    arcGISDisplayName=_(u'Plot resolution, in DPI'), 
     3777    arcGISCategory=_(u'Output file options')) 
     3778 
    37533779AddArgumentMetadata(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=_( 
     3782u"""Plot file width in inches (for EMF format) or pixels (for PNG 
     3783format)."""), 
    37573784    arcGISDisplayName=_(u'Plot width'), 
    37583785    arcGISCategory=_(u'Output file options')) 
    37593786 
    37603787AddArgumentMetadata(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=_( 
     3790u"""Plot file width in inches (for EMF format) or pixels (for PNG 
     3791format)."""), 
    37643792    arcGISDisplayName=_(u'Plot height'), 
    37653793    arcGISCategory=_(u'Output file options')) 
     
    37683796    typeMetadata=FloatTypeMetadata(minValue=1.0), 
    37693797    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."""), 
     3798u"""The default pointsize of plotted text."""), 
    37723799    arcGISDisplayName=_(u'Default pointsize of plotted text'), 
    37733800    arcGISCategory=_(u'Output file options')) 
     
    37763803    typeMetadata=UnicodeStringTypeMetadata(), 
    37773804    description=_( 
    3778 u"""Background color for the output PNG file. The color must be a 
    3779 valid name in R's color palette, or "transparent" if there is no 
    3780 background color."""), 
     3805u"""PNG plot file background color. The color must be a valid name in 
     3806R's color palette, or "transparent" if there is no background color. 
     3807This parameter is ignored if the plot format file is EMF."""), 
    37813808    arcGISDisplayName=_(u'Plot background color'), 
    37823809    arcGISCategory=_(u'Output file options')) 
     
    38803907 
    38813908CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'outputPlotFile', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'outputPlotFile') 
     3909CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'res', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'res') 
    38823910CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'width', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'width') 
    38833911CopyArgumentMetadata(ModelEvaluation.PlotPerformanceOfBinaryClassificationModel, u'height', ModelEvaluation.PlotROCOfBinaryClassificationModel, u'height') 
  • MGET/Branches/Jason/PythonPackage/src/GeoEco/Statistics/ScatterplotMatrixForDataframe.r

    r339 r812  
    8484} 
    8585 
    86 ScatterplotMatrixToFile <- function(filename, df, transforms=NULL, .diag=NULL, lower=NULL, upper=NULL, width=480, height=480, pointsize=12.0, bg="white") 
     86ScatterplotMatrixToFile <- 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") 
    8787{ 
    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 
    8993    tryCatch(ScatterplotMatrix(df, transforms, .diag, lower, upper), finally=dev.off()) 
    9094}