-
Notifications
You must be signed in to change notification settings - Fork 0
/
getImages.py
73 lines (54 loc) · 2.15 KB
/
getImages.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
61
62
63
64
65
66
67
68
69
70
71
72
73
import wget
from datetime import timedelta, datetime
import numpy as np
import sys
from PIL import Image
import os
#url = 'http://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/2019/07/27/094000_8_0.png'
base_url = 'http://himawari8-dl.nict.go.jp/himawari8/img/D531106/{1}d/550/{0:%Y/%m/%d/%H%M%S}_{2}_{3}.png'
#filepath = 'C:/Users/<username>/Documents/Himawari8Downloader/'
filepath = os.getcwd()+'/'
resolution=20 # best resolution: 20, valid: [1, 2, 4, 8, 16, 20]
#startdate
year=2019
month=7
day=26
hour=0
minutes=0 #multiple of 10
number_of_frames=500
number=1 #at what frame to start. Default: 1
#usefull to continue after e.g. an network-error
start_tile_x=6
start_tile_y=0
number_of_tiles_x=4
number_of_tiles_y=3
def removeTempFiles():
filelist = [ f for f in os.listdir(filepath+'temp/') if f.endswith(".png") ]
for f in filelist:
os.remove(os.path.join(filepath+'temp/', f))
def mergeImages(number):
images = [[Image.open(filepath+'temp/{0}-{1}.png'.format(x,y)) for x in np.arange(number_of_tiles_x)+start_tile_x] for y in np.arange(number_of_tiles_y)+start_tile_y]
total_width = 550*number_of_tiles_x
max_height = 550*number_of_tiles_y
new_im = Image.new('RGB', (total_width, max_height))
x_offset = 0
y_offset = 0
for x in np.arange(number_of_tiles_x):
x_offset=x*550
for y in np.arange(number_of_tiles_y):
y_offset=y*550
new_im.paste(images[y][x], (x_offset,y_offset))
new_im.save(filepath+'Result/{0:04d}.png'.format(number))
removeTempFiles()
start_date = datetime(year, month, day, hour, minutes, 0)
if not os.path.exists(filepath+'Result/'):
os.makedirs(filepath+'Result/')
if not os.path.exists(filepath+'temp/'):
os.makedirs(filepath+'temp/')
removeTempFiles()
for td in (start_date + timedelta(minutes=10*it) for it in range(number-1,number_of_frames)):
for tile_x in np.arange(number_of_tiles_x)+start_tile_x:
for tile_y in np.arange(number_of_tiles_y)+start_tile_y:
filename = wget.download(base_url.format(td,resolution,tile_x,tile_y),filepath+'temp/{0}-{1}.png'.format(tile_x,tile_y))
mergeImages(number)
number=number+1