-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhysplit_traceback_v2.py
More file actions
137 lines (95 loc) · 4.11 KB
/
hysplit_traceback_v2.py
File metadata and controls
137 lines (95 loc) · 4.11 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def traceback(aerofilt_dir):
import hysplit_tools as tools
import numpy as np
import pandas as pan
import os,sys
import math
import datetime as dt
Tman_coord = [39.0,84.0]
Tman_a = 800 #km semi-major axis
Tman_b = 300 #km semi-minor axis
Tman_tilt = 70 #degrees between North and major axis
Gobi_coord = [43.0,106.0]
Gobi_a = 1000 #km semi_major axis
Gobi_b = 500
Gobi_tilt = 65 #degrees between North and major axis
G_maxlon = 118
G_minlon = 95
G_maxlat = 49
G_minlat = 37
T_maxlon = 93
T_minlon = 75
T_maxlat = 43
T_minlat = 35
#load .mat file
[aerofilt_topdir, station_id] = os.path.split(aerofilt_dir)
data_keys = ('station','start_loc','start_date','end_loc','delta_t','delta_d','desert_tag')
startdir = os.getcwd()
os.chdir(aerofilt_dir)
output_filename = station_id+'traceback'
hysplit_files = os.listdir(os.getcwd())
data_index = []
start_date = []
start_loc = []
end_loc = []
delta_t = []
station = []
delta_d = []
desert_tag = []
files = 0
tracks = 0
G = 0
T = 0
print 'Traceback is Processing %s folder' %station_id
for h in hysplit_files:
filetest = h.split('.')
try:
if filetest[1] == 'mat' and not('Aerostats' in h or 'traceback' in h):
files += 1
hysplit_dict = scipy.io.loadmat(h)
lat = hysplit_dict['lat']
lon = hysplit_dict['lon']
data_index = []
d_total = 0
tracks = tracks + len(lat)
for n in range(1,len(lat)):
[d_temp,theta_temp] = tools.haversine(lat[n-1],lon[n-1],lat[n],lon[n])
d_total = d_total + d_temp
if G_minlat < lat[n] < G_maxlat:
if G_minlon < lon[n] < G_maxlon:
[G_range,G_theta] = tools.haversine(lat[n],lon[n],Gobi_coord[0],Gobi_coord[1])
G_rad = tools.ellipserad(Gobi_a,Gobi_b,G_theta,Gobi_tilt)
if G_range < G_rad:
data_index.append(n)
delta_d.append(d_total)
desert_tag.append('Gobi')
G += 1
if T_minlat < lat[n] < T_maxlat:
if T_minlon < lon[n] < T_maxlon:
[T_range,T_theta] = tools.haversine(lat[n],lon[n],Tman_coord[0],Tman_coord[1])
T_rad = tools.ellipserad(Tman_a,Tman_b,T_theta,Tman_tilt)
if T_range < T_rad:
data_index.append(n)
delta_d.append(d_total)
desert_tag.append('Tman')
T += 1
for n in range(0,len(data_index)):
tempdate = dt.datetime(hysplit_dict['year'][0],hysplit_dict['month'][0],hysplit_dict['day'][0],\
hysplit_dict['hour'][0])
start_date.append(tempdate)
start_loc.append((lat[0],lon[0]))
end_loc.append((lat[data_index[n]],lon[data_index[n]]))
delta_t.append(hysplit_dict['delta_t'][data_index[n]])
station.append(station_id)
except IndexError:
pass
output_data = (station,start_loc,end_loc,delta_t,delta_d,desert_tag)
output_dict = dict(zip(data_keys,output_data))
df_out = pan.DataFrame(output_dict, index = start_date)
pan.save(df_out, output_filename)
os.chdir(startdir)
print 'Out of %i files, %i total tracks checked' %(files,tracks)
G_percent = 100.0*G/tracks
T_percent = 100.0*T/tracks
print '%0.3f percent of tracks passed over Gobi (or %i total)' %(G_percent, G)
print '%0.3f percent of tracks passed over Taklimikan (or %i total)' %(T_percent, T)