Skip to content

Commit

Permalink
Add --infrared flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cben committed Jul 13, 2021
1 parent 8e57943 commit 8249d43
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions himawaripy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ def calculate_time_offset(latest_date, auto, preferred_offset):
def download_chunk(args):
global counter

x, y, latest, level = args
url_format = "https://himawari8-dl.nict.go.jp/himawari8/img/D531106/{}d/{}/{}_{}_{}.png"
url = url_format.format(level, WIDTH, strftime("%Y/%m/%d/%H%M%S", latest), x, y)
x, y, band, latest, level = args
# TODO: apparently can get each of 16 bands from URLs like
# https://himawari8.nict.go.jp/img/FULL_24h/B07/1d/550/2021/07/13/161000_0_0.png
url_format = "https://himawari8-dl.nict.go.jp/himawari8/img/{}/{}d/{}/{}_{}_{}.png"
url = url_format.format(band, level, WIDTH, strftime("%Y/%m/%d/%H%M%S", latest), x, y)

tiledata = download(url)

Expand All @@ -71,7 +73,7 @@ def download_chunk(args):
print("Downloading tiles: completed.")
else:
print("Downloading tiles: {}/{} completed...".format(counter.value, level * level))
return x, y, tiledata
return x, y, band, tiledata


def parse_args():
Expand Down Expand Up @@ -105,6 +107,12 @@ def parse_args():
default=4,
help="increases the quality (and the size) of each tile. possible values are 4, 8, 16, 20",
)
parser.add_argument(
"--infrared",
action="store_true",
default=False,
help="download an infrared band instead of visible light. behavior might change in future."
)
parser.add_argument(
"-d",
"--deadline",
Expand Down Expand Up @@ -192,13 +200,15 @@ def thread_main(args):
if args.auto_offset or args.offset != 10:
print("Offset version: {} GMT.".format(strftime("%Y/%m/%d %H:%M:%S", requested_time)))

png = Image.new("RGB", (WIDTH * level, HEIGHT * level))
image_mode = "LA" if args.infrared else "RGB"
png = Image.new(image_mode, (WIDTH * level, HEIGHT * level))

p = mp_dummy.Pool(level * level)
print("Downloading tiles...")
res = p.map(download_chunk, it.product(range(level), range(level), (requested_time,), (args.level,)))
band = "INFRARED_FULL" if args.infrared else "D531106"
res = p.map(download_chunk, it.product(range(level), range(level), (band,), (requested_time,), (args.level,)))

for (x, y, tiledata) in res:
for (x, y, band, tiledata) in res:
tile = Image.open(io.BytesIO(tiledata))
png.paste(tile, (WIDTH * x, HEIGHT * y, WIDTH * (x + 1), HEIGHT * (y + 1)))

Expand Down

0 comments on commit 8249d43

Please sign in to comment.