forked from Unidata/netcdf4-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubset.py
More file actions
15 lines (14 loc) · 647 Bytes
/
subset.py
File metadata and controls
15 lines (14 loc) · 647 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# use 'orthogonal indexing' feature to subselect data over CONUS.
import netCDF4
import numpy as np
import matplotlib.pyplot as plt
# use real data from CFS reanalysis.
# note: we're reading GRIB2 data!
URL="http://nomads.ncdc.noaa.gov/thredds/dodsC/modeldata/cmd_flxf/2010/201007/20100701/flxf00.gdas.2010070100.grb2"
nc = netCDF4.Dataset(URL)
lats = nc.variables['lat'][:]; lons = nc.variables['lon'][:]
latselect = np.logical_and(lats>25,lats<50)
lonselect = np.logical_and(lons>230,lons<305)
data = nc.variables['Soil_moisture_content'][0,0,latselect,lonselect]
plt.contourf(data[::-1]) # flip latitudes so they go south -> north
plt.show()