cdp 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/gemspec +2 -2
- data/lib/cdp.rb +25 -6
- data/test/test_cdp.rb +22 -0
- metadata +4 -2
data/gemspec
CHANGED
@@ -3,10 +3,10 @@ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
|
3
3
|
|
4
4
|
spec = Gem::Specification.new do |s|
|
5
5
|
s.name = "cdp"
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.2'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.files = ["lib/cdp.rb"] + ["gemspec"]
|
9
|
-
|
9
|
+
s.test_file = "test/test_cdp.rb"
|
10
10
|
s.description = "Climate Data Processing helpers"
|
11
11
|
s.summary = "---"
|
12
12
|
s.author = "Ralf Mueller"
|
data/lib/cdp.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'cdo'
|
2
|
-
|
2
|
+
require 'socket'
|
3
|
+
module Cdp
|
3
4
|
|
4
|
-
def
|
5
|
+
def Cdp.setCDO
|
5
6
|
#===============================================================================
|
6
7
|
# setup of CDO on different machines
|
7
8
|
hostname = Socket.gethostname
|
@@ -17,25 +18,25 @@ module CDP
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
+
def Cdp.setDEBUG
|
21
22
|
Cdo.checkCdo
|
22
23
|
Cdo.debug = true unless ENV['DEBUG'].nil?
|
23
24
|
end
|
24
25
|
|
25
26
|
#===============================================================================
|
26
27
|
# compute the experiments from the data directories and link the corresponding files
|
27
|
-
def
|
28
|
+
def Cdp.splitFilesIntoExperiments(files)
|
28
29
|
gridFile = files.pop
|
29
30
|
experiments = files.map {|f| File.basename(File.dirname(f))}.uniq.sort_by {|f| f.length}.reverse
|
30
31
|
# take the larges part of the filenames as experiment name if the files are in
|
31
32
|
# the current directory
|
32
33
|
if experiments == ["."] then
|
33
|
-
n = files.map(&:size).min.times.map {|i|
|
34
|
+
n = files.map(&:size).min.times.map {|i|
|
34
35
|
if files.map {|f| f[0,i-1]}.uniq.size == 1
|
35
36
|
1
|
36
37
|
else
|
37
38
|
nil
|
38
|
-
end
|
39
|
+
end
|
39
40
|
}.find_all {|v| not v.nil?}.size-1
|
40
41
|
uniqName = files[0][0,n]
|
41
42
|
experiments = [uniqName]
|
@@ -51,4 +52,22 @@ module CDP
|
|
51
52
|
|
52
53
|
[gridFile,experimentFiles,experimentAnalyzedData]
|
53
54
|
end
|
55
|
+
|
56
|
+
def Cdp.manualAreaWeights(areaVarname,areaFile,ofile=nil)
|
57
|
+
area = Cdo.selname(areaVarname,:in => areaFile)
|
58
|
+
areaSum = Cdo.enlarge(area,:in => "-fldsum #{area}")
|
59
|
+
if ofile.nil?
|
60
|
+
weights = Cdo.setname("area_weight",:in => " -div #{area} #{areaSum}")
|
61
|
+
else
|
62
|
+
Cdo.setname("area_weight",:in => " -div #{area} #{areaSum}", :out => ofile)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
def Cdp.manualMaskedAreaWeights(areaVarname,areaFile,maskVarname,maskFile,ofile=nil)
|
66
|
+
maskedArea = Cdo.div(:in => " -selname,#{areaVarname} #{areaFile} -selname,#{maskVarname} #{maskFile}")
|
67
|
+
if ofile.nil?
|
68
|
+
maskedAreaSum = Cdo.setname("area_weight", :in => " -div #{maskedArea} -enlarge,#{maskedArea} -fldsum #{maskedArea}")
|
69
|
+
else
|
70
|
+
Cdo.setname("area_weight", :in => " -div #{maskedArea} -enlarge,#{maskedArea} -fldsum #{maskedArea}", :out => ofile)
|
71
|
+
end
|
72
|
+
end
|
54
73
|
end
|
data/test/test_cdp.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'cdp'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
DATADIR = ENV['HOME'] + "/data/icon"
|
7
|
+
ICONGRID = DATADIR + "/icon-R2B04-grid-etopo.nc"
|
8
|
+
ICONMASK = DATADIR + "/mask.nc"
|
9
|
+
|
10
|
+
class TestCdp < Test::Unit::TestCase
|
11
|
+
def test_area_weight
|
12
|
+
Cdo.debug = true
|
13
|
+
weights = Cdp.manualAreaWeights("cell_area",ICONGRID)
|
14
|
+
assert_equal("1",Cdo.outputkey("value", :in => Cdo.fldsum(:in => weights)).first)
|
15
|
+
end
|
16
|
+
def test_masked_area_weight
|
17
|
+
Cdo.debug = true
|
18
|
+
Cdp.setCDO
|
19
|
+
weights = Cdp.manualMaskedAreaWeights("cell_area",ICONGRID,"wet_c",ICONMASK)
|
20
|
+
assert_equal("1",Cdo.outputkey("value", :in => Cdo.fldsum(:in => weights)).uniq.first)
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cdp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -35,6 +35,7 @@ extra_rdoc_files: []
|
|
35
35
|
files:
|
36
36
|
- lib/cdp.rb
|
37
37
|
- gemspec
|
38
|
+
- test/test_cdp.rb
|
38
39
|
homepage:
|
39
40
|
licenses:
|
40
41
|
- BSD
|
@@ -60,4 +61,5 @@ rubygems_version: 1.8.23
|
|
60
61
|
signing_key:
|
61
62
|
specification_version: 3
|
62
63
|
summary: ! '---'
|
63
|
-
test_files:
|
64
|
+
test_files:
|
65
|
+
- test/test_cdp.rb
|