|
| 1 | +""" |
| 2 | +RGB Image |
| 3 | +--------- |
| 4 | +The :meth:`pygmt.Figure.grdimage` method can be used to plot Red, Green, Blue |
| 5 | +(RGB) images, or any 3-band false color combination. Here, we'll use |
| 6 | +:py:func:`rioxarray.open_rasterio` to read a GeoTIFF file into an |
| 7 | +:class:`xarray.DataArray` format, and plot it on a map. |
| 8 | +
|
| 9 | +The example below shows a Worldview 2 satellite image over |
| 10 | +`Lāhainā, Hawaiʻi during the August 2023 wildfires |
| 11 | +<https://en.wikipedia.org/wiki/2023_Hawaii_wildfires#L%C4%81hain%C4%81>`_. |
| 12 | +Data is sourced from a Cloud-Optimized GeoTIFF (COG) file hosted on |
| 13 | +`OpenAerialMap <https://map.openaerialmap.org>`_ under a |
| 14 | +`CC BY-NC 4.0 <https://creativecommons.org/licenses/by-nc/4.0/>`_ license. |
| 15 | +""" |
| 16 | +import pygmt |
| 17 | +import rioxarray |
| 18 | + |
| 19 | +############################################################################### |
| 20 | +# Read 3-band data from GeoTIFF into an xarray.DataArray object: |
| 21 | +with rioxarray.open_rasterio( |
| 22 | + filename="https://oin-hotosm.s3.us-east-1.amazonaws.com/64d6a49a19cb3a000147a65b/0/64d6a49a19cb3a000147a65c.tif", |
| 23 | + overview_level=5, |
| 24 | +) as img: |
| 25 | + # Subset to area of Lāhainā in EPSG:32604 coordinates |
| 26 | + image = img.rio.clip_box(minx=738000, maxx=755000, miny=2300000, maxy=2318000) |
| 27 | + image = image.load() # Force loading the DataArray into memory |
| 28 | +image |
| 29 | + |
| 30 | +############################################################################### |
| 31 | +# Plot the RGB imagery: |
| 32 | +fig = pygmt.Figure() |
| 33 | +with pygmt.config(FONT_TITLE="Times-Roman"): # Set title font to Times-Roman |
| 34 | + fig.grdimage( |
| 35 | + grid=image, |
| 36 | + # Use a map scale where 1 cm on the map equals 1 km on the ground |
| 37 | + projection="x1:100000", |
| 38 | + frame=[r"WSne+tL@!a¯hain@!a¯, Hawai`i on 9 Aug 2023", "af"], |
| 39 | + ) |
| 40 | +fig.show() |
0 commit comments