Skip to content

Commit

Permalink
use CommonDataModel.Attributes for DeferAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Oct 27, 2023
1 parent 314087e commit c1449e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
24 changes: 12 additions & 12 deletions src/defer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function metadata(ds::NCDataset)
end


function DeferDataset(r::Resource,groupname::String,attrib::DeferAttributes,dim::DeferDimensions,group::DeferGroups,data::OrderedDict)
function DeferDataset(r::Resource,groupname::String,dim::DeferDimensions,group::DeferGroups,data::OrderedDict)
_boundsmap = nothing
dds = DeferDataset(r,groupname,attrib,dim,group,data,_boundsmap)
dds = DeferDataset(r,groupname,dim,group,data,_boundsmap)
if (r.mode == "r")
initboundsmap!(dds)
end
Expand All @@ -65,10 +65,9 @@ function DeferDataset(filename,mode,info)
NCDataset(filename,mode) do ds
r = Resource(filename,mode,info)
groupname = "/"
da = DeferAttributes(r,"/",r.metadata["attrib"])
dd = DeferDimensions(r,r.metadata["dim"])
dg = DeferGroups(r,r.metadata["group"])
return DeferDataset(r,groupname,da,dd,dg,info)
return DeferDataset(r,groupname,dd,dg,info)
end
end

Expand All @@ -77,10 +76,9 @@ function DeferDataset(filename,mode = "r")
info = metadata(ds)
r = Resource(filename,mode,info)
groupname = "/"
da = DeferAttributes(r,"/",r.metadata["attrib"])
dd = DeferDimensions(r,r.metadata["dim"])
dg = DeferGroups(r,r.metadata["group"])
return DeferDataset(r,groupname,da,dd,dg,info)
return DeferDataset(r,groupname,dd,dg,info)
end
end
export DeferDataset
Expand Down Expand Up @@ -116,9 +114,8 @@ function variable(dds::DeferDataset,varname::AbstractString)
end
T = data["eltype"]
N = length(data["dimensions"])
da = DeferAttributes(dds.r,varname,data["attrib"])

return DeferVariable{T,N}(dds.r,varname,da,data)
return DeferVariable{T,N}(dds.r,varname,data)
end

variable(dds::DeferDataset,varname::Symbol) = variable(dds,string(varname))
Expand All @@ -142,18 +139,21 @@ Base.getindex(dd::DeferDimensions,name::AbstractString) = dd.data[name]["length"
unlimited(dd::DeferDimensions) = [dimname for (dimname,dim) in dd.data if dim["unlimited"]]


Base.keys(da::DeferAttributes) = collect(keys(da.data))
Base.getindex(da::DeferAttributes,name::AbstractString) = da.data[name]
attribnames(dds::DeferDataset) = collect(keys(dds.r.metadata["attrib"]))
attrib(dds::DeferDataset,name::SymbolOrString) = dds.r.metadata["attrib"][String(name)]


attribnames(dv::DeferVariable) = collect(keys(dv.data["attrib"]))
attrib(dv::DeferVariable,name::SymbolOrString) = dv.data["attrib"][String(name)]

#------------------------------------------------

Base.keys(dg::DeferGroups) = collect(keys(dg.data))
function Base.getindex(dg::DeferGroups,name::AbstractString)
data = dg.data[name]
da = DeferAttributes(dg.r,"/",data["attrib"])
dd = DeferDimensions(dg.r,data["dim"])
dg = DeferGroups(dg.r,data["group"])
return DeferDataset(dg.r,name,da,dd,dg,data)
return DeferDataset(dg.r,name,dd,dg,data)
end


Expand Down
8 changes: 0 additions & 8 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ struct Resource
metadata::OrderedDict
end

mutable struct DeferAttributes <: BaseAttributes
r::Resource
varname::String # "/" for global attributes
data::OrderedDict
end

mutable struct DeferDimensions <: AbstractDimensions
r::Resource
data::OrderedDict
Expand All @@ -167,7 +161,6 @@ end
mutable struct DeferDataset <: AbstractNCDataset
r::Resource
groupname::String
attrib::DeferAttributes
dim::DeferDimensions
group::DeferGroups
data::OrderedDict
Expand All @@ -177,7 +170,6 @@ end
mutable struct DeferVariable{T,N} <: AbstractNCVariable{T,N}
r::Resource
varname::String
attrib::DeferAttributes
data::OrderedDict
end

Expand Down

0 comments on commit c1449e1

Please sign in to comment.