CoolFace
Apppublic

4l3x4ndre/Metadata-Augmented-UNET-LST-NDVI-prediction

sourceHugging Facemitupdated 10mo agoView on Hugging Face
0likes
App README

๐Ÿ™๏ธ Urban Greening Planner: High-Resolution LST and NDVI Forecasting

This project presents a data-driven deep learning framework designed to predict future Land Surface Temperature (LST) and Normalized Difference Vegetation Index (NDVI) maps conditioned on proposed changes in land cover. It serves as a tool to estimate the microclimatic impact of urban modifications.

The core model is a multi-modal U-Net that fuses high-resolution satellite imagery with non-spatial environmental context (static geographical and demographic metadata) to forecast environmental variables.

![Open in Spaces](https://huggingface.co/spaces/4l3x4ndre/Metadata-Augmented-UNET-LST-NDVI-prediction)

๐ŸŽฏ Project Goal

As urban areas expand, accurate forecasting of the microclimatic impact of land-use changes is essential. This project aims to:

  • โ€”Predict future LST and NDVI based on user-defined land-use change scenarios.
  • โ€”Provide a rapid, scalable alternative to computationally expensive traditional simulations (e.g., CFD).
  • โ€”Quantify cooling potentials of green infrastructure interventions.

Detailed methodology and results are available in the manuscript (soon).

๐Ÿ—๏ธ Architecture & Models

The project implements a Metadata-Augmented U-Net architecture.

  • โ€”Backbone: Standard U-Net (or U-Net++) for spatial translation.
  • โ€”Embeddings:
  • โ€”Metadata Encoder: An MLP processes static data (latitude, longitude, population, time delta) to condition the model on the climatic zone.
  • โ€”Temporal Encoder (Optional): An LSTM processes historical temperature time series (CRU data), though findings suggest static metadata is superior for this task.
  • โ€”Fusion: Embeddings are broadcasted and concatenated at the U-Net bottleneck (or throughout the decoder in U-Net++).

Architecture diagram of the U-Net variants:

[image]

Source code for the models can be found in `src/model.py`.

Note: Due to storage constraints, only 2 trained models are included in this repository:

  1. 1.BEST_metadata_unet.pth (Our best performing model)
  2. 2.standard_no-embedding_unet.pth (Baseline)

These two models are available in the Hugging Face Space.

โš™๏ธ Installation

  1. 1.Clone the repository:
bash
    git clone <repository_url>
    cd urban_planner
  1. 1.Install dependencies:
bash
    pip install -r requirements.txt
  1. 1.Earth Engine Setup: The project relies on Google Earth Engine. Ensure you have a GEE account and authenticate:
bash
    earthengine authenticate
  1. 1.Environment Variables (.env): This project uses dotenv to manage environment variables. Create a .env file in the root directory of the project and populate it with the necessary variables. An example .env file might look like this:
    WANDB_API_KEY="your_wandb_api_key_here"
    GEE_SERVICE_ACCOUNT="your-gee-service-account@your-project-id.iam.gserviceaccount.com"
    GEE_PROJECT_ID="your-gee-project-id"

Remember to replace the placeholder values with your actual API key, service account, and project ID. Information on GEE service accounts.

  1. 1.Data Acquisition:

This project saves each sample as a separate .npz file. Due to data size constraints, the data set is not included in the repository. To create the data set, run:

bash
   python -m src.data.parallel_dataset 

or use hpc/dataset.slurm

Then:

bash
   python -m src.data.processing_10m.process

or use hpc/dataset_process_10m.slurm.

Processed temperatures are included. To download the raw temperatures:

bash
   python -m src.data.nc_file_aggregator

or use hpc/dataset_process_temperature.slurm.

๐Ÿš€ Usage

๐Ÿงช Model Evaluation

The test directory contains a suite for evaluating trained model checkpoints.

To run the evaluation:

bash

python test/evaluate.py --checkpoint-path /path/to/your/model.pth

Key Features:

  • โ€”Per-Class Metrics: MAE/RMSE breakdown by Dynamic World land cover types.
  • โ€”Interpretable Errors: Reports LST errors in ยฐC.
  • โ€”Image Quality: Assesses output sharpness using Laplacian Variance.
  • โ€”Visualizations: Generates Ground Truth vs. Prediction plots.
  • โ€”WandB Integration: Logs metrics to Weights & Biases.

See `test/evaluate.py` for implementation details.

๐Ÿ“ฑ App: Interactive Urban Greening Planner

The project includes an interactive Streamlit application (located at `app/Home.py`) that allows you to explore the model's capabilities in a user-friendly interface. This application enables you to:

  • โ€”Select any location and time period to fetch real-time satellite data from Google Earth Engine.
  • โ€”Design custom urban greening or land-use change scenarios on an interactive canvas.
  • โ€”Forecast the microclimatic impact (LST and NDVI) of your proposed changes using a pre-trained model.

Getting Started with the App:

  1. 1.Earth Engine Credentials: The application fetches live data from Google Earth Engine. To use it, you will need to provide your GEE credentials
  • โ€”GEE Project ID: Your Google Cloud Project ID linked to your Earth Engine account.
  • โ€”GEE Service Account: The email address of your service account.
  • โ€”Service Account Private Key File (`.private-key.json`): Ensure this file is present in the root directory of the project. You can find more information on setting up a service account here.

You can either set these credentials in a .env file (as described in the "Environment Variables" section above) or directly within the application's "Google Earth Engine Credentials" expander on the main page.

  1. 1.Run the Application:
bash
    streamlit run app/Home.py
  1. 1.Demo:

[image]

๐Ÿ“Š Data & Licensing

๐Ÿ›ฐ๏ธ Data Sources

All images come from Google Earth Engine datasets:

  • โ€”Satellite Imagery: Sentinel-2 (ESA) and Landsat 8 (USGS).
  • โ€”Land Cover: Dynamic World V1 (Google/WRI).
  • โ€”Climate Data: Climatic Research Unit (CRU) Time Series.

Metadata source:

โš–๏ธ Licenses

  • โ€”Code: MIT License
  • โ€”CRU Data: The Climatic Research Unit gridded Time Series (CRU) dataset is distributed under the Creative Commons Attribution License 4.0 and the Open Data Commons Attribution License. See `docs/licenses/LICENSE_CRU.txt` for full terms.
  • โ€”Copernicus Data: Uses data from the Copernicus Climate Change Service.

โš–๏ธ Code Used

  • โ€”Beatiful Figures: Andrey Churkin's repository on GitHub under MIT License.
  • โ€”PyTorch Nested U-Net 4ui_iurz1's repository on GitHub under MIT License.

๐Ÿ“ Directory

urban_planner/
โ”œโ”€โ”€ conf/               # Configuration files
โ”œโ”€โ”€ app/                # Streamlit application
โ”œโ”€โ”€ app_dev/            # Streamlit application used to produce figures and interpret results
โ”œโ”€โ”€ data/               # Data storage (raw/processed)
โ”œโ”€โ”€ docs/               # Documentation and manuscript
โ”œโ”€โ”€ hpc/                # SLURM scripts for HPC
โ”œโ”€โ”€ src/                # Source code (data loading, modeling, training)
โ”œโ”€โ”€ test/               # Evaluation scripts
โ””โ”€โ”€ reports/            # Generated analysis and figures