Exemplo n.º 1
0
def ingest_reflectance_image(mrgeo, filtered_metadata, band, image_name):
    cnt = 0
    red_refl_paths = mrgeo.gateway.new_array(mrgeo.gateway.jvm.String,
                                             len(filtered_metadata))
    driver = gdal.GetDriverByName('GTiff')
    for key in filtered_metadata:
        md = filtered_metadata[key]
        red_ds = gdal.Open(md[band], GA_ReadOnly)
        bqa_ds = gdal.Open(md["BQA"], GA_ReadOnly)
        ndv, xsize, ysize, GeoT, Projection, data_type = GetGeoInfo(md[band])
        if ndv is None:
            ndv = 0
        red_band = red_ds.GetRasterBand(1)
        red_data = red_band.ReadAsArray()
        bqa_band = bqa_ds.GetRasterBand(1)
        bqa_data = bqa_band.ReadAsArray()
        data_type = gdal.GDT_Float32
        red_data = numpy.float32(red_data)
        # Change nodata value to NaN since we're changing the type to Float32
        red_data[red_data == ndv] = RasterMapOp.nan()
        ndv = RasterMapOp.nan()
        toa_reflectance(red_data, bqa_data, md, band)
        # Now turn the array into a GTiff.
        ntf = tempfile.NamedTemporaryFile(suffix=".tif", delete=False)
        red_temp_file = ntf.name
        CreateGeoTiff(red_temp_file, red_data, driver, ndv, xsize, ysize, GeoT,
                      Projection, data_type)
        red_refl_paths[cnt] = red_temp_file
        cnt += 1
        # close the datasets
        red_ds = None
        bqa_ds = None

    red = mrgeo.ingest_image(red_refl_paths)
    red.save(image_name)
    for rf in red_refl_paths:
        os.remove(rf)
    return red
Exemplo n.º 2
0
def ingest_reflectance_image(mrgeo, filtered_metadata, band, image_name):
    cnt = 0
    red_refl_paths = mrgeo.gateway.new_array(mrgeo.gateway.jvm.String, len(filtered_metadata))
    driver = gdal.GetDriverByName('GTiff')
    for key in filtered_metadata:
        md = filtered_metadata[key]
        red_ds = gdal.Open(md[band], GA_ReadOnly)
        bqa_ds = gdal.Open(md["BQA"], GA_ReadOnly)
        ndv, xsize, ysize, GeoT, Projection, data_type = GetGeoInfo(md[band])
        if ndv is None:
            ndv = 0
        red_band = red_ds.GetRasterBand(1)
        red_data = red_band.ReadAsArray()
        bqa_band = bqa_ds.GetRasterBand(1)
        bqa_data = bqa_band.ReadAsArray()
        data_type = gdal.GDT_Float32
        red_data = numpy.float32(red_data)
        # Change nodata value to NaN since we're changing the type to Float32
        red_data[red_data == ndv] = RasterMapOp.nan()
        ndv = RasterMapOp.nan()
        toa_reflectance(red_data, bqa_data, md, band)
        # Now turn the array into a GTiff.
        ntf = tempfile.NamedTemporaryFile(suffix=".tif", delete=False)
        red_temp_file = ntf.name
        CreateGeoTiff(red_temp_file, red_data, driver, ndv,
                      xsize, ysize, GeoT, Projection, data_type)
        red_refl_paths[cnt] = red_temp_file
        cnt += 1
        # close the datasets
        red_ds = None
        bqa_ds = None

    red = mrgeo.ingest_image(red_refl_paths)
    red.save(image_name)
    for rf in red_refl_paths:
        os.remove(rf)
    return red
Exemplo n.º 3
0
    def createRasterMapOp(self,
                          tileIds,
                          zoomLevel,
                          tileSize,
                          name='',
                          imageNoData=None,
                          imageInitialData=None):
        if imageNoData is None:
            imageNoData = self._defaultImageNoData
        if imageInitialData is None:
            imageInitialData = self._defaultImageInitialData

        # Capture image initial and nodata to compare against
        self._imageInitialData = imageInitialData
        self._imageNoData = imageNoData
        mapop = self._rasterMapOpTestSupport.createRasterMapOp(
            tileIds, zoomLevel, tileSize, name, imageNoData, imageInitialData)
        return RasterMapOp(mapop=mapop,
                           gateway=self._mrgeo.gateway,
                           context=self._sparkContext)
Exemplo n.º 4
0
    def createRasterMapOpWithBounds(self,
                                    tileIds,
                                    zoomLevel,
                                    tileSize,
                                    w,
                                    s,
                                    e,
                                    n,
                                    name='',
                                    imageNoData=None,
                                    imageInitialData=None):
        if imageNoData is None:
            imageNoData = self._defaultImageNoData
        if imageInitialData is None:
            imageInitialData = self._defaultImageInitialData

        bounds = self._jvm.Bounds(w, s, e, n)
        mapop = self._rasterMapOpTestSupport.createRasterMapOpWithBounds(
            tileIds, zoomLevel, tileSize, name, bounds, imageNoData,
            imageInitialData)
        return RasterMapOp(mapop=mapop,
                           gateway=self._mrgeo.gateway,
                           context=self._sparkContext)
Exemplo n.º 5
0
    with open(landsat['json']) as metafile:
        metadata = json.load(metafile)

    mrgeo = MrGeo()
    # mrgeo.usedebug()

    mrgeo.start()

    bqa = mrgeo.ingest_image(landsat['bqa'])
    # bqa.export('/data/export/landsat-bqa.tif', singleFile=True)

    cloud_mask = bqa < 32768  # 0 where clouds, 1 where no clouds
    # cloud_mask.export('/data/export/landsat-clouds.tif', singleFile=True)

    red = cloud_mask.con(positiveRaster=mrgeo.ingest_image(landsat[4]),
                         negativeConst=RasterMapOp.nan())
    green = cloud_mask.con(positiveRaster=mrgeo.ingest_image(landsat[3]),
                           negativeConst=RasterMapOp.nan())
    blue = cloud_mask.con(positiveRaster=mrgeo.ingest_image(landsat[2]),
                          negativeConst=RasterMapOp.nan())
    # red = mrgeo.ingest_image(landsat[4])
    # green = mrgeo.ingest_image(landsat[3])
    # blue = mrgeo.ingest_image(landsat[2])

    red.save('landsat-dn-r')
    # red.export('/data/export/landsat-dn-r.tif', singleFile=True)
    # green.export('/data/export/landsat-dn-g.tif', singleFile=True)
    # blue.export('/data/export/landsat-dn-b.tif', singleFile=True)

    rgb = red.bandcombine(green, blue)
    rgb.export('/data/export/landsat-rgb-dn.tif', singleFile=True)
Exemplo n.º 6
0
    with open(landsat["json"]) as metafile:
        metadata = json.load(metafile)

    mrgeo = MrGeo()
    # mrgeo.usedebug()

    mrgeo.start()

    bqa = mrgeo.ingest_image(landsat["bqa"])
    # bqa.export('/data/export/landsat-bqa.tif', singleFile=True)

    cloud_mask = bqa < 32768  # 0 where clouds, 1 where no clouds
    # cloud_mask.export('/data/export/landsat-clouds.tif', singleFile=True)

    red = cloud_mask.con(positiveRaster=mrgeo.ingest_image(landsat[4]), negativeConst=RasterMapOp.nan())
    green = cloud_mask.con(positiveRaster=mrgeo.ingest_image(landsat[3]), negativeConst=RasterMapOp.nan())
    blue = cloud_mask.con(positiveRaster=mrgeo.ingest_image(landsat[2]), negativeConst=RasterMapOp.nan())
    # red = mrgeo.ingest_image(landsat[4])
    # green = mrgeo.ingest_image(landsat[3])
    # blue = mrgeo.ingest_image(landsat[2])

    red.save("landsat-dn-r")
    # red.export('/data/export/landsat-dn-r.tif', singleFile=True)
    # green.export('/data/export/landsat-dn-g.tif', singleFile=True)
    # blue.export('/data/export/landsat-dn-b.tif', singleFile=True)

    rgb = red.bandcombine(green, blue)
    rgb.export("/data/export/landsat-rgb-dn.tif", singleFile=True)

    r_rad = toa_radiance(red, metadata, 4)