Skip to content

Commit

Permalink
Add --band flag
Browse files Browse the repository at this point in the history
An initial step to boramalper#108
  • Loading branch information
cben committed Jul 13, 2021
1 parent 8e57943 commit e9e6934
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions himawaripy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ 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
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 +71,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 +105,13 @@ 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(
"--band",
type=int,
choices=range(0, 17),
default=0,
help="If 0, get RGB visible light picture; if 1 to 16, get just that band as greyscale image. See https://en.wikipedia.org/wiki/Himawari_8#Instruments."
)
parser.add_argument(
"-d",
"--deadline",
Expand Down Expand Up @@ -192,13 +199,20 @@ 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))
if args.band > 0:
band = "FULL_24h/B{:02d}".format(args.band)
image_mode = "LA"
else:
band = "D531106"
image_mode = "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,)))
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 e9e6934

Please sign in to comment.