icechunk.xarray#
Xarray integration for writing datasets to Icechunk.
icechunk.xarray #
Functions:
| Name | Description |
|---|---|
to_icechunk | Write an Xarray object to a group of an Icechunk store. |
to_icechunk #
to_icechunk(
obj,
session,
*,
group=None,
mode=None,
safe_chunks=True,
align_chunks=False,
append_dim=None,
region=None,
encoding=None,
chunkmanager_store_kwargs=None,
split_every=None,
)
Write an Xarray object to a group of an Icechunk store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj | DataArray | Dataset | Xarray object to write | required |
session | Session | Writable Icechunk Session | required |
mode | "w", "w-", "a", "a-", r+", None | Persistence mode:
The default mode is "a" if .. note:: When modifying an existing Zarr array that is lazily opened, the "w" behavior can be surprising since the underlying file that is being lazily read from might get deleted before the data is computed. | "w" |
group | str | Group path. (a.k.a. | None |
encoding | dict | Nested dictionary with variable names as keys and dictionaries of variable specific encodings as values, e.g., | None |
append_dim | hashable | If set, the dimension along which the data will be appended. All other dimensions on overridden variables must remain the same size. | None |
region | dict or auto | Optional mapping from dimension names to either a) If Alternatively integer slices can be provided; for example, Users are expected to ensure that the specified region aligns with Zarr chunk boundaries, and that dask chunks are also aligned. Xarray makes limited checks that these multiple chunk boundaries line up. It is possible to write incomplete chunks and corrupt the data with this option if you are not careful. | None |
safe_chunks | bool | If True, only allow writes to when there is a many-to-one relationship between Zarr chunks (specified in encoding) and Dask chunks. Set False to override this restriction; however, data may become corrupted if Zarr arrays are written in parallel. In addition to the many-to-one relationship validation, it also detects partial chunks writes when using the region parameter, these partial chunks are considered unsafe in the mode "r+" but safe in the mode "a". Note: Even with these validations it can still be unsafe to write two or more chunked arrays in the same location in parallel if they are not writing in independent regions. | True |
align_chunks | bool | If True, rechunks the Dask array to align with Zarr chunks before writing. This ensures each Dask chunk maps to one or more contiguous Zarr chunks, which avoids race conditions. Internally, the process sets safe_chunks=False and tries to preserve the original Dask chunking as much as possible. Note: While this alignment avoids write conflicts stemming from chunk boundary misalignment, it does not protect against race conditions if multiple uncoordinated processes write to the same Zarr array concurrently. | False |
chunkmanager_store_kwargs | dict | Additional keyword arguments passed on to the | None |
split_every | int | None | Number of tasks to merge at every level of the tree reduction. | None |
Returns:
| Type | Description |
|---|---|
None | |
Notes
Two restrictions apply to the use of region:
- If
regionis set, all variables in a dataset must have at least one dimension in common with the region. Other variables should be written in a separate single call toto_icechunk(). - Dimensions cannot be included in both
regionandappend_dimat the same time. To create empty arrays to fill in withregion, use the_XarrayDatasetWriterdirectly.
Source code in icechunk-python/python/icechunk/xarray.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |