Project

General

Profile

RE: converting .csv to .nc to perform time-based statistics » kyle.rb

Ralf Mueller, 2020-04-16 15:53

 
require 'cdo'
require 'parallel'
cdo = Cdo.new
inputs=File.open(ARGV[0]).readlines.map(&:chomp).map(&:split)

Parallel.each(inputs, in_threads: 12) {|input|
year, month, day, hour, *values = input
puts '############################## '+year
values.each_with_index {|value,index|
cdo.settaxis("#{year}-#{month}-#{day},#{hour}:00:00,1hours",input: "-setname,var#{index} -const,#{value},r1x1", output: "var#{index}_#{year}-#{month}-#{day}_#{hour}.nc", options: '-f nc')
}
}

(0..7).each {|i|
cdo.cat(input: Dir.glob("var#{i}_*.nc").sort, output: "VAR#{i}.nc")
}
(7-7/7)