gdal Read a netCDF file with gdal Read a netCDF file (.nc) with python gdal


Example

How to read a netCDF file (.nc) with python gdal ?

import gdal

# Path of netCDF file
netcdf_fname = "/filepath/PREVIMER_WW3-GLOBAL-30MIN.nc"

# Specify the layer name to read
layer_name = "hs"

# Open netcdf file.nc with gdal
ds = gdal.Open("NETCDF:{0}:{1}".format(netcdf_name, layer_name))

# Read full data from netcdf
data = ds.ReadAsArray(0, 0, ds.RasterXSize, ds.RasterYSize)
data[data < 0] = 0

netCDF display