Writing stores¶
Write HEALPix pyramids to Zarr stores on local disk or S3, and choose
storage options and chunk sizes for them (grid_doctor.io).
Writing a pyramid¶
save_pyramid(pyramid, path, s3_options=None, *, mode='a', region='auto', zarr_format=2, encoding=None, write_coords='auto', structure='flat')
¶
Write a HEALPix pyramid to Zarr stores on S3 or local disk.
Each level is stored below "<path>/level_<level>.zarr".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyramid
|
dict[int, Dataset]
|
Mapping of HEALPix level to dataset. |
required |
path
|
str
|
Target prefix. An |
required |
s3_options
|
S3Options | None
|
Options forwarded to :class: |
None
|
mode
|
Literal['a', 'w', 'r+']
|
Zarr write mode. |
'a'
|
region
|
Literal['auto'] | Region
|
Region writes for partial updates. |
'auto'
|
zarr_format
|
Literal[2, 3]
|
Zarr format version. |
2
|
encoding
|
PyramidEncoding | None
|
Per-level encoding dictionaries. |
None
|
write_coords
|
bool | Literal['auto']
|
Whether to materialise the |
'auto'
|
structure
|
Literal['flat', 'multiscales']
|
separate stores ('flat'), or combine them into a datatree ('multiscales'). |
'flat'
|
Source code in grid_doctor/io/_save.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
To split the write across many jobs (one array-job element per time range, say), see Parallel writes.
S3 options¶
get_s3_options(endpoint_url, secrets_file, **kwargs)
¶
Build an S3 options dictionary from an endpoint and credentials file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint_url
|
str
|
S3-compatible endpoint URL. |
required |
secrets_file
|
str | Path
|
JSON file containing |
required |
**kwargs
|
str
|
Additional options merged into the returned dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Options for |
Source code in grid_doctor/io/_options.py
Chunking¶
Chunk sizes balance the number of objects in a store against the amount of data read for a small selection.
chunk_for_target_store_size(*, level, dtype='float32', target_stored_mib=16.0, compression_ratio=2.0, access='map', ntime=None, max_time_chunk=None, max_cell_chunk=None)
¶
Compute (time, cell) chunks for a HEALPix dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
HEALPix order / level. |
required |
dtype
|
DTypeLike
|
Variable dtype. |
'float32'
|
target_stored_mib
|
float
|
Desired approximate compressed chunk size on disk. |
16.0
|
compression_ratio
|
float
|
Estimated ratio: uncompressed_bytes / compressed_bytes |
2.0
|
access
|
Literal['time_series', 'map']
|
"map" or "time_series". |
'map'
|
ntime
|
int | None
|
Total time size. Needed for time_series mode unless max_time_chunk is given. |
None
|
max_time_chunk
|
int | None
|
Optional cap for time chunk. |
None
|
max_cell_chunk
|
int | None
|
Optional cap for cell chunk. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Chunk sizes, e.g. {"time": 5, "cell": 786432}. |