Raster ExampleΒΆ

This example makes a simple request to our raster service and displays the image.

from pprint import pprint

import descarteslabs as dl
import matplotlib.pyplot as plt


raster_client = dl.Raster()

aoi = {
    "type": "Polygon",
    "coordinates": [
        [
            [-105.86975097656249, 36.94550173495345],
            [-104.930419921875, 36.94550173495345],
            [-104.930419921875, 37.70120736474139],
            [-105.86975097656249, 37.70120736474139],
            [-105.86975097656249, 36.94550173495345],
        ]
    ],
}

img, meta = raster_client.ndarray(
    "landsat:LC08:PRE:TOAR:meta_LC80330342017072_v1",
    bands=["swir1", "swir2", "nir", "alpha"],
    scales=[[0, 4000], [0, 4000], [0, 4000], None],
    data_type="Byte",
    cutline=aoi,
    resolution=120,
)

# visualize the image
plt.figure(figsize=[8, 8])
plt.axis("off")
plt.imshow(img)
plt.show()
https://cdn.descarteslabs.com/docs/public/_images/sphx_glr_plot_hello_raster_001.png

We can also view the metadata returned by raster.

pprint(meta)

Out:

{u'bands': [{u'band': 1,
             u'block': [697, 1],
             u'colorInterpretation': u'Gray',
             u'description': {u'color': u'Gray',
                              u'data_description': u'TOAR, 0-10000 is 0 - 100% reflective',
                              u'data_range': [0, 10000],
                              u'data_unit': u'TOAR',
                              u'data_unit_description': u'Top of atmosphere reflectance',
                              u'default_range': [0, 10000],
                              u'description': u'Short wave infrared 1',
                              u'dtype': u'UInt16',
                              u'id': u'landsat:LC08:PRE:TOAR:swir1',
                              u'modified': u'2019-08-08T18:48:53.187931+00:00',
                              u'name': u'swir1',
                              u'name_common': u'swir1',
                              u'name_vendor': u'B6',
                              u'nbits': 14,
                              u'nodata': None,
                              u'owner_type': u'core',
                              u'physical_range': [0.0, 1.0],
                              u'processing_level': u'TOAR',
                              u'product': u'landsat:LC08:PRE:TOAR',
                              u'resolution': 30,
                              u'resolution_unit': u'meters',
                              u'tags': [u'spectral',
                                        u'swir',
                                        u'swir1',
                                        u'30m',
                                        u'landsat'],
                              u'type': u'spectral',
                              u'vendor_order': 6,
                              u'wavelength_center': 1608.9,
                              u'wavelength_fwhm': 84.7,
                              u'wavelength_max': 1651.25,
                              u'wavelength_min': 1566.55,
                              u'wavelength_unit': u'nm'},
             u'mask': {u'flags': [u'PER_DATASET', u'ALPHA'],
                       u'overviews': []},
             u'metadata': {},
             u'type': u'Byte'},
            {u'band': 2,
             u'block': [697, 1],
             u'colorInterpretation': u'Gray',
             u'description': {u'color': u'Gray',
                              u'data_description': u'TOAR, 0-10000 is 0 - 100% reflective',
                              u'data_range': [0, 10000],
                              u'data_unit': u'TOAR',
                              u'data_unit_description': u'Top of atmosphere reflectance',
                              u'default_range': [0, 10000],
                              u'description': u'Short wave infrared 2',
                              u'dtype': u'UInt16',
                              u'id': u'landsat:LC08:PRE:TOAR:swir2',
                              u'modified': u'2019-08-08T18:48:50.040753+00:00',
                              u'name': u'swir2',
                              u'name_common': u'swir2',
                              u'name_vendor': u'B7',
                              u'nbits': 14,
                              u'nodata': None,
                              u'owner_type': u'core',
                              u'physical_range': [0.0, 1.0],
                              u'processing_level': u'TOAR',
                              u'product': u'landsat:LC08:PRE:TOAR',
                              u'resolution': 30,
                              u'resolution_unit': u'meters',
                              u'tags': [u'spectral',
                                        u'swir',
                                        u'swir2',
                                        u'30m',
                                        u'landsat'],
                              u'type': u'spectral',
                              u'vendor_order': 7,
                              u'wavelength_center': 2200.7,
                              u'wavelength_fwhm': 186.7,
                              u'wavelength_max': 2294.05,
                              u'wavelength_min': 2107.35,
                              u'wavelength_unit': u'nm'},
             u'mask': {u'flags': [u'PER_DATASET', u'ALPHA'],
                       u'overviews': []},
             u'metadata': {},
             u'type': u'Byte'},
            {u'band': 3,
             u'block': [697, 1],
             u'colorInterpretation': u'Gray',
             u'description': {u'color': u'Gray',
                              u'data_description': u'TOAR, 0-10000 is 0 - 100% reflective',
                              u'data_range': [0, 10000],
                              u'data_unit': u'TOAR',
                              u'data_unit_description': u'Top of atmosphere reflectance',
                              u'default_range': [0, 10000],
                              u'description': u'Near Infrared',
                              u'dtype': u'UInt16',
                              u'id': u'landsat:LC08:PRE:TOAR:nir',
                              u'modified': u'2019-08-08T18:48:49.050363+00:00',
                              u'name': u'nir',
                              u'name_common': u'nir',
                              u'name_vendor': u'B5',
                              u'nbits': 14,
                              u'nodata': None,
                              u'owner_type': u'core',
                              u'physical_range': [0.0, 1.0],
                              u'processing_level': u'TOAR',
                              u'product': u'landsat:LC08:PRE:TOAR',
                              u'resolution': 30,
                              u'resolution_unit': u'meters',
                              u'tags': [u'spectral',
                                        u'nir',
                                        u'near-infrared',
                                        u'30m',
                                        u'landsat'],
                              u'type': u'spectral',
                              u'vendor_order': 5,
                              u'wavelength_center': 864.7,
                              u'wavelength_fwhm': 28.3,
                              u'wavelength_max': 878.85,
                              u'wavelength_min': 850.55,
                              u'wavelength_unit': u'nm'},
             u'mask': {u'flags': [u'PER_DATASET', u'ALPHA'],
                       u'overviews': []},
             u'metadata': {},
             u'type': u'Byte'},
            {u'band': 4,
             u'block': [697, 1],
             u'colorInterpretation': u'Alpha',
             u'description': {u'color': u'Alpha',
                              u'data_description': u'0: nodata, 1: valid data',
                              u'data_range': [0, 1],
                              u'data_unit_description': u'unitless',
                              u'default_range': [0, 1],
                              u'description': u'Alpha (valid data)',
                              u'dtype': u'UInt16',
                              u'id': u'landsat:LC08:PRE:TOAR:alpha',
                              u'name': u'alpha',
                              u'name_common': u'alpha',
                              u'nbits': 1,
                              u'nodata': None,
                              u'owner_type': u'core',
                              u'product': u'landsat:LC08:PRE:TOAR',
                              u'resolution': 15,
                              u'resolution_unit': u'meters',
                              u'tags': [u'mask',
                                        u'alpha',
                                        u'15m',
                                        u'landsat'],
                              u'type': u'mask'},
             u'metadata': {},
             u'type': u'Byte'}],
 u'coordinateSystem': {u'proj4': u'+proj=utm +zone=13 +datum=WGS84 +units=m +no_defs ',
                       u'wkt': u'PROJCS["UTM Zone 13, Northern Hemisphere",\n    GEOGCS["WGS 84",\n        DATUM["WGS_1984",\n            SPHEROID["WGS 84",6378137,298.257223563,\n                AUTHORITY["EPSG","7030"]],\n            AUTHORITY["EPSG","6326"]],\n        PRIMEM["Greenwich",0,\n            AUTHORITY["EPSG","8901"]],\n        UNIT["degree",0.0174532925199433,\n            AUTHORITY["EPSG","9122"]],\n        AUTHORITY["EPSG","4326"]],\n    PROJECTION["Transverse_Mercator"],\n    PARAMETER["latitude_of_origin",0],\n    PARAMETER["central_meridian",-105],\n    PARAMETER["scale_factor",0.9996],\n    PARAMETER["false_easting",500000],\n    PARAMETER["false_northing",0],\n    UNIT["Meter",1]]'},
 u'cornerCoordinates': {u'center': [464376.95, 4130900.095],
                        u'lowerLeft': [422556.95, 4088780.095],
                        u'lowerRight': [506196.95, 4088780.095],
                        u'upperLeft': [422556.95, 4173020.095],
                        u'upperRight': [506196.95, 4173020.095]},
 u'driverLongName': u'In Memory Raster',
 u'driverShortName': u'MEM',
 u'files': [],
 u'geoTransform': [422556.94995920244,
                   120.0,
                   0.0,
                   4173020.094713287,
                   0.0,
                   -120.0],
 u'metadata': {u'': {u'Corder': u'RPCL',
                     u'id': u'landsat:LC08:PRE:TOAR:meta_LC80330342017072_v1'}},
 u'size': [697, 702],
 u'wgs84Extent': {u'coordinates': [[[-105.8785042, 37.7011425],
                                    [-105.86971, 36.9418968],
                                    [-104.9304027, 36.945061],
                                    [-104.9296988, 37.7043942],
                                    [-105.8785042, 37.7011425]]],
                  u'type': u'Polygon'}}

Total running time of the script: ( 0 minutes 3.343 seconds)

Gallery generated by Sphinx-Gallery