-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatcf.py
57 lines (49 loc) · 1.56 KB
/
atcf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 16 13:24:14 2017
@author: Sergey.Vinogradov
"""
from datetime import datetime
#==test============================================================================
def readTrack ( atcfFile ):
"""
Reads ATCF-formatted file
Args:
'atcfFile': (str) - full path to the ATCF file
Returns:
dict: 'lat', 'lon', 'vmax', 'mslp','dates'
"""
lines = open(atcfFile).readlines()
myOcn = []
myCy = []
myDate = []
myLat = []
myLon = []
myVmax = []
myMSLP = []
for line in lines:
r = line.rstrip().split(',')
myOcn.append (r[0])
myCy.append (int(r[1]))
myDate.append (datetime.strptime(r[2].strip(),'%Y%m%d%H'))
latSign = -1.0
if 'N' in r[6]:
latSign = 1.0
myLat.append (latSign*0.1*float(r[6][:-1]))
lonSign = -1.0
if 'E' in r[7]:
lonSign = 1.0
myLon.append (lonSign*0.1*float(r[7][:-1]))
myVmax.append (float(r[8]))
myMSLP.append (float(r[9]))
return {
'basin' : myOcn, 'cy' : myCy, 'dates' : myDate,
'lat' : myLat, 'lon' : myLon,
'vmax' : myVmax, 'mslp' : myMSLP }
#==============================================================================
if __name__ == "__main__":
# Demo
atcfFile = 'bal182012.dat'
trk = readTrack (atcfFile)
import matplotlib.pyplot as plt
plt.plot(trk['lon'],trk['lat'])