Last active
December 15, 2015 11:23
-
-
Save p0we7/5783db11ec2ddeb67d14 to your computer and use it in GitHub Desktop.
Get hight quality image via himawari8 by @pepsin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require "cairo" | |
def get_url time, x, y | |
str = "http://himawari8-dl.nict.go.jp/himawari8/img/D531106/20d/550/#{time}00_#{x}_#{y}.png" | |
end | |
def merge time | |
puts "Start image process" | |
w = 20 | |
h = 20 | |
partial_width = 550 | |
surface = Cairo::ImageSurface.new(w * partial_width, h * partial_width) | |
cr = Cairo::Context.new(surface) | |
arr = [] | |
h.times do |y| | |
w.times do |x| | |
name = "himawari_#{x}_#{y}.png" | |
arr.push name | |
puts name | |
png = Cairo::ImageSurface.from_png(name) | |
cr.set_source(*png) | |
cr.matrix = Cairo::Matrix.new(1,0,0,1,x * partial_width, y * partial_width) | |
cr.paint() | |
end | |
end | |
cr.target.write_to_png("#{time.split("/").join("_")}.png") | |
cr.destroy | |
surface.destroy | |
arr.each do |file| | |
File.delete file | |
end | |
end | |
def run time | |
merge_name = time.split("/").join("_") + ".png" | |
unless File.exists? merge_name | |
ts = [] | |
20.times do |x| | |
thread = Thread.new do | |
20.times do |y| | |
name = "himawari_#{x}_#{y}.png" | |
unless File.exists? name | |
url = get_url time, x, y | |
uri = URI.parse(url) | |
req = Net::HTTP::Get.new uri.path | |
res = Net::HTTP.start(uri.host, uri.port, use_ssl: false) do |http| | |
http.request req | |
end | |
file = File.open(name, "w+") | |
file.write(res.body) | |
file.close | |
end | |
end | |
end | |
ts.push thread | |
end | |
ts.map(&:join) | |
sleep 5 | |
end | |
unless File.exists? merge_name | |
merge time | |
end | |
end | |
24.times do |hour| | |
hour = hour.to_s | |
if hour.length < 2 | |
hour = "0" + hour | |
end | |
6.times do |minute| | |
minute = (minute * 10).to_s | |
if minute.length < 2 | |
minute = "0" + minute | |
end | |
str = "2015/12/01/" + hour + minute | |
puts str | |
run str | |
end | |
end | |
# run "2015/12/01/0000" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use ?
Install Ruby
apt (Debian 或 Ubuntu)
yum (CentOS、Fedora 或 RHEL(
Other Distributions
See : Ruby installation
Download & Use Script