@@ -181,6 +181,7 @@ intervals = MovingIntervals(:open, :closed; left=left_bounds, width=width)
181181
182182# Access the first interval
183183first_interval = intervals[1] # Interval(1, 3)
184+ ```
184185"""
185186struct MovingIntervals{T,O,L,R} <: DD.AbstractBins
186187 i1:: T
@@ -618,7 +619,7 @@ Computes the YAXArrays dataset `ods` and saves it to a Zarr dataset at `path`.
618619- `max_cache`: The maximum amount of data to cache in memory while computing the dataset.
619620- `overwrite`: Whether to overwrite the dataset at `path` if it already exists.
620621"""
621- function compute_to_zarr (ods, path; max_cache= 5e8 ,overwrite= false )
622+ function compute_to_zarr (ods, path; max_cache= 5e8 , custom_loopranges = nothing , overwrite= false )
622623 if ! isa (ods,Dataset)
623624 throw (ArgumentError (" Direct saving of YAXArrays is not supported. Please wrap your array `a` into a Dataset by calling `Dataset(layer=a)`" ))
624625 end
@@ -629,35 +630,49 @@ function compute_to_zarr(ods, path; max_cache=5e8,overwrite=false)
629630 end
630631 rpd = DAE. remove_aliases! (g)
631632 DAE. fuse_graph! (g)
632- op = DAE. gmwop_from_conn (only (g. connections), g. nodes)
633- lr = DAE. optimize_loopranges (op,max_cache)
634-
635- newcubes = map (collect (keys (outnodes))) do k
636- looprange = lr. lr. members
637- lw = op. outspecs[1 ]. lw
638- mylr = DAE. mysub (lw,looprange)
639- newcs = map (mylr,lw. windows. members) do mlr, w
640- map (mlr) do lr
641- DAE. windowmin (w[first (lr)]): DAE. windowmax (w[last (lr)]) |> length
642- end |> chunktype_from_chunksizes
643- end |> GridChunks
644- k=> YAXArrays. Datasets. setchunks (ods. cubes[k],newcs)
645- end
646- newds = Dataset (;newcubes... )
647-
648- emptyds = savedataset (newds,path= path,skeleton= true , overwrite= true )
649- outars = Array {Any} (undef,length (op. outspecs))
650- fill! (outars,nothing )
651- for (k,v) in outnodes
652- v = get (rpd, v, v)
653- outars[v] = emptyds. cubes[k]. data
633+ opinfo = map (g. connections) do conn
634+ op = DAE. gmwop_from_conn (conn, g. nodes)
635+ lr = if custom_loopranges === nothing
636+ DAE. optimize_loopranges (op, max_cache)
637+ else
638+ DAE. custom_loopranges (op, custom_loopranges)
639+ end
640+
641+ newcubes = map (conn. outputids, op. outspecs) do oid, ospec
642+ looprange = lr. lr. members
643+ lw = ospec. lw
644+ mylr = DAE. mysub (lw, looprange)
645+ newcs = map (mylr, lw. windows. members) do mlr, w
646+ map (mlr) do lr
647+ DAE. windowmin (w[first (lr)]): DAE. windowmax (w[last (lr)]) |> length
648+ end |> chunktype_from_chunksizes
649+ end |> GridChunks
650+ k = findfirst (== (oid), outnodes)
651+ if k === nothing
652+ l = findall (== (oid), rpd)
653+ k = findfirst (in (l), outnodes)
654+ end
655+ k => YAXArrays. Datasets. setchunks (ods. cubes[k], newcs)
656+ end
657+ op, lr, newcubes
654658 end
655- runner = if DAE. Distributed. nworkers () > 1
656- DAE. DaggerRunner (op,lr,outars)
657- else
658- DAE. LocalRunner (op,lr,outars)
659+
660+ newds = Dataset (; reduce (vcat, last .(opinfo))... )
661+
662+ emptyds = savedataset (newds, path= path, skeleton= true , overwrite= overwrite)
663+
664+ for (op, lr, newcubes) in opinfo
665+
666+ outars = map (newcubes) do (k, _)
667+ emptyds. cubes[k]. data
668+ end
669+ runner = if DAE. Distributed. nworkers () > 1
670+ DAE. DaggerRunner (op, lr, outars)
671+ else
672+ DAE. LocalRunner (op, lr, outars)
673+ end
674+ run (runner)
659675 end
660- run (runner)
661676 emptyds
662677end
663678
0 commit comments