-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakeObs.py
More file actions
executable file
·175 lines (103 loc) · 4.03 KB
/
makeObs.py
File metadata and controls
executable file
·175 lines (103 loc) · 4.03 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python
path_work="./"
path_scripts="./"
def getObs(dateANL, satellites, model):
"""
get observactions of all satellites in set for dateANL
"""
success = False
dateStart=dateANL-model.timeDeltaMinus
dateEnd =dateANL+model.timeDeltaPlus
for satellite in satellites:
satellite.getObs(dateANL, model)
if dateANL.day <> dateStart.day : satellite.getObs(dateStart, model)
if dateANL.day <> dateEnd.day : satellite.getObs(dateEnd, model)
def decodObs(dateANL, satellites, model):
"""
decod observactions of all satellites in set for dateANL
"""
dateStart=dateANL-model.timeDeltaMinus
dateEnd =dateANL+model.timeDeltaPlus
for satellite in satellites:
satellite.decodObs(dateANL, model)
if dateANL.day <> dateStart.day : satellite.decodObs(dateANL, model)
if dateANL.day <> dateEnd.day : satellite.decodObs(dateANL, model)
def prepareObs(dateANL, satellites, model):
"""
Prepare* observactions of all satellites in set
*call satellite.prepararObs()
"""
import numpy as np
res=[]
success = False
for satellite in satellites:
success, data = satellite.prepareObs(dateANL, model)
if success: res = res+data
return success, np.array(res)
def splitObsInSlots(obs, dateANL, model):
""" split Obs in slot files """
from datetime import datetime, timedelta
import numpy as np
ret=[]
obsTotal=0
for i in range(1,model.nSlots+1):
dateI=dateANL-model.timeDeltaMinus +timedelta(hours=i-1)
dateF=dateANL-model.timeDeltaMinus+timedelta(hours=1)+timedelta(hours=i-1)-timedelta(minutes=1)
obs_i=np.array(filter( lambda data : dateI <= data[0] <= dateF, obs))
obsTotal+=len(obs_i)
print "slot "+str(i)+": "+str(len(obs_i))
print dateI
print dateF
print " "
ret.append(obs_i)
print "obs total: "+str(obsTotal)
return ret
def main(args):
import Metop_a
import modelWRF
import datetime
import saveFileObs
satellites=[]
model=modelWRF.ModelWRF()
dateANL=args.dateANL
if args.metop_a : satellites.append(Metop_a.Metop_a())
if args.get :
success = getObs(dateANL, satellites, model)
print "getting..."+str(success)
if args.decod :
success = decodObs(dateANL, satellites, model)
print "decoding..."+str(success)
if args.prepare :
print "preparing..."
success, obs =prepareObs(dateANL, satellites, model)
if not success: print "no hay observaciones"
else: slotsObs=splitObsInSlots(obs, dateANL, model)
# obs,aceptados, descartados, rmsValorChicas = testerObs(obs, args.debug)
saveFileObs.saveSlots(slotsObs, args.destinaton, model)
if __name__ == "__main__":
import argparse
def mkdate(datestring):
from datetime import datetime, timedelta
return datetime.strptime(datestring, '%Y%m%d-%H')
parser = argparse.ArgumentParser()
parser.add_argument('dateANL', type=mkdate, help="Date [YYYYmmdd-hh] of analisis time")
parser.add_argument('--NoMetop_a', action='store_false', default=True,
dest='metop_a',
help='Don\'t make observations from metop a')
parser.add_argument('--NoGet', action='store_false', default=True,
dest='get',
help='Don\'t get observations')
parser.add_argument('--NoDecod', action='store_false', default=True,
dest='decod',
help='Don\'t get observations')
parser.add_argument('--NoPrepare', action='store_false', default=True,
dest='prepare',
help='Don\'t prepare Observations')
parser.add_argument('--debug', action='store_true', default=False,
dest='debug',
help='debug mode')
parser.add_argument('destinaton', help="folder to save slots files (obsXX.dat)")
args = parser.parse_args()
main(args)
#
#