Module: Cdp
- Defined in:
- lib/cdp.rb
Constant Summary collapse
- @@debug =
false
Class Method Summary collapse
-
.areaWeights(areaVarname, areaFile, ofile = nil, force = false) ⇒ Object
compute area weights from an area variable.
- .debug ⇒ Object
-
.maskedAreaWeights(areaVarname, areaFile, maskVarname, maskFile, ofile = nil, force = false) ⇒ Object
compute area weights from an area variable with a mask from another file.
-
.setCDO ⇒ Object
setup of CDO on different machines based on the hostname.
- .setDebug(value = true) ⇒ Object
-
.splitFilesIntoExperiments(files, exp = nil) ⇒ Object
compute the experiments from the data directories and link the corresponding files.
Class Method Details
.areaWeights(areaVarname, areaFile, ofile = nil, force = false) ⇒ Object
compute area weights from an area variable
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/cdp.rb', line 72 def Cdp.areaWeights(areaVarname,areaFile,ofile=nil,force=false) if ofile.nil? area = Cdo.selname(areaVarname,:input => areaFile) Cdo.setname("area_weight",:input => " -div #{area} -enlarge,#{area} -fldsum #{area}") else unless File.exist?(ofile) and not force puts "Resuse existing file #{ofile}" if @@debug return ofile else area = Cdo.selname(areaVarname,:input => areaFile) Cdo.setname("area_weight",:input => " -div #{area} -enlarge,#{area} -fldsum #{area}", :output => ofile) end end end |
.debug ⇒ Object
32 33 34 |
# File 'lib/cdp.rb', line 32 def Cdp.debug @@debug end |
.maskedAreaWeights(areaVarname, areaFile, maskVarname, maskFile, ofile = nil, force = false) ⇒ Object
compute area weights from an area variable with a mask from another file
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cdp.rb', line 88 def Cdp.maskedAreaWeights(areaVarname,areaFile,maskVarname,maskFile,ofile=nil,force=false) if ofile.nil? maskedArea = Cdo.div(:input => " -selname,#{areaVarname} #{areaFile} -selname,#{maskVarname} #{maskFile}") Cdo.setname("area_weight", :input => " -div #{maskedArea} -enlarge,#{maskedArea} -fldsum #{maskedArea}") else if File.exist?(ofile) and not force puts "Resuse existing file #{ofile}" if @@debug return ofile else maskedArea = Cdo.div(:input => " -selname,#{areaVarname} #{areaFile} -selname,#{maskVarname} #{maskFile}") Cdo.setname("area_weight", :input => " -div #{maskedArea} -enlarge,#{maskedArea} -fldsum #{maskedArea}", :output => ofile) end end end |
.setCDO ⇒ Object
setup of CDO on different machines based on the hostname
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cdp.rb', line 11 def Cdp.setCDO hostname = Socket.gethostname case hostname when /thingol/ Cdo.setCdo(ENV['HOME']+"/local/bin/cdo-dev") when /lizard/ Cdo.setCdo(ENV['HOME']+"/local/rhel55-x64/bin/cdo") when /blizzard/ Cdo.setCdo(ENV['HOME']+"/local/bin/cdo") when /thunder/ Cdo.setCdo(ENV['HOME']+"/local/squeeze-x64/bin/cdo") else puts "Use default Cdo:#{Cdo.getCdo} (version:#{Cdo.version})" end end |
.setDebug(value = true) ⇒ Object
27 28 29 30 31 |
# File 'lib/cdp.rb', line 27 def Cdp.setDebug(value=true) Cdo.checkCdo Cdo.debug = true unless ENV['DEBUG'].nil? @@debug = value end |
.splitFilesIntoExperiments(files, exp = nil) ⇒ Object
compute the experiments from the data directories and link the corresponding files
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cdp.rb', line 37 def Cdp.splitFilesIntoExperiments(files,exp=nil) defautExpName = 'exp' experiments = files.map {|f| File.basename(File.dirname(f))}.uniq.sort_by {|f| f.length}.reverse # take the larges part of the filenames as experiment name if the files are in # the current directory if exp.nil? if [["."],[".."],[".",".."],[""]].include?(experiments) then n = files.map(&:size).min.times.map {|i| if files.map {|f| f[0,i-1]}.uniq.size == 1 1 else nil end }.find_all {|v| not v.nil?}.size-1 uniqName = files[0][0,n] uniqName = defautExpName if uniqName.empty? experiments = [uniqName] end experiments [defautExpName] if experiments == [".."] else experiments = [exp] end experimentFiles, experimentAnalyzedData = {},{} experiments.each {|experiment| experimentFiles[experiment] = files.grep(/#{experiment}/) experimentFiles[experiment].each {|file| files.delete(file)} experimentFiles[experiment].sort! experimentAnalyzedData[experiment] = [] } [experimentFiles,experimentAnalyzedData] end |