Skip to content

Instantly share code, notes, and snippets.

@ict4eo
Last active December 31, 2015 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ict4eo/8023769 to your computer and use it in GitHub Desktop.
Save ict4eo/8023769 to your computer and use it in GitHub Desktop.
Quick view of netCDF file (param/lat/lon type)
import gdal
import netCDF4
import sys
import matplotlib.pyplot as plt
def plot(file_path, title=""):
gdal_data = gdal.Open(file_path)
arr = gdal_data.ReadAsArray()
#print "shapes", arr.shape, arr.dtype
plt.imshow(arr)
plt.colorbar()
plt.title(title)
plt.show()
var_name = 'airtemp'
file_path_out = '/path/to/%s/daily/' % var_name
root_name = 'ecmwf_2mtemperature_fulldaily_0.125deg_-22S16E-35S33E_'
year = 2001
day = 181
file_name = root_name + str(year) + '_avg_%03d.nc' % day
data_path = file_path_out + file_name
plot(data_path, file_name)
file_name = root_name + str(year) + '_avg_%03d_studyarea.nc' % day
data_path = file_path_out + file_name
plot(data_path, file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment