Skip to content

Commit 7bd3961

Browse files
committed
Merge branch 'master' into diskarrays
Conflicts: src/variable.jl
2 parents 0873d6d + 5ec49f2 commit 7bd3961

File tree

10 files changed

+54
-40
lines changed

10 files changed

+54
-40
lines changed

docs/src/attributes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typeof(attributes_as_dictionary)
2323

2424
## Possible type promotion in Julia
2525

26-
There is a subtile problem with the following code:
26+
There is a subtle problem with the following code:
2727

2828
```julia
2929
ncv1 = defVar(ds,"v1", UInt8, ("longitude", "latitude", "time"), attrib = [
@@ -48,7 +48,7 @@ Julia effectively promotes the `_FillValue` to Float64 which leads to a `"NetCDF
4848
# "_FillValue" => 255.0
4949
```
5050

51-
Note that the type of the second element of the `Pair`.
51+
Note the type of the second element of the `Pair`.
5252

5353
Using a Julia `Dict` does not show this behaviour:
5454

docs/src/dimensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dimensions
22

3-
In the NetCDF data model, dimension have names and a length (but possibly an unlimited length) and are defined for a NetCDF dataset (or group).
3+
In the NetCDF data model, dimensions have names and a length (but possibly an unlimited length) and are defined for a NetCDF dataset (or group).
44
For a given `Variable` or `CFVariable`,the names of the corresponding dimensions are obtained with using [`dimnames`](@ref).
55

66
```@docs

docs/src/experimental.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Multi-file support
44

5-
Multiple files can also be aggregated over a given dimensions (or the record dimension). In this example, 3 sea surface temperature fields from the
5+
Multiple files can also be aggregated over a given dimension (or the record dimension). In this example, 3 sea surface temperature fields from the
66
1992-01-01 to 1992-01-03 are aggregated using the OPeNDAP service from PODAAC.
77

88
```julia
@@ -51,7 +51,7 @@ name(ncbat)
5151

5252
If there are multiple variables with the `standard_name` equal to `height`, an error is returned because it is ambiguous which variable should be accessed.
5353

54-
All variables whose dimensions are also dimensions of `ncbat` are considered as related and can also be accessed by sub-setting `ncbar` with their variable names
54+
All variables whose dimensions are also dimensions of `ncbat` are considered as related and can also be accessed by sub-setting `ncbat` with their variable names
5555
of CF Standard name:
5656

5757
```jldoctest mylabel
@@ -67,7 +67,7 @@ The previous call to `ncbat[CF"longitude"]` would also worked if there are multi
6767

6868
## Views
6969

70-
In Julia, a [view of an array](https://docs.julialang.org/en/v1/base/arrays/#Views-(SubArrays-and-other-view-types)) is a subset of an array but whose elements still point to the original parent array. If one modifies an element of a view, the corresponding element is the parent array is modified too:
70+
In Julia, a [view of an array](https://docs.julialang.org/en/v1/base/arrays/#Views-(SubArrays-and-other-view-types)) is a subset of an array but whose elements still point to the original parent array. If one modifies an element of a view, the corresponding element in the parent array is modified too:
7171

7272
```jldoctest example_view_julia
7373
A = zeros(4,4)
@@ -81,7 +81,7 @@ A[2,2]
8181
2.0
8282
```
8383

84-
Views do not use copy of the array. The parent array and the indices of the view and the obtained via the function [`parent`](https://docs.julialang.org/en/v1/base/arrays/#Base.parent) and [`parentindices`](https://docs.julialang.org/en/v1/base/arrays/#Base.parentindices).
84+
Views do not use copy of the array. The parent array and the indices of the view are obtained via the function [`parent`](https://docs.julialang.org/en/v1/base/arrays/#Base.parent) and [`parentindices`](https://docs.julialang.org/en/v1/base/arrays/#Base.parentindices).
8585

8686
```jldoctest example_view_julia
8787
parent(subset) == A
@@ -129,7 +129,7 @@ lon_subset[:] == [2, 3, 4]
129129
true
130130
```
131131

132-
A view of a NetCDF variable, also implement the function `parent` and `parentindices` with the same meaning as for julia `Array`s.
132+
A view of a NetCDF variable also implements the function `parent` and `parentindices` with the same meaning as for julia `Array`s.
133133

134134
A whole dataset can also be sliced using a `view(ds, dim1=range1, dim2=range2...)`. For example:
135135

@@ -149,8 +149,8 @@ Such sliced datasets can for example be saved into a new NetCDF file using `writ
149149
write("slice.nc",ds_subset)
150150
```
151151

152-
Any dimensions not mentioned in the `@view` call is not sliced.
153-
While `@view` produces a slices based on indices, the `NCDatasets.@select` macro produces a slice (of an NetCDF variable or dataset)
152+
Any dimension not mentioned in the `@view` call is not sliced.
153+
While `@view` produces a slice based on indices, the `NCDatasets.@select` macro produces a slice (of an NetCDF variable or dataset)
154154
based on the values of other related variables (typically coordinates).
155155

156156
## Data selection based on values

docs/src/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Variables
7575
[...]
7676
```
7777

78-
This creates the central structure of NCDatasets.jl, `NCDataset`, which represents the contents of the netCDF file (without immediatelly loading everything in memory).
78+
This creates the central structure of NCDatasets.jl, `NCDataset`, which represents the contents of the netCDF file (without immediately loading everything in memory).
7979

8080
The following displays the information just for the variable `varname`:
8181

@@ -187,7 +187,7 @@ end
187187
### Edit an existing netCDF file
188188

189189
When you need to modify the variables or the attributes of a netCDF, you have
190-
to open it with the `"a"` option. Here of instance we add a global attribute *creator* to the
190+
to open it with the `"a"` option. Here, for instance, we add a global attribute *creator* to the
191191
file created in the previous step.
192192

193193
```julia
@@ -231,7 +231,7 @@ ncarea.attrib["units"] = "meter2";
231231

232232
### Get one or several variables by specifying the value of an attribute
233233

234-
The variable name are not always standardized, for example the longitude we can
234+
The variable names are not always standardized. For example, for the longitude we can
235235
find: `lon`, `LON`, `longitude`, ...
236236

237237
The solution implemented in the function `varbyattrib` consists in searching for the
@@ -242,7 +242,7 @@ nclon = varbyattrib(ds, standard_name = "longitude");
242242
```
243243
will return the list of variables of the dataset `ds` that have "longitude"
244244
as standard name. To directly load the data of the first variable with the
245-
attribute `standard_name` equal to `"longitude"` one can the following:
245+
attribute `standard_name` equal to `"longitude"` one can do the following:
246246

247247
```julia
248248
data = varbyattrib(ds, standard_name = "longitude")[1][:]

docs/src/issues.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Stacktrace:
146146
during initialization of module NetCDF_jll
147147
```
148148

149-
You will likely have similar issue with julia installed from other package manager (like Debian/Ubuntu apt, Homebrew...). The only supported solution is to install
149+
You will likely have similar issues with julia installed from other package managers (like Debian/Ubuntu apt, Homebrew...). The only supported solution is to install
150150
the [offical julia builds](https://julialang.org/downloads/).
151151

152152

docs/src/performance.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
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 does depedent 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 resulting type of a read operation in known:
44

55
```julia
66
ds = NCDataset("file.nc")
77
nctemp = ds["temp"]
88
temp = nctemp[:,:] :: Array{Float64,2}
99
# or
1010
# call_barrier_function(nctemp)
11+
12+
Alternatively, one can also use so called "[function barriers](https://docs.julialang.org/en/v1/manual
1113
# call_barrier_function(temp)
1214
close(ds)
13-
```
14-
15-
Alternatively, one can also use so called "[function barriers](https://docs.julialang.org/en/v1/manual/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):
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):
1616

1717
```julia
1818
ds = NCDataset("file.nc")
@@ -36,7 +36,7 @@ ds = NCDataset("file.nc")
3636
close(ds)
3737
```
3838

39-
* Avoid when possible indexing with arrays and `CartesianIndex` as they also result in loading the data element-wise.
39+
* Avoid, when possible, indexing with arrays and `CartesianIndex` as they also result in loading the data element-wise.
4040

4141
```julia
4242
ds = NCDataset("dataset.nc");

docs/src/tutorials.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ variables:
9898
```
9999

100100

101-
This is the typically error message which is returned when the credentials are not configured properly:
101+
This is the typical error message which is returned when the credentials are not configured properly:
102102

103103
```
104104
syntax error, unexpected WORD_WORD, expecting SCAN_ATTR or SCAN_DATASET or SCAN_ERROR
@@ -157,9 +157,9 @@ This script produces the following plot:
157157

158158
## Access data from S3 object storage
159159

160-
NASA EarthData is also available from AWS S3 object storage at the AWS region us-west-2. This example assumes that you have access to an AWS instance in this region (available thought e.g. [Pangeo Cloud](https://pangeo.io/cloud.html) after registration thanks to funding from the NASA's ACCESS/AWS Cloud Credits for Research program and the fine folks at [Pangeo](https://github.com/pangeo-data)).
160+
NASA EarthData is also available from AWS S3 object storage at the AWS region us-west-2. This example assumes that you have access to an AWS instance in this region (available through e.g. [Pangeo Cloud](https://pangeo.io/cloud.html) after registration thanks to funding from the NASA's ACCESS/AWS Cloud Credits for Research program and the fine folks at [Pangeo](https://github.com/pangeo-data)).
161161

162-
The S3 access token available from [https://archive.podaac.earthdata.nasa.gov/s3credentials](https://archive.podaac.earthdata.nasa.gov/s3credentials) are only valid for 1 hour. It is therefore preferable to get this token programmatically using your EarthData username and password. The function `earthdata_s3credentials` is a translation of ["Sample script to receive credentials"](https://web.archive.org/web/20220623090241/https://nasa.github.io/cumulus-distribution-api/#temporary-s3-credentials) to Julia:
162+
The S3 access tokens available from [https://archive.podaac.earthdata.nasa.gov/s3credentials](https://archive.podaac.earthdata.nasa.gov/s3credentials) are only valid for 1 hour. It is therefore preferable to get this token programmatically using your EarthData username and password. The function `earthdata_s3credentials` is a translation of ["Sample script to receive credentials"](https://web.archive.org/web/20220623090241/https://nasa.github.io/cumulus-distribution-api/#temporary-s3-credentials) to Julia:
163163

164164
```julia
165165
using AWS, Base64, JSON3, HTTP, NCDatasets, URIs

src/dataset.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function NCDataset(filename::AbstractString,
192192
elseif mode == "a"
193193
NC_WRITE
194194
elseif mode == "c"
195-
ncmode = NC_CLOBBER
195+
NC_CLOBBER
196196
else
197197
throw(NetCDFError(-1, "Unsupported mode '$(mode)' for filename '$(filename)'"))
198198
end

src/variable.jl

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ function checkbuffer(len,data)
9292
end
9393
end
9494

95+
@inline function unsafe_load!(ncvar::Variable, data, indices::Union{Integer, UnitRange, StepRange, Colon}...)
96+
sizes = size(ncvar)
97+
normalizedindices = normalizeindexes(sizes, indices)
98+
ind = to_indices(ncvar,normalizedindices)
99+
100+
start,count,stride,jlshape = ncsub(ind)
101+
102+
@boundscheck begin
103+
checkbounds(ncvar,indices...)
104+
checkbuffer(prod(count),data)
105+
end
106+
107+
nc_get_vars!(ncvar.ds.ncid,ncvar.varid,start,count,stride,data)
108+
end
109+
95110
"""
96111
NCDatasets.load!(ncvar::Variable, data, indices)
97112
@@ -101,7 +116,8 @@ bounds checking can be elided by the compiler (which typically require
101116
type-stable code).
102117
103118
```julia
104-
ds = Dataset("file.nc")
119+
using NCDatasets
120+
ds = NCDataset("file.nc")
105121
ncv = ds["vgos"].var;
106122
# data must have the right shape and type
107123
data = zeros(eltype(ncv),size(ncv));
@@ -115,20 +131,18 @@ data = zeros(5); # must have the right shape and type
115131
load!(ds["temp"].var,data,:,1) # loads the 1st column
116132
```
117133
134+
!!! note
135+
136+
For a netCDF variable of type `NC_CHAR`, the element type of the `data`
137+
array must be `UInt8` and cannot be the julia `Char` type, because the
138+
julia `Char` type uses 4 bytes and the NetCDF `NC_CHAR` only 1 byte.
118139
"""
119140
@inline function load!(ncvar::Variable{T,N}, data::AbstractArray{T}, indices::Union{Integer, UnitRange, StepRange, Colon}...) where {T,N}
120-
sizes = size(ncvar)
121-
normalizedindices = normalizeindexes(sizes, indices)
122-
ind = to_indices(ncvar,normalizedindices)
123-
124-
start,count,stride,jlshape = ncsub(ind)
125-
126-
@boundscheck begin
127-
checkbounds(ncvar,indices...)
128-
checkbuffer(prod(count),data)
129-
end
141+
@inline unsafe_load!(ncvar, data, indices...)
142+
end
130143

131-
nc_get_vars!(ncvar.ds.ncid,ncvar.varid,start,count,stride,data)
144+
@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...)
132146
end
133147

134148
@inline function load!(ncvar::Variable{T,2}, data::AbstractArray{T}, i::Colon,j::UnitRange) where T
@@ -312,19 +326,19 @@ nomissing(a::AbstractArray) = a
312326
"""
313327
a = nomissing(da,value)
314328
315-
Retun the values of the array `da` of type `Array{Union{T,Missing},N}`
329+
Retun the values of the array `da` of type `AbstractArray{Union{T,Missing},N}`
316330
as a regular Julia array `a` by replacing all missing value by `value`
317331
(converted to type `T`).
318332
This function is identical to `coalesce.(da,T(value))` where T is the element
319-
tyoe of `da`.
333+
type of `da`.
320334
## Example:
321335
322336
```julia-repl
323337
julia> nomissing([missing,1.,2.],NaN)
324338
# returns [NaN, 1.0, 2.0]
325339
```
326340
"""
327-
function nomissing(da::Array{Union{T,Missing},N},value) where {T,N}
341+
function nomissing(da::AbstractArray{Union{T,Missing},N},value) where {T,N}
328342
return replace(da, missing => T(value))
329343
end
330344

test/test_https.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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_broken begin
6+
@test begin
77
NCDataset(sample_url) do ds
88
haskey(ds,"lon")
99
end

0 commit comments

Comments
 (0)