Skip to main content

Add your description here

Project description

CML Wet-Dry PyTorch

License Python PyTorch

A PyTorch re-implementation and improvement of commercial microwave link (CML) wet-dry detection based on Polz et al. 2020.

๐Ÿ”ฌ Overview

This project provides machine learning tools for rainfall detection and estimation using commercial microwave link (CML) data combined with weather radar observations. Commercial microwave links are telecommunication infrastructure that can be used as opportunistic sensors for precipitation monitoring, offering valuable insights for meteorological applications.

The package implements deep learning approaches to:

  • Detect precipitation events (wet/dry classification)
  • Estimate rainfall rates from CML signal attenuation
  • Process and analyze large meteorological datasets efficiently

โœจ Features

  • ๐Ÿง  Deep Learning Models: Custom CNN architecture for CML time series analysis
  • ๐Ÿ“Š Efficient Data Processing: Zarr-based dataset handling for large meteorological data
  • ๐Ÿ”ง Configurable Training: YAML-based experiment configuration
  • ๐Ÿ“ˆ Comprehensive Evaluation: Multiple metrics including accuracy, TPR, TNR, and correlation
  • ๐Ÿš€ Production Ready: Inference pipeline for integration in operational deployment

๐Ÿ› ๏ธ Installation

Requirements

  • Python โ‰ฅ 3.12
  • CUDA-capable GPU (recommended for training)

Install from source

git clone https://github.com/jpolz/cml_wd_pytorch.git
cd cml_wd_pytorch
pip install -e .

Dependencies

The project automatically installs:

  • PyTorch
  • XArray
  • Zarr
  • NumPy
  • Matplotlib
  • NetCDF4
  • Einops
  • scikit-learn
  • TQDM
  • PyYAML

๐Ÿš€ Quick Start

1. Configuration

Edit the configuration file to match your data paths:

# src/cml_wd_pytorch/config/config.yml
data:
  path_train: "/path/to/training/data.zarr"
  path_val: "/path/to/validation/data.zarr"
  reflength: 60

training:
  batch_size: 100
  epochs: 500
  learning_rate: 0.0001

2. [WIP] Training a Model

Wet/Dry Classification

from cml_wd_pytorch.train.training_wet_dry import main

# Run training with configuration
main()

Rain Rate Estimation

from cml_wd_pytorch.train.training_rain_rate import main

# Run training with configuration
main()

3. Running Inference

from cml_wd_pytorch.inference.run_inference import cnn_wd
import xarray as xr

# Load your CML data
data = xr.open_dataset("your_cml_data.nc")

# Ensure data is in the expected format
# Example: data should be an xarray DataArray of total loss (TL) with dimensions [time, channel_id, cml_id]
data = data["tl"].transpose("time", "channel_id", "cml_id")

# Run inference using either a model path or a run_id:
# Option 1: Provide the path to a trained model (.pth)
results = cnn_wd("path/to/trained/model.pth", data)

# Option 2: Provide a run_id (will automatically locate model and config in results/{run_id}/)
results = cnn_wd(run_id, data)

# Optionally, you can specify a custom config path:
# results = cnn_wd("path/to/trained/model.pth", data, config_path="path/to/config.yml")

๐Ÿ“Š Data Format for training

The package expects data in Zarr format with the following structure:

dataset.zarr/
โ”œโ”€โ”€ sample_number/     # Sample dimension
โ”œโ”€โ”€ channel_id/        # CML channel dimension  
โ”œโ”€โ”€ timestep/          # Time dimension
โ”œโ”€โ”€ tl/               # CML signal attenuation [sample_number, channel_id, timestep]
โ”œโ”€โ”€ radar/            # Radar rainfall [sample_number, timestep]
โ”œโ”€โ”€ wet_radar/        # Wet/dry labels [sample_number]
โ””โ”€โ”€ cml_rain/         # CML-derived rain rates [sample_number, timestep, channel_id]

๐Ÿ—๏ธ Project Structure

cml_wd_pytorch/
โ”œโ”€โ”€ src/cml_wd_pytorch/
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ””โ”€โ”€ cnn.py              # CNN model architecture
โ”‚   โ”œโ”€โ”€ train/
โ”‚   โ”‚   โ”œโ”€โ”€ training_wet_dry.py # Wet/dry classification training
โ”‚   โ”‚   โ””โ”€โ”€ training_rain_rate.py # Rain rate estimation training
โ”‚   โ”œโ”€โ”€ dataloader/
โ”‚   โ”‚   โ””โ”€โ”€ dataloaderzarr.py   # Zarr dataset loader
โ”‚   โ”œโ”€โ”€ inference/
โ”‚   โ”‚   โ””โ”€โ”€ run_inference.py    # Inference pipeline
โ”‚   โ”œโ”€โ”€ evaluation/
โ”‚   โ”‚   โ”œโ”€โ”€ summarize_scores.py # Evaluation utilities
โ”‚   โ”‚   โ””โ”€โ”€ summarize_scores_wet_dry.py
โ”‚   โ””โ”€โ”€ config/
โ”‚       โ””โ”€โ”€ config.yml          # Configuration file
โ”œโ”€โ”€ preprocessing/
โ”‚   โ”œโ”€โ”€ create_dataset.py       # Dataset creation pipeline
โ”‚   โ”œโ”€โ”€ cml_radklim_to_zarr.py  # Data format conversion
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ dummy_data.zarr         # Example dataset
โ”‚   โ”œโ”€โ”€ dummy_model             # Example models
โ”‚   โ””โ”€โ”€ gen_dummy_data.py       # Dummy data generator
โ”œโ”€โ”€ results/                    # Training outputs and models
โ”œโ”€โ”€ pyproject.toml              # Project configuration
โ”œโ”€โ”€ environment.yml             # Conda environment [outdated]
โ””โ”€โ”€ LICENSE                     # BSD 3-Clause License

๐ŸŽฏ Model Architecture

The CNN model features:

  • Input: 2-channel time series (180 timesteps)
  • Convolutional blocks: Multi-layer 1D convolutions with ReLU
  • Max pooling: Temporal dimensionality reduction
  • Fully connected layers: Dense layers with dropout (40% default)
  • Configurable output: Sigmoid (classification) or ReLU (regression)

Default architecture:

  • Filters: [48, 96, 96, 192, 192]
  • Kernel size: 3
  • FC neurons: 128
  • Dropout: 0.4

๐Ÿ“ˆ Performance Metrics

The package provides comprehensive evaluation:

Classification Metrics

  • Accuracy
  • True Positive Rate (TPR)
  • True Negative Rate (TNR)
  • Binary Cross Entropy (BCE) loss

Regression Metrics

  • Mean Squared Error (MSE)
  • Root Mean Squared Error (RMSE)
  • Pearson correlation coefficient

๐Ÿ”ฌ Scientific Background

This implementation is based on the methodology described in:

Polz, J., et al. (2020). "Rainfall event detection in commercial microwave link attenuation data using convolutional neural networks." Atmospheric Measurement Techniques, 13, 3835โ€“3853. DOI: 10.5194/amt-13-3835-2020

Commercial microwave links (CMLs) are point-to-point radio connections used in cellular networks. Rain causes signal attenuation that can be exploited for precipitation estimation, making CML networks valuable for meteorological applications.

๐Ÿ“š Examples

Example data and preprocessing scripts are available in the data/ and preprocessing/ directories:

  • Data preprocessing workflows
  • Model evaluation and analysis tools
  • Dummy data generation for testing

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Development Setup

git clone https://github.com/jpolz/cml_wd_pytorch.git
cd cml_wd_pytorch
pip install -e .[dev]

๐Ÿ‘ฅ Contributors

  • Julius Polz (@jpolz) - Main Author - Karlsruhe Institute of Technology
  • @waggerle - Contributor
  • @cchwala - Contributor

๐Ÿ“„ License

This project is licensed under the BSD 3-Clause License. See LICENSE for details.

๐Ÿ“ฌ Contact

  • Julius Polz - julius.polz@kit.edu
  • Karlsruhe Institute of Technology (KIT)
  • Institute of Meteorology and Climate Research

๐Ÿ”— Related Publications

If you use this software in your research, please cite:

@article{polz_rain_2020,
	title = {Rain event detection in commercial microwave link attenuation data using convolutional neural networks},
	volume = {13},
	issn = {1867-1381},
	doi = {https://doi.org/10.5194/amt-13-3835-2020},
	number = {7},
	urldate = {2020-12-04},
	journal = {Atmospheric Measurement Techniques},
	author = {Polz, Julius and Chwala, Christian and Graf, Maximilian and Kunstmann, Harald},
	month = jul,
	year = {2020},
	note = {Publisher: Copernicus GmbH},
	pages = {3835--3853},

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cml_wd_pytorch-0.1.4.tar.gz (5.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cml_wd_pytorch-0.1.4-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file cml_wd_pytorch-0.1.4.tar.gz.

File metadata

  • Download URL: cml_wd_pytorch-0.1.4.tar.gz
  • Upload date:
  • Size: 5.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cml_wd_pytorch-0.1.4.tar.gz
Algorithm Hash digest
SHA256 5d9d65d9ea7279cd14621f01212db5da1bb4647d898cb56d5b7c380be807e27a
MD5 3d4b8820a0ef0df57c692d652db25d6b
BLAKE2b-256 c466fe671d6b6c602c45db081acd63e241e6d068925dc5cad8bf8cd04c8ed9a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for cml_wd_pytorch-0.1.4.tar.gz:

Publisher: cd.yml on jpolz/cml_wd_pytorch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cml_wd_pytorch-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: cml_wd_pytorch-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cml_wd_pytorch-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 58fd3887733019fc33346b5f391408a4de188aa278ec8e0e1c6d7ca2fa5457c1
MD5 1c18b9febf9373f87d9e58e74d00b11a
BLAKE2b-256 f90a9fc6c5af2f4e307dc692cbbc8ef5bb638faece5406dee398ed6ed1ca2987

See more details on using hashes here.

Provenance

The following attestation bundles were made for cml_wd_pytorch-0.1.4-py3-none-any.whl:

Publisher: cd.yml on jpolz/cml_wd_pytorch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page