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 surface (level=71) temperature. It has been tested with IDL v 8.1.
; 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.
ct = colortable(72, /reverse)
cntrplot = contour( $
T[*,*,71], $ ;; level=71 => surface
lons, $
lats, $
/fill, $
n_levels=20, $
rgb_table=ct, $
title='surface air temperature' $
)
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