NetCDF (.nc)
- Import supports Version 3 and 4 of the netCDF format.
- Export supports Version 3 of the netCDF format.
Background & Context

-
- MIME type: application/x-netcdf
- NetCDF data file format.
- Self-describing format for exchanging scientific data.
- Used in atmospheric research, GIS, and related fields.
- NetCDF is an acronym derived from network Common Data Form.
- Binary file format.
- Conceptually based on NASA's Common Data Format, but incompatible with this format.
- Developed by the Unidata center at the University Corporation for Atmospheric Research (UCAR).
Import & Export

- Import["file.nc"] imports a netCDF file, returning the names of the datasets stored in the file.
- Import["file.nc",elem] imports the specified element from a netCDF file.
- The import format can be specified with Import["file","NetCDF"] or Import["file",{"NetCDF",elem,…}].
- Export["file.nc",expr] exports a numeric array to netCDF.
- Export["file.nc",{expr1,…}, {"Datasets",{"/dataset1",…}}] creates a netCDF file, storing the data arrays {expr1,…} as separate datasets.
- Export["file.nc",expr,elem] exports the specified element to a netCDF file.
- Export["file.nc",{elem1->expr1,elem2->expr2,…},"Rules"] uses rules to specify the elements to be exported.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Import Elements



- General Import elements:
-
"Elements" list of elements and options available in this file "Rules" full list of rules for each element and option "Options" list of rules for options, properties, and settings - Structure elements:
-
"Datasets" names of all datasets "Groups" names of all groups "Summary" summary of properties "Version" netCDF version of the file - Names of groups and datasets are given as the absolute paths starting with the root group name "/".
- Import by default uses the "Datasets" element for the netCDF format.
- Data representation elements:
-
"Data" all datasets imported as an association {"Data",dataset} or dataset named dataset - The following basic data types are supported:
-
"Integer8" 8-bit integers "Integer16" 16-bit integers "Integer32" 32-bit integers "Integer64" 64-bit integers "UnsignedInteger8" 8-bit unsigned integers "UnsignedInteger16" 16-bit unsigned integers "UnsignedInteger32" 32-bit unsigned integers "UnsignedInteger64" 64-bit unsigned integers "Real32" IEEE single‐precision numbers "Real64" IEEE double‐precision numbers "String" string of ASCII characters - The following structured data types are supported:
-
"ByteArray" a ByteArray of an arbitrary length "Enum" an enumeration "Compound" a compound dataset consisting of any other data format and other compound datasets - Metadata elements:
-
"Attributes" attributes of all groups and datasets "DataEncoding" specifies how each dataset is compressed "DataFormat" type used to represent each dataset "Dimensions" data dimensions of each dataset "DimensionNames" names of dimensions of each dataset {"metadata",dataset} metadata of the named dataset "Metadata" global attributes (attributes of the root group)
Export Elements

- General Export element:
-
"Rules" a list of imported elements in the form of elemexpr - Export["file.nc",{elem1->expr1,…},"Rules"] uses rules to specify the elements to be exported.
- Available Export elements:
-
"Datasets" datasets and their associated elements - With the "Datasets" element, the following expressions can be given:
-
data stores data under "Dataset1" {"name1"data1,…} a list of dataset names and their associated data {"name1"ds1,…} specifies each dataset dsi using a list of rules
Examples
open allclose allBasic Examples (3)
Scope (6)
Show all elements available in the file:
Import, by default, returns the list of datasets in the file:
Import contents of a dataset by specifying its name:
Import dimensions and data format for all datasets in the file:
Import Elements (23)
Attributes (3)
Data (3)
DataFormat (2)
Dimensions (3)
DimensionNames (2)
Metadata (2)
NamedDimensions (3)
Applications (1)
Download a netCDF file with sea surface temperature data:
Import general information about the file:
Get the list of all datasets in the file:
Read attributes of every dataset:
Get a description of every dataset to see what they contain:
Read all attributes of the "/sst" dataset:
Import dimensions of the dataset; notice that time is the first dimension:
Determine the range of collected data (removing duplicated first) and add a small margin to it:
Visualize the changes of sea surface temperature:
Learn more about the file contents by inspecting metadata, for instance, how the data was collected: