### Install stackstac library Source: https://stackstac.readthedocs.io/en/latest/index.html Installs the stackstac package along with optional visualization dependencies using pip. This command ensures all necessary components for cloud-native geoprocessing are available in the environment. ```bash pip install 'stackstac[viz]' ``` -------------------------------- ### Configure Stackstac parameters Source: https://stackstac.readthedocs.io/en/latest/api/main/stackstac.stack.html Example configuration demonstrating how to set spatial bounds, chunking, and data types for a Stackstac operation. These parameters control how STAC items are loaded into a Dask-backed xarray DataArray. ```python import numpy as np from rasterio.enums import Resampling # Example configuration for stackstac.stack config = { "bounds": (10.0, 45.0, 12.0, 47.0), # (min_x, min_y, max_x, max_y) "snap_bounds": True, "resampling": Resampling.nearest, "chunksize": (1, 1, 512, 512), "dtype": "float32", "fill_value": np.nan, "rescale": True, "sortby_date": "asc", "xy_coords": "topleft" } ``` -------------------------------- ### PandasIndex Examples Source: https://stackstac.readthedocs.io/en/latest/basic.html Demonstrates the creation and structure of PandasIndex objects for different data types (object, float64, datetime64). These indices are commonly used in libraries like xarray to label data dimensions. ```python PandasIndex(Index(['red', 'green', 'blue'], dtype='object', name='band')) ``` ```python PandasIndex(Float64Index([399960.0, 399970.0, 399980.0, 399990.0, 400000.0, 400010.0, 400020.0, 400030.0, 400040.0, 400050.0, ... 509660.0, 509670.0, 509680.0, 509690.0, 509700.0, 509710.0, 509720.0, 509730.0, 509740.0, 509750.0], dtype='float64', name='x', length=10980)) ``` ```python PandasIndex(Float64Index([4000020.0, 4000010.0, 4000000.0, 3999990.0, 3999980.0, 3999970.0, 3999960.0, 3999950.0, 3999940.0, 3999930.0, ... 3890320.0, 3890310.0, 3890300.0, 3890290.0, 3890280.0, 3890270.0, 3890260.0, 3890250.0, 3890240.0, 3890230.0], dtype='float64', name='y', length=10980)) ``` ```python PandasIndex(DatetimeIndex(['2020-03-01', '2020-04-01', '2020-05-01'], dtype='datetime64[ns]', name='time', freq='MS')) ``` -------------------------------- ### stackstac.rio_env.LayeredEnv Source: https://stackstac.readthedocs.io/en/latest/api/internal/stackstac.rio_env.LayeredEnv.html Manages GDAL configuration options for different situations (always, opening, reading). Access the rasterio.Env for each situation with layered_env.always, layered_env.read, etc. To ensure thread-safety, each thread accessing these properties gets its own thread-local copy of a rasterio.Env. ```APIDOC ## stackstac.rio_env.LayeredEnv ### Description Manages GDAL configuration options for different situations (always, opening, reading). Access the `rasterio.Env` for each situation with `layered_env.always`, `layered_env.read`, etc. To ensure thread-safety, each thread accessing these properties gets its own thread-local copy of a `rasterio.Env`. Options are layered as follows: * `always`: the base set of options * `open`: `always` + `open` * `open_vrt`: `open` + `open_vrt` * `read`: `always` + `read` ### Methods #### `__init__` ```python __init__(_always_, _open=None_, _open_vrt=None_, _read=None_) ``` Initializes the LayeredEnv with base options and optional overrides for opening, opening VRTs, and reading. ##### Parameters - **_always** (rasterio.Env) - Required - The base set of GDAL options. - **_open** (rasterio.Env, optional) - The GDAL options to apply when opening datasets. - **_open_vrt** (rasterio.Env, optional) - The GDAL options to apply when opening VRT datasets. - **_read** (rasterio.Env, optional) - The GDAL options to apply when reading from datasets. #### `updated` ```python updated([always, open, open_vrt, read]) ``` Duplicates this LayeredEnv, adding additional options for each situation. ##### Parameters - **always** (rasterio.Env, optional) - Additional base GDAL options. - **open** (rasterio.Env, optional) - Additional GDAL options for opening datasets. - **open_vrt** (rasterio.Env, optional) - Additional GDAL options for opening VRT datasets. - **read** (rasterio.Env, optional) - Additional GDAL options for reading from datasets. ### Attributes - **`always`** (rasterio.Env) - The base `rasterio.Env` object. - **`open`** (rasterio.Env) - The `rasterio.Env` object to use while opening datasets. - **`open_vrt`** (rasterio.Env) - The `rasterio.Env` object to use while opening VRTs. - **`read`** (rasterio.Env) - The `rasterio.Env` object to use while reading from datasets. ### Example Usage ```python import rasterio from stackstac.rio_env import LayeredEnv # Define base options base_env = rasterio.Env(GDAL_TIFF_OVR_BLOCKSIZE=128) # Create a LayeredEnv layered_env = LayeredEnv(always=base_env, read=rasterio.Env(GDAL_CACHEMAX=0)) # Access different environments with layered_env.read as env: # Use env for reading operations print(env.get('GDAL_CACHEMAX')) # Output: 0 with layered_env.always as env: # Use env for base operations print(env.get('GDAL_TIFF_OVR_BLOCKSIZE')) # Output: 128 ``` ``` -------------------------------- ### Accessing Band Metadata and Spatial Indexes Source: https://stackstac.readthedocs.io/en/latest/examples/cluster.html Examples of how band-specific attributes like common names, wavelengths, and spatial resolutions are stored, alongside the definition of temporal and spatial indexes (x, y, time) within the data structure. ```python import numpy as np import pandas as pd # Example of band metadata extraction common_names = np.array([None, 'blue', 'coastal', 'green', 'nir', 'nir08', 'nir09', 'red', 'rededge', 'rededge', 'rededge', None, 'swir16', 'swir22', None, None], dtype=object) # Example of spatial index definition x_index = pd.Index([391300.0, 391400.0, 391500.0], name='x') y_index = pd.Index([3984700.0, 3984600.0, 3984500.0], name='y') # EPSG code representation epsg = 32613 ``` -------------------------------- ### Initialize Coiled Dask Cluster Source: https://stackstac.readthedocs.io/en/latest/examples/gif.html Configures and connects to a Coiled Dask cluster to enable parallel processing of large geospatial datasets. This setup optimizes performance by running computations in a region close to the data source. ```python cluster = coiled.Cluster( name="stackstac-eu", n_workers=20, package_sync=True, backend_options={"region": "eu-central-1"} ) client = distributed.Client(cluster) client ``` -------------------------------- ### Reproject and Set Resolution using stackstac.stack Source: https://stackstac.readthedocs.io/en/latest/api/main/stackstac.stack.html This example shows how to reproject the STAC items to a specified Coordinate Reference System (CRS) and resolution using the `epsg` and `resolution` parameters. It's crucial that the resolution is provided in the units of the output CRS. ```python import stackstac import satsearch items = satsearch.Search(...).items() # Reproject to 100-meter resolution in web mercator xr_stack = stackstac.stack(items, epsg=3857, resolution=100) ``` -------------------------------- ### Compute Dask Array with Progress Bar Source: https://stackstac.readthedocs.io/en/latest/basic.html Demonstrates how to trigger the computation of a lazy Dask array using a context manager to display a progress bar. This is essential for monitoring long-running geospatial data processing tasks. ```python import dask.diagnostics with dask.diagnostics.ProgressBar(): data = aoi.compute() ``` -------------------------------- ### Filtering Satellite Data by Cloud Cover Source: https://stackstac.readthedocs.io/en/latest/examples/gif.html This example shows how to filter satellite data based on cloud cover using the 'eo:cloud_cover' attribute. It assumes the existence of a data structure (like a GeoDataFrame or xarray DataArray) with this metadata, allowing for the selection of scenes with minimal cloud presence. ```python import xarray as xr import numpy as np # Assume 'data' is an xarray DataArray with satellite imagery and metadata # For demonstration, we create a dummy DataArray with a 'cloud_cover' attribute data = xr.DataArray( np.random.rand(10, 10), dims=('y', 'x'), coords={'y': np.arange(10), 'x': np.arange(10)}, attrs={'eo:cloud_cover': np.random.rand(10) * 100} # Dummy cloud cover values ) # Define the maximum acceptable cloud cover percentage max_cloud_cover = 20 # Filter the data to include only scenes with cloud cover less than the threshold filtered_data = data.where(data.attrs['eo:cloud_cover'] < max_cloud_cover, drop=True) print(f"Original data shape: {data.shape}") print(f"Filtered data shape (cloud cover < {max_cloud_cover}%): {filtered_data.shape}") print(f"Cloud cover values in filtered data: {filtered_data.attrs['eo:cloud_cover']}") ``` -------------------------------- ### Initialize STAC Catalog and Search Source: https://stackstac.readthedocs.io/en/latest/basic.html Connects to the Earth Search AWS STAC catalog and performs a spatial and temporal query for Sentinel-2 data. Returns an item collection containing metadata for the requested scenes. ```python import pystac_client import stackstac lon, lat = -105.78, 35.79 URL = "https://earth-search.aws.element84.com/v1" catalog = pystac_client.Client.open(URL) items = catalog.search( intersects=dict(type="Point", coordinates=[lon, lat]), collections=["sentinel-2-l2a"], datetime="2020-03-01/2020-06-01" ).item_collection() ``` -------------------------------- ### Custom Dtype and Fill Value with stackstac.stack Source: https://stackstac.readthedocs.io/en/latest/api/main/stackstac.stack.html This example demonstrates how to specify a custom data type (`dtype`) and fill value (`fill_value`) for the output DataArray. The `rescale` parameter is also set to `False`, indicating that no automatic rescaling of data values should be performed. ```python import stackstac import satsearch items = satsearch.Search(...).items() # Custom dtype and fill_value xr_stack = stackstac.stack(items, rescale=False, fill_value=0, dtype="uint16") ``` -------------------------------- ### Initialize Interactive Map with ipyleaflet Source: https://stackstac.readthedocs.io/en/latest/examples/show.html Sets up an interactive map centered on a specific coordinate with a defined zoom level and height for visualization. ```python m = ipyleaflet.Map() m.center = 35.677153763176115, -105.8485489524901 m.zoom = 10 m.layout.height = "700px" m ``` -------------------------------- ### Spatial Subsetting with xarray .loc Source: https://stackstac.readthedocs.io/en/latest/basic.html Selects a spatial subset of an xarray DataArray using coordinate ranges. This example demonstrates slicing based on UTM coordinates and a buffer, effectively extracting a region of interest. ```python aoi = monthly.loc[..., y_utm+buffer:y_utm-buffer, x_utm-buffer:x_utm+buffer] aoi ``` -------------------------------- ### Import required geospatial and distributed computing libraries Source: https://stackstac.readthedocs.io/en/latest/examples/show.html Initializes the environment by importing necessary modules for stackstac, STAC client interaction, map visualization, and Dask distributed computing. ```python import stackstac import pystac_client import ipyleaflet import xarray as xr import IPython.display as dsp import coiled import distributed ``` -------------------------------- ### Function: stackstac.show Source: https://stackstac.readthedocs.io/en/latest/api/main/stackstac.show.html The show function creates an ipyleaflet.Map to visualize DataArrays. It computes data on the fly as the user pans, requiring a dask distributed cluster. ```APIDOC ## FUNCTION stackstac.show ### Description Quickly create an `ipyleaflet.Map` displaying a `DataArray`. As you pan around the map, the part of the array that is in view is computed on the fly by dask. ### Method Python Function ### Parameters #### Arguments - **arr** (`DataArray`) - Required - The DataArray to visualize. Must have x and y dimensions and an epsg coordinate set. - **center** (`Tuple[float, float]`) - Optional - Centerpoint for the map in (lat, lon) order. Defaults to auto-centering. - **zoom** (`int`) - Optional - Initial zoom level for the map. - **range** (`Tuple[float, float]`) - Optional - Min and max values for visualization scaling. Defaults to 2nd/98th percentile. - **cmap** (`Union[str, Colormap]`) - Optional - Colormap for single-band data. Defaults to 'viridis'. - **checkerboard** (`bool`) - Optional - Whether to show a checkerboard pattern for missing data. Defaults to True. - **interpolation** (`Literal['linear', 'nearest']`) - Optional - Interpolation method for reprojection. Defaults to 'linear'. ### Request Example ```python import stackstac stackstac.show(my_data_array, cmap='magma', interpolation='nearest') ``` ### Response #### Success Response - **return** (`ipyleaflet.Map`) - The interactive map object displaying the array. ``` -------------------------------- ### Coordinate Transformation with pyproj Source: https://stackstac.readthedocs.io/en/latest/basic.html Converts longitude and latitude coordinates to UTM coordinates using the pyproj library. This is a crucial step for aligning geographic points with projected raster data. ```python import pyproj x_utm, y_utm = pyproj.Proj(monthly.crs)(lon, lat) buffer = 2000 # meters ``` -------------------------------- ### Create and Connect to a Coiled Dask Cluster Source: https://stackstac.readthedocs.io/en/latest/examples/cluster.html This snippet demonstrates how to initialize a Dask cluster using Coiled, specifying the number of workers, package synchronization, and the cloud region for backend operations. It then establishes a client connection to this cluster. ```python import coiled import distributed cluster = coiled.Cluster( name="stackstac", n_workers=8, package_sync=True, backend_options={"region": "us-west-2"}, # where the data is ) client = distributed.Client(cluster) client ``` -------------------------------- ### Execute Parallel Computation and Visualization Source: https://stackstac.readthedocs.io/en/latest/examples/cluster.html Demonstrates initializing a compute cluster, executing a parallel computation task, and plotting the resulting multi-dimensional imagery. ```python client.wait_for_workers(8) %time rgb_ = monthly_rgb.compute() rgb_.plot.imshow(row="time", rgb="band", robust=True, size=6); ``` -------------------------------- ### xarray DataArray Representation Source: https://stackstac.readthedocs.io/en/latest/basic.html Shows the detailed representation of an xarray DataArray after spatial subsetting. It includes dimensions, dask array information, coordinates, and attributes, providing insights into the data structure and its metadata. ```python xarray.DataArray 'stackstac-3a21164f19f81366a5242c365d798d31' * time: 3 * band: 3 * y: 400 * x: 400 * dask.array | | Array | Chunk ---|---|--- Bytes | 10.99 MiB | 0.93 MiB Shape | (3, 3, 400, 400) | (1, 1, 387, 316) Dask graph | 36 chunks in 16 graph layers Data type | float64 numpy.ndarray * Coordinates: (21) * band (band) threshold) stackstac.add_to_map(high_ndvi, ndvi_map, "ndvi", range=[0, 1], cmap="YlGn") return ndvi_map ``` -------------------------------- ### Filter and Resample Satellite Data Source: https://stackstac.readthedocs.io/en/latest/basic.html Filters a stack of satellite imagery by cloud coverage, selects RGB bands, and performs a monthly median resampling. This process uses xarray's indexing and resampling capabilities to produce aggregated temporal composites. ```python lowcloud = stack[stack["eo:cloud_cover"] < 20] rgb = lowcloud.sel(band=["red", "green", "blue"]) monthly = rgb.resample(time="MS").median("time", keep_attrs=True) ``` -------------------------------- ### Configure and connect to a Coiled Dask cluster Source: https://stackstac.readthedocs.io/en/latest/examples/show.html Sets up a remote Dask cluster using Coiled to perform heavy data computation near the data source. The cluster is configured with specific worker resources and region settings for optimal performance. ```python cluster = coiled.Cluster( name="stackstac-show", n_workers=22, worker_cpu=4, worker_memory="16GiB", package_sync=True, backend_options={"region": "us-west-2"}, ) client = distributed.Client(cluster) client ``` -------------------------------- ### Analyze temporal intervals Source: https://stackstac.readthedocs.io/en/latest/examples/gif.html Calculates and visualizes the temporal distribution of satellite scenes by computing the difference between consecutive time indices. ```python # What's the typical interval between scenes? good.time.diff("time").dt.days.plot.hist(); ``` -------------------------------- ### SingleThreadedRioDataset Class Initialization (Python) Source: https://stackstac.readthedocs.io/en/latest/api/internal/stackstac.rio_reader.SingleThreadedRioDataset.html Initializes the SingleThreadedRioDataset, an interface for rasterio datasets with single-threaded drivers. It requires an environment, a dataset, and optionally a VRT. Concurrent reads are protected by a lock. ```python class SingleThreadedRioDataset: """ Interface for a rasterio dataset whose driver is inherently single-threaded (like hdf5). Concurrent reads are protected by a lock. """ def __init__(self, env, ds, vrt=None): """ Initializes the SingleThreadedRioDataset. Args: env: The rasterio environment. ds: The rasterio dataset. vrt: Optional VRT dataset. """ pass ``` -------------------------------- ### Load Landsat WRS Paths with Stackstac Source: https://stackstac.readthedocs.io/en/latest/examples/gif.html This snippet shows how to extract the World Reference System (WRS) path for Landsat scenes using Stackstac. It assumes the data is loaded and the 'wrs_path' attribute is available. The output is a NumPy array of strings representing the WRS paths. ```python import numpy as np # Assuming 'data' is a loaded dataset object with a 'wrs_path' attribute # Example placeholder for demonstration: data = { 'wrs_path': np.array(['011', '012', '012', '012', '012', '011', '012', '011', '012', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '011', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '012', '011', '012', '011', '012', '011', '012', '011', '011', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', '011', '012', ' ``` -------------------------------- ### Query STAC Catalog for Sentinel-2 Data Source: https://stackstac.readthedocs.io/en/latest/examples/show.html Uses pystac_client to search the Earth Search AWS STAC API for Sentinel-2 L2A collections within a defined bounding box and date range. ```python bbox=[m.west, m.south, m.east, m.north] stac_items = pystac_client.Client.open( "https://earth-search.aws.element84.com/v1" ).search( bbox=bbox, collections=["sentinel-2-l2a"], datetime="2020-04-01/2020-04-15" ).item_collection() ``` -------------------------------- ### Create monthly median RGB composites Source: https://stackstac.readthedocs.io/en/latest/examples/cluster.html Uses xarray's selection and resampling methods to isolate RGB bands and compute the median value for each month in the dataset. ```python rgb = stack.sel(band=["red", "green", "blue"]) monthly_rgb = rgb.resample(time="MS").median(dim="time") monthly_rgb ``` -------------------------------- ### Create Time Stack with stackstac Source: https://stackstac.readthedocs.io/en/latest/examples/show.html Converts a collection of STAC items into a stackstac data cube with a specified spatial resolution. ```python stack = stackstac.stack(stac_items, resolution=80) ```