Skip to main content

A Python package for extracting meteorological data from MeteoSwiss OpenData API

Project description

MCH-Extract: MeteoSwiss OpenData Extraction Tool

⚠️ DISCLAIMER: This tool is NOT official and is NOT affiliated with MeteoSwiss. It is an independent project that provides a convenient access to publicly available MeteoSwiss measurement data through the Open Government Data initiative.

A simple Python tool for downloading weather data from Switzerland's automatic ground-based weather stations. Designed for scientists and researchers who need easy access to publicly available MeteoSwiss data without dealing with complex APIs.

What Does This Tool Do?

  • Download weather data from Swiss weather stations with simple commands
  • Get data in different time intervals: daily, hourly, monthly, or 10-minute measurements
  • Save data in Excel-friendly CSV or efficient Parquet formats
  • Access data programmatically in Python for analysis
  • Handle data validation automatically - just specify what you want

Installation

Install using pip (requires Python 3.10 or newer):

pip install mch-extract

Verify the tool is installed and working:

mch-extract --help

Quick Examples

Command Line (Terminal)

Get daily temperature and precipitation data for two stations:

mch-extract --from 2024-06-01 --to 2024-06-07 \
    --stations PAY VIT \
    --variables temperature precipitation \
    --daily \
    --output my_weather_data.csv

Get hourly temperature data with detailed output:

mch-extract --from 2024-06-01 \
    --stations PAY \
    --variables temperature \
    --hourly \
    --output hourly_temp.csv \
    --verbose

In Python Scripts

from datetime import date
from mchextract import get_data

# Download weather data
data = get_data(
    stations=['PAY', 'VIT'],  # Payerne and Villars-Tiercelin stations
    variables=['temperature', 'precipitation'],
    start_date=date(2024, 6, 1),
    end_date=date(2024, 6, 7),
    timescale='daily'
)

print(f"Downloaded {len(data)} rows of data")
print(data.head())

# Save to file
data.write_csv("my_data.csv")

How to Use

Command Line Options

Required:

  • --from DATE: Start date (YYYY-MM-DD format, e.g., 2024-06-01)
  • --stations CODES: Weather station codes (e.g., PAY VIT ROM)
  • Time resolution: Choose one of --daily, --hourly, --monthly, or --ten-minute

Optional:

  • --to DATE: End date (defaults to most recent valid date)
  • --variables VARS: What to measure (e.g., temperature precipitation). If not set, will return all available parameters for the stations
  • --dwh PARAMS: Additional MeteoSwiss DWH parameters shortnames to include. See below on how to find them.
  • --output FILE: Where to save data. Supported format are: .csv, .json, .parquet. If not set, will print CSV data to STDOUT
  • --verbose: Show detailed progress information

Available Weather Variables

As a convenience, some "easy to use" variables are provided. These will be automatically converted to DWH parameters for you.

  • temperature: Air temperature
  • precipitation: Rainfall and snow
  • pressure: Atmospheric pressure
  • humidity: Relative humidity
  • sunshine: Sunshine duration
  • evaporation: Evaporation measurements

Time Intervals

  • --daily: One measurement per day
  • --hourly: One measurement per hour
  • --monthly: Monthly averages
  • --ten-minute: Real-time measurements every 10 minutes

Station Codes

Weather stations use 3-letter codes:

  • PAY: Payerne
  • VIT: Villars-Tiercelin
  • KLO: Zurich/Kloten
  • GVE: Geneva
  • And many more...

If you use an invalid code, the tool will show you all available stations.

References

For the list of available stations and parameters, consult the following CSV files:

More Examples

Command Line Examples

# Download precipitation data for multiple stations
mch-extract --from 2024-01-01 --to 2024-01-31 --stations PAY VIT ROM \
    --variables precipitation --hourly --output rain_data.csv

# Get temperature and humidity for Zurich area
mch-extract --from 2024-12-01 --to 2024-12-31 --stations KLO \
    --variables temperature humidity --daily --output zurich_weather.csv

# Monthly climate summary for Geneva
mch-extract --from 2024-01-01 --to 2025-01-01 --stations GVE \
    --variables temperature precipitation pressure \
    --monthly --output geneva_climate.csv

Python Examples

from datetime import date
from mchextract import get_data

# Get recent weather for analysis
data = get_data(
    stations=['PAY', 'VIT'],
    variables=['temperature', 'precipitation'],
    start_date=date(2024, 6, 1),
    end_date=date(2024, 6, 7),
    timescale='daily'
)

# Basic data exploration
print(f"Data shape: {data.shape}")
print(f"Average temperature: {data['temperature'].mean():.1f}°C")
print(f"Total precipitation: {data['precipitation'].sum():.1f}mm")

# Save for Excel
data.write_csv("weather_analysis.csv")

About the Data

Swiss Weather Network

This tool accesses data from Switzerland's official weather monitoring network:

  • ~160 complete weather stations: Measure temperature, precipitation, wind, sunshine, humidity, radiation, and pressure
  • ~100 precipitation stations: Focus on rainfall and snow measurements

Data Types Available

  • 10-minute data: Real-time measurements (updated every 20 minutes)
  • Hourly data: Hourly summaries
  • Daily data: Daily summaries (most common for research)
  • Monthly data: Monthly climate summaries

Data Coverage

  • Historical: From when each station started until end of last year
  • Recent: From January 1st of current year until yesterday
  • Real-time: Current data (only for hourly and 10-minute intervals)

Data Quality

  • All data comes pre-processed from MeteoSwiss
  • Quality control and validation already applied
  • Follows international meteorological standards
  • Some stations have data going back to 1981 or earlier

Troubleshooting

Common Problems

"Invalid station code"

  • Check your 3-letter station codes (e.g., PAY, KLO, GVE)
  • The tool will show available stations if you use an invalid code

"No data available for date range"

  • Make sure your dates are in YYYY-MM-DD format
  • Check that the date range is reasonable (not too far in the future)
  • Some stations may not have all variables available

"Network error" or "Download failed"

  • Check your internet connection
  • MeteoSwiss servers might be temporarily unavailable

Need more help?

  • Use --verbose to see detailed information about what's happening
  • Check that your dates and station codes are correct

Getting Detailed Output

Add --verbose to any command to see what the tool is doing:

mch-extract --from 2024-01-01 --stations PAY --variables temperature \
    --daily --output debug.csv --verbose

Important Notes

Attribution

If using this data in publications or research, please consult MeteoSwiss guidelines on how to cite them. Data is provided under Creative Commons Licence CC BY 4.0. See Terms of use.

Disclaimer

  • This tool is NOT official and NOT affiliated with MeteoSwiss
  • It provides convenient access to publicly available MeteoSwiss OpenData
  • For climate analyses, consider MeteoSwiss' official climate data products

Data Usage

  • All data comes from MeteoSwiss OpenData and can be used freely
  • Please respect MeteoSwiss servers - don't make excessive requests
  • For large-scale or commercial usage, consider contacting MeteoSwiss directly
  • This tool is not meant to be integrated into any automated solutions

Development and Contributing

This project is open source. For developers interested in:

  • Setting up a development environment
  • Running tests
  • Contributing code
  • Building from source

Please see DEVELOPMENT.md for detailed technical documentation.

Learn More

Keywords

MeteoSwiss, MeteoSchweiz, MétéoSuisse, data extraction, OpenData, wrapper, Python API, Python package

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

mch_extract-0.1.4.tar.gz (56.8 kB view details)

Uploaded Source

Built Distribution

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

mch_extract-0.1.4-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mch_extract-0.1.4.tar.gz
  • Upload date:
  • Size: 56.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.21

File hashes

Hashes for mch_extract-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6ddad43d46abc57484d8afe088786e3ae6a379428cd691882a0a72b9bc9bfba7
MD5 e5e77139c36f3b5ecd9dbd062c41891c
BLAKE2b-256 25f0fab5f0b6810b50c25e0b42e0ad1ea4e5d96bec6c79b72b734071e6308a44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mch_extract-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cb1903cd1eca7a4b9a8f3cc3760957c271a307f524860a09c325788d29934a3e
MD5 5192ec8b2be7646b91bd2f2183a993dc
BLAKE2b-256 ee8baf4a378ebfb3c2c3cdb975c18224f0a98e3694251bc8cb6b13f361717a97

See more details on using hashes here.

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