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:

{'bands': [{'band': 1,
            'block': [697, 1],
            'colorInterpretation': 'Gray',
            'description': {'color': 'Gray',
                            'data_description': 'TOAR, 0-10000 is 0 - 100% '
                                                'reflective',
                            'data_range': [0, 10000],
                            'data_unit': 'TOAR',
                            'data_unit_description': 'Top of atmosphere '
                                                     'reflectance',
                            'default_range': [0, 10000],
                            'description': 'Short wave infrared 1',
                            'dtype': 'UInt16',
                            'id': 'landsat:LC08:PRE:TOAR:swir1',
                            'modified': '2019-08-08T18:48:53.187931+00:00',
                            'name': 'swir1',
                            'name_common': 'swir1',
                            'name_vendor': 'B6',
                            'nbits': 14,
                            'nodata': None,
                            'owner_type': 'core',
                            'physical_range': [0.0, 1.0],
                            'processing_level': 'TOAR',
                            'product': 'landsat:LC08:PRE:TOAR',
                            'resolution': 30,
                            'resolution_unit': 'meters',
                            'tags': ['spectral',
                                     'swir',
                                     'swir1',
                                     '30m',
                                     'landsat'],
                            'type': 'spectral',
                            'vendor_order': 6,
                            'wavelength_center': 1608.9,
                            'wavelength_fwhm': 84.7,
                            'wavelength_max': 1651.25,
                            'wavelength_min': 1566.55,
                            'wavelength_unit': 'nm'},
            'mask': {'flags': ['PER_DATASET', 'ALPHA'], 'overviews': []},
            'metadata': {},
            'type': 'Byte'},
           {'band': 2,
            'block': [697, 1],
            'colorInterpretation': 'Gray',
            'description': {'color': 'Gray',
                            'data_description': 'TOAR, 0-10000 is 0 - 100% '
                                                'reflective',
                            'data_range': [0, 10000],
                            'data_unit': 'TOAR',
                            'data_unit_description': 'Top of atmosphere '
                                                     'reflectance',
                            'default_range': [0, 10000],
                            'description': 'Short wave infrared 2',
                            'dtype': 'UInt16',
                            'id': 'landsat:LC08:PRE:TOAR:swir2',
                            'modified': '2019-08-08T18:48:50.040753+00:00',
                            'name': 'swir2',
                            'name_common': 'swir2',
                            'name_vendor': 'B7',
                            'nbits': 14,
                            'nodata': None,
                            'owner_type': 'core',
                            'physical_range': [0.0, 1.0],
                            'processing_level': 'TOAR',
                            'product': 'landsat:LC08:PRE:TOAR',
                            'resolution': 30,
                            'resolution_unit': 'meters',
                            'tags': ['spectral',
                                     'swir',
                                     'swir2',
                                     '30m',
                                     'landsat'],
                            'type': 'spectral',
                            'vendor_order': 7,
                            'wavelength_center': 2200.7,
                            'wavelength_fwhm': 186.7,
                            'wavelength_max': 2294.05,
                            'wavelength_min': 2107.35,
                            'wavelength_unit': 'nm'},
            'mask': {'flags': ['PER_DATASET', 'ALPHA'], 'overviews': []},
            'metadata': {},
            'type': 'Byte'},
           {'band': 3,
            'block': [697, 1],
            'colorInterpretation': 'Gray',
            'description': {'color': 'Gray',
                            'data_description': 'TOAR, 0-10000 is 0 - 100% '
                                                'reflective',
                            'data_range': [0, 10000],
                            'data_unit': 'TOAR',
                            'data_unit_description': 'Top of atmosphere '
                                                     'reflectance',
                            'default_range': [0, 10000],
                            'description': 'Near Infrared',
                            'dtype': 'UInt16',
                            'id': 'landsat:LC08:PRE:TOAR:nir',
                            'modified': '2019-08-08T18:48:49.050363+00:00',
                            'name': 'nir',
                            'name_common': 'nir',
                            'name_vendor': 'B5',
                            'nbits': 14,
                            'nodata': None,
                            'owner_type': 'core',
                            'physical_range': [0.0, 1.0],
                            'processing_level': 'TOAR',
                            'product': 'landsat:LC08:PRE:TOAR',
                            'resolution': 30,
                            'resolution_unit': 'meters',
                            'tags': ['spectral',
                                     'nir',
                                     'near-infrared',
                                     '30m',
                                     'landsat'],
                            'type': 'spectral',
                            'vendor_order': 5,
                            'wavelength_center': 864.7,
                            'wavelength_fwhm': 28.3,
                            'wavelength_max': 878.85,
                            'wavelength_min': 850.55,
                            'wavelength_unit': 'nm'},
            'mask': {'flags': ['PER_DATASET', 'ALPHA'], 'overviews': []},
            'metadata': {},
            'type': 'Byte'},
           {'band': 4,
            'block': [697, 1],
            'colorInterpretation': 'Alpha',
            'description': {'color': 'Alpha',
                            'data_description': '0: nodata, 1: valid data',
                            'data_range': [0, 1],
                            'data_unit_description': 'unitless',
                            'default_range': [0, 1],
                            'description': 'Alpha (valid data)',
                            'dtype': 'UInt16',
                            'id': 'landsat:LC08:PRE:TOAR:alpha',
                            'name': 'alpha',
                            'name_common': 'alpha',
                            'nbits': 1,
                            'nodata': None,
                            'owner_type': 'core',
                            'product': 'landsat:LC08:PRE:TOAR',
                            'resolution': 15,
                            'resolution_unit': 'meters',
                            'tags': ['mask', 'alpha', '15m', 'landsat'],
                            'type': 'mask'},
            'metadata': {},
            'type': 'Byte'}],
 'coordinateSystem': {'proj4': '+proj=utm +zone=13 +datum=WGS84 +units=m '
                               '+no_defs ',
                      'wkt': 'PROJCS["WGS 84 / UTM zone 13N",\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["metre",1,\n'
                             '        AUTHORITY["EPSG","9001"]],\n'
                             '    AXIS["Easting",EAST],\n'
                             '    AXIS["Northing",NORTH],\n'
                             '    AUTHORITY["EPSG","32613"]]'},
 'cornerCoordinates': {'center': [464376.95, 4130900.095],
                       'lowerLeft': [422556.95, 4088780.095],
                       'lowerRight': [506196.95, 4088780.095],
                       'upperLeft': [422556.95, 4173020.095],
                       'upperRight': [506196.95, 4173020.095]},
 'driverLongName': 'In Memory Raster',
 'driverShortName': 'MEM',
 'files': [],
 'geoTransform': [422556.94995920244,
                  120.0,
                  0.0,
                  4173020.094713287,
                  0.0,
                  -120.0],
 'metadata': {'': {'Corder': 'RPCL',
                   'id': 'landsat:LC08:PRE:TOAR:meta_LC80330342017072_v1'}},
 'size': [697, 702],
 'wgs84Extent': {'coordinates': [[[-105.8785042, 37.7011425],
                                  [-105.86971, 36.9418968],
                                  [-104.9304027, 36.945061],
                                  [-104.9296988, 37.7043942],
                                  [-105.8785042, 37.7011425]]],
                 'type': 'Polygon'}}

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

Gallery generated by Sphinx-Gallery