ldcast

Latent diffusion for generative precipitation nowcasting

https://github.com/meteoswiss/ldcast

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.0%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Latent diffusion for generative precipitation nowcasting

Basic Info
  • Host: GitHub
  • Owner: MeteoSwiss
  • License: apache-2.0
  • Language: Python
  • Default Branch: master
  • Size: 169 KB
Statistics
  • Stars: 134
  • Watchers: 8
  • Forks: 16
  • Open Issues: 8
  • Releases: 0
Created over 3 years ago · Last pushed about 3 years ago
Metadata Files
Readme License

README.md

LDCast is a precipitation nowcasting model based on a latent diffusion model (LDM, used by e.g. Stable Diffusion).

This repository contains the code for using LDCast to make predictions and the code used to generate the analysis in the LDCast paper (a preprint is available at https://arxiv.org/abs/2304.12891).

A GPU is recommended for both using and training LDCast, although you may be able to generate some samples with a CPU and enough patience.

Installation

It is recommended you install the code in its own virtual environment (created with e.g. pyenv or conda).

Clone the repository, then, in the main directory, run bash $ pip install -e . This should automatically install the required packages (which might take some minutes). In the paper, we used PyTorch 11.2 but are not aware of any problems with newer versions.

If you don't want the requirements to be installed (e.g. if you installed them manually with conda), use: bash $ pip install --no-dependencies -e .

Using LDCast

Pretrained models

The pretrained models are available at the Zenodo repository https://doi.org/10.5281/zenodo.7780914. Unzip the file ldcast-models.zip. The default is to unzip it to the models directory, but you can also use another location.

Producing predictions

The easiest way to produce predictions is to use the ldcast.forecast.Forecast class, which will set up all models and data transformations and is callable with a past precipitation array. ```python from ldcast import forecast

fc = forecast.Forecast( ldmweightsfn=ldmweightsfn, autoencweightsfn=autoencweightsfn ) Rpred = fc(Rpast) `` Here,ldmweightsfnis the path to the LDM weights andautoencweightsfnis the path to the autoencoder weights.R_pastis a NumPy array of precipitation rates with shape(timesteps, height, width)wheretimestepsmust be 4 andheightandwidth` must be divisible by 32.

Ensemble predictions

If want to process multiple cases at once and/or generate several ensemble members, there is the ldcast.forecast.ForecastDistributed class. The usage is similar to the Forecast class, for example: ```python from ldcast import forecast

fc = forecast.ForecastDistributed( ldmweightsfn=ldmweightsfn, autoencweightsfn=autoencweightsfn ) Rpred = fc(Rpast, ensemblemembers=32) `` Here,Rpastshould be of shape(cases, timesteps, height, width)wherecasesis the number of cases you want to process. For each case,ensemblememberspredictions are produced (this is the last axis ofRpred).ForecastDistributed` automatically distributes the workload to multiple GPUs if you have them.

Demo

For a practical example, you can run the demo in the scripts directory. First download the ldcast-demo-20210622.zip file from the Zenodo repository, then unzip it in the data directory. Then run bash $ python forecast_demo.py A sample output can be found in the file ldcast-demo-video-20210622.zip in the data repository. See the function forecast_demo in forecast_demo.py see how the Forecast class works. To run an ensemble mean of 8 members using the ForecastDistributed class, you can use: bash $ python forecast_demo.py --ensemble-members=8

The demo for a single ensemble member runs in a couple of minutes on our system using one V100 GPU; with a CPU around 10 minutes or more would be expected. A progress bar will show the status of the generation.

Training

Training data

The preprocessed training data, needed to rerun the LDCast training, can be found at the Zenodo repository. Unzip the ldcast-datasets.zip file to the data directory.

Training the autoencoder

In the scripts directory, run bash $ python train_autoenc.py --model_dir="../models/autoenc_train" to run the training of the autoencoder with the default parameters. The training checkpoints will be saved in the ../models/autoenc_train directory (feel free to change this).

It has been reported that this training may encounter a condition where the loss goes to nan. If this happens, try restarting from the latest checkpoint: bash $ python train_autoenc.py --model_dir="../models/autoenc_train" --ckpt_path="../models/autoenc_train/<checkpoint_file>" where <checkpoint_file> should be the latest checkpoint in the ../models/autoenc_train/ directory.

Training the diffusion model

In the scripts directory, run bash $ python train_genforecast.py --model_dir="../models/genforecast_train" to run the training of the diffusion model with the default parameters, or bash $ python train_genforecast.py --model_dir="../models/genforecast_train" --config=<path_to_config_file> to run the training with different parameters. Some config files can be found in the config directory. The training checkpoints will be saved in the ../models/genforecast_train directory (again, this can be changed freely).

Evaluation

You can find scripts for evaluating models in the scripts directory: * eval_genforecast.py to evaluate LDCast * eval_dgmr.py to evaluate DGMR (requires tensorflow installation and the DGMR model from https://github.com/deepmind/deepmind-research/tree/master/nowcasting placed in the models/dgmr directory) * eval_pysteps.py to evaluate PySTEPS (requires pysteps installation) * metrics.py to produce metrics from the evaluation results produced with the functions in scripts above * plot_genforecast.py to make plots from the results generated

Owner

  • Name: MeteoSwiss
  • Login: MeteoSwiss
  • Kind: organization
  • Location: Zurich, Geneva, Locarno, Payerne

Federal Office of Meteorology and Climatology MeteoSwiss

GitHub Events

Total
  • Watch event: 24
  • Fork event: 2
Last Year
  • Watch event: 24
  • Fork event: 2

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 24
  • Total Committers: 2
  • Avg Commits per committer: 12.0
  • Development Distribution Score (DDS): 0.458
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Jussi Leinonen j****n@m****h 13
Jussi Leinonen j****n@g****m 11
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 20
  • Total pull requests: 0
  • Average time to close issues: 17 days
  • Average time to close pull requests: N/A
  • Total issue authors: 12
  • Total pull request authors: 0
  • Average comments per issue: 2.15
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • nathzi1505 (4)
  • bugsuse (3)
  • tomasvanoyen (3)
  • caglarkucuk (1)
  • jacksd233 (1)
  • jichongxing2023 (1)
  • wang6501sfx (1)
  • ajikmr (1)
  • M4verrick (1)
  • DaDaDa-FH (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Dependencies

setup.py pypi
  • dask *
  • einops *
  • fire *
  • h5py *
  • matplotlib *
  • netCDF4 *
  • numba *
  • numpy *
  • omegaconf *
  • pyshp *
  • pytorch-lightning *
  • scipy *
  • torch *
  • tqdm *