Recipe: Python program as OPeNDAP client: Difference between revisions

Pchakrab (talk | contribs)
Move from http to https
 
(2 intermediate revisions by one other user not shown)
Line 4: Line 4:


By accessing the collection <code>inst01hr_3d_T_Cv</code> via the OPeNDAP server
By accessing the collection <code>inst01hr_3d_T_Cv</code> via the OPeNDAP server
  http://opendap.nccs.nasa.gov/dods/OSSE/G5NR/Ganymed/7km
  https://opendap.nccs.nasa.gov/dods/OSSE/G5NR/Ganymed/7km


we want to read the surface temperature data inside the box bound by latitudes 25<sup>o</sup>N, 50<sup>o</sup>N and longitudes -130<sup>o</sup>W, -65<sup>o</sup>W for 2006/Sep/18, 9z, compute its min/max and plot the temperature data.
we want to read the surface temperature data inside the box bound by latitudes 25<sup>o</sup>N, 50<sup>o</sup>N and longitudes -130<sup>o</sup>W, -65<sup>o</sup>W for 2006/Sep/18, 9z, compute its min/max and plot the temperature data.
Line 16: Line 16:


==== Code ====
==== Code ====
The code below reads the temperature data inside the box bounded by latitudes 25<sup>o</sup>N, 50<sup>o</sup>N and longitudes -130<sup>o</sup>N, -65<sup>o</sup>N, computes the maximum and minimum temperatures and plots (using the matplotlib package) the surface (level=71) temperature.
This code accesses the collection <code>inst01hr_3d_T_Cv</code> from the OPeNDAP server, reads a subset of the temperature data (all levels inside the bounding box specified above) and computes its max/min. It then plots the data at the surface (level=72).
 
This code accesses the collection <code>inst01hr_3d_T_Cv</code> from the OPeNDAP server and reads a subset of the temperature data (all levels inside the bounding box specified above) and computes its max/min. It then computes the max/min of the above data at the surface (level=72).


NOTE:
NOTE:
Line 35: Line 33:
from mpl_toolkits.basemap import Basemap
from mpl_toolkits.basemap import Basemap


rootgrp = nc4.Dataset('http://opendap.nccs.nasa.gov:9090/dods/OSSE/G5NR/Ganymed/7km/0.5000_deg/inst/inst01hr_3d_T_Cv', 'r')
rootgrp = nc4.Dataset('https://opendap.nccs.nasa.gov:9090/dods/OSSE/G5NR/Ganymed/7km/0.5000_deg/inst/inst01hr_3d_T_Cv', 'r')
print "rootgrp.variables['t'].shape", rootgrp.variables['t'].shape
print "rootgrp.variables['t'].shape", rootgrp.variables['t'].shape