Recipe: IDL program to read data from downloaded file
Back to G5NR Data Access Guide.
Problem
We want to read a downloaded data file using IDL.
Solution
For the purpose of this example, we assume that we have already downloaded the file c1440_NR.inst01hr_3d_T_Cv.20060918_0900z.nc4
from the ftp/http server. For more information about file naming conventions, and how to download a file from the ftp server, please follow the links in the #See Also section.
Code
The code below reads the global temperature data from file, computes the maximum and minimum temperatures and plots (using the matplotlib
package) the aire temperature at the surface (level=71). It has been tested with IDL v 8.3.
; file
file = 'c1440_NR.inst01hr_3d_T_Cv.20060918_0900z.nc4'
; read data from file
ncid = ncdf_open(file)
ncdf_varget, ncid, 'T', T
ncdf_close, ncid
; max/min of T
print, 'max(T):', max(T)
print, 'min(T):', min(T)
; plot T at the surface
lons = findgen(720)*0.5-180.
lats = findgen(361)*0.5-90.
basemap = map('Cylindrical Equal Area', limit=[-90., -180., 90., 180.])
cntrplot = contour( $
T[*,*,71], $ ;; level=71 => surface
lons, $
lats, $
grid_units=2, $ ;; degrees
n_levels=20, $
rgb_table=34, $
;; /fill, $
/overplot, $
title='surface air temperature' $
)
cntnt = mapcontinents(/countries)
END
Output
Running this IDL script
IDL> .run g5nr_reader.pro
we get the text output
max(T): 315.651 min(T): 180.367
and the plot
Discussions
Modifications to read a subset of the data
The above python code can be easily modified to read a subset of the data instead. For example, to read temperature data inside the box bounded by latitudes 25oN, 50oN and longitudes -130oN, -65oN, we will replace line 15 in the code above by
T = rootgrp.variables['T'][0,:,229:280,99:230]
The conversion of lat/lon co-ordinates to indices is left as an exercise for the user.
Running the modified script, produces the text output
rootgrp.variables['T'].shape (1, 72, 361, 720) Reading T... done. T.shape: (72, 51, 131) min(T): 191.6956 max(T): 305.6048
See Also
- File Spec: File:G5NR-Ganymed-7km FileSpec-ON6-V1.0.pdf
- Recipe: Retrieve (global) data from FTP server