icechunk¶
helpers
¶
Shared helpers: repositories, commits, and OCS-shaped test data.
The write/read pair here is the pattern open-climate-service uses for every
ingest: open a writable session on a branch, hand session.store to xarray
as if it were any other zarr store, then commit. Nothing is visible to readers
until that commit lands.
Functions:¶
quiet_icechunk_logs()
¶
Silence icechunk's Rust-layer INFO and WARN output.
Local filesystem storage prints two warnings on every repository open -- about concurrent-commit safety and conditional PUT metadata -- which are correct advice for production object stores and pure noise in a lesson. Examples call this once at startup so their output stays readable.
Source code in icechunk/src/ocs_stack_icechunk/helpers.py
open_repo(path)
¶
Open an icechunk repository, creating it if it does not exist.
Mirrors open_or_create_repo in open-climate-service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Directory for the repository, conventionally ending |
required |
Returns:
| Type | Description |
|---|---|
Any
|
An |
Source code in icechunk/src/ocs_stack_icechunk/helpers.py
write_dataset(repo, ds, message, *, branch='main', append_dim=None)
¶
Write a dataset to a branch and commit it as one transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Any
|
The repository to write into. |
required |
ds
|
Dataset
|
The dataset to store. |
required |
message
|
str
|
Commit message, which becomes part of the permanent history. |
required |
branch
|
str
|
Branch to write on. |
'main'
|
append_dim
|
str | None
|
When given, append along this dimension instead of replacing the store's contents. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The new snapshot id. |
Source code in icechunk/src/ocs_stack_icechunk/helpers.py
read_dataset(repo, *, branch=None, snapshot_id=None, tag=None)
¶
Open a dataset from a branch tip, a tag, or a specific snapshot.
At most one selector may be given; with none, the read is of main.
Silently preferring one selector over another would make a typo look like a
working read of the wrong point in history, which is the failure mode
version control exists to prevent -- so a conflict raises instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Any
|
The repository to read from. Defaults to the |
required |
branch
|
str | None
|
Branch whose tip to read. |
None
|
snapshot_id
|
str | None
|
A specific snapshot to read. |
None
|
tag
|
str | None
|
A tag to read. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
The dataset as of that point in history. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If more than one of branch, snapshot_id, and tag is given, or if one of them is given as an empty string. |
Source code in icechunk/src/ocs_stack_icechunk/helpers.py
describe_history(repo, *, branch='main')
¶
Summarize a branch's commit history, newest first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo
|
Any
|
The repository to inspect. |
required |
branch
|
str
|
Branch whose ancestry to walk. |
'main'
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
One dict per snapshot with its id, short id, message, and timestamp. |
Source code in icechunk/src/ocs_stack_icechunk/helpers.py
climate_dataset(days=30, ny=32, nx=32, start='2024-01-01', offset=0.0, seed=0)
¶
Build a small OCS-shaped dataset with dims (time, y, x).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
int
|
Number of daily time steps; must be at least 1. |
30
|
ny
|
int
|
Grid height; must be at least 1. |
32
|
nx
|
int
|
Grid width; must be at least 1. |
32
|
start
|
str
|
First date, as an ISO date string. |
'2024-01-01'
|
offset
|
float
|
Constant added to every value, to make revisions distinguishable. |
0.0
|
seed
|
int
|
Seed for the noise term. |
0
|
Returns:
| Type | Description |
|---|---|
Dataset
|
A dataset with one variable, |
Raises:
| Type | Description |
|---|---|
ValueError
|
If days, ny, or nx is less than 1. |