sw_stop.py
1.62 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
# sw_stop.py
# script to get SW Stop time from OMNI HOUR dataset (omni_hour_all)
# normally used in depotDECODER while updating OMNI
# arg : nc file name
from netCDF4 import Dataset
import numpy as np
from datetime import datetime, date, time, timedelta
import sys
def main():
filename = sys.argv[1]
data = Dataset(filename, "r", format="NETCDF4")
density = np.array(data['N'][:])
densityIndex= np.array(np.where(~np.isnan(density)))
maxdens = 0
if densityIndex.shape[1] > 0 :
maxdens = densityIndex.max()
bx = np.array(data['B'][:]).T[0]
bxIndex = np.array(np.where(~np.isnan(bx)))
maxbx = 0
if bxIndex.shape[1] > 0 :
maxbx = bxIndex.max()
stopIndex = np.minimum(maxdens,maxbx)
if stopIndex == 0 :
sys.exit()
ddstopTime = np.array(data['Time'][:])[stopIndex]
ddstopTime = ''.join(ddstopTime)
# print ddstopTime
dtstopTime = ddTime2Datetime([ddstopTime,])[0]
dtstopTime = dtstopTime.isoformat()
print dtstopTime
# with open('OMNI_stop.txt','w') as omniStop:
# omniStop.write(dtstopTime)
# omniStop.close()
def ddTime2Datetime(ddTime):
myDatetime = []
for t in ddTime:
year = int(t[0:4])
day = int(t[4:7]) + 1
myDate = datetime(year, 1, 1) + timedelta(day - 1)
hour = int(t[7:9])
minute = int(t[9:11])
seconds = int(t[11:13])
ms = int(t[13:16])*1000
myTime = time(hour, minute,seconds,ms)
myDatetime.append( datetime.combine(myDate, myTime) )
return myDatetime
if __name__ == '__main__':
main()