登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2014-4-6 17:57 编辑
写了一个将netCDF数据转为GrADS数据的脚本程序,需要MeteoInfo最新文件的支持(见置顶帖子)。GrADS的二进制格式数据比较简单,容易用Fortran等程序读取,而netCDF数据格式比较复杂,用程序读取有些难度。这个脚本程序需要定义一些GrADSDataInfo的参数,然后就按照这些参数自动生成control文件。
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2012-5-28
- # Purpose: Convert NetCDF data to GrADS binary data
- # Note: Sample
- #-----------------------------------------------------------
- import clr
- from System import *
- clr.AddReference("MeteoInfoC.dll")
- from MeteoInfoC import *
- from MeteoInfoC.Data import *
- from MeteoInfoC.Data.MeteoData import *
- #---- Set data folders
- dataDir = 'D:\\Temp\\nc\\'
- #---- Set input/output data files
- inFile = dataDir + 'HadISST_SST_update.nc'
- outCtlFile = dataDir + 'HadISST_SST_update.ctl'
- outDataFile = dataDir + 'HadISST_SST_update.dat'
- #---- Define data info
- ncDataInfo = MeteoDataInfo()
- gDataInfo = GrADSDataInfo()
- #---- Open NetCDF data file
- ncDataInfo.OpenNCData(inFile)
- xArray = ncDataInfo.GetX()
- yArray = ncDataInfo.GetY()
- tNum = ncDataInfo.GetTimeNumber()
- sTime = ncDataInfo.GetTime(0)
- #---- Set output GrADS data info
- gDataInfo.FileName = outCtlFile
- gDataInfo.DSET = outDataFile
- gDataInfo.TITLE = 'HadISST data'
- gDataInfo.DTYPE = 'GRIDDED'
- gDataInfo.XDEF.Type = 'LINEAR'
- gDataInfo.XDEF.XNum = xArray.Length
- gDataInfo.XDEF.XMin = xArray[0]
- gDataInfo.XDEF.XDelt = xArray[1] - xArray[0]
- gDataInfo.YDEF.Type = 'LINEAR'
- gDataInfo.YDEF.YNum = yArray.Length
- gDataInfo.YDEF.YMin = yArray[0]
- gDataInfo.YDEF.YDelt = yArray[1] - yArray[0]
- gDataInfo.ZDEF.Type = 'LINEAR'
- gDataInfo.ZDEF.ZNum = 1
- gDataInfo.ZDEF.SLevel = 1
- gDataInfo.ZDEF.ZDelt = 1
- gDataInfo.TDEF.Type = 'LINEAR'
- gDataInfo.TDEF.TNum = tNum
- gDataInfo.TDEF.STime = sTime
- gDataInfo.TDEF.TDelt = '1mo'
- aVar = Variable()
- aVar.Name = 'sst'
- aVar.Units = '99'
- aVar.Description = 'Sea Surface Temporature'
- gDataInfo.VARDEF.AddVar(aVar)
- gDataInfo.MissingValue = ncDataInfo.MissingValue
- #---- Write GrADS data file
- gDataInfo.CreateDataFile(outDataFile)
- for t in range(0, tNum):
- ncDataInfo.TimeIndex = t
- print t
- sst = ncDataInfo.GetGridData('sst')
- if t == 0:
- gDataInfo.MissingValue = sst.MissingValue
- print gDataInfo.MissingValue
- gDataInfo.WriteGridData(sst)
- gDataInfo.CloseDataFile()
- #---- Write GrADS control file
- gDataInfo.WriteGrADSCTLFile()
- print 'Finished...'
netCDF数据sst等值线图:
转为GrADS格点数据sst等值线图:
|