From 01a77f09cea26bcc0f85afe9032cc9b3e38a201b Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 5 Sep 2023 11:39:34 +0200 Subject: [PATCH 1/9] Replace subsetcube in tutorial with getindex --- docs/examples/UserGuide/examples_from_esdl_study_1.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/examples/UserGuide/examples_from_esdl_study_1.jl b/docs/examples/UserGuide/examples_from_esdl_study_1.jl index c2240d63..f856ea20 100644 --- a/docs/examples/UserGuide/examples_from_esdl_study_1.jl +++ b/docs/examples/UserGuide/examples_from_esdl_study_1.jl @@ -46,6 +46,7 @@ vars = ["gross_primary_productivity", "air_temperature_2m", "surface_moisture"] time_overlap = Date("2001-01-01")..Date("2020-12-31") # So we "virtually get" the cube data virtually: +cube_subset = cube_handle[Variable=At(vars), time=At(time_overlap)] cube_subset = subsetcube(cube_handle, variable=vars, time=time_overlap) # The next function estimates the median seasonal cycle. This changes the dimension of the cube, as the time domain is replaced by day of year (doy); Eq. 9 in the manuscript: From b1c7cf98f7162c348e41be239008900fc10e9e7f Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 5 Sep 2023 14:18:21 +0200 Subject: [PATCH 2/9] Delete getCubeDes This is not used anymore, because the show methods of DimensionalData are used. --- src/Cubes/Cubes.jl | 4 ---- src/Cubes/Slices.jl | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index 41f956d8..018127f4 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -496,10 +496,6 @@ end cubesize(c::YAXArray{T}) where {T} = (sizeof(T)) * prod(map(length, caxes(c))) cubesize(::YAXArray{T,0}) where {T} = sizeof(T) -getCubeDes(::DD.Dimension) = "Cube axis" -getCubeDes(::YAXArray) = "YAXArray" -getCubeDes(::Type{T}) where {T} = string(T) - function DD.show_after(io::IO,mime, c::YAXArray) foreach(getattributes(c)) do p if p[1] in ("labels", "name", "units") diff --git a/src/Cubes/Slices.jl b/src/Cubes/Slices.jl index 5a0097fd..36390fff 100644 --- a/src/Cubes/Slices.jl +++ b/src/Cubes/Slices.jl @@ -36,8 +36,7 @@ function getdata(x::YAXSlice) PickAxisArray(x.c.data, m) end -getCubeDes(s::YAXSlice) = - string(join(axname.(s.sliceaxes[2]), " x "), " slices over an ", getCubeDes(s.c)) + cubesize(s::YAXSlice) = cubesize(s.c) Base.ndims(::YAXSlice{<:Any,N}) where {N} = N From 539516df8c90cded397aaf7df6682f0da4da18e9 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 5 Sep 2023 14:23:28 +0200 Subject: [PATCH 3/9] Remove commented interpretsubset --- src/Cubes/Cubes.jl | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index 018127f4..577b476e 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -406,24 +406,6 @@ end sorted(x, y) = x < y ? (x, y) : (y, x) -#TODO move everything that is subset-related to its own file or to axes.jl -#= -interpretsubset(subexpr::Union{CartesianIndices{1},LinearIndices{1}}, ax) = - subexpr.indices[1] -interpretsubset(subexpr::CartesianIndex{1}, ax) = subexpr.I[1] -interpretsubset(subexpr, ax) = axVal2Index(ax, subexpr, fuzzy=true) -function interpretsubset(subexpr::NTuple{2,Any}, ax) - x, y = sorted(subexpr...) - Colon()(sorted(axVal2Index_lb(ax, x), axVal2Index_ub(ax, y))...) -end -interpretsubset(subexpr::NTuple{2,Int}, ax::RangeAxis{T}) where {T<:TimeType} = - interpretsubset(map(T, subexpr), ax) -interpretsubset(subexpr::UnitRange{<:Integer}, ax::RangeAxis{T}) where {T<:TimeType} = - interpretsubset(T(first(subexpr)) .. T(last(subexpr) + 1), ax) -interpretsubset(subexpr::Interval, ax) = interpretsubset((subexpr.left, subexpr.right), ax) -interpretsubset(subexpr::AbstractVector, ax::CategoricalAxis) = - axVal2Index.(Ref(ax), subexpr, fuzzy=true) -=# function _subsetcube(z, subs; kwargs...) kwargs = Dict{Any,Any}(kwargs) From f24bed709d06e58a5c6c04be9f9442adc5b965b1 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 5 Sep 2023 14:24:13 +0200 Subject: [PATCH 4/9] Remove old renameaxis code --- src/Cubes/Cubes.jl | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index 577b476e..b84410de 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -378,24 +378,6 @@ _iscompressed(c) = YAXArrayBase.iscompressed(c) # lift renameaxis functionality from Axes.jl to YAXArrays renameaxis!(c::YAXArray, p::Pair) = DD.set(c, Symbol(first(p)) => last(p)) -#= -function renameaxis!(c::YAXArray, p::Pair) - #This needs to be deleted, because DimensionalData cannot update the axlist - # Because this is a tuple instead of a vector - axlist = caxes(c) - i = findAxis(p[1], axlist) - axlist[i] = renameaxis(axlist[i], p[2]) - c -end -function renameaxis!(c::YAXArray, p::Pair{<:Any,<:CubeAxis}) - i = findAxis(p[1], caxes(c)) - i === nothing && throw(ArgumentError("$(p[1]) Axis not found")) - length(caxes(c)[i].values) == length(p[2].values) || - throw(ArgumentError("Length of replacement axis must equal length of old axis")) - caxes(c)[i] = p[2] - c -end -=# function _subsetcube end function subsetcube(z::YAXArray{T}; kwargs...) where {T} From 41d5aaa5d02238579d4468aa1f61e410d9b733be Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 5 Sep 2023 14:24:41 +0200 Subject: [PATCH 5/9] Remove commented getindex --- src/Cubes/Cubes.jl | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index b84410de..bc0e920a 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -259,16 +259,6 @@ cubechunks(c) = approx_chunksize(eachchunk(c)) DiskArrays.eachchunk(c::YAXArray) = c.chunks getindex_all(a) = getindex(a, ntuple(_ -> Colon(), ndims(a))...).data -#= -function Base.getindex(x::YAXArray, i...) - if length(i)==1 && istable(first(i)) - batchextract(x,first(i)) - else - getdata(x)[i...] - end -end -=# - function batchextract(x,i) # This function should be documented and moved to DimensionalData From fd275b6919e994d09855ea891f216544d969d680 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 5 Sep 2023 14:25:26 +0200 Subject: [PATCH 6/9] Remove commented Axes module definition --- src/Cubes/Cubes.jl | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index bc0e920a..d9d3900f 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -27,31 +27,6 @@ function subsetcube end "Returns the axes of a Cube" function caxes end -# TODO: Give Axes an own module in YAXArrays -#= -include("Axes.jl") -using .Axes: - CubeAxis, - RangeAxis, - CategoricalAxis, - findAxis, - getAxis, - axVal2Index, - axname, - axsym, - axVal2Index_lb, - axVal2Index_ub, - renameaxis, - axcopy - -""" -The `Axes` module handles the Axes of a data cube. -It provides the following exports: - -$(EXPORTS) -""" -Axes -=# """ mutable struct CleanMe From 37b063e5063dbfe65859d1ce0665cdffff5cdea6 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 5 Sep 2023 14:28:19 +0200 Subject: [PATCH 7/9] Remove commented imports of Axes module --- src/DAT/DAT.jl | 2 - src/DAT/dciterators.jl | 1 - src/DAT/registration.jl | 1 - src/DAT/tablestats.jl | 1 - src/DatasetAPI/Datasets.jl | 1 - test/Cubes/axes.jl | 108 ------------------------------------- test/Datasets/datasets.jl | 3 -- test/runtests.jl | 1 - 8 files changed, 118 deletions(-) delete mode 100644 test/Cubes/axes.jl diff --git a/src/DAT/DAT.jl b/src/DAT/DAT.jl index 0cd04a05..29334280 100644 --- a/src/DAT/DAT.jl +++ b/src/DAT/DAT.jl @@ -18,8 +18,6 @@ using Distributed: import ..Cubes: cubechunks, iscompressed, chunkoffset, YAXArray, caxes, YAXSlice import ..Cubes: cubechunks, iscompressed, chunkoffset, YAXArray, caxes, YAXSlice import ..YAXArrays: findAxis, getOutAxis, getAxis -#import ..Cubes.Axes: -# AxisDescriptor, axname, ByInference, axsym, getOutAxis, getAxis, findAxis, match_axis import ..Datasets: Dataset, createdataset using ..YAXArrays: ByInference, YAXArrays import ...YAXArrays.workdir diff --git a/src/DAT/dciterators.jl b/src/DAT/dciterators.jl index 3a7a38a2..c9f9de5f 100644 --- a/src/DAT/dciterators.jl +++ b/src/DAT/dciterators.jl @@ -1,6 +1,5 @@ import YAXArrays.DAT: DATConfig import YAXArrays.YAXTools: PickAxisArray -#using YAXArrays.Cubes.Axes: axcopy using DiskArrays: GridChunks, AbstractDiskArray using Tables: Tables, Schema, AbstractColumns diff --git a/src/DAT/registration.jl b/src/DAT/registration.jl index 79c60cb1..793052f6 100644 --- a/src/DAT/registration.jl +++ b/src/DAT/registration.jl @@ -1,5 +1,4 @@ export InDims, OutDims, MovingWindow -#using ..Cubes.Axes: get_descriptor, findAxis, Axes import ..YAXArrays: get_descriptor, findAxis, AxisDescriptor using ..YAXArrays: YAXDefaults using YAXArrayBase: yaxcreate diff --git a/src/DAT/tablestats.jl b/src/DAT/tablestats.jl index 6d11ee38..e7a88365 100644 --- a/src/DAT/tablestats.jl +++ b/src/DAT/tablestats.jl @@ -1,5 +1,4 @@ import OnlineStats: OnlineStat, Extrema, fit!, value, HistogramStat, Ash -#import ...Cubes.Axes: CategoricalAxis, RangeAxis import IterTools using WeightedOnlineStats using Distributed: nworkers diff --git a/src/DatasetAPI/Datasets.jl b/src/DatasetAPI/Datasets.jl index ffaad506..8f816f4a 100644 --- a/src/DatasetAPI/Datasets.jl +++ b/src/DatasetAPI/Datasets.jl @@ -1,5 +1,4 @@ module Datasets -#import ..Cubes.Axes: axsym, axname, CubeAxis, findAxis, CategoricalAxis, RangeAxis, caxes import ..Cubes: Cubes, YAXArray, concatenatecubes, CleanMe, subsetcube, copy_diskarray, setchunks, caxes using ...YAXArrays: YAXArrays, YAXDefaults, findAxis using DataStructures: OrderedDict, counter diff --git a/test/Cubes/axes.jl b/test/Cubes/axes.jl deleted file mode 100644 index d539e3b2..00000000 --- a/test/Cubes/axes.jl +++ /dev/null @@ -1,108 +0,0 @@ -@testset "Axes" begin - - using Dates - using YAXArrays.Cubes.Axes: - axVal2Index, axVal2Index_lb, axVal2Index_ub, findAxis, axname, axsym, renameaxis - using YAXArrayBase: dimname, dimvals, iscontdim - - axestotest = [ - (CategoricalAxis, "CatAxis", ["One", "Two", "Three"], nothing), - (RangeAxis, "IntRange", 1:10, 1), - (RangeAxis, "FloatRange", 1.0:-0.1:0.1, 0.1), - ( - RangeAxis, - "MonthTimeRange", - Date(2001, 1, 1):Month(1):Date(2002, 12, 31), - Day(30), - ), - ( - RangeAxis, - "DayTimeRange", - DateTime(2002, 1, 1):Day(1):DateTime(2002, 1, 31), - Hour(24), - ), - (RangeAxis, "Single_IntRange", 1:1, 0), - - #This is currently not used, because we need to design, how this should behave. - ( - RangeAxis, - "IrregularTimeAxis", - [DateTime("2016-10-03T10:12:28"), DateTime("2016-10-15T10:12:28"), - DateTime("2016-10-27T10:12:28"), DateTime("2016-11-08T10:12:28"), - DateTime("2016-11-20T10:12:28"), DateTime("2016-12-02T10:12:28"), - DateTime("2016-12-14T10:12:27"), DateTime("2016-12-26T10:12:27"), - DateTime("2017-01-07T10:12:25"), DateTime("2017-01-19T10:12:25"), - DateTime("2017-01-31T10:12:25"), DateTime("2017-02-24T10:12:24")], - Day(1) - ), - (RangeAxis, "PureArray", [0.0, 0.2, 0.4, 0.6], 0.2), - (CategoricalAxis, "CatAxis", ["One", "Two", "Three", "Four", "Five", - "Six", "Seven", "Eight", "Nine", "Ten", "Eleven"], nothing), - ] - - for (axt, axn, axv, axstep) in axestotest - ax = axt(axn, axv) - @test size(ax) == size(axv) - @test size(ax, 1) == size(axv, 1) - @test ndims(ax) == 1 - @test length(ax) == length(axv) - ax2 = YAXArrays.Cubes.Axes.axcopy(ax, axv) - ax3 = YAXArrays.Cubes.Axes.axcopy(ax) - @test typeof(ax2) == typeof(ax) - @test ax2.values == ax.values - @test typeof(ax3) == typeof(ax) - @test ax3.values == ax.values - b = IOBuffer() - show(b, ax) - @test caxes(ax) == [ax] - @test YAXArrays.Cubes.Axes.axname(ax) == axn - @test YAXArrays.Cubes.Axes.axname(typeof(ax)) == axn - @test YAXArrays.Cubes.axsym(ax) == Symbol(axn) - @test dimname(ax, 1) == axn - @test dimvals(ax, 1) == axv - #Test axVal2Index separately - if ax isa CategoricalAxis - for (i, v) in enumerate(axv) - @test axVal2Index(ax, v) == i - @test axVal2Index(ax, v[1:2], fuzzy=true) == i - end - @test iscontdim(ax, 1) == false - else - for (i, v) in enumerate(axv) - @test axVal2Index(ax, v) == i - #@test axVal2Index_ub(ax, v + axstep / 2, fuzzy = true) == i - #@test axVal2Index_lb(ax, v - axstep / 2, fuzzy = true) == i - end - @test iscontdim(ax, 1) == true - end - ax3 = renameaxis(ax, "Test") - ax4 = renameaxis(ax, :Test) - @test axname(ax3) == "Test" - @test axsym(ax3) == :Test - - # test getindex method - for i in eachindex(axv) - @test ax[i] == axv[i] - end - end - axlist = map(i -> i[1](i[2], i[3]), axestotest) - @test findAxis("Int", axlist) == 2 - @test findAxis(RangeAxis("FloatRange", 1.0:-0.1:0.1), axlist) == 3 - @test getAxis(RangeAxis("FloatRange", 1.0:-0.1:0.1), axlist) == - RangeAxis("FloatRange", 1.0:-0.1:0.1) - #Test whether multiple axes with same name throw an error - @test_throws ErrorException findAxis("CatAxis", axlist) - - multiplevalax = CategoricalAxis("MultVal", ["One", "Two", "One"]) - @test_throws ErrorException axVal2Index(multiplevalax, "one", fuzzy=true) - @testset "Hashtests" begin - catax = CategoricalAxis("Catax", [1, 2]) - catay = CategoricalAxis("Catay", [1, 2]) - catax2 = CategoricalAxis("Catax", [2, 2]) - cataxfloat = CategoricalAxis("Catax", [1.0, 2.0]) - @test hash(catax) == hash(cataxfloat) - @test hash(catax) != hash(catay) - @test hash(catax) != hash(catax2) - end - -end diff --git a/test/Datasets/datasets.jl b/test/Datasets/datasets.jl index 4e9ccef5..25389630 100644 --- a/test/Datasets/datasets.jl +++ b/test/Datasets/datasets.jl @@ -142,16 +142,13 @@ using Dates @testset "collectdims" begin dcollect = YAXArrays.Datasets.collectdims(m) @test dcollect["time"].ax isa DD.Dimension - #@test YAXArrays.Cubes.Axes.axname(dcollect["time"].ax) == "time" @test DD.lookup(dcollect["time"].ax) == DateTime(2001, 1, 4):Day(1):DateTime(2001, 1, 13) @test dcollect["time"].offs == 2 @test dcollect["d2"].ax isa DD.Dimension - #@test YAXArrays.Cubes.Axes.axname(dcollect["d2"].ax) == "d2" @test DD.lookup(dcollect["d2"].ax) == 0.1:0.1:0.5 @test dcollect["d2"].offs == 0 @test dcollect["d3"].ax isa DD.Dimension - #@test YAXArrays.Cubes.Axes.axname(dcollect["d3"].ax) == "d3" @test DD.lookup(dcollect["d3"].ax) == ["One", "Two"] @test dcollect["d3"].offs == 0 a1 = [0.1, 0.2, 0.3, 0.4] diff --git a/test/runtests.jl b/test/runtests.jl index 4154c968..914db4d0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,7 +7,6 @@ using YAXArrayBase @run_package_tests include("tools.jl") -#include("Cubes/axes.jl") include("Cubes/cubes.jl") include("Cubes/transformedcubes.jl") include("Cubes/batchextraction.jl") From dfb8ed3a2d066915554b0311d1c78c4160832960 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 6 Sep 2023 15:16:26 +0200 Subject: [PATCH 8/9] Remove usage of subsetcube from docs --- docs/examples/UserGuide/examples_from_esdl_study_1.jl | 3 +-- docs/src/tutorials/intro.jl | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/examples/UserGuide/examples_from_esdl_study_1.jl b/docs/examples/UserGuide/examples_from_esdl_study_1.jl index f856ea20..d89b8c21 100644 --- a/docs/examples/UserGuide/examples_from_esdl_study_1.jl +++ b/docs/examples/UserGuide/examples_from_esdl_study_1.jl @@ -46,8 +46,7 @@ vars = ["gross_primary_productivity", "air_temperature_2m", "surface_moisture"] time_overlap = Date("2001-01-01")..Date("2020-12-31") # So we "virtually get" the cube data virtually: -cube_subset = cube_handle[Variable=At(vars), time=At(time_overlap)] -cube_subset = subsetcube(cube_handle, variable=vars, time=time_overlap) +cube_subset = cube_handle[Variable=At(vars), time=time_overlap] # The next function estimates the median seasonal cycle. This changes the dimension of the cube, as the time domain is replaced by day of year (doy); Eq. 9 in the manuscript: # $$ diff --git a/docs/src/tutorials/intro.jl b/docs/src/tutorials/intro.jl index 6561002a..7ad68833 100644 --- a/docs/src/tutorials/intro.jl +++ b/docs/src/tutorials/intro.jl @@ -3,6 +3,7 @@ # In this tutorial we will explore the features of the YAXArrays package. using YAXArrays, EarthDataLab, Zarr, NetCDF +using DimensionalData: Where # ## Use data larger than RAM# # @@ -19,8 +20,10 @@ c = esdc(res="low") # ## Subsets happen lazily -europe = subsetcube(c, region="Europe", time=2000:2016, - Variable=["air_temperature_2m", "net_ecosystem", "soil_moisture"]) - plot(europe.time.values,europe[Variable="air_temperature_2m", lat=50, lon=11].data) +europe = c[region="Europe", time=2000:2016, + Variable=Where( x-> any(contains.((x,),["air_temperature_2m", "net_ecosystem", "moisture"])))] + + +plot(lookup(europe, Ti).data,europe[Variable=At("air_temperature_2m"), lat=50, lon=11].data) From 95e776016995538b9ff4786c3db5897ea0281ff8 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 6 Sep 2023 15:36:32 +0200 Subject: [PATCH 9/9] Remove subsetcube function This function is not used anymore, because the indexing is now handled in DimensionalData. --- src/Cubes/Cubes.jl | 49 ++------------------------------------ src/DatasetAPI/Datasets.jl | 3 +-- test/Cubes/cubes.jl | 25 +------------------ 3 files changed, 4 insertions(+), 73 deletions(-) diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index d9d3900f..706bcbf2 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -17,12 +17,8 @@ using Tables: istable, schema, columns using DimensionalData: DimensionalData as DD, AbstractDimArray, NoName import DimensionalData: name -export concatenatecubes, caxes, subsetcube, readcubedata, renameaxis!, YAXArray, setchunks +export concatenatecubes, caxes, readcubedata, renameaxis!, YAXArray, setchunks -""" -This function calculates a subset of a cube's data -""" -function subsetcube end "Returns the axes of a Cube" function caxes end @@ -340,53 +336,12 @@ _iscompressed(c::DiskArrays.PermutedDiskArray) = _iscompressed(c.a.parent) _iscompressed(c::DiskArrays.SubDiskArray) = _iscompressed(c.v.parent) _iscompressed(c) = YAXArrayBase.iscompressed(c) -# lift renameaxis functionality from Axes.jl to YAXArrays +# lift renameaxis functionality from DimensionalData to YAXArrays renameaxis!(c::YAXArray, p::Pair) = DD.set(c, Symbol(first(p)) => last(p)) -function _subsetcube end - -function subsetcube(z::YAXArray{T}; kwargs...) where {T} - newaxes, substuple = _subsetcube(z, collect(Any, map(Base.OneTo, size(z))); kwargs...) - newdata = view(getdata(z), substuple...) - YAXArray(newaxes, newdata, z.properties, cleaner=z.cleaner) -end - sorted(x, y) = x < y ? (x, y) : (y, x) -function _subsetcube(z, subs; kwargs...) - kwargs = Dict{Any,Any}(kwargs) - for f in YAXDefaults.subsetextensions - f(kwargs) - end - newaxes = deepcopy(collect(DD.Dimension, caxes(z))) - foreach(kwargs) do kw - axdes, subexpr = kw - axdes = string(axdes) - iax = findAxis(axdes, caxes(z)) - if isa(iax, Nothing) - throw(ArgumentError("Axis $axdes not found in cube")) - else - oldax = newaxes[iax] - subinds = interpretsubset(subexpr, oldax) - subs2 = subs[iax][subinds] - subs[iax] = subs2 - if !isa(subinds, AbstractVector) && !isa(subinds, AbstractRange) - newaxes[iax] = axcopy(oldax, oldax.values[subinds:subinds]) - else - newaxes[iax] = axcopy(oldax, oldax.values[subinds]) - end - end - end - substuple = ntuple(i -> subs[i], length(subs)) - inewaxes = findall(i -> isa(i, AbstractVector), substuple) - newaxes = newaxes[inewaxes] - @assert length.(newaxes) == - map(length, filter(i -> isa(i, AbstractVector), collect(substuple))) - newaxes, substuple -end - - function Base.getindex(a::YAXArray, args::DD.Dimension...; kwargs...) kwargsdict = Dict(kwargs...) for ext in YAXDefaults.subsetextensions diff --git a/src/DatasetAPI/Datasets.jl b/src/DatasetAPI/Datasets.jl index 8f816f4a..5d7493e4 100644 --- a/src/DatasetAPI/Datasets.jl +++ b/src/DatasetAPI/Datasets.jl @@ -1,5 +1,5 @@ module Datasets -import ..Cubes: Cubes, YAXArray, concatenatecubes, CleanMe, subsetcube, copy_diskarray, setchunks, caxes +import ..Cubes: Cubes, YAXArray, concatenatecubes, CleanMe, copy_diskarray, setchunks, caxes using ...YAXArrays: YAXArrays, YAXDefaults, findAxis using DataStructures: OrderedDict, counter using Dates: Day, Hour, Minute, Second, Month, Year, Date, DateTime, TimeType, AbstractDateTime @@ -326,7 +326,6 @@ function open_dataset(g; driver = :all) sdimlist = Dict(Symbol(k) => v.ax for (k, v) in dimlist) Dataset(allcubes, sdimlist,gatts) end -#Base.getindex(x::Dataset; kwargs...) = subsetcube(x; kwargs...) YAXDataset(; kwargs...) = Dataset(YAXArrays.YAXDefaults.cubedir[]; kwargs...) diff --git a/test/Cubes/cubes.jl b/test/Cubes/cubes.jl index 3abb53f7..a8e6b490 100644 --- a/test/Cubes/cubes.jl +++ b/test/Cubes/cubes.jl @@ -94,28 +94,5 @@ using DimensionalData @test a2.properties == Dict("att" => 5) @test YAXArrayBase.iscompressed(a) == false end -#= - @testset "Subsets" begin - s = YAXArrays.Cubes.subsetcube(a, X = 1.5..3.5) - @test s.data == [2 6 10 14 18; 3 7 11 15 19] - @test s.axes[1] == X(2.0:3.0) - @test s.axes[2] == Y([1, 2, 3, 4, 5]) - ax = a.axes[1] - @test YAXArrays.Cubes.interpretsubset(CartesianIndices((1:2,)), ax) == 1:2 - @test YAXArrays.Cubes.interpretsubset(CartesianIndex((2,)), ax) == 2 - @test YAXArrays.Cubes.interpretsubset(2.1, ax) == 2 - @test YAXArrays.Cubes.interpretsubset((3.5, 1.5), ax) == 2:3 - @test YAXArrays.Cubes.interpretsubset(0.8..2.2, ax) == 1:2 - tax = RangeAxis("ADate", Date(2001):Day(1):Date(2003, 2, 28)) - @test YAXArrays.Cubes.interpretsubset((Date(2001, 1, 2), Date(2001, 1, 5)), tax) == - 2:4 - @test YAXArrays.Cubes.interpretsubset(2001:2002, tax) == 1:730 - @test YAXArrays.Cubes.interpretsubset([1, 3, 5], a.axes[2]) == [1, 3, 5] - s2 = a[X = 0.5..3.5, Y = [1, 5, 4]] - @test s2.data == [1 17 13; 2 18 14; 3 19 15] - @test s2.axes[1] == X(1.0:3.0) - @test s2.axes[2] == Y([1, 5, 4]) - end -=# -end +end \ No newline at end of file