Example #1
0
def makeSummary(year, month, day, julianDay, selectedObjects, imageLinks):
    headerStuff = [
        E.H2("Matsu Analytic Summary Report for {}-{}-{} (Julian day {})".format(year, month, day, julianDay)),
        E.TABLE(E.TR(E.TD(E.B("Analysis date:")), E.TD(time.ctime(time.time()))), style="margin-left: 20px;"),
        E.H3("Analytic Environment", style="margin-bottom: 5px;"),
        E.TABLE(E.TR(E.TD(E.B("Analytic")), E.TD("GMM-KNN")),
                E.TR(E.TD(E.B("Noise Correction Enabled")), E.TD("False")),
                E.TR(E.TD(E.B("Report Format")), E.TD("GMM-KNN v1")), style="margin-left: 20px;"),
        E.H3("Summary", style="margin-bottom: 5px;"),
        E.TABLE(E.TR(E.TD(E.B("Number of images:")), E.TD(" " + repr(len(imageLinks)))),
                E.TR(E.TD(E.B("Image reports:"), style="min-width: 130px;", valign="top"), E.TD(*[E.SPAN(" ", imageLinks[x]) for x in sorted(imageLinks.keys())])), style="margin-left: 20px;"),
        ]

    if len(selectedObjects) > 0:
        selectedObjects.sort(lambda a, b: cmp(a["score"][1], b["score"][1]))
        for rank, cluster in enumerate(selectedObjects):
            cluster["knnrank"] = rank + 1

        selectedObjects.sort(lambda a, b: cmp(a["score"][0], b["score"][0]))
        for rank, cluster in enumerate(selectedObjects):
            cluster["gmmrank"] = rank + 1

        anomalousObjects = E.TABLE(E.TR(E.TD(E.B("Rank (GMM)"), align="center", style="min-width: 100px;"), E.TD(E.B("Rank (KNN)"), align="center", style="min-width: 100px;"), E.TD(E.B("Image"), style="min-width: 230px;"), E.TD(E.B("Object id"), style="min-width: 80px;"), E.TD(E.B("Raw GMM score"), align="center", style="min-width: 120px;"), E.TD(E.B("Raw KNN score"), align="center", style="min-width: 120px;"), E.TD(E.B("Clump size (pixels)"), align="center", style="min-width: 150px;")), style="margin-left: 20px;")

        for cluster in selectedObjects:
            shortName = cluster["imageName"]
            imageLink = E.A(shortName, href=("image_reports/" + shortName + ".html"))
            anomalousObjects.append(E.TR(E.TD(repr(cluster["gmmrank"]), align="center", style="min-width: 100px;"), E.TD(repr(cluster["knnrank"]), align="center", style="min-width: 100px;"), E.TD(imageLink, style="min-width: 230px;"), E.TD(cluster["id"], style="min-width: 80px;"), E.TD("{:g}".format(cluster["score"][0]), align="center", style="min-width: 120px;"), E.TD("{:g}".format(math.log10(cluster["score"][1])), align="center", style="min-width: 120px;"), E.TD(repr(cluster["other"]["numPixels"]), align="center", style="min-width: 150px;")))

        scoresDistributionGMM = histogram("x", numBins=50, style="fill: darkviolet;", normalized=True, xlabel="Raw GMM score (low is anomalous)", ylabel="normalized histogram", width=1200, height=400).calc({"x": numpy.array([x["score"][0] for x in selectedObjects])})
        scoresDistributionGMM["width"] = "600"
        scoresDistributionGMM["height"] = "200"
        scoresDistributionGMM["style"] = scoresDistributionGMM["style"] + "; margin-left: 20px;"

        scoresDistributionKNN = histogram("x", numBins=50, style="fill: darkviolet;", normalized=True, xlabel="Raw KNN score (low is anomalous)", ylabel="normalized histogram", width=1200, height=400).calc({"x": numpy.array([math.log10(x["score"][1]) for x in selectedObjects])})
        scoresDistributionKNN["width"] = "600"
        scoresDistributionKNN["height"] = "200"
        scoresDistributionKNN["style"] = scoresDistributionKNN["style"] + "; margin-left: 20px;"

        html = E.HTML(
            E.HEAD(),
            E.BODY(
                *(headerStuff + [
                        E.H3("Most anomalous objects", style="margin-bottom: 5px;"),
                        scoresDistributionGMM,
                        scoresDistributionKNN,
                        anomalousObjects,
                        E.P(E.I("See the individual reports for hyperspectral details."))
                        ])))

    else:
        html = E.HTML(E.HEAD(), E.BODY(*(headerStuff + [E.H3("No anomalous objects today", style="margin-bottom: 5px;")])))
        
    print "    /var/www/reports/{}-{}/gmm-knn/summary-report-{}-{}-{}.html".format(year, month, year, month, day); sys.stdout.flush()
    open("/var/www/reports/{}-{}/gmm-knn/summary-report-{}-{}-{}.html".format(year, month, year, month, day), "w").write("<!DOCTYPE html>" + htmlToString(html))
Example #2
0
        E.TABLE(E.TR(E.TD(E.B("Image size:")), E.TD("{}x{} ({} pixels)".format(imageValue["metadata"]["width"], imageValue["metadata"]["height"], imageValue["metadata"]["width"]*imageValue["metadata"]["height"]))),
                E.TR(E.TD(E.B("Default RGB:")), E.TD("Bands 5, 4, 3")),
                E.TR(E.TD(E.B("Number of bands:")), E.TD(repr(len(wavelengths)))),
                E.TR(E.TD(E.B("File type:")), E.TD("GeoTIFF")),
                E.TR(E.TD(E.B("Units:")), E.TD("spectral radiance")),
                E.TR(E.TD(E.B("Sensor:")), E.TD("ALI")), style="margin-left: 20px;"),
        E.H3("Notes", style="margin-bottom: 5px;"),
        E.DIV(E.P("Objects are described in terms of four concentric sets of pixels:", style="margin-bottom: 0px;"), E.UL(E.LI(E.B("seeds:"), " extremely anomalous pixels that started the search"), E.LI(E.B("clump:"), " bucket-fill clump of contiguous semi-anomalous pixels"), E.LI(E.B("first border:"), " pixels adjacent to but not included in the clump"), E.LI(E.B("second border:"), " pixels adjacent to the first border"), style="margin-top: 0px;"),
              E.P("Selected objects are outlined in the image (at the second border).", style="margin-bottom: 0px;"), style="font-size: 11pt; margin-left: 20px;"))

    html = E.HTML(
        E.HEAD(),
        E.BODY(
            E.TABLE(E.TR(E.TD(E.I("(Click image to enlarge.)"), align="center")),
                    E.TR(E.TD(E.A(E.IMG(src=(shortName + ".svg"), width="400"), href=(shortName + ".svg")), align="center")), style="float: right;"),
            imageSummary,
            E.H3("Object details", style="margin-bottom: 5px; clear: right;"),
            E.P("No objects passed cuts.", style="margin-left: 20px;") if len(tableRows) == 0 else E.TABLE(*tableRows, width="100%", style="margin-left: 20px;")
        ))

    if makingReport:
        print "    writing /var/www/reports/{}-{}/gmm-knn/image_reports/{}.html".format(year, month, shortName); sys.stdout.flush()
        open("/var/www/reports/{}-{}/gmm-knn/image_reports/{}.html".format(year, month, shortName), "w").write("<!DOCTYPE html>" + htmlToString(html))

if lastJulianDay is not None:
    year = time.strftime("%Y", time.strptime(lastJulianDay, "%Y %j"))
    month = time.strftime("%m", time.strptime(lastJulianDay, "%Y %j"))
    day = time.strftime("%d", time.strptime(lastJulianDay, "%Y %j"))
    makeSummary(year, month, day, lastJulianDay, selectedObjects, imageLinks)