Skip to main content

No project description provided

Project description

Python bindings for Open Meteo file format

Python 3.8+ PyPI version Build and Test Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Publish

Installation

Note: This package is currently under active development and not yet ready for production use. APIs may change without notice until the first stable release.

pip install omfiles

Features

  • Fast reading and writing of multi-dimensional arrays
  • Hierarchical data structure support
  • Integration with NumPy arrays
  • Chunked data access for efficient I/O
  • Support for fsspec and xarray

Reading Arrays

Basic Reading

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 OmFilePyReader

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

Reading Data from S3

import fsspec
from omfiles import OmFilePyReader

# path to the file on S3
s3_path = "s3://openmeteo/data/dwd_icon_d2/temperature_2m/chunk_3960.om"
# Create a filesystem
fs = fsspec.filesystem("s3", anon=True)
# Open the file with the filesystem object and configure caching
backend = fs.open(s3_path, mode="rb", cache_type="mmap", block_size=1024, cache_options={"location": "cache"})
# Create reader from the fsspec file object using a context manager.
# This will automatically close the file when the block is exited.
with OmFilePyReader(backend) as reader:
    # Read a specific region from the data
    data = reader[57812:57813, 0:100]
    print(f"First 10 temperature values: {data[:10]}")
    # [18.0, 17.7, 17.65, 17.45, 17.15, 17.6, 18.7, 20.75, 21.7, 22.65]

Writing Arrays

Simple Array

import numpy as np
from omfiles import OmFilePyWriter

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

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

# Write array with compression
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. This writes the trailer and flushes the buffers.
writer.close(variable)

Hierarchical Structure

import numpy as np
from omfiles import OmFilePyWriter

# 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 = OmFilePyWriter("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_scalar(
    0, # This is just placeholder data, later we will support creating groups with no data
    name="root",
    children=[features_var, labels_var, metadata_var]
)

# Finalize the file
writer.close(root_var)

Development

# setup python virtual environment with pyenv
python -m venv .venv
source .venv/bin/activate
# To always activate this environment in this directory run `pyenv local pyo3`
pip install maturin

maturin develop --extras=dev
# if you encounter an error:  Both VIRTUAL_ENV and CONDA_PREFIX are set. Please unset one of them
unset CONDA_PREFIX

Tests

cargo test --no-default-features

Benchmarks

Before running the benchmarks, make sure to compile the release version of the library:

maturin develop --release

Then run the benchmarks:

python benchmarks/main.py

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-0.0.2.tar.gz (36.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-0.0.2-cp38-abi3-win_amd64.whl (610.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

omfiles-0.0.2-cp38-abi3-musllinux_1_2_x86_64.whl (992.4 kB view details)

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

omfiles-0.0.2-cp38-abi3-manylinux_2_28_x86_64.whl (791.2 kB view details)

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

omfiles-0.0.2-cp38-abi3-manylinux_2_28_aarch64.whl (975.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ ARM64

omfiles-0.0.2-cp38-abi3-macosx_11_0_arm64.whl (733.3 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

omfiles-0.0.2-cp38-abi3-macosx_10_12_x86_64.whl (708.1 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for omfiles-0.0.2.tar.gz
Algorithm Hash digest
SHA256 da4de8b61791f4da49ab12ef887ba020b587e0acb799df98c43db8f8c4f5082c
MD5 edc7d0e7e4d720f3842b7637daa2a80f
BLAKE2b-256 a985092ed0a0612a32868b9eb8661abe5729003ff22655993cba73b96c11b983

See more details on using hashes here.

File details

Details for the file omfiles-0.0.2-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: omfiles-0.0.2-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 610.4 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.8.2

File hashes

Hashes for omfiles-0.0.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 69dc91c2c254788be886b1ca35136834e43138b8a5821dd3eda8a4e812b43c67
MD5 34785ddbb451c4f5df9e13f72d390950
BLAKE2b-256 59955177af4dbbee3f933a94b69302abb5bbd3d8f3948c6db92ecbc36739dff5

See more details on using hashes here.

File details

Details for the file omfiles-0.0.2-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-0.0.2-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 817d81cdda7aa0261511096df800bac4386f91e847dc2a53e118a01a8ff6134d
MD5 896915c53cb73193d11037dd1fba5db9
BLAKE2b-256 813c78830a8e617e80aa0707bd1954c692397ff86f342071a16e704e0e4e40c8

See more details on using hashes here.

File details

Details for the file omfiles-0.0.2-cp38-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-0.0.2-cp38-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6d984009a27c54d1ceaf058a96dcb7882d198f63ac294e037e3324374e2480fa
MD5 7f8420ce6f5f80363174fb177d021b12
BLAKE2b-256 7838127d0d3a9dd816795658397ef687071c6509d1488adef75d1b7c7c7b6a52

See more details on using hashes here.

File details

Details for the file omfiles-0.0.2-cp38-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for omfiles-0.0.2-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b5eec23c429b0bc7c8739a4388985732df76e5524ebb69ff123b790dc530bd98
MD5 173a1caca815879299b5e64e62a6c636
BLAKE2b-256 68d6f1880bb09d308458c253ba4fe7dc4f5eebf68b9bbac235d886bfccd3155d

See more details on using hashes here.

File details

Details for the file omfiles-0.0.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for omfiles-0.0.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 41b8cafe33ffcceabbc169994d5dd7282cfc99ec20d75e2e1584d8833d841f50
MD5 ed07a2813fe6bec0127c360c2de512e3
BLAKE2b-256 dddd5bcb98441e13259833954bb39bba58cf77d6a4b582557aa3c937e7cde554

See more details on using hashes here.

File details

Details for the file omfiles-0.0.2-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for omfiles-0.0.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a0c3de984d96791177fc7018b1c323b9fccef6b2b846e9562b6e146c6547acff
MD5 126005bbfef71c7be2ab471e9fec564a
BLAKE2b-256 344c8a8ef0890af5eb75be6e431fbb0e8c55217e7db5daceaae2b77df47cbaf4

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