1.. _raster.netcdf: 2 3================================================================================ 4NetCDF: Network Common Data Form 5================================================================================ 6 7.. shortname:: netCDF 8 9.. build_dependencies:: libnetcdf 10 11This format is supported for read and write access. This page only 12describes the raster support (you can find documentation for the :ref:`vector 13side <vector.netcdf>`) NetCDF is an interface for 14array-oriented data access and is used for representing scientific data. 15 16The fill value metadata or missing_value backward compatibility is 17preserved as NODATA value when available. 18 19NOTE: Implemented as ``gdal/frmts/netcdf/netcdfdataset.cpp``. 20 21Driver capabilities 22------------------- 23 24.. supports_createcopy:: 25 26.. supports_create:: 27 28.. supports_georeferencing:: 29 30Multiple Image Handling (Subdatasets) 31------------------------------------- 32 33Network Command Data Form is a container for several different arrays 34most used for storing scientific dataset. One NetCDF file may contain 35several datasets. They may differ in size, number of dimensions and may 36represent data for different regions. 37 38If the file contains only one NetCDF array which appears to be an image, 39it may be accessed directly, but if the file contains multiple images it 40may be necessary to import the file via a two step process. 41 42The first step is to get a report of the components images (dataset) in 43the file using gdalinfo, and then to import the desired images using 44gdal_translate. The gdalinfo utility lists all multidimensional 45subdatasets from the input NetCDF file. 46 47The name of individual images are assigned to the SUBDATASET_n_NAME 48metadata item. The description for each image is found in the 49SUBDATASET_n_DESC metadata item. For NetCDF images will follow this 50format: *NETCDF:filename:variable_name* 51 52where *filename* is the name of the input file, and *variable_name* is 53the dataset selected within the file. 54 55On the second step you provide this name for **gdalinfo** to get 56information about the dataset or **gdal_translate** to read dataset. 57 58For example, we want to read data from a NetCDF file: 59 60:: 61 62 $ gdalinfo sst.nc 63 Driver: netCDF/Network Common Data Format 64 Size is 512, 512 65 Coordinate System is `' 66 Metadata: 67 NC_GLOBAL#title=IPSL model output prepared for IPCC Fourth Assessment SRES A2 experiment 68 NC_GLOBAL#institution=IPSL (Institut Pierre Simon Laplace, Paris, France) 69 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 70 NC_GLOBAL#contact=Sebastien Denvil, sebastien.denvil@ipsl.jussieu.fr 71 NC_GLOBAL#project_id=IPCC Fourth Assessment 72 NC_GLOBAL#table_id=Table O1 (13 November 2004) 73 NC_GLOBAL#experiment_id=SRES A2 experiment 74 NC_GLOBAL#realization=1 75 NC_GLOBAL#cmor_version=9.600000e-01 76 NC_GLOBAL#Conventions=CF-1.0 77 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 78 NC_GLOBAL#references=Dufresne et al, Journal of Climate, 2015, vol XX, p 136 79 NC_GLOBAL#comment=Test drive 80 Subdatasets: 81 SUBDATASET_1_NAME=NETCDF:"sst.nc":lon_bnds 82 SUBDATASET_1_DESC=[180x2] lon_bnds (64-bit floating-point) 83 SUBDATASET_2_NAME=NETCDF:"sst.nc":lat_bnds 84 SUBDATASET_2_DESC=[170x2] lat_bnds (64-bit floating-point) 85 SUBDATASET_3_NAME=NETCDF:"sst.nc":time_bnds 86 SUBDATASET_3_DESC=[24x2] time_bnds (64-bit floating-point) 87 SUBDATASET_4_NAME=NETCDF:"sst.nc":tos 88 SUBDATASET_4_DESC=[24x170x180] sea_surface_temperature (32-bit floating-point)Corner Coordinates: 89 Upper Left ( 0.0, 0.0) 90 Lower Left ( 0.0, 512.0) 91 Upper Right ( 512.0, 0.0) 92 Lower Right ( 512.0, 512.0) 93 Center ( 256.0, 256.0) 94 95This NetCDF files contain 4 datasets, lon_bnds, lat_bnds, tim_bnds and 96tos. Now select the subdataset, described as: ``NETCDF:"sst.nc":tos`` 97``[24x17x180] sea_surface_temperature (32-bit floating-point)`` 98and get the information about the number of bands there is inside this 99variable. 100 101:: 102 103 $ gdalinfo NETCDF:"sst.nc":tos 104 Driver: netCDF/Network Common Data Format 105 Size is 180, 170 106 Coordinate System is `' 107 Origin = (1.000000,-79.500000) 108 Pixel Size = (1.98888889,0.99411765) 109 Metadata: 110 NC_GLOBAL#title=IPSL model output prepared for IPCC Fourth Assessment SRES A2 experiment 111 NC_GLOBAL#institution=IPSL (Institut Pierre Simon Laplace, Paris, France) 112 113.... More metadata 114 115:: 116 117 time#standard_name=time 118 time#long_name=time 119 time#units=days since 2001-1-1 120 time#axis=T 121 time#calendar=360_day 122 time#bounds=time_bnds 123 time#original_units=seconds since 2001-1-1 124 Corner Coordinates: 125 Upper Left ( 1.0000000, -79.5000000) 126 Lower Left ( 1.0000000, 89.5000000) 127 Upper Right ( 359.000, -79.500) 128 Lower Right ( 359.000, 89.500) 129 Center ( 180.0000000, 5.0000000) 130 Band 1 Block=180x1 Type=Float32, ColorInterp=Undefined 131 NoData Value=1e+20 132 Metadata: 133 NETCDF_VARNAME=tos 134 NETCDF_DIMENSION_time=15 135 NETCDF_time_units=days since 2001-1-1 136 Band 2 Block=180x1 Type=Float32, ColorInterp=Undefined 137 NoData Value=1e+20 138 Metadata: 139 NETCDF_VARNAME=tos 140 NETCDF_DIMENSION_time=45 141 NETCDF_time_units=days since 2001-1-1 142 143.... More Bands 144 145:: 146 147 Band 22 Block=180x1 Type=Float32, ColorInterp=Undefined 148 NoData Value=1e+20 149 Metadata: 150 NETCDF_VARNAME=tos 151 NETCDF_DIMENSION_time=645 152 NETCDF_time_units=days since 2001-1-1 153 Band 23 Block=180x1 Type=Float32, ColorInterp=Undefined 154 NoData Value=1e+20 155 Metadata: 156 NETCDF_VARNAME=tos 157 NETCDF_DIMENSION_time=675 158 NETCDF_time_units=days since 2001-1-1 159 Band 24 Block=180x1 Type=Float32, ColorInterp=Undefined 160 NoData Value=1e+20 161 Metadata: 162 NETCDF_VARNAME=tos 163 NETCDF_DIMENSION_time=705 164 NETCDF_time_units=days since 2001-1-1 165 166gdalinfo displays the number of bands into this subdataset. There are 167metadata attached to each band. In this example, the metadata informs us 168that each band correspond to an array of monthly sea surface temperature 169from January 2001. There are 24 months of data in this subdataset. You 170may also use **gdal_translate** for reading the subdataset. 171 172Note that you should provide exactly the contents of the line marked 173**SUBDATASET_n_NAME** to GDAL, including the **NETCDF:** prefix. 174 175The **NETCDF** prefix must be first. It triggers the subdataset NetCDF 176driver. This driver is intended only for importing remote sensing and 177geospatial datasets in form of raster images. If you want explore all 178data contained in NetCDF file you should use another tools. 179 180Dimension 181--------- 182 183The NetCDF driver assume that data follows the CF-1 convention from 184`UNIDATA <http://www.unidata.ucar.edu/software/netcdf/docs/conventions.html>`__ 185The dimensions inside the NetCDF file use the following rules: (Z,Y,X). 186If there are more than 3 dimensions, the driver will merge them into 187bands. For example if you have an 4 dimension arrays of the type (P, T, 188Y, X). The driver will multiply the last 2 dimensions (P*T). The driver 189will display the bands in the following order. It will first increment T 190and then P. Metadata will be displayed on each band with its 191corresponding T and P values. 192 193Georeference 194------------ 195 196There is no universal way of storing georeferencing in NetCDF files. The 197driver first tries to follow the CF-1 Convention from UNIDATA looking 198for the Metadata named "grid_mapping". If "grid_mapping" is not present, 199the driver will try to find an lat/lon grid array to set geotransform 200array. The NetCDF driver verifies that the Lat/Lon array is equally 201space. 202 203If those 2 methods fail, NetCDF driver will try to read the following 204metadata directly and set up georeferencing. 205 206- spatial_ref (Well Known Text) 207 208- GeoTransform (GeoTransform array) 209 210or, 211 212- Northernmost_Northing 213- Southernmost_Northing 214- Easternmost_Easting 215- Westernmost_Easting 216 217Open options 218------------ 219 220The following open options are available: 221 222- **HONOUR_VALID_RANGE**\ =YES/NO: (GDAL > 2.2) Whether to set to 223 nodata pixel values outside of the validity range indicated by 224 valid_min, valid_max or valid_range attributes. Default is YES. 225 226Creation Issues 227--------------- 228 229This driver supports creation of NetCDF file following the CF-1 230convention. You may create set of 2D datasets. Each variable array is 231named Band1, Band2, ... BandN. 232 233Each band will have metadata tied to it giving a short description of 234the data it contains. 235 236GDAL NetCDF Metadata 237-------------------- 238 239All NetCDF attributes are transparently translated as GDAL metadata. 240 241The translation follow these directives: 242 243- Global NetCDF metadata have a **NC_GLOBAL** tag prefixed. 244- Dataset metadata have their **variable name** prefixed. 245- Each prefix is followed by a **#** sign. 246- The NetCDF attribute follows the form: **name=value**. 247 248Example: 249 250:: 251 252 $ gdalinfo NETCDF:"sst.nc":tos 253 Driver: netCDF/Network Common Data Format 254 Size is 180, 170 255 Coordinate System is `' 256 Origin = (1.000000,-79.500000) 257 Pixel Size = (1.98888889,0.99411765) 258 Metadata: 259 260NetCDF global attributes 261 262:: 263 264 NC_GLOBAL#title=IPSL model output prepared for IPCC Fourth Assessment SRES A2 experiment 265 266Variables attributes for: tos, lon, lat and time 267 268:: 269 270 tos#standard_name=sea_surface_temperature 271 tos#long_name=Sea Surface Temperature 272 tos#units=K 273 tos#cell_methods=time: mean (interval: 30 minutes) 274 tos#_FillValue=1.000000e+20 275 tos#missing_value=1.000000e+20 276 tos#original_name=sosstsst 277 tos#original_units=degC 278 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; 279 lon#standard_name=longitude 280 lon#long_name=longitude 281 lon#units=degrees_east 282 lon#axis=X 283 lon#bounds=lon_bnds 284 lon#original_units=degrees_east 285 lat#standard_name=latitude 286 lat#long_name=latitude 287 lat#units=degrees_north 288 lat#axis=Y 289 lat#bounds=lat_bnds 290 lat#original_units=degrees_north 291 time#standard_name=time 292 time#long_name=time 293 time#units=days since 2001-1-1 294 time#axis=T 295 time#calendar=360_day 296 time#bounds=time_bnds 297 time#original_units=seconds since 2001-1-1 298 299Important Changes 300~~~~~~~~~~~~~~~~~ 301 302- Added support for NC2, NC4 and NC4C file types for reading and 303 writing, and HDF4 for reading. See `NetCDF File 304 Format <http://www.unidata.ucar.edu/software/netcdf/docs/netcdf/File-Format.html#File-Format>`__ 305 for details. 306 307 - ``NC`` : NetCDF Classic Format: The Original Binary Format. 308 - ``NC2`` : 64-bit Offset Format: Supporting Larger Variables 309 - ``NC4`` : NetCDF-4 Format: Uses HDF5 310 - ``NC4C`` : NetCDF-4 Classic Model Format: HDF5 with NetCDF 311 Limitations 312 - ``HDF4`` : HDF4 SD Format 313 314- Improved support for CF-1.5 projected and geographic SRS reading and 315 writing 316 317- Improvements to metadata (global and variable) handling 318 319- Added simple progress indicator 320 321- Added support for DEFLATE compression (reading and writing) and szip 322 (reading) - requires NetCDF-4 support 323 324- Added support for valid_range/valid_min/valid_max 325 326- Proper handling of signed/unsigned byte data 327 328- Added support for Create() function - enables to use NetCDF directly 329 with gdalwarp 330 331- Added support for CF two-dimensional coordinate variables (see `CF 332 Conventions <http://cfconventions.org/1.6.html#idp5559280>`__) via 333 GDAL GEOLOCATION arrays (see :ref:`rfc-4`) 334 335Creation Options 336~~~~~~~~~~~~~~~~ 337 338- **FORMAT=[NC/NC2/NC4/NC4C]**: Set the NetCDF file format to use, NC 339 is the default. NC2 is normally supported by recent NetCDF 340 installations, but NC4 and NC4C are available if NetCDF was compiled 341 with NetCDF-4 (and HDF5) support. 342- **COMPRESS=[NONE/DEFLATE]**: Set the compression to use. DEFLATE is 343 only available if NetCDF has been compiled with NetCDF-4 support. 344 NC4C format is the default if DEFLATE compression is used. 345 346- **ZLEVEL=[1-9]**: Set the level of compression when using DEFLATE 347 compression. A value of 9 is best, and 1 is least compression. The 348 default is 1, which offers the best time/compression ratio. 349 350- **WRITE_BOTTOMUP=[YES/NO]**: Set the y-axis order for export, 351 overriding the order detected by the driver. NetCDF files are usually 352 assumed "bottom-up", contrary to GDAL's model which is "north up". 353 This normally does not create a problem in the y-axis order, unless 354 there is no y axis geo-referencing. The default for this setting is 355 YES, so files will be exported in the NetCDF default "bottom-up" 356 order. For import see Configuration Option GDAL_NETCDF_BOTTOMUP 357 below. 358 359- **WRITE_GDAL_TAGS=[YES/NO]**: Define if GDAL tags used for 360 georeferencing (spatial_ref and GeoTransform) should be exported, in 361 addition to CF tags. Not all information is stored in the CF tags 362 (such as named datums and EPSG codes), therefore the driver exports 363 these variables by default. In import the CF "grid_mapping" variable 364 takes precedence and the GDAL tags are used if they do not conflict 365 with CF metadata. 366 367- **WRITE_LONLAT=[YES/NO/IF_NEEDED]**: Define if CF lon/lat variables 368 are written to file. Default is YES for geographic SRS and NO for 369 projected SRS. This is normally not necessary for projected SRS as 370 GDAL and many applications use the X/Y dimension variables and CF 371 projection information. Use of IF_NEEDED option creates lon/lat 372 variables if the projection is not part of the CF-1.5 standard. 373 374- **TYPE_LONLAT=[float/double]**: Set the variable type to use for 375 lon/lat variables. Default is double for geographic SRS and float for 376 projected SRS. If lon/lat variables are written for a projected SRS, 377 the file is considerably large (each variable uses X*Y space), 378 therefore TYPE_LONLAT=float and COMPRESS=DEFLATE are advisable in 379 order to save space. 380 381- **PIXELTYPE=[DEFAULT/SIGNEDBYTE]**: By setting this to SIGNEDBYTE, a 382 new Byte file can be forced to be written as signed byte. 383 384Configuration Options 385~~~~~~~~~~~~~~~~~~~~~ 386 387- **GDAL_NETCDF_BOTTOMUP=[YES/NO]** : Set the y-axis order for import, 388 overriding the order detected by the driver. This option is usually 389 not needed unless a specific dataset is causing problems (which 390 should be reported in GDAL trac). 391 392VSI Virtual File System API support 393----------------------------------- 394 395Since GDAL 2.4, and with Linux kernel >=4.3 and libnetcdf >=4.5, read 396operations on /vsi file systems are supported. 397 398NetCDF-4 groups support on reading (GDAL >= 3.0) 399------------------------------------------------ 400 401The driver has undergone significant changes in GDAL 3.0 to support 402NetCDF-4 groups on reading: 403 404- Explore recursively all nested groups to create the subdatasets list 405 406- Subdatasets in nested groups use the /group1/group2/.../groupn/var 407 standard NetCDF-4 convention, except for variables in the root group 408 which do not have a leading slash for backward compatibility with the 409 NetCDF-3 driver 410 411- Global attributes of each nested group are also collected in the GDAL 412 dataset metadata, using the same convention 413 /group1/group2/.../groupn/NC_GLOBAL#attr_name, except for the root 414 group which do not have a leading slash for backward compatibility 415 416- When searching for a variable containing auxiliary information on the 417 selected subdataset, like coordinate variables or grid_mapping, we 418 now also search in parent groups and their children as specified in 419 `Support of groups in 420 CF <https://github.com/cf-convention/cf-conventions/issues/144>`__ 421 422Multidimensional API support 423---------------------------- 424 425.. versionadded:: 3.1 426 427The netCDF driver supports the :ref:`multidim_raster_data_model` for reading and 428creation operations. 429 430The :cpp:func:`GDALGroup::GetGroupNames` method supports the following options: 431 432- GROUP_BY=SAME_DIMENSION. If set, single-dimensional variables will be exposed 433 as a "virtual" subgroup. This enables the user to get a clearer organization of 434 variables, for example in datasets where variables belonging to different 435 trajectories are indexed by different dimensions but mixed in the same netCDF 436 group. 437 438The :cpp:func:`GDALGroup::OpenGroup` method supports the following options: 439 440- GROUP_BY=SAME_DIMENSION. See above description 441 442The :cpp:func:`GDALGroup::GetMDArrayNames` method supports the following options: 443 444- SHOW_ALL=YES/NO. Defaults to NO. If set to YES, all variables will be listed. 445- SHOW_ZERO_DIM=YES/NO. Defaults to NO. If set to NO, variables with 0-dimension 446 will not be listed. 447- SHOW_COORDINATES=YES/NO. Defaults to YES. If set to NO, variables refererenced 448 in the ``coordinates`` attribute of another variable will not be listed. 449- SHOW_BOUNDS=YES/NO. Defaults to YES. If set to NO, variables refererenced 450 in the ``bounds`` attribute of another variable will not be listed. 451- SHOW_INDEXING=YES/NO. Defaults to YES. If set to NO, 452 single-dimensional variables whose name is equal to the name of their indexing 453 variable will not be listed. 454- SHOW_TIME=YES/NO. Defaults to YES. If set to NO, 455 single-dimensional variables whose ``standard_name`` attribute is "time" 456 will not be listed. 457- GROUP_BY=SAME_DIMENSION. If set, single-dimensional variables will not be listed 458 459The :cpp:func:`GDALGroup::CreateMDArray` method supports the following options: 460 461- NC_TYPE=NC_CHAR/NC_BYTE/NC_INT64/NC_UINT64: to overload the netCDF data type 462 normally deduced from the GDAL data type passed to CreateMDArray(). 463 NC_CHAR can only be used for strings of a fixed size. 464- BLOCKSIZE=size_dim0,size_dim1,...,size_dimN: to set the netCDF chunk size, 465 as set by nc_def_var_chunking(). There must be exactly as many values as the 466 number of dimensions passed to CreateMDArray() 467- COMPRESS=DEFLATE: to ask for deflate compression 468- ZLEVEL=number: DEFLATE compression level (1-9) 469- CHECKSUM=YES/NO: Whether to turn on Fletcher32 checksums. Checksum generation 470 requires chunking, and if no explicit chunking has been asked with the 471 BLOCKSIZE option, a default one will be used. Defaults to NO. 472- FILTER=filterid,param1,...,paramN: Define a filter (typically a compression 473 method) used for writing. This should be a list of numeric values, separated 474 by commas. The first value is the filter id (list of potential values at 475 https://support.hdfgroup.org/services/contributions.html#filters) and following 476 values are per-filter parameters. More details about netCDF-4 filter support at 477 https://www.unidata.ucar.edu/software/netcdf/docs/md__Users_wfisher_Desktop_docs_netcdf-c_docs_filters.html 478 479Driver building 480--------------- 481 482This driver is compiled with the UNIDATA NetCDF library. 483 484You need to download or compile the NetCDF library before configuring 485GDAL with NetCDF support. 486 487See `NetCDF GDAL wiki <http://trac.osgeo.org/gdal/wiki/NetCDF>`__ for 488build instructions and information regarding HDF4, NetCDF-4 and HDF5. 489 490See Also: 491--------- 492 493- :ref:`Vector side of the netCDF driver. <vector.netcdf>` 494- `NetCDF CF-1.5 495 convention <http://cf-pcmdi.llnl.gov/documents/cf-conventions/1.5/cf-conventions.html>`__ 496- `NetCDF compiled 497 libraries <http://www.unidata.ucar.edu/downloads/netcdf/index.jsp>`__ 498- `NetCDF 499 Documentation <http://www.unidata.ucar.edu/software/netcdf/docs/>`__ 500