NeuroWhAI의 잡블로그

2020년 8월 장마 기상청 레이더 종합영상 본문

자료

2020년 8월 장마 기상청 레이더 종합영상

NeuroWhAI 2020. 8. 12. 23:40


youtu.be/_EgyPLzRZhE

2020년 8월 2일 20시 ~ 12일 22시 기상청 종합영상

8월 초 장마 기간 동안의 종합영상을 모아 하나의 영상으로 만들었습니다.
이번 장마가 어땠는지 넓은 시각(?)에서 볼 수 있습니다.
영상 1초 = 현실 1시간이며 범례는 보시면 아시겠지만 시간당 강수량에 따라 색이 다릅니다.

 

이미지를 여러 날에 걸쳐 수집하여 이어붙힌 것인데 당연히 수동으로 하진 않았고 간단하게 파이썬을 사용했습니다.
코드가 궁금하신 분은 아래에...

더보기
import urllib.request
from datetime import datetime, timedelta
import time
from pathlib import Path

tm = datetime(2020, 8, 12, 22, 0) # 시작할 시간. (5분 단위로 입력.)
while True:
    tm_str = tm.strftime("%Y%m%d%H%M")
    file_path = Path(f"img/{tm_str}.png")
    if file_path.is_file():
        break
    url = f"https://www.weather.go.kr/w/cgi-bin/rdr_new/nph-rdr_sat_lgt_img_v3?tm={tm_str}&sat=ir1&rdr=lng&map=HC&size=640&zoom_level=0&zoom_x=0000000&zoom_y=0000000&fog=0"
    print(tm_str)
    try:
        urllib.request.urlretrieve(url, file_path)
    except Exception as e:
        print("Error: ", e)
        time.sleep(5)
        continue
    time.sleep(1)
    tm = tm -  timedelta(minutes=5)

print("Complete.")
import os
from os import walk

list_file = "img_paths.txt"

for (_, _, filenames) in walk("img"):
    with open(list_file, "w") as f:
        f.writelines(map(lambda name: f"file img/{name}\n", filenames))
    break

imgs_per_second = 12
os.popen(f"ffmpeg -y -r {imgs_per_second} -f concat -safe 0 -i {list_file} "\
    "-vf \"yadif,format=yuv420p,scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2\" "\
    "-force_key_frames \"expr:gte(t,n_forced/2)\" -use_editlist 0 -movflags +faststart "\
    "-preset slow -crf 20 -bf 2 -c:v libx264 -b:v 50M out.mp4").read()

os.remove(list_file)


Comments