Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/DAT/xmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct XOutput{D<:Tuple{Vararg{DD.Dimension}},T}
outtype::T
properties
end
function XOutput(outaxes...; outtype=1,properties=Dict())
function XOutput(outaxes::DD.Dimension...; outtype=1, properties=Dict())
XOutput(outaxes, outtype,properties)
end

Expand Down Expand Up @@ -224,6 +224,8 @@ end
dataeltype(y::YAXArray) = eltype(y.data)
dataeltype(y::DimWindowArray) = eltype(y.data.data)

tupelize(x) = (x,)
tupelize(x::Tuple) = x


function xmap(f, ars::Union{YAXArrays.Cubes.YAXArray,DimWindowArray}...;
Expand All @@ -243,29 +245,23 @@ function xmap(f, ars::Union{YAXArrays.Cubes.YAXArray,DimWindowArray}...;
end

#Create outspecs
if output isa XOutput
output = (output,)
output = tupelize(output)

alloutdims = mapreduce(approxunion!, output, init=[]) do o
o.outaxes
end

allinandoutdims = (unique(DD.basedims((alldims..., alloutdims...)))...,)


outaxinfo = map(output) do o
nout_old = length(o.outaxes)
n_added = -1
r = map(o.outaxes) do ax
ax_indim = DD.dims(alldims,ax)
if isnothing(ax_indim)
n_added += 1
ax, nout_old + length(alldims) + n_added
else
idim = DD.dimnum(alldims,ax)
ax, idim
end
end
outaxes = map(first,r)
dimsmap = map(last,r)
addaxes = DD.otherdims(alldims,DD.basedims(outaxes))
dimsmapadd = setdiff(ntuple(identity,length(alldims)),dimsmap)
outaxes = o.outaxes
addaxes = DD.otherdims(alldims, DD.basedims(outaxes))
outwindows = map(i->[Base.OneTo(length(i))],outaxes)
extrawindows = Base.OneTo.(length.(addaxes))
(outaxes...,addaxes...), (dimsmap...,dimsmapadd...), (outwindows...,extrawindows...)
alloutaxes = (outaxes..., addaxes...)
dimsmap = DD.dimnum(allinandoutdims, alloutaxes)
alloutaxes, tupelize(dimsmap), (outwindows..., extrawindows...)
end
outaxes = map(first,outaxinfo)
dimsmap = map(Base.Fix2(getindex,2),outaxinfo)
Expand Down
16 changes: 8 additions & 8 deletions test/Datasets/datasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ using Dates


## second example
using Downloads
path2file = "https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.nc"
filename = Downloads.download(path2file, "sresa1b_ncar_ccsm3-example.nc")
ds = open_dataset(filename)
f = "./temp.zarr"
savedataset(ds, path=f, driver=:zarr, overwrite=true)
rm(f, recursive=true, force=true)
rm(filename)
# using Downloads
# path2file = "https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.nc"
# filename = Downloads.download(path2file, "sresa1b_ncar_ccsm3-example.nc")
# ds = open_dataset(filename)
# f = "./temp.zarr"
# savedataset(ds, path=f, driver=:zarr, overwrite=true)
# rm(f, recursive=true, force=true)
# rm(filename)

## third example
# using EarthDataLab
Expand Down
Loading