-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclean_radar_images.py
executable file
·60 lines (48 loc) · 1.93 KB
/
clean_radar_images.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
#!/usr/bin/python3
import os
import sys
import time
from datetime import timedelta
from datetime import datetime
import shutil
secsPerDay = 86400
pastSecs = secsPerDay * 2
baseDir = '/home/disk/bob/impacts/radar'
baseDirNexrad = baseDir+'/nexrad'
radar = ['kaspr']
nexrad = ['AKQ','BGM','BOX','CCX','CLE','DIX','DOX','DTX','DVN','ENX',
'GRB','GRR','GYX','ILN','ILX','IND','IWX','LOT','LWX','MHX',
'MKX','OKX','RAX','TYX','VWX']
nexradProd = ['N0R','N0V']
dir_prefix = 'imageset'
# Get current time
nowTime = time.gmtime()
now = datetime(nowTime.tm_year, nowTime.tm_mon, nowTime.tm_mday,
nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec)
nowDateHourStr = now.strftime("%Y%m%d%H")
nowUnixTime = int(now.strftime("%s"))
# Compute oldest time to keep
pastDelta = timedelta(0, pastSecs)
lastGoodTimeObj = now - pastDelta
lastGoodTimeStr = lastGoodTimeObj.strftime("%Y%m%d%H")
lastGoodUnixTime = int(lastGoodTimeObj.strftime("%s"))
print 'lastGoodTime = ',lastGoodTimeStr
# For each radar, remove runs older than 2 days
for iradar in range(0,len(radar)):
radarBaseDir = baseDir+'/'+radar[iradar]
for dir in os.listdir(radarBaseDir):
dirUnixTime = int(dir.replace(dir_prefix,''))
if dirUnixTime < lastGoodUnixTime:
shutil.rmtree(radarBaseDir+'/'+dir)
# For each nexrad radar, remove images older than 2 days
for inexrad in range(0,len(nexrad)):
for iprod in range(0,len(nexradProd)):
localDir = baseDirNexrad+'/'+nexrad[inexrad]+'/'+nexradProd[iprod]
for file in os.listdir(localDir):
(fileTimeStr,ext) = os.path.splitext(file)
fileTimeObj = datetime.strptime(fileTimeStr,'%Y%m%d%H%M')
fileTimeUnix = int(fileTimeObj.strftime("%s"))
if fileTimeUnix < lastGoodUnixTime:
os.remove(localDir+'/'+file)
#print 'removed ',file
#dirObjTime = datetime.fromtimestamp(dirUnixTime)