Module: Astrarium::Calculations

Defined in:
lib/astrarium/calculations.rb

Constant Summary collapse

SIGNS =
%i[aries taurus gemini cancer leo virgo libra scorpio sagittarius capricorn aquarius pisces]
SWE4R_PLANETS =
{
  sun: Swe4r::SE_SUN,
  moon: Swe4r::SE_MOON,
  mercury: Swe4r::SE_MERCURY,
  venus: Swe4r::SE_VENUS,
  mars: Swe4r::SE_MARS,
  jupiter: Swe4r::SE_JUPITER,
  saturn: Swe4r::SE_SATURN,
  uranus: Swe4r::SE_URANUS,
  neptune: Swe4r::SE_NEPTUNE,
  pluto: Swe4r::SE_PLUTO
}

Class Method Summary collapse

Class Method Details

.house_longitudes(year, month, day, hour, latitude, longitude) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/astrarium/calculations.rb', line 50

def self.house_longitudes(year, month, day, hour, latitude, longitude)
  jd = Swe4r::swe_julday(year, month, day, hour)
  houses = Swe4r::swe_houses(jd, latitude, longitude, 'P')

  (1..12).each_with_object({}) do |i, hash|
    hash[i] = houses[i]
  end
end

.house_planets(year, month, day, hour, latitude, longitude, altitude) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/astrarium/calculations.rb', line 35

def self.house_planets(year, month, day, hour, latitude, longitude, altitude)
  houses = house_signs(year, month, day, hour, latitude, longitude) # {1 => :libra, 2 => :scorpio, ...}
  house_planets = houses.keys.each_with_object({}) { |i, hash| hash[i] = [] }

  planet_signs(year, month, day, hour, latitude, longitude, altitude).each do |planet, sign|
    house = houses.key(sign)
    if house
      house_planets[house] << planet
    end
  end

  # Convert empty arrays to nil for empty houses
  house_planets.transform_values { |planets| planets.empty? ? nil : planets }
end

.house_signs(year, month, day, hour, latitude, longitude) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/astrarium/calculations.rb', line 19

def self.house_signs(year, month, day, hour, latitude, longitude)
  longitudes = house_longitudes(year, month, day, hour, latitude, longitude)

  longitudes.each_with_object({}) do |house_with_longitude, hash|
    hash[house_with_longitude[0]] = SIGNS[(house_with_longitude[1] / 30.0).to_i]
  end # first house is the ascendant
end

.planet_longitudes(year, month, day, hour, latitude, longitude, altitude) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/astrarium/calculations.rb', line 59

def self.planet_longitudes(year, month, day, hour, latitude, longitude, altitude)
  jd = Swe4r::swe_julday(year, month, day, hour)

  # Set the geographic location for topocentric positions
  Swe4r::swe_set_topo(longitude, latitude, altitude)

  # Set the sidereal mode for sidereal positions
  Swe4r::swe_set_sid_mode(Swe4r::SE_SIDM_LAHIRI, 0, 0)

  SWE4R_PLANETS.each_with_object({}) do |item, hash|
    planet_name = item[0]
    swe4r_planet = item[1]
    body = Swe4r::swe_calc_ut(jd, swe4r_planet, Swe4r::SEFLG_MOSEPH)

    hash[planet_name] = body[0]
  end
end

.planet_signs(year, month, day, hour, latitude, longitude, altitude) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/astrarium/calculations.rb', line 27

def self.planet_signs(year, month, day, hour, latitude, longitude, altitude)
  longitudes = planet_longitudes(year, month, day, hour, latitude, longitude, altitude)

  longitudes.each_with_object({}) do |planet_with_longitude, hash|
    hash[planet_with_longitude[0]] = SIGNS[(planet_with_longitude[1] / 30.0).to_i]
  end
end