read data with time
py3gradsではtime, lat, lonの3つをgrads上で範囲を与えてデータを読み込むとうまく読み込めないので,grads上ではlat, lonのみを範囲を与えてtimeについては1点のみを指定し,そのtimeを順次変更してpythonにデータを読み込む.例は以下のとおり
from py3grads import Grads
# Reading a grads data using py3grads
ctl_fn_fl='/data/REANALYSES/JRA55/grd_san/fcst_surf.san/PRESsfc_san.ctl'
ga = Grads(verbose=False)
ga('open ' + ctl_fn_fl)
ret=ga('q file 1')
tsz=int(ret[0][4].split(' ')[16])
ga('set lon 150 250') # longitue & latitude range is set for just faster reading
ga('set lat 20 80')
ga('set t 1')
lons2d=ga.exp('lon')
lats2d=ga.exp('lat')
lons1d=lons2d[0,:]
lats1d=lats2d[:,0]
pressfc_djf=np.zeros([tsz,ysz,xsz])
for t in range(tsz):
ga('set t %d'%(t+1))
pressfc_djf[t,:,:]=ga.exp('v1')