Skip to content

Commit

Permalink
Return transit data instead of nil for never rising bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
rhannequin committed Apr 13, 2024
1 parent 1188980 commit 0ed0566
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/astronoby/events/observation_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def initialize(
private

def compute
@transit_time = Util::Time.decimal_hour_to_time(@date, initial_transit)
@transit_altitude = local_horizontal_altitude_transit

return if h0.nil?

delta_m_rising = (local_horizontal_altitude_rising - shift).degrees./(
Expand All @@ -72,7 +75,6 @@ def compute
@rising_time = Util::Time.decimal_hour_to_time(@date, corrected_rising)
@rising_azimuth = local_horizontal_azimuth_rising
@transit_time = Util::Time.decimal_hour_to_time(@date, corrected_transit)
@transit_altitude = local_horizontal_altitude_transit
@setting_time = Util::Time.decimal_hour_to_time(@date, corrected_setting)
@setting_azimuth = local_horizontal_azimuth_setting
end
Expand Down Expand Up @@ -174,7 +176,6 @@ def local_horizontal_altitude_rising
end

def local_horizontal_azimuth_rising
# TODO: What happens if the body doesn't rise or is circumpolar?
@local_horizontal_azimuth_rising ||= begin
shift = -@standard_altitude
term1 = declination_rising.sin + shift.sin * @observer.latitude.cos
Expand All @@ -185,7 +186,6 @@ def local_horizontal_azimuth_rising
end

def local_horizontal_altitude_transit
# TODO: What happens if the body doesn't rise/set or is circumpolar?
@local_horizontal_altitude_transit ||= Angle.asin(
@observer.latitude.sin * declination_transit.sin +
@observer.latitude.cos * declination_transit.cos * local_hour_angle_transit.cos
Expand All @@ -200,7 +200,6 @@ def local_horizontal_altitude_setting
end

def local_horizontal_azimuth_setting
# TODO: What happens if the body doesn't set or is circumpolar?
shift = -@standard_altitude
term1 = declination_setting.sin + shift.sin * @observer.latitude.cos
term2 = shift.cos * @observer.latitude.cos
Expand Down
56 changes: 54 additions & 2 deletions spec/astronoby/events/observation_events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
end

context "when the body does not rise" do
it "returns nil" do
it "returns an object's upper transit time" do
date = Date.new(2016, 1, 21)
observer = Astronoby::Observer.new(
latitude: Astronoby::Angle.from_degrees(38),
Expand All @@ -300,7 +300,33 @@

transit_time = events.transit_time

expect(transit_time).to be_nil
expect(transit_time).to eq Time.utc(2016, 1, 21, 0, 8, 2)
end
end

context "when the body is circumpolar" do
it "returns an object's upper transit time" do
date = Date.new(2016, 1, 21)
observer = Astronoby::Observer.new(
latitude: Astronoby::Angle.from_degrees(38),
longitude: Astronoby::Angle.from_degrees(-78)
)
coordinates_of_the_day = Astronoby::Coordinates::Equatorial.new(
right_ascension: Astronoby::Angle.from_hms(2, 52, 43),
declination: Astronoby::Angle.from_dms(89, 20, 9)
)
events = described_class.new(
observer: observer,
date: date,
coordinates_of_the_previous_day: coordinates_of_the_day,
coordinates_of_the_day: coordinates_of_the_day,
coordinates_of_the_next_day: coordinates_of_the_day
)

transit_time = events.transit_time

expect(transit_time).to eq Time.utc(2016, 1, 21, 0, 0, 14)
# Time from Stellarium: 2016-01-21T00:01:35
end
end
end
Expand Down Expand Up @@ -537,5 +563,31 @@
expect(transit_altitude.str(:dms)).to eq "+89° 4′ 6.548″"
# Azimuth from SkySafari: +89° 12′ 1.4″
end

context "when the body is circumpolar" do
it "returns an object's upper transit azimuth" do
date = Date.new(2016, 1, 21)
observer = Astronoby::Observer.new(
latitude: Astronoby::Angle.from_degrees(38),
longitude: Astronoby::Angle.from_degrees(-78)
)
coordinates_of_the_day = Astronoby::Coordinates::Equatorial.new(
right_ascension: Astronoby::Angle.from_hms(2, 52, 43),
declination: Astronoby::Angle.from_dms(89, 20, 9)
)
events = described_class.new(
observer: observer,
date: date,
coordinates_of_the_previous_day: coordinates_of_the_day,
coordinates_of_the_day: coordinates_of_the_day,
coordinates_of_the_next_day: coordinates_of_the_day
)

transit_altitude = events.transit_altitude

expect(transit_altitude.str(:dms)).to eq "+38° 39′ 50.9999″"
# Azimuth from Stellarium: +38° 41′ 5.4″
end
end
end
end

0 comments on commit 0ed0566

Please sign in to comment.