Class: Astroscript::Calculator
- Inherits:
-
Object
- Object
- Astroscript::Calculator
- Defined in:
- lib/astroscript/calculator.rb
Instance Attribute Summary collapse
-
#altitude ⇒ Object
Returns the value of attribute altitude.
-
#arc ⇒ Object
Returns the value of attribute arc.
-
#asc ⇒ Object
readonly
Returns the value of attribute asc.
-
#equasc ⇒ Object
readonly
Returns the value of attribute equasc.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#house_method ⇒ Object
Returns the value of attribute house_method.
-
#jd ⇒ Object
Returns the value of attribute jd.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#mc ⇒ Object
readonly
Returns the value of attribute mc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#transformer ⇒ Object
Returns the value of attribute transformer.
-
#tz ⇒ Object
Returns the value of attribute tz.
-
#vertex ⇒ Object
readonly
Returns the value of attribute vertex.
Instance Method Summary collapse
- #[](abbr) ⇒ Object
- #ascendant ⇒ Object
- #av ⇒ Object (also: #avx)
- #ayanamsha ⇒ Object
- #before_sunrise? ⇒ Boolean
- #calc(id, equatorial: false, heliocentric: false) ⇒ Object
- #datetime ⇒ Object
- #datetime=(time) ⇒ Object
- #dc ⇒ Object
- #flip(d) ⇒ Object
- #get_body(abbr, jd = nil) ⇒ Object
- #get_houses(calc_method = nil) ⇒ Object
- #house_cusps(calc_method = nil) ⇒ Object
- #ic ⇒ Object
- #init(*args) ⇒ Object
-
#initialize(*args) ⇒ Calculator
constructor
A new instance of Calculator.
- #midheaven ⇒ Object
-
#oe ⇒ Object
obliquity of the ecliptic.
- #options ⇒ Object
- #ramc ⇒ Object
- #set_topo(latitude, longitude, altitude = nil) ⇒ Object
- #solunar_phase ⇒ Object
- #svp ⇒ Object
- #timezone ⇒ Object
- #to_a ⇒ Object
- #true_node? ⇒ Boolean
- #update(params) ⇒ Object
- #utc ⇒ Object
- #which_house(degree) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Calculator
Returns a new instance of Calculator.
8 9 10 11 12 13 14 15 |
# File 'lib/astroscript/calculator.rb', line 8 def initialize *args @arc = 0 params = args.last.is_a?(Hash) ? args.pop : {} init_params(params) # defaults set_topo(51.476852, -0.000500) # Royal Observatory Greenwich, London, UK self.datetime = DateTime.now.new_offset # Time.now.utc end |
Instance Attribute Details
#altitude ⇒ Object
Returns the value of attribute altitude.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def altitude @altitude end |
#arc ⇒ Object
Returns the value of attribute arc.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def arc @arc end |
#asc ⇒ Object (readonly)
Returns the value of attribute asc.
6 7 8 |
# File 'lib/astroscript/calculator.rb', line 6 def asc @asc end |
#equasc ⇒ Object (readonly)
Returns the value of attribute equasc.
6 7 8 |
# File 'lib/astroscript/calculator.rb', line 6 def equasc @equasc end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
6 7 8 |
# File 'lib/astroscript/calculator.rb', line 6 def flags @flags end |
#house_method ⇒ Object
Returns the value of attribute house_method.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def house_method @house_method end |
#jd ⇒ Object
Returns the value of attribute jd.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def jd @jd end |
#latitude ⇒ Object
Returns the value of attribute latitude.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def longitude @longitude end |
#mc ⇒ Object (readonly)
Returns the value of attribute mc.
6 7 8 |
# File 'lib/astroscript/calculator.rb', line 6 def mc @mc end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def prefix @prefix end |
#transformer ⇒ Object
Returns the value of attribute transformer.
6 7 8 |
# File 'lib/astroscript/calculator.rb', line 6 def transformer @transformer end |
#tz ⇒ Object
Returns the value of attribute tz.
5 6 7 |
# File 'lib/astroscript/calculator.rb', line 5 def tz @tz end |
#vertex ⇒ Object (readonly)
Returns the value of attribute vertex.
6 7 8 |
# File 'lib/astroscript/calculator.rb', line 6 def vertex @vertex end |
Instance Method Details
#[](abbr) ⇒ Object
111 112 113 114 |
# File 'lib/astroscript/calculator.rb', line 111 def [](abbr) abbr = abbr.upcase if abbr.size == 2 get_body(abbr) end |
#ascendant ⇒ Object
116 117 118 |
# File 'lib/astroscript/calculator.rb', line 116 def ascendant @asc || (get_houses && @asc) end |
#av ⇒ Object Also known as: avx
186 187 188 |
# File 'lib/astroscript/calculator.rb', line 186 def av flip(vertex) end |
#ayanamsha ⇒ Object
63 64 65 |
# File 'lib/astroscript/calculator.rb', line 63 def ayanamsha @ayanamsha ? Swe4r.swe_get_ayanamsa_ex_ut(@jd, @flags) : 0 end |
#before_sunrise? ⇒ Boolean
195 196 197 198 199 200 |
# File 'lib/astroscript/calculator.rb', line 195 def before_sunrise? ac = house_cusps[0] # sunrise ic = house_cusps[3] # midnight ic += 360 if ic < ac get_body(:SO).to_f.between?(ac, ic) # before sunrise? end |
#calc(id, equatorial: false, heliocentric: false) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/astroscript/calculator.rb', line 93 def calc(id, equatorial: false, heliocentric: false) flags = self.flags flags |= Swe4r::SEFLG_EQUATORIAL if equatorial flags |= Swe4r::SEFLG_HELCTR if heliocentric Swe4r.swe_calc_ut(jd, id, flags) end |
#datetime ⇒ Object
47 48 49 |
# File 'lib/astroscript/calculator.rb', line 47 def datetime @tz ? timezone.to_local(utc) : utc end |
#datetime=(time) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/astroscript/calculator.rb', line 79 def datetime=(time) @oe = nil @ra = nil @planetary_hours = nil @jd = AstroHelper.datetime_to_jd(time) end |
#dc ⇒ Object
178 179 180 |
# File 'lib/astroscript/calculator.rb', line 178 def dc flip(asc) end |
#flip(d) ⇒ Object
191 192 193 |
# File 'lib/astroscript/calculator.rb', line 191 def flip(d) (d + 180) % 360 end |
#get_body(abbr, jd = nil) ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/astroscript/calculator.rb', line 101 def get_body(abbr, jd = nil) @jd = jd if jd $logger.warn "use :NN with @true_node configuration instead of #{abbr}" if %i[MN TN].include?(abbr) if abbr =~ /^C(\d+)$/ HouseCusp.new(::Regexp.last_match(1).to_i, self) else Body.new(abbr, self) end end |
#get_houses(calc_method = nil) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/astroscript/calculator.rb', line 136 def get_houses(calc_method = nil) if calc_method @house_method = calc_method else @house_method ||= "P" # 'C' end raise "you must call set_topo with latitude and longitude before get_houses" unless @latitude && @longitude flag = @ayanamsha ? Swe4r::SEFLG_SIDEREAL : 0 @house_cusps, ascmc, *, ascmc_speeds = Swe4r.swe_houses_ex2(jd, flag, @latitude, @longitude, @house_method) # @house_cusps.pop if @house_cusps.first.zero? # FIXME bug @asc, @mc, @ramc, @vertex = *ascmc[0..3] @equasc, = *ascmc[4..7] # * ascmc[4] = equasc * "equatorial ascendant" * # * ascmc[5] = coasc1 * "co-ascendant" (W. Koch) * # * ascmc[6] = coasc2 * "co-ascendant" (M. Munkasey) * # * ascmc[7] = polasc * "polar ascendant" (M. Munkasey) * @asc_speed, @mc_speed, *, @vertex_speed = *ascmc_speeds[0..3] true end |
#house_cusps(calc_method = nil) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/astroscript/calculator.rb', line 124 def house_cusps(calc_method = nil) case calc_method when :asc AstroHelper.harmonic_cusps(get_position(:asc).lon) when :mc AstroHelper.harmonic_cusps(get_position(:mc).lon, 10) else get_houses(calc_method) unless @house_cusps && calc_method.nil? @house_cusps[1..12] end end |
#ic ⇒ Object
182 183 184 |
# File 'lib/astroscript/calculator.rb', line 182 def ic flip(mc) end |
#init(*args) ⇒ Object
55 56 57 |
# File 'lib/astroscript/calculator.rb', line 55 def init *args AstroHelper.init_calc(self, *args) end |
#midheaven ⇒ Object
120 121 122 |
# File 'lib/astroscript/calculator.rb', line 120 def midheaven @mc end |
#oe ⇒ Object
obliquity of the ecliptic
75 76 77 |
# File 'lib/astroscript/calculator.rb', line 75 def oe # obliquity of the ecliptic @oe ||= Swe4r.swe_calc_ut(@jd, -1, 0).first end |
#options ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/astroscript/calculator.rb', line 24 def opts = {} opts[:house_method] = house_method opts[:latitude] = AstroHelper.print_dms(latitude, lat: true) opts[:longitude] = AstroHelper.print_dms(longitude, lon: true) opts[:jd] = @jd opts[:tz] = @tz.to_s # date = @tz.to_local(DateTime.new(*Swe4r::swe_revjul(@jd))).to_s date = DateTime.new(*Swe4r.swe_revjul(@jd)).to_s opts[:date] = DateTime.parse(date).strftime("%Y-%m-%d %I:%M %p") opts[:ayanamsha] = AstroHelper.print_dms ayanamsha, seconds: true opts[:flags] = @flags opts end |
#ramc ⇒ Object
158 159 160 |
# File 'lib/astroscript/calculator.rb', line 158 def ramc @ramc || (get_houses && @ramc) end |
#set_topo(latitude, longitude, altitude = nil) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/astroscript/calculator.rb', line 86 def set_topo(latitude, longitude, altitude = nil) @latitude = latitude @longitude = longitude @altitude = altitude.to_f Swe4r.swe_set_topo(@longitude, @latitude, @altitude) end |
#solunar_phase ⇒ Object
202 203 204 |
# File 'lib/astroscript/calculator.rb', line 202 def solunar_phase (get_body(:MO).to_f - get_body(:SO).to_f + 360) % 360 end |
#svp ⇒ Object
67 68 69 |
# File 'lib/astroscript/calculator.rb', line 67 def svp -ayanamsha end |
#timezone ⇒ Object
39 40 41 |
# File 'lib/astroscript/calculator.rb', line 39 def timezone TZInfo::Timezone.get(@tz) end |
#to_a ⇒ Object
51 52 53 |
# File 'lib/astroscript/calculator.rb', line 51 def to_a [@tz, @jd, @latitude, @longitude, @altitude] end |
#true_node? ⇒ Boolean
71 72 73 |
# File 'lib/astroscript/calculator.rb', line 71 def true_node? !!@true_node end |
#update(params) ⇒ Object
59 60 61 |
# File 'lib/astroscript/calculator.rb', line 59 def update(params) init_params(params) end |
#utc ⇒ Object
43 44 45 |
# File 'lib/astroscript/calculator.rb', line 43 def utc DateTime.new(*Swe4r.swe_revjul(@jd)) end |
#which_house(degree) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/astroscript/calculator.rb', line 162 def which_house(degree) get_houses unless @house_cusps min_cusp = house_cusps.min degree += 360 if degree < min_cusp # Iterate through the house cusps house_cusps.each_with_index do |cusp, i| # Check if the degree is within the current house next_cusp = house_cusps[i + 1] return 12 if next_cusp.nil? next_cusp += 360 if next_cusp == min_cusp # $logger.debug("#{degree.round(2)}.between? #{cusp},#{next_cusp}") return i + 1 if degree.between?(cusp, next_cusp) end end |