Skip to main content

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 functionsdownload_station_year() for a single station/year, or download_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_USER and CEDA_PASS env 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:

  1. 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).
  2. Downloads datasets:

    • Attempts to download datasets for each station-year combination, prioritizing nearest stations.
  3. 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

uk_midas_client-0.562.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

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

uk_midas_client-0.562-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file uk_midas_client-0.562.tar.gz.

File metadata

  • Download URL: uk_midas_client-0.562.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uk_midas_client-0.562.tar.gz
Algorithm Hash digest
SHA256 cc7b0448fef668d9b5ed9b1a27b41832249708ae00d4670f2364c5b3b2f5af12
MD5 e91d1d4d4fb6d98ed2b2a46807d58acd
BLAKE2b-256 4e4d845430978eadeea5aa7270e00700f89ecb4b7567ca57c6ea40976bd87f8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for uk_midas_client-0.562.tar.gz:

Publisher: publish.yml on Katielocks/uk-midas-client

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

File details

Details for the file uk_midas_client-0.562-py3-none-any.whl.

File metadata

File hashes

Hashes for uk_midas_client-0.562-py3-none-any.whl
Algorithm Hash digest
SHA256 5fd3f15f145b510e1713f7f7875b64e23a22200884401bc66e3cc3f27c562b23
MD5 e5b6d007a9b03b13ef4f6534f2a64826
BLAKE2b-256 62680bc1f092ca3215cf1860646c3b390b5be278740003fc90fd3b09b53b51d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for uk_midas_client-0.562-py3-none-any.whl:

Publisher: publish.yml on Katielocks/uk-midas-client

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