Skip to content

Commit fc4e099

Browse files
authored
Merge branch 'Alexander-Barth:master' into diskarrays
2 parents 7bd3961 + 36d2d51 commit fc4e099

File tree

8 files changed

+45
-23
lines changed

8 files changed

+45
-23
lines changed

docs/Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
[deps]
2+
CommonDataModel = "1fbeeb36-5f17-413c-809b-666fb144f157"
3+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
24
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
35
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
4-
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
6+
7+
[compat]
8+
Documenter = "0.27"

docs/make.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using Pkg
22
Pkg.activate(@__DIR__)
33
CI = get(ENV, "CI", nothing) == "true"
4-
using Documenter, NCDatasets
4+
using Documenter, NCDatasets, CommonDataModel
55

66
makedocs(
7-
modules = [NCDatasets],
8-
sitename= "NCDatasets.jl",
7+
modules = [NCDatasets, CommonDataModel],
8+
sitename = "NCDatasets.jl",
99
doctest = false,
1010
format = Documenter.HTML(
1111
prettyurls = CI,
@@ -21,6 +21,7 @@ makedocs(
2121
"Experimental features" => "experimental.md",
2222
"Tutorials" => "tutorials.md",
2323
],
24+
checkdocs = :none,
2425
)
2526

2627
if CI

docs/src/dataset.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ Otherwise, we attempt to use standard structures from the Julia standard library
3131
## Groups
3232

3333
```@docs
34-
defGroup(ds::NCDataset,groupname)
34+
defGroup
3535
getindex(g::NCDatasets.Groups,groupname::AbstractString)
3636
Base.keys(g::NCDatasets.Groups)
37-
groupname(ds::NCDataset)
3837
```
3938

4039
## Common methods

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ subdata = NCDataset("/tmp/test.nc")["temperature"][10:30,30:5:end]
122122
```
123123

124124
This might be useful in an interactive session. However, the file `test.nc` is not closed, which can be a problem if you open many files. On Linux the number of opened files is often limited to 1024 (soft limit). If you write to a file, you should also always close the file to make sure that the data is properly written to the disk.
125+
(open files will get closed eventually when the dataset variable is finalized by julia's garbage collector).
125126

126127
An alternative way to ensure the file has been closed is to use a `do` block: the file will be closed automatically when leaving the block.
127128

docs/src/performance.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
# [Performance tips](@id performance_tips)
22

3-
* Reading data from a file is not type-stable, because the type of the output of the read operation is dependent on the type defined in the NetCDF files and the value of various attribute (like `scale_factor`, `add_offset` and `units` for time conversion). All this information cannot be inferred from a static analysis of the source code. It is therefore recommended to use [type annotation](https://docs.julialang.org/en/v1/manual/types/index.html#Type-Declarations-1) if resulting type of a read operation in known:
3+
* Reading data from a file is not type-stable, because the type of the output of the read operation is dependent on the type defined in the NetCDF files and the value of various attribute (like `scale_factor`, `add_offset` and `units` for time conversion). All this information cannot be inferred from a static analysis of the source code. It is therefore recommended to use [type annotation](https://docs.julialang.org/en/v1/manual/types/index.html#Type-Declarations-1) if the resulting type of a read operation in known:
44

55
```julia
66
ds = NCDataset("file.nc")
77
nctemp = ds["temp"]
8-
temp = nctemp[:,:] :: Array{Float64,2}
9-
# or
10-
# call_barrier_function(nctemp)
8+
temp = nctemp[:,:] :: Array{Float32,2}
119

12-
Alternatively, one can also use so called "[function barriers](https://docs.julialang.org/en/v1/manual
13-
# call_barrier_function(temp)
14-
close(ds)
15-
```/performance-tips/index.html#kernel-functions-1)" or the in-place `NCDatasets.load!` function (which is unexported, so it has to be prefixed with the module name):
10+
# heavy computation using temp
11+
# ...
12+
```
13+
14+
Alternatively, one can also use so-called [function barriers](https://docs.julialang.org/en/v1/manual/performance-tips/index.html#kernel-functions-1)
15+
since the function `heavy_computation` will be specialized based on the type its input parameters.
16+
17+
18+
```julia
19+
function heavy_computation(temp)
20+
# heavy computation using temp
21+
# ...
22+
end
23+
24+
ds = NCDataset("file.nc")
25+
nctemp = ds["temp"]
26+
temp = nctemp[:,:]
27+
output = heavy_computation(temp)
28+
```
29+
30+
Calling the barrier function with `nctemp` would also be type-stable.
31+
Using the in-place `NCDatasets.load!` function (which is unexported, so it has to be prefixed with the module name) does also lead to type-stable code and allows to reuse a memory buffer:
1632

1733
```julia
1834
ds = NCDataset("file.nc")
1935

20-
temp = zeros(10,20)
36+
temp = zeros(Float32,10,20)
2137
NCDatasets.load!(variable(ds,"temp"),temp,:,:)
2238
```
2339

src/groupes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Base.getindex(g::Groups,groupname::SymbolOrString)
3232
end
3333

3434
"""
35-
defGroup(ds::NCDataset,groupname, attrib = []))
35+
defGroup(ds::NCDataset,groupname; attrib = []))
3636
3737
Create the group with the name `groupname` in the dataset `ds`.
3838
`attrib` is a list of attribute name and attribute value pairs (see `NCDataset`).

src/variable.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ load!(ds["temp"].var,data,:,1) # loads the 1st column
138138
julia `Char` type uses 4 bytes and the NetCDF `NC_CHAR` only 1 byte.
139139
"""
140140
@inline function load!(ncvar::Variable{T,N}, data::AbstractArray{T}, indices::Union{Integer, UnitRange, StepRange, Colon}...) where {T,N}
141-
@inline unsafe_load!(ncvar, data, indices...)
141+
unsafe_load!(ncvar, data, indices...)
142142
end
143143

144144
@inline function load!(ncvar::Variable{Char,N}, data::AbstractArray{UInt8}, indices::Union{Integer, UnitRange, StepRange, Colon}...) where N
145-
@inline unsafe_load!(ncvar, data, indices...)
145+
unsafe_load!(ncvar, data, indices...)
146146
end
147147

148148
@inline function load!(ncvar::Variable{T,2}, data::AbstractArray{T}, i::Colon,j::UnitRange) where T

test/test_https.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ using Test
33

44
sample_url = "https://rda.ucar.edu/thredds/dodsC/files/g/ds084.1/2018/20181231/gfs.0p25.2018123118.f003.grib2"
55

6-
@test begin
7-
NCDataset(sample_url) do ds
8-
haskey(ds,"lon")
9-
end
10-
end
6+
# opendal server too unreliable
7+
# @test begin
8+
# NCDataset(sample_url) do ds
9+
# haskey(ds,"lon")
10+
# end
11+
# end

0 commit comments

Comments
 (0)