Skip to content

v0.1 multi scales convention - #113

Draft
lazarusA wants to merge 10 commits into
JuliaDataCubes:mainfrom
lazarusA:la/m_scales
Draft

lazarusA wants to merge 10 commits into
JuliaDataCubes:mainfrom
lazarusA:la/m_scales

Conversation

@lazarusA

@lazarusA lazarusA commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

a lot of tokens and babysitting, I tried to have stops in between, hence all commits in between, but I think it works as intended.

For sure, we will need some time to digest and test that all things are correct.

This will only work after

- Add test/Project.toml and drop [extras]/[targets] from the root project.
- Require Zarr 0.11 and allow YAXArrayBase 0.8.
- Pin unreleased DiskArrayEngine (main), YAXArrayBase (la/zarrcore) and
  YAXArrays (la/base8) via root [sources]; Pkg.test ignores [sources] in
  test/Project.toml. Remove these before registering.
- Workspace now only holds test; docs is resolved separately because
  RasterDataSources requires HTTP 1.x while Zarr 0.11 needs HTTP 2.
- Ignore the local dev/ checkouts.
- Write the multiscales attributes through ZarrCore.writeattrs; the
  3-argument Zarr.writeattrs no longer exists. Temporary until
  buildpyramids writes a new store with the attributes set in zgroup.
- Write multiscales "datasets" entries as {"path": ...} objects instead
  of Pairs.
- Do not index the base with Ti=1 when opening a Zarr pyramid.
- Remove the unused write(path, ::Pyramid), which called an unimported
  savecube, and tms_json, which referenced undefined functions.
Pure functions that build the root group attributes of a multiscale
store following the v0.1 tags of zarr-conventions/multiscales, proj and
spatial. Nothing writes them yet.

- multiscales layout: one child group per level, scale relative to
  derived_from, translation 0 and per-level spatial:transform and
  spatial:shape, as in the convention's examples.
- resampling_method uses the convention's names ("average" for mean).
- proj:code is only written when the CRS has an unambiguous authority
  code; proj:wkt2 is always written. Without a CRS proj is left out.
- spatial:transform is corner based and handles point and interval
  lookups; levels collapsed to one cell take their cell size from
  level 0.

Tests validate the attributes against the official schemas (vendored
in test/schemas, the remote PROJJSON reference is stubbed to stay
offline) and against the convention's geospatial-pyramid example.
The multiscales metadata can now be written in two styles:

- ConventionStyle (default) follows the README and examples of the
  multiscales convention: translation 0, identity transform on level 0
  and "average" for mean.
- CellCenterStyle measures translations between cell centers,
  (step - 1) / 2, leaves out the transform of level 0 and names mean
  "mean", as topozarr does.

proj:wkt2 is now written on a single line, which matches pyproj.

test/fixtures/topozarr holds root attributes written by topozarr 0.1.9
together with the script that generated them; CellCenterStyle output is
compared against them key by key.
- New src/levels.jl: coarse dimensions start at the corner of the base
  and have factor times larger cells, so every level lies exactly on
  its grid. The lookup keeps its type, order and locus. Replaces
  agg_axis, which drifted for lengths not divisible by the factor.
- Pyramid(data) takes nlevels or factors (e.g. [1, 2, 8]) and
  edges=:keep (default, partial windows at the end become a cell) or
  edges=:drop (they are left out, as topozarr does). Levels are
  computed with partial windows and trimmed for :drop; trimmed cells
  never feed coarser levels.
- aggregate_by_factor gets the window size instead of inferring it.
- Slicing a pyramid maps indices per dimension with the factor of each
  level, so non spatial dimensions such as Ti select the same step in
  every level. Previously their index was divided by 2^level too.
- In memory pyramids only downsample the spatial dimensions and return
  no levels when none are needed.

The topozarr fixtures gain an odd sized case; levels built with
edges=:drop reproduce topozarr's shapes and transforms.
buildpyramids(src, dest) replaces building inside the source store.
The multiscales convention stores every level, including the base, in
its own child group, so the source is copied to dest/0 and the levels
are written to dest/1, dest/2, ... The root group only holds the
zarr_conventions, multiscales, spatial: and proj: attributes, written
once when the group is created. The source is not modified.

- Keywords for the levels (nlevels, factors, edges), the metadata style
  (ConventionStyle or CellCenterStyle), the CRS (taken from the lookups
  by default), chunk size, compressor (zstd by default), consolidated
  metadata and overwriting.
- write(dest, ::Pyramid) writes an in memory pyramid the same way.
- buildpyramids(path) throws an error pointing to the new form.
- Depend on ZarrCore, ZarrZstd and ZarrBlosc instead of the Zarr
  package. Blosc is loaded so existing Blosc compressed stores open.
- Pyramid(data) records the convention name of its resampling method.

Consolidation goes through an internal ZarrCore method, rooted at ".",
because consolidate_metadata(::ZGroup) writes v2 metadata for v3 groups
and the v3 method mis-builds child paths when the group path is empty.

With style=CellCenterStyle() and edges=:drop the root attributes equal
those written by topozarr.
Pyramid(path) reads stores with a multiscales layout: the cumulative
factor of every entry is computed from its derived_from chain and the
spatial scale of its transform, the entry without derived_from is the
base and coarser entries become the levels in order of their factor.
Assets can be groups or arrays inside groups, scalar arrays such as
xarray's spatial_ref are skipped, and levels finer than the base are
skipped with a warning. The root attributes, including proj:code,
become the metadata of the pyramid. Stores in the previous layout, with
the base at the root, are read as before.

selectlevel picks the finest level whose factor fits the requested
image size instead of assuming powers of two.

Adds a store written by topozarr 0.1.9 as a fixture and the dem
example of the multiscales convention. Reading the topozarr store and
zstd coordinate arrays are marked broken until YAXArrayBase handles
scalar arrays without dimension_names and passes the compressor on to
coordinates.
Stores written with xarray, such as topozarr's, have a scalar
spatial_ref array in every level, written without dimension_names.
Levels are now opened through a copy of the group without scalar
arrays, so YAXArrays never tries to read their dimensions and the
scalar is not merged into the level cube.

Coordinate arrays now get the compressor from YAXArrayBase, the
corresponding tests and the topozarr store test are no longer broken.
YAXArrayBase (la/zarrcore, 9040952) now reads scalar arrays without
dimension_names, such as xarray's spatial_ref, and Cube builds the
level from the remaining arrays. Levels are opened with open_dataset
again; the topozarr store test covers this.
- README: buildpyramids(src, dest), its main keywords, write for in
  memory pyramids, reading stores and remote stores.
- New docs page on multiscale Zarr stores: layout, levels, edges,
  metadata styles, CRS, reading and the API. index.md gets an overview.
- Update the plotting example to the new buildpyramids.
- CHANGELOG entry for 0.2.0 and version bump.

The docs are not built here; docs/juliacon.qmd is left as given at the
talk.
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.88608% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.24%. Comparing base (dc23dcc) to head (22c908f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/conventions.jl 94.39% 6 Missing ⚠️
src/reader.jl 90.56% 5 Missing ⚠️
ext/PyramidSchemeArchGDALExt.jl 50.00% 1 Missing ⚠️
src/PyramidScheme.jl 96.77% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #113       +/-   ##
===========================================
+ Coverage   73.12%   84.24%   +11.12%     
===========================================
  Files           4        8        +4     
  Lines         346      565      +219     
===========================================
+ Hits          253      476      +223     
+ Misses         93       89        -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lazarusA
lazarusA marked this pull request as draft October 9, 2026 08:08
@felixcremer felixcremer mentioned this pull request Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant