Skip to content

Commit

Permalink
use CommonDataModel.Dimensions for SubDimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Oct 29, 2023
1 parent ce14b6e commit 30130a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
21 changes: 10 additions & 11 deletions src/subvariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,31 +114,30 @@ Base.setindex!(v::SubVariable,data,indices::CartesianIndices) =



dimnames(ds::SubDataset) = dimnames(ds.ds)
defDim(ds::SubDataset,name::SymbolOrString,len) = defDim(ds.ds,name,len)



Base.keys(ds::SubDimensions) = keys(ds.dim)

function Base.getindex(sd::SubDimensions,dimname)
function dim(ds::SubDataset,dimname::SymbolOrString)
dn = Symbol(dimname)
if hasproperty(sd.indices,dn)
ind = getproperty(sd.indices,dn)
if hasproperty(ds.indices,dn)
ind = getproperty(ds.indices,dn)
if ind == Colon()
return sd.dim[dimname]
return ds.ds.dim[dimname]
else
return length(ind)
end
else
return sd.dim[dimname]
return ds.ds.dim[dimname]
end
end

unlimited(sd::SubDimensions) = unlimited(sd.dim)
unlimited(ds::SubDataset) = unlimited(ds.ds)


function SubDataset(ds::AbstractNCDataset,indices)
dim = SubDimensions(ds.dim,indices)
group = OrderedDict((n => SubDataset(g,indices) for (n,g) in ds.group)...)
SubDataset(ds,indices,dim,ds.attrib,group)
SubDataset(ds,indices,ds.attrib,group)
end

function Base.view(ds::AbstractNCDataset; indices...)
Expand Down
9 changes: 1 addition & 8 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,9 @@ struct SubVariable{T,N,TA,TI,TAttrib,TV} <: AbstractNCVariable{T,N}
var::TV
end

struct SubDataset{TD,TI,TDIM,TA,TG} <: AbstractNCDataset
struct SubDataset{TD,TI,TA,TG} <: AbstractNCDataset
ds::TD
indices::TI
dim::TDIM
attrib::TA
group::TG
end


struct SubDimensions{TD,TI} <: AbstractDimensions
dim::TD
indices::TI
end

0 comments on commit 30130a2

Please sign in to comment.