Skip to content

Instantly share code, notes, and snippets.

@mickey24
Created March 14, 2011 16:18
Show Gist options
  • Save mickey24/869400 to your computer and use it in GitHub Desktop.
Save mickey24/869400 to your computer and use it in GitHub Desktop.
奥村先生による福島原発のデータ fukushima*.csv ( http://oku.edu.mie-u.ac.jp/~okumura/stat/data/ ) をRなどで処理しやすい形に加工するスクリプトです.使い方についてはコメント欄を参照してください.
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require "time"
puts %w[datetime mon day hour min place gamma neutron wind_dir wind_speed].join("\t")
lines = ARGF.each_line.to_a[2..-1]
date = ""
lines.each do |line|
list = line.split(",")
# date
date = list[0].empty? ? date : list[0]
date =~ /(\d+)\D+(\d+)/
mon = $1
day = $2
# time
time = list[1].gsub(/午後(\d+)/){$1.to_i + 12}
time =~ /(\d+)\D+(\d+)/
hour = $1
min = $2
# datetime
datetime = "2011/#{mon}/#{day} #{hour}:#{min}"
# place
place = list[2].gsub("付近", "")
# gamma
gamma = list[3].to_f * (list[3].include?("μ") ? 1 : 1.0/1000)
# neutron
neutron = list[4].to_f * (list[4].include?("μ") ? 1 : 1.0/1000)
# wind_dir
wind_dir = list[5]
# wind_speed
wind_speed = list[6].chomp
puts [datetime, mon, day, hour, min, place, gamma, neutron, wind_dir, wind_speed].join("\t")
end
@kohske
Copy link

kohske commented Mar 15, 2011

あ、もうすでに時系列プロットも作ってたんですね。

@mickey24
Copy link
Author

おお,ありがとうございます!greplあたりは知らなかったので参考になりました.

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