mch-extract


Namemch-extract JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryA Python package for extracting meteorological data from MeteoSwiss OpenData API
upload_time2025-07-16 20:17:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords data meteorology meteoswiss ogd switzerland weather
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://opendatadocs.meteoswiss.ch/) without dealing with the complexities of the FSDI REST API.

## 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-minutes measurements
- **Save data** in Excel-friendly CSV or efficient Parquet formats
- **Access data programmatically** in Python for analysis using [Polars](https://docs.pola.rs/) or Pandas
- **Handle data validation** automatically - just specify what you want

## Installation

Install using pip (requires Python 3.10 or newer):

```bash
pip install mch-extract
```

Verify the tool is installed and working:

```bash
mch-extract --help
```

## Quick Examples

### Command Line (Terminal)

Get daily temperature and precipitation data for two stations:

```bash
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:

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

### In Python Scripts

```python
from datetime import date
from mchextract import get_data

# Download weather data as a Polars DataFrame
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'
)

# If you prefer working with Pandas, you can convert the Polars DataFrame:
# data = data.to_pandas()
# (requires `pandas` package to be installed separately)

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 `--monthly`, `--daily`, `--hourly`, or `--10min`

**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
- `--no-cache`: Disable caching (useful for testing or debugging)

### 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

- `--monthly`: Monthly averages
- `--daily`: One measurement per day
- `--hourly`: One measurement per hour
- `--10min`: 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

STAC browser: https://data.geo.admin.ch/browser/index.html#/collections/ch.meteoschweiz.ogd-smn?.language=en

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

- Stations list
  - regular: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn/ogd-smn_meta_stations.csv
  - precip: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn-precip/ogd-smn-precip_meta_stations.csv
- Parameters list:
  - regular: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn/ogd-smn_meta_parameters.csv
  - precip: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn-precip/ogd-smn-precip_meta_parameters.csv
- Inventory (which station has which parameters):
  - regular: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn/ogd-smn_meta_datainventory.csv
  - precip: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn-precip/ogd-smn-precip_meta_datainventory.csv

## More Examples

### Command Line Examples

```bash
# 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

```python
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-minutes 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-minutes 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:

```bash
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](https://creativecommons.org/licenses/by/4.0/). See [Terms of use](https://opendatadocs.meteoswiss.ch/general/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](https://opendatadocs.meteoswiss.ch/c-climate-data)

### 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](DEVELOPMENT.md) for detailed technical documentation.

## Learn More

- [MeteoSwiss OpenData Documentation](https://opendatadocs.meteoswiss.ch/)
- [Weather Station Network Information](https://opendatadocs.meteoswiss.ch/a-data-groundbased/a1-automatic-weather-stations)
- [Interactive Station Map](https://www.meteoswiss.admin.ch/services-and-publications/applications/measurement-values-and-measuring-networks.html#param=messnetz-automatisch&lang=en)
- [MeteoSwiss Open Data Explorer](https://www.meteoswiss.admin.ch/services-and-publications/applications/ext/download-data-without-coding-skills.html)

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

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mch-extract",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "data, meteorology, meteoswiss, ogd, switzerland, weather",
    "author": null,
    "author_email": "Martin Spoto <martin.spoto98@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/76/93/bc9c3684a65626ac17af1c2d36f3b3acbf25a5ad69201ce1313b27e14482/mch_extract-0.2.1.tar.gz",
    "platform": null,
    "description": "# MCH-Extract: MeteoSwiss OpenData Extraction Tool\n\n> **\u26a0\ufe0f 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.\n\nA 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](https://opendatadocs.meteoswiss.ch/) without dealing with the complexities of the FSDI REST API.\n\n## What Does This Tool Do?\n\n- **Download weather data** from Swiss weather stations with simple commands\n- **Get data in different time intervals**: daily, hourly, monthly, or 10-minutes measurements\n- **Save data** in Excel-friendly CSV or efficient Parquet formats\n- **Access data programmatically** in Python for analysis using [Polars](https://docs.pola.rs/) or Pandas\n- **Handle data validation** automatically - just specify what you want\n\n## Installation\n\nInstall using pip (requires Python 3.10 or newer):\n\n```bash\npip install mch-extract\n```\n\nVerify the tool is installed and working:\n\n```bash\nmch-extract --help\n```\n\n## Quick Examples\n\n### Command Line (Terminal)\n\nGet daily temperature and precipitation data for two stations:\n\n```bash\nmch-extract --from 2024-06-01 --to 2024-06-07 \\\n    --stations PAY VIT \\\n    --variables temperature precipitation \\\n    --daily \\\n    --output my_weather_data.csv\n```\n\nGet hourly temperature data with detailed output:\n\n```bash\nmch-extract --from 2024-06-01 \\\n    --stations PAY \\\n    --variables temperature \\\n    --hourly \\\n    --output hourly_temp.csv \\\n    --verbose\n```\n\n### In Python Scripts\n\n```python\nfrom datetime import date\nfrom mchextract import get_data\n\n# Download weather data as a Polars DataFrame\ndata = get_data(\n    stations=['PAY', 'VIT'],  # Payerne and Villars-Tiercelin stations\n    variables=['temperature', 'precipitation'],\n    start_date=date(2024, 6, 1),\n    end_date=date(2024, 6, 7),\n    timescale='daily'\n)\n\n# If you prefer working with Pandas, you can convert the Polars DataFrame:\n# data = data.to_pandas()\n# (requires `pandas` package to be installed separately)\n\nprint(f\"Downloaded {len(data)} rows of data\")\nprint(data.head())\n\n# Save to file\ndata.write_csv(\"my_data.csv\")\n```\n\n## How to Use\n\n### Command Line Options\n\n**Required:**\n\n- `--from DATE`: Start date (YYYY-MM-DD format, e.g., 2024-06-01)\n- `--stations CODES`: Weather station codes (e.g., PAY VIT ROM)\n- **Time resolution**: Choose one of `--monthly`, `--daily`, `--hourly`, or `--10min`\n\n**Optional:**\n\n- `--to DATE`: End date (defaults to most recent valid date)\n- `--variables VARS`: What to measure (e.g., temperature precipitation). If not set, will return all available parameters for the stations\n- `--dwh PARAMS`: Additional MeteoSwiss DWH parameters shortnames to include. See below on how to find them.\n- `--output FILE`: Where to save data. Supported format are: `.csv`, `.json`, `.parquet`. If not set, will print CSV data to STDOUT\n- `--verbose`: Show detailed progress information\n- `--no-cache`: Disable caching (useful for testing or debugging)\n\n### Available Weather Variables\n\nAs a convenience, some \"easy to use\" variables are provided. These will be automatically converted to DWH parameters for you.\n\n- `temperature`: Air temperature\n- `precipitation`: Rainfall and snow\n- `pressure`: Atmospheric pressure\n- `humidity`: Relative humidity\n- `sunshine`: Sunshine duration\n- `evaporation`: Evaporation measurements\n\n### Time Intervals\n\n- `--monthly`: Monthly averages\n- `--daily`: One measurement per day\n- `--hourly`: One measurement per hour\n- `--10min`: Real-time measurements every 10 minutes\n\n### Station Codes\n\nWeather stations use 3-letter codes:\n\n- `PAY`: Payerne\n- `VIT`: Villars-Tiercelin\n- `KLO`: Zurich/Kloten\n- `GVE`: Geneva\n- And many more...\n\nIf you use an invalid code, the tool will show you all available stations.\n\n### References\n\nSTAC browser: https://data.geo.admin.ch/browser/index.html#/collections/ch.meteoschweiz.ogd-smn?.language=en\n\nFor the list of available stations and parameters, consult the following CSV files:\n\n- Stations list\n  - regular: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn/ogd-smn_meta_stations.csv\n  - precip: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn-precip/ogd-smn-precip_meta_stations.csv\n- Parameters list:\n  - regular: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn/ogd-smn_meta_parameters.csv\n  - precip: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn-precip/ogd-smn-precip_meta_parameters.csv\n- Inventory (which station has which parameters):\n  - regular: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn/ogd-smn_meta_datainventory.csv\n  - precip: https://data.geo.admin.ch/ch.meteoschweiz.ogd-smn-precip/ogd-smn-precip_meta_datainventory.csv\n\n## More Examples\n\n### Command Line Examples\n\n```bash\n# Download precipitation data for multiple stations\nmch-extract --from 2024-01-01 --to 2024-01-31 --stations PAY VIT ROM \\\n    --variables precipitation --hourly --output rain_data.csv\n\n# Get temperature and humidity for Zurich area\nmch-extract --from 2024-12-01 --to 2024-12-31 --stations KLO \\\n    --variables temperature humidity --daily --output zurich_weather.csv\n\n# Monthly climate summary for Geneva\nmch-extract --from 2024-01-01 --to 2025-01-01 --stations GVE \\\n    --variables temperature precipitation pressure \\\n    --monthly --output geneva_climate.csv\n```\n\n### Python Examples\n\n```python\nfrom datetime import date\nfrom mchextract import get_data\n\n# Get recent weather for analysis\ndata = get_data(\n    stations=['PAY', 'VIT'],\n    variables=['temperature', 'precipitation'],\n    start_date=date(2024, 6, 1),\n    end_date=date(2024, 6, 7),\n    timescale='daily'\n)\n\n# Basic data exploration\nprint(f\"Data shape: {data.shape}\")\nprint(f\"Average temperature: {data['temperature'].mean():.1f}\u00b0C\")\nprint(f\"Total precipitation: {data['precipitation'].sum():.1f}mm\")\n\n# Save for Excel\ndata.write_csv(\"weather_analysis.csv\")\n```\n\n## About the Data\n\n### Swiss Weather Network\n\nThis tool accesses data from Switzerland's official weather monitoring network:\n\n- **~160 complete weather stations**: Measure temperature, precipitation, wind, sunshine, humidity, radiation, and pressure\n- **~100 precipitation stations**: Focus on rainfall and snow measurements\n\n### Data Types Available\n\n- **10-minutes data**: Real-time measurements (updated every 20 minutes)\n- **Hourly data**: Hourly summaries\n- **Daily data**: Daily summaries (most common for research)\n- **Monthly data**: Monthly climate summaries\n\n### Data Coverage\n\n- **Historical**: From when each station started until end of last year\n- **Recent**: From January 1st of current year until yesterday\n- **Real-time**: Current data (only for hourly and 10-minutes intervals)\n\n### Data Quality\n\n- All data comes pre-processed from MeteoSwiss\n- Quality control and validation already applied\n- Follows international meteorological standards\n- Some stations have data going back to 1981 or earlier\n\n## Troubleshooting\n\n### Common Problems\n\n**\"Invalid station code\"**\n\n- Check your 3-letter station codes (e.g., PAY, KLO, GVE)\n- The tool will show available stations if you use an invalid code\n\n**\"No data available for date range\"**\n\n- Make sure your dates are in YYYY-MM-DD format\n- Check that the date range is reasonable (not too far in the future)\n- Some stations may not have all variables available\n\n**\"Network error\" or \"Download failed\"**\n\n- Check your internet connection\n- MeteoSwiss servers might be temporarily unavailable\n\n**Need more help?**\n\n- Use `--verbose` to see detailed information about what's happening\n- Check that your dates and station codes are correct\n\n### Getting Detailed Output\n\nAdd `--verbose` to any command to see what the tool is doing:\n\n```bash\nmch-extract --from 2024-01-01 --stations PAY --variables temperature \\\n    --daily --output debug.csv --verbose\n```\n\n## Important Notes\n\n### Attribution\n\nIf 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](https://creativecommons.org/licenses/by/4.0/). See [Terms of use](https://opendatadocs.meteoswiss.ch/general/terms-of-use).\n\n### Disclaimer\n\n- This tool is **NOT official** and **NOT affiliated** with MeteoSwiss\n- It provides convenient access to publicly available MeteoSwiss OpenData\n- For climate analyses, consider MeteoSwiss' [official climate data products](https://opendatadocs.meteoswiss.ch/c-climate-data)\n\n### Data Usage\n\n- All data comes from MeteoSwiss OpenData and can be used freely\n- Please respect MeteoSwiss servers - don't make excessive requests\n- For large-scale or commercial usage, consider contacting MeteoSwiss directly\n- This tool is not meant to be integrated into any automated solutions\n\n## Development and Contributing\n\nThis project is open source. For developers interested in:\n\n- Setting up a development environment\n- Running tests\n- Contributing code\n- Building from source\n\nPlease see [DEVELOPMENT.md](DEVELOPMENT.md) for detailed technical documentation.\n\n## Learn More\n\n- [MeteoSwiss OpenData Documentation](https://opendatadocs.meteoswiss.ch/)\n- [Weather Station Network Information](https://opendatadocs.meteoswiss.ch/a-data-groundbased/a1-automatic-weather-stations)\n- [Interactive Station Map](https://www.meteoswiss.admin.ch/services-and-publications/applications/measurement-values-and-measuring-networks.html#param=messnetz-automatisch&lang=en)\n- [MeteoSwiss Open Data Explorer](https://www.meteoswiss.admin.ch/services-and-publications/applications/ext/download-data-without-coding-skills.html)\n\n#### Keywords\nMeteoSwiss, MeteoSchweiz, M\u00e9t\u00e9oSuisse, data extraction, OpenData, wrapper, Python API, Python package",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python package for extracting meteorological data from MeteoSwiss OpenData API",
    "version": "0.2.1",
    "project_urls": {
        "Documentation": "https://github.com/martintops/mch-extract#readme",
        "Homepage": "https://github.com/martintops/mch-extract",
        "Issues": "https://github.com/martintops/mch-extract/issues",
        "Repository": "https://github.com/martintops/mch-extract"
    },
    "split_keywords": [
        "data",
        " meteorology",
        " meteoswiss",
        " ogd",
        " switzerland",
        " weather"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "cec02e9debc014c25e2df4db9988722cec28531b6651e1a90b06e8e9194024b0",
                "md5": "9421740df5bfe88a55b2b3b7f75c1f5b",
                "sha256": "8da87b027936fd74f7a3050f453632cffb66a9d96d2636ef90db7864fe24ad41"
            },
            "downloads": -1,
            "filename": "mch_extract-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9421740df5bfe88a55b2b3b7f75c1f5b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 25113,
            "upload_time": "2025-07-16T20:17:00",
            "upload_time_iso_8601": "2025-07-16T20:17:00.615307Z",
            "url": "https://files.pythonhosted.org/packages/ce/c0/2e9debc014c25e2df4db9988722cec28531b6651e1a90b06e8e9194024b0/mch_extract-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7693bc9c3684a65626ac17af1c2d36f3b3acbf25a5ad69201ce1313b27e14482",
                "md5": "289e463898a7fc9a76de35897067236a",
                "sha256": "66d1323ab310b6aff2609ebfc05a59418b23190bd4f30ff69a2624b8b7a35361"
            },
            "downloads": -1,
            "filename": "mch_extract-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "289e463898a7fc9a76de35897067236a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 57945,
            "upload_time": "2025-07-16T20:17:01",
            "upload_time_iso_8601": "2025-07-16T20:17:01.739944Z",
            "url": "https://files.pythonhosted.org/packages/76/93/bc9c3684a65626ac17af1c2d36f3b3acbf25a5ad69201ce1313b27e14482/mch_extract-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-16 20:17:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "martintops",
    "github_project": "mch-extract#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mch-extract"
}
        
Elapsed time: 0.51100s