Skip to content

Instantly share code, notes, and snippets.

@tenomoto
Last active March 18, 2022 07:55
Show Gist options
  • Save tenomoto/73843ed9498485a19fa7c178a50a79fb to your computer and use it in GitHub Desktop.
Save tenomoto/73843ed9498485a19fa7c178a50a79fb to your computer and use it in GitHub Desktop.
Select a tropical cyclone in JMA besttrack and print in y,m,d,h,lon,lat,slp

Python

  • process_bst.py

AWK

  1. RSMC Best Track Dataから1951-2021 (ALL)をダウンロードして解凍。
  2. AWKで台風を切り出す。 最初のフィールドが66666が各台風のタイトル。行番号(NR),番号,名前を抽出。
% awk '$1==66666{print NR,$2,$8}' bst_all.txt > list.txt
  1. 対象とする台風と次の台風が始まる行番号を確認。
% awk '$2==1721{print $1}' list.txt
65619
% awk '$2==1722{print $1}' list.txt
65663
  1. 対象とする台風のデータを抽出。
% awk -v OFS=',' 'NR>65619 && NR< 65663 {print}' bst_all.txt > 1721.txt
  1. 処理しやすいCSV形式(年,月,日,時,経度,緯度,中心気圧)に変換。
% awk '{print 20 substr($1,1,2), substr($1,3,2), substr($1,5,2), substr($1,7,2), $5*0.1, $4*0.1, $6}' 1721.txt > 1721_ymdh_loc_pc.txt

Fortran

#66666 2122 039 0029 2122 0 6 RAI 20220204
#21121118 002 2 058 1448 1002 000
import sys
tcnum = sys.argv[1]
if int(tcnum[0:2]) > 50:
yy = 19
else:
yy = 20
with open("bst_all.txt", "r") as f:
line = f.readline().strip()
while line:
x = line.split()
name = x[7] if len(x) > 7 else ""
if x[0] == '66666' and x[1] == tcnum :
line = f.readline().strip()
while line:
x = line.split()
if x[0] == '66666': break
x0 = x[0]
print(f"{yy}{x0[0:2]},{x0[2:4]},{x0[4:6]},{x0[6:8]},{int(x[4])*0.1:.1f},{int(x[3])*0.1:.1f},{x[5]}")
line = f.readline().strip()
else:
line = f.readline().strip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment