forked from yichung279/Rain-forcast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
47 lines (37 loc) · 1.78 KB
/
Copy pathtest.py
File metadata and controls
47 lines (37 loc) · 1.78 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
from PIL import Image,ImageDraw,ImageFont
from datetime import timedelta,datetime
from rain import centroid
import argparse
import json
if __name__ == '__main__':
with open('config.json', 'r') as data_file:
config = json.load(data_file)
radius = 150
parser = argparse.ArgumentParser()
parser.add_argument("bigin", help ="info1:datetime of bigin image(YYYYmmDDHHMM),")
parser.add_argument("end", help ="info2:datetime of end image(YYYYmmDDHHMM),")
parser.add_argument("x", help ="info3:location x on rader graph of CWB (NCKU is at 1675,1475)")
parser.add_argument("y", help ="info4:location -y on rader graph of CWB (NCKU is at 1675,1475)")
args = parser.parse_args()
x=int(args.x)
y=int(args.y)
begin = datetime.strptime(args.bigin, "%Y%m%d%H%M")
end = datetime.strptime(args.end, "%Y%m%d%H%M")
_10mins = timedelta(seconds=600)
file_datetime = begin
fnt = ImageFont.truetype('zh.ttf', 10)
font_color = 250
base = config['cwbPath'] + 'CV1_3600_' + end.strftime("%Y%m%d%H%M") + ".png"
base_im = Image.open(base).crop((x - radius, y - radius, x + radius, y + radius))
while (file_datetime < end) :
stamp = file_datetime.strftime("%Y%m%d%H%M")
fname = config['cwbPath'] + 'CV1_3600_' + stamp + ".png"
image = Image.open(fname).crop((x - radius, y - radius, x + radius, y + radius))
centr =centroid (image)
if centr[0] != 0 :
ImageDraw.Draw( base_im ).text( (centr[0]-3,centr[1]- 5 ),'@'+stamp, font=fnt ,fill = (font_color ,0 , 0 ) )
if font_color > 0:
font_color -= 10
file_datetime = file_datetime +_10mins
base_im.save('pub/'+end.strftime("%Y%m%d%H%M")+'.png')
print (config['path_save']+end.strftime("%Y%m%d%H%M")+'.png')