
Then any metadata item can be accessed with its key.

Metadata can also be accessed as a Python dictionary, which (in my opinion) is more useful. This file only contains one time step (time dimension is 1). With these variables we can find the precipitation at a given location for a given time.

The variables we’re interested in are lat, lon, time, and prcp (precipitation). root group (NETCDF4_CLASSIC data model, file format HDF5): start_year: 1980 source: Daymet Software Version 3.0 Version_software: Daymet Software Version 3.0 Version_data: Daymet Data Version 3.0 Conventions: CF-1.6 citation: Please see for current Daymet data citation information references: Please see for current information on Daymet references dimensions(sizes): time(1), nv(2), y(8075), x(7814) variables(dimensions): float32 time_bnds(time,nv), int16 lambert_conformal_conic(), float32 lat(y,x), float32 lon(y,x), float32 prcp(time,y,x), float32 time(time), float32 x(x), float32 y(y) groups:Ībove you can see information for the file format, data source, data version, citation, dimensions, and variables. Printing the dataset, ds, gives us information about the variables contained in the file and their dimensions. netCDF4 allows us to access the metadata and data associated with a NetCDF file. Variables contain both metadata and data. import netCDF4 as nc fn = '/path/to/file.nc4' ds = nc.Dataset(fn) General File StructureĪ NetCDF file has three basic parts: metadata, dimensions and variables. For this article, I’m using a file containing climate data from Daymet. Loading a dataset is simple, just pass a NetCDF file path to netCDF4.Dataset(). To be sure your netCDF4 module is properly installed start an interactive session in the terminal (type python and press ‘Enter’).

To install with anaconda (conda) simply type conda install netCDF4. I generally recommend using the anaconda Python distribution to eliminate the confusion that can come with dependencies and versioning. For this article we’ll focus strictly on netCDF4 as it is my personal preference.įor information on how to read and plot NetCDF data in Python with xarray and rioxarray check out this article. NetCDF files can be read with a few different Python modules. This article will get you started with reading data from NetCDF files using Python. NetCDF provides a solution for these challenges. When each value is also assigned to a geographic location, data management is further complicated. With multiple measurements per day, data values accumulate quickly and become unwieldy to work with. Variables stored in NetCDF are often measured multiple times per day over large (continental) areas.

Some examples of these data are temperature, precipitation, and wind speed. Network common data form (NetCDF) is commonly used to store multidimensional geographic data.
