Skip to main content

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, download_locations() to bulk-grab multiple nearest stations for many locations, and download_by_counties() for downloading groups of counties.

  • Cache Location – current config defaults to data/raw/weather/ (edit in settings).

  • Cache Format - customizable cache 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.


Finding a station ID (src_id)

The Met Office assigns every MIDAS station a five-digit source-ID (e.g. 03743).
You can look it up in three quick ways:

  1. CEDA MIDAS Station Search (recommended)
    • Open https://archive.ceda.ac.uk/tools/midas_stations – no login required.
    • In “Search for station name” type part of the name (e.g. Oxford) and press Search.
      The first column of the results table is the src_id.
    • Use the check-box “Show only stations with MIDAS Open data” or restrict the year range / current stations only options to narrow results.
    • If you do not know the station name, switch to the postcode or county tabs on the same page.
  2. Interactive maps
    • CEDA also publishes KML layers for Google Earth – each marker popup shows the src_id. Download the layers from the same tools section.

Quick start

pip install uk-midas-client
from midas_client import (
    download_station_year,
    download_locations,
    download_by_counties,
)

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(
    table="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,
    locations=locs,
    years=range(2021, 2022),
    tables={"TD": ["max_air_temp", "min_air_temp"]},
)

results = download_by_counties(
    counties={"Hampshire": []},
   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.

Release files for uk-midas-client 0.602

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uk-midas-client 0.602
File Size Uploaded
uk_midas_client-0.602.tar.gz 18.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uk-midas-client 0.602
File Interpreter ABI Platform
uk_midas_client-0.602-py3-none-any.whl Python 3 none any Details

Total release size: 34.1 kB

Release files / uk_midas_client-0.602.tar.gz

Download URL uk_midas_client-0.602.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2a9a50bd2dd5028489fa975dde6c8141fa337dc60266a0abc3409bda310bd398
BLAKE2b-256 checksum
How to use checksums
71fe5f41a23f9a8605733d0887c327792f5b29464a84051f3d3ddea14e1ced19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 24, 2025.

Transparency log

Release files / uk_midas_client-0.602-py3-none-any.whl

Download URL uk_midas_client-0.602-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7e9c86990b01dfbf11b2db67b4431afca7d49f80e5db6e68a32b61dccb92194
BLAKE2b-256 checksum
How to use checksums
c6d0d9d7b0c60d2dec556ab0b2a12e3165beb365b691180ed183745455374690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 24, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.602 This release

2 release files

0.601

2 release files

0.600

2 release files

0.573

2 release files

0.562

2 release files

0.557

2 release files

0.554

2 release files

0.553

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page