Skip to content

Instantly share code, notes, and snippets.

@p0we7
Last active December 15, 2015 11:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p0we7/5783db11ec2ddeb67d14 to your computer and use it in GitHub Desktop.
Save p0we7/5783db11ec2ddeb67d14 to your computer and use it in GitHub Desktop.
Get hight quality image via himawari8 by @pepsin
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"
@p0we7
Copy link
Author

p0we7 commented Dec 9, 2015

  • How to use ?

    • Install Ruby

      • apt (Debian 或 Ubuntu)

        sudo apt-get install ruby-full
        
      • yum (CentOS、Fedora 或 RHEL(

        sudo yum install ruby
        
      • Other Distributions

      See : Ruby installation

  • Download & Use Script

    curl https://gist.githubusercontent.com/p0we7/5783db11ec2ddeb67d14/raw/himawari8.rb -o himawari8.rb
    ruby himawari8.rb
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment