Changeset 446 in lmdz_wrf
- Timestamp:
- May 28, 2015, 5:28:25 PM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r440 r446 2353 2353 2354 2354 valsv = np.zeros((2,dimt), dtype=np.float) 2355 # Checking for time consistency 2356 if otim.getncattr('units') != tunits: 2357 print warnmsg 2358 print ' ' + fname + ': different time units in the plot!!' 2359 newtimes = drw.coincident_CFtimes(otim[:], tunits, otim.getncattr('units')) 2360 else: 2361 newtimes = otim[:] 2355 2362 2356 2363 if tini == -1: 2357 valsv[1,:] = otim[:]2364 valsv[1,:] = newtimes[:] 2358 2365 valsv[0,:] = ovar[:] 2359 2366 else: 2360 valsv[1,:] = otim[tiniid:tendid+1]2367 valsv[1,:] = newtimes[tiniid:tendid+1] 2361 2368 valsv[0,:] = ovar[tiniid:tendid+1] 2362 2369 -
trunk/tools/drawing_tools.py
r440 r446 2209 2209 return boolv 2210 2210 2211 def coincident_CFtimes(tvalB, tunitA, tunitB): 2212 """ Function to make coincident times for two different sets of CFtimes 2213 tvalB= time values B 2214 tunitA= time units times A to which we want to make coincidence 2215 tunitB= time units times B 2216 >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00', 2217 'hours since 1949-12-01 00:00:00') 2218 [ 0. 3600. 7200. 10800. 14400. 18000. 21600. 25200. 28800. 32400.] 2219 >>> coincident_CFtimes(np.arange(10),'seconds since 1949-12-01 00:00:00', 2220 'hours since 1979-12-01 00:00:00') 2221 [ 9.46684800e+08 9.46688400e+08 9.46692000e+08 9.46695600e+08 2222 9.46699200e+08 9.46702800e+08 9.46706400e+08 9.46710000e+08 2223 9.46713600e+08 9.46717200e+08] 2224 """ 2225 import datetime as dt 2226 fname = 'coincident_CFtimes' 2227 2228 trefA = tunitA.split(' ')[2] + ' ' + tunitA.split(' ')[3] 2229 trefB = tunitB.split(' ')[2] + ' ' + tunitB.split(' ')[3] 2230 tuA = tunitA.split(' ')[0] 2231 tuB = tunitB.split(' ')[0] 2232 2233 if tuA != tuB: 2234 if tuA == 'microseconds': 2235 if tuB == 'microseconds': 2236 tB = tvalB*1. 2237 elif tuB == 'seconds': 2238 tB = tvalB*10.e6 2239 elif tuB == 'minutes': 2240 tB = tvalB*60.*10.e6 2241 elif tuB == 'hours': 2242 tB = tvalB*3600.*10.e6 2243 elif tuB == 'days': 2244 tB = tvalB*3600.*24.*10.e6 2245 else: 2246 print errormsg 2247 print ' ' + fname + ": combination of time untis: '" + tuA + \ 2248 "' & '" + tuB + "' not ready !!" 2249 quit(-1) 2250 elif tuA == 'seconds': 2251 if tuB == 'microseconds': 2252 tB = tvalB/10.e6 2253 elif tuB == 'seconds': 2254 tB = tvalB*1. 2255 elif tuB == 'minutes': 2256 tB = tvalB*60. 2257 elif tuB == 'hours': 2258 tB = tvalB*3600. 2259 elif tuB == 'days': 2260 tB = tvalB*3600.*24. 2261 else: 2262 print errormsg 2263 print ' ' + fname + ": combination of time untis: '" + tuA + \ 2264 "' & '" + tuB + "' not ready !!" 2265 quit(-1) 2266 elif tuA == 'minutes': 2267 if tuB == 'microseconds': 2268 tB = tvalB/(60.*10.e6) 2269 elif tuB == 'seconds': 2270 tB = tvalB/60. 2271 elif tuB == 'minutes': 2272 tB = tvalB*1. 2273 elif tuB == 'hours': 2274 tB = tvalB*60. 2275 elif tuB == 'days': 2276 tB = tvalB*60.*24. 2277 else: 2278 print errormsg 2279 print ' ' + fname + ": combination of time untis: '" + tuA + \ 2280 "' & '" + tuB + "' not ready !!" 2281 quit(-1) 2282 elif tuA == 'hours': 2283 if tuB == 'microseconds': 2284 tB = tvalB/(3600.*10.e6) 2285 elif tuB == 'seconds': 2286 tB = tvalB/3600. 2287 elif tuB == 'minutes': 2288 tB = tvalB/60. 2289 elif tuB == 'hours': 2290 tB = tvalB*1. 2291 elif tuB == 'days': 2292 tB = tvalB*24. 2293 else: 2294 print errormsg 2295 print ' ' + fname + ": combination of time untis: '" + tuA + \ 2296 "' & '" + tuB + "' not ready !!" 2297 quit(-1) 2298 elif tuA == 'days': 2299 if tuB == 'microseconds': 2300 tB = tvalB/(24.*3600.*10.e6) 2301 elif tuB == 'seconds': 2302 tB = tvalB/(24.*3600.) 2303 elif tuB == 'minutes': 2304 tB = tvalB/(24.*60.) 2305 elif tuB == 'hours': 2306 tB = tvalB/24. 2307 elif tuB == 'days': 2308 tB = tvalB*1. 2309 else: 2310 print errormsg 2311 print ' ' + fname + ": combination of time untis: '" + tuA + \ 2312 "' & '" + tuB + "' not ready !!" 2313 quit(-1) 2314 else: 2315 print errormsg 2316 print ' ' + fname + ": time untis: '" + tuA + "' not ready !!" 2317 quit(-1) 2318 else: 2319 tB = tvalB*1. 2320 2321 if trefA != trefB: 2322 trefTA = dt.datetime.strptime(trefA, '%Y-%m-%d %H:%M:%S') 2323 trefTB = dt.datetime.strptime(trefB, '%Y-%m-%d %H:%M:%S') 2324 2325 difft = trefTB - trefTA 2326 diffv = difft.days*24.*3600.*10.e6 + difft.seconds*10.e6 + difft.microseconds 2327 print ' ' + fname + ': different reference refA:',trefTA,'refB',trefTB 2328 print ' difference:',difft,':',diffv,'microseconds' 2329 2330 if tuA == 'microseconds': 2331 tB = tB + diffv 2332 elif tuA == 'seconds': 2333 tB = tB + diffv/10.e6 2334 elif tuA == 'minutes': 2335 tB = tB + diffv/(60.*10.e6) 2336 elif tuA == 'hours': 2337 tB = tB + diffv/(3600.*10.e6) 2338 elif tuA == 'dayss': 2339 tB = tB + diffv/(24.*3600.*10.e6) 2340 else: 2341 print errormsg 2342 print ' ' + fname + ": time untis: '" + tuA + "' not ready !!" 2343 quit(-1) 2344 2345 return tB 2346 2347 ####### ###### ##### #### ### ## # 2348 2211 2349 def plot_TimeSeries(valtimes, vunits, tunits, hfileout, vtit, ttit, tkind, tformat, \ 2212 2350 tit, linesn, lloc, kfig):
Note: See TracChangeset
for help on using the changeset viewer.