Skip to main content

Python bindings for the Open-Meteo file format

Project description

Python Bindings for Open Meteo File Format

Python 3.10 | 3.11 | 3.12 | 3.13 | 3.14 PyPI version Build and Test

Features

  • Read Open-Meteo (.om) files directly from cloud storage using Python
  • Traverse the hierarchical data structure
  • Arrays/array slices are returned directly as NumPy arrays
  • Support for fsspec and xarray
  • Chunked data access behind the scenes

Installation

pip install omfiles

Pre-Built Wheels & Platform Support

We provide pre-built wheels for the following platforms:

  • Linux x86_64 (manylinux_2_28_x86_64)
  • Linux aarch64 (manylinux_2_28_aarch64)
  • Linux musl x86_64 (musllinux_1_2_x86_64)
  • Windows x86_64 (win_amd64)
  • Windows ARM64 (win_arm64)
  • macOS x86_64 (macosx_10_12_x86_64)
  • macOS ARM64 (macosx_11_0_arm64)

Reading

Reading Files without Hierarchy

OM files are structured like a tree of variables. The following example assumes that the file test_file.om contains an array variable as a root variable which has a dimensionality greater than 2 and a size of at least 2x100:

from omfiles import OmFileReader

reader = OmFileReader("test_file.om")
data = reader[0:2, 0:100, ...]
reader.close() # Close the reader to release resources

Reading Hierarchical Files, e.g. S3 Spatial Files

import datetime as dt

import fsspec
import numpy as np
from omfiles import OmFileReader

# Example: URI for a spatial data file in the `data_spatial` S3 bucket
# See data organization details: https://github.com/open-meteo/open-data?tab=readme-ov-file#data-organization
MODEL_DOMAIN = "dwd_icon"
# Note: Spatial data is only retained for 7 days. The script uses one file within this period.
date_time = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=2)
S3_URI = (
    f"s3://openmeteo/data_spatial/{MODEL_DOMAIN}/{date_time.year}/"
    f"{date_time.month:02}/{date_time.day:02}/0000Z/"
    f"{date_time.strftime('%Y-%m-%d')}T0000.om"
)
print(f"Using om file: {S3_URI}")

# Create and open filesystem, wrapping it in a blockcache
backend = fsspec.open(
    f"blockcache::{S3_URI}",
    mode="rb",
    s3={"anon": True, "default_block_size": 65536},  # s3 settings
    blockcache={"cache_storage": "cache"},  # blockcache settings
)
# Create reader from the fsspec file object using a context manager.
# This will automatically close the file when the block is exited.
with OmFileReader(backend) as root:
    # We are at the root of the data hierarchy!
    # What type of node is this?
    print(f"root.is_array: {root.is_array}")  # False
    print(f"root.is_scalar: {root.is_scalar}")  # False
    print(f"root.is_group: {root.is_group}")  # True

    temperature_reader = root.get_child_by_name("temperature_2m")
    print(f"temperature_reader.is_array: {temperature_reader.is_array}")  # True
    print(f"temperature_reader.is_scalar: {temperature_reader.is_scalar}")  # False
    print(f"temperature_reader.is_group: {temperature_reader.is_group}")  # False

    # What shape does the stored array have?
    print(f"temperature_reader.shape: {temperature_reader.shape}")  # (1441, 2879)

    # Read all data from the array
    temperature_data = temperature_reader.read_array((...))
    print(f"temperature_data.shape: {temperature_data.shape}")  # (1441, 2879)

    # It's also possible to read any subset of the array
    temperature_data_subset1 = temperature_reader.read_array((slice(0, 10), slice(0, 10)))
    print(temperature_data_subset1)
    print(f"temperature_data_subset1.shape: {temperature_data_subset1.shape}")  # (10, 10)

    # Numpy basic indexing is supported for direct access if the reader is an array.
    temperature_data_subset2 = temperature_reader[0:10, 0:10]
    print(temperature_data_subset2)
    print(f"temperature_data_subset2.shape: {temperature_data_subset2.shape}")  # (10, 10)

    # Compare the two temperature subsets and verify that they are the same
    are_equal = np.array_equal(temperature_data_subset1, temperature_data_subset2, equal_nan=True)
    print(f"Are the two temperature subsets equal? {are_equal}")

Writing

Single Array

import numpy as np
from omfiles import OmFileWriter

# Create sample data
data = np.random.rand(100, 100).astype(np.float32)

# Initialize writer
writer = OmFileWriter("simple.om")

# Write array with compression
array_variable = writer.write_array(
    data,
    chunks=[50, 50],
    scale_factor=1.0,
    add_offset=0.0,
    compression="pfor_delta_2d",
    name="data"
)

# Finalize the file using array_variable as entry-point
writer.close(array_variable)

Hierarchical Structure

import numpy as np
from omfiles import OmFileWriter

# Create sample data
features = np.random.rand(1000, 64).astype(np.float32)
labels = np.random.randint(0, 10, size=(1000,), dtype=np.int32)

# Initialize writer
writer = OmFileWriter("hierarchical.om")

# Write child arrays first
features_var = writer.write_array(features, chunks=[100, 64], name="features", compression="pfor_delta_2d")
labels_var = writer.write_array(labels, chunks=[100], name="labels")
metadata_var = writer.write_scalar(42, name="metadata")

# Create root group with children
root_var = writer.write_group(
    name="root",
    children=[features_var, labels_var, metadata_var],
)
# Finalize the file using root_var as entry-point into the hierarchy
writer.close(root_var)

Examples

There are some examples how to use this library in examples/. They should be run as uv scripts to automatically setup the correct python environment.

uv run examples/plot_map.py

Development

# install the required dependencies in .venv directory
uv sync
# to run the tests
uv run pytest tests/
# to build the wheels
uv run build
# or to trigger maturin directly:
# maturin develop

Tests

cargo test

runs rust tests.

uv run pytest tests/

runs Python tests.

Python Type Stubs

Can be generated from the rust doc comments via

cargo run stub_gen

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

thk2b_omfiles-1.0.0-cp310-abi3-win_arm64.whl (999.4 kB view details)

Uploaded CPython 3.10+Windows ARM64

thk2b_omfiles-1.0.0-cp310-abi3-win_amd64.whl (820.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

thk2b_omfiles-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_34_x86_64.whl (13.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ x86-64

thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

thk2b_omfiles-1.0.0-cp310-abi3-macosx_11_0_arm64.whl (974.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

thk2b_omfiles-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl (991.1 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 c4074ebbed2d24dcda91a319e089e41399302b20dec9ead1c88a96eba00b438f
MD5 03e9fb9a2cd3827f8ee642fa14b1395d
BLAKE2b-256 6cafe5dd5aaffe13ecd55edec5d6b2ce2f431503f3ccec0a5a0b897c14313230

See more details on using hashes here.

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5566684fa3cd9e2b19f85f8b04eb630c68b604c643f7aeeacef42316e27bb84a
MD5 91755d2be591470f8b6a743704ee77c2
BLAKE2b-256 8334d280989f5a367e7f51a0b29c4155428e716a2b199576b79d65d8afee13c3

See more details on using hashes here.

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e302b5496aabe6e491050de37453e8b26ffe34e54a8a4d27365a7eee4bb070da
MD5 cd9c87411d85dab8150aa1c773b5dde5
BLAKE2b-256 87ddb3ff92fb53f711f3116485fa772cf4fe2e25c72af5f609689f4f0341efdf

See more details on using hashes here.

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 31f8ce76c8dc23937390edc3269ae6593986e39bd63c653e386d228fc8346102
MD5 9cb58279adf9ce52a09125ff96477dcb
BLAKE2b-256 9703b303b6ab8e227a0f0d83a1fffcb457b105ac73fbfce97ca15546a898885a

See more details on using hashes here.

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e694c842dc5f0c202bff0929d22cb47e5269f3753fcf854bf24776b31748acd9
MD5 65ae9d6be5c6f5e969b9e8c7779bbd18
BLAKE2b-256 4f610c0d89e2f1d03bc4f9f855bace063d4772bf06802c305fdcaffbd0c09f72

See more details on using hashes here.

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c4bf2b19ba455b36c1b783d2fb2e139f4b1ad8e001a8308c4667ed6020601568
MD5 289ae89b59c376e8f9a8a0fe888137b2
BLAKE2b-256 3efb1ee9b9e5492b315c1c4a18e731ef14c6ded3171a0b7e03df8d8c7a70dfc6

See more details on using hashes here.

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a1f175e6b7e75489fd0ca19d0217f0602e4c3e08f9e259a37d2c65564bb4ec8
MD5 cdec385771bdce3a4c2db4d7eb05979a
BLAKE2b-256 8f99e7632ffd251e98589c89af0a4e457a5e7a8be733f2727112d866fcf40d07

See more details on using hashes here.

File details

Details for the file thk2b_omfiles-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for thk2b_omfiles-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 95b202a871c042c4ca723d5a9e98d6e6591635ebf3bb3cc20e43946f17b5196a
MD5 e2593ad1298667dc70cc4543e834eca1
BLAKE2b-256 e80a55acf62e1eb61ecdc7d1009b8384949fcc069b7fc4a2d13779f3b43b8fab

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