- 积分
- 55946
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2014-9-14 19:23 编辑
从格点数据中提取某个点的数据其实就是一个插值过程,通常用双线性插值,MeteoInfo的格点数据类GridData有toStation(double x, double y)方法用双线性插值方法从格点数据中获取某个点的数据。下面两个脚本程序演示了从GDAS再分析数据中获取某点的边界层高度和三维风向风速数据,示例程序用的数据格式是ARL(HYSPLIT模式用的),不过只要是MeteoInfo支持的数据格式(比如netCDF, GRIB等)都可以用下面的脚本程序(只需做简单的改动)。脚本程序里有比较丰富的注释,这里就不多说了。需要说明在Java的Calendar中月份是从0开始的,因此月设为10其实是11月。
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-9-11
- # Purpose: Extract station PBL data from ARL meteorological data
- # Note: Sample
- #-----------------------------------------------------------
- from org.meteoinfo.data.meteodata import MeteoDataInfo
- import os.path
- from java.util import Date
- from java.util import Calendar
- from java.util import Locale
- from java.text import SimpleDateFormat
- #---- Set directories
- dataDir = 'P:/MetData/MetData/2011/'
- #---- Set times - this case show seasonal variation
- cal = Calendar.getInstance()
- cal.set(2011, 10, 1)
- sTime = cal.getTime()
- cal.set(2011, 11, 1)
- eTime = cal.getTime()
- aTime = sTime
- format = SimpleDateFormat('MMMyy', Locale.ENGLISH)
- format1 = SimpleDateFormat('yyyy-MM-dd HH:00')
- format2 = SimpleDateFormat('yyyyMMddHH')
- cal.setTime(sTime)
- #---- Create a MeteoDataInfo object
- mydata = MeteoDataInfo()
- #---- Set lon/lat of the location
- lon = 20.5
- lat = 40.5
- #---- Set output text file
- outpath = os.path.join(dataDir, 'PBL_data-1.txt')
- outf = open(outpath, 'w')
- outf.write('Time,PBLH')
- #---- Loop
- i = 0
- sum = 0.0
- while aTime <= eTime:
- for w in range(5):
- inFile = dataDir + "gdas1." + format.format(aTime) + ".w" + str(w + 1)
- print inFile
- if os.path.isfile(inFile):
- mydata.openARLData(inFile) #Open ARL data file
- tNum = mydata.getDataInfo().getTimeNum()
- print tNum
- for t in range(tNum):
- dTime = mydata.getDataInfo().getTimes().get(t)
- print format1.format(dTime)
- mydata.setTimeIndex(t) #Set time index
- gData = mydata.getGridData("PBLH") #Get PBLH grid data
- pblh = gData.toStation(lon, lat) #Intepolate PBLH data to the location
- print 'PBLH = %10.2f' %pblh
- outf.write(os.linesep)
- outf.write(format2.format(dTime) + ',%-7.2f ' %pblh)
- sum += pblh
- i += 1
-
- cal.add(Calendar.MONTH, 1)
- aTime = cal.getTime()
- outf.close()
- #---- Calculate seasonal average PBLH value
- ave = sum / i
- print 'Average PBLH: %10.2f' %ave
- print 'Finished!'
- #--------------------------------------------------------
- # Author: Yaqiang Wang
- # Date: 2014-9-11
- # Purpose: Extract station wind data from ARL meteorological data
- # Note: Sample
- #-----------------------------------------------------------
- from org.meteoinfo.data import DataMath
- from org.meteoinfo.data.meteodata import MeteoDataInfo
- import os.path
- from java.util import Date
- from java.util import Calendar
- from java.util import Locale
- from java.text import SimpleDateFormat
- #---- Set directories
- dataDir = 'P:/MetData/MetData/2011/'
- #---- Set times - this case show seasonal variation
- cal = Calendar.getInstance()
- cal.set(2011, 10, 1)
- sTime = cal.getTime()
- cal.set(2011, 10, 10)
- eTime = cal.getTime()
- aTime = sTime
- format = SimpleDateFormat('MMMyy', Locale.ENGLISH)
- format1 = SimpleDateFormat('yyyy-MM-dd HH:00')
- format2 = SimpleDateFormat('yyyyMMddHH')
- cal.setTime(sTime)
- #---- Create a MeteoDataInfo object
- mydata = MeteoDataInfo()
- #---- Set lon/lat of the location
- lon = 20.5
- lat = 40.5
- #---- Set output text file
- outpath = os.path.join(dataDir, 'wind_data.txt')
- outf = open(outpath, 'w')
- outf.write('Time,Pressure,WindDir,WindSpeed')
- #---- Loop
- while aTime <= eTime:
- for w in range(5):
- inFile = dataDir + 'gdas1.' + format.format(aTime) + '.w' + str(w + 1)
- print inFile
- if os.path.isfile(inFile):
- mydata.openARLData(inFile) #Open ARL data file
- dataInfo = mydata.getDataInfo()
- tNum = dataInfo.getTimeNum() #Get time number
- print tNum
- zdim = dataInfo.getVariable('UWND').getZDimension()
- zNum = zdim.getDimLength() #Get level number
- for t in range(tNum):
- dTime = dataInfo.getTimes().get(t)
- print format1.format(dTime)
- mydata.setTimeIndex(t) #Set time index
- for z in range(zNum):
- mydata.setLevelIndex(z) #Set level index
- lev = zdim.getDimValue().get(z)
- uData = mydata.getGridData('UWND') #Get U grid data
- vData = mydata.getGridData('VWND') #Get V grid data
- #Calculate wind direction and wind speed from U/V
- windData = DataMath.getDSFromUV(uData, vData)
- wdData = windData[0]
- wsData = windData[1]
- wd = wdData.toStation(lon, lat) #Intepolate grid data to the location
- ws = wsData.toStation(lon, lat)
- print 'Wind direction = %10.2f; Wind speed = %10.2f' %(wd,ws)
- outf.write(os.linesep)
- line = format2.format(dTime) + ',%d'%lev + ',%.2f '%wd + ',%.2f'%ws
- outf.write(line)
-
- cal.add(Calendar.MONTH, 1)
- aTime = cal.getTime()
- outf.close()
- print 'Finished!'
|
评分
-
查看全部评分
|