mk_apos 0.1.0

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: fa8ede1b3c58383c1fc41348959bedb24e34c72f
4
+ data.tar.gz: da78fd2c8b82bc794e3986ccbcebc2d4118e0a99
5
+ SHA512:
6
+ metadata.gz: f6473dd4869c17c5f1881ec19881de77acab0738a81d4abfdbf0253071c9503df892f37b9922be14bb9ad6b22ec34aeea402212de64269c343bcbbeaa587d963
7
+ data.tar.gz: 570c104c39aca9be932492d883e247ff17960b43b9a248422ceb1d1534b4bba8721d7c95250ee0c4e50961d7df21c2ab8dc7f030ef8201e90c796d7aea572654
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mk_apos.gemspec
4
+ gemspec
5
+ group :development do
6
+ gem "guard"
7
+ gem "guard-rspec", "~> 4.7.0"
8
+ end
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ ## Rails files
44
+ #rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ #dsl.watch_spec_files_for(rails.app_files)
46
+ #dsl.watch_spec_files_for(rails.views)
47
+
48
+ #watch(rails.controllers) do |m|
49
+ # [
50
+ # rspec.spec.call("routing/#{m[1]}_routing"),
51
+ # rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ # rspec.spec.call("acceptance/#{m[1]}")
53
+ # ]
54
+ #end
55
+
56
+ ## Rails config changes
57
+ #watch(rails.spec_helper) { rspec.spec_dir }
58
+ #watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ #watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ ## Capybara features specs
62
+ #watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ #watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ ## Turnip features and steps
66
+ #watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ #watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ # Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ #end
70
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Masaru Koizumi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # MkApos
2
+
3
+ This is the gem library which calculates apparent positions of SUn and Moon.
4
+
5
+ ## Preparation
6
+
7
+ This library needs a JPL's DE430 binary file.
8
+
9
+ Download linux_p1550p2650.430 from [ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de430/](ftp://ssd.jpl.nasa.gov/pub/eph/planets/Linux/de430/), and place at a suitable directory.
10
+
11
+ If neccessary, rename the binary file.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'mk_apos'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install mk_apos
28
+
29
+ ## Usage
30
+
31
+ ### Instantiation
32
+
33
+ require "mk_apos"
34
+
35
+ a = MkApos.new("/path/to/<JPLEPH binary>", "20160914")
36
+ a = MkApos.new("/path/to/<JPLEPH binary>", "20160914123456")
37
+ a = MkApos.new("/path/to/<JPLEPH binary>", "2016091412345698765")
38
+ a = MkApos.new("/path/to/<JPLEPH binary>")
39
+
40
+ * You can set UTC formatted `YYYYMMDD` or `YYYYMMDDHHMMSS` or `YYYYMMDDHHMMSSU...` as an argument. (`U` is microsecond)
41
+ * If you don't set a second argument, this class considers the system time to have been set as a second argument.
42
+
43
+ ### Calculation
44
+
45
+ p a.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')
46
+ p a.tdb.strftime('%Y-%m-%d %H:%M:%S.%3N')
47
+ p a.jd_tdb
48
+ p a.sun
49
+ p a.moon
50
+
51
+ ## Development
52
+
53
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/komasaru/mk_apos.
60
+
61
+
62
+ ## License
63
+
64
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mk_apos"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/mk_apos ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mk_apos"
4
+
5
+ a = MkApos.new(*ARGV) # JPLEPH's path, UTC
6
+ p a.utc.strftime('%Y-%m-%d %H:%M:%S.%3N')
7
+ p a.tdb.strftime('%Y-%m-%d %H:%M:%S.%3N')
8
+ p a.jd_tdb
9
+ p a.sun
10
+ p a.moon
11
+
@@ -0,0 +1,41 @@
1
+ module MkApos
2
+ class Apos
3
+ attr_reader :utc, :tdb, :jd_tdb
4
+ include MkApos::Compute
5
+
6
+ def initialize(bin_path, utc)
7
+ @bin_path, @utc = bin_path, utc
8
+ # === t1(= TDB), t2(= TDB) における位置・速度(ICRS 座標)用Hash
9
+ @icrs_1, @icrs_2 = Hash.new, Hash.new
10
+ # === 時刻 t2 の変換(UTC(協定世界時) -> TDB(太陽系力学時))
11
+ @tdb = utc2tdb(@utc)
12
+ # === 時刻 t2 のユリウス日
13
+ @jd_tdb = get_jd(@tdb)
14
+ # === 時刻 t2(= TDB) におけるの位置・速度(ICRS 座標)の計算 (地球, 月, 太陽)
15
+ Const::BODIES.each { |k, v| @icrs_2[k] = get_icrs(v, @jd_tdb) }
16
+ # === 時刻 t2(= TDB) における地球と太陽・月の距離
17
+ @r_e = get_r_e
18
+ end
19
+
20
+ #=========================================================================
21
+ # SUN
22
+ #
23
+ # @param: <none>
24
+ # @return: [lambda, beta, d] (太陽視黄経、視黄緯、地心距離)
25
+ #=========================================================================
26
+ def sun
27
+ return compute_sun
28
+ end
29
+
30
+ #=========================================================================
31
+ # MOON
32
+ #
33
+ # @param: <none>
34
+ # @return: [alpha, delta] (月視黄経、視黄緯、地心距離)
35
+ #=========================================================================
36
+ def moon
37
+ return compute_moon
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,45 @@
1
+ module MkApos
2
+ class Argument
3
+ def initialize(*args)
4
+ @args = *args
5
+ end
6
+
7
+ #=========================================================================
8
+ # 引数取得
9
+ #
10
+ # @return: [BIN_PATH, TARGET, CENTER, JD, KM]
11
+ #=========================================================================
12
+ def get_args
13
+ bin_path = get_binpath
14
+ utc = get_utc
15
+ check_bin_path(bin_path)
16
+ return [bin_path, utc]
17
+ rescue => e
18
+ raise
19
+ end
20
+
21
+ def get_binpath
22
+ raise unless bin_path = @args.shift
23
+ return bin_path
24
+ rescue => e
25
+ raise Const::MSG_ERR_1
26
+ end
27
+
28
+ def get_utc
29
+ utc = @args.shift
30
+ return Time.now unless utc
31
+ (raise Const::MSG_ERR_2) unless utc =~ /^\d{8}$|^\d{14,}$/
32
+ year, month, day = utc[ 0, 4].to_i, utc[ 4, 2].to_i, utc[ 6, 2].to_i
33
+ hour, min, sec = utc[ 8, 2].to_i, utc[10, 2].to_i, utc[12, 2].to_i
34
+ usec = utc.split(//).size > 14 ? utc[14..-1].to_s : "0"
35
+ (raise Const::MSG_ERR_3) unless Date.valid_date?(year, month, day)
36
+ (raise Const::MSG_ERR_3) if hour > 23 || min > 59 || sec > 60
37
+ d = usec.split(//).size
38
+ return Time.new(year, month, day, hour, min, sec + Rational(usec.to_i, 10 ** d), "+00:00")
39
+ end
40
+
41
+ def check_bin_path(bin_path)
42
+ raise Const::MSG_ERR_4 unless File.exist?(bin_path)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,252 @@
1
+ module MkApos
2
+ module Compute
3
+ module_function
4
+
5
+ #=========================================================================
6
+ # UTC -> TDB
7
+ #
8
+ # @param: utc (Time Object)
9
+ # @return: tdb (Time Object)
10
+ #=========================================================================
11
+ def utc2tdb(utc)
12
+ return MkTime.new(utc.strftime("%Y%m%d%H%M%S%6N")).tdb
13
+ rescue => e
14
+ raise
15
+ end
16
+
17
+ #=========================================================================
18
+ # ユリウス日取得
19
+ #
20
+ # @param: t (Time Object)
21
+ # @return: jd (Julian Day(Numeric))
22
+ #=========================================================================
23
+ def get_jd(t)
24
+ return MkTime.new(t.strftime("%Y%m%d%H%M%S")).jd
25
+ rescue => e
26
+ raise
27
+ end
28
+
29
+ #=========================================================================
30
+ # ICRS 座標取得
31
+ #
32
+ # * JPL DE430 データを自作 RubyGems ライブラリ eph_jpl を使用して取得。
33
+ #
34
+ # @param: target (対象天体(Symbol))
35
+ # @param: jd (ユリウス日(Numeric))
36
+ # @return: [
37
+ # pos_x, pos_y, pos_z,
38
+ # vel_x, vel_y, vel_z
39
+ # ] (位置・速度(Array), 単位: AU, AU/day)
40
+ #=========================================================================
41
+ def get_icrs(target, jd)
42
+ return EphJpl.new(@bin_path, target, 12, jd).calc
43
+ rescue => e
44
+ raise
45
+ end
46
+
47
+ #=========================================================================
48
+ # t2(= TDB) における地球と太陽・月の距離
49
+ #
50
+ # @param: <none>
51
+ # @return: r_e (地球と太陽・月の距離(Hash))
52
+ #=========================================================================
53
+ def get_r_e
54
+ r_e = Hash.new
55
+
56
+ begin
57
+ @icrs_2.each do |k, v|
58
+ next if k == :earth
59
+ r_e[k] = calc_dist(@icrs_2[:earth][0, 3], v[0, 3])
60
+ end
61
+ return r_e
62
+ rescue => e
63
+ raise
64
+ end
65
+ end
66
+
67
+ #=========================================================================
68
+ # 天体Aと天体Bの距離計算
69
+ #
70
+ # @param: pos_a (位置ベクトル)
71
+ # @param: pos_a (位置ベクトル)
72
+ # @return: r (距離)
73
+ #=========================================================================
74
+ def calc_dist(pos_a, pos_b)
75
+ r = (0..2).inject(0.0) { |sum, i| sum + (pos_b[i] -pos_a[i]) ** 2 }
76
+ return Math.sqrt(r)
77
+ rescue => e
78
+ raise
79
+ end
80
+
81
+ #=========================================================================
82
+ # 視黄経・視黄緯の計算(太陽)
83
+ #
84
+ # @param: <none>
85
+ # @return: [[視赤経, 視赤緯, 地心距離], [視黄経, 視黄緯, 地心距離]]
86
+ #=========================================================================
87
+ def compute_sun
88
+ # === 太陽が光を発した時刻 t1(JD) の計算
89
+ t_1_jd = calc_t1(:sun, @tdb)
90
+ # === 時刻 t1(= TDB) におけるの位置・速度(ICRS 座標)の計算 (地球, 月, 太陽)
91
+ Const::BODIES.each { |k, v| @icrs_1[k] = get_icrs(v, t_1_jd) }
92
+ # === 時刻 t2 における地球重心から時刻 t1 における太陽への方向ベクトルの計算
93
+ v_12 = calc_unit_vector(@icrs_2[:earth][0,3], @icrs_1[:sun][0,3])
94
+ # === GCRS 座標系: 光行差の補正(方向ベクトルの Lorentz 変換)
95
+ dd = conv_lorentz(v_12)
96
+ pos_sun = calc_pos(dd, @r_e[:sun])
97
+ # === 瞬時の真座標系: GCRS への bias & precession(歳差) & nutation(章動)の適用
98
+ bpn = EphBpn.new(@tdb.strftime("%Y%m%d%H%M%S"))
99
+ pos_sun_bpn = bpn.apply_bpn(pos_sun)
100
+ # === 座標変換
101
+ eq_pol_s = MkCoord.rect2pol(pos_sun_bpn)
102
+ ec_rect_s = MkCoord.rect_eq2ec(pos_sun_bpn, bpn.eps)
103
+ ec_pol_s = MkCoord.rect2pol(ec_rect_s)
104
+ return [eq_pol_s, ec_pol_s]
105
+ rescue => e
106
+ raise
107
+ end
108
+
109
+ #=========================================================================
110
+ # 視黄経・視黄緯の計算(月)
111
+ #
112
+ # @param: <none>
113
+ # @return: [[視赤経, 視赤緯, 地心距離], [視黄経, 視黄緯, 地心距離]]
114
+ #=========================================================================
115
+ def compute_moon
116
+ # === 月が光を発した時刻 t1(jd) の計算
117
+ t_1_jd = calc_t1(:moon, @tdb)
118
+ # === 時刻 t1(= TDB) におけるの位置・速度(ICRS 座標)の計算 (地球, 月, 太陽)
119
+ Const::BODIES.each { |k, v| @icrs_1[k] = get_icrs(v, t_1_jd) }
120
+ # === 時刻 t2 における地球重心から時刻 t1 における月への方向ベクトルの計算
121
+ v_12 = calc_unit_vector(@icrs_2[:earth][0,3], @icrs_1[:moon][0,3])
122
+ # === GCRS 座標系: 光行差の補正(方向ベクトルの Lorentz 変換)
123
+ dd = conv_lorentz(v_12)
124
+ pos_moon = calc_pos(dd, @r_e[:moon])
125
+ # === 瞬時の真座標系: GCRS への bias & precession(歳差) & nutation(章動)の適用
126
+ bpn = EphBpn.new(@tdb.strftime("%Y%m%d%H%M%S"))
127
+ pos_moon_bpn = bpn.apply_bpn(pos_moon)
128
+ # === 座標変換
129
+ eq_pol_m = MkCoord.rect2pol(pos_moon_bpn)
130
+ ec_rect_m = MkCoord.rect_eq2ec(pos_moon_bpn, bpn.eps)
131
+ ec_pol_m = MkCoord.rect2pol(ec_rect_m)
132
+ return [eq_pol_m, ec_pol_m]
133
+ rescue => e
134
+ raise
135
+ end
136
+
137
+ #=========================================================================
138
+ # 対象天体が光を発した時刻 t1 の計算(太陽・月専用)
139
+ #
140
+ # * 計算式: c * (t2 - t1) = r12 (但し、 c: 光の速度。 Newton 法で近似)
141
+ # * 太陽・月専用なので、太陽・木星・土星・天王星・海王星の重力場による
142
+ # 光の曲がりは非考慮。
143
+ #
144
+ # @param: target (対象天体(Symbol))
145
+ # @param: tdb (Time Object(観測時刻;TDB))
146
+ # @return: t_1 (Numeric(Julian Day))
147
+ #=========================================================================
148
+ def calc_t1(target, tdb)
149
+ t_1 = MkTime.new(tdb.strftime("%Y%m%d%H%M%S")).jd
150
+ t_2 = t_1
151
+ pv_1 = @icrs_2[target]
152
+ df, m = 1.0, 0
153
+ while df > 1.0e-10 || m > 10
154
+ r_12 = (0..2).map { |i| pv_1[i] - @icrs_2[:earth][i] }
155
+ r_12_d = calc_dist(pv_1, @icrs_2[:earth])
156
+ df = (Const::C * Const::DAYSEC / Const::AU) * (t_2 - t_1) - r_12_d
157
+ df_wk = (0..2).inject(0.0) { |s, i| s + r_12[i] * @icrs_2[target][i + 3] }
158
+ df /= ((Const::C * Const::DAYSEC / Const::AU) + (df_wk) / r_12_d)
159
+ t_1 += df
160
+ m += 1
161
+ pv_1 = get_icrs(Const::BODIES[target], t_1)
162
+ end
163
+ return t_1
164
+ rescue => e
165
+ raise
166
+ end
167
+
168
+ #=========================================================================
169
+ # 天体Aから見た天体Bの方向ベクトル計算(太陽・月専用)
170
+ #
171
+ # * 太陽・月専用なので、太陽・木星・土星・天王星・海王星の重力場による
172
+ # 光の曲がりは非考慮。
173
+ #
174
+ # @param: pos_a (位置ベクトル(天体A))
175
+ # @param: pos_b (位置ベクトル(天体B))
176
+ # @return: vec (方向(単位)ベクトル)
177
+ #=========================================================================
178
+ def calc_unit_vector(pos_a, pos_b)
179
+ vec = [0.0, 0.0, 0.0]
180
+
181
+ begin
182
+ w = calc_dist(pos_a, pos_b)
183
+ vec = (0..2).map { |i| pos_b[i] - pos_a[i] }
184
+ return vec.map { |v| v / w } unless w == 0.0
185
+ rescue => e
186
+ raise
187
+ end
188
+ end
189
+
190
+ #=========================================================================
191
+ # 光行差の補正(方向ベクトルの Lorentz 変換)
192
+ #
193
+ # * vec_dd = f * vec_d + (1 + g / (1 + f)) * vec_v
194
+ # 但し、 f = vec_v * vec_d (ベクトル内積)
195
+ # g = sqrt(1 - v^2) (v: 速度)
196
+ #
197
+ # @param: v_d (方向(単位)ベクトル)
198
+ # @return: v_dd (補正後ベクトル)
199
+ #=========================================================================
200
+ def conv_lorentz(vec_d)
201
+ vec_v = @icrs_2[:earth][3,3].map { |v| (v / Const::DAYSEC) / (Const::C / Const::AU.to_f) }
202
+ g = inner_prod(vec_v, vec_d)
203
+ f = Math.sqrt(1.0 - calc_velocity(vec_v))
204
+ vec_dd_1 = vec_d.map { |d| d * f }
205
+ vec_dd_2 = vec_v.map { |v| (1.0 + g / (1.0 + f)) * v }
206
+ vec_dd = (0..2).map { |i| vec_dd_1[i] + vec_dd_2[i] }.map { |a| a / (1.0 + g) }
207
+ return vec_dd
208
+ rescue => e
209
+ raise
210
+ end
211
+
212
+ #=========================================================================
213
+ # ベクトルの内積
214
+ #
215
+ # @param: a (ベクトル)
216
+ # @param: b (ベクトル)
217
+ # @return: w (スカラー(内積の値))
218
+ #=========================================================================
219
+ def inner_prod(a, b)
220
+ return (0..2).inject(0.0) { |s, i| s + a[i] * b[i] }
221
+ rescue => e
222
+ raise
223
+ end
224
+
225
+ #=========================================================================
226
+ # 天体の速度ベクトルから実際の速度を計算
227
+ #
228
+ # @param: vec (ベクトル)
229
+ # @return: v (速度)
230
+ #=========================================================================
231
+ def calc_velocity(vec)
232
+ v = vec.inject(0.0) { |s, i| s + i * i }
233
+ return Math.sqrt(v)
234
+ rescue => e
235
+ raise
236
+ end
237
+
238
+ #=========================================================================
239
+ # 単位(方向)ベクトルと距離から位置ベクトルを計算
240
+ #
241
+ # @param: d (単位(方向)ベクトル)
242
+ # @param: r (距離)
243
+ # @return pos (位置ベクトル)
244
+ #=========================================================================
245
+ def calc_pos(d, r)
246
+ return d.map { |a| a * r }
247
+ rescue => e
248
+ raise
249
+ end
250
+ end
251
+ end
252
+
@@ -0,0 +1,12 @@
1
+ module MkApos
2
+ module Const
3
+ MSG_ERR_1 = "[ERROR] Binary file path is invalid!"
4
+ MSG_ERR_2 = "[ERROR] Format: YYYYMMDD or YYYYMMDDHHMMSS or YYYYMMDDHHMMSSU..."
5
+ MSG_ERR_3 = "[ERROR] Invalid date-time!"
6
+ MSG_ERR_4 = "[ERROR] Binary file is not found!"
7
+ BODIES = {earth: 3, moon: 10, sun: 11} # 天体名と JPL での天体番号
8
+ AU = 149597870700 # 1天文単位 (m)
9
+ C = 299792458 # 光速 (m/s)
10
+ DAYSEC = 86400 # 1日の秒数(s)
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module MkApos
2
+ VERSION = "0.1.0"
3
+ end
data/lib/mk_apos.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "eph_bpn"
2
+ require "eph_jpl"
3
+ require "mk_coord"
4
+ require "mk_time"
5
+ require "mk_apos/version"
6
+ require "mk_apos/argument"
7
+ require "mk_apos/compute"
8
+ require "mk_apos/const"
9
+ require "mk_apos/apos"
10
+
11
+ module MkApos
12
+ def self.new(*args)
13
+ bin_path, utc = MkApos::Argument.new(*args).get_args
14
+ return unless utc
15
+ return MkApos::Apos.new(bin_path, utc)
16
+ end
17
+ end
data/mk_apos.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mk_apos/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mk_apos"
8
+ spec.version = MkApos::VERSION
9
+ spec.authors = ["komasaru"]
10
+ spec.email = ["masaru@mk-mode.com"]
11
+
12
+ spec.summary = %q{Apparent position calculation tool.}
13
+ spec.description = %q{MkApos is a Apparent position calculation tool.}
14
+ spec.homepage = "https://github.com/komasaru/mk_apos"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "eph_bpn"
31
+ spec.add_dependency "eph_jpl"
32
+ spec.add_dependency "mk_coord"
33
+ spec.add_dependency "mk_time"
34
+ spec.add_development_dependency "bundler", "~> 1.12"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mk_apos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - komasaru
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eph_bpn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eph_jpl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mk_coord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mk_time
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: MkApos is a Apparent position calculation tool.
112
+ email:
113
+ - masaru@mk-mode.com
114
+ executables:
115
+ - mk_apos
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Guardfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - exe/mk_apos
130
+ - lib/mk_apos.rb
131
+ - lib/mk_apos/apos.rb
132
+ - lib/mk_apos/argument.rb
133
+ - lib/mk_apos/compute.rb
134
+ - lib/mk_apos/const.rb
135
+ - lib/mk_apos/version.rb
136
+ - mk_apos.gemspec
137
+ homepage: https://github.com/komasaru/mk_apos
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.6.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Apparent position calculation tool.
161
+ test_files: []