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 Distribution

omfiles-1.1.2.tar.gz (234.2 kB view details)

Uploaded Source

Built Distributions

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

omfiles-1.1.2-cp310-abi3-win_arm64.whl (982.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

omfiles-1.1.2-cp310-abi3-win_amd64.whl (802.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

omfiles-1.1.2-cp310-abi3-musllinux_1_2_x86_64.whl (1.2 MB view details)

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

omfiles-1.1.2-cp310-abi3-manylinux_2_28_x86_64.whl (1.0 MB view details)

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

omfiles-1.1.2-cp310-abi3-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

omfiles-1.1.2-cp310-abi3-macosx_11_0_arm64.whl (956.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

omfiles-1.1.2-cp310-abi3-macosx_10_12_x86_64.whl (974.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file omfiles-1.1.2.tar.gz.

File metadata

  • Download URL: omfiles-1.1.2.tar.gz
  • Upload date:
  • Size: 234.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for omfiles-1.1.2.tar.gz
Algorithm Hash digest
SHA256 00fbff49ae1a22591f0489d4169fbd7826e0d91b4745061947f55ec7506c38d0
MD5 c932bed9f74c0b7ee87bc0f9ebcf470f
BLAKE2b-256 2340e6a174ba240e624245019ff38e5ac1ccf651c04d14d8b93465e43e23024f

See more details on using hashes here.

File details

Details for the file omfiles-1.1.2-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: omfiles-1.1.2-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 982.5 kB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for omfiles-1.1.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 d6ff4b8eea6ab41d64652ba6d7fc8b5fe6b1bd50d30c510444bbe0fc6869f152
MD5 a97b0f9aa539133677f6e86415b05cc9
BLAKE2b-256 de838500f51bdc78869c614ada701713def5da70f7bd9462e7bb26ba0549c76f

See more details on using hashes here.

File details

Details for the file omfiles-1.1.2-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: omfiles-1.1.2-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 802.7 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for omfiles-1.1.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f8460060dc67cf7472430c3335168f9fce88fefc473bab2ec798829c2aa8344e
MD5 cd852b104dc2a92af185eddb5b35abf7
BLAKE2b-256 267a4b8d22106100ff7639cfd57f95cee3515930deb7072c609b0f4620eef0cc

See more details on using hashes here.

File details

Details for the file omfiles-1.1.2-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-1.1.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 280d430f014da09a58b070026a9a310a648a5ebcab27da02e73651b28a8d8dac
MD5 f557c1be9043039e36bbe8f495ddc314
BLAKE2b-256 eacf803c232538dd42a7b58ff97dbb0538ea2ff0374c0db78a9598e4bd9b4156

See more details on using hashes here.

File details

Details for the file omfiles-1.1.2-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-1.1.2-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bd3e6c243c1e7d54b88004a698e998e75cfea81deac06125b04393d3cb8b7498
MD5 c29952446357e2ad018ca248428224bb
BLAKE2b-256 8f934496313e01d01626d6ef1693d6d530193301c121ca7652fce8f86a22d25b

See more details on using hashes here.

File details

Details for the file omfiles-1.1.2-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for omfiles-1.1.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 265b4a0384112a37345ea3b8d16efac97f6915c1e4cb7376da9eb6f8ab3c6d6a
MD5 ac65e744cd35dd649448276697cb339b
BLAKE2b-256 ae033f31e4346d4a246efcae5cc143b9dada6e48f98a63cf00ef39a6ace13d62

See more details on using hashes here.

File details

Details for the file omfiles-1.1.2-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for omfiles-1.1.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b202fbff873be3d3cd105618fd845fbe6bfd7bdf92fd5d8aa0902fb7b5604f9a
MD5 c3520abd45aa13933b13d25b00c8e9c1
BLAKE2b-256 2ac0e8b6eec748bbb7ebaeca4b0ec73d0b2c71dace1b0bba19ebb2047425834e

See more details on using hashes here.

File details

Details for the file omfiles-1.1.2-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-1.1.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6ade54414a776a9e1ff3a8d5483dd0944f762c396731a62fa14d8f6183caea60
MD5 dfe7377873fa003486ced8013734e226
BLAKE2b-256 efa48707e87a49c15df65cc9d517c398131973819931f4246d300ba3fe27a678

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