Created
March 14, 2011 16:18
-
-
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などで処理しやすい形に加工するスクリプトです.使い方についてはコメント欄を参照してください.
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
#!/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 |
あ、もうすでに時系列プロットも作ってたんですね。
おお,ありがとうございます!greplあたりは知らなかったので参考になりました.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
被災された方々に、謹んでお見舞い申し上げます。
奥村先生の所から直接とってきて時系列プロットするスクリプトを貼り付けておいたので、必要であれば使ってください。
お役に立てば幸いです。
d <- read.csv('http://oku.edu.mie-u.ac.jp/~okumura/stat/data/fukushima1.csv', fileEncoding="sjis", skip=1, na="-", as.is=TRUE)
d <- d[,1:7]
for (i in 4:5) d[,i] <- as.numeric(str_replace(d[,i], "([0-9.]+).*", "\1")) * ifelse(grepl("n", d[,4]), 1/1000, 1)
iday<-which(d[,1]!="")
d[,1] <- rep(d[iday,1], diff(c(iday, nrow(d)+1)))
d$stime <- paste(d[,1],
ifelse(grepl("午前", d[,2]), "AM", "PM"),
as.integer(str_replace(d[,2], "..([0-9]).", "\1"))+1,
"/",
str_replace(d[,2], "..[0-9].([0-9]).*", "\1"))
d$time <- strptime(d$stime, "%m月%d日 %p %I / %M")
ggplot(d, aes(as.POSIXct(time), γ線, colour=計測場所)) + geom_line() + theme_grey(base_family="sans") + xlab("日時(日ー月)") + ylab("γ線(μSV/h)")