sweph4ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +8 -0
- data/SEAS_18.SE1 +0 -0
- data/ext/extconf.rb +12 -0
- data/ext/libswe.a +0 -0
- data/ext/swelib32.lib +0 -0
- data/ext/sweodef.h +318 -0
- data/ext/sweph4ruby.c +101 -0
- data/ext/swephexp.h +643 -0
- data/lib/sweph4ruby.rb +161 -0
- data/test/test.rb +129 -0
- metadata +50 -0
data/lib/sweph4ruby.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'sweph4ruby.so'
|
2
|
+
|
3
|
+
# Encapsulates the functionality provided by sweph4ruby extension in a ruby class
|
4
|
+
class Rsweph
|
5
|
+
|
6
|
+
# Body number constants
|
7
|
+
SE_ECL_NUT = -1
|
8
|
+
SE_SUN = 0
|
9
|
+
SE_MOON = 1
|
10
|
+
SE_MERCURY = 2
|
11
|
+
SE_VENUS = 3
|
12
|
+
SE_MARS = 4
|
13
|
+
SE_JUPITER = 5
|
14
|
+
SE_SATURN = 6
|
15
|
+
SE_URANUS = 7
|
16
|
+
SE_NEPTUNE = 8
|
17
|
+
SE_PLUTO = 9
|
18
|
+
SE_MEAN_NODE = 10
|
19
|
+
SE_TRUE_NODE = 11
|
20
|
+
SE_MEAN_APOG = 12
|
21
|
+
SE_OSCU_APOG = 13
|
22
|
+
SE_EARTH = 14
|
23
|
+
SE_CHIRON = 15
|
24
|
+
SE_PHOLUS = 16
|
25
|
+
SE_CERES = 17
|
26
|
+
SE_PALLAS = 18
|
27
|
+
SE_JUNO = 19
|
28
|
+
SE_VESTA = 20
|
29
|
+
SE_NPLANETS = 21
|
30
|
+
|
31
|
+
attr_reader :eph_path
|
32
|
+
|
33
|
+
# Sets a default path for the ephemeris directory $LOAD_PATH[1]
|
34
|
+
def initialize
|
35
|
+
@eph_path = $LOAD_PATH[1]
|
36
|
+
@s = Sweph.new()
|
37
|
+
@s.swe_set_ephe_path(@eph_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Sets the path for the ephemeris directory.
|
41
|
+
#
|
42
|
+
# For more information on the underlying Swiss Ephemeris library function:
|
43
|
+
# http://www.astro.com/swisseph/swephprg.htm?lang=f#_Toc100044341
|
44
|
+
def swe_set_ephe_path(path)
|
45
|
+
self.initialize() if @s == nil
|
46
|
+
@eph_path = path
|
47
|
+
@s.swe_set_ephe_path(@eph_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the julian day as a float, for a given date and time.
|
51
|
+
#
|
52
|
+
# For more information on the underlying Swiss Ephemeris library function:
|
53
|
+
# http://www.astro.com/swisseph/swephprg.htm?lang=f#_Toc100044332
|
54
|
+
def swe_julday(year, month, day, hour, minute)
|
55
|
+
self.initialize() if @s == nil
|
56
|
+
|
57
|
+
@s.swe_julday(year, month, day, hour + minute / 60)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Calculates the position of a body (Planet, moon node, asteroid) given a julian day and a body number.
|
61
|
+
#
|
62
|
+
# Returns an array of 6 floats containing:
|
63
|
+
# * [0] = longitude
|
64
|
+
# * [1] = latitude
|
65
|
+
# * [2] = distance
|
66
|
+
# * [3] = speed in longitude
|
67
|
+
# * [4] = speed in latitude
|
68
|
+
# * [5] = speed in dist
|
69
|
+
#
|
70
|
+
# For more information on the underlying Swiss Ephemeris library function:
|
71
|
+
# http://www.astro.com/swisseph/swephprg.htm?lang=f#_Toc100044303
|
72
|
+
def swe_calc(julian_day, body_number)
|
73
|
+
self.initialize() if @s == nil
|
74
|
+
|
75
|
+
raise "Invalid body number #{body_number}" if body_number >= SE_NPLANETS || body_number < SE_ECL_NUT
|
76
|
+
|
77
|
+
@s.swe_calc(julian_day, body_number)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Calculates the position of houses given a julian day, location (longitude, latitude) and the house system "PKORCAEVXHTBG".
|
81
|
+
#
|
82
|
+
# * house system allowed values and meanings are:
|
83
|
+
# * �P� Placidus
|
84
|
+
# * �K� Koch
|
85
|
+
# * �O� Porphyrius
|
86
|
+
# * �R� Regiomontanus
|
87
|
+
# * �C� Campanus
|
88
|
+
# * �A� or �E� Equal (cusp 1 is Ascendant)
|
89
|
+
# * �V� Vehlow equal (Asc. in middle of house 1)
|
90
|
+
# * �X� axial rotation system
|
91
|
+
# * �H� azimuthal or horizontal system
|
92
|
+
# * �T� Polich/Page (�topocentric� system)
|
93
|
+
# * �B� Alcabitus
|
94
|
+
# * �G� Gauquelin sectors
|
95
|
+
# * �M� Morinus
|
96
|
+
#
|
97
|
+
# Returns an array of 21 floats containing:
|
98
|
+
# * [0] = 0
|
99
|
+
# * [1] = House 1
|
100
|
+
# * [2] = House 2
|
101
|
+
# * [3] = House 3
|
102
|
+
# * [4] = House 4
|
103
|
+
# * [5] = House 5
|
104
|
+
# * [6] = House 6
|
105
|
+
# * [7] = House 7
|
106
|
+
# * [8] = House 8
|
107
|
+
# * [9] = House 9
|
108
|
+
# * [10] = House 10
|
109
|
+
# * [11] = House 11
|
110
|
+
# * [12] = House 12
|
111
|
+
# * [13] = Ascendant
|
112
|
+
# * [14] = MC
|
113
|
+
# * [15] = ARMC
|
114
|
+
# * [16] = Vertex
|
115
|
+
# * [17] = equatorial ascendant
|
116
|
+
# * [18] = co-ascendant
|
117
|
+
# * [19] = co-ascendant
|
118
|
+
# * [20] = polar ascendant
|
119
|
+
#
|
120
|
+
# For more information on the underlying Swiss Ephemeris library function:
|
121
|
+
# http://www.astro.com/swisseph/swephprg.htm?lang=f#_Toc100044344
|
122
|
+
def swe_houses(julian_day, latitude, longitude, house_system)
|
123
|
+
self.initialize() if @s == nil
|
124
|
+
|
125
|
+
@s.swe_houses(julian_day, latitude, longitude, house_system)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Gets the name of a planet in English, given its body number.
|
129
|
+
#
|
130
|
+
# For more information on the underlying Swiss Ephemeris library function:
|
131
|
+
# http://www.astro.com/swisseph/swephprg.htm?lang=f#_Toc100044309
|
132
|
+
def swe_get_planet_name(body_number)
|
133
|
+
self.initialize() if @s == nil
|
134
|
+
|
135
|
+
raise "Invalid body number #{body_number}" if body_number >= SE_NPLANETS || body_number < SE_ECL_NUT
|
136
|
+
|
137
|
+
@s.swe_get_planet_name(body_number)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Calculate the house position of a body (Planet, moon node, asteroid).
|
141
|
+
#
|
142
|
+
# For more information on the underlying Swiss Ephemeris library function:
|
143
|
+
# http://www.astro.com/swisseph/swephprg.htm?lang=f#_Toc100044349
|
144
|
+
def swe_house_pos(armc, geolat, eps, house_system, lon, lat)
|
145
|
+
self.initialize() if @s == nil
|
146
|
+
|
147
|
+
@s.swe_house_pos(armc, geolat, eps, house_system, lon, lat)
|
148
|
+
end
|
149
|
+
|
150
|
+
# For percision fanatics.
|
151
|
+
#
|
152
|
+
# For more information on the underlying Swiss Ephemeris library function:
|
153
|
+
# http://www.astro.com/swisseph/swephprg.htm?lang=f#_Toc100044334
|
154
|
+
def swe_deltat(julian_day)
|
155
|
+
self.initialize() if @s == nil
|
156
|
+
|
157
|
+
@s.swe_deltat(julian_day)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
#puts File::PATH_SEPARATOR
|
data/test/test.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sweph4ruby'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
class Rsweph_test < Test::Unit::TestCase
|
6
|
+
|
7
|
+
|
8
|
+
def test_initialize()
|
9
|
+
s = Rsweph.new()
|
10
|
+
assert_equal($LOAD_PATH[1] , s.eph_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_swe_set_ephe_path()
|
14
|
+
s = Rsweph.new()
|
15
|
+
s.swe_set_ephe_path($LOAD_PATH[1])
|
16
|
+
assert_equal($LOAD_PATH[1] , s.eph_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_swe_julday()
|
20
|
+
s = Rsweph.new()
|
21
|
+
assert_equal(2453577.0, s.swe_julday(2005, 7, 25, 12, 0))
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_swe_calc()
|
25
|
+
|
26
|
+
test_planet_values = []
|
27
|
+
test_planet_values[0] = 122
|
28
|
+
test_planet_values[1] = 359
|
29
|
+
test_planet_values[2] = 140
|
30
|
+
test_planet_values[3] = 152
|
31
|
+
test_planet_values[4] = 28
|
32
|
+
test_planet_values[5] = 192
|
33
|
+
test_planet_values[6] = 121
|
34
|
+
test_planet_values[7] = 340
|
35
|
+
test_planet_values[8] = 316
|
36
|
+
test_planet_values[9] = 262
|
37
|
+
|
38
|
+
s = Rsweph.new()
|
39
|
+
jul_day = s.swe_julday(2005, 7, 25, 12, 0)
|
40
|
+
|
41
|
+
for i in 0..9
|
42
|
+
assert_equal(test_planet_values[i], s.swe_calc(jul_day, i)[0].to_i())
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_swe_houses()
|
48
|
+
|
49
|
+
test_houses_values = []
|
50
|
+
test_houses_values[0] = 0
|
51
|
+
test_houses_values[1] = 210
|
52
|
+
test_houses_values[2] = 238
|
53
|
+
test_houses_values[3] = 272
|
54
|
+
test_houses_values[4] = 309
|
55
|
+
test_houses_values[5] = 342
|
56
|
+
test_houses_values[6] = 9
|
57
|
+
test_houses_values[7] = 30
|
58
|
+
test_houses_values[8] = 58
|
59
|
+
test_houses_values[9] = 92
|
60
|
+
test_houses_values[10] = 129
|
61
|
+
test_houses_values[11] = 162
|
62
|
+
|
63
|
+
s = Rsweph.new()
|
64
|
+
jul_day = s.swe_julday(2005, 7, 25, 12, 0)
|
65
|
+
houses = s.swe_houses(jul_day, 47.23, 8.33, "P")
|
66
|
+
|
67
|
+
for i in 0..11
|
68
|
+
assert_equal(test_houses_values[i], houses[i].to_i())
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_swe_get_planet_name()
|
73
|
+
test_planet_values = []
|
74
|
+
test_planet_values[0] = "Sun"
|
75
|
+
test_planet_values[1] = "Moon"
|
76
|
+
test_planet_values[2] = "Mercury"
|
77
|
+
test_planet_values[3] = "Venus"
|
78
|
+
test_planet_values[4] = "Mars"
|
79
|
+
test_planet_values[5] = "Jupiter"
|
80
|
+
test_planet_values[6] = "Saturn"
|
81
|
+
test_planet_values[7] = "Uranus"
|
82
|
+
test_planet_values[8] = "Neptune"
|
83
|
+
test_planet_values[9] = "Pluto"
|
84
|
+
|
85
|
+
s = Rsweph.new()
|
86
|
+
|
87
|
+
for i in 0..9
|
88
|
+
assert_equal(test_planet_values[i], s.swe_get_planet_name(i))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_swe_house_pos()
|
93
|
+
|
94
|
+
test_planet_house_values = []
|
95
|
+
test_planet_house_values[0] = 9
|
96
|
+
test_planet_house_values[1] =5
|
97
|
+
test_planet_house_values[2] = 10
|
98
|
+
test_planet_house_values[3] = 10
|
99
|
+
test_planet_house_values[4] = 6
|
100
|
+
test_planet_house_values[5] = 12
|
101
|
+
test_planet_house_values[6] = 9
|
102
|
+
test_planet_house_values[7] = 4
|
103
|
+
test_planet_house_values[8] = 4
|
104
|
+
test_planet_house_values[9] = 2
|
105
|
+
|
106
|
+
s = Rsweph.new()
|
107
|
+
|
108
|
+
jul_day = s.swe_julday(2005, 7, 25, 12, 0)
|
109
|
+
|
110
|
+
houses = []
|
111
|
+
houses = s.swe_houses(jul_day, 47.23, 8.33, "P")
|
112
|
+
armc = houses[15]
|
113
|
+
|
114
|
+
eps = s.swe_calc(jul_day, -1)[0]
|
115
|
+
|
116
|
+
for i in 0..9
|
117
|
+
body_data = []
|
118
|
+
|
119
|
+
body_data = s.swe_calc(jul_day, i)
|
120
|
+
house = s.swe_house_pos(armc, 47.23, eps, 'P', body_data[0], body_data[1])
|
121
|
+
assert_equal(test_planet_house_values[i], house.to_i())
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.10
|
3
|
+
specification_version: 1
|
4
|
+
name: sweph4ruby
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2005-08-09
|
8
|
+
summary: An astrology library
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: pedro.santos@bizarrologia.com
|
12
|
+
homepage: http://rubyforge.org/projects/sweph4ruby/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: sweph4ruby
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
-
|
22
|
+
- ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
authors:
|
28
|
+
- Pedro Moreira Santos
|
29
|
+
files:
|
30
|
+
- MIT-LICENSE
|
31
|
+
- README
|
32
|
+
- SEAS_18.SE1
|
33
|
+
- ext/extconf.rb
|
34
|
+
- ext/libswe.a
|
35
|
+
- ext/swelib32.lib
|
36
|
+
- ext/sweodef.h
|
37
|
+
- ext/sweph4ruby.c
|
38
|
+
- ext/swephexp.h
|
39
|
+
- lib/sweph4ruby.rb
|
40
|
+
- test/test.rb
|
41
|
+
test_files:
|
42
|
+
- test/test.rb
|
43
|
+
rdoc_options: []
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README
|
46
|
+
executables: []
|
47
|
+
extensions:
|
48
|
+
- ext/extconf.rb
|
49
|
+
requirements: []
|
50
|
+
dependencies: []
|