NetCDF (Network Common Data Format) files have a .nc suffix, and the data structure in the file contains three description types: dimensions, variables, and attributes, each of which is assigned a name and an ID.
Mathematically, the data stored by netcdf is a single-valued function with multiple independent variables. With the formula is f(x,y,z,...) = value, the function of the independent variables x, y, z, etc. in netcdf is called dimension (dimension) or axis (axis), the function value in netcdf is called variable (Variables). And the independent variables and function values in the physics of some of the properties, such as units of measurement (scale), the name of physics, etc. in netcdf is called attributes (Attributes).
NetCDF name{ Dimensions:… // Define dimensions Variables:… // Define variables Attributes:… //Properties Data:…// Data }
Reading .nc files can be done with python's netCdf4 module or with ncbrowser, here I used Matlab.
MATLAB features numerical analysis, numerical and symbolic computation, engineering and scientific drawing, design and simulation of control systems, digital image processing, digital signal processing, and financial and fiscal engineering.
This is the basic interface of matlab when it is opened, with the command ribbon at the top, the command line input field at the right, the folder details in the current path at the top left, and the software workspace at the bottom left.
Commands to read nc files
%% Display structure
% ncdisp(ncFilePath);% displays all the structure of the nc file to get a rough idea of what's in it
% ncdisp(ncFilePath,'evap');% display the contents of the specified variable, note that it must be a variable variable.
% ncdisp(ncFilePath,'/','min');% Simple display of the structure as well as the definitions
% ncdisp(ncFilePath,'/','full');% show all structure and definition information in full
Then ncread is called to read the value of the variable:
vardata = ncread(source,varname) vardata = ncread(source,varname,start,count,stride)
(1)start
The position at which to start reading each dimension of the variable specified by varname.
(2)count
Number of elements of each dimension read from the start position specified by start
(3)stride
The step size of each dimension read when the number of reads per dimension from start is count
Update: reading .nc files with python
Installing the netCDF4 library
Import nc library, read file information with Dataset function
() read all variable names
() read all variable information
Reading the value of a single variable
This is how to use Matlab and Python to read Netcdf files in detail, for more information about Matlab and Python to read Netcdf files, please pay attention to my other related articles!