示例#1
0
 def ipe_metadata(self):
     if self._ipe_metadata is None:
         try:
             self._ipe_metadata = get_ipe_metadata(self.interface.gbdx_connection, self.ipe_id, self.ipe_node_id)
         except BadRequest:
             raise
     return self._ipe_metadata
示例#2
0
 def metadata(self):
     assert self.graph() is not None
     if self._ipe_meta is not None:
         return self._ipe_meta
     if self._interface is not None:
         self._ipe_meta = get_ipe_metadata(
             self._interface.gbdx_futures_session, self._ipe_id, self._id)
     return self._ipe_meta
示例#3
0
    def graph(self, conn=None):
        if (self._ipe_id is not None and self._ipe_graph is not None):
            return self._ipe_graph

        _nodes = [{k: v
                   for k, v in node.items() if not k.startswith('_')}
                  for node in self._nodes]
        graph = {"edges": self._edges, "nodes": _nodes}

        if self._interface is not None and conn is None:
            conn = self._interface.gbdx_futures_session

        if conn is not None:
            self._ipe_id = register_ipe_graph(conn, graph)
            self._ipe_graph = graph
            self._ipe_meta = get_ipe_metadata(conn, self._ipe_id, self._id)
            return self._ipe_graph

        return graph
示例#4
0
def generate_vrt_template(conn, ipe_id, node, level, num_bands=None):
    meta = get_ipe_metadata(conn, ipe_id, node=node)
    image_md = meta['image']
    if num_bands is None:
        num_bands = image_md["numBands"]
    tfm = meta['georef']
    tile_size_x = image_md['tileXSize']
    tile_size_y = image_md['tileYSize']

    vrt = ET.Element("VRTDataset",
                     {"rasterXSize": str(image_md["imageWidth"]), "rasterYSize": str(image_md["imageHeight"])})
    ET.SubElement(vrt, "SRS").text = tfm["spatialReferenceSystemCode"]
    ET.SubElement(vrt, "GeoTransform").text = ", ".join(map(str, [tfm["translateX"],
                                                                  tfm["scaleX"],
                                                                  tfm["shearX"],
                                                                  tfm["translateY"],
                                                                  tfm["shearY"],
                                                                  tfm["scaleY"]]))

    for i in xrange(num_bands):
        bidx = i + 1
        band = ET.SubElement(vrt, "VRTRasterBand",
                             {"dataType": NODE_DATA_TYPES.get(node, "Float32"), "band": str(bidx)})
        for x, y in product(xrange(image_md['numXTiles']), xrange(image_md['numYTiles'])):
            src = ET.SubElement(band, "ComplexSource")
            ET.SubElement(src,
                          "SourceFilename").text = "{baseurl}/tile/{bucket}/{ipe_graph_id}/{node}/{x}/{y}.tif".format(
                baseurl=VIRTUAL_IPE_URL,
                bucket="idaho-virtual",
                ipe_graph_id=ipe_id,
                node=node,
                x=x,
                y=y) + "$query"
            ET.SubElement(src, "SourceBand").text = str(bidx)
            ET.SubElement(src, "SrcRect", {"xOff": str(image_md["tileXOffset"]), "yOff": str(image_md["tileYOffset"]),
                                           "xSize": str(tile_size_x), "ySize": str(tile_size_y)})
            ET.SubElement(src, "DstRect", {"xOff": str(x * tile_size_x), "yOff": str(y * tile_size_y),
                                           "xSize": str(tile_size_x), "ySize": str(tile_size_y)})

            ET.SubElement(src, "SourceProperties", {"RasterXSize": str(tile_size_x), "RasterYSize": str(tile_size_y),
                                                    "BlockXSize": "256", "BlockYSize": "256",
                                                    "DataType": DTLOOKUP.get(meta["image"]["dataType"], "Float32")})
    return ET.tostring(vrt, 'utf-8')
示例#5
0
 def ipe_metadata(self):
     if self._ipe_metadata is None:
         self._ipe_metadata = get_ipe_metadata(
             self.interface.gbdx_connection, self.ipe_id, self.ipe_node_id)
     return self._ipe_metadata
示例#6
0
 def test_ipe_metadata_error(self):
     ipe_id = 'no_id'
     try:
         get_ipe_metadata(self.gbdx.gbdx_connection, ipe_id)
     except BadRequest:
         pass