{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Rasters 3: Cloud-optimized GeoTIFFs with multiple bands" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "1. Read in a high-resolution, cloud-optimized GeoTIFF that consists of multiple bands\n", "2. Combine the bands into a single, true-color image and plot that image\n", "3. Overlay the GeoTIFF on GeoAxes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Prerequisites\n", "\n", "| Concepts | Importance | Notes |\n", "| --- | --- | --- |\n", "| Rasters 1-2| Necessary | |\n", "\n", "* **Time to learn**: 30 minutes\n", "***" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Imports" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import cartopy.crs as ccrs\n", "import cartopy.feature as cfeature\n", "import numpy as np\n", "import rioxarray as rxr\n", "import rasterio" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Read in a multi-band raster file in GeoTIFF format that consists of multiple bands" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Process the GeoTIFF file, originating from [Planet Labs](https://www.planet.com/); (see ref. 2 at end of notebook) using the [rioxarray](https://corteva.github.io/rioxarray/stable/) library." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "rasFile = '/spare11/atm533/data/raster/la.tif'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
<xarray.DataArray (band: 4, y: 4096, x: 4096)>\n", "[67108864 values with dtype=uint8]\n", "Coordinates:\n", " * band (band) int64 1 2 3 4\n", " * x (x) float64 -1.317e+07 -1.317e+07 ... -1.315e+07 -1.315e+07\n", " * y (y) float64 4.011e+06 4.011e+06 ... 3.992e+06 3.992e+06\n", " spatial_ref int64 0\n", "Attributes:\n", " AREA_OR_POINT: Area\n", " scale_factor: 1.0\n", " add_offset: 0.0
rasterio
assumes that a GeoTIFF with 3 bands has a band order of red, green and blue (RGB). It interprets a 4-band image as RGB/A, where *A* denotes *alpha*, or transparency. Each of these four bands, or channels, have pixel values ranging from 0 to 255. For the three colors, the range goes from no color to saturated (full) color. For alpha, the range goes from completely transparent to completely opaque.\n",
"dstack
function to create a single NumPy array that now has all three channels. This is known as a true color image.\n",
"