### Contribute to eodag-cube: Setup Development Environment Source: https://github.com/cs-si/eodag-cube/blob/develop/README.rst Clones the eodag-cube repository, installs it in editable mode with development dependencies, and sets up pre-commit hooks for code quality. ```bash git clone https://github.com/CS-SI/eodag-cube.git cd eodag-cube python -m pip install -e .[dev] pre-commit install tox ``` -------------------------------- ### Get rasterio environment with credentials using EOProduct.rio_env() Source: https://context7.com/cs-si/eodag-cube/llms.txt Explains how to retrieve a rasterio environment pre-configured with necessary authentication credentials for accessing cloud-hosted geospatial data, particularly for S3. It shows examples for both the entire product and asset-specific environments. ```python from eodag import EODataAccessGateway import rasterio dag = EODataAccessGateway() search_results = dag.search( provider='earth_search', collection='S2_MSI_L1C', geom=[1, 43.5, 2, 44], start='2020-06-04', end='2020-06-05', ) product = search_results[0] # Get rasterio environment for S3 access dataset_url = product.assets["blue"]["href"] # Example: 's3://sentinel-s2-l1c/tiles/31/T/DJ/2020/6/4/0/B02.jp2' with product.rio_env(dataset_url) as env: with rasterio.open(dataset_url) as src: # Read with proper AWS credentials data = src.read(1) print(f"Data shape: {data.shape}") print(f"Bounds: {src.bounds}") print(f"Resolution: {src.res}") # For asset-specific environment with product.assets["blue"].rio_env(): blue_url = product.assets["blue"]["href"] with rasterio.open(blue_url) as src: metadata = src.meta profile = src.profile print(f"Metadata: {metadata}") ``` -------------------------------- ### Install eodag-cube Python Package Source: https://github.com/cs-si/eodag-cube/blob/develop/README.rst Installs the eodag-cube package using pip. This command is typically run in a terminal or command prompt. ```python python -m pip install eodag-cube ``` -------------------------------- ### Search and Get Raster Dataset with EO-DAG Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/clip-reproject.ipynb This snippet shows how to initialize EO-DAG, define search criteria for satellite imagery (S2_MSI_L2A_COG), execute the search, and retrieve the first matching product. It then converts a specified asset ('B01') into an xarray Dataset using the 'rasterio' engine, making it ready for further processing. ```python from eodag import EODataAccessGateway dag = EODataAccessGateway() search_criteria = { "productType": "S2_MSI_L2A_COG", "start": "2024-04-01", "end": "2024-04-30", "geom": {"lonmin": 1.306, "latmin": 42.527, "lonmax": 1.551, "latmax": 42.662}, "cloudCover": 1, # Cloud cover < 1 } search_results = dag.search(**search_criteria) product = search_results[0] ds = product.assets["B01"].to_xarray(engine="rasterio") ``` -------------------------------- ### Get fsspec file object for custom processing with EOProduct Source: https://context7.com/cs-si/eodag-cube/llms.txt Demonstrates how to obtain an fsspec file object from an EOProduct for low-level file access. It shows how to get the object for the entire product or specific assets and how to integrate it with libraries like rasterio. It also covers handling offline products with wait and timeout parameters. ```python from eodag import EODataAccessGateway import rasterio dag = EODataAccessGateway() search_results = dag.search( provider='earth_search', collection='S2_MSI_L1C', geom=[1, 43.5, 2, 44], start='2020-06-04', end='2020-06-05', ) product = search_results[0] # Get file object for entire product file_obj = product.get_file_obj() print(file_obj) # # Get file object for specific asset blue_file = product.assets["blue"].get_file_obj() print(blue_file) # # Use with rasterio for custom processing with product.rio_env(blue_file.path): with rasterio.open(blue_file.path) as src: # Read specific window window = rasterio.windows.Window(0, 0, 512, 512) data = src.read(1, window=window) print(f"Window shape: {data.shape}") print(f"CRS: {src.crs}") print(f"Transform: {src.transform}") # For offline products, wait for availabilityoffline_file = product.get_file_obj( wait=10.0, # Check every 10 minutes timeout=120.0 # Give up after 2 hours ) ``` -------------------------------- ### EODAG-Cube Local Fallback and Archive Handling - Python Source: https://context7.com/cs-si/eodag-cube/llms.txt This example illustrates EODAG-Cube's capability to automatically fall back to local data sources when remote access fails. The library can download and extract archives, as well as scan configured local directories to find requested data files. This ensures data availability even if the primary remote provider is unavailable or if data has been previously downloaded. ```python from eodag import EODataAccessGateway dag = EODataAccessGateway() search_results = dag.search( provider='some_provider', collection='some_collection', geom=[1, 43.5, 2, 44], start='2020-06-04', end='2020-06-05', ) product = search_results[0] # The library will attempt to find the product locally if remote access fails. # This might involve downloading, extracting archives, or scanning local directories. # No explicit code is needed here to trigger the fallback mechanism; it's automatic. ``` -------------------------------- ### EODAG-cube: Get File Object for Asset (Python) Source: https://github.com/cs-si/eodag-cube/blob/develop/README.rst Retrieves a file-like object for a specific asset using fsspec, enabling direct interaction with the data file (e.g., for streaming or further processing). ```python product.assets["blue"].get_file_obj() ``` -------------------------------- ### Detect xarray Engines for Files - Python Source: https://context7.com/cs-si/eodag-cube/llms.txt The `guess_engines` utility function identifies compatible xarray backends for a given file, based on its extension and available installed libraries. It supports formats like GeoTIFF, NetCDF, and GRIB. The function takes a file-like object as input and returns a list of engine names, or an empty list if no compatible engines are found. It's useful for debugging and understanding data accessibility. ```python import fsspec from eodag_cube.utils.xarray import guess_engines # Check engines for GeoTIFF fs = fsspec.filesystem("https") file = fs.open("https://example.com/satellite.tif") engines = guess_engines(file) print(engines) # ['rasterio'] # Check engines for NetCDF file = fs.open("https://example.com/climate.nc") engines = guess_engines(file) print(engines) # ['h5netcdf', 'netcdf4', 'scipy'] # Check engines for GRIB file = fs.open("https://example.com/weather.grib") engines = guess_engines(file) print(engines) # ['cfgrib'] # Check engines for unknown format file = fs.open("https://example.com/data.dat") engines = guess_engines(file) print(engines) # [] (no engines found) # List all available xarray engines import xarray as xr all_engines = xr.backends.list_engines() print(all_assets.keys()) # dict_keys(['netcdf4', 'h5netcdf', 'scipy', 'pseudonetcdf', # 'zarr', 'cfgrib', 'pynio', 'rasterio']) ``` -------------------------------- ### Initialize EODataAccessGateway Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/to_xarray.ipynb Initializes the EODataAccessGateway object from the eodag library. This is the first step to interact with data providers and search for products. ```python from eodag import EODataAccessGateway dag = EODataAccessGateway() ``` -------------------------------- ### EODAG-cube: Search and Access Earth Observation Data (Python) Source: https://github.com/cs-si/eodag-cube/blob/develop/README.rst Demonstrates using the EODataAccessGateway to search for satellite data based on criteria like provider, collection, geometry, and time range. It then shows how to retrieve a product and convert it to an Xarray format. ```python from eodag import EODataAccessGateway from rasterio.crs import CRS dag = EODataAccessGateway() search_criteria = dict( provider='earth_search', collection='S2_MSI_L1C', geom=[1, 43.5, 2, 44], start='2020-06-04', end='2020-06-05', ) search_results = dag.search(**search_criteria) product = search_results[0] product ``` -------------------------------- ### try_open_dataset for Smart File Opening Source: https://context7.com/cs-si/eodag-cube/llms.txt Explains the try_open_dataset utility for intelligently opening datasets. It automatically detects file types and selects appropriate xarray engines, supporting both local and remote files and allowing custom engine specification and xarray parameters. ```python import fsspec from eodag_cube.utils.xarray import try_open_dataset # Open local GeoTIFF file fs = fsspec.filesystem("file") file = fs.open("/path/to/satellite_image.tif") dataset = try_open_dataset(file) # Automatically uses rasterio engine for GeoTIFF print(dataset) # Open remote NetCDF file fs = fsspec.filesystem("https") file = fs.open("https://example.com/data/climate.nc") dataset = try_open_dataset(file) # Automatically uses h5netcdf or netcdf4 engine print(dataset.data_vars) # Open with specific engine file = fs.open("https://example.com/data/weather.grib") dataset = try_open_dataset(file, engine="cfgrib") print(dataset) # Open with custom xarray parameters file = fs.open("/path/to/large_dataset.nc") dataset = try_open_dataset( file, chunks={"time": 10, "lat": 100, "lon": 100}, decode_times=True, mask_and_scale=True ) print(dataset.chunks) # Handles various formats automatically: ``` -------------------------------- ### Order Offline EO Products with Wait/Timeout - Python Source: https://context7.com/cs-si/eodag-cube/llms.txt This code demonstrates how to handle EO products that are initially offline and require ordering. The EODAG library can automatically trigger orders and wait for the product to become available. Users can customize the polling interval (`wait`) and the maximum waiting time (`timeout`) for the order to complete. It also shows how to order specific assets or monitor the ordering process using `get_file_obj`. ```python from eodag import EODataAccessGateway dag = EODataAccessGateway() search_results = dag.search( provider='some_provider', collection='archive_collection', geom=[1, 43.5, 2, 44], start='2018-01-01', end='2018-01-31', ) product = search_results[0] # Check if product is offline print(product.properties.get("order:status")) # 'offline' # Order and wait for product (default: check every 5 minutes, timeout after 20 minutes) xarray_dict = product.to_xarray() # Custom wait interval and timeout xarray_dict = product.to_xarray( wait=10.0, # Check order status every 10 minutes timeout=120.0 # Give up after 2 hours ) # Order specific asset only blue_dataset = product.assets["blue"].to_xarray( wait=5.0, timeout=60.0 ) # Monitor ordering process with explicit file access try: file_obj = product.get_file_obj(wait=15.0, timeout=180.0) # Product ordered and available print(f"Product available at: {file_obj.path}") except Exception as e: # Ordering failed or timed out print(f"Failed to access product: {e}") # After successful order, product status changes print(product.properties.get("order:status")) # 'online' ``` -------------------------------- ### Load EO Data: Auto-Download, Local Access (Python) Source: https://context7.com/cs-si/eodag-cube/llms.txt Demonstrates loading Earth Observation data using EODAG-cube. It first attempts remote access and falls back to downloading the product if remote access fails. The code then loads the data from the local path into an xarray dictionary. It works with single files, directories, and archives. ```python try: # First attempts remote access via HTTP/S3 xarray_dict = product.to_xarray() except Exception: # If remote access fails, automatic fallback occurs: # 1. Download product (triggers product.download()) # 2. Extract if archive (zip, tar, etc.) # 3. Scan local directory for data files # 4. Build XarrayDict from found files # 5. Return local data pass # Force download and local access product_path = product.download(extract=True) print(f"Downloaded to: {product_path}") # Load from local path local_xarray_dict = product.to_xarray() # Works with both: # - Single files: /path/to/product.tif # - Directories: /path/to/product/ (scans recursively) # - Archives: /path/to/product.zip (extracts first) ``` -------------------------------- ### EODAG-cube: Convert Product to XarrayDict (Python) Source: https://github.com/cs-si/eodag-cube/blob/develop/README.rst Converts the entire EO product to an XarrayDict object, providing a convenient way to handle multi-band raster data. ```python product.to_xarray() ``` -------------------------------- ### Scan Local Directory for Files (Python) Source: https://context7.com/cs-si/eodag-cube/llms.txt Shows how to manually scan a local directory for data files using Python's pathlib and os modules. This is useful for inspecting the contents after a download or when dealing with local data sources. It handles both single files and recursively scans directories. ```python from pathlib import Path import os if os.path.isfile(product_path): files = [product_path] else: files = [str(x) for x in Path(product_path).rglob("*") if x.is_file()] print(f"Found {len(files)} files") for f in files[:5]: print(f" {f}") ``` -------------------------------- ### Configure HTTP header authentication for data access Source: https://context7.com/cs-si/eodag-cube/llms.txt Illustrates how to configure EO products to use HTTP header-based authentication, commonly required for APIs that use API keys or tokens. It shows the registration of a downloader with HTTPHeaderAuth for both API key and Bearer token authentication. ```python from eodag import EODataAccessGateway from eodag.plugins.download import Download from eodag.plugins.authentication.header import HTTPHeaderAuth from eodag.config import PluginConfig dag = EODataAccessGateway() search_results = dag.search(provider='some_provider', collection='some_collection') product = search_results[0] # Register downloader with header authentication product.register_downloader( Download("provider", PluginConfig()), HTTPHeaderAuth( "provider", PluginConfig.from_mapping({ "credentials": {"apikey": "your_secret_api_key_here"}, "headers": {"X-API-Key": "{apikey}"} }) ) ) # Now access the product with automatic authentication xarray_dict = product.to_xarray() # Headers are automatically added to HTTP requests # Request includes: X-API-Key: your_secret_api_key_here # Example with Bearer token authentication product.register_downloader( Download("provider", PluginConfig()), HTTPHeaderAuth( "provider", PluginConfig.from_mapping({ "credentials": {"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."}, "headers": {"Authorization": "Bearer {token}"} }) ) ) # Access with bearer token dataset = product.assets["data"].to_xarray() ``` -------------------------------- ### XarrayDict for Multiple Datasets Source: https://context7.com/cs-si/eodag-cube/llms.txt Illustrates the usage of XarrayDict, a specialized dictionary for managing multiple xarray Datasets. It supports iteration, direct access, sorting, and both manual and automatic resource cleanup using context managers. ```python from eodag import EODataAccessGateway dag = EODataAccessGateway() search_results = dag.search( provider='earth_search', collection='S2_MSI_L1C', geom=[1, 43.5, 2, 44], start='2020-06-04', end='2020-06-05', ) product = search_results[0] # Get XarrayDict xarray_dict = product.to_xarray() print(xarray_dict) # Iterate over datasets for band_name, dataset in xarray_dict.items(): print(f"{band_name}: {dataset.dims}") # Access specific datasets blue = xarray_dict['blue'] red = xarray_dict['red'] # Sort datasets by key xarray_dict.sort() print(list(xarray_dict.keys())) # Manual resource management xarray_dict.close() # Close all datasets and file objects # Automatic resource management with context manager with product.to_xarray() as xarray_dict: # Process data for key, ds in xarray_dict.items(): mean = ds.band_data.mean().compute() print(f"{key} mean: {mean}") # Compute RGB composite if all(band in xarray_dict for band in ['red', 'green', 'blue']): import numpy as np rgb = np.stack([ xarray_dict['red'].band_data.values[0], xarray_dict['green'].band_data.values[0], xarray_dict['blue'].band_data.values[0] ], axis=-1) print(f"RGB composite shape: {rgb.shape}") # Resources automatically cleaned up ``` -------------------------------- ### Convert Grib Data to xarray from dedl Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/to_xarray.ipynb Searches for 'DT_CLIMATE_ADAPTATION' product data from the 'dedl' provider for a specified date range and converts the first result to an xarray Dataset using the `to_xarray` method. This process reads data locally after download and requires 'cfgrib'. ```python prods = dag.search(provider="dedl", productType="DT_CLIMATE_ADAPTATION", start="2025-01-01", end="2025-01-02") xd_grib = prods[0].to_xarray() ``` -------------------------------- ### Load Product to Xarray Dataset using EOProduct.to_xarray() Source: https://context7.com/cs-si/eodag-cube/llms.txt Converts an Earth Observation product into a dictionary of xarray Datasets. This method handles single-file and multi-asset products with automatic parallel loading. It supports specifying roles, custom xarray parameters like chunking, masking, and engine selection, and can be used with a context manager for proper file handling. ```python from eodag import EODataAccessGateway # Initialize gateway and search for products dag = EODataAccessGateway() search_results = dag.search( provider='earth_search', collection='S2_MSI_L1C', geom=[1, 43.5, 2, 44], # [lonmin, latmin, lonmax, latmax] start='2020-06-04', end='2020-06-05', ) # Get first product product = search_results[0] # Load all product data (all bands) xarray_dict = product.to_xarray() # Returns: XarrayDict with multiple Datasets # Example: {'blue': , 'red': , 'nir': } # Access specific dataset blue_band = xarray_dict['blue'] print(blue_band) # Size: 123MB # Dimensions: (band: 1, x: 10980, y: 10980) # Coordinates: # * band (band) int64 8B 1 # * x (x) float64 88kB 6e+05 6e+05 6e+05 ... 7.098e+05 7.098e+05 # * y (y) float64 88kB 4.9e+06 4.9e+06 4.9e+06 ... 4.79e+06 4.79e+06 # Data variables: # band_data (band, y, x) uint16 241MB ... # Load only specific roles (data, data-mask, metadata, etc.) data_only = product.to_xarray(roles={"data"}) # Pass custom xarray parameters for chunking and processing chunked_data = product.to_xarray( chunks={"x": 512, "y": 512}, # Dask chunking for large datasets masked=True, # Apply mask to invalid data engine="rasterio" # Force specific xarray engine ) # Use context manager to ensure files are properly closed with product.to_xarray() as xarray_dict: for key, dataset in xarray_dict.items(): print(f"Band {key}: shape {dataset.band_data.shape}") # Perform analysis... # Files automatically closed on exit ``` -------------------------------- ### Load Single Asset to Xarray Dataset using Asset.to_xarray() Source: https://context7.com/cs-si/eodag-cube/llms.txt Accesses individual assets (like bands or files) within a product and converts them into an xarray.Dataset. This is useful for loading specific bands without the entire product. It allows customization with parameters like wait time, timeout for ordering, and masking, and returned datasets can be further processed. ```python from eodag import EODataAccessGateway dag = EODataAccessGateway() search_results = dag.search( provider='earth_search', collection='S2_MSI_L1C', geom=[1, 43.5, 2, 44], start='2020-06-04', end='2020-06-05', ) product = search_results[0] # Load single asset (blue band) blue_dataset = product.assets["blue"].to_xarray() # Returns: xr.Dataset with blue band data print(blue_dataset) # Size: 241MB # Dimensions: (band: 1, x: 10980, y: 10980) # Data variables: # band_data (band, y, x) uint16 241MB ... # Attributes: # id: S2A_MSIL1C_20200604T105031_N0209_R051_T31TDJ # collection: S2_MSI_L1C # productType: S2_MSI_L1C # platformSerialIdentifier: S2A # List all available assets print(product.assets.keys()) # dict_keys(['blue', 'red', 'green', 'nir', 'coastal', 'rededge1', ...]) # Load with custom parameters red_dataset = product.assets["red"].to_xarray( wait=5.0, # Wait time for offline products (minutes) timeout=60.0, # Timeout for ordering (minutes) masked=True ) # Process the dataset mean_value = red_dataset.band_data.mean().compute() print(f"Mean red band value: {mean_value}") ``` -------------------------------- ### AWS S3 Authentication with eodag Source: https://context7.com/cs-si/eodag-cube/llms.txt Demonstrates how to register AWS S3 downloaders using different authentication methods, including basic credentials, custom endpoints, session tokens, and requester-pays buckets. These configurations are essential for accessing data stored in AWS S3 compatible storage. ```python from eodag import EODataAccessGateway from eodag.plugins.aws import AwsDownload, AwsAuth from eodag.utils.config import PluginConfig # Basic AWS S3 authentication product.register_downloader( AwsDownload("provider", PluginConfig()), AwsAuth( "provider", PluginConfig.from_mapping({ "credentials": { "aws_access_key_id": "AKIAIOSFODNN7EXAMPLE", "aws_secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" } }) ) ) # Access S3 data with credentials xarray_dict = product.to_xarray() # With custom S3 endpoint (e.g., MinIO, DigitalOcean Spaces) product.register_downloader( AwsDownload("provider", PluginConfig()), AwsAuth( "provider", PluginConfig.from_mapping({ "s3_endpoint": "https://nyc3.digitaloceanspaces.com", "credentials": { "aws_access_key_id": "YOUR_SPACES_KEY", "aws_secret_access_key": "YOUR_SPACES_SECRET" } }) ) ) # With session tokens (temporary credentials) product.register_downloader( AwsDownload("provider", PluginConfig()), AwsAuth( "provider", PluginConfig.from_mapping({ "credentials": { "aws_access_key_id": "ASIAIOSFODNN7EXAMPLE", "aws_secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY", "aws_session_token": "FwoGZXIvYXdzEBQa..." } }) ) ) # With requester-pays bucket product.register_downloader( AwsDownload("provider", PluginConfig()), AwsAuth( "provider", PluginConfig.from_mapping({ "credentials": { "aws_access_key_id": "AKIAIOSFODNN7EXAMPLE", "aws_secret_access_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" }, "requester_pays": True }) ) ) dataset = product.to_xarray() ``` -------------------------------- ### EODAG-cube: Access Single Asset as xarray.Dataset (Python) Source: https://github.com/cs-si/eodag-cube/blob/develop/README.rst Extracts a specific asset (e.g., 'blue' band) from the EO product and converts it into an xarray.Dataset object for detailed analysis. ```python product.assets["blue"].to_xarray() ``` -------------------------------- ### Configure AWS S3 authentication for data access Source: https://context7.com/cs-si/eodag-cube/llms.txt Details the configuration process for accessing data from S3-compatible storage using eodag. This includes support for custom endpoints, session tokens, and requester-pays buckets through the AwsAuth plugin. ```python from eodag import EODataAccessGateway from eodag.plugins.download.aws import AwsDownload from eodag.plugins.authentication.aws_auth import AwsAuth from eodag.config import PluginConfig dag = EODataAccessGateway() search_results = dag.search(provider='aws_provider', collection='some_collection') product = search_results[0] ``` -------------------------------- ### Convert NetCDF Data to xarray from cop_cds Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/to_xarray.ipynb Searches for 'ERA5_SL' product data from the 'cop_cds' provider for a specified date range and converts the first result to an xarray Dataset using the `to_xarray` method. Requires 'h5netcdf' for remote NetCDF handling. ```python prods = dag.search( provider="cop_cds", productType="ERA5_SL", start="2024-01-01", end="2024-01-02", **{"ecmwf:data_format": "netcdf", "ecmwf:download_format": "unarchived"}, ) xd_nc = prods[0].to_xarray() ``` -------------------------------- ### Clip Dataset using rioxarray clip_box Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/clip-reproject.ipynb This snippet demonstrates how to clip an xarray Dataset to a specified bounding box using the `clip_box` method from rioxarray. It requires the bounding box coordinates (minx, miny, maxx, maxy) and the CRS. The output is a clipped xarray Dataset. ```python minx, miny, maxx, maxy = product.search_intersection.bounds clipped_ds = ds.rio.clip_box(minx=minx, miny=miny, maxx=maxx, maxy=maxy, crs="EPSG:4326") clipped_ds ``` -------------------------------- ### Filter EO Assets by Role - Python Source: https://context7.com/cs-si/eodag-cube/llms.txt This snippet demonstrates how to filter Earth Observation (EO) assets based on their assigned roles (e.g., 'data', 'data-mask', 'thumbnail') when loading them into xarray datasets. By specifying desired roles, users can optimize performance by only downloading and processing necessary data bands. The `to_xarray` method of a product object accepts a `roles` argument, which can be a set of role strings or `None` to include all assets. ```python from eodag import EODataAccessGateway dag = EODataAccessGateway() search_results = dag.search( provider='earth_search', collection='S2_MSI_L1C', geom=[1, 43.5, 2, 44], start='2020-06-04', end='2020-06-05', ) product = search_results[0] # Check available roles in product for key, asset in product.assets.items(): if "roles" in asset: print(f"{key}: {asset['roles']}") # blue: ['data', 'reflectance'] # red: ['data', 'reflectance'] # thumbnail: ['thumbnail'] # quality: ['data-mask', 'cloud'] # Load only data assets (exclude masks and metadata) data_only = product.to_xarray(roles={"data"}) print(data_only.keys()) # dict_keys(['blue', 'red', 'green', 'nir', ...]) # Load data and quality masks data_and_masks = product.to_xarray(roles={"data", "data-mask"}) print(data_and_masks.keys()) # dict_keys(['blue', 'red', 'green', 'quality', 'cloud_mask', ...]) # Load all assets regardless of roles all_assets = product.to_xarray(roles=None) print(all_assets.keys()) # dict_keys(['blue', 'red', 'thumbnail', 'metadata', ...]) # Load only specific role types reflectance_bands = product.to_xarray(roles={"reflectance"}) thumbnails = product.to_xarray(roles={"thumbnail"}) ``` -------------------------------- ### Read Sentinel-2 L2A Raster Data from creodias_s3 with Python Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/to_xarray.ipynb This Python code snippet uses the eodag library to search for Sentinel-2 Level 2A products from the creodias_s3 provider within a specified date range. It then retrieves the first product and converts it into an xarray Dataset, making the raster data accessible for analysis. Dependencies include eodag and rasterio. ```python prods = dag.search( provider="creodias_s3", productType="S2_MSI_L2A", start="2024-01-01", end="2024-01-02", items_per_page=1 ) xd_s3_s2 = prods[0].to_xarray() xd_s3_s2 ``` -------------------------------- ### Reproject Dataset using rioxarray reproject Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/clip-reproject.ipynb This code snippet shows how to reproject a clipped xarray Dataset to a new Coordinate Reference System (CRS) and a specified resolution using the `reproject` method from rioxarray. It takes the destination CRS and resolution as input, returning a reprojected Dataset. ```python reproj_ds = clipped_ds.rio.reproject(dst_crs="EPSG:4326", resolution=0.0006) reproj_ds ``` -------------------------------- ### Plotting Reprojected Data Source: https://github.com/cs-si/eodag-cube/blob/develop/docs/notebooks/clip-reproject.ipynb This snippet visualizes the 'band_data' variable of the reprojected xarray Dataset using matplotlib. It generates a plot of the data, useful for verifying the clipping and reprojection results. ```python reproj_ds.band_data.plot() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.