spliner 1.0.3 → 1.0.4
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/lib/spliner.rb +1 -1
- data/lib/spliner/spliner.rb +17 -2
- data/spec/spliner_spec.rb +10 -0
- metadata +67 -63
data/lib/spliner.rb
CHANGED
data/lib/spliner/spliner.rb
CHANGED
@@ -42,15 +42,17 @@ module Spliner
|
|
42
42
|
# @overload initialize(key_points, options)
|
43
43
|
# @param key_points [Hash{Float => Float}] keys are X values in increasing order, values Y
|
44
44
|
# @param options [Hash]
|
45
|
-
# @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%'
|
45
|
+
# @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%', or float 0.1
|
46
46
|
# @option options [Symbol] :emethod (:linear) extrapolation method
|
47
|
+
# @option options [Symbol] :fix_invalid_x (false) delete data points not in increasing order
|
47
48
|
#
|
48
49
|
# @overload initialize(x, y, options)
|
49
50
|
# @param x [Array(Float),Vector] the X values of the key points
|
50
51
|
# @param y [Array(Float),Vector] the Y values of the key points
|
51
52
|
# @param options [Hash]
|
52
|
-
# @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%'
|
53
|
+
# @option options [Range,String] :extrapolate ('0%') either a range or percentage, eg '10.0%', or float 0.1
|
53
54
|
# @option options [Symbol] :emethod (:linear) extrapolation method
|
55
|
+
# @option options [Symbol] :fix_invalid_x (false) delete data points not in increasing order
|
54
56
|
#
|
55
57
|
def initialize(*param)
|
56
58
|
# sort parameters from two alternative initializer signatures
|
@@ -67,6 +69,15 @@ module Spliner
|
|
67
69
|
end
|
68
70
|
options ||= {}
|
69
71
|
|
72
|
+
if options[:fix_invalid_x]
|
73
|
+
pp = Hash[x.zip y]
|
74
|
+
pp.keys.each_cons(2) do |a,b|
|
75
|
+
pp.delete b if b < a
|
76
|
+
end
|
77
|
+
x = pp.keys
|
78
|
+
y = pp.values
|
79
|
+
end
|
80
|
+
|
70
81
|
@sections = split_at_duplicates(x).map {|slice| SplinerSection.new x[slice], y[slice] }
|
71
82
|
|
72
83
|
# Handle extrapolation option parameter
|
@@ -79,6 +90,10 @@ module Spliner
|
|
79
90
|
@range = (x.first - extra)..(x.last + extra)
|
80
91
|
when Range
|
81
92
|
@range = ex
|
93
|
+
when Float
|
94
|
+
span = x.last - x.first
|
95
|
+
extra = span * ex
|
96
|
+
@range = (x.first - extra)..(x.last + extra)
|
82
97
|
when nil
|
83
98
|
@range = x.first..x.last
|
84
99
|
else
|
data/spec/spliner_spec.rb
CHANGED
@@ -99,6 +99,10 @@ describe Spliner::Spliner do
|
|
99
99
|
s3 = Spliner::Spliner.new KEYS_0_100, :extrapolate => '10 %'
|
100
100
|
expect(s3.range.first).to be_within(0.0001).of(-10.0)
|
101
101
|
expect(s3.range.last).to be_within(0.0001).of(110.0)
|
102
|
+
|
103
|
+
s4 = Spliner::Spliner.new KEYS_0_100, :extrapolate => 0.1
|
104
|
+
expect(s3.range.first).to be_within(0.0001).of(-10.0)
|
105
|
+
expect(s3.range.last).to be_within(0.0001).of(110.0)
|
102
106
|
end
|
103
107
|
|
104
108
|
it 'splits data points with duplicate X values into separate sections' do
|
@@ -130,4 +134,10 @@ describe Spliner::Spliner do
|
|
130
134
|
expect(Spliner::Spliner::interpolate(DATASET, 0..2, :extrapolate => '5%')).to eq(DATASET.values)
|
131
135
|
end
|
132
136
|
|
137
|
+
it 'has the option :fix_invalid_x to delete invalid x values (not increasing)' do
|
138
|
+
s = Spliner::Spliner.new [0.0, -1.0, 1.0], [0.0, 1.0, 1.0], :extrapolate => '100%', :fix_invalid_x => true
|
139
|
+
expect(s[0.5]).to be_within(0.001).of(0.5)
|
140
|
+
expect(s[-0.5]).to be_within(0.001).of(-0.5)
|
141
|
+
end
|
142
|
+
|
133
143
|
end
|
metadata
CHANGED
@@ -1,85 +1,89 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: spliner
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 1.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
7
|
+
authors:
|
8
|
+
- Tallak Tveide
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.11'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.11'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0.9'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.9'
|
46
|
+
description: Simple library to perform cubic spline interpolation based on key X,Y
|
47
|
+
values
|
48
|
+
email:
|
49
|
+
- tallak@tveide.net
|
40
50
|
executables: []
|
41
|
-
|
42
51
|
extensions: []
|
43
|
-
|
44
52
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
- spliner.gemspec
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- .travis.yml
|
56
|
+
- Gemfile
|
57
|
+
- README.markdown
|
58
|
+
- Rakefile
|
59
|
+
- lib/spliner.rb
|
60
|
+
- lib/spliner/spliner.rb
|
61
|
+
- lib/spliner/spliner_section.rb
|
62
|
+
- spec/spliner_spec.rb
|
63
|
+
- spliner.gemspec
|
57
64
|
homepage: http://www.github.com/tallakt/spliner
|
58
65
|
licenses: []
|
59
|
-
|
60
66
|
post_install_message:
|
61
67
|
rdoc_options: []
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
71
|
none: false
|
67
|
-
requirements:
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.9.1
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
77
|
none: false
|
73
|
-
requirements:
|
74
|
-
|
75
|
-
|
76
|
-
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
77
82
|
requirements: []
|
78
|
-
|
79
83
|
rubyforge_project: spliner
|
80
84
|
rubygems_version: 1.8.24
|
81
85
|
signing_key:
|
82
86
|
specification_version: 3
|
83
87
|
summary: Cubic spline interpolation library
|
84
88
|
test_files: []
|
85
|
-
|
89
|
+
has_rdoc:
|