Skip to content

Commit adc36d5

Browse files
update docs
1 parent 848863d commit adc36d5

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

src/dataset.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ function varbyattrib(ds::Union{AbstractDataset,AbstractVariable}; kwargs...)
219219
return varlist
220220
end
221221

222+
"""
223+
var = getindex(ds::Union{AbstractDataset,AbstractVariable},cfname::CFStdName)
224+
225+
Return the NetCDF variable `var` with the standard name `cfname` from a
226+
dataset. If the first argument is a variable, then the search is limited to
227+
all variables with the same dimension names.
228+
"""
222229
function Base.getindex(ds::Union{AbstractDataset,AbstractVariable},n::CFStdName)
223230
ncvars = varbyattrib(ds, standard_name = String(n.name))
224231
if length(ncvars) == 1
@@ -228,7 +235,27 @@ function Base.getindex(ds::Union{AbstractDataset,AbstractVariable},n::CFStdName)
228235
end
229236
end
230237

238+
"""
239+
names = keys(g::Groups)
240+
241+
Return the names of all subgroubs of the group `g`.
242+
"""
231243
Base.keys(groups::Groups) = groupnames(groups.ds)
244+
245+
"""
246+
group = getindex(g::Groups,groupname::AbstractString)
247+
248+
Return the NetCDF `group` with the name `groupname` from the parent
249+
group `g`.
250+
251+
For example:
252+
253+
```julia
254+
ds = NCDataset("results.nc", "r");
255+
forecast_group = ds.group["forecast"]
256+
forecast_temp = forecast_group["temperature"]
257+
```
258+
"""
232259
Base.getindex(groups::Groups,name) = group(groups.ds,name)
233260

234261

src/dimension.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,47 @@ function show_dim(io::IO, d)
8585
end
8686
end
8787

88+
"""
89+
keys(d::Dimensions)
90+
91+
Return a list of all dimension names in NCDataset `ds`.
8892
93+
# Examples
8994
95+
```julia
96+
ds = NCDataset("results.nc", "r");
97+
dimnames = keys(ds.dim)
98+
```
99+
"""
90100
Base.keys(dims::Dimensions) = dimnames(dims.ds)
101+
102+
91103
Base.getindex(dims::Dimensions,name) = dim(dims.ds,name)
104+
105+
106+
"""
107+
setindex!(d::Dimensions,len,name::AbstractString)
108+
109+
Defines the dimension called `name` to the length `len`, for example:
110+
111+
```julia
112+
ds = NCDataset("file.nc","c")
113+
ds.dim["longitude"] = 100
114+
```
115+
116+
If `len` is the special value `Inf`, then the dimension is considered as
117+
`unlimited`, i.e. it will grow as data is added to the NetCDF file.
118+
"""
92119
Base.setindex!(dims::Dimensions,data,name) = defDim(dims.ds,name,data)
120+
121+
93122
Base.show(io::IO,dims::Dimensions) = show_dim(io,dims)
94123

124+
"""
125+
unlimited(d::Dimensions)
126+
127+
Return the names of all unlimited dimensions.
128+
"""
95129
unlimited(dims::Dimensions) = unlimited(dims.ds)
96130

97131

src/select.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,10 @@ if we have a time series of temperature and salinity, the temperature values
184184
can also be selected based on salinity:
185185
186186
```julia
187-
# create a sample time series
188187
using NCDatasets, Dates
188+
using CommonDataModel: @select
189189
fname = "sample_series.nc"
190+
# create a sample time series
190191
time = DateTime(2000,1,1):Day(1):DateTime(2009,12,31)
191192
salinity = randn(length(time)) .+ 35
192193
temperature = randn(length(time))
@@ -202,10 +203,11 @@ ds = NCDataset(fname)
202203
# load all temperature data from January where the salinity is larger than 35.
203204
v = @select(ds["temperature"],Dates.month(time) == 1 && salinity >= 35)
204205
205-
# this is equivalent to
206+
# this is equivalent to:
206207
v2 = ds["temperature"][findall(Dates.month.(time) .== 1 .&& salinity .>= 35)]
207208
208-
@test v == v2
209+
v == v2
210+
# returns true
209211
close(ds)
210212
```
211213

0 commit comments

Comments
 (0)