Skip to content

Commit

Permalink
Merge pull request #434 from JuliaDataCubes/la/skeleton
Browse files Browse the repository at this point in the history
update skeleton values
  • Loading branch information
lazarusA authored Sep 10, 2024
2 parents 07a30ea + bd54221 commit 0ccd686
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions docs/src/UserGuide/write.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,27 @@ using YAXArrays, Zarr, FillArrays
create the `Zeros` array

````@ansi write
a = YAXArray(Zeros(Union{Missing, Int32}, 10, 20))
a = YAXArray(Zeros(Union{Missing, Float32}, 5, 4, 5))
````

and save them as
Now, save to disk with

````@example write
r = savecube(a, "skeleton.zarr", driver=:zarr, skeleton=true)
r = savecube(a, "skeleton.zarr", driver=:zarr, skeleton=true, overwrite=true)
nothing # hide
````

::: warning

`overwrite=true` will delete your previous `.zarr` file before creating a new one.

:::


and check that all the values are `missing`

````@example write
all(ismissing,r[:,:])
all(ismissing, r[:,:,:])
````

If using `FillArrays` is not possible, using the `zeros` function works as well, though it does allocate the array in memory.
Expand All @@ -113,3 +120,39 @@ The `skeleton` argument is also available for `savedataset`.

:::

Using the toy array defined above we can do

````@example write
ds = Dataset(skeleton=a) # skeleton will the variable name
````

````@example write
ds_s = savedataset(ds, path="skeleton.zarr", driver=:zarr, skeleton=true, overwrite=true)
nothing # hide
````

## Update values of `dataset`

Now, we show how to start updating the array values. In order to do it we need to open the dataset first with writing `w` rights as follows:

````@example write
ds_open = zopen("skeleton.zarr", "w")
ds_array = ds_open["skeleton"]
````

and then we simply update values by indexing them where necessary

````@example write
ds_array[:,:,1] = rand(Float32, 5, 4) # this will update values directly into disk!
````

we can verify is this working by loading again directly from disk

````@example write
ds_open = open_dataset("skeleton.zarr")
ds_array = ds_open["skeleton"]
ds_array.data[:,:,1]
````

indeed, those entries had been updated.

0 comments on commit 0ccd686

Please sign in to comment.