PyGrADS可以很方便地将GrADS中的变量导入Python内存空间

请看下面的例子:

from pylab import *
from grads import GrADS

# Start GrADS and open the data file
# ----------------------------------
ga = GrADS(Bin='grads',Echo=False,Port=True,Window=False)
ga.open('../data/model.ctl')

# XY slices
# ---------
ts1 = ga.exp('ts')   #ts1.shape=(46,73)
ts2 = ga.expr('ts')  #ts2.shape=(46,73)
print("XY Skin temperature: ")
print(ts1.data-ts2.data)

# XYT slices
# ----------
ga('set t 2 3')
ts1 = ga.exp('ts') #ts1.shape=(2,46,73)
ts2 = ga.expr('ts')#ts2.shape=(2,46,73)
print("XYT Skin temperature: ")
print(ts1.data-ts2.data)

# XYZ slices
# ----------
ga('set t 3')
ga('set z 5 6')
xx1 = ga.exp('ua')#xx1.shape=(2, 46, 73)
xx2 = ga.expr('ua')#xx2.shape=(2, 46, 73)
print("XYZ Zonal Wind")
print(xx1.data-xx2.data)

# XZT slices
# ----------
ga('set t 2 4')
ga('set z 1 5')
ga('set y 20')
xx2 = ga.expr('ua')#xx2.shape=(3,5,73)
print("XZT Zonal Wind")
print(xx2)

exp()和expr()的区别在于exp()导出的变量可以使用imp('gvarname',pyvarname)再导入回GrADS中,而expr则不行.

这是因为使用exp导出的时候保留了原始变量的所有信息,expr则只导出数据而已.

你可能感兴趣的:(python,PyGrADS,GrADS)