Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Jan 15, 2024
1 parent 848863d commit adc36d5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ function varbyattrib(ds::Union{AbstractDataset,AbstractVariable}; kwargs...)
return varlist
end

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

"""
names = keys(g::Groups)
Return the names of all subgroubs of the group `g`.
"""
Base.keys(groups::Groups) = groupnames(groups.ds)

"""
group = getindex(g::Groups,groupname::AbstractString)
Return the NetCDF `group` with the name `groupname` from the parent
group `g`.
For example:
```julia
ds = NCDataset("results.nc", "r");
forecast_group = ds.group["forecast"]
forecast_temp = forecast_group["temperature"]
```
"""
Base.getindex(groups::Groups,name) = group(groups.ds,name)


Expand Down
34 changes: 34 additions & 0 deletions src/dimension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,47 @@ function show_dim(io::IO, d)
end
end

"""
keys(d::Dimensions)
Return a list of all dimension names in NCDataset `ds`.
# Examples
```julia
ds = NCDataset("results.nc", "r");
dimnames = keys(ds.dim)
```
"""
Base.keys(dims::Dimensions) = dimnames(dims.ds)


Base.getindex(dims::Dimensions,name) = dim(dims.ds,name)


"""
setindex!(d::Dimensions,len,name::AbstractString)
Defines the dimension called `name` to the length `len`, for example:
```julia
ds = NCDataset("file.nc","c")
ds.dim["longitude"] = 100
```
If `len` is the special value `Inf`, then the dimension is considered as
`unlimited`, i.e. it will grow as data is added to the NetCDF file.
"""
Base.setindex!(dims::Dimensions,data,name) = defDim(dims.ds,name,data)


Base.show(io::IO,dims::Dimensions) = show_dim(io,dims)

"""
unlimited(d::Dimensions)
Return the names of all unlimited dimensions.
"""
unlimited(dims::Dimensions) = unlimited(dims.ds)


Expand Down
8 changes: 5 additions & 3 deletions src/select.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ if we have a time series of temperature and salinity, the temperature values
can also be selected based on salinity:
```julia
# create a sample time series
using NCDatasets, Dates
using CommonDataModel: @select
fname = "sample_series.nc"
# create a sample time series
time = DateTime(2000,1,1):Day(1):DateTime(2009,12,31)
salinity = randn(length(time)) .+ 35
temperature = randn(length(time))
Expand All @@ -202,10 +203,11 @@ ds = NCDataset(fname)
# load all temperature data from January where the salinity is larger than 35.
v = @select(ds["temperature"],Dates.month(time) == 1 && salinity >= 35)
# this is equivalent to
# this is equivalent to:
v2 = ds["temperature"][findall(Dates.month.(time) .== 1 .&& salinity .>= 35)]
@test v == v2
v == v2
# returns true
close(ds)
```
Expand Down

2 comments on commit adc36d5

@Alexander-Barth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/98913

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" adc36d568ed658f35803554006e31098ccdbcf99
git push origin v0.3.2

Please sign in to comment.