radiation 0.0.3 → 0.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDQxMmMyNzdkMmY0NzUxMTE0NmQ4NzQ2ZTYwMTBiNzhlZWI5ZTViMQ==
4
+ YjYxM2U4YjVkYWQxNzM2YTM0MjBiNWQwYTMzNDAwYzU5MTdhYzNkNg==
5
5
  data.tar.gz: !binary |-
6
- ZjU3MzFhMTA1YzA2ODgyZTJlYzhhNjRlYjhmMjQ1MjQ4MzRkZTM1OQ==
6
+ NjE0ZTlkNGM1OTg4ZjU5YjVlZWFhZGM5NTBlODcyMjA4OTYwMTBiMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MjJhYzU4ZmZmYjY1NTUyM2I5MzU4ZWRkOWY0ODViZjM4NGVmY2U4MGJlY2Q1
10
- MTU5ZGNmZTY2ZjQwY2QyZGIyYjcxNWRhYWExMjdmZTgyOWUzODBiZTBlMjQy
11
- OGY0MmIxZjBkMzM5NzhjMzcyZGMzOGIyZGYzZWUzYjI2ZTdkYjU=
9
+ MjdjZTVkYmUwZDljOGM0MWVjYjEyMzBiYzVmZjc1YjE1ZTYxYzQ0OGUzNjhl
10
+ Yjc4OWZjOWI2NmM1OGY2NjZmYzg2YTlhNzdjYzFjMjllMzVhZjJjMGFmNmNl
11
+ OGZjMDZmM2FkZmM3Njg0MjJhOWZiOWJhYTk4ZTdiYzk4N2U4MjE=
12
12
  data.tar.gz: !binary |-
13
- ZDBkZTg1OWY1Y2IxYzQzMWEzMjJhODU0YmExNWJkNTczOWMwMGZiY2FjMjI4
14
- MTYwN2M5MTczNzc5NGRiMmZmMzM2NTJmMTFkNDkxNzQ2YWY0MDBkNzQwZGQx
15
- ZmZlODEwYzlmM2JiYjAyY2MzNjlmMjljOTVlNTljMzYwYzIwMmM=
13
+ MTk2ZTFhY2E0ZWVkZGExYzUxN2U4MTc5NWQ2MjAyMGY0ZGEyNTQ5NTA0ZDEy
14
+ MjkwMzk5ZDdkMWYzNjM4NDZjNzU2NzFmN2YxYzE1NzVjOTI4ZTIyMGQ3YTkw
15
+ MWM4MzkxNzgyYjY4ODliYzc2ZDQ1M2M2NGUyYTY2MTU0NGFjYWI=
data/README.md CHANGED
@@ -9,15 +9,20 @@ by [Laboratoire National Henri Becquerel](http://www.nucleide.org/DDEP_WG/DDEPda
9
9
 
10
10
  ## Example Usage
11
11
 
12
+ ### Command line interface
13
+
14
+ $> radiation
15
+
16
+ ### In your ruby files:
17
+
18
+ require "radiation"
12
19
  Radiation::Source.new(nuclide: "Ra-226").energies.collect{|e| e.value}
13
20
 
14
21
  See also files in `./samples/`.
15
22
 
16
-
17
23
  ## Planned features
18
24
 
19
25
  * Efficiency calibration for given peaks or spectra
20
- * CLI
21
26
  * Better access to resources
22
27
 
23
28
 
data/bin/radiation ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Trap interrupts to quit cleanly. See
4
+ # https://twitter.com/mitchellh/status/283014103189053442
5
+ Signal.trap("INT") { exit 1 }
6
+
7
+ require 'radiation/cli'
8
+ # Set debug flag so we can rescue Thor::error's
9
+ # and set the correct exit code.
10
+ ENV["THOR_DEBUG"] = "1"
11
+ Radiation::CLI.start(ARGV)
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require "radiation"
3
+ require "thor"
4
+
5
+ module Radiation
6
+ class CLI < Thor
7
+
8
+ desc "version", "Prints version information"
9
+ def version
10
+ puts "radiation version #{Radiation::VERSION}"
11
+ end
12
+ map %w(-v --version) => :version
13
+
14
+ option :resource
15
+ desc "source NUCLIDE", "decay radiation data"
16
+ def source(nuclide)
17
+ resource = options[:resource] ? options[:resource] : "internal"
18
+ puts ["E_ɣ", "ΔE_ɣ", "I_ɣ", "ΔI_ɣ"].join("\t")
19
+ puts Radiation::Source.new(nuclide: nuclide, resource: resource).intensities.collect{|l| [l[:energy].value, l[:energy].delta, l[:intensity].value, l[:intensity].delta].join("\t") }
20
+ end
21
+
22
+ option :resource
23
+ desc "calibrate NUCLIDE SPECTRUM.xml", "calibrate a spectrum"
24
+ long_desc <<-LONGDESC
25
+ Calibrates a decay radiation spectrum that has been analysed with HDTV. Stored peak fits in HDTV can be stored with hdtv>fit write filname.xml
26
+ Example: \n
27
+ $>radiation calibrate Ra-226 Ge00.xml
28
+ With --resource=nucleide.org more decay radiation sources are available.
29
+ LONGDESC
30
+ def calibrate(nuclide, file)
31
+ resource = options[:resource] ? options[:resource] : "internal"
32
+ source = Radiation::Source.new(nuclide: nuclide, resource: resource)
33
+ spectrum = Radiation::Spectrum.new(source: source ).parse_hdtv(file)
34
+ spectrum.calibrate.calibration.each{|c| puts c}
35
+ end
36
+
37
+ end
38
+ end
@@ -2,7 +2,8 @@
2
2
  require 'radiation/source/resource/internal'
3
3
  require 'radiation/source/resource/nucleideorg'
4
4
 
5
- class Radiation::Source
5
+ module Radiation
6
+ class Source
6
7
  class Resource
7
8
 
8
9
  def initialize(resource)
@@ -21,3 +22,4 @@ class Radiation::Source
21
22
 
22
23
  end
23
24
  end
25
+ end
@@ -3,7 +3,8 @@ require 'radiation/source/resource'
3
3
  require 'combinatorics'
4
4
 
5
5
 
6
- class Radiation::Source
6
+ module Radiation
7
+ class Source
7
8
  attr_reader :data
8
9
 
9
10
  def initialize(options={})
@@ -32,4 +33,5 @@ class Radiation::Source
32
33
  !!(nuclide =~ /\A[a-zA-Z]{1,2}-\d{1,3}\z/)
33
34
  end
34
35
 
36
+ end
35
37
  end
@@ -3,7 +3,8 @@ require "linefit"
3
3
  require "plusminus"
4
4
  require "xmlsimple"
5
5
 
6
- class Radiation::Spectrum
6
+ module Radiation
7
+ class Spectrum
7
8
  attr_accessor :peaks, :source, :calibration
8
9
 
9
10
  def initialize(options={})
@@ -46,7 +47,7 @@ class Radiation::Spectrum
46
47
  return self
47
48
  end
48
49
 
49
- def guess_calibration(energies=@source.energies, rounding=3)
50
+ def guess_calibration(energies=@source.energies, rounding=4)
50
51
  # Build all possible combinations of known energies and peaks
51
52
  arr = [energies, @peaks.collect{|peak| peak[:channel]}].comprehension
52
53
  # The approximate value for b in $Energy = a + b * Channel$ will be most frequent for $a \approx 0$
@@ -69,7 +70,7 @@ class Radiation::Spectrum
69
70
  end
70
71
 
71
72
  end
72
-
73
+ end
73
74
 
74
75
 
75
76
  class Float
@@ -1,3 +1,3 @@
1
1
  module Radiation
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/radiation.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "combinatorics"
24
24
  spec.add_dependency "linefit"
25
25
  spec.add_dependency "xml-simple"
26
+ spec.add_dependency "thor"
26
27
 
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.3"
@@ -49,7 +49,7 @@ describe Radiation do
49
49
  source = Radiation::Source.new(nuclide: "Ra-226")
50
50
 
51
51
  it "can guess a inital energy calibration based on adc values" do
52
- Radiation::Spectrum.new(peaks: peaks, source: source).guess_calibration.calibration.should be == [0, 0.36]
52
+ Radiation::Spectrum.new(peaks: peaks, source: source).guess_calibration.calibration.should be == [0, 0.3597]
53
53
  end
54
54
 
55
55
  it "can match channels to given energies by using a calibration" do
@@ -63,7 +63,7 @@ describe Radiation do
63
63
 
64
64
  it "can read peaks from hdtv xml data" do
65
65
  expect { Radiation::Spectrum.new(source: source ).parse_hdtv("./samples/B0-Ra226.xml") }.to_not raise_error
66
- Radiation::Spectrum.new(source: source ).parse_hdtv("./samples/B0-Ra226.xml").calibrate.calibration.should be == [0.311879195357135.pm(0.002317818766849388), 0.10022085942781585.pm(4.767016096075808e-07)]
66
+ Radiation::Spectrum.new(source: source ).parse_hdtv("./samples/B0-Ra226.xml").calibrate.calibration[1].round(3).should be == 0.100
67
67
  end
68
68
 
69
69
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-18 00:00:00.000000000 Z
11
+ date: 2013-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plusminus
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +139,8 @@ dependencies:
125
139
  description: Decay Radiation
126
140
  email:
127
141
  - jan.mayer@ikp.uni-koeln.de
128
- executables: []
142
+ executables:
143
+ - radiation
129
144
  extensions: []
130
145
  extra_rdoc_files: []
131
146
  files:
@@ -137,11 +152,13 @@ files:
137
152
  - LICENSE.txt
138
153
  - README.md
139
154
  - Rakefile
155
+ - bin/radiation
140
156
  - data/Eu-152.bib
141
157
  - data/Eu-152.csv
142
158
  - data/Ra-226.bib
143
159
  - data/Ra-226.csv
144
160
  - lib/radiation.rb
161
+ - lib/radiation/cli.rb
145
162
  - lib/radiation/source.rb
146
163
  - lib/radiation/source/resource.rb
147
164
  - lib/radiation/source/resource/internal.rb