Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zarr-python v3 compatibility #516

Merged
merged 54 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
39722e7
Save progress for next week
mpiannucci Oct 4, 2024
d3c7e37
Bump zarr python version
mpiannucci Oct 5, 2024
25d7d14
Get some tests working others failing
mpiannucci Oct 5, 2024
ffe5f9d
get through single hdf to zarr
mpiannucci Oct 8, 2024
5aef233
Save progress
mpiannucci Oct 8, 2024
b9323d2
Cleanup, almost working with hdf
mpiannucci Oct 9, 2024
0f17119
Closer...
mpiannucci Oct 9, 2024
5c8806b
Updating tests
mpiannucci Oct 9, 2024
80fedcd
reorganize
mpiannucci Oct 10, 2024
1f69a0b
Save progress
mpiannucci Oct 10, 2024
d556e52
Refactor to clean things up
mpiannucci Oct 10, 2024
b27e64c
Fix circular import
mpiannucci Oct 10, 2024
41d6e8e
Iterate
mpiannucci Oct 10, 2024
7ade1a6
Change zarr dep
mpiannucci Oct 10, 2024
492ddee
More conversion
mpiannucci Oct 10, 2024
6e5741c
Specify zarr version
mpiannucci Oct 15, 2024
c0316ac
Working remote hdf tests
mpiannucci Oct 23, 2024
59bd36c
Working grib impl
mpiannucci Oct 23, 2024
187ced2
Add back commented out code
mpiannucci Oct 23, 2024
690ed21
Make grib codec a compressor since its bytes to array
mpiannucci Oct 23, 2024
5019b15
Switch back
mpiannucci Oct 23, 2024
d96cf46
Add first pass at grib zarr 3 codec
mpiannucci Oct 26, 2024
cbcb720
Fix typing
mpiannucci Oct 29, 2024
b88655f
Fix some broken tests; use async filesystem wrapper
moradology Nov 6, 2024
73eaf33
Implement zarr3 compatibility for grib
moradology Nov 20, 2024
3757199
Use zarr3 stores directly; avoid use of internal fs
moradology Nov 21, 2024
9444ff8
Merge pull request #4 from moradology/fix/zarr3-grib-tests
mpiannucci Nov 26, 2024
d8848ce
Forward
mpiannucci Nov 26, 2024
1fa294e
More
mpiannucci Nov 26, 2024
543178d
Figure out async wrapper
mpiannucci Nov 26, 2024
96b56cd
Closer on hdf5
mpiannucci Nov 26, 2024
0808b05
netcdf but failing
mpiannucci Nov 26, 2024
aef006e
grib passing
mpiannucci Nov 26, 2024
d9bf0dd
Fix inline test
mpiannucci Nov 26, 2024
884fc68
More
mpiannucci Nov 26, 2024
1145f45
standardize compressor name
mpiannucci Nov 27, 2024
94ec479
Fix one more hdf test
mpiannucci Nov 27, 2024
a9693d1
Small tweaks
mpiannucci Nov 27, 2024
7e9112a
Hide fsspec import where necessary
mpiannucci Nov 27, 2024
a7af691
Update with many fixes - but stioll not complete
martindurant Jan 16, 2025
f7b87de
Merge branch 'main' into v3
martindurant Jan 16, 2025
95f340f
min python
martindurant Jan 16, 2025
fa364a7
Loads of changes
martindurant Jan 22, 2025
53922a2
Merge branch 'main' into v3
martindurant Jan 23, 2025
0486ac1
more improvements (slowly slowly)
martindurant Jan 23, 2025
c522a52
grib and combine
martindurant Jan 29, 2025
9b96d8c
more fix!
martindurant Jan 29, 2025
17478bd
env typo
martindurant Jan 29, 2025
2d5033c
Add HDF4 simple test
martindurant Jan 29, 2025
9066360
fix other runs
martindurant Jan 29, 2025
4750f8e
comma
martindurant Jan 29, 2025
73385f5
lint
martindurant Jan 29, 2025
1a79a5c
CI deps
martindurant Jan 29, 2025
f51604f
skip tests needing datatree
martindurant Jan 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [310, 311, 312]
python-version: [311, 312]

steps:
- uses: actions/checkout@v4
Expand All @@ -19,8 +19,9 @@ jobs:
- name: Install kerchunk
shell: bash -l {0}
run: |
pip install -e .
pip install -e . --no-deps
pip list
- name: Test with pytest
shell: bash -l {0}
run: |
pytest -v --cov
pytest -v --timeout 60 --cov
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 25.1.0
hooks:
- id: black
exclude: ^docs/
- repo: https://github.com/pycqa/flake8
rev: '4.0.1'
rev: '7.1.1'
hooks:
- id: flake8
exclude: tests/|^docs/|__init__.py
4 changes: 2 additions & 2 deletions ci/environment-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- defaults
dependencies:
- python=3.10
- python=3.12
- dask
- zarr
- xarray>=2024.10.0
Expand All @@ -17,7 +17,7 @@ dependencies:
- aiohttp
- pytest-cov
- pytest-subtests
- fsspec<=2024.12.0
- fsspec
- dask
- scipy
- s3fs
Expand Down
38 changes: 0 additions & 38 deletions ci/environment-py310.yml

This file was deleted.

9 changes: 5 additions & 4 deletions ci/environment-py311.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ dependencies:
- cfgrib
# Temporary workaround for #508
- eccodes <2.38

- ujson
- cftime
- astropy
- requests
- aiohttp
- pytest-cov
- pytest-subtests
- fsspec<=2024.12.0
- pytest-timeout
- dask
- scipy
- s3fs
Expand All @@ -34,5 +34,6 @@ dependencies:
- tifffile
- rioxarray
- netCDF4
# - pip:
# - git+https://github.com/fsspec/filesystem_spec
- pip:
- git+https://github.com/fsspec/filesystem_spec
- git+https://github.com/zarr-developers/zarr-python
9 changes: 5 additions & 4 deletions ci/environment-py312.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ dependencies:
- cfgrib
# Temporary workaround for #508
- eccodes <2.38

- ujson
- cftime
- astropy
- requests
- aiohttp
- pytest-cov
- pytest-subtests
- fsspec<=2024.12.0
- pytest-timeout
- gcsfs
- dask
- scipy
Expand All @@ -34,5 +34,6 @@ dependencies:
- tifffile
- rioxarray
- netCDF4
# - pip:
# - git+https://github.com/fsspec/filesystem_spec
- pip:
- git+https://github.com/fsspec/filesystem_spec
- git+https://github.com/zarr-developers/zarr-python
2 changes: 1 addition & 1 deletion kerchunk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import codecs
from kerchunk import codecs

from importlib.metadata import version as _version

Expand Down
3 changes: 2 additions & 1 deletion kerchunk/_grib_idx.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,8 @@ def _extract_single_group(grib_group: dict, idx: int, storage_options: Dict):
return None

dt = xr.open_datatree(
fsspec.filesystem("reference", fo=grib_tree_store).get_mapper(""),
"reference://",
storage_options={"fo": grib_tree_store},
engine="zarr",
consolidated=False,
)
Expand Down
81 changes: 79 additions & 2 deletions kerchunk/codecs.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import ast
from dataclasses import dataclass
import io

import numcodecs
from numcodecs.abc import Codec
import numpy as np
import threading
import zlib
from zarr.core.array_spec import ArraySpec
from zarr.abc.codec import ArrayBytesCodec
from zarr.core.buffer import Buffer, NDBuffer
from zarr.core.common import JSON, parse_named_configuration
from zarr.registry import register_codec


class FillStringsCodec(Codec):
Expand Down Expand Up @@ -115,6 +121,78 @@ def decode(self, buf, out=None):
numcodecs.register_codec(GRIBCodec, "grib")


@dataclass(frozen=True)
class GRIBZarrCodec(ArrayBytesCodec):
eclock = threading.RLock()

var: str
dtype: np.dtype

def __init__(self, *, var: str, dtype: np.dtype) -> None:
object.__setattr__(self, "var", var)
object.__setattr__(self, "dtype", dtype)

@classmethod
def from_dict(cls, data: dict[str, JSON]) -> "GRIBZarrCodec":
_, configuration_parsed = parse_named_configuration(
data, "bytes", require_configuration=True
)
configuration_parsed = configuration_parsed or {}
return cls(**configuration_parsed) # type: ignore[arg-type]

def to_dict(self) -> dict[str, JSON]:
if self.endian is None:
return {"name": "grib"}
else:
return {
"name": "grib",
"configuration": {"var": self.var, "dtype": self.dtype},
}

async def _decode_single(
self,
chunk_bytes: Buffer,
chunk_spec: ArraySpec,
) -> NDBuffer:
assert isinstance(chunk_bytes, Buffer)
import eccodes

if self.var in ["latitude", "longitude"]:
var = self.var + "s"
dt = self.dtype or "float64"
else:
var = "values"
dt = self.dtype or "float32"

with self.eclock:
mid = eccodes.codes_new_from_message(chunk_bytes.to_bytes())
try:
data = eccodes.codes_get_array(mid, var)
missingValue = eccodes.codes_get_string(mid, "missingValue")
if var == "values" and missingValue:
data[data == float(missingValue)] = np.nan
return data.astype(dt, copy=False)

finally:
eccodes.codes_release(mid)

async def _encode_single(
self,
chunk_array: NDBuffer,
chunk_spec: ArraySpec,
) -> Buffer | None:
# This is a one way codec
raise NotImplementedError

def compute_encoded_size(
self, input_byte_length: int, _chunk_spec: ArraySpec
) -> int:
raise NotImplementedError


register_codec("grib", GRIBZarrCodec)


class AsciiTableCodec(numcodecs.abc.Codec):
"""Decodes ASCII-TABLE extensions in FITS files"""

Expand Down Expand Up @@ -166,7 +244,6 @@ def decode(self, buf, out=None):
arr2 = np.empty((self.nrow,), dtype=dt_out)
heap = buf[arr.nbytes :]
for name in dt_out.names:

if dt_out[name] == "O":
dt = np.dtype(self.ftypes[self.types[name]])
counts = arr[name][:, 0]
Expand Down Expand Up @@ -245,7 +322,7 @@ class ZlibCodec(Codec):
codec_id = "zlib"

def __init__(self):
...
pass

def decode(self, data, out=None):
if out:
Expand Down
Loading
Loading