edfize 0.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 07173882caa9f634f306d9f351e05213db2bd7b4
4
+ data.tar.gz: 0b78baa7a05690594bcd77afa437cdd864ef3fae
5
+ SHA512:
6
+ metadata.gz: a77a87ed38e265fa516302a98643a9f2f1810b1f6b7c46e57bb92372d8fa0936c5a1359a4f7b7ee3bc41985550ee3276d913bf3cbad3d7b6638ca2efee32b3ae
7
+ data.tar.gz: 154f9505e976ccacbbbfab96d94d2f9d2c29f2b74edbf039a888f430c512bca2feed80658782f6b4c4cdf9373e006c2db713db1b24f251e4011f051867d78947
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## 0.1.0
2
+ - Initial EDF class to load headers and signals into Ruby objects
3
+ - `edfize` command has the following actions:
4
+ - `check`: Validates EDFs in the current directory for errors
5
+ - `test`: Same as `check`
6
+ - `run`: Prints out the headers of all edfs in the current directory
7
+ - `help`: Displays information about `edfize` along with all available commands
8
+ - `version`: Displays the current `edfize` version
9
+ - `edfize test` checks for the following:
10
+ - Expected Length Check: The expected total size is computed from the (`number
11
+ of data records` * `total samples across all signals`) + `size of header` and
12
+ this is compared to the actual file size.
data/LICENSE.txt ADDED
@@ -0,0 +1,111 @@
1
+ Copyright (c) 2014 Division of Medicine Program of Sleep Medicine Epidemiology
2
+ https://github.com/sleepepi
3
+
4
+
5
+ This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
6
+
7
+
8
+ Legal Code
9
+ http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
10
+
11
+ Creative Commons
12
+ Attribution-NonCommercial-ShareAlike 3.0 Unported
13
+
14
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE.
15
+
16
+ License
17
+
18
+ THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
19
+
20
+ BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
21
+
22
+ 1. Definitions
23
+
24
+ a. "Adaptation" means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.
25
+
26
+ b. "Collection" means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(g) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License.
27
+
28
+ c. "Distribute" means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.
29
+
30
+ d. "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, Noncommercial, ShareAlike.
31
+
32
+ e. "Licensor" means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
33
+
34
+ f. "Original Author" means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
35
+
36
+ g. "Work" means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
37
+
38
+ h. "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
39
+
40
+ i. "Publicly Perform" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
41
+
42
+ j."Reproduce" means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
43
+
44
+ 2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
45
+
46
+ 3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
47
+
48
+ a. to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
49
+
50
+ b. to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";
51
+
52
+ c. to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
53
+
54
+ d. to Distribute and Publicly Perform Adaptations.
55
+
56
+ The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights described in Section 4(e).
57
+
58
+ 4. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
59
+
60
+ a. You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(d), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(d), as requested.
61
+
62
+ b. You may Distribute or Publicly Perform an Adaptation only under: (i) the terms of this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License"). You must include a copy of, or the URI, for Applicable License with every copy of each Adaptation You Distribute or Publicly Perform. You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License. You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.
63
+
64
+ c. You may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in con-nection with the exchange of copyrighted works.
65
+
66
+ d. If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and, (iv) consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(d) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
67
+
68
+ e. For the avoidance of doubt:
69
+
70
+ i. Non-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
71
+
72
+ ii. Waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and,
73
+
74
+ iii. Voluntary License Schemes. The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c).
75
+
76
+ f. Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
77
+
78
+ 5. Representations, Warranties and Disclaimer
79
+
80
+ UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
81
+
82
+ 6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
83
+
84
+ 7. Termination
85
+
86
+ a. This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
87
+
88
+ b. Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
89
+
90
+ 8. Miscellaneous
91
+
92
+ a. Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
93
+
94
+ b. Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
95
+
96
+ c. If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
97
+
98
+ d. No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
99
+
100
+ e. This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
101
+
102
+ f. The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
103
+
104
+
105
+ Creative Commons Notice
106
+
107
+ Creative Commons is not a party to this License, and makes no warranty whatsoever in connection with the Work. Creative Commons will not be liable to You or any party on any legal theory for any damages whatsoever, including without limitation any general, special, incidental or consequential damages arising in connection to this license. Notwithstanding the foregoing two (2) sentences, if Creative Commons has expressly identified itself as the Licensor hereunder, it shall have all rights and obligations of Licensor.
108
+
109
+ Except for the limited purpose of indicating to the public that the Work is licensed under the CCPL, Creative Commons does not authorize the use by either party of the trademark "Creative Commons" or any related trademark or logo of Creative Commons without the prior written consent of Creative Commons. Any permitted use will be in compliance with Creative Commons' then-current trademark usage guidelines, as may be published on its website or otherwise made available upon request from time to time. For the avoidance of doubt, this trademark restriction does not form part of this License.
110
+
111
+ Creative Commons may be contacted at http://creativecommons.org/.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Edfize
2
+
3
+ [![Build Status](https://travis-ci.org/sleepepi/edfize.svg?branch=master)](https://travis-ci.org/sleepepi/edfize)
4
+ [![Dependency Status](https://gemnasium.com/sleepepi/edfize.svg)](https://gemnasium.com/sleepepi/edfize)
5
+ [![Code Climate](https://codeclimate.com/github/sleepepi/edfize.png)](https://codeclimate.com/github/sleepepi/edfize)
6
+
7
+ Ruby gem used to load, validate, and parse European Data Format files. Used for batch testing EDFs for errors. Ruby 2.0+ compatible.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'edfize'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install edfize
22
+
23
+ ## Usage
24
+
25
+ ### Validate EDFs
26
+
27
+ Use `edfize check` to check that EDFs stored in the current directory have a valid format.
28
+
29
+ cd <edf-directory>
30
+ edfize check
31
+
32
+ ### Print Signal Header information
33
+
34
+ Use `edfize run` to print out signal header information for each EDF in the current directory.
35
+
36
+ cd <edf-directory>
37
+ edfize run
38
+
39
+ ### View A List of All Available Commands for Edfize
40
+
41
+ Use `edfize help` to list available commands and descriptions for Edfize.
42
+
43
+ edfize help
44
+
45
+ ### View Current Version of Edfize
46
+
47
+ Use `edfize version` to check the version of Edfize.
48
+
49
+ edfize version
50
+
51
+ ### Upgrade Edfize
52
+
53
+ Use `gem install edfize` to update Edfize to the latest stable
54
+
55
+ Use `gem install edfize --pre` to update Edfize to the latest prerelease
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/sleepepi/edfize/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = false
10
+ end
11
+
12
+ task default: :test
data/bin/edfize ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/edfize', __FILE__)
4
+
5
+ Edfize.launch(ARGV)
data/edfize.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # Compiling the Gem
2
+ # gem build edfize.gemspec
3
+ # gem install ./edfize-x.x.x.gem --no-ri --no-rdoc --local
4
+ #
5
+ # gem push edfize-x.x.x.gem
6
+ # gem list -r edfize
7
+ # gem install edfize
8
+
9
+ # coding: utf-8
10
+ lib = File.expand_path('../lib', __FILE__)
11
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
12
+ require 'edfize/version'
13
+
14
+ Gem::Specification.new do |spec|
15
+ spec.name = "edfize"
16
+ spec.version = Edfize::VERSION::STRING
17
+ spec.authors = ["Remo Mueller"]
18
+ spec.email = ["remosm@gmail.com"]
19
+ spec.summary = %q{Load, validate, and parse European Data Format files. Used for batch testing EDFs for errors.}
20
+ spec.description = %q{Load, validate, and parse European Data Format files. Used for batch testing EDFs for errors. Run `edfize` on command line to view full list of options.}
21
+ spec.homepage = "https://github.com/sleepepi/edfize"
22
+ spec.license = "CC BY-NC-SA 3.0"
23
+
24
+ spec.files = Dir['{bin,lib}/**/*'] + ['CHANGELOG.md', 'LICENSE.txt', 'Rakefile', 'README.md', 'edfize.gemspec']
25
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
26
+ spec.test_files = spec.files.grep(%r{^(test)/})
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "colorize", "~> 0.7.2"
30
+
31
+ spec.add_development_dependency "bundler", "~> 1.6"
32
+ spec.add_development_dependency "rake"
33
+ end
data/lib/edfize/edf.rb ADDED
@@ -0,0 +1,254 @@
1
+ require 'edfize/signal'
2
+
3
+ module Edfize
4
+ class Edf
5
+ attr_reader :signals, :filename
6
+
7
+ HEADER_OFFSET = 256
8
+
9
+ def initialize(filename)
10
+ @filename = filename
11
+ @signals = []
12
+ signal_labels
13
+ transducer_types
14
+ physical_dimensions
15
+ physical_minimums
16
+ physical_maximums
17
+ digital_minimums
18
+ digital_maximums
19
+ prefilterings
20
+ samples_in_data_records
21
+ reserved_areas
22
+ end
23
+
24
+ def size
25
+ File.size(@filename)
26
+ end
27
+
28
+ def size_of_header
29
+ HEADER_OFFSET + ns * (16 + 80 + 8 + 8 + 8 + 8 + 8 + 80 + 8 + 32)
30
+ end
31
+
32
+ def expected_size_of_header
33
+ 256 + (ns * 256)
34
+ end
35
+
36
+ def total_size
37
+ IO.binread(@filename).size
38
+ end
39
+
40
+ def expected_data_size
41
+ result = 0
42
+ @signals.each do |signal|
43
+ result += signal.samples_in_data_record.to_i * 2 # NR * Int(16)
44
+ end
45
+ result * number_of_data_records.to_i
46
+ end
47
+
48
+ def expected_total_size
49
+ expected_data_size + size_of_header
50
+ # (duration_of_a_data_record.to_i * number_of_data_records.to_i * number_of_signals.to_i) * 8
51
+ end
52
+
53
+ def print_header
54
+ puts @filename
55
+ puts "#{size} bytes (Total File Size)"
56
+ puts "'#{header_version}' (0)"
57
+ puts "'#{header_local_patient_identification}' (local patient identification)"
58
+ puts "'#{header_local_recording_identification}' (local recording indentification)"
59
+ puts "'#{header_start_date_of_recording}' (dd.mm.yy start date of recording)"
60
+ puts "'#{header_start_time_of_recording}' (hh.mm.ss start time of recording)"
61
+ # puts "--- RESERVED"
62
+ puts "'#{number_of_data_records}' (number of data records, -1 if unknown)"
63
+ puts "'#{duration_of_a_data_record}' seconds (duration of a data record)"
64
+ puts "'#{number_of_signals}' number of signals (ns) in data record"
65
+ signals.each_with_index do |signal, index|
66
+ puts "'#{signal.label}' (signal[#{index+1}] label)"
67
+ puts "'#{signal.physical_dimension}' (signal[#{index+1}] physical_dimension)"
68
+ puts "'#{signal.transducer_type}' (signal[#{index+1}] transducer_type)"
69
+ puts "'#{signal.physical_minimum}' (signal[#{index+1}] physical_minimum)"
70
+ puts "'#{signal.physical_maximum}' (signal[#{index+1}] physical_maximum)"
71
+ puts "'#{signal.digital_minimum}' (signal[#{index+1}] digital_minimum)"
72
+ puts "'#{signal.digital_maximum}' (signal[#{index+1}] digital_maximum)"
73
+ puts "'#{signal.prefiltering}' (signal[#{index+1}] prefiltering)"
74
+ puts "'#{signal.samples_in_data_record}' (signal[#{index+1}] samples_in_data_record)"
75
+ puts "'#{signal.reserved_area}' (signal[#{index+1}] reserved_area)"
76
+ end
77
+ puts "#{size} bytes (Total File Size)"
78
+ puts "Size of Header (bytes) : #{size_of_header}"
79
+ puts "Size of Data (bytes) : #{data_size}"
80
+ puts "Total Size (bytes) : #{total_size}"
81
+
82
+ puts "Expected Size of Header (bytes) : #{expected_size_of_header}"
83
+ puts "Expected Size of Data (bytes) : #{expected_data_size}"
84
+ puts "Expected Total Size (bytes) : #{expected_total_size}"
85
+ end
86
+
87
+ def header_version
88
+ IO.binread(@filename, 8)
89
+ end
90
+
91
+ # 80 ascii : local patient identification (mind item 3 of the additional EDF+ specs)
92
+ def header_local_patient_identification
93
+ IO.binread(@filename, 80, 8)
94
+ end
95
+
96
+ # 80 ascii : local recording identification (mind item 4 of the additional EDF+ specs)
97
+ def header_local_recording_identification
98
+ IO.binread(@filename, 80, 88)
99
+ end
100
+
101
+ # 8 ascii : startdate of recording (dd.mm.yy) (mind item 2 of the additional EDF+ specs)
102
+ def header_start_date_of_recording
103
+ IO.binread(@filename, 8, 168)
104
+ end
105
+
106
+ # 8 ascii : starttime of recording (hh.mm.ss)
107
+ def header_start_time_of_recording
108
+ IO.binread(@filename, 8, 176)
109
+ end
110
+
111
+ # 8 ascii : number of bytes in header record
112
+ def number_of_bytes_in_header
113
+ IO.binread(@filename, 8, 184)
114
+ end
115
+
116
+ # 44 ascii : reserved
117
+ # def reserved
118
+ # IO.binread(@filename, 44, 192)
119
+ # end
120
+
121
+ # 8 ascii : number of data records (-1 if unknown, obey item 10 of the additional EDF+ specs)
122
+ def number_of_data_records
123
+ IO.binread(@filename, 8, 236)
124
+ end
125
+
126
+ # 8 ascii : duration of a data record, in seconds
127
+ def duration_of_a_data_record
128
+ IO.binread(@filename, 8, 244)
129
+ end
130
+
131
+ # 4 ascii : number of signals (ns) in data record
132
+ def number_of_signals
133
+ IO.binread(@filename, 4, 252)
134
+ end
135
+
136
+ def ns
137
+ Integer(self.number_of_signals) rescue 0
138
+ end
139
+
140
+ # ns * 16 ascii : ns * label (e.g. EEG Fpz-Cz or Body temp) (mind item 9 of the additional EDF+ specs)
141
+ def signal_labels
142
+ offset = HEADER_OFFSET
143
+ (0..ns-1).to_a.each do |signal_number|
144
+ @signals[signal_number] ||= Signal.new()
145
+ @signals[signal_number].label = IO.binread(@filename, 16, offset+(signal_number*16))
146
+ end
147
+ end
148
+
149
+ # ns * 80 ascii : ns * transducer type (e.g. AgAgCl electrode)
150
+ def transducer_types
151
+ offset = HEADER_OFFSET + ns * 16
152
+ (0..ns-1).to_a.each do |signal_number|
153
+ @signals[signal_number] ||= Signal.new()
154
+ @signals[signal_number].transducer_type = IO.binread(@filename, 80, offset+(signal_number*80))
155
+ end
156
+ end
157
+
158
+ # ns * 8 ascii : ns * physical dimension (e.g. uV or degreeC)
159
+ def physical_dimensions
160
+ offset = HEADER_OFFSET + ns * (16 + 80)
161
+ (0..ns-1).to_a.each do |signal_number|
162
+ @signals[signal_number] ||= Signal.new()
163
+ @signals[signal_number].physical_dimension = IO.binread(@filename, 8, offset+(signal_number*8))
164
+ end
165
+ end
166
+
167
+ # ns * 8 ascii : ns * physical minimum (e.g. -500 or 34)
168
+ def physical_minimums
169
+ offset = HEADER_OFFSET + ns * (16 + 80 + 8)
170
+ (0..ns-1).to_a.each do |signal_number|
171
+ @signals[signal_number] ||= Signal.new()
172
+ @signals[signal_number].physical_minimum = IO.binread(@filename, 8, offset+(signal_number*8))
173
+ end
174
+ end
175
+
176
+ # ns * 8 ascii : ns * physical maximum (e.g. 500 or 40)
177
+ def physical_maximums
178
+ offset = HEADER_OFFSET + ns * (16 + 80 + 8 + 8)
179
+ (0..ns-1).to_a.each do |signal_number|
180
+ @signals[signal_number] ||= Signal.new()
181
+ @signals[signal_number].physical_maximum = IO.binread(@filename, 8, offset+(signal_number*8))
182
+ end
183
+ end
184
+
185
+ # ns * 8 ascii : ns * digital minimum (e.g. -2048)
186
+ def digital_minimums
187
+ offset = HEADER_OFFSET + ns * (16 + 80 + 8 + 8 + 8)
188
+ (0..ns-1).to_a.each do |signal_number|
189
+ @signals[signal_number] ||= Signal.new()
190
+ @signals[signal_number].digital_minimum = IO.binread(@filename, 8, offset+(signal_number*8))
191
+ end
192
+ end
193
+
194
+ # ns * 8 ascii : ns * digital maximum (e.g. 2047)
195
+ def digital_maximums
196
+ offset = HEADER_OFFSET + ns * (16 + 80 + 8 + 8 + 8 + 8)
197
+ (0..ns-1).to_a.each do |signal_number|
198
+ @signals[signal_number] ||= Signal.new()
199
+ @signals[signal_number].digital_maximum = IO.binread(@filename, 8, offset+(signal_number*8))
200
+ end
201
+ end
202
+
203
+ # ns * 80 ascii : ns * prefiltering (e.g. HP:0.1Hz LP:75Hz)
204
+ def prefilterings
205
+ offset = HEADER_OFFSET + ns * (16 + 80 + 8 + 8 + 8 + 8 + 8)
206
+ (0..ns-1).to_a.each do |signal_number|
207
+ @signals[signal_number] ||= Signal.new()
208
+ @signals[signal_number].prefiltering = IO.binread(@filename, 80, offset+(signal_number*80))
209
+ end
210
+ end
211
+
212
+ # ns * 8 ascii : ns * nr of samples in each data record
213
+ def samples_in_data_records
214
+ offset = HEADER_OFFSET + ns * (16 + 80 + 8 + 8 + 8 + 8 + 8 + 80)
215
+ (0..ns-1).to_a.each do |signal_number|
216
+ @signals[signal_number] ||= Signal.new()
217
+ @signals[signal_number].samples_in_data_record = IO.binread(@filename, 8, offset+(signal_number*8))
218
+ end
219
+ end
220
+
221
+ # ns * 32 ascii : ns * reserved
222
+ def reserved_areas
223
+ offset = HEADER_OFFSET + ns * (16 + 80 + 8 + 8 + 8 + 8 + 8 + 80 + 8)
224
+ (0..ns-1).to_a.each do |signal_number|
225
+ @signals[signal_number] ||= Signal.new()
226
+ @signals[signal_number].reserved_area = IO.binread(@filename, 32, offset+(signal_number*32))
227
+ end
228
+ end
229
+
230
+ def get_samples
231
+ offset = size_of_header
232
+ current_read_offset = 0
233
+ (0..ns-1).to_a.each do |signal_number|
234
+ @signals[signal_number] ||= Signal.new()
235
+ read_size = @signals[signal_number].samples_in_data_record.to_i * 2 * number_of_data_records.to_i
236
+ @signals[signal_number].samples = IO.binread(@filename, read_size, size_of_header + current_read_offset).unpack('s*')
237
+ current_read_offset += read_size
238
+ end
239
+ end
240
+
241
+ # 2-byte integer
242
+ # [16Bit]signed short: -32767 to 32767
243
+ # .unpack('s*')
244
+ def data_signals
245
+ data_section = IO.binread(@filename, nil, size_of_header)
246
+ dataset_section.unpack('s*')
247
+ end
248
+
249
+ def data_size
250
+ data_section = IO.binread(@filename, nil, size_of_header)
251
+ data_section.size
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,21 @@
1
+ module Edfize
2
+ class Signal
3
+ attr_accessor :label, :transducer_type, :physical_dimension, :physical_minimum, :physical_maximum,
4
+ :digital_minimum, :digital_maximum, :prefiltering, :samples_in_data_record, :reserved_area, :samples
5
+
6
+ def initialize
7
+ @label = ''
8
+ @physical_dimension = ''
9
+ @transducer_type = ''
10
+ @physical_minimum = ''
11
+ @physical_maximum = ''
12
+ @digital_minimum = ''
13
+ @digital_maximum = ''
14
+ @prefiltering = ''
15
+ @samples_in_data_record = ''
16
+ @reserved_area = ''
17
+ @samples = []
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module Edfize
2
+ module Tests
3
+ # This test checks that the length calculated from the EDF header matches
4
+ # the total length of the file
5
+ def self.test_expected_length(edf)
6
+ passes = (edf.expected_total_size == edf.total_size)
7
+ puts " #{passes ? 'PASS' : 'FAIL'}".colorize( passes ? :green : :red ) + " Expected File Size"
8
+ unless passes or not verbose
9
+ puts " Expected : #{edf.expected_total_size} bytes"
10
+ puts " Actual : #{edf.total_size} bytes"
11
+ end
12
+ passes
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ require 'edfize/tests/check_length'
2
+
3
+ module Edfize
4
+ module Tests
5
+ def self.verbose
6
+ true
7
+ end
8
+
9
+ def self.run(edf)
10
+ puts "\n#{edf.filename}"
11
+
12
+ failure_count = 0
13
+ test_count = 0
14
+
15
+ test_expected_length(edf) ? nil : failure_count += 1
16
+ test_count += 1
17
+
18
+ [test_count, failure_count]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ module Edfize
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+ BUILD = "beta1"
7
+
8
+ STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
+ end
10
+ end
data/lib/edfize.rb ADDED
@@ -0,0 +1,70 @@
1
+ require 'edfize/edf'
2
+ require 'edfize/tests'
3
+ require 'edfize/version'
4
+
5
+ require 'colorize'
6
+
7
+ module Edfize
8
+ def self.launch(argv)
9
+ case argv.first.to_s.scan(/\w/).first
10
+ when 'v'
11
+ version
12
+ when 'c', 't'
13
+ check
14
+ when 'r'
15
+ print_headers
16
+ else
17
+ help
18
+ end
19
+ end
20
+
21
+ def self.print_headers
22
+ puts "----------------"
23
+ edfs_in_current_directory.each do |edf_file_name|
24
+ edf = Edfize::Edf.new(edf_file_name)
25
+ edf.print_header
26
+ puts "----------------"
27
+ end
28
+ end
29
+
30
+ def self.version
31
+ puts "Edfize #{Edfize::VERSION::STRING}"
32
+ end
33
+
34
+ def self.check
35
+ test_start_time = Time.now
36
+ edf_count = edfs_in_current_directory.count
37
+ test_count = 0
38
+ failure_count = 0
39
+ puts "Started\n"
40
+ edfs_in_current_directory.each do |edf_file_name|
41
+ edf = Edfize::Edf.new(edf_file_name)
42
+ tests_run, failures = Edfize::Tests.run(edf)
43
+ test_count += tests_run
44
+ failure_count += failures
45
+ end
46
+ puts "\nFinished in #{Time.now - test_start_time}s"
47
+ puts "#{edf_count} EDF#{'s' unless edf_count == 1}, #{test_count} test#{'s' unless test_count == 1}, " + "#{failure_count} failure#{'s' unless failure_count == 1}".colorize( failure_count == 0 ? :green : :red )
48
+ end
49
+
50
+ def self.help
51
+ help_message = <<-EOT
52
+ Usage: edfize COMMAND [ARGS]
53
+
54
+ The most common edfize commands are:
55
+ [c]heck Check EDFs in current directory for errors
56
+ [t]est Same as [c]heck
57
+ [h]elp Show edfize command-line documentation
58
+ [v]ersion Returns the version of Edfize
59
+
60
+ Commands can be referenced by the first letter:
61
+ Ex: `edfize t`, for test
62
+
63
+ EOT
64
+ puts help_message
65
+ end
66
+
67
+ def self.edfs_in_current_directory
68
+ Dir.glob('*.edf')
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edfize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.beta1
5
+ platform: ruby
6
+ authors:
7
+ - Remo Mueller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Load, validate, and parse European Data Format files. Used for batch
56
+ testing EDFs for errors. Run `edfize` on command line to view full list of options.
57
+ email:
58
+ - remosm@gmail.com
59
+ executables:
60
+ - edfize
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - CHANGELOG.md
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/edfize
69
+ - edfize.gemspec
70
+ - lib/edfize.rb
71
+ - lib/edfize/edf.rb
72
+ - lib/edfize/signal.rb
73
+ - lib/edfize/tests.rb
74
+ - lib/edfize/tests/check_length.rb
75
+ - lib/edfize/version.rb
76
+ homepage: https://github.com/sleepepi/edfize
77
+ licenses:
78
+ - CC BY-NC-SA 3.0
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">"
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.1
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Load, validate, and parse European Data Format files. Used for batch testing
100
+ EDFs for errors.
101
+ test_files: []