Last active
December 3, 2021 08:43
-
-
Save blaylockbk/37dfcba1a6b31a4d6ccd350a5283c976 to your computer and use it in GitHub Desktop.
Basics of opening NetCDF files with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#from netCDF4 import Dataset # use scipy instead | |
from scipy.io import netcdf #### <--- This is the library to import. | |
# Open file in a netCDF reader | |
directory = './' | |
wrf_file_name = directory+'filename' | |
nc = netcdf.netcdf_file(wrf_file_name,'r') | |
#Look at the variables available | |
nc.variables | |
#Look at the dimensions | |
nc.dimensions | |
#Look at a specific variable's dimensions | |
nc.variables['T2'].dimensions ## output is ('Time', 'south_north', 'west_east') | |
#Look at a specific variable's units | |
nc.variables['T2'].units ## output is ('K') | |
####### | |
#update: you should use xarray now to read netcdf files |
thanks a lot mate (-:
hi, I get this when I try to import NetCDF "No module named 'scipy'". how do I deal with it?
hi, I get this when I try to import NetCDF "No module named 'scipy'". how do I deal with it?
pip install scipy
or conda install scipy
in your terminal :-)
cant't find coltbls?
@fipoucat You only need to import the scipy module.
But this is a really old gist. I would recommend using xarray to read netcdf files instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
really helping!