Skip to content

Commit cc966fd

Browse files
authored
Merge pull request #503 from JuliaDataCubes/la/merge_xcompute
2 parents 00f1b73 + bbb3293 commit cc966fd

File tree

4 files changed

+118
-449
lines changed

4 files changed

+118
-449
lines changed

docs/make.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ makedocs(; sitename="YAXArrays.jl",
1717
)
1818
# To edit the sidebar, you must edit `docs/src/.vitepress/config.mts`.
1919

20-
deploydocs(;
20+
DocumenterVitepress.deploydocs(;
2121
repo="github.com/JuliaDataCubes/YAXArrays.jl.git", # this must be the full URL!
22-
target="build", # this is where Vitepress stores its output
22+
target=joinpath(@__DIR__, "build"),
2323
branch = "gh-pages",
2424
devbranch="master",
2525
push_preview = true

docs/src/.vitepress/config.mts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export default defineConfig({
9191
],
9292
// ignoreDeadLinks: true,
9393
vite: {
94+
define: {
95+
__DEPLOY_ABSPATH__: JSON.stringify('REPLACE_ME_DOCUMENTER_VITEPRESS_DEPLOY_ABSPATH'),
96+
},
9497
build: {
9598
assetsInlineLimit: 0, // so we can tell whether we have created inlined images or not, we don't let vite inline them
9699
},

docs/src/UserGuide/compute.md

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,30 @@ note that the following can be extended to arbitrary `YAXArrays` with additional
147147

148148
Let's generate a new `cube` using `mapCube` and saving the output directly into disk.
149149

150+
:::tabs
151+
152+
== xmap (DAE)
153+
154+
````@ansi mapCube
155+
r = f.(lon_yax, lat_yax, time_yax)
156+
````
157+
158+
or as
159+
160+
````@ansi mapCube
161+
r = xmap(f, lon_yax, lat_yax, time_yax, output=XOutput(outtype=Float32), inplace=false)
162+
````
163+
164+
and triggering the computation and saving to `zarr` is done with `compute_to_zarr`:
165+
166+
````@ansi mapCube
167+
gen_cube = compute_to_zarr(Dataset(layer=r), "my_gen_cube.zarr", overwrite=true, max_cache=1e9)
168+
````
169+
170+
note that it takes as input a `Dataset`.
171+
172+
== mapCube
173+
150174
````@ansi mapCube
151175
gen_cube = mapCube(g, (lon_yax, lat_yax, time_yax);
152176
indims = (InDims(), InDims(), InDims("time")),
@@ -163,6 +187,7 @@ Note that currently the `time` axis in the output cube goes first.
163187
:::
164188

165189

190+
166191
Check that it is working
167192

168193
````@ansi mapCube
@@ -233,26 +258,49 @@ end
233258
f1(xin) = xin + 1
234259
f2(xin) = xin + 2
235260
````
261+
262+
````@example outdims
263+
properties_one = Dict{String, Any}("name" => "plus_one")
264+
properties_two = Dict{String, Any}("name" => "plus_two");
265+
nothing # hide
266+
````
267+
268+
:::tabs
269+
270+
== xmap (DAE)
271+
272+
````@example outdims
273+
output_one = XOutput(yax_test.time; properties=properties_one)
274+
output_two = XOutput(yax_test.time; properties=properties_two)
275+
output_flat = XOutput(;)
276+
277+
ds = xmap(one_to_many, yax_test⊘:time,
278+
output=(output_one, output_two, output_flat)
279+
);
280+
nothing # hide
281+
````
282+
283+
== mapCube
284+
236285
now, we define `InDims` and `OutDims`:
237286

238287
````@example outdims
239288
indims_one = InDims("Time")
240289
# outputs dimension
241-
properties_one = Dict{String, Any}("name" => "plus_one")
242-
properties_two = Dict{String, Any}("name" => "plus_two")
243-
244290
outdims_one = OutDims("Time"; properties=properties_one)
245291
outdims_two = OutDims("Time"; properties=properties_two)
246292
outdims_flat = OutDims(;) # it will get the default `layer` name if open as dataset
293+
nothing # hide
247294
````
248-
249295
````@example outdims
250296
ds = mapCube(one_to_many, yax_test,
251297
indims = indims_one,
252298
outdims = (outdims_one, outdims_two, outdims_flat));
253299
nothing # hide
254300
````
255301

302+
:::
303+
256304
let's see the second output
257305

258306
````@example outdims
@@ -278,17 +326,36 @@ function many_to_many(xout_one, xout_two, xout_flat, xin_one, xin_two, xin_drei)
278326
return nothing
279327
end
280328
f2mix(xin_xyt, xin_xy) = xin_xyt - xin_xy
329+
nothing # hide
281330
````
282331

332+
:::tabs
333+
334+
== xmap (DAE)
335+
336+
````@example outdims
337+
output_time = XOutput(yax_test.time)
338+
output_flat = XOutput()
339+
340+
r1, r2, r3 = xmap(many_to_many, yax_test⊘:time, yax_2d, yax_test⊘"time",
341+
output =(output_time, output_time, output_flat), inplace=true);
342+
dsout = Dataset(many_to_many_two=r2)
343+
344+
compute_to_zarr(dsout, "test_mm.zarr", overwrite=true)
345+
````
346+
347+
== mapCube
348+
283349
#### Specify path in OutDims
284350

285351
````@example outdims
286352
indims_one = InDims("Time")
287353
indims_2d = InDims() # ? it matches only to the other 2 dimensions and uses the same values for each time step
288354
properties = Dict{String, Any}("name"=> "many_to_many_two")
289355
outdims_one = OutDims("Time")
290-
outdims_two = OutDims("Time"; path = "test_mm.zarr", properties)
291-
outdims_flat = OutDims()
356+
outdims_two = OutDims("Time"; path = "test_mm.zarr", properties, overwrite=true)
357+
outdims_flat = OutDims();
358+
nothing # hide
292359
````
293360

294361
````@example outdims
@@ -304,6 +371,9 @@ And we can open the one that was saved directly to disk.
304371
ds_mm = open_dataset("test_mm.zarr")
305372
````
306373

374+
:::
375+
376+
307377
### Different InDims names
308378

309379
Here, the goal is to operate at the pixel level (longitude, latitude), and then apply the corresponding function to the extracted values. Consider the following toy cubes:
@@ -322,8 +392,11 @@ and
322392
Random.seed!(123)
323393
data = rand(3.0:5.0, 5, 4, 3)
324394
325-
axlist = (YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-05")),
326-
lon(1:4), lat(1:3),)
395+
axlist = (
396+
YAX.time(Date("2022-01-01"):Day(1):Date("2022-01-05")),
397+
lon(1:4),
398+
lat(1:3),
399+
)
327400
328401
properties = Dict("description" => "multi dimensional test cube")
329402
yax_test = YAXArray(axlist, data, properties)
@@ -345,12 +418,26 @@ end
345418

346419
with the final mapCube operation as follows
347420

421+
:::tabs
422+
423+
== xmap (DAE)
424+
425+
````@example outdims
426+
ds = xmap(mix_time_depth, yax_test ⊘ :time, yax_2d ⊘ :depth,
427+
output = XOutput(yax_test.time), inplace=false)
428+
````
429+
430+
== mapCube
431+
348432
````@example outdims
349433
ds = mapCube(time_depth, (yax_test, yax_2d),
350434
indims = (InDims("Time"), InDims("depth")), # ? anchor dimensions and then map over the others.
351435
outdims = OutDims("Time"))
352436
````
353437

438+
:::
439+
440+
354441
- TODO:
355442
- Example passing additional arguments to function.
356443
- MovingWindow
@@ -463,9 +550,27 @@ end
463550
output[:] .= mean(pixel)
464551
end
465552

553+
````
554+
555+
:::tabs
556+
557+
== xmap (DAE)
558+
559+
````julia
560+
meantime = xmap(mymean, a:time)
561+
# and save!
562+
compute_to_zarr(Dataset(time_mean=meantime), tempname())
563+
````
564+
565+
== mapCube
566+
567+
````julia
466568
mapCube(mymean, a, indims=InDims("time"), outdims=OutDims())
467569
````
468570

571+
:::
572+
573+
469574
In the last example, `mapCube` was used to map the `mymean` function. `mapslices` is a convenient function that can replace `mapCube`, where you can omit defining an extra function with the output argument as an input (e.g. `mymean`). It is possible to simply use `mapslice`
470575

471576
````julia

0 commit comments

Comments
 (0)