edfize 0.1.0.beta5 → 0.1.0.beta6

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: f4a48063129c0326118a9f2758d13786a65bcfe2
4
- data.tar.gz: 2f6b9b8f5a4d36c98b4bd7af31ada7c63a2b57b9
3
+ metadata.gz: fd66c8588e2ded11c90880663301a6ff5c735316
4
+ data.tar.gz: fa67299dca68b65f0d56393112f7b4395d5d58ed
5
5
  SHA512:
6
- metadata.gz: 7a22f2735682235b18aad50522791969cdc9e63aaf5e12c00a7777f5503f33d563115041400b9906607bd5398b48138f11b903749b373f92cae82aba315bea4a
7
- data.tar.gz: 1faecd4de21fef9b0e495373bb81e9bcb6d5fc250abbe1876acc67b0087b34b21f6f856e4f1519f1e849c5baf048a382acb97072e7c333dfd3970ca76d2d7e5d
6
+ metadata.gz: 598a5dad055dd6e3ad3b7b339961a04ce05367ef460773e221ef9f7bd6ae7213cf35e84c71ffdd976bcda481141c7cd627eb669c9b2dfed52ed13636ccfa4d69
7
+ data.tar.gz: f1be2b665756ca380aac2d8f842e130f6f1f8417a4f5b5b0686b11b06fa1c2edebac07f7cd561382c1f73926c43edff64d0928fe70cb50ff29c4ac6d47b63b0f
data/README.md CHANGED
@@ -81,9 +81,9 @@ puts "EDF #{edf.filename} contains the following #{edf.signals.count} signal#{'s
81
81
 
82
82
  edf.signals.each do |signal|
83
83
  puts "Signal"
84
- puts " Label : #{signal.label}"
85
- puts " Samples Per Data Record: #{signal.samples_per_data_record}"
86
- puts " First 10 Samples : #{(signal.samples[0..10] + ['...']).inspect}\n\n"
84
+ puts " Label : #{signal.label}"
85
+ puts " Samples Per Data Record : #{signal.samples_per_data_record}"
86
+ puts " First 10 Physical Values : #{(signal.physical_values[0..10] + ['...']).inspect}\n\n"
87
87
  end
88
88
  ```
89
89
 
@@ -93,74 +93,74 @@ When run, the code above will output the following:
93
93
  EDF shhs1-200001.edf contains the following 14 signals:
94
94
 
95
95
  Signal
96
- Label : SaO2
97
- Samples Per Data Record: 1
98
- First 10 Samples : [29695, 29695, 29695, 29695, 29695, 29695, 29695, 29695, 28927, 28927, 28927, "..."]
96
+ Label : SaO2
97
+ Samples Per Data Record : 1
98
+ First 10 Physical Values : [95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 95.31242847333486, 94.14053559166858, 94.14053559166858, 94.14053559166858, "..."]
99
99
 
100
100
  Signal
101
- Label : H.R.
102
- Samples Per Data Record: 1
103
- First 10 Samples : [-12493, -12493, -12493, -12697, -12697, -12697, -13107, -13107, -13107, -13107, -13107, "..."]
101
+ Label : H.R.
102
+ Samples Per Data Record : 1
103
+ First 10 Physical Values : [77.34416723887999, 77.34416723887999, 77.34416723887999, 76.56595712214848, 76.56595712214848, 76.56595712214848, 75.00190737773708, 75.00190737773708, 75.00190737773708, 75.00190737773708, 75.00190737773708, "..."]
104
104
 
105
105
  Signal
106
- Label : EEG(sec)
107
- Samples Per Data Record: 125
108
- First 10 Samples : [-5, -13, -2, -13, -23, 1, 21, -9, 6, -17, 6, "..."]
106
+ Label : EEG(sec)
107
+ Samples Per Data Record : 125
108
+ First 10 Physical Values : [-4.411764705882348, 5.392156862745111, 2.4509803921568647, 0.49019607843136725, -0.49019607843136725, -10.294117647058826, 3.4313725490196134, 12.25490196078431, -1.470588235294116, -2.4509803921568647, -8.333333333333329, "..."]
109
109
 
110
110
  Signal
111
- Label : ECG
112
- Samples Per Data Record: 125
113
- First 10 Samples : [3, 7, -10, 0, 5, 4, 0, 3, 11, -12, -3, "..."]
111
+ Label : ECG
112
+ Samples Per Data Record : 125
113
+ First 10 Physical Values : [0.03431372549019618, 0.03431372549019618, 0.03431372549019618, 0.03431372549019618, 0.044117647058823595, 0.044117647058823595, 0.044117647058823595, 0.044117647058823595, 0.044117647058823595, 0.03431372549019618, 0.03431372549019618, "..."]
114
114
 
115
115
  Signal
116
- Label : EMG
117
- Samples Per Data Record: 125
118
- First 10 Samples : [51, 9, -48, 84, 10, -23, 20, -10, 58, 2, 26, "..."]
116
+ Label : EMG
117
+ Samples Per Data Record : 125
118
+ First 10 Physical Values : [12.622549019607845, 3.7990196078431353, -3.5539215686274517, -2.5735294117647065, 8.455882352941174, 1.5931372549019613, 9.436274509803923, -8.700980392156861, -2.5735294117647065, 13.112745098039213, -12.867647058823529, "..."]
119
119
 
120
120
  Signal
121
- Label : EOG(L)
122
- Samples Per Data Record: 50
123
- First 10 Samples : [29, 3, -127, 15, -67, 47, -3, -33, -25, 16, 28, "..."]
121
+ Label : EOG(L)
122
+ Samples Per Data Record : 50
123
+ First 10 Physical Values : [28.921568627450966, 17.15686274509804, 25.0, 19.117647058823536, -5.392156862745097, -9.313725490196077, -0.49019607843136725, -1.470588235294116, 1.470588235294116, -1.470588235294116, 0.49019607843136725, "..."]
124
124
 
125
125
  Signal
126
- Label : EOG(R)
127
- Samples Per Data Record: 50
128
- First 10 Samples : [12, 25, 127, -106, 59, -3, 9, 7, 20, 7, -7, "..."]
126
+ Label : EOG(R)
127
+ Samples Per Data Record : 50
128
+ First 10 Physical Values : [12.25490196078431, 1.470588235294116, 10.294117647058812, 5.392156862745111, 17.15686274509804, 18.137254901960773, 25.980392156862735, 32.84313725490196, 25.0, 26.960784313725497, 22.058823529411768, "..."]
129
129
 
130
130
  Signal
131
- Label : EEG
132
- Samples Per Data Record: 125
133
- First 10 Samples : [-3, 31, 65, 4, 52, 12, -2, 21, -26, 34, -9, "..."]
131
+ Label : EEG
132
+ Samples Per Data Record : 125
133
+ First 10 Physical Values : [-2.4509803921568647, 1.470588235294116, -9.313725490196077, -6.372549019607845, -0.49019607843136725, -10.294117647058826, -12.25490196078431, -12.25490196078431, -7.352941176470594, 1.470588235294116, 6.372549019607845, "..."]
134
134
 
135
135
  Signal
136
- Label : THOR RES
137
- Samples Per Data Record: 10
138
- First 10 Samples : [-27, 17, -25, -57, 18, -24, 6, 32, 38, -21, 41, "..."]
136
+ Label : THOR RES
137
+ Samples Per Data Record : 10
138
+ First 10 Physical Values : [0.207843137254902, 0.207843137254902, 0.15294117647058825, 0.0980392156862745, 0.03529411764705881, -0.0117647058823529, -0.050980392156862786, -0.08235294117647052, -0.10588235294117654, -0.1215686274509804, -0.13725490196078427, "..."]
139
139
 
140
140
  Signal
141
- Label : ABDO RES
142
- Samples Per Data Record: 10
143
- First 10 Samples : [-40, 34, -2, -28, 68, -117, -20, -24, 5, -27, 67, "..."]
141
+ Label : ABDO RES
142
+ Samples Per Data Record : 10
143
+ First 10 Physical Values : [0.30980392156862746, 0.24705882352941178, 0.16078431372549018, 0.06666666666666665, -0.0039215686274509665, -0.08235294117647052, -0.1607843137254903, -0.2078431372549019, -0.2313725490196079, -0.2549019607843137, -0.2705882352941176, "..."]
144
144
 
145
145
  Signal
146
- Label : POSITION
147
- Samples Per Data Record: 1
148
- First 10 Samples : [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, "..."]
146
+ Label : POSITION
147
+ Samples Per Data Record : 1
148
+ First 10 Physical Values : [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, "..."]
149
149
 
150
150
  Signal
151
- Label : LIGHT
152
- Samples Per Data Record: 1
153
- First 10 Samples : [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "..."]
151
+ Label : LIGHT
152
+ Samples Per Data Record : 1
153
+ First 10 Physical Values : [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, "..."]
154
154
 
155
155
  Signal
156
- Label : NEW AIR
157
- Samples Per Data Record: 10
158
- First 10 Samples : [6, 7, 3, 3, 7, 3, 6, 0, 5, 5, 9, "..."]
156
+ Label : NEW AIR
157
+ Samples Per Data Record : 10
158
+ First 10 Physical Values : [6.372549019607845, 6.372549019607845, 5.392156862745111, 3.4313725490196134, 7.35294117647058, 6.372549019607845, 8.333333333333343, 9.313725490196077, 6.372549019607845, 6.372549019607845, 7.35294117647058, "..."]
159
159
 
160
160
  Signal
161
- Label : OX stat
162
- Samples Per Data Record: 1
163
- First 10 Samples : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, "..."]
161
+ Label : OX stat
162
+ Samples Per Data Record : 1
163
+ First 10 Physical Values : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, "..."]
164
164
  ```
165
165
 
166
166
  ## Contributing
data/lib/edfize/edf.rb CHANGED
@@ -179,15 +179,23 @@ module Edfize
179
179
  end
180
180
 
181
181
  def get_data_records
182
+ @signals.each{|signal| signal.initialize_array_sizes!(@number_of_data_records)}
183
+
182
184
  current_read_offset = size_of_header
183
185
  (0..@number_of_data_records-1).to_a.each do |data_record_index|
184
186
  @signals.each do |signal|
185
187
  # 16-bit signed integer size = 2 Bytes = 2 ASCII characters
188
+ # 16-bit signed integer in "Little Endian" format (least significant byte first)
189
+ # unpack: s< 16-bit signed, (little-endian) byte order
186
190
  read_size = signal.samples_per_data_record * SIZE_OF_SAMPLE_IN_BYTES
187
- signal.samples[data_record_index..data_record_index+signal.samples_per_data_record] = IO.binread(@filename, read_size, current_read_offset).unpack('s*')
191
+ start_index = data_record_index * signal.samples_per_data_record
192
+ end_index = (data_record_index + 1) * signal.samples_per_data_record
193
+ signal.digital_values[start_index..end_index] = IO.binread(@filename, read_size, current_read_offset).unpack('s<*')
188
194
  current_read_offset += read_size
189
195
  end
190
196
  end
197
+
198
+ @signals.each{|signal| signal.calculate_physical_values!}
191
199
  end
192
200
 
193
201
  def data_size
data/lib/edfize/signal.rb CHANGED
@@ -4,7 +4,7 @@ module Edfize
4
4
  :physical_minimum, :physical_maximum,
5
5
  :digital_minimum, :digital_maximum,
6
6
  :prefiltering, :samples_per_data_record,
7
- :reserved_area, :samples
7
+ :reserved_area, :digital_values, :physical_values
8
8
 
9
9
  SIGNAL_CONFIG = {
10
10
  label: { size: 16, after_read: :strip, name: 'Label' },
@@ -20,7 +20,8 @@ module Edfize
20
20
  }
21
21
 
22
22
  def initialize
23
- @samples = []
23
+ @digital_values = []
24
+ @physical_values = []
24
25
  end
25
26
 
26
27
  def print_header
@@ -29,5 +30,18 @@ module Edfize
29
30
  end
30
31
  end
31
32
 
33
+ # Physical value (dimension PhysiDim) = (ASCIIvalue-DigiMin)*(PhysiMax-PhysiMin)/(DigiMax-DigiMin) + PhysiMin.
34
+ def calculate_physical_values!
35
+ @physical_values = @digital_values.collect{|sample| ( sample - @digital_minimum ) * ( @physical_maximum - @physical_minimum ) / ( @digital_maximum - @digital_minimum) + @physical_minimum }
36
+ end
37
+
38
+ def samples
39
+ @physical_values
40
+ end
41
+
42
+ def initialize_array_sizes!(data_records)
43
+ @physical_values = Array.new(@samples_per_data_record * data_records)
44
+ end
45
+
32
46
  end
33
47
  end
@@ -3,7 +3,7 @@ module Edfize
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
5
  TINY = 0
6
- BUILD = "beta5"
6
+ BUILD = "beta6"
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.beta5
4
+ version: 0.1.0.beta6
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-05 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize