zarrchive 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. zarrchive-0.2.0/LICENSE +21 -0
  2. zarrchive-0.2.0/PKG-INFO +298 -0
  3. zarrchive-0.2.0/README.md +262 -0
  4. zarrchive-0.2.0/pyproject.toml +121 -0
  5. zarrchive-0.2.0/src/zarrchive/__init__.py +72 -0
  6. zarrchive-0.2.0/src/zarrchive/append.py +458 -0
  7. zarrchive-0.2.0/src/zarrchive/bulk.py +594 -0
  8. zarrchive-0.2.0/src/zarrchive/cam_store.py +817 -0
  9. zarrchive-0.2.0/src/zarrchive/chunking.py +649 -0
  10. zarrchive-0.2.0/src/zarrchive/cli/__init__.py +7 -0
  11. zarrchive-0.2.0/src/zarrchive/cli/attributes.py +97 -0
  12. zarrchive-0.2.0/src/zarrchive/cli/import_cmd.py +217 -0
  13. zarrchive-0.2.0/src/zarrchive/cli/init_cmd.py +267 -0
  14. zarrchive-0.2.0/src/zarrchive/cli/main.py +97 -0
  15. zarrchive-0.2.0/src/zarrchive/codecs/__init__.py +18 -0
  16. zarrchive-0.2.0/src/zarrchive/codecs/dimension_order.py +384 -0
  17. zarrchive-0.2.0/src/zarrchive/codecs/registry.py +445 -0
  18. zarrchive-0.2.0/src/zarrchive/coverage.py +152 -0
  19. zarrchive-0.2.0/src/zarrchive/encoding.py +274 -0
  20. zarrchive-0.2.0/src/zarrchive/fidelity.py +64 -0
  21. zarrchive-0.2.0/src/zarrchive/import_writer.py +682 -0
  22. zarrchive-0.2.0/src/zarrchive/planning.py +1524 -0
  23. zarrchive-0.2.0/src/zarrchive/quantization.py +58 -0
  24. zarrchive-0.2.0/src/zarrchive/schema.py +1002 -0
  25. zarrchive-0.2.0/src/zarrchive/sources.py +297 -0
  26. zarrchive-0.2.0/src/zarrchive/store_file_dir_count.py +912 -0
  27. zarrchive-0.2.0/src/zarrchive/store_layout.py +730 -0
  28. zarrchive-0.2.0/src/zarrchive/store_metadata.py +173 -0
  29. zarrchive-0.2.0/src/zarrchive/store_template.py +219 -0
  30. zarrchive-0.2.0/src/zarrchive/store_writer.py +1055 -0
  31. zarrchive-0.2.0/src/zarrchive/structure.py +527 -0
  32. zarrchive-0.2.0/src/zarrchive/time_grid.py +558 -0
  33. zarrchive-0.2.0/src/zarrchive/upload/__init__.py +13 -0
  34. zarrchive-0.2.0/src/zarrchive/upload/archive_meta.py +91 -0
  35. zarrchive-0.2.0/src/zarrchive/upload/bootstrap.py +118 -0
  36. zarrchive-0.2.0/src/zarrchive/upload/client.py +389 -0
  37. zarrchive-0.2.0/src/zarrchive/upload/server.py +486 -0
  38. zarrchive-0.2.0/src/zarrchive/upload/zip_stream.py +150 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Raphael Jolivet, Valentin Bauer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,298 @@
1
+ Metadata-Version: 2.4
2
+ Name: zarrchive
3
+ Version: 0.2.0
4
+ Summary: Schema-driven Zarr v3 storage for camera sensor timeseries, driven by a YAML template.
5
+ Keywords: zarr,all-sky camera,timeseries,cf,acdd,image codecs
6
+ Author: Raphael Jolivet, Valentin Bauer
7
+ Author-email: Raphael Jolivet <raphael.jolivet@minesparis.psl.eu>, Valentin Bauer <valentin.bauer@minesparis.psl.eu>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
16
+ Requires-Dist: pydantic>=2.12.5
17
+ Requires-Dist: pyyaml>=6.0.3
18
+ Requires-Dist: imagecodecs>=2026.6.6
19
+ Requires-Dist: xarray>=2026.2.0
20
+ Requires-Dist: zarr>=3.4.1
21
+ Requires-Dist: cast-value-rs>=0.4.2
22
+ Requires-Dist: numpy>=2.4.3
23
+ Requires-Dist: filelock>=3.30.2
24
+ Requires-Dist: fastapi>=0.115 ; extra == 'upload'
25
+ Requires-Dist: uvicorn>=0.30 ; extra == 'upload'
26
+ Requires-Dist: stream-unzip>=0.0.100 ; extra == 'upload'
27
+ Requires-Dist: requests>=2.32 ; extra == 'upload'
28
+ Requires-Dist: fsspec>=2024.1.0 ; extra == 'upload'
29
+ Requires-Dist: aiohttp>=3.9 ; extra == 'upload'
30
+ Requires-Python: >=3.12
31
+ Project-URL: Homepage, https://git.sophia.minesparis.psl.eu/oie/zarrchive
32
+ Project-URL: Issues, https://git.sophia.minesparis.psl.eu/oie/zarrchive/-/issues
33
+ Project-URL: Repository, https://git.sophia.minesparis.psl.eu/oie/zarrchive
34
+ Provides-Extra: upload
35
+ Description-Content-Type: text/markdown
36
+
37
+ # zarrchive
38
+
39
+ Schema-driven [Zarr v3](https://zarr-specs.readthedocs.io/) storage for time
40
+ series and the static data that goes with them, including images.
41
+
42
+ A single YAML **template** describes the archive: dimensions, dtypes, chunking,
43
+ sharding, codecs, metadata. The store it creates is plain Zarr v3, readable by
44
+ any tool that speaks the spec, with or without this library.
45
+
46
+ ## Install
47
+
48
+ Requires Python ≥ 3.12.
49
+
50
+ ```bash
51
+ uv add zarrchive # or: pip install zarrchive
52
+ uv add 'zarrchive[upload]' # plus the camera→archive transfer feature
53
+ ```
54
+
55
+ Reading a store back needs only `xarray` and, when the template uses an
56
+ `imagecodecs` codec, `imagecodecs`. Never this library:
57
+
58
+ ```python
59
+ import imagecodecs.zarr, xarray as xr
60
+ imagecodecs.zarr.register_codecs()
61
+ ds = xr.open_zarr("out.zarr")
62
+ ```
63
+
64
+ ## Python API
65
+
66
+ ```python
67
+ import xarray as xr
68
+ from zarrchive import Zarrchive, load_template
69
+
70
+ load_template("cam.yaml") # validate without opening a store
71
+
72
+ with Zarrchive("out.zarr", "cam.yaml") as store: # create or open
73
+ store.write("radiance", frame, loc={"time": "2020-01-01T00:15:00"})
74
+ ```
75
+
76
+ `Zarrchive(path, template)` takes the write lock for the session, creates the
77
+ store if it is absent, and restores the metadata on exit. `frame` is an
78
+ `xarray.DataArray`, or a numpy array with `dims=`. `loc` supplies the axes the
79
+ payload does not carry, by label, so `"R"` is a value of the `band` coordinate
80
+ rather than an index.
81
+
82
+ The main methods:
83
+
84
+ | Method | Effect |
85
+ |---|---|
86
+ | `write(name, data, loc=...)` | One observation, or a whole batch when the payload carries a `time` coordinate. |
87
+ | `bulk_write(name=[blocks], workers=...)` | Chunk-aligned blocks written shard by shard, without holding a shard in memory. |
88
+ | `reserve_time(labels)` | Grow the time axis before the data arrives. |
89
+ | `delete_before(cutoff)` / `delete_after(cutoff)` | Drop from one end of the time axis. |
90
+ | `finalize()` | Write the global attributes and consolidate metadata. Done for you on exit from a `with` block. |
91
+
92
+ Details in [Writing](docs/writing.md) and the [Python API](docs/api.md).
93
+
94
+ ## CLI
95
+
96
+ ```bash
97
+ zarrchive init examples/out.zarr -s examples/template.yml -a examples/meta.yml
98
+ ```
99
+
100
+ Creates a store, or updates the metadata of one that exists. The layout of an
101
+ array is fixed when it is created, so a re-run with the same options does
102
+ nothing, and an option that contradicts the store on disk is refused rather than
103
+ ignored.
104
+
105
+ ```bash
106
+ zarrchive init STORE -s TEMPLATE [-a ATTRIBUTES]
107
+ [--separator .|/] [--no-shard]
108
+ [--shard DIMENSION=SIZE] [-n/--dry-run]
109
+ ```
110
+
111
+ `-a` reads placeholder values from a YAML, JSON or INI file. `--shard time=96`
112
+ sets the shard size along the time axis, `--no-shard` writes one storage object
113
+ per chunk, and `-n` prints the plan without touching the store. Metadata is
114
+ always consolidated, so a reader opens the store in one request.
115
+
116
+ ```bash
117
+ zarrchive import examples/out.zarr -v captures -b examples
118
+ ```
119
+
120
+ Fills one variable from image files. One file fills one chunk, the pattern's
121
+ placeholders give the coordinates, and the file supplies the dimensions the
122
+ pattern does not name. No dimension is assumed: a single calibration file is a
123
+ pattern with no time group. The pattern defaults to the one the store records for
124
+ the variable (`-p` overrides it), and `-b` sets the folder it is resolved against
125
+ (the current directory by default).
126
+
127
+ The store is the source of truth, so `import` takes no template. Because every
128
+ variable is materialised at `init`, its dimensions, dtype, chunking, sharding,
129
+ codec and default pattern are all read back from the store; a store that does not
130
+ carry them is refused with a clear message rather than guessed at.
131
+
132
+ A PNG or TIFF re-encoded into a JPEG array is refused unless you pass
133
+ `--allow-lossy`; a JPEG file stored into a JPEG array keeps its bytes. `--rmse`
134
+ caps the drift of a lossy re-encode, and `--workers` sets how many processes
135
+ encode shards.
136
+
137
+ See [Command line](docs/cli.md).
138
+
139
+ ## Quickstart
140
+
141
+ **1. Describe the store.** One file, validated on load. Unknown fields, bad
142
+ dtypes and impossible chunk/shard combinations fail here, before any data moves.
143
+
144
+ ```yaml
145
+ # cam.yaml
146
+ dimensions:
147
+ time: # a block declares the coordinate variable too
148
+ size: expand # grows as observations arrive
149
+ type: uint64
150
+ grid: {frequency: PT15M, grid_tolerance: PT1S} # omit for a free axis
151
+ attributes: {units: seconds since 1970-01-01 00:00:00}
152
+ band:
153
+ values: [R, G1, B, G2] # static; size and type inferred from the labels
154
+ y: auto # taken from the first frame written, fixed after that
155
+ x: auto
156
+
157
+ chunks: {time: 1, band: -1, y: -1, x: -1} # one frame per chunk; -1 = whole axis
158
+ shards: {time: 96, band: -1, y: -1, x: -1} # 96 chunks per file on disk
159
+
160
+ variables:
161
+ radiance:
162
+ dimensions: [time, band, y, x]
163
+ type: float32
164
+ encoding: {name: imagecodecs_jpegxl, args: {lossless: true}}
165
+ attributes: {units: W m-2 sr-1, _FillValue: .nan}
166
+
167
+ attributes:
168
+ Conventions: CF-1.13, ACDD-1.3
169
+ title: All-sky camera radiance
170
+ ```
171
+
172
+ Prefer a fixed size over `auto` when the geometry is known. An axis declared
173
+ `auto` has no length until the first write, so its arrays start against a zero
174
+ length and are rebuilt once, when a file sizes the axis. An image size that is
175
+ fixed in practice is better written as an integer, which creates every array at
176
+ its real shape from the start.
177
+
178
+ **2. Write to it.** Creating the store writes every array's metadata and any
179
+ static coordinates; re-opening an existing store with the same template is a
180
+ no-op.
181
+
182
+ ```python
183
+ from zarrchive import Zarrchive
184
+
185
+ with Zarrchive("out.zarr", "cam.yaml") as store:
186
+ store.write("radiance", frame, loc={"time": "2020-01-01T00:15:00"})
187
+ ```
188
+
189
+ A payload that carries a `time` dimension *and* coordinate is a whole batch: the
190
+ axis is reserved once and each shard written once.
191
+
192
+ **3. Read it back.** Plain xarray, as in Install above.
193
+
194
+ ## Example
195
+
196
+ A small, runnable dataset lives in [`examples/`](examples/): a colour image
197
+ variable, a boolean calibration mask, four JPEG captures in
198
+ `images/2024-08-13/`, and the metadata file that fills the template's
199
+ placeholders. It is complete enough to run both commands and read the store
200
+ back, and small enough to read end to end.
201
+
202
+ ```bash
203
+ # 1. Create the store. -a fills the template's {placeholders}.
204
+ zarrchive init examples/out.zarr -s examples/template.yml -a examples/meta.yml
205
+
206
+ # 2. Fill the image variable from the four captures. No -s: the store
207
+ # describes itself, and no -p either: the template's source pattern is
208
+ # stored in the variable's metadata and reused.
209
+ zarrchive import examples/out.zarr -v captures -b examples
210
+
211
+ # 3. Import the single calibration mask, a PNG with no time axis.
212
+ zarrchive import examples/out.zarr -v mask -b examples
213
+ ```
214
+
215
+ Read it back with plain xarray, as any reader would:
216
+
217
+ ```python
218
+ import imagecodecs.zarr, xarray as xr
219
+ imagecodecs.zarr.register_codecs()
220
+
221
+ xr.open_zarr("examples/out.zarr").sizes
222
+ # Frozen({'time': 4, 'y': 212, 'x': 221, 'band': 3})
223
+
224
+ xr.open_zarr("examples/out.zarr", group="calibration")["mask"]
225
+ # <xarray.DataArray 'mask' (y: 212, x: 221)> bool
226
+ ```
227
+
228
+ The template declares its `time` and `band` coordinates inline, in the
229
+ `dimensions` section, and keeps only the two data variables in `variables`:
230
+ `captures[time, y, x, band]` in JPEG, and `mask[y, x]` in a `calibration` group.
231
+ `y` and `x` are `auto`, so their size comes from the first file imported.
232
+
233
+ [`examples/notebook.ipynb`](examples/notebook.ipynb) opens the same store with
234
+ `xarray`, lists its groups and variables, and renders a capture, an animation of
235
+ the four, and the mask. Its outputs are saved, so it reads without running.
236
+
237
+ ## What it does
238
+
239
+ - Layout and metadata live in a validated template, not in calling code.
240
+ - The time axis is either pinned to a fixed grid, where jitter snaps onto slots
241
+ and anything further off is rejected, or free, holding the exact instants it is
242
+ given.
243
+ - Appends land at the end, and written rows are never rewritten or shifted.
244
+ Deletion also only ever removes from an end.
245
+ - Appending or deleting touches the chunks it must and no others. The archive is
246
+ never rebuilt.
247
+ - The template's CF and ACDD attributes are written into the store and restored
248
+ after every write.
249
+ - Encoding goes through the codec the template names: JPEG-XL, JPEG2000, ZFP or
250
+ Blosc/Zstd, with the axis order each needs, plus optional float-to-integer
251
+ quantization.
252
+ - Adding a variable to the template and re-opening creates its array alongside
253
+ the others, leaving old data in place.
254
+ - An open store holds an exclusive lock for its whole session, so two writers
255
+ cannot interleave.
256
+
257
+ ## Documentation
258
+
259
+ Start here if you want to do more than write one frame:
260
+
261
+ | Page | What it covers |
262
+ |---|---|
263
+ | **[Command line](docs/cli.md)** | `zarrchive init` and `zarrchive import`: creating a store from a shell, filling a variable from image files, and what a re-run can and cannot change. |
264
+ | **[Template YAML](docs/template.md)** | Every field of the template: dimensions, chunks and shards, variables, groups, encodings, quantization, the time axis, placeholders. |
265
+ | **[Writing](docs/writing.md)** | The two time models, append-only rules, reserving, single vs. batch vs. bulk writes, metadata edits, locking. |
266
+ | **[Reading](docs/reading.md)** | Opening a store with xarray, codec registration, consolidated metadata, what a reader needs. |
267
+ | **[Deleting](docs/deletion.md)** | `delete_before` / `delete_after`, why two mechanisms, and how shard size becomes a retention decision. |
268
+ | **[Upload client and server](docs/upload.md)** | Shipping a day from a camera to an archive and reclaiming it, with authentication and Docker. |
269
+ | **[Python API](docs/api.md)** | Every member of `Zarrchive` and the module map. |
270
+ | **[Storage layout](docs/storage-layout.md)** | Chunks, shards, and where the write cost goes. |
271
+ | **[Example notebook](examples/notebook.ipynb)** | Loading the example store with xarray: its groups and variables, one capture, an animation, the mask. Outputs saved, so it reads without running. |
272
+
273
+ The template format has its own versioned contract in
274
+ [`schema/schema.yml`](schema/schema.yml), kept in step with the code by a test.
275
+
276
+ ## Project layout
277
+
278
+ | Path | Purpose |
279
+ |---|---|
280
+ | [`src/zarrchive/`](src/zarrchive/) | The library: pure logic (`schema`, `time_grid`, `planning`, `chunking`, `encoding`, `structure`) and a thin I/O shell (`cam_store`, `store_writer`, `append`). |
281
+ | [`src/zarrchive/codecs/`](src/zarrchive/codecs/) | Turns a template's `encoding:` block into zarr codecs, with the transposes image codecs need. |
282
+ | [`src/zarrchive/cli/`](src/zarrchive/cli/) | The `zarrchive` command: one module per subcommand, on top of the same API. |
283
+ | [`src/zarrchive/upload/`](src/zarrchive/upload/) | The optional camera→archive transfer. |
284
+ | [`schema/`](schema/) | The template format, as a versioned contract. |
285
+ | [`docs/`](docs/) | The detail behind this README. |
286
+ | [`tests/zarrchive/`](tests/zarrchive/) | Test suite and YAML fixtures. |
287
+
288
+ The code follows a functional-core / imperative-shell split: as much logic as
289
+ possible lives in pure functions, and filesystem access stays in a few thin
290
+ modules. Each module's docstring says which kind it is.
291
+
292
+ ## Development
293
+
294
+ ```bash
295
+ uv sync --group dev --extra upload
296
+ make test # uv run pytest
297
+ make lint # ruff check, ruff format --check, ty check
298
+ ```
@@ -0,0 +1,262 @@
1
+ # zarrchive
2
+
3
+ Schema-driven [Zarr v3](https://zarr-specs.readthedocs.io/) storage for time
4
+ series and the static data that goes with them, including images.
5
+
6
+ A single YAML **template** describes the archive: dimensions, dtypes, chunking,
7
+ sharding, codecs, metadata. The store it creates is plain Zarr v3, readable by
8
+ any tool that speaks the spec, with or without this library.
9
+
10
+ ## Install
11
+
12
+ Requires Python ≥ 3.12.
13
+
14
+ ```bash
15
+ uv add zarrchive # or: pip install zarrchive
16
+ uv add 'zarrchive[upload]' # plus the camera→archive transfer feature
17
+ ```
18
+
19
+ Reading a store back needs only `xarray` and, when the template uses an
20
+ `imagecodecs` codec, `imagecodecs`. Never this library:
21
+
22
+ ```python
23
+ import imagecodecs.zarr, xarray as xr
24
+ imagecodecs.zarr.register_codecs()
25
+ ds = xr.open_zarr("out.zarr")
26
+ ```
27
+
28
+ ## Python API
29
+
30
+ ```python
31
+ import xarray as xr
32
+ from zarrchive import Zarrchive, load_template
33
+
34
+ load_template("cam.yaml") # validate without opening a store
35
+
36
+ with Zarrchive("out.zarr", "cam.yaml") as store: # create or open
37
+ store.write("radiance", frame, loc={"time": "2020-01-01T00:15:00"})
38
+ ```
39
+
40
+ `Zarrchive(path, template)` takes the write lock for the session, creates the
41
+ store if it is absent, and restores the metadata on exit. `frame` is an
42
+ `xarray.DataArray`, or a numpy array with `dims=`. `loc` supplies the axes the
43
+ payload does not carry, by label, so `"R"` is a value of the `band` coordinate
44
+ rather than an index.
45
+
46
+ The main methods:
47
+
48
+ | Method | Effect |
49
+ |---|---|
50
+ | `write(name, data, loc=...)` | One observation, or a whole batch when the payload carries a `time` coordinate. |
51
+ | `bulk_write(name=[blocks], workers=...)` | Chunk-aligned blocks written shard by shard, without holding a shard in memory. |
52
+ | `reserve_time(labels)` | Grow the time axis before the data arrives. |
53
+ | `delete_before(cutoff)` / `delete_after(cutoff)` | Drop from one end of the time axis. |
54
+ | `finalize()` | Write the global attributes and consolidate metadata. Done for you on exit from a `with` block. |
55
+
56
+ Details in [Writing](docs/writing.md) and the [Python API](docs/api.md).
57
+
58
+ ## CLI
59
+
60
+ ```bash
61
+ zarrchive init examples/out.zarr -s examples/template.yml -a examples/meta.yml
62
+ ```
63
+
64
+ Creates a store, or updates the metadata of one that exists. The layout of an
65
+ array is fixed when it is created, so a re-run with the same options does
66
+ nothing, and an option that contradicts the store on disk is refused rather than
67
+ ignored.
68
+
69
+ ```bash
70
+ zarrchive init STORE -s TEMPLATE [-a ATTRIBUTES]
71
+ [--separator .|/] [--no-shard]
72
+ [--shard DIMENSION=SIZE] [-n/--dry-run]
73
+ ```
74
+
75
+ `-a` reads placeholder values from a YAML, JSON or INI file. `--shard time=96`
76
+ sets the shard size along the time axis, `--no-shard` writes one storage object
77
+ per chunk, and `-n` prints the plan without touching the store. Metadata is
78
+ always consolidated, so a reader opens the store in one request.
79
+
80
+ ```bash
81
+ zarrchive import examples/out.zarr -v captures -b examples
82
+ ```
83
+
84
+ Fills one variable from image files. One file fills one chunk, the pattern's
85
+ placeholders give the coordinates, and the file supplies the dimensions the
86
+ pattern does not name. No dimension is assumed: a single calibration file is a
87
+ pattern with no time group. The pattern defaults to the one the store records for
88
+ the variable (`-p` overrides it), and `-b` sets the folder it is resolved against
89
+ (the current directory by default).
90
+
91
+ The store is the source of truth, so `import` takes no template. Because every
92
+ variable is materialised at `init`, its dimensions, dtype, chunking, sharding,
93
+ codec and default pattern are all read back from the store; a store that does not
94
+ carry them is refused with a clear message rather than guessed at.
95
+
96
+ A PNG or TIFF re-encoded into a JPEG array is refused unless you pass
97
+ `--allow-lossy`; a JPEG file stored into a JPEG array keeps its bytes. `--rmse`
98
+ caps the drift of a lossy re-encode, and `--workers` sets how many processes
99
+ encode shards.
100
+
101
+ See [Command line](docs/cli.md).
102
+
103
+ ## Quickstart
104
+
105
+ **1. Describe the store.** One file, validated on load. Unknown fields, bad
106
+ dtypes and impossible chunk/shard combinations fail here, before any data moves.
107
+
108
+ ```yaml
109
+ # cam.yaml
110
+ dimensions:
111
+ time: # a block declares the coordinate variable too
112
+ size: expand # grows as observations arrive
113
+ type: uint64
114
+ grid: {frequency: PT15M, grid_tolerance: PT1S} # omit for a free axis
115
+ attributes: {units: seconds since 1970-01-01 00:00:00}
116
+ band:
117
+ values: [R, G1, B, G2] # static; size and type inferred from the labels
118
+ y: auto # taken from the first frame written, fixed after that
119
+ x: auto
120
+
121
+ chunks: {time: 1, band: -1, y: -1, x: -1} # one frame per chunk; -1 = whole axis
122
+ shards: {time: 96, band: -1, y: -1, x: -1} # 96 chunks per file on disk
123
+
124
+ variables:
125
+ radiance:
126
+ dimensions: [time, band, y, x]
127
+ type: float32
128
+ encoding: {name: imagecodecs_jpegxl, args: {lossless: true}}
129
+ attributes: {units: W m-2 sr-1, _FillValue: .nan}
130
+
131
+ attributes:
132
+ Conventions: CF-1.13, ACDD-1.3
133
+ title: All-sky camera radiance
134
+ ```
135
+
136
+ Prefer a fixed size over `auto` when the geometry is known. An axis declared
137
+ `auto` has no length until the first write, so its arrays start against a zero
138
+ length and are rebuilt once, when a file sizes the axis. An image size that is
139
+ fixed in practice is better written as an integer, which creates every array at
140
+ its real shape from the start.
141
+
142
+ **2. Write to it.** Creating the store writes every array's metadata and any
143
+ static coordinates; re-opening an existing store with the same template is a
144
+ no-op.
145
+
146
+ ```python
147
+ from zarrchive import Zarrchive
148
+
149
+ with Zarrchive("out.zarr", "cam.yaml") as store:
150
+ store.write("radiance", frame, loc={"time": "2020-01-01T00:15:00"})
151
+ ```
152
+
153
+ A payload that carries a `time` dimension *and* coordinate is a whole batch: the
154
+ axis is reserved once and each shard written once.
155
+
156
+ **3. Read it back.** Plain xarray, as in Install above.
157
+
158
+ ## Example
159
+
160
+ A small, runnable dataset lives in [`examples/`](examples/): a colour image
161
+ variable, a boolean calibration mask, four JPEG captures in
162
+ `images/2024-08-13/`, and the metadata file that fills the template's
163
+ placeholders. It is complete enough to run both commands and read the store
164
+ back, and small enough to read end to end.
165
+
166
+ ```bash
167
+ # 1. Create the store. -a fills the template's {placeholders}.
168
+ zarrchive init examples/out.zarr -s examples/template.yml -a examples/meta.yml
169
+
170
+ # 2. Fill the image variable from the four captures. No -s: the store
171
+ # describes itself, and no -p either: the template's source pattern is
172
+ # stored in the variable's metadata and reused.
173
+ zarrchive import examples/out.zarr -v captures -b examples
174
+
175
+ # 3. Import the single calibration mask, a PNG with no time axis.
176
+ zarrchive import examples/out.zarr -v mask -b examples
177
+ ```
178
+
179
+ Read it back with plain xarray, as any reader would:
180
+
181
+ ```python
182
+ import imagecodecs.zarr, xarray as xr
183
+ imagecodecs.zarr.register_codecs()
184
+
185
+ xr.open_zarr("examples/out.zarr").sizes
186
+ # Frozen({'time': 4, 'y': 212, 'x': 221, 'band': 3})
187
+
188
+ xr.open_zarr("examples/out.zarr", group="calibration")["mask"]
189
+ # <xarray.DataArray 'mask' (y: 212, x: 221)> bool
190
+ ```
191
+
192
+ The template declares its `time` and `band` coordinates inline, in the
193
+ `dimensions` section, and keeps only the two data variables in `variables`:
194
+ `captures[time, y, x, band]` in JPEG, and `mask[y, x]` in a `calibration` group.
195
+ `y` and `x` are `auto`, so their size comes from the first file imported.
196
+
197
+ [`examples/notebook.ipynb`](examples/notebook.ipynb) opens the same store with
198
+ `xarray`, lists its groups and variables, and renders a capture, an animation of
199
+ the four, and the mask. Its outputs are saved, so it reads without running.
200
+
201
+ ## What it does
202
+
203
+ - Layout and metadata live in a validated template, not in calling code.
204
+ - The time axis is either pinned to a fixed grid, where jitter snaps onto slots
205
+ and anything further off is rejected, or free, holding the exact instants it is
206
+ given.
207
+ - Appends land at the end, and written rows are never rewritten or shifted.
208
+ Deletion also only ever removes from an end.
209
+ - Appending or deleting touches the chunks it must and no others. The archive is
210
+ never rebuilt.
211
+ - The template's CF and ACDD attributes are written into the store and restored
212
+ after every write.
213
+ - Encoding goes through the codec the template names: JPEG-XL, JPEG2000, ZFP or
214
+ Blosc/Zstd, with the axis order each needs, plus optional float-to-integer
215
+ quantization.
216
+ - Adding a variable to the template and re-opening creates its array alongside
217
+ the others, leaving old data in place.
218
+ - An open store holds an exclusive lock for its whole session, so two writers
219
+ cannot interleave.
220
+
221
+ ## Documentation
222
+
223
+ Start here if you want to do more than write one frame:
224
+
225
+ | Page | What it covers |
226
+ |---|---|
227
+ | **[Command line](docs/cli.md)** | `zarrchive init` and `zarrchive import`: creating a store from a shell, filling a variable from image files, and what a re-run can and cannot change. |
228
+ | **[Template YAML](docs/template.md)** | Every field of the template: dimensions, chunks and shards, variables, groups, encodings, quantization, the time axis, placeholders. |
229
+ | **[Writing](docs/writing.md)** | The two time models, append-only rules, reserving, single vs. batch vs. bulk writes, metadata edits, locking. |
230
+ | **[Reading](docs/reading.md)** | Opening a store with xarray, codec registration, consolidated metadata, what a reader needs. |
231
+ | **[Deleting](docs/deletion.md)** | `delete_before` / `delete_after`, why two mechanisms, and how shard size becomes a retention decision. |
232
+ | **[Upload client and server](docs/upload.md)** | Shipping a day from a camera to an archive and reclaiming it, with authentication and Docker. |
233
+ | **[Python API](docs/api.md)** | Every member of `Zarrchive` and the module map. |
234
+ | **[Storage layout](docs/storage-layout.md)** | Chunks, shards, and where the write cost goes. |
235
+ | **[Example notebook](examples/notebook.ipynb)** | Loading the example store with xarray: its groups and variables, one capture, an animation, the mask. Outputs saved, so it reads without running. |
236
+
237
+ The template format has its own versioned contract in
238
+ [`schema/schema.yml`](schema/schema.yml), kept in step with the code by a test.
239
+
240
+ ## Project layout
241
+
242
+ | Path | Purpose |
243
+ |---|---|
244
+ | [`src/zarrchive/`](src/zarrchive/) | The library: pure logic (`schema`, `time_grid`, `planning`, `chunking`, `encoding`, `structure`) and a thin I/O shell (`cam_store`, `store_writer`, `append`). |
245
+ | [`src/zarrchive/codecs/`](src/zarrchive/codecs/) | Turns a template's `encoding:` block into zarr codecs, with the transposes image codecs need. |
246
+ | [`src/zarrchive/cli/`](src/zarrchive/cli/) | The `zarrchive` command: one module per subcommand, on top of the same API. |
247
+ | [`src/zarrchive/upload/`](src/zarrchive/upload/) | The optional camera→archive transfer. |
248
+ | [`schema/`](schema/) | The template format, as a versioned contract. |
249
+ | [`docs/`](docs/) | The detail behind this README. |
250
+ | [`tests/zarrchive/`](tests/zarrchive/) | Test suite and YAML fixtures. |
251
+
252
+ The code follows a functional-core / imperative-shell split: as much logic as
253
+ possible lives in pure functions, and filesystem access stays in a few thin
254
+ modules. Each module's docstring says which kind it is.
255
+
256
+ ## Development
257
+
258
+ ```bash
259
+ uv sync --group dev --extra upload
260
+ make test # uv run pytest
261
+ make lint # ruff check, ruff format --check, ty check
262
+ ```