在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:Alexander-Barth/NCDatasets.jl开源软件地址:https://github.com/Alexander-Barth/NCDatasets.jl开源编程语言:Julia 99.2%开源软件介绍:NCDatasets
The module
Other features include:
InstallationInside the Julia shell, you can download and install the package by issuing: using Pkg
Pkg.add("NCDatasets") Windows users are required to pin the version of NetCDF_jll until this issue is resolved (help is more than welcome). using Pkg
Pkg.add("NetCDF_jll")
Pkg.pin(name="NetCDF_jll", version="400.702.400") ManualThis Manual is a quick introduction in using NCDatasets.jl. For more details you can read the stable or latest documentation.
Explore the content of a netCDF fileBefore reading the data from a netCDF file, it is often useful to explore the list of variables and attributes defined in it. For interactive use, the following commands (without ending semicolon) display the content of the file similarly to using NCDatasets
ds = Dataset("file.nc") This creates the central structure of NCDatasets.jl, The following displays the information just for the variable ds["varname"] while to get the global attributes you can do: ds.attrib which produces a listing like:
Load a netCDF fileLoading a variable with known structure can be achieved by accessing the variables and attributes directly by their name. # The mode "r" stands for read-only. The mode "r" is the default mode and the parameter can be omitted.
ds = Dataset("/tmp/test.nc","r")
v = ds["temperature"]
# load a subset
subdata = v[10:30,30:5:end]
# load all data
data = v[:,:]
# load all data ignoring attributes like scale_factor, add_offset, _FillValue and time units
data2 = v.var[:,:]
# load an attribute
unit = v.attrib["units"]
close(ds) In the example above, the subset can also be loaded with: subdata = Dataset("/tmp/test.nc")["temperature"][10:30,30:5:end] This might be useful in an interactive session. However, the file An alternative way to ensure the file has been closed is to use a data =
Dataset(filename,"r") do ds
ds["temperature"][:,:]
end # ds is closed Create a netCDF fileThe following gives an example of how to create a netCDF file by defining dimensions, variables and attributes. using NCDatasets
using DataStructures
# This creates a new NetCDF file /tmp/test.nc.
# The mode "c" stands for creating a new file (clobber)
ds = Dataset("/tmp/test.nc","c")
# Define the dimension "lon" and "lat" with the size 100 and 110 resp.
defDim(ds,"lon",100)
defDim(ds,"lat",110)
# Define a global attribute
ds.attrib["title"] = "this is a test file"
# Define the variables temperature with the attribute units
v = defVar(ds,"temperature",Float32,("lon","lat"), attrib = OrderedDict(
"units" => "degree Celsius"))
# add additional attributes
v.attrib["comments"] = "this is a string attribute with Unicode Ω ∈ ∑ ∫ f(x) dx"
# Generate some example data
data = [Float32(i+j) for i = 1:100, j = 1:110]
# write a single column
v[:,1] = data[:,1]
# write a the complete data set
v[:,:] = data
close(ds) Edit an existing netCDF fileWhen you need to modify variables or attributes in a netCDF file, you have
to open it with the ds = Dataset("/tmp/test.nc","a")
ds.attrib["creator"] = "your name"
close(ds); BenchmarkThe benchmark loads a variable of the size 1000x500x100 in slices of 1000x500 (applying the scaling of the CF conventions) and computes the maximum of each slice and the average of each maximum over all slices. This operation is repeated 100 times. The code is available at https://github.com/Alexander-Barth/NCDatasets.jl/tree/master/test/perf .
All runtimes are in seconds. Julia 1.6.0 (with NCDatasets b953bf5), R 3.4.4 (with ncdf4 1.17) and Python 3.6.9 (with netCDF4 1.5.4). This CPU is a i7-7700. Filing an issueWhen you file an issue, please include sufficient information that would allow somebody else to reproduce the issue, in particular:
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论