Skip to content

Commit a0f5246

Browse files
meggartfelixcremer
andauthored
Fixes for EarthDataLab tests (#282)
* Allow some niceties when subsetting * Dont wrap yaxarrays into yaxarrays * fix zarr output * Changes to cubetable --------- Co-authored-by: Felix Cremer <[email protected]> Co-authored-by: Fabian Gans <[email protected]>
1 parent 1d1e1ab commit a0f5246

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

src/Cubes/Cubes.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Data types that
55
module Cubes
66
using DiskArrays: DiskArrays, eachchunk, approx_chunksize, max_chunksize, grid_offset, GridChunks
77
using Distributed: myid
8-
using Dates: TimeType
8+
using Dates: TimeType, Date
99
using IntervalSets: Interval, (..)
1010
using Base.Iterators: take, drop
11-
using ..YAXArrays: workdir, YAXDefaults, findAxis
11+
using ..YAXArrays: workdir, YAXDefaults, findAxis, getAxis
1212
using YAXArrayBase: YAXArrayBase, iscompressed, dimnames, iscontdimval
1313
import YAXArrayBase: getattributes, iscontdim, dimnames, dimvals, getdata
1414
using DiskArrayTools: CFDiskArray
@@ -254,7 +254,7 @@ of this chunking, use `savecube` on the resulting array. The `chunks` argument c
254254
setchunks(c::YAXArray,chunks) = YAXArray(c.axes,c.data,c.properties,interpret_cubechunks(chunks,c),c.cleaner)
255255
cubechunks(c) = approx_chunksize(eachchunk(c))
256256
DiskArrays.eachchunk(c::YAXArray) = c.chunks
257-
getindex_all(a) = getindex(a, ntuple(_ -> Colon(), ndims(a))...)
257+
getindex_all(a) = getindex(a, ntuple(_ -> Colon(), ndims(a))...).data
258258

259259
#=
260260
function Base.getindex(x::YAXArray, i...)
@@ -455,7 +455,29 @@ function _subsetcube(z, subs; kwargs...)
455455
end
456456

457457

458-
Base.getindex(a::YAXArray, args::DD.Dimension...; kwargs...) = view(a, args...; kwargs...)
458+
function Base.getindex(a::YAXArray, args::DD.Dimension...; kwargs...)
459+
kwargsdict = Dict(kwargs...)
460+
for ext in YAXDefaults.subsetextensions
461+
ext(kwargsdict)
462+
end
463+
d2 = Dict()
464+
for (k,v) in kwargsdict
465+
d = getAxis(k,a)
466+
if d !== nothing
467+
if d isa DD.Ti
468+
if v isa UnitRange{Int}
469+
v = Date(first(v))..Date(last(v),12,31)
470+
end
471+
d2[:Ti] = v
472+
else
473+
d2[DD.name(d)] = v
474+
end
475+
else
476+
d2[k] = v
477+
end
478+
end
479+
view(a, args...; d2...)
480+
end
459481

460482
Base.read(d::YAXArray) = getindex_all(d)
461483

@@ -474,6 +496,7 @@ cubesize(::YAXArray{T,0}) where {T} = sizeof(T)
474496
getCubeDes(::DD.Dimension) = "Cube axis"
475497
getCubeDes(::YAXArray) = "YAXArray"
476498
getCubeDes(::Type{T}) where {T} = string(T)
499+
477500
function DD.show_after(io::IO,mime, c::YAXArray)
478501
foreach(getattributes(c)) do p
479502
if p[1] in ("labels", "name", "units")

src/DAT/dciterators.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ function CubeTable(; expandaxes = (), cubes...)
147147
axn = filter(collect(expandaxes)) do ax
148148
findAxis(ax, i) !== nothing
149149
end
150-
foreach(j -> push!(inaxnames, DD.name(getAxis(j, i))), axn)
150+
foreach(j -> push!(inaxnames, string(DD.name(getAxis(j, i)))), axn)
151151
InDims(axn...)
152152
end
153153
end
154-
axnames = map(i -> DD.name.(caxes(i)), c)
154+
axnames = map(i -> string.(DD.name.(caxes(i))), c)
155155
foreach(1:length(axnames)) do i
156156
otheraxes = axnames[[1:i-1;i+1:length(axnames)]]
157157
if !isempty(otheraxes) && isempty(intersect(axnames[i], union(otheraxes...)))
@@ -160,7 +160,6 @@ function CubeTable(; expandaxes = (), cubes...)
160160
end
161161
allvars = union(axnames...)
162162
allnums = collect(1:length(allvars))
163-
164163
configiter =
165164
mapCube(identity, c, debug = true, indims = indims, outdims = (), ispar = false)
166165
# if inax !== nothing

src/DAT/tablestats.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,11 @@ function getStatOutAxes(tab, agg, ::Type{<:WeightedCovMatrix})
180180
s = varsym(agg)
181181
icube = findfirst(isequal(s), varn)
182182
ax = tab.dc.incubes[icube].axesSmall[1]
183-
oldname = YAXArrays.Cubes.Axes.axname(ax)
183+
oldname = DD.name(ax)
184184
coname = string("Co", oldname)
185-
v = ax.values
186-
axtype = axt(ax)
187-
a1 = axtype(oldname, copy(v))
188-
a2 = axtype(coname, copy(v))
185+
v = ax.val
186+
a1 = DD.Dim{oldname}(copy(v))
187+
a2 = DD.Dim{Symbol(coname)}(copy(v))
189188
(a1, a2)
190189
end
191190
function getStatOutAxes(tab,agg,::Type{<:Union{Ash,HistogramStat, WeightedAdaptiveHist}})

src/DatasetAPI/Datasets.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ function savedataset(
562562
chunkoffset = [alloffsets[k] for k in keys(ds.axes)]
563563
axdata = arrayfromaxis.(axesall, chunkoffset)
564564

565+
565566

566567
dshandle = if ispath(path)
567568
# We go into append mode
@@ -734,7 +735,7 @@ function createdataset(
734735
if hasmissings
735736
v = CFDiskArray(v, attr)
736737
end
737-
YAXArray(axlist, v, propfromattr(attr), cleaner = cleaner)
738+
YAXArray((axlist...,), v, propfromattr(attr), cleaner = cleaner)
738739
end
739740
if groupaxis === nothing
740741
return allcubes[1], allcubes[1]
@@ -804,7 +805,7 @@ function createdataset(
804805
# function dataattfromaxis(ax::CubeAxis,n)
805806
# prependrange(1:length(ax.values),n), Dict{String,Any}("_ARRAYVALUES"=>collect(ax.values))
806807
# end
807-
function dataattfromaxis(ax::DD.Dimensions.Ti, n, T::Type{<:TimeType})
808+
function dataattfromaxis(ax::DD.Dimension, n, T::Type{<:TimeType})
808809
data = timeencode(datetodatetime(DD.lookup(ax)), "days since 1980-01-01", defaultcal(T))
809810
prependrange(data, n),
810811
Dict{String,Any}("units" => "days since 1980-01-01", "calendar" => defaultcal(T))

0 commit comments

Comments
 (0)