<jupyter_start><jupyter_text>Accessing GOES data with the Planetary Computer STAC APIThe [Cloud and Moisture Imagery](https://planetarycomputer.microsoft.com/dataset/goes-cmi) product contains one or more Earth-view images with pixel values identifying brightness values that are scaled to support visual analysis. Data AccessThis example will load data from the `goes-cmi` collection and plot it. We'll select a date and time that captures images of Hurricane Florence.<jupyter_code>import pystac_client
import planetary_computer

catalog = pystac_client.Client.open(
    "https://planetarycomputer.microsoft.com/api/stac/v1/"
)

bbox = [-67.2729, 25.6000, -61.7999, 27.5423]
search = catalog.search(
    collections=["goes-cmi"],
    bbox=bbox,
    datetime=["2018-09-11T13:00:00Z", "2018-09-11T15:40:00Z"],
    limit=1,
    query={"goes:image-type": {"eq": "MESOSCALE"}},
)<jupyter_output><empty_output><jupyter_text>As usual, we'll sign the items before loading them.<jupyter_code>item = planetary_computer.sign(next(search.get_items()))<jupyter_output><empty_output><jupyter_text>The GOES-CMI items have many assets available for the various bands. You can view the full list at https://planetarycomputer.microsoft.com/dataset/goes-cmi. We'll use the blue, red, and near-infrared bands.<jupyter_code>import rioxarray
import xarray as xr

bands = ["C01_2km", "C02_2km", "C03_2km"]
common_names = [
    item.assets[band].extra_fields["eo:bands"][0]["common_name"] for band in bands
]
ds = xr.concat(
    [rioxarray.open_rasterio(item.assets[band].href) for band in bands], dim="band"
).assign_coords(band=common_names)
ds<jupyter_output><empty_output><jupyter_text>GOES doesn't have a true green band, which we need for our true color image. We'll simulate it with a linear combination of the other bands (See Bah et. al (2018) for more on this technique).<jupyter_code>green = (
    0.45 * ds.sel(band="red") + 0.1 * ds.sel(band="nir09") + 0.45 * ds.sel(band="blue")
).assign_coords(band="green")
green<jupyter_output><empty_output><jupyter_text>Finally, we'll apply a color correction.<jupyter_code>import numpy as np

γ = 2.2

rgb = xr.concat([ds, green], dim="band").sel(band=["red", "green", "blue"])
rgb = rgb / rgb.max(dim=["band", "y", "x"])
rgb = np.clip(rgb ** (1 / γ), 0, 1)
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(12, 12))

rgb.plot.imshow(rgb="band", ax=ax)
ax.set(title="GOES true color image");<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.139440616132955, 'fraction_numerical': 0.03526550466153223, 'mean_word_length': 5.634408602150538, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '17057', 'license': 'MIT', 'n_tokens_mistral': 937, 'n_tokens_neox': 863, 'n_words': 224, 'path': 'datasets/goes/goes-cmi-example.ipynb', 'repo_name': 'ianthomas23/PlanetaryComputerExamples', 'size': '2467'}