def createOutputGraphic(self, fileName, firstInd = None, maxInd = None):

        #### Set Progressor ####
        writeMSG = ARCPY.GetIDMessage(84186)
        ARCPY.SetProgressor("step", writeMSG, 0, 3, 1)
        ARCPY.AddMessage(writeMSG)

        #### Set Colors ####
        colors = NUM.array(["#4575B5", "#849EBA", "#C0CCBE", "#FFFFBF",
          "#FAB984", "#ED7551", "#D62F27"])
        cutoffs = NUM.array([-2.58, -1.96, -1.65, 1.65, 1.96, 2.58])

        #### Import Matplotlib ####
        pdfOutput = REPORT.openPDF(fileName)

        #### Set Base Figure ####
        title = ARCPY.GetIDMessage(84334)
        report = REPORT.startNewReport(22, title = title, landscape = True,
                                       titleFont = REPORT.ssTitleFont)
        grid = report.grid
        startRow = 1
        gridPlot = PLT.subplot2grid(grid.gridInfo, (startRow, 0),
                                    colspan = 20, rowspan = 16)

        #### Set Data ####
        distVals = []
        zVals = []
        for testIter in range(self.nIncrements):
            d, gi, ei, vi, zi, pv = self.giResults[testIter]
            distVals.append(d)
            zVals.append(zi)

        #### Plot Values ####
        zVals = NUM.array(zVals)
        binVals = NUM.digitize(zVals, cutoffs)
        binColors = colors[binVals]

        #### Line Graph First ####
        lines = PLT.plot(distVals, zVals, color='k', linestyle='-')

        #### Add Series and First/Max Points ####
        if firstInd != None:
            #### First Peak ####
            firstPoint = PLT.plot(distVals[firstInd], zVals[firstInd],
                                  color='#00FFFF', marker='o', alpha = 0.7,
                                  markeredgecolor='k', markersize = 14)

        if maxInd != None:
            #### Max Peak ####
            if maxInd != firstInd:
                maxPoint = PLT.plot(distVals[maxInd], zVals[maxInd],
                                    color='#00FFFF', marker='o', alpha = 0.7,
                                    markeredgecolor='k', markersize = 14)

        #### Points Next ####
        for ind, dist in enumerate(distVals):
            color = binColors[ind]
            points = PLT.plot(dist, zVals[ind], color=color, marker='o',
                              alpha = 0.7, markeredgecolor='k',
                              markersize = 8)

        #### Set Axis and Tick Labels ####
        yLabel = ARCPY.GetIDMessage(84335)
        distanceOut = self.ssdo.distanceInfo.outputString
        xLabel = ARCPY.GetIDMessage(84077).format(distanceOut)
        PYLAB.ylabel(yLabel, fontproperties = REPORT.ssLabFont, labelpad = 20)
        PYLAB.xlabel(xLabel, fontproperties = REPORT.ssLabFont, labelpad = 20)
        gridPlot.yaxis.grid(True, linestyle='-', which='major',
                            color='lightgrey', alpha=0.5)
        REPORT.setTickFontSize(gridPlot)

        #### Scoot Max Z ####
        minD, maxD = UTILS.increaseMinMax(distVals, multiplier = .15)
        minZ, maxZ = UTILS.increaseMinMax(zVals, multiplier = .15)
        PYLAB.ylim(ymin = minZ, ymax = maxZ)
        PYLAB.xlim(xmin = minD, xmax = maxD)

        #### Create Legend ####
        rColors = [ i for i in reversed(colors) ]
        grid.writeCell((startRow, 20), yLabel, colspan = 2,
                        fontObj = REPORT.ssBoldFont, justify = "right")
        labels = ["> 2.58", "1.96 - 2.58", "1.65 - 1.96", "-1.65 - 1.65",
                  "-1.96 - -1.65", "-2.58 - -1.96", "< -2.58"]

        gridCount = 0
        for ind, lab in enumerate(labels):
            color = rColors[ind]
            row = ind + 1 + startRow
            gridCount += 1

            #### Add Points ####
            gridLegend = PLT.subplot2grid(grid.gridInfo, (row, 20))
            PLT.plot(0.0, 0.0, color = color, marker = "o", alpha = .7)
            REPORT.clearGrid(gridLegend)

            #### Add Text ####
            gridLegend = PLT.subplot2grid(grid.gridInfo, (row, 21))
            PLT.text(0.0, 0.3, lab, fontproperties = REPORT.ssFont,
                     horizontalalignment = "left")
            REPORT.clearGrid(gridLegend)

        #### Add Peak Marker ####
        currentRow = startRow + gridCount + 1
        grid.createLineRow(currentRow, startCol = 20, endCol = 22)
        currentRow += 1

        gridLegend = PLT.subplot2grid(grid.gridInfo, (currentRow, 20))
        PLT.plot(0.0, 0.0, color='#00FFFF', marker='o', alpha = 0.4,
                 markeredgecolor='k', markersize = 14)
        REPORT.clearGrid(gridLegend)

        #### Add Text ####
        gridLegend = PLT.subplot2grid(grid.gridInfo, (currentRow, 21))
        PLT.text(0.0, 0.3, "Peaks", fontproperties = REPORT.ssFont,
                 horizontalalignment = "left")
        REPORT.clearGrid(gridLegend)

        #### Add To PDF ####
        PLT.savefig(pdfOutput, format='pdf')
        PLT.close()
        ARCPY.SetProgressorPosition()

        #### Tabular Output ####
        title = ARCPY.GetIDMessage(84160) + ARCPY.GetIDMessage(84282)
        titlePlus = title + " " + ARCPY.GetIDMessage(84377)
        report = REPORT.startNewReport(7, title = title, landscape = True,
                                       titleFont = REPORT.ssTitleFont)
        grid = report.grid

        #### Create Column Labels ####
        grid.createColumnLabels(self.resLabels, justify = "right",
                                fontObj = REPORT.ssBoldFont)

        #### Create Output Text Table ####
        hasNoNeighs = self.noNeighs.any()
        strNoNeighs = ARCPY.GetIDMessage(84111)
        for testIter in range(self.nIncrements):
            if grid.rowCount >= 19:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(7, title = titlePlus,
                                                   landscape = True,
                                     titleFont = REPORT.ssTitleFont)
                grid = report.grid

                #### Create Column Labels ####
                grid.createColumnLabels(self.resLabels, justify = "right",
                                        fontObj = REPORT.ssBoldFont)

            #### Get Results ####
            d, gi, ei, vi, zi, pv = self.giResults[testIter]
            d = LOCALE.format("%0.2f", round(d, 2))

            #### Add Asterisk to No Neigh Distances ####
            if hasNoNeighs:
                numNoNeighs = self.noNeighs[testIter]
                if numNoNeighs:
                    d += strNoNeighs
                else:
                    d += " "

            grid.writeCell((grid.rowCount, 0), d,
                            justify = "right")
            grid.writeCell((grid.rowCount, 1),
                            LOCALE.format("%0.6f", gi),
                            justify = "right")
            grid.writeCell((grid.rowCount, 2),
                            LOCALE.format("%0.6f", ei),
                            justify = "right")
            grid.writeCell((grid.rowCount, 3),
                            LOCALE.format("%0.6f", vi),
                            justify = "right")
            grid.writeCell((grid.rowCount, 4),
                            LOCALE.format("%0.6f", zi),
                            justify = "right")
            grid.writeCell((grid.rowCount, 5),
                            LOCALE.format("%0.6f", pv),
                            justify = "right")
            grid.stepRow()

        if grid.rowCount <= 19:
            grid.createLineRow(grid.rowCount, startCol = 0, endCol = 7)
            grid.stepRow()

        #### Add Footnotes, Peaks, Linear Unit, No Neighbor Message ####
        footNotes = []

        #### Report Peaks ####
        firstPeakMess = ARCPY.GetIDMessage(84419)
        decimalSep = UTILS.returnDecimalChar()
        if decimalSep == ".":
            numSep = ","
        else:
            numSep = ";"
        if self.firstPeakInd != None:
            zi = LOCALE.format("%0.6f", self.giResults[self.firstPeakInd,4])
            d = LOCALE.format("%0.2f", round(self.firstPeakDistance, 2))
            firstPeakMess = firstPeakMess.format(d, numSep, zi)
        else:
            firstPeakMess = firstPeakMess.format("None",numSep, "None")
        footNotes += REPORT.splitFootnote(firstPeakMess, 145)

        maxPeakMess = ARCPY.GetIDMessage(84420)
        if self.maxPeakInd != None:
            zi = LOCALE.format("%0.6f", self.giResults[self.maxPeakInd,4])
            d = LOCALE.format("%0.2f", round(self.maxPeakDistance, 2))
            maxPeakMess = maxPeakMess.format(d, numSep, zi)
        else:
            maxPeakMess = maxPeakMess.format("None",numSep, "None")
        footNotes += REPORT.splitFootnote(maxPeakMess, 145)

        #### Add Linear/Angular Unit ####
        distanceOut = self.ssdo.distanceInfo.outputString
        dmsg = ARCPY.GetIDMessage(84344)
        distanceMeasuredStr = dmsg.format(distanceOut)
        footNotes += REPORT.splitFootnote(distanceMeasuredStr, 145)

        #### Add No Neighbor Message ####
        if hasNoNeighs:
            noNeighMess = ARCPY.GetIDMessage(84417)
            footNotes += REPORT.splitFootnote(noNeighMess, 145)

        for line in footNotes:
            if grid.rowCount >= 19:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(7, title = titlePlus,
                                                   landscape = True,
                                     titleFont = REPORT.ssTitleFont)

                grid = report.grid

            #### Write Footnote ####
            grid.writeCell((grid.rowCount, 0), line,
                            colspan = 7, justify = "left")
            grid.stepRow()

        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        ##### Add Dataset/Parameter Info ####
        paramLabels = [84253, 84016, 84374, 84375, 84376, 84235, 84236, 84418]
        paramLabels = [ ARCPY.GetIDMessage(i) for i in paramLabels ]

        paramValues = [self.ssdo.inputFC, self.varName,
                       "%i" % self.nIncrements,
                       UTILS.formatValue(self.begDist),
                       UTILS.formatValue(self.dIncrement),
                       self.concept, "%s" % self.rowStandard,
                       str(self.ssdo.selectionSet)]

        title = ARCPY.GetIDMessage(84373)
        REPORT.createParameterPage(paramLabels, paramValues,
                                   title = title,
                                   pdfOutput = pdfOutput,
                                   titleFont = REPORT.ssTitleFont)

        #### Finish Up ####
        ARCPY.AddMessage(fileName)
        pdfOutput.close()
        ARCPY.SetProgressorPosition()
예제 #2
0
    def reportHTML(self, htmlFile = None):
        """Generates a graphical html report for General G."""

        #### Shorthand Attributes ####
        zg = self.zg

        #### Progress and Create HTML File Name ####
        writeMSG = ARCPY.GetIDMessage(84228)
        ARCPY.SetProgressor("default", writeMSG)
        ARCPY.AddMessage(writeMSG)
        if not htmlFile:
            prefix = ARCPY.GetIDMessage(84242)
            outputDir = UTILS.returnScratchWorkSpace()
            baseDir = UTILS.getBaseFolder(outputDir)
            htmlFile = UTILS.returnScratchName(prefix, fileType = "TEXT", 
                                               scratchWS = baseDir,
                                               extension = "html")

        #### Obtain Correct Images ####
        imageDir = UTILS.getImageDir()
        lowStr = ARCPY.GetIDMessage(84245)
        highStr = ARCPY.GetIDMessage(84246)
        if zg <= -2.58:
            imageFile = OS.path.join(imageDir, "lowGGValues01.png")
            info = ("1%", lowStr)
            imageBox = OS.path.join(imageDir, "dispersedBox01.png")
        elif (-2.58 < zg <= -1.96):
            imageFile = OS.path.join(imageDir, "lowGGValues05.png")
            info = ("5%", lowStr)
            imageBox = OS.path.join(imageDir, "dispersedBox05.png")
        elif (-1.96 < zg <= -1.65):
            imageFile = OS.path.join(imageDir, "lowGGValues10.png")
            info = ("10%", lowStr)
            imageBox = OS.path.join(imageDir, "dispersedBox10.png")
        elif (-1.65 < zg < 1.65):
            imageFile = OS.path.join(imageDir, "randomGGValues.png")
            imageBox = OS.path.join(imageDir, "randomBox.png")
        elif (1.65 <= zg < 1.96):
            imageFile = OS.path.join(imageDir, "highGGValues10.png")
            info = ("10%", highStr)
            imageBox = OS.path.join(imageDir, "clusteredBox10.png")
        elif (1.96 <= zg < 2.58):
            imageFile = OS.path.join(imageDir, "highGGValues05.png")
            info = ("5%", highStr)
            imageBox = OS.path.join(imageDir, "clusteredBox05.png")
        else:
            imageFile = OS.path.join(imageDir, "highGGValues01.png")
            info = ("1%", highStr)
            imageBox = OS.path.join(imageDir, "clusteredBox01.png")

        #### Footnote ####
        footStart = ARCPY.GetIDMessage(84230).format(zg)
        if abs(zg) >= 1.65:
            footEnd = ARCPY.GetIDMessage(84231)
            footEnd = footEnd.format(*info)
            footerText = footStart + footEnd 
        else:
            footEnd = ARCPY.GetIDMessage(84232)
            footerText = footStart + footEnd

        #### Root Element ####
        title = ARCPY.GetIDMessage(84247)
        reportElement, reportTree = REPORT.xmlReport(title = title)

        #### Begin Graphic SubElement ####
        graphicElement = REPORT.xmlGraphic(reportElement, imageFile, 
                                           footerText = footerText)

        #### Floating Table ####
        rowVals = [ [ARCPY.GetIDMessage(84153), self.ggString, ""],
                    [ARCPY.GetIDMessage(84151), self.zgString, imageBox],
                    [ARCPY.GetIDMessage(84152), self.pvString, ""] ]

        fTable = REPORT.xmlTable(graphicElement, rowVals, 
                                 tType = "ssFloat")

        #### General G Table ####
        rowVals = [ [ARCPY.GetIDMessage(84153), self.ggString],
                    [ARCPY.GetIDMessage(84154), self.egString],
                    [ARCPY.GetIDMessage(84150), self.vgString],
                    [ARCPY.GetIDMessage(84151), self.zgString],
                    [ARCPY.GetIDMessage(84152), self.pvString] ]

        mTable = REPORT.xmlTable(reportElement, rowVals,
                                 title = ARCPY.GetIDMessage(84159))

        #### Dataset Table ####
        rowVals = [ [UTILS.addColon(ARCPY.GetIDMessage(84233)), 
                     self.ssdo.inputFC],
                    [UTILS.addColon(ARCPY.GetIDMessage(84016)), 
                     self.varName],
                    [UTILS.addColon(ARCPY.GetIDMessage(84234)), 
                     WU.wTypeDispatch[self.wType]],
                    [UTILS.addColon(ARCPY.GetIDMessage(84235)),
                     self.concept],
                    [UTILS.addColon(ARCPY.GetIDMessage(84236)), 
                     str(self.rowStandard)],
                    [UTILS.addColon(ARCPY.GetIDMessage(84237)), 
                     self.thresholdStr],
                    [UTILS.addColon(ARCPY.GetIDMessage(84238)), 
                     str(self.weightsFile)],
                    [UTILS.addColon(ARCPY.GetIDMessage(84418)),
                     str(self.ssdo.selectionSet)] ]

        dTable = REPORT.xmlTable(reportElement, rowVals,
                                 title = ARCPY.GetIDMessage(84239))

        #### Create HTML ####
        html = REPORT.report2html(reportTree, htmlFile)
        ARCPY.AddMessage(htmlFile)

        return htmlFile
예제 #3
0
    def reportHTML(self, htmlFile = None):
        """Generates a graphical html report for Moran's I."""

        #### Shorthand Attributes ####
        zi = self.zi

        #### Progress and Create HTML File Name ####
        writeMSG = ARCPY.GetIDMessage(84228)
        ARCPY.SetProgressor("default", writeMSG)
        ARCPY.AddMessage(writeMSG)
        if not htmlFile:
            prefix = ARCPY.GetIDMessage(84227)
            outputDir = UTILS.returnScratchWorkSpace()
            baseDir = UTILS.getBaseFolder(outputDir)
            htmlFile = UTILS.returnScratchName(prefix, fileType = "TEXT", 
                                           scratchWS = baseDir,
                                           extension = "html")

        #### Obtain Correct Images ####
        imageDir = UTILS.getImageDir()
        clustStr = ARCPY.GetIDMessage(84243)
        dispStr = ARCPY.GetIDMessage(84244)
        if zi <= -2.58:
            imageFile = OS.path.join(imageDir, "dispersedValues01.png")
            info = ("1%", dispStr)
            imageBox = OS.path.join(imageDir, "dispersedBox01.png")
        elif (-2.58 < zi <= -1.96):
            imageFile = OS.path.join(imageDir, "dispersedValues05.png")
            info = ("5%", dispStr)
            imageBox = OS.path.join(imageDir, "dispersedBox05.png")
        elif (-1.96 < zi <= -1.65):
            imageFile = OS.path.join(imageDir, "dispersedValues10.png")
            info = ("10%", dispStr)
            imageBox = OS.path.join(imageDir, "dispersedBox10.png")
        elif (-1.65 < zi < 1.65):
            imageFile = OS.path.join(imageDir, "randomValues.png")
            imageBox = OS.path.join(imageDir, "randomBox.png")
        elif (1.65 <= zi < 1.96):
            imageFile = OS.path.join(imageDir, "clusteredValues10.png")
            info = ("10%", clustStr)
            imageBox = OS.path.join(imageDir, "clusteredBox10.png")
        elif (1.96 <= zi < 2.58):
            imageFile = OS.path.join(imageDir, "clusteredValues05.png")
            info = ("5%", clustStr)
            imageBox = OS.path.join(imageDir, "clusteredBox05.png")
        else:
            imageFile = OS.path.join(imageDir, "clusteredValues01.png")
            info = ("1%", clustStr)
            imageBox = OS.path.join(imageDir, "clusteredBox01.png")

        #### Footnote ####
        footStart = ARCPY.GetIDMessage(84230).format(zi)
        if abs(zi) >= 1.65:
            footEnd = ARCPY.GetIDMessage(84231)
            footEnd = footEnd.format(*info)
            footerText = footStart + footEnd 
        else:
            footEnd = ARCPY.GetIDMessage(84232)
            footerText = footStart + footEnd

        #### Root Element ####
        title = ARCPY.GetIDMessage(84229)
        reportElement, reportTree = REPORT.xmlReport(title = title)

        #### Begin Graphic SubElement ####
        graphicElement = REPORT.xmlGraphic(reportElement, imageFile, 
                                           footerText = footerText)

        #### Floating Table ####
        rowVals = [ [ARCPY.GetIDMessage(84148), self.giString, ""],
                    [ARCPY.GetIDMessage(84151), self.ziString, imageBox],
                    [ARCPY.GetIDMessage(84152), self.pvString, ""] ]

        fTable = REPORT.xmlTable(graphicElement, rowVals, 
                                 tType = "ssFloat")

        #### Moran Table ####
        rowVals = [ [ARCPY.GetIDMessage(84148), self.giString],
                    [ARCPY.GetIDMessage(84149), self.eiString],
                    [ARCPY.GetIDMessage(84150), self.viString],
                    [ARCPY.GetIDMessage(84151), self.ziString],
                    [ARCPY.GetIDMessage(84152), self.pvString] ]

        mTable = REPORT.xmlTable(reportElement, rowVals,
                                 title = ARCPY.GetIDMessage(84160))

        #### Dataset Table ####
        rowVals = [ [UTILS.addColon(ARCPY.GetIDMessage(84233)), 
                     self.ssdo.inputFC],
                    [UTILS.addColon(ARCPY.GetIDMessage(84016)), 
                     self.varName],
                    [UTILS.addColon(ARCPY.GetIDMessage(84234)), 
                     WU.wTypeDispatch[self.wType]],
                    [UTILS.addColon(ARCPY.GetIDMessage(84235)),
                     self.concept],
                    [UTILS.addColon(ARCPY.GetIDMessage(84236)), 
                     str(self.rowStandard)],
                    [UTILS.addColon(ARCPY.GetIDMessage(84237)), 
                     self.thresholdStr],
                    [UTILS.addColon(ARCPY.GetIDMessage(84238)), 
                     str(self.weightsFile)],
                    [UTILS.addColon(ARCPY.GetIDMessage(84418)),
                     str(self.ssdo.selectionSet)] ]

        dTable = REPORT.xmlTable(reportElement, rowVals,
                                 title = ARCPY.GetIDMessage(84239))

        #### Create HTML ####
        html = REPORT.report2html(reportTree, htmlFile)
        ARCPY.AddMessage(htmlFile)

        return htmlFile
def CreateTableReport(fileName,calc_values):
    pdfOutput = REPORT.openPDF(fileName)

    #Set up Table
    NumColumns = 4
    report = REPORT.startNewReport(NumColumns,
                                   title = 'Your Solar Energy Potential Report ',
                                   landscape = False,
                                   numRows = "", # probably empty
                                   titleFont = REPORT.ssTitleFont)
    grid = report.grid


    keys = ["PV System Investment ",
            "Area of rooftop (ft2)",
            "System size (Kw)",
            "Total Cost of System ($)",
            "      Rebates ($3.50/W)",
            "      Tax Credit (30%)",
            "Actual Cost ($)",
            "PV System & Savings ",
            "Total Annual Solar Energy (KwHm2/yr)",
            "System Peak Power Output (watts)",
            "System Annual Energy Output(KwH/yr)",
            "Average HouseHold Use (KwH/yr)",
            "Production Percentage",
            "Saving from usage ($/yr)",
            "Saving from net metering ($yr)",
            "Total Savings",
            "Years to Pay Back System "]

    vals = calc_values

    for keyInd, keyVal in enumerate(keys):
        cVal = vals[keyInd]
        #write item key to column 2
        if "PV System" in keyVal:
          grid.stepRow() # move to next row
          grid.createLineRow(grid.rowCount, startCol = 1, endCol = 3)
          grid.stepRow() # move to next row
          grid.writeCell((grid.rowCount, 1),
                   "{}   ".format(keyVal),
                   justify = "left",
                   fontObj = REPORT.ssBoldFont,
                   color = "Maroon",
                   )
          grid.stepRow() # move to next row
          grid.createLineRow(grid.rowCount, startCol = 1, endCol = 3)
        else:
          grid.writeCell((grid.rowCount, 1),
                   "{}  =".format(keyVal),
                   justify = "left",
                   )

        # write item value to column 3
        if cVal:
          if "Total Savings" in keyVal:
            grid.writeCell((grid.rowCount, 2),
                       round(cVal,2),
                       justify = "right",
                       fontObj = REPORT.ssBoldFont
                       )
          elif "Cost" in keyVal:
            grid.writeCell((grid.rowCount, 2),
                       round(cVal,2),
                       justify = "right",
                       fontObj = REPORT.ssBoldFont
                       )
          else:
            grid.writeCell((grid.rowCount, 2),
                     round(cVal,2),
                     justify = "right",
                     )
        grid.stepRow() # move to next row

    grid.createLineRow(grid.rowCount, startCol = 1, endCol = 3)
    grid.stepRow()
    grid.finalizeTable() # Will fill empty rows with spaces.
    report.write(pdfOutput) # write to PDF
    pdfOutput.close()

    return fileName
    def reportHTML(self, htmlFile=None):
        """Generates a graphical html report for Nearest Neighbor Stat."""

        #### Shorthand Attributes ####
        zScore = self.zn

        #### Progress and Create HTML File Name ####
        writeMSG = ARCPY.GetIDMessage(84228)
        ARCPY.SetProgressor("default", writeMSG)
        ARCPY.AddMessage(writeMSG)
        if not htmlFile:
            prefix = ARCPY.GetIDMessage(84240)
            outputDir = UTILS.returnScratchWorkSpace()
            baseDir = UTILS.getBaseFolder(outputDir)
            htmlFile = UTILS.returnScratchName(prefix,
                                               fileType="TEXT",
                                               scratchWS=baseDir,
                                               extension="html")

        #### Obtain Correct Images ####
        imageDir = UTILS.getImageDir()
        clustStr = ARCPY.GetIDMessage(84243)
        dispStr = ARCPY.GetIDMessage(84244)
        if zScore <= -2.58:
            imageFile = OS.path.join(imageDir, "clusteredPoints01.png")
            info = ("1%", clustStr)
            imageBox = OS.path.join(imageDir, "dispersedBox01.png")
        elif (-2.58 < zScore <= -1.96):
            imageFile = OS.path.join(imageDir, "clusteredPoints05.png")
            info = ("5%", clustStr)
            imageBox = OS.path.join(imageDir, "dispersedBox05.png")
        elif (-1.96 < zScore <= -1.65):
            imageFile = OS.path.join(imageDir, "clusteredPoints10.png")
            info = ("10%", clustStr)
            imageBox = OS.path.join(imageDir, "dispersedBox10.png")
        elif (-1.65 < zScore < 1.65):
            imageFile = OS.path.join(imageDir, "randomPoints.png")
            imageBox = OS.path.join(imageDir, "randomBox.png")
        elif (1.65 <= zScore < 1.96):
            imageFile = OS.path.join(imageDir, "dispersedPoints10.png")
            info = ("10%", dispStr)
            imageBox = OS.path.join(imageDir, "clusteredBox10.png")
        elif (1.96 <= zScore < 2.58):
            imageFile = OS.path.join(imageDir, "dispersedPoints05.png")
            info = ("5%", dispStr)
            imageBox = OS.path.join(imageDir, "clusteredBox05.png")
        else:
            imageFile = OS.path.join(imageDir, "dispersedPoints01.png")
            info = ("1%", dispStr)
            imageBox = OS.path.join(imageDir, "clusteredBox01.png")

        #### Footnote ####
        footStart = ARCPY.GetIDMessage(84230).format(zScore)
        if abs(zScore) >= 1.65:
            footEnd = ARCPY.GetIDMessage(84231)
            footEnd = footEnd.format(*info)
            footerText = footStart + footEnd
        else:
            footEnd = ARCPY.GetIDMessage(84232)
            footerText = footStart + footEnd

        #### Root Element ####
        title = ARCPY.GetIDMessage(84161)
        reportElement, reportTree = REPORT.xmlReport(title=title)

        #### Begin Graphic SubElement ####
        graphicElement = REPORT.xmlGraphic(reportElement,
                                           imageFile,
                                           footerText=footerText)

        #### Floating Table ####
        rowVals = [[ARCPY.GetIDMessage(84164), self.ratioString, ""],
                   [ARCPY.GetIDMessage(84151), self.znString, imageBox],
                   [ARCPY.GetIDMessage(84152), self.pvString, ""]]

        fTable = REPORT.xmlTable(graphicElement, rowVals, tType="ssFloat")

        #### NN Table ####
        rowVals = [[ARCPY.GetIDMessage(84162), self.nnStringD],
                   [ARCPY.GetIDMessage(84163), self.enStringD],
                   [ARCPY.GetIDMessage(84164), self.ratioString],
                   [ARCPY.GetIDMessage(84151), self.znString],
                   [ARCPY.GetIDMessage(84152), self.pvString]]

        nnTable = REPORT.xmlTable(reportElement,
                                  rowVals,
                                  title=ARCPY.GetIDMessage(84161))

        #### Dataset Table ####
        rowVals = [[
            UTILS.addColon(ARCPY.GetIDMessage(84233)), self.ssdo.inputFC
        ], [UTILS.addColon(ARCPY.GetIDMessage(84235)), self.concept],
                   [
                       UTILS.addColon(ARCPY.GetIDMessage(84241)),
                       LOCALE.format("%0.6f", self.studyArea)
                   ],
                   [
                       UTILS.addColon(ARCPY.GetIDMessage(84418)),
                       str(self.ssdo.selectionSet)
                   ]]

        dTable = REPORT.xmlTable(reportElement,
                                 rowVals,
                                 title=ARCPY.GetIDMessage(84239))

        #### Create HTML ####
        html = REPORT.report2html(reportTree, htmlFile)
        ARCPY.AddMessage(htmlFile)

        return htmlFile
예제 #6
0
    def createOutputGraphic(self, fileName):
        """Create OLS Output Report File.

        INPUTS
        fileName (str): path to output report file (*.pdf)
        """

        #### Set Progressor ####
        writeMSG = ARCPY.GetIDMessage(84186)
        ARCPY.SetProgressor("step", writeMSG, 0, 6, 1)
        ARCPY.AddMessage(writeMSG)

        #### Set Colors ####
        colors = NUM.array([
            "#4575B5", "#849EBA", "#C0CCBE", "#FFFFBF", "#FAB984", "#ED7551",
            "#D62F27"
        ])
        cutoffs = NUM.array([-2.5, -1.5, -0.5, 0.5, 1.5, 2.5])

        #### Set Data ####
        stdRes = self.stdRedisuals.flatten()
        predicted = self.yHat.flatten()

        #### Create PDF Output ####
        pdfOutput = REPORT.openPDF(fileName)

        ##### Make Coefficient Table ####
        title = ARCPY.GetIDMessage(84075) + " - " + ARCPY.GetIDMessage(84370)
        contStr = ARCPY.GetIDMessage(84377)
        varTitlePlus = title + " " + contStr

        numCols = 9
        report = REPORT.startNewReport(9,
                                       title=title,
                                       landscape=True,
                                       titleFont=REPORT.ssTitleFont)
        grid = report.grid
        colLabs = self.coefRaw[0]
        tabVals = self.coefRaw[1:]

        #### Create Column Labels ####
        writeVarColHeaders(grid, colLabs)

        #### Loop Through Explanatory Variables ####
        for row in UTILS.ssRange(self.k):
            if grid.rowCount >= 20:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(9,
                                               title=varTitlePlus,
                                               landscape=True,
                                               titleFont=REPORT.ssTitleFont)
                grid = report.grid
                writeVarColHeaders(grid, colLabs)

            #### Variable Name ####
            rowVals = tabVals[row]
            for ind, val in enumerate(rowVals):
                justify = "right"
                gridCell = PLT.subplot2grid(grid.gridInfo,
                                            (grid.rowCount, ind))
                if ind in [4, 7]:
                    if not val.count("*"):
                        x0 = .925
                elif ind == 0:
                    justify = "left"
                    x0 = 0.0
                else:
                    x0 = 1.0

                #### Limit Col Value Length to 12 ####
                if ind in [0, 1, 2, 5, 8]:
                    val = val[0:12]

                PLT.text(x0,
                         0.5,
                         val,
                         fontproperties=REPORT.ssFont,
                         horizontalalignment=justify,
                         **REPORT.bAlignment)
                REPORT.clearGrid(gridCell)

            grid.stepRow()
        grid.createLineRow(grid.rowCount, startCol=0, endCol=numCols)
        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        #### Diagnostic Table/Interpret Tables ####
        numCols = 6
        title = ARCPY.GetIDMessage(84076)
        titlePlus = title + " " + contStr
        report = REPORT.startNewReport(numCols,
                                       title=title,
                                       landscape=True,
                                       numRows=22,
                                       titleFont=REPORT.ssTitleFont)
        grid = report.grid
        ind2Col = {0: 0, 1: 1, 2: 3, 3: 5}

        for row in self.diagRaw:
            for ind, val in enumerate(row):
                #### Limit Col Length to 23 ####
                if ind not in [0, 2]:
                    val = val[0:23]

                #### Set Col Info ####
                justify = self.diagJustify[ind]
                if ind == 2:
                    colspan = 2
                else:
                    colspan = 1
                col = ind2Col[ind]
                grid.writeCell((grid.rowCount, col),
                               val,
                               justify=justify,
                               colspan=colspan)
            grid.stepRow()
        grid.createEmptyRow()

        #### Add Footnotes ####
        notesMSG = ARCPY.GetIDMessage(84081)
        grid.writeCell((grid.rowCount, 0),
                       notesMSG,
                       colspan=2,
                       fontObj=REPORT.ssBoldFont,
                       justify="left")
        grid.stepRow()

        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName is None:
            splitLineAt = 145
        else:
            splitLineAt = 100

        #### Draw Interpretation Notes ####
        for note in self.interpretRaw:
            text = " ".join(note)
            lines = REPORT.splitFootnote(text, splitLineAt)
            for line in lines:
                if grid.rowCount >= 22:
                    #### Finalize Page ####
                    grid.finalizeTable()
                    report.write(pdfOutput)

                    #### New Page ####
                    report = REPORT.startNewReport(
                        numCols,
                        title=titlePlus,
                        landscape=True,
                        numRows=22,
                        titleFont=REPORT.ssTitleFont)

                    grid = report.grid

                #### Write Footnote ####
                grid.writeCell((grid.rowCount, 0),
                               line,
                               colspan=2,
                               justify="left")
                grid.stepRow()

        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        ##### Make Scatterplot Matrices ####
        k = len(self.indVarNames)
        title = ARCPY.GetIDMessage(84371)
        titlePlus = title + " " + contStr
        report = REPORT.startNewReport(6,
                                       title=title,
                                       landscape=True,
                                       numRows=4,
                                       titleFont=REPORT.ssTitleFont)
        grid = report.grid

        #### Loop Through Explanatory Variables ####
        seq = list(NUM.arange(0, k, 5))
        if seq[-1] < k:
            seq.append(k)

        for ind, s in enumerate(seq[0:-1]):
            if grid.rowCount == 4:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(6,
                                               title=titlePlus,
                                               landscape=True,
                                               numRows=4,
                                               titleFont=REPORT.ssTitleFont)
                grid = report.grid

            #### New Group of Vars ####
            e = seq[ind + 1]
            values = self.x[:, (s + 1):(e + 1)]
            numVars = e - s
            varNames = self.indVarNames[s:e]
            lenRow = len(varNames)

            #### Histogram ####
            for vInd, vName in enumerate(varNames):
                data = values[:, vInd]
                gridHist = PLT.subplot2grid(grid.gridInfo,
                                            (grid.rowCount, vInd))
                PLT.hist(data)
                gridHist.xaxis.set_visible(False)
                gridHist.yaxis.set_visible(False)
                gridHist.set_title(vName[0:14],
                                   fontproperties=REPORT.ssBoldFont)

            #### Add Dep Var ####
            gridHist = PLT.subplot2grid(grid.gridInfo, (grid.rowCount, lenRow))
            PLT.hist(self.y)
            gridHist.xaxis.set_visible(False)
            gridHist.yaxis.set_visible(False)
            gridHist.set_title(self.depVarName[0:14],
                               fontproperties=REPORT.ssBoldFont)
            grid.stepRow()

            for vInd, vName in enumerate(varNames):
                xVals = values[:, vInd]
                m = NUM.polyfit(xVals, self.y, 1)
                yFit = NUM.polyval(m, xVals)
                gridScat = PLT.subplot2grid(grid.gridInfo,
                                            (grid.rowCount, vInd))
                PLT.scatter(xVals,
                            self.y,
                            s=10,
                            edgecolors=None,
                            linewidths=0.05)
                PLT.plot(xVals, yFit, color='k', lw=1, alpha=.7)
                gridScat.xaxis.set_visible(False)
                gridScat.yaxis.set_ticks([])
                if vInd == 0:
                    gridScat.yaxis.set_label_text(
                        self.depVarName[0:14],
                        fontproperties=REPORT.ssBoldFont)
            grid.stepRow()

        #### Add Help Text ####
        if grid.rowCount == 4:
            #### Finalize Page ####
            grid.finalizeTable()
            report.write(pdfOutput)

            #### New Page ####
            report = REPORT.startNewReport(6,
                                           title=titlePlus,
                                           landscape=True,
                                           numRows=4,
                                           titleFont=REPORT.ssTitleFont)
            grid = report.grid

        #### Get Help Info ####
        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName is None:
            splitLineAt = 110
        else:
            splitLineAt = 55
        helpTxt1 = REPORT.splitFootnote(ARCPY.GetIDMessage(84403), splitLineAt)
        helpTxt2 = REPORT.splitFootnote(ARCPY.GetIDMessage(84404), splitLineAt)
        helpTxt1 = "\n".join(helpTxt1)
        helpTxt2 = "\n".join(helpTxt2)
        helpTxt = helpTxt1 + "\n\n" + helpTxt2
        grid.writeCell((grid.rowCount, 0),
                       helpTxt,
                       fontObj=REPORT.ssBigFont,
                       colspan=6,
                       justify="left")
        grid.stepRow()

        #### Finalize Page ####
        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        #### Histogram of Residuals ####
        title = ARCPY.GetIDMessage(84341)
        titlePlus = title + " " + contStr
        numCols = 10
        report = REPORT.startNewReport(numCols,
                                       title=title,
                                       landscape=True,
                                       titleFont=REPORT.ssTitleFont,
                                       numRows=30)
        numRows = report.numRows
        grid = report.grid
        histGrid = PLT.subplot2grid((numRows, numCols), (0, 1),
                                    rowspan=22,
                                    colspan=numCols - 2)

        #### Add Histogram ####
        n, bins, patches = PLT.hist(stdRes,
                                    15,
                                    normed=True,
                                    facecolor='#8400A8',
                                    alpha=0.75)

        #### Bell Curve ####
        x = NUM.arange(-3.5, 3.5, 0.01)
        y = PYLAB.normpdf(x, 0, 1)
        PLT.plot(x, y, color='blue', lw=1, linestyle="-")

        #### Axis Info ####
        histGrid.yaxis.grid(True,
                            linestyle='-',
                            which='both',
                            color='lightgrey',
                            alpha=0.5)
        PYLAB.ylabel(ARCPY.GetIDMessage(84055),
                     fontproperties=REPORT.ssLabFont)
        PYLAB.xlabel(ARCPY.GetIDMessage(84337),
                     fontproperties=REPORT.ssLabFont)

        #### Text Box ####
        grid.rowCount = 25

        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName is None:
            splitLineAt = 120
        else:
            splitLineAt = 80

        infoRows = REPORT.splitFootnote(ARCPY.GetIDMessage(84421), splitLineAt)
        for row in infoRows:
            if grid.rowCount >= numRows:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(numCols,
                                               title=titlePlus,
                                               landscape=True,
                                               titleFont=REPORT.ssTitleFont)
                grid = report.grid

            grid.writeCell((grid.rowCount, 0),
                           row,
                           colspan=numCols,
                           justify="left",
                           fontObj=REPORT.ssBigFont)
            grid.stepRow()

        #### Add To PDF ####
        grid.finalizeTable()
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        #### Scatterplot of Std. Residuals and Predicted Y ####
        title = ARCPY.GetIDMessage(84336)
        numCols = 10
        report = REPORT.startNewReport(numCols,
                                       title=title,
                                       landscape=False,
                                       titleFont=REPORT.ssTitleFont,
                                       numRows=32)
        numRows = report.numRows
        grid = report.grid
        scatGrid = PLT.subplot2grid(grid.gridInfo, (0, 1),
                                    rowspan=20,
                                    colspan=numCols - 2)

        #### Best Fit Line ####
        sortedYHatInd = NUM.argsort(predicted)
        sortedYHat = predicted[sortedYHatInd]
        sortedSTDRes = stdRes[sortedYHatInd]
        m = NUM.polyfit(sortedYHat, sortedSTDRes, 1)
        yFit = NUM.polyval(m, sortedYHat)
        PLT.plot(sortedYHat, yFit, color='k', lw=2, alpha=.7)

        #### Plot Values ####
        binVals = NUM.digitize(stdRes, cutoffs)
        binColors = colors[binVals]
        scat = PLT.scatter(predicted, stdRes, s=30, c=binColors)

        #### Labels ####
        PYLAB.ylabel(ARCPY.GetIDMessage(84337),
                     fontproperties=REPORT.ssLabFont)
        PYLAB.xlabel(ARCPY.GetIDMessage(84338),
                     fontproperties=REPORT.ssLabFont)

        scatGrid.yaxis.grid(True,
                            linestyle='-',
                            which='both',
                            color='lightgrey',
                            alpha=0.5)

        #### Text Box ####
        grid.rowCount = 23

        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName is None:
            splitLineAt = 60
        else:
            splitLineAt = 30

        infoRows = REPORT.splitFootnote(ARCPY.GetIDMessage(84422), splitLineAt)
        numLines = len(infoRows)
        if numLines > 9:
            #### Place Text and Small Scatter on Next Page ####
            grid.finalizeTable()
            report.write(pdfOutput)

            #### New Page ####
            titlePlus = title + " " + contStr
            report = REPORT.startNewReport(numCols,
                                           title=titlePlus,
                                           landscape=False,
                                           titleFont=REPORT.ssTitleFont,
                                           numRows=32)
            grid = report.grid

        startGrid = grid.rowCount * 1
        for row in infoRows:
            grid.writeCell((grid.rowCount, 0),
                           row,
                           colspan=7,
                           justify="left",
                           fontObj=REPORT.ssBigFont)
            grid.stepRow()

        #### Random Scatter ####
        scatLines = 8
        smallScatGrid = PLT.subplot2grid(grid.gridInfo, (startGrid, 7),
                                         rowspan=scatLines,
                                         colspan=3)
        RAND.seed(seed=100)
        rN = 200
        randRes = RAND.normal(0, 1, (rN, ))
        randPred = RAND.normal(0, 1, (rN, ))
        randX = NUM.ones((rN, 2))
        randX[:, 1] = randRes
        coef, sumRes, rank, s = LA.lstsq(randX, randPred)
        randYHat = NUM.dot(randX, coef)
        randE = randPred - randYHat
        ess = (randE**2.0).sum()
        fdof = (rN - 2) * 1.0
        s2 = ess / fdof
        se = NUM.sqrt(s2)
        seRandE = randE / se

        sortedXP = NUM.argsort(randYHat)
        sRandPred = randYHat[sortedXP]
        sRandRes = seRandE[sortedXP]
        mRand = NUM.polyfit(sRandPred, sRandRes, 1)
        yRandFit = NUM.polyval(mRand, sRandPred)
        PLT.plot(sRandPred, yRandFit, color='k', lw=1, alpha=.7)

        binValsR = NUM.digitize(seRandE, cutoffs)
        binColorsR = colors[binValsR]
        scat = PLT.scatter(randYHat,
                           seRandE,
                           s=10,
                           c=binColorsR,
                           edgecolors=None,
                           linewidths=0.05)
        smallScatGrid.yaxis.grid(True,
                                 linestyle='-',
                                 which='both',
                                 color='lightgrey',
                                 alpha=0.5)
        smallScatGrid.yaxis.set_ticks([0])
        smallScatGrid.yaxis.set_ticklabels([])
        meanY = randYHat.mean()
        smallScatGrid.xaxis.set_ticks([meanY])
        smallScatGrid.xaxis.set_ticklabels([ARCPY.GetIDMessage(84340)],
                                           fontproperties=REPORT.ssLabFont)
        RAND.seed()

        #### Adjust Row Count to End of Lines/Scatter ####
        if numLines < scatLines:
            grid.rowCount = startGrid + scatLines

        #### Add To PDF ####
        grid.finalizeTable()
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        ##### Add Dataset/Parameter Info ####
        paramLabels = [84253, 84359, 84360, 84112]
        paramLabels = [ARCPY.GetIDMessage(i) for i in paramLabels]
        paramValues = [
            self.ssdo.inputFC, self.ssdo.masterField, self.ssdo.templateFC,
            self.depVarName
        ]

        #### Set Analysis Field Names ####
        countRows = len(paramLabels) + 1
        maxVarLen = 100
        varLines = [i[0:(maxVarLen - 1)] for i in self.indVarNames]
        for ind, varLine in enumerate(varLines):
            if ind == 0:
                paramLabels.append(ARCPY.GetIDMessage(84402))
            elif countRows >= 20:
                paramLabels.append(ARCPY.GetIDMessage(84402))
                countRows = 1
            else:
                paramLabels.append("")
            countRows += 1
            paramValues.append(varLine)

        #### Add Selection Set Boolean ####
        paramLabels.append(ARCPY.GetIDMessage(84418))
        paramValues.append(str(self.ssdo.selectionSet))

        title = ARCPY.GetIDMessage(84372)
        REPORT.createParameterPage(paramLabels,
                                   paramValues,
                                   title=title,
                                   pdfOutput=pdfOutput,
                                   titleFont=REPORT.ssTitleFont)
        ARCPY.SetProgressorPosition()

        #### Finish Up ####
        ARCPY.AddMessage(fileName)
        pdfOutput.close()
예제 #7
0
    def createOutputGraphic(self, fileName):
        """Create OLS Output Report File.

        INPUTS
        fileName (str): path to output report file (*.pdf)
        """

        #### Set Progressor ####
        writeMSG = ARCPY.GetIDMessage(84186)
        ARCPY.SetProgressor("step", writeMSG, 0, 6, 1)
        ARCPY.AddMessage(writeMSG)

        #### Set Colors ####
        colors = NUM.array(["#4575B5", "#849EBA", "#C0CCBE", "#FFFFBF",
          "#FAB984", "#ED7551", "#D62F27"])
        cutoffs = NUM.array([-2.5, -1.5, -0.5, 0.5, 1.5, 2.5])

        #### Set Data ####
        stdRes = self.stdRedisuals.flatten()
        predicted = self.yHat.flatten()

        #### Create PDF Output ####
        pdfOutput = REPORT.openPDF(fileName)

        ##### Make Coefficient Table ####
        title = ARCPY.GetIDMessage(84075) + " - " + ARCPY.GetIDMessage(84370)
        contStr = ARCPY.GetIDMessage(84377)
        varTitlePlus = title + " " + contStr

        numCols = 9
        report = REPORT.startNewReport(9, title = title, landscape = True,
                                       titleFont = REPORT.ssTitleFont)
        grid = report.grid
        colLabs = self.coefRaw[0]
        tabVals = self.coefRaw[1:]

        #### Create Column Labels ####
        writeVarColHeaders(grid, colLabs)

        #### Loop Through Explanatory Variables ####
        for row in xrange(self.k):
            if grid.rowCount >= 20:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(9, title = varTitlePlus,
                                               landscape = True,
                                               titleFont = REPORT.ssTitleFont)
                grid = report.grid
                writeVarColHeaders(grid, colLabs)

            #### Variable Name ####
            rowVals = tabVals[row]
            for ind, val in enumerate(rowVals):
                justify = "right"
                gridCell = PLT.subplot2grid(grid.gridInfo,
                                            (grid.rowCount, ind))
                if ind in [4, 7]:
                    if not val.count("*"):
                        x0 = .925
                elif ind == 0:
                    justify = "left"
                    x0 = 0.0
                else:
                    x0 = 1.0

                #### Limit Col Value Length to 12 ####
                if ind in [0, 1, 2, 5, 8]:
                    val = val[0:12]

                PLT.text(x0, 0.5, val,
                         fontproperties = REPORT.ssFont,
                         horizontalalignment = justify,
                         **REPORT.bAlignment)
                REPORT.clearGrid(gridCell)

            grid.stepRow()
        grid.createLineRow(grid.rowCount, startCol = 0, endCol = numCols)
        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        #### Diagnostic Table/Interpret Tables ####
        numCols = 6
        title = ARCPY.GetIDMessage(84076)
        titlePlus = title + " " + contStr
        report = REPORT.startNewReport(numCols, title = title,
                                       landscape = True, numRows = 22,
                                       titleFont = REPORT.ssTitleFont)
        grid = report.grid
        ind2Col = {0:0, 1:1, 2:3, 3:5}

        for row in self.diagRaw:
            for ind, val in enumerate(row):
                #### Limit Col Length to 23 ####
                if ind not in [0,2]:
                    val = val[0:23]

                #### Set Col Info ####
                justify = self.diagJustify[ind]
                if ind == 2:
                    colspan = 2
                else:
                    colspan = 1
                col = ind2Col[ind]
                grid.writeCell((grid.rowCount, col), val,
                                justify = justify, colspan = colspan)
            grid.stepRow()
        grid.createEmptyRow()

        #### Add Footnotes ####
        notesMSG = ARCPY.GetIDMessage(84081)
        grid.writeCell((grid.rowCount, 0), notesMSG,
                        colspan = 2, fontObj = REPORT.ssBoldFont,
                        justify = "left")
        grid.stepRow()


        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName == None:
            splitLineAt = 145
        else:
            splitLineAt = 100

        #### Draw Interpretation Notes ####
        for note in self.interpretRaw:
            text = " ".join(note)
            lines = REPORT.splitFootnote(text, splitLineAt)
            for line in lines:
                if grid.rowCount >= 22:
                    #### Finalize Page ####
                    grid.finalizeTable()
                    report.write(pdfOutput)

                    #### New Page ####
                    report = REPORT.startNewReport(numCols, title = titlePlus,
                                               landscape = True, numRows = 22,
                                               titleFont = REPORT.ssTitleFont)

                    grid = report.grid

                #### Write Footnote ####
                grid.writeCell((grid.rowCount, 0), line,
                                colspan = 2, justify = "left")
                grid.stepRow()

        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        ##### Make Scatterplot Matrices ####
        k = len(self.indVarNames)
        title = ARCPY.GetIDMessage(84371)
        titlePlus = title + " " + contStr
        report = REPORT.startNewReport(6, title = title,
                                       landscape = True, numRows = 4,
                                       titleFont = REPORT.ssTitleFont)
        grid = report.grid

        #### Loop Through Explanatory Variables ####
        seq = list(NUM.arange(0, k, 5))
        if seq[-1] < k:
            seq.append(k)

        for ind, s in enumerate(seq[0:-1]):
            if grid.rowCount == 4:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(6, title = titlePlus,
                                               landscape = True, numRows = 4,
                                               titleFont = REPORT.ssTitleFont)
                grid = report.grid

            #### New Group of Vars ####
            e = seq[ind + 1]
            values = self.x[:,(s+1):(e+1)]
            numVars = e - s
            varNames = self.indVarNames[s:e]
            lenRow = len(varNames)

            #### Histogram ####
            for vInd, vName in enumerate(varNames):
                data = values[:,vInd]
                gridHist = PLT.subplot2grid(grid.gridInfo,
                                    (grid.rowCount, vInd))
                PLT.hist(data)
                gridHist.xaxis.set_visible(False)
                gridHist.yaxis.set_visible(False)
                gridHist.set_title(vName[0:14],
                                   fontproperties = REPORT.ssBoldFont)


            #### Add Dep Var ####
            gridHist = PLT.subplot2grid(grid.gridInfo, (grid.rowCount, lenRow))
            PLT.hist(self.y)
            gridHist.xaxis.set_visible(False)
            gridHist.yaxis.set_visible(False)
            gridHist.set_title(self.depVarName[0:14],
                               fontproperties = REPORT.ssBoldFont)
            grid.stepRow()

            for vInd, vName in enumerate(varNames):
                xVals = values[:,vInd]
                m = NUM.polyfit(xVals, self.y, 1)
                yFit = NUM.polyval(m, xVals)
                gridScat = PLT.subplot2grid(grid.gridInfo,
                                    (grid.rowCount, vInd))
                PLT.scatter(xVals, self.y, s = 10, edgecolors = None,
                            linewidths = 0.05)
                PLT.plot(xVals, yFit, color='k', lw = 1, alpha = .7)
                gridScat.xaxis.set_visible(False)
                gridScat.yaxis.set_ticks([])
                if vInd == 0:
                    gridScat.yaxis.set_label_text(self.depVarName[0:14],
                                     fontproperties = REPORT.ssBoldFont)
            grid.stepRow()


        #### Add Help Text ####
        if grid.rowCount == 4:
            #### Finalize Page ####
            grid.finalizeTable()
            report.write(pdfOutput)

            #### New Page ####
            report = REPORT.startNewReport(6, title = titlePlus,
                                           landscape = True, numRows = 4,
                                           titleFont = REPORT.ssTitleFont)
            grid = report.grid

        #### Get Help Info ####
        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName == None:
            splitLineAt = 110
        else:
            splitLineAt = 55
        helpTxt1 = REPORT.splitFootnote(ARCPY.GetIDMessage(84403), splitLineAt)
        helpTxt2 = REPORT.splitFootnote(ARCPY.GetIDMessage(84404), splitLineAt)
        helpTxt1 = "\n".join(helpTxt1)
        helpTxt2 = "\n".join(helpTxt2)
        helpTxt = helpTxt1 + "\n\n" + helpTxt2
        grid.writeCell((grid.rowCount, 0), helpTxt,
                        fontObj = REPORT.ssBigFont,
                        colspan = 6, justify = "left")
        grid.stepRow()

        #### Finalize Page ####
        grid.finalizeTable()

        #### Add To PDF ####
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        #### Histogram of Residuals ####
        title = ARCPY.GetIDMessage(84341)
        titlePlus = title + " " + contStr
        numCols = 10
        report = REPORT.startNewReport(numCols, title = title,
                                       landscape = True,
                                       titleFont = REPORT.ssTitleFont,
                                       numRows = 30)
        numRows = report.numRows
        grid = report.grid
        histGrid = PLT.subplot2grid((numRows, numCols), (0, 1),
                                    rowspan=22, colspan=numCols-2)

        #### Add Histogram ####
        n, bins, patches = PLT.hist(stdRes, 15, normed = True,
                                    facecolor='#8400A8', alpha=0.75)

        #### Bell Curve ####
        x = NUM.arange(-3.5, 3.5, 0.01)
        y = PYLAB.normpdf(x, 0, 1)
        PLT.plot(x, y, color='blue', lw=1, linestyle = "-")

        #### Axis Info ####
        histGrid.yaxis.grid(True, linestyle='-', which='both',
                            color='lightgrey', alpha=0.5)
        PYLAB.ylabel(ARCPY.GetIDMessage(84055),
                     fontproperties = REPORT.ssLabFont)
        PYLAB.xlabel(ARCPY.GetIDMessage(84337),
                     fontproperties = REPORT.ssLabFont)

        #### Text Box ####
        grid.rowCount = 25

        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName == None:
            splitLineAt = 120
        else:
            splitLineAt = 80

        infoRows = REPORT.splitFootnote(ARCPY.GetIDMessage(84421),
                                        splitLineAt)
        for row in infoRows:
            if grid.rowCount >= numRows:
                #### Finalize Page ####
                grid.finalizeTable()
                report.write(pdfOutput)

                #### New Page ####
                report = REPORT.startNewReport(numCols, title = titlePlus,
                                               landscape = True,
                                               titleFont = REPORT.ssTitleFont)
                grid = report.grid

            grid.writeCell((grid.rowCount, 0), row, colspan = numCols,
                           justify = "left", fontObj = REPORT.ssBigFont)
            grid.stepRow()

        #### Add To PDF ####
        grid.finalizeTable()
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        #### Scatterplot of Std. Residuals and Predicted Y ####
        title = ARCPY.GetIDMessage(84336)
        numCols = 10
        report = REPORT.startNewReport(numCols, title = title,
                                       landscape = False,
                                       titleFont = REPORT.ssTitleFont,
                                       numRows = 32)
        numRows = report.numRows
        grid = report.grid
        scatGrid = PLT.subplot2grid(grid.gridInfo, (0, 1),
                                    rowspan = 20, colspan = numCols-2)

        #### Best Fit Line ####
        sortedYHatInd = NUM.argsort(predicted)
        sortedYHat = predicted[sortedYHatInd]
        sortedSTDRes = stdRes[sortedYHatInd]
        m = NUM.polyfit(sortedYHat, sortedSTDRes, 1)
        yFit = NUM.polyval(m, sortedYHat)
        PLT.plot(sortedYHat, yFit, color='k', lw = 2, alpha = .7)

        #### Plot Values ####
        binVals = NUM.digitize(stdRes, cutoffs)
        binColors = colors[binVals]
        scat = PLT.scatter(predicted, stdRes, s = 30, c = binColors)

        #### Labels ####
        PYLAB.ylabel(ARCPY.GetIDMessage(84337),
                     fontproperties = REPORT.ssLabFont)
        PYLAB.xlabel(ARCPY.GetIDMessage(84338),
                     fontproperties = REPORT.ssLabFont)

        scatGrid.yaxis.grid(True, linestyle='-', which='both',
                            color='lightgrey', alpha=0.5)

        #### Text Box ####
        grid.rowCount = 23

        #### Set Line Width Based on Non-Latin Font File ####
        if REPORT.fontFilePathName == None:
            splitLineAt = 60
        else:
            splitLineAt = 30

        infoRows = REPORT.splitFootnote(ARCPY.GetIDMessage(84422),
                                        splitLineAt)
        numLines = len(infoRows)
        if numLines > 9:
            #### Place Text and Small Scatter on Next Page ####
            grid.finalizeTable()
            report.write(pdfOutput)

            #### New Page ####
            titlePlus = title + " " + contStr
            report = REPORT.startNewReport(numCols, title = titlePlus,
                                           landscape = False,
                                           titleFont = REPORT.ssTitleFont,
                                           numRows = 32)
            grid = report.grid

        startGrid = grid.rowCount * 1
        for row in infoRows:
            grid.writeCell((grid.rowCount, 0), row, colspan = 7,
                           justify = "left", fontObj = REPORT.ssBigFont)
            grid.stepRow()

        #### Random Scatter ####
        scatLines = 8
        smallScatGrid = PLT.subplot2grid(grid.gridInfo, (startGrid, 7),
                                         rowspan = scatLines, colspan = 3)
        RAND.seed(seed=100)
        rN = 200
        randRes = RAND.normal(0, 1, (rN,))
        randPred = RAND.normal(0, 1, (rN,))
        randX = NUM.ones((rN,2))
        randX[:,1] = randRes
        coef, sumRes, rank, s = LA.lstsq(randX, randPred)
        randYHat = NUM.dot(randX, coef)
        randE = randPred - randYHat
        ess = (randE**2.0).sum()
        fdof = (rN - 2) * 1.0
        s2 = ess / fdof
        se = NUM.sqrt(s2)
        seRandE = randE / se

        sortedXP = NUM.argsort(randYHat)
        sRandPred = randYHat[sortedXP]
        sRandRes = seRandE[sortedXP]
        mRand = NUM.polyfit(sRandPred, sRandRes, 1)
        yRandFit = NUM.polyval(mRand, sRandPred)
        PLT.plot(sRandPred, yRandFit, color='k', lw = 1, alpha = .7)

        binValsR = NUM.digitize(seRandE, cutoffs)
        binColorsR = colors[binValsR]
        scat = PLT.scatter(randYHat, seRandE, s = 10, c = binColorsR,
                           edgecolors = None, linewidths = 0.05)
        smallScatGrid.yaxis.grid(True, linestyle='-', which='both',
                                 color='lightgrey', alpha=0.5)
        smallScatGrid.yaxis.set_ticks([0])
        smallScatGrid.yaxis.set_ticklabels([])
        meanY = randYHat.mean()
        smallScatGrid.xaxis.set_ticks([meanY])
        smallScatGrid.xaxis.set_ticklabels([ARCPY.GetIDMessage(84340)],
                                 fontproperties = REPORT.ssLabFont)
        RAND.seed()

        #### Adjust Row Count to End of Lines/Scatter ####
        if numLines < scatLines:
            grid.rowCount = startGrid + scatLines

        #### Add To PDF ####
        grid.finalizeTable()
        report.write(pdfOutput)
        ARCPY.SetProgressorPosition()

        ##### Add Dataset/Parameter Info ####
        paramLabels = [84253, 84359, 84360, 84112]
        paramLabels = [ ARCPY.GetIDMessage(i) for i in paramLabels ]
        paramValues = [self.ssdo.inputFC, self.ssdo.masterField,
                       self.ssdo.templateFC, self.depVarName]

        #### Set Analysis Field Names ####
        countRows = len(paramLabels) + 1
        maxVarLen = 100
        varLines = [ i[0:(maxVarLen - 1)] for i in self.indVarNames ]
        for ind, varLine in enumerate(varLines):
            if ind == 0:
                paramLabels.append(ARCPY.GetIDMessage(84402))
            elif countRows >= 20:
                paramLabels.append(ARCPY.GetIDMessage(84402))
                countRows = 1
            else:
                paramLabels.append("")
            countRows += 1
            paramValues.append(varLine)

        #### Add Selection Set Boolean ####
        paramLabels.append(ARCPY.GetIDMessage(84418))
        paramValues.append(str(self.ssdo.selectionSet))

        title = ARCPY.GetIDMessage(84372)
        REPORT.createParameterPage(paramLabels, paramValues,
                                   title = title,
                                   pdfOutput = pdfOutput,
                                   titleFont = REPORT.ssTitleFont)
        ARCPY.SetProgressorPosition()

        #### Finish Up ####
        ARCPY.AddMessage(fileName)
        pdfOutput.close()
예제 #8
0
    def reportHTML(self, htmlFile = None):
        """Generates a graphical html report for Nearest Neighbor Stat."""

        #### Shorthand Attributes ####
        zScore = self.zn

        #### Progress and Create HTML File Name ####
        writeMSG = ARCPY.GetIDMessage(84228)
        ARCPY.SetProgressor("default", writeMSG)
        ARCPY.AddMessage(writeMSG)
        if not htmlFile:
            prefix = ARCPY.GetIDMessage(84240)
            outputDir = UTILS.returnScratchWorkSpace()
            baseDir = UTILS.getBaseFolder(outputDir)
            htmlFile = UTILS.returnScratchName(prefix, fileType = "TEXT", 
                                               scratchWS = baseDir,
                                               extension = "html")

        #### Obtain Correct Images ####
        imageDir = UTILS.getImageDir()
        clustStr = ARCPY.GetIDMessage(84243)
        dispStr = ARCPY.GetIDMessage(84244)
        if zScore <= -2.58:
            imageFile = OS.path.join(imageDir, "clusteredPoints01.png")
            info = ("1%", clustStr)
            imageBox = OS.path.join(imageDir, "dispersedBox01.png")
        elif (-2.58 < zScore <= -1.96):
            imageFile = OS.path.join(imageDir, "clusteredPoints05.png")
            info = ("5%", clustStr)
            imageBox = OS.path.join(imageDir, "dispersedBox05.png")
        elif (-1.96 < zScore <= -1.65):
            imageFile = OS.path.join(imageDir, "clusteredPoints10.png")
            info = ("10%", clustStr)
            imageBox = OS.path.join(imageDir, "dispersedBox10.png")
        elif (-1.65 < zScore < 1.65):
            imageFile = OS.path.join(imageDir, "randomPoints.png")
            imageBox = OS.path.join(imageDir, "randomBox.png")
        elif (1.65 <= zScore < 1.96):
            imageFile = OS.path.join(imageDir, "dispersedPoints10.png")
            info = ("10%", dispStr)
            imageBox = OS.path.join(imageDir, "clusteredBox10.png")
        elif (1.96 <= zScore < 2.58):
            imageFile = OS.path.join(imageDir, "dispersedPoints05.png")
            info = ("5%", dispStr)
            imageBox = OS.path.join(imageDir, "clusteredBox05.png")
        else:
            imageFile = OS.path.join(imageDir, "dispersedPoints01.png")
            info = ("1%", dispStr)
            imageBox = OS.path.join(imageDir, "clusteredBox01.png")

        #### Footnote ####
        footStart = ARCPY.GetIDMessage(84230).format(zScore)
        if abs(zScore) >= 1.65:
            footEnd = ARCPY.GetIDMessage(84231)
            footEnd = footEnd.format(*info)
            footerText = footStart + footEnd 
        else:
            footEnd = ARCPY.GetIDMessage(84232)
            footerText = footStart + footEnd

        #### Root Element ####
        title = ARCPY.GetIDMessage(84161)
        reportElement, reportTree = REPORT.xmlReport(title = title)

        #### Begin Graphic SubElement ####
        graphicElement = REPORT.xmlGraphic(reportElement, imageFile, 
                                           footerText = footerText)

        #### Floating Table ####
        rowVals = [ [ARCPY.GetIDMessage(84164), self.ratioString, ""],
                    [ARCPY.GetIDMessage(84151), self.znString, imageBox],
                    [ARCPY.GetIDMessage(84152), self.pvString, ""] ]

        fTable = REPORT.xmlTable(graphicElement, rowVals, 
                                 tType = "ssFloat")

        #### NN Table ####
        rowVals = [ [ARCPY.GetIDMessage(84162), self.nnStringD],
                    [ARCPY.GetIDMessage(84163), self.enStringD],
                    [ARCPY.GetIDMessage(84164), self.ratioString],
                    [ARCPY.GetIDMessage(84151), self.znString],
                    [ARCPY.GetIDMessage(84152), self.pvString] ]

        nnTable = REPORT.xmlTable(reportElement, rowVals,
                                  title = ARCPY.GetIDMessage(84161))

        #### Dataset Table ####
        rowVals = [ [UTILS.addColon(ARCPY.GetIDMessage(84233)), 
                     self.ssdo.inputFC],
                    [UTILS.addColon(ARCPY.GetIDMessage(84235)),
                     self.concept],
                    [UTILS.addColon(ARCPY.GetIDMessage(84241)), 
                     LOCALE.format("%0.6f", self.studyArea)],
                    [UTILS.addColon(ARCPY.GetIDMessage(84418)),
                     str(self.ssdo.selectionSet)] ]

        dTable = REPORT.xmlTable(reportElement, rowVals,
                         title = ARCPY.GetIDMessage(84239))

        #### Create HTML ####
        html = REPORT.report2html(reportTree, htmlFile)
        ARCPY.AddMessage(htmlFile)

        return htmlFile