Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --band flag #122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ near-realtime picture of Earth.

```
usage: himawaripy [-h] [--version] [--auto-offset | -o OFFSET]
[-l {4,8,16,20}] [-d DEADLINE] [--save-battery]
[--output-dir OUTPUT_DIR] [--dont-change]
[-l {4,8,16,20}]
[--band {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}]
[-d DEADLINE] [--save-battery] [--output-dir OUTPUT_DIR]
[--dont-change]

set (near-realtime) picture of Earth as your desktop background

Expand All @@ -44,14 +46,17 @@ optional arguments:
-l {4,8,16,20}, --level {4,8,16,20}
increases the quality (and the size) of each tile.
possible values are 4, 8, 16, 20
--band {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
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.
-d DEADLINE, --deadline DEADLINE
deadline in minutes to download all the tiles, set 0
to cancel
--save-battery stop refreshing on battery
--output-dir OUTPUT_DIR
directory to save the temporary background image
--dont-change don't change the wallpaper (just download it)

```

Most of the time himawaripy can accurately detect your timezone if you pass the flag `--auto-offset`, although you may
Expand Down
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