Microsoft Planetary Computer Examples

repository·main·Indexed 19 days ago

https://github.com/microsoft/planetarycomputerexamples

A collection of practical examples, quickstarts, and tutorials for the Microsoft Planetary Computer. It provides guidance on accessing and processing geospatial analyses using STAC APIs, Dask, Xarray, and Leafmap. Featured content includes workflows for the Global Downscaled Projections for Climate Impacts Research (GDPCIR) dataset, 3DEP seamless DEM data, and benchmark tutorials for the Cloud Cover competition using PyTorch Lightning.

Tokens
9.4K
Snippets
35
Records
40
Agent score
66%

What's inside microsoft-planetarycomputerexamples

  1. Overview of the GDPCIR dataset

    main

    The Global Downscaled Projections for Climate Impacts Research (GDPCIR) dataset, produced by the Climate Impact Lab, provides global, daily climate variables on a 1/4-degree regular global grid.

    Key variables included:

    • tasmin: Daily minimum air temperature at the surface.
    • tasmax: Daily maximum air temperature at the surface.
    • pr: Daily cumulative surface precipitation.

    Supported scenarios:

    • CMIP6 historical
    • ssp1-2.6
    • ssp2-4.5
    • ssp3-7.0
    • ssp5-8.5

    The dataset covers 25 global climate models.

  2. Explore Planetary Computer examples and tutorials

    main

    The planetarycomputerexamples repository provides a collection of notebooks and guides for working with the Planetary Computer Hub. You can use these resources to learn how to access STAC APIs, work with specific datasets (like Sentinel-2, Landsat, or ERA5), and perform advanced geospatial analyses using tools like Dask, Xarray, and Leafmap.

    To view these examples without local setup, you can use nbviewer.

    Key learning paths include:

    • Quickstarts: High-level introductions to topics like reading STAC APIs, Zarr data, or using Leafmap.
    • Datasets: Specific implementation examples for various geospatial datasets.
    • Tutorials: In-depth guides on complex topics like Cloudless Mosaics, Landcover Classification, and Zonal Statistics.
  3. Advanced GDPCIR workflows: Ensembles and Indicators

    main

    Beyond basic exploration, you can use the following notebooks to perform advanced climate analysis:

    • Building Ensembles: Use ensemble.ipynb to learn how to select specific STAC collections and build climate model ensembles.
    • Computing Indicators: Use indicators.ipynb to compute climate and impact indicators using the xclim library.
    Notebooks available:
    - ./ensemble.ipynb
    - ./indicators.ipynb
  4. Inspect Sentinel-1 RTC assets and metadata

    main

    Sentinel-1 RTC items contain assets representing terrain-corrected gamma nought values for different polarizations. Common asset names include hh, hv, vh, and vv. You can check available polarizations using the sar:polarizations property in the STAC metadata. For quick visualization, use the rendered_preview asset.

    # Check available polarizations
    print(item.properties["sar:polarizations"])
    
    # Quick visualization using the rendered_preview asset
    from IPython.display import Image
    Image(url=item.assets["rendered_preview"].href)
  5. Compare Sentinel-1 GRD and RTC products

    main

    Every Sentinel-1 RTC item is derived from a Sentinel-1 GRD item. You can find the original GRD item by following the derived_from link in the RTC item's metadata. RTC products are terrain-corrected, meaning they align more accurately with Earth's surface compared to the original GRD products.

    # Get the RTC item
    rtc_item = catalog.get_collection("sentinel-1-rtc").get_item("ITEM_ID")
    
    # Access the original GRD item via the 'derived_from' link
    import pystac
    gr_item = pystac.read_file(rtc_item.get_single_link("derived_from").target)
  6. Run the Local Server via Docker Compose

    main

    The localserver service runs a simple Python HTTP server on port 8889. It is used to serve local files from the datasets, quickstarts, and tutorials directories. These directories are mounted to /opt/src inside the container. To start the service, run docker-compose up.

    localserver:
            image: python:3.9-alpine
            ports:
                - "8889:8889"
            volumes:
                - ./datasets:/opt/src/datasets
                - ./quickstarts:/opt/src/quickstarts
                - ./tutorials:/opt/src/tutorials
            command: python3 -m "http.server" 8889 -d /opt/src
  7. Set up Planetary Computer API authentication

    main

    To access data with more permissive access, you should use a subscription key. If you are running on the Planetary Computer Hub, the environment variable PC_SDK_SUBSCRIPTION_KEY is set automatically. Otherwise, you can manually set your key using pc.settings.set_subscription_key().

    import planetary_computer as pc
    # Replace <YOUR API Key> with your actual key from the developer portal
    pc.settings.set_subscription_key(<YOUR API Key>)
  8. Set up your Planetary Computer environment

    main

    To use the Planetary Computer locally, you must provide an API key. You can do this by setting the PC_SDK_SUBSCRIPTION_KEY environment variable or by using the planetary_computer.settings.set_subscription_key() method in your Python code.

    # Option 1: Set environment variable PC_SDK_SUBSCRIPTION_KEY
    
    # Option 2: Use the SDK method
    import planetary_computer
    planetary_computer.settings.set_subscription_key('<YOUR API Key>')
  9. Set up the Planetary Computer environment

    main

    To access data with more permissive access, you should use an API key. You can set the PC_SDK_SUBSCRIPTION_KEY environment variable or use the planetary_computer SDK to set it programmatically. If you are using the Planetary Computer Hub, the key is configured automatically.

    Required imports for Sentinel-2 workflows:

    from pystac.extensions.eo import EOExtension as eo
    import pystac_client
    import planetary_computer
    import planetary_computer
    
    # Set the subscription key programmatically
    planetary_computer.settings.set_subscription_key('<YOUR API Key>')
  10. Prepare a Code Execution submission for Cloud Cover challenge

    main

    This competition requires a code execution submission (submission.zip) rather than just a CSV of predictions. Your submission must contain a folder (e.g., benchmark_src) with the following structure:

    1. Model Weights: The trained .ckpt or weight files.
    2. cloud_dataset.py: The dataset implementation.
    3. cloud_model.py: The model implementation.
    4. losses.py: Custom loss functions (e.g., intersection_over_union).
    5. main.py: The entry point script. It must:
      • Load the model weights.
      • Perform inference on images in data/test_features.
      • Save predictions as .tif files in a predictions/ directory.
      • Crucially: main.py must run via python main.py without any command-line arguments.

    Submission Format: Zip the contents of your source folder (not the folder itself) into submission.zip.

    Note: Do not include the actual prediction files in your zip archive.