edfize 0.1.0 → 0.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5f84db69e7bbe84842214eee8dd220ee6a89a72
4
- data.tar.gz: 0f447049e2a23134804e007de36b70186295845a
3
+ metadata.gz: 6dff2062988c3f2049fb84f7e69ab8a2a6a9d050
4
+ data.tar.gz: 74403328abbb74f222e6cd09e7f1c2033bfe79ab
5
5
  SHA512:
6
- metadata.gz: 1decca6f10873141a21d139ba6b76126e5b9750c4ee28f6225ad4c498a08aac977dfc977435f5a82d937829fef9bcb3d8fc1e97a80b4072771a7f34cf7dda77a
7
- data.tar.gz: d0f21d699870bac05cb8c2694e26860ca35d31bf3999247ce4244351436f88866348c08cd489b3c2c162a54d4cf10d493fc97fdc4f071c22f09cd7ea102070e7
6
+ metadata.gz: 5196f1d573d713da7214c2c0b5210f3603e56d5df54ece83de093b5f3be220c4db33066408593df7d35b6955eb10b954c608d6a9c0bfb7980e3591c3c7062704
7
+ data.tar.gz: cb47c743158f709599374ca69bd3d601d9ba25ba19243f6d0416b0a7a3b73bc87176af901acef8e8f1997f7367d26274b8f3bb90b8b29592333ddd3b35f06a11
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.2.0
2
+
3
+ ### Enhancements
4
+ - EDFs can now be partially loaded by specifying the epoch number and epoch size in seconds
5
+
6
+ ### Testing
7
+ - Updated to minitest test framework along with simplecov for coverage
8
+
1
9
  ## 0.1.0 (May 28, 2014)
2
10
  - Initial EDF class to load headers and signals into Ruby objects
3
11
  - `edfize` command has the following actions:
data/lib/edfize/edf.rb CHANGED
@@ -58,6 +58,13 @@ module Edfize
58
58
  get_data_records
59
59
  end
60
60
 
61
+ # Epoch Number is Zero Indexed, and Epoch Size is in Seconds (Not Data Records)
62
+ def load_epoch(epoch_number, epoch_size)
63
+ # reset_signals!
64
+ load_digital_signals_by_epoch(epoch_number, epoch_size)
65
+ calculate_physical_values!
66
+ end
67
+
61
68
  def size_of_header
62
69
  HEADER_OFFSET + ns * Signal::SIGNAL_CONFIG.collect{|k,h| h[:size]}.inject(:+)
63
70
  end
@@ -153,6 +160,11 @@ module Edfize
153
160
  @number_of_signals
154
161
  end
155
162
 
163
+ def reset_signals!
164
+ @signals = []
165
+ read_signal_header
166
+ end
167
+
156
168
  def create_signals
157
169
  (0..ns-1).to_a.each do |signal_number|
158
170
  @signals[signal_number] ||= Signal.new()
@@ -190,12 +202,25 @@ module Edfize
190
202
  calculate_physical_values!()
191
203
  end
192
204
 
205
+ def load_digital_signals_by_epoch(epoch_number, epoch_size)
206
+ size_of_data_record_in_bytes = @signals.collect(&:samples_per_data_record).inject(:+).to_i * SIZE_OF_SAMPLE_IN_BYTES
207
+ data_records_to_retrieve = (epoch_size / @duration_of_a_data_record rescue 0)
208
+ length_of_bytes_to_read = (data_records_to_retrieve+1) * size_of_data_record_in_bytes
209
+ epoch_offset_size = epoch_number * epoch_size * size_of_data_record_in_bytes # TODO: The size in bytes of an epoch
210
+
211
+ all_signal_data = (IO.binread(@filename, length_of_bytes_to_read, size_of_header + epoch_offset_size).unpack('s<*') rescue [])
212
+ load_signal_data(all_signal_data, data_records_to_retrieve+1)
213
+ end
214
+
193
215
  # 16-bit signed integer size = 2 Bytes = 2 ASCII characters
194
216
  # 16-bit signed integer in "Little Endian" format (least significant byte first)
195
217
  # unpack: s< 16-bit signed, (little-endian) byte order
196
218
  def load_digital_signals
197
- @all_signal_data = IO.binread(@filename, nil, size_of_header).unpack('s<*')
219
+ all_signal_data = IO.binread(@filename, nil, size_of_header).unpack('s<*')
220
+ load_signal_data(all_signal_data, @number_of_data_records)
221
+ end
198
222
 
223
+ def load_signal_data(all_signal_data, data_records_retrieved)
199
224
  all_samples_per_data_record = @signals.collect{|s| s.samples_per_data_record}
200
225
  total_samples_per_data_record = all_samples_per_data_record.inject(:+).to_i
201
226
 
@@ -206,11 +231,11 @@ module Edfize
206
231
  offset += samples_per_data_record
207
232
  end
208
233
 
209
- (0..@number_of_data_records-1).to_a.each do |data_record_index|
234
+ (0..data_records_retrieved-1).to_a.each do |data_record_index|
210
235
  @signals.each_with_index do |signal, signal_index|
211
236
  read_start = data_record_index * total_samples_per_data_record + offsets[signal_index]
212
237
  (0..signal.samples_per_data_record - 1).to_a.each do |value_index|
213
- signal.digital_values << @all_signal_data[read_start+value_index]
238
+ signal.digital_values << all_signal_data[read_start+value_index]
214
239
  end
215
240
  end
216
241
  end
data/lib/edfize/signal.rb CHANGED
@@ -39,7 +39,7 @@ module Edfize
39
39
 
40
40
  # Physical value (dimension PhysiDim) = (ASCIIvalue-DigiMin)*(PhysiMax-PhysiMin)/(DigiMax-DigiMin) + PhysiMin.
41
41
  def calculate_physical_values!
42
- @physical_values = @digital_values.collect{|sample| ( sample - @digital_minimum ) * ( @physical_maximum - @physical_minimum ) / ( @digital_maximum - @digital_minimum) + @physical_minimum }
42
+ @physical_values = @digital_values.collect{|sample| (( sample - @digital_minimum ) * ( @physical_maximum - @physical_minimum ) / ( @digital_maximum - @digital_minimum) + @physical_minimum rescue nil) }
43
43
  end
44
44
 
45
45
  def samples
@@ -1,9 +1,9 @@
1
1
  module Edfize
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  TINY = 0
6
- BUILD = nil
6
+ BUILD = "beta1"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edfize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -92,9 +92,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ">="
95
+ - - ">"
96
96
  - !ruby/object:Gem::Version
97
- version: '0'
97
+ version: 1.3.1
98
98
  requirements: []
99
99
  rubyforge_project:
100
100
  rubygems_version: 2.2.2