A Python client for UK Met Office MIDAS via CEDA Archives
Project description
MIDAS Client
Features
- MIDAS tables – supports all hourly / daily rain, temperature, weather, wind, radiation & soil temp tables (
RH,RD,TD,WH,WD,WM,RY,SH). - Helper functions –
download_station_year()for a single station/year, ordownload_locations()to bulk-grab multiple nearest stations for many locations. - Cache Location – current config defaults to
data/raw/weather/(edit in settings). - Cache Format - customizable cashe format; supports
csv,parquet,json. Defaults to csv. - Config: JSON – tweak dataset version, default columns, cache directory, etc. in
settings.json. - CEDA auth – automatically gets a bearer token using your
CEDA_USERandCEDA_PASSenv vars.
Quick start
pip install uk-midas-client
from midas_client import download_station_year, download_locations
Set your CEDA credentials using either username/password:
export CEDA_USER="me@example.com"
export CEDA_PASS="••••••••"
and/or use a token:
export CEDA_TOKEN="••••••••..."
Fetch a single station-year
df = download_station_year("TD", station_id="03743", year=2020)
print(df.head())
Bulk Download Nearest Stations
Given a DataFrame containing observation locations with associated latitude and longitude coordinates, the algorithm:
-
Identifies the nearest MIDAS stations:
- Finds the k-nearest MIDAS stations for each observation location that support a specified observation type (e.g., Rain Hourly —
RH).
- Finds the k-nearest MIDAS stations for each observation location that support a specified observation type (e.g., Rain Hourly —
-
Downloads datasets:
- Attempts to download datasets for each station-year combination, prioritizing nearest stations.
-
Fallback mechanism:
-
If a dataset for the closest station-year combination is unavailable, the algorithm sequentially attempts downloads from the next nearest stations until either:
- A valid dataset is successfully retrieved, or
- All k nearest stations have been attempted unsuccessfully.
-
Caching and Output Structure
The resulting datasets are stored in a specified cache directory (cache_dir), following the naming convention:
{obs}_{year}.{fmt}
Additionally, the process generates a JSON mapping file (station_map.json) within cache_dir. This file maps each observation location's input loc_id to the corresponding downloaded station identifiers.
Example Usage
import pandas as pd
locs = pd.DataFrame({
"loc_id": ["here"],
"lat": [51.5],
"long": [-0.1],
})
station_map = download_locations(
locs,
years=range(2021, 2022),
tables={"TD": ["max_air_temp", "min_air_temp"]}
)
Status
This project is currently in a pre-1.0 prototype stage and may change without notice.
License
Released under the MIT License. You are free to use, modify and distribute this software.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uk_midas_client-0.553.tar.gz.
File metadata
- Download URL: uk_midas_client-0.553.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71d01ae50728a730691030212e9685b761c9e5da3e7cbb9bb749d8e9a79380a6
|
|
| MD5 |
395302a96dee503356d022dd1343f213
|
|
| BLAKE2b-256 |
8670db3a696664dc9dbc2e7254a234ded691f5ecce7e742e7313a544e2421c8d
|
Provenance
The following attestation bundles were made for uk_midas_client-0.553.tar.gz:
Publisher:
publish.yml on Katielocks/uk-midas-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uk_midas_client-0.553.tar.gz -
Subject digest:
71d01ae50728a730691030212e9685b761c9e5da3e7cbb9bb749d8e9a79380a6 - Sigstore transparency entry: 238356698
- Sigstore integration time:
-
Permalink:
Katielocks/uk-midas-client@fc58c5b6dc17add47835276ce3e4f593f97b2e1f -
Branch / Tag:
refs/tags/v0.553 - Owner: https://github.com/Katielocks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc58c5b6dc17add47835276ce3e4f593f97b2e1f -
Trigger Event:
push
-
Statement type:
File details
Details for the file uk_midas_client-0.553-py3-none-any.whl.
File metadata
- Download URL: uk_midas_client-0.553-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1612e2b632f4c8caddcff54b5420c33e3d0902e747c7dc6ee458128c7c97733
|
|
| MD5 |
62c786962ab2abcc03f0fcbfd454b323
|
|
| BLAKE2b-256 |
b85720f9526564679e39889ce8e5e8b23de9ca89dc4a363e90b090a56546334f
|
Provenance
The following attestation bundles were made for uk_midas_client-0.553-py3-none-any.whl:
Publisher:
publish.yml on Katielocks/uk-midas-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
uk_midas_client-0.553-py3-none-any.whl -
Subject digest:
b1612e2b632f4c8caddcff54b5420c33e3d0902e747c7dc6ee458128c7c97733 - Sigstore transparency entry: 238356700
- Sigstore integration time:
-
Permalink:
Katielocks/uk-midas-client@fc58c5b6dc17add47835276ce3e4f593f97b2e1f -
Branch / Tag:
refs/tags/v0.553 - Owner: https://github.com/Katielocks
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fc58c5b6dc17add47835276ce3e4f593f97b2e1f -
Trigger Event:
push
-
Statement type: