-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFLpathData.py
81 lines (69 loc) · 2.9 KB
/
getFLpathData.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import xarray as xr
from datetime import datetime as dt
import numpy as np
def getFLpathData(flFile,pathStrt,pathEnd,crdsOnly=False):
"""
Return flight-level data between a path start and end time.
Parameters
----------
flFile : string
Filename of the flight-level file to be loaded.
pathStrt,pathEnd : datetimes
Start/end times of the flight path.
crdsOnly : bool, optional
If True, only lat/lon will be extracted and returned (for speed).
Returns
-------
allData : dict
Dictionary containing FL data along the path bounded by the path start/end times.
"""
flData = xr.open_dataset(flFile)
dtNum = flData.get('datetime_FL').data
lat = flData.get('lat').to_masked_array()
lon = flData.get('lon').to_masked_array()
if not crdsOnly:
alt = flData.get('Alt').to_masked_array()
ws = flData.get('windSpd').to_masked_array()
wd = flData.get('windDir').to_masked_array()
u = flData.get('u').to_masked_array()
v = flData.get('v').to_masked_array()
uRel = flData.get('u_relative').to_masked_array()
vRel = flData.get('v_relative').to_masked_array()
w = flData.get('w_dpj').to_masked_array()
staticP = flData.get('staticPres').to_masked_array()
dynamicP = flData.get('dynamicPres').to_masked_array()
rh = flData.get('RH_hybrid').to_masked_array()
temp = flData.get('TA').to_masked_array()
td = flData.get('TD').to_masked_array()
dtStr = np.char.mod('%d',dtNum)
flDT = np.asarray([dt.strptime(fDate,'%Y%m%d%H%M%S') for fDate in dtStr])
if pathStrt == 0 and pathEnd == -1:
strtIx = 0
endIx = -2
else:
strtIx = np.squeeze(np.where(flDT == pathStrt))
endIx = np.squeeze(np.where(flDT == pathEnd))
dtPath = flDT[strtIx:endIx+1]
latPath = lat[strtIx:endIx+1]
lonPath = lon[strtIx:endIx+1]
if not crdsOnly:
altPath = alt[strtIx:endIx+1]
wsPath = ws[strtIx:endIx+1]
wdPath = wd[strtIx:endIx+1]
uPath = u[strtIx:endIx+1]
vPath = v[strtIx:endIx+1]
uRelPath = uRel[strtIx:endIx+1]
vRelPath = vRel[strtIx:endIx+1]
wPath = w[strtIx:endIx+1]
staticPPath = staticP[strtIx:endIx+1]
dynamicPPath = dynamicP[strtIx:endIx+1]
rhPath = rh[strtIx:endIx+1]
tempPath = temp[strtIx:endIx+1]
tdPath = td[strtIx:endIx+1]
allData = {'datetime': dtPath, 'lat': latPath, 'lon': lonPath, 'alt': altPath,
'windSpd': wsPath, 'windDir': wdPath, 'u': uPath, 'v': vPath,
'uRel': uRelPath, 'vRel': vRelPath, 'w': wPath, 'staticPres': staticPPath,
'dynamicPres': dynamicPPath, 'rh': rhPath, 'temp': tempPath, 'td': tdPath}
else:
allData = {'datetime': dtPath, 'lat': latPath, 'lon': lonPath}
return allData