NetCDF:网络通用数据格式

司机简称

时间维

生成依赖项

伦敦银行同业拆借利率

此格式支持读写访问。本页仅介绍栅格支持(您可以找到 vector side )NetCDF是面向数组的数据访问接口,用于表示科学数据。

填充值元数据或缺少值的向后兼容性在可用时保留为NODATA值。

注:执行为 gdal/frmts/netcdf/netcdfdataset.cpp .

驱动程序功能

Supports CreateCopy()

This driver supports the GDALDriver::CreateCopy() operation

Supports Create()

This driver supports the GDALDriver::Create() operation

Supports Georeferencing

This driver supports georeferencing

多图像处理(子数据集)

网络命令数据表单是多个不同数组的容器,大多数数组用于存储科学数据集。一个NetCDF文件可能包含多个数据集。它们可能在大小、维数上不同,并且可能代表不同区域的数据。

如果文件只包含一个看似是图像的NetCDF数组,则可以直接访问它,但如果文件包含多个图像,则可能需要通过两步过程导入文件。

第一步是使用gdalinfo获取文件中组件图像(dataset)的报告,然后使用gdal_translate导入所需的图像。gdalinfo实用程序列出输入NetCDF文件中的所有多维子数据集。

将单个图像的名称指定给子数据集名称元数据项。在子数据集描述元数据项中可以找到每个图像的描述。对于NetCDF,图像将遵循以下格式: NETCDF:filename:variable_name

在哪里? 文件名 是输入文件的名称,并且 variable_name 是在文件中选择的数据集。

在第二步中,为 gdalinfo 获取有关数据集的信息或 gdal_translate 读取数据集。

例如,我们希望从NetCDF文件中读取数据:

$ gdalinfo sst.nc
Driver: netCDF/Network Common Data Format
Size is 512, 512
Coordinate System is `'
Metadata:
  NC_GLOBAL#title=IPSL  model output prepared for IPCC Fourth Assessment SRES A2 experiment
  NC_GLOBAL#institution=IPSL (Institut Pierre Simon Laplace, Paris, France)
  NC_GLOBAL#source=IPSL-CM4_v1 (2003) : atmosphere : LMDZ (IPSL-CM4_IPCC, 96x71x19) ; ocean ORCA2 (ipsl_cm4_v1_8, 2x2L31); sea ice LIM (ipsl_cm4_v
  NC_GLOBAL#contact=Sebastien Denvil, sebastien.denvil@ipsl.jussieu.fr
  NC_GLOBAL#project_id=IPCC Fourth Assessment
  NC_GLOBAL#table_id=Table O1 (13 November 2004)
  NC_GLOBAL#experiment_id=SRES A2 experiment
  NC_GLOBAL#realization=1
  NC_GLOBAL#cmor_version=9.600000e-01
  NC_GLOBAL#Conventions=CF-1.0
  NC_GLOBAL#history=YYYY/MM/JJ: data generated; YYYY/MM/JJ+1 data transformed  At 16:37:23 on 01/11/2005, CMOR rewrote data to comply with CF standards and IPCC Fourth Assessment requirements
  NC_GLOBAL#references=Dufresne et al, Journal of Climate, 2015, vol XX, p 136
  NC_GLOBAL#comment=Test drive
Subdatasets:
  SUBDATASET_1_NAME=NETCDF:"sst.nc":lon_bnds
  SUBDATASET_1_DESC=[180x2] lon_bnds (64-bit floating-point)
  SUBDATASET_2_NAME=NETCDF:"sst.nc":lat_bnds
  SUBDATASET_2_DESC=[170x2] lat_bnds (64-bit floating-point)
  SUBDATASET_3_NAME=NETCDF:"sst.nc":time_bnds
  SUBDATASET_3_DESC=[24x2] time_bnds (64-bit floating-point)
  SUBDATASET_4_NAME=NETCDF:"sst.nc":tos
  SUBDATASET_4_DESC=[24x170x180] sea_surface_temperature (32-bit floating-point)Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  512.0)
Upper Right (  512.0,    0.0)
Lower Right (  512.0,  512.0)
Center      (  256.0,  256.0)

此NetCDF文件包含4个数据集:lon_bnds、lat_bnds、tim_bnds和tos。现在选择子数据集,描述如下: NETCDF:"sst.nc":tos [24x17x180] sea_surface_temperature (32-bit floating-point) 并获取关于这个变量中带数的信息。

$ gdalinfo NETCDF:"sst.nc":tos
Driver: netCDF/Network Common Data Format
Size is 180, 170
Coordinate System is `'
Origin = (1.000000,-79.500000)
Pixel Size = (1.98888889,0.99411765)
Metadata:
  NC_GLOBAL#title=IPSL  model output prepared for IPCC Fourth Assessment SRES A2 experiment
  NC_GLOBAL#institution=IPSL (Institut Pierre Simon Laplace, Paris, France)

.... 更多元数据

  time#standard_name=time
  time#long_name=time
  time#units=days since 2001-1-1
  time#axis=T
  time#calendar=360_day
  time#bounds=time_bnds
  time#original_units=seconds since 2001-1-1
Corner Coordinates:
Upper Left  (   1.0000000, -79.5000000)
Lower Left  (   1.0000000,  89.5000000)
Upper Right (     359.000,     -79.500)
Lower Right (     359.000,      89.500)
Center      ( 180.0000000,   5.0000000)
Band 1 Block=180x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1e+20
  Metadata:
    NETCDF_VARNAME=tos
    NETCDF_DIMENSION_time=15
    NETCDF_time_units=days since 2001-1-1
Band 2 Block=180x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1e+20
  Metadata:
    NETCDF_VARNAME=tos
    NETCDF_DIMENSION_time=45
    NETCDF_time_units=days since 2001-1-1

.... 更多乐队

Band 22 Block=180x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1e+20
  Metadata:
    NETCDF_VARNAME=tos
    NETCDF_DIMENSION_time=645
    NETCDF_time_units=days since 2001-1-1
Band 23 Block=180x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1e+20
  Metadata:
    NETCDF_VARNAME=tos
    NETCDF_DIMENSION_time=675
    NETCDF_time_units=days since 2001-1-1
Band 24 Block=180x1 Type=Float32, ColorInterp=Undefined
  NoData Value=1e+20
  Metadata:
    NETCDF_VARNAME=tos
    NETCDF_DIMENSION_time=705
    NETCDF_time_units=days since 2001-1-1

gdalinfo显示此子数据集中的带区数。每个波段都附加了元数据。在这个例子中,元数据告诉我们,每个波段对应于2001年1月以来的一系列月海面温度。此子数据集中有24个月的数据。你也可以使用 gdal_translate 用于读取子数据集。

请注意,您应该在GDAL中准确地提供标记行的内容 SUBDATASET_n_NAME ,包括 NETCDF: 前缀。

这个 NETCDF 前缀必须是第一个。它触发子数据集NetCDF驱动程序。此驱动程序仅用于以栅格图像的形式导入遥感和地理空间数据集。如果您想浏览NetCDF文件中包含的所有数据,应该使用其他工具。

Starting with GDAL 3.5, the VARIABLES_AS_BANDS=YES open option can be used to indicate to the driver that if the netCDF file only contains 2D variables of the same type and indexed by the same dimensions, then they should be reported as multiple bands of a same dataset.

$ gdalinfo autotest/gdrivers/data/netcdf/two_vars_scale_offset.nc -oo VARIABLES_AS_BANDS=YES

Driver: netCDF/Network Common Data Format
Files: autotest/gdrivers/data/netcdf/two_vars_scale_offset.nc
Size is 21, 21
Metadata:
  NC_GLOBAL#Conventions=COARDS/CF-1.0
  x#actual_range={-10,10}
  x#long_name=x
  y#actual_range={-10,10}
  y#long_name=y
  z#add_offset=1.5
  z#long_name=z
  z#scale_factor=0.01
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,   21.0)
Upper Right (   21.0,    0.0)
Lower Right (   21.0,   21.0)
Center      (   10.5,   10.5)
Band 1 Block=21x1 Type=Float32, ColorInterp=Undefined
  NoData Value=9.96920996838686905e+36
  Offset: 1.5,   Scale:0.01
  Metadata:
    add_offset=1.5
    long_name=z
    NETCDF_VARNAME=z
    scale_factor=0.01
Band 2 Block=21x1 Type=Float32, ColorInterp=Undefined
  NoData Value=9.96920996838686905e+36
  Offset: 2.5,   Scale:0.1
  Metadata:
    add_offset=2.5
    long_name=q
    NETCDF_VARNAME=q
    scale_factor=0.1

尺寸

NetCDF驱动程序假设数据遵循 UNIDATA NetCDF文件中的维度使用以下规则:(Z、Y、X)。如果有超过3个维度,驱动程序会将它们合并到波段中。例如,如果有一个类型为(P,T,Y,X)的四维数组。驱动器将乘以最后2维(P*T)。驾驶员将按以下顺序显示波段。它将首先递增T,然后递增P。元数据将显示在每个波段及其对应的T和P值。

地理参考

There is no universal way of storing georeferencing in NetCDF files. The driver first tries to follow the CF-1 Convention from UNIDATA looking for the Metadata named "grid_mapping". If "grid_mapping" is not present, the driver will try to find an lat/lon grid array to set geotransform array. The NetCDF driver verifies that the Lat/Lon array is equally spaced.

3.4 新版功能: crs_wkt attribute support

如果这两个方法失败,NetCDF驱动程序将尝试直接读取以下元数据并设置地理参考。

  • 空间参考(众所周知的文本)

  • GeoTransform(GeoTransform数组)

或者,

  • Northernmost_Northing

  • Southernmost_Northing

  • Easternmost_Easting

  • Westernmost_Easting

See also the configuration options GDAL_NETCDF_VERIFY_DIMS and GDAL_NETCDF_IGNORE_XY_AXIS_NAME_CHECKS which control this behavior.

打开选项

以下打开选项可用:

  • HONOUR_VALID_RANGE =是/否:(GDAL>2.2)是否设置为有效_min、有效_max或有效_range属性指示的有效范围之外的nodata像素值。默认为“是”。

  • IGNORE_XY_AXIS_NAME_CHECKS=YES/NO: (GDAL >= 3.4.2) Whether X/Y dimensions should be always considered as geospatial axis, even if the lack conventional attributes confirming it. Default is NO.

  • VARIABLES_AS_BANDS=YES/NO: (GDAL >= 3.5) If set to YES, and if the netCDF file only contains 2D variables of the same type and indexed by the same dimensions, then they should be reported as multiple bands of a same dataset. Default is NO (that is each variable will be reported as a separate subdataset)

创建问题

此驱动程序支持按照CF-1约定创建NetCDF文件。您可以创建一组二维数据集。每个变量数组都被命名为Band1,Band2。。。班登。

每个波段都有与之相关的元数据,对其包含的数据进行简短描述。

GDAL NetCDF元数据

所有NetCDF属性都透明地转换为GDAL元数据。

翻译遵循以下指令:

  • 全局NetCDF元数据具有 NC_GLOBAL 标记前缀。

  • 数据集元数据具有 变量名 前缀。

  • 每个前缀后面跟一个 # 签字。

  • NetCDF属性的格式如下: name=value .

例子:

$ gdalinfo NETCDF:"sst.nc":tos
Driver: netCDF/Network Common Data Format
Size is 180, 170
Coordinate System is `'
Origin = (1.000000,-79.500000)
Pixel Size = (1.98888889,0.99411765)
Metadata:

NetCDF全局属性

NC_GLOBAL#title=IPSL  model output prepared for IPCC Fourth Assessment SRES A2 experiment

变量属性:tos、lon、lat和时间

tos#standard_name=sea_surface_temperature
tos#long_name=Sea Surface Temperature
tos#units=K
tos#cell_methods=time: mean (interval: 30 minutes)
tos#_FillValue=1.000000e+20
tos#missing_value=1.000000e+20
tos#original_name=sosstsst
tos#original_units=degC
tos#history= At   16:37:23 on 01/11/2005: CMOR altered the data in the following ways: added 2.73150E+02 to yield output units;  Cyclical dimension was output starting at a different lon;
lon#standard_name=longitude
lon#long_name=longitude
lon#units=degrees_east
lon#axis=X
lon#bounds=lon_bnds
lon#original_units=degrees_east
lat#standard_name=latitude
lat#long_name=latitude
lat#units=degrees_north
lat#axis=Y
lat#bounds=lat_bnds
lat#original_units=degrees_north
time#standard_name=time
time#long_name=time
time#units=days since 2001-1-1
time#axis=T
time#calendar=360_day
time#bounds=time_bnds
time#original_units=seconds since 2001-1-1

On writing, when using the CreateCopy() interface or gdal_translate, dataset level metadata that follows the naming convention NC_GLOBAL#key=value will be used to write the netCDF attributes. Metadata set at the band level using key=value will also be used to write variable attributes.

Product specific behavior

Sentinel 5

3.4 新版功能.

The most verbose metadata is reported in the json:ISO_METADATA, json:ESA_METADATA, json:EOP_METADATA, json:QA_STATISTICS, json:GRANULE_DESCRIPTION, json:ALGORITHM_SETTINGS and json:SUPPORT_DATA metadata domains.

Can be discovered for example with:

gdalinfo -mdd all -json S5P.nc

创建选项

  • [FORMAT=[NC/NC2/NC4/NC4C]] :设置要使用的NetCDF文件格式,默认为NC。最近的NetCDF安装通常支持NC2,但如果NetCDF是使用NetCDF-4(和HDF5)支持编译的,则NC4和NC4C可用。

  • [COMPRESS=[NONE/DEFLATE]] :设置要使用的压缩。只有在NetCDF已使用NetCDF-4支持编译时,DEFLATE才可用。如果使用DEFLATE压缩,则默认使用NC4C格式。

  • [ZLEVEL=[1-9]] :设置使用放气压缩时的压缩级别。值9是最好的,值1是最小的压缩。默认值是1,它提供了最佳的时间/压缩比。

  • [WRITE_BOTTOMUP=[YES/NO]] :设置导出的y轴顺序,覆盖驱动程序检测到的顺序。NetCDF文件通常被假定为“自底向上”,而GDAL的模型则相反,它是“北向上”。这通常不会在y轴顺序中产生问题,除非没有y轴地理参考。此设置的默认值为“是”,因此文件将以NetCDF默认的“自底向上”顺序导出。有关导入,请参阅下面的配置选项GDAL_NETCDF_BOTTOMUP。

  • WRITE_GDAL_TAGS=[YES/NO]: Define if GDAL tags used for georeferencing (spatial_ref and GeoTransform) should be exported, in addition to CF tags. Not all information is stored in the CF tags (such as named datums and EPSG codes), therefore the driver exports these variables by default. In import the CF "grid_mapping" variable takes precedence and the GDAL tags are used if they do not conflict with CF metadata. In GDAL 4, spatial_ref will not be exported. The crs_wkt CF metatata attribute will be used instead.

  • [WRITE_LONLAT=[YES/NO/IF_NEEDED]] :定义是否将CF lon/lat变量写入文件。对于地理SRS,默认值为“是”,而对于计划的SRS,默认值为“否”。对于投影SRS,这通常是不必要的,因为GDAL和许多应用程序使用X/Y维度变量和CF投影信息。如果投影不是CF-1.5标准的一部分,则使用IF_NEEDED选项创建lon/lat变量。

  • [TYPE_LONLAT=[float/double]] :设置用于lon/lat变量的变量类型。对于地理SRS,默认值为double,对于投影SRS,默认值为float。如果lon/lat变量是为投影的SRS编写的,则该文件相当大(每个变量使用X*Y空间),因此建议键入“LONLAT=float”和“COMPRESS=DEFLATE”以节省空间。

  • [PIXELTYPE=[DEFAULT/SIGNEDBYTE]] :通过将其设置为signed Byte,可以强制将新的字节文件写入为SIGNEDBYTE。

  • WRITE_GDAL_VERSION=[YES/NO]: (GDAL >= 3.5.0) Define if a "GDAL" text global attribute should be added on file creation with the GDAL version. Defaults to YES

  • WRITE_GDAL_HISTORY=[YES/NO]: (GDAL >= 3.5.0) Define if the "history" global attribute should be prepended with a date/time and GDAL information. Defaults to YES.

Creation of multidimensional files with CreateCopy() 2D raster API

Starting with GDAL 3.1, the preferred way of creating > 2D files is to use the the 多维栅格数据模型 API. However it is possible to create such files with the 2D raster API using the CreateCopy() method (note that at time of writing, this is not supported using the Create() method).

The NETCDF_DIM_EXTRA={dim1_name,...dimN_name} metadata item must be set on the source dataset, where dim1_name is the name of the slowest varying dimension and dimN_name the name of the fastest varying one.

For each extra dimension, the NETCDF_DIM_{dim_name}_DEF={dimension_size,netcdf_data_type} metadata item must be set where dimension_size is the size of the dimension (number of samples along that dimension) and netcdf_data_type is the integer value for the netCDF data type of the corresponding indexing variable. Among the most useful data types:

  • 4 for Int

  • 5 for Float

  • 6 for Double

  • 10 for Int64

The NETCDF_DIM_{dim_name}_VALUES={value1,...valueN} is set to define the values of the indexing variable corresponding to dimension.

dim_name#attribute metadata items can also be set to define the attributes of the indexing variable of the dimension.

Example of creation of a Time,Z,Y,X 4D file in Python:

# Create in-memory file with required metadata to define the extra >2D
# dimensions
size_z = 2
size_time = 3
src_ds = gdal.GetDriverByName('MEM').Create('', 4, 3, size_z * size_time)
src_ds.SetMetadataItem('NETCDF_DIM_EXTRA', '{time,Z}')
# 6 is NC_DOUBLE
src_ds.SetMetadataItem('NETCDF_DIM_Z_DEF', f"{{{size_z},6}}")
src_ds.SetMetadataItem('NETCDF_DIM_Z_VALUES', '{1.25,2.50}')
src_ds.SetMetadataItem('Z#axis', 'Z')
src_ds.SetMetadataItem('NETCDF_DIM_time_DEF', f"{{{size_time},6}}")
src_ds.SetMetadataItem('NETCDF_DIM_time_VALUES', '{1,2,3}')
src_ds.SetMetadataItem('time#axis', 'T')
src_ds.SetGeoTransform([2,1,0,49,0,-1])

# Create netCDF file
gdal.GetDriverByName('netCDF').CreateCopy('out.nc', src_ds)

配置选项

  • [GDAL_NETCDF_BOTTOMUP=[YES/NO]] :设置导入的y轴顺序,覆盖驱动程序检测到的顺序。通常不需要此选项,除非特定数据集导致问题(应在GDAL-trac中报告)。

  • GDAL_NETCDF_VERIFY_DIMS=[YES/STRICT] : Try to guess which dimensions represent the latitude and longitude only by their attributes (STRICT) or also by guessing the name (YES), default is YES.

  • GDAL_NETCDF_IGNORE_XY_AXIS_NAME_CHECKS=[YES/NO] : Whether X/Y dimensions should be always considered as geospatial axis, even if the lack conventional attributes confirming it. Default is NO.

VSI虚拟文件系统API支持

由于GDAL 2.4和Linux内核>=4.3和libnetcdf>=4.5,因此支持对/vsi文件系统的读取操作。

NetCDF-4组支持读取(GDAL>=3.0)

为了支持NetCDF-4组的阅读,该驱动程序在GDAL 3.0中发生了重大变化:

  • 递归地探索所有嵌套组以创建子数据集列表

  • 嵌套组中的子数据集使用/group1/group2/../groupn/var标准NetCDF-4约定,但根组中的变量不具有与NetCDF-3驱动程序向后兼容的前导斜杠

  • 每个嵌套组的全局属性也使用相同的约定/group1/group2/../groupn/NC_Global#attr_name在GDAL数据集元数据中收集,除了根组没有前导斜杠表示向后兼容之外

  • 在搜索包含所选子数据集辅助信息的变量(如坐标变量或网格映射)时,我们现在还搜索父组及其子组,如中所述 Support of groups in CF

多维API支持

3.1 新版功能.

netCDF驱动程序支持 多维栅格数据模型 用于读取和创建操作。

The GDALGroup::GetGroupNames() method supports the following options:

  • GROUP_BY=SAME_DIMENSION. If set, single-dimensional variables will be exposed as a "virtual" subgroup. This enables the user to get a clearer organization of variables, for example in datasets where variables belonging to different trajectories are indexed by different dimensions but mixed in the same netCDF group.

The GDALGroup::OpenGroup() method supports the following options:

  • GROUP_BY=SAME_DIMENSION. See above description

这个 GDALGroup::GetMDArrayNames() 方法支持以下选项:

  • SHOW_ALL=YES/NO。默认为NO。如果设置为YES,将列出所有变量。

  • SHOW_ZERO_DIM=是/否。默认为否。如果设置为否,则不列出0维变量。

  • SHOW_COORDINATES=是/否。默认为是。如果设置为“否”,则在 coordinates 将不会列出另一个变量的属性。

  • SHOW_BOUNDS=是/否。默认为是。如果设置为“否”,则在 bounds 将不会列出另一个变量的属性。

  • SHOW_index=YES/NO。默认为YES。如果设置为“否”,则不会列出名称等于其索引变量名称的一维变量。

  • 显示时间=是/否。默认为是。如果设置为否,则为 standard_name 属性是“时间”将不会被列出。

  • GROUP_BY=SAME_DIMENSION. If set, single-dimensional variables will not be listed

这个 GDALGroup::CreateMDArray() 方法支持以下选项:

  • NC_TYPE=NC_CHAR/NC_BYTE/NC_INT64/NC_UINT64:重载通常从传递给CreateMDArray()的GDAL数据类型推断出的netCDF数据类型。NCu CHAR只能用于固定大小的字符串。

  • BLOCKSIZE=size_dim0,size_dim1,…,size_dimN:设置netCDF块大小,由nc_def_var_chunking()设置。必须有与传递给CreateMDArray()的维度数相同的值

  • COMPRESS=DEFLATE:请求DEFLATE压缩

  • ZLEVEL=编号:放气压缩级别(1-9)

  • CHECKSUM=YES/NO:是否启用Fletcher32校验和。校验和生成需要分块,如果BLOCKSIZE选项未要求显式分块,则将使用默认的分块。默认为“否”。

  • FILTER=filterid,param1,…,paramN:定义用于写入的过滤器(通常是压缩方法)。这应该是一个数值列表,用逗号分隔。第一个值是filter id(在https://support.hdfgroup.org/services/contributions.html#过滤器)以下是每个过滤器参数的值。有关netCDF-4过滤器支持的更多详细信息,请访问https://www.unidata.ucar.edu/software/netcdf/docs/mduu Usersu wfisheru Desktopu docsu netcdf-cu docsu filters.html

司机楼

这个驱动程序是用UNIDATA NetCDF库编译的。

在使用NetCDF支持配置GDAL之前,需要下载或编译NetCDF库。

NetCDF GDAL wiki 有关HDF4、NetCDF-4和HDF5的构建说明和信息。

参见: