xlandsat.composite(scene, bands=('red', 'green', 'blue'), rescale_to=None, dtype='uint8')[source]#

Create a composite using the given bands.

The composite will be an RGBA array if NaNs are present in any band (with transparency of the NaN pixels set to full), or RGB is no NaNs are present. The RGB(A) array is encoded using the given dtype for easier plotting with matplotlib.

Optionally rescale each band to the given range for improved contrast.

  • scene (xarray.Dataset) – A Landsat scene, as read with xlandsat.load_scene.

  • bands (list of str) – A list of variable names from the scene that will be used as the composite’s red, green, and blue channels, respectively.

  • rescale_to (None or list) – If not None, then should be a list/tuple with the minimum and maximum reflectance ranges to use for rescaling. The same values are used for each band. Bands are rescaled separately. Example: rescale_to=[0, 0.5]. Default is None.

  • dtype (str or numpy dtype) – The type of the output array. Will determine the range of values in the composite. Float types will result in [-1, 1] range outputs. Default is "uint8" meaning outputs in [0, 255] range and a smaller memory footprint. Use a float type for higher radiometric precision.


composite (xarray.DataArray) – The composite as a 3D DataArray of type uint8. The first 2 dimensions are the same as the scene with the "channel" added as third dimension. Metadata from the scene is copied to the composite.



Use the xarray.DataArray.plot.imshow method to plot the composite using matplotlib.