Link Search Menu Expand Document

高空觀測數據之自動下載

Table of contents

背景

  • NCEP (National Centers for Environmental Prediction)彙整了全球高空觀測數據(ds351.0),是MM5/WRF進行四階同化需要的數據,資料格式是little_r格式,可以被obsgridWRFDA等程式接受。
  • 同樣的,NCEP並無提供指定範圍自動下載的工具,只能下載全球範圍所有觀測值。高空數據層數較多,檔案較地面數據更大。
  • 幸好檔案是ASCII格式,可以達到很高的壓縮率。

批次執行與自動執行

詳見樓上

程式差異說明

因程式與ff.py很相像,此處介紹其差異之處

  • 儲存路徑
kuang@114-32-164-198 ~/python_eg/NCEP_fetch
$ diff ff.py uu.py
53c53
< path='/Users/WRF4.1/NCEP/FNL/'
---
> path='/Users/WRF4.1/NCEP/UPA_ds351.0/'
  • 檔名中的日期出現在不同位置
    • FNL: fnl_20211124_18_00.grib2
    • SRF: SURFACE_OBS:2021111818
    • UPA: OBS:2021111818
55c55
< blk=os.popen('ls '+path+yrold+'|tail -n1').read().strip('\n').split('_')
---
> blk=os.popen('ls '+path+yrold+'|tail -n1').read().strip('\n').split('_')[-1].split(':')
  • 高空數據有可能被壓縮(gzip),取用檔名時要多加此一選項。(如沒有gz則不會有任何改變)
57c57
<   begd=int(blk[1])
---
>   begd=int(int(blk[1].replace('.gz',''))/100)
  • 高空數據更新較慢,比實際日期晚8天
64c64
< edate = tdate+datetime.timedelta(days=-2)
---
> edate = tdate+datetime.timedelta(days=-8)
  • url字串的內容也有所差異
76,82c76,77
< mos=[ymd[4:6] for ymd in ymds]
< head=['grib2/'+yr+'/'+yr+'.' for yr in yrs]
< med='/fnl_'
< udl='_'
< tail='_00.grib2'
< listoffiles=[head[i]+mos[i]+med+ymds[i]+udl+str(h)+tail for i in xrange(len(ymds)) for h in ['00','06','12','18']]
< #sys.exit('OK')
---
> head=['little_r/'+yr+'/OBS:' for yr in yrs]
> listoffiles=[head[i]+ymds[i]+str(h)  for i in xrange(len(ymds)) for h in ['00','06','12','18']]
  • macOS能夠處理冒號,不需更換。
86c81
<     ofile=file[idx+1:].replace(':','_')
---
>     ofile=file[idx+1:]#.replace(':','_')
88c83
<     ofile=file.replace(':','_')
---
>     ofile=file#.replace(':','_')
  • 高空數據有可能被壓縮(gzip),測試邏輯要多加此一選項。
91c86
<   if os.path.isfile(path1+ofile):continue
---
>   if os.path.isfile(path1+ofile) or os.path.isfile(path1+ofile+'.gz') :continue
  • NCEP 資料庫編碼,高空數據是ds351.0
96c91
<     infile=opener.open("http://rda.ucar.edu/data/ds083.2/"+file)
---
>     infile=opener.open("http://rda.ucar.edu/data/ds351.0/"+file)

完整程式碼