Class: Astronoby::Observer

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/observer.rb

Constant Summary collapse

DEFAULT_ELEVATION =
Distance.zero
DEFAULT_TEMPERATURE =
283.15
PRESSURE_AT_SEA_LEVEL =
1013.25
PASCAL_PER_MILLIBAR =
0.01
EARTH_GRAVITATIONAL_ACCELERATION =
9.80665
MOLAR_MASS_OF_AIR =
0.0289644
UNIVERSAL_GAS_CONSTANT =
8.31432

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude:, longitude:, elevation: DEFAULT_ELEVATION, utc_offset: 0, temperature: DEFAULT_TEMPERATURE, pressure: nil) ⇒ Observer

Returns a new instance of Observer.

Parameters:

  • latitude (Astronoby::Angle)

    geographic latitude of the observer

  • longitude (Astronoby::Angle)

    geographic longitude of the observer

  • elevation (Astronoby::Distance) (defaults to: DEFAULT_ELEVATION)

    geographic elevation (or altitude) of the observer above sea level

  • utc_offset (Numeric, String) (defaults to: 0)

    offset from Coordinated Universal Time

  • temperature (Numeric) (defaults to: DEFAULT_TEMPERATURE)

    temperature at the observer’s location in kelvins

  • pressure (Numeric) (defaults to: nil)

    atmospheric pressure at the observer’s location in millibars



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/astronoby/observer.rb', line 40

def initialize(
  latitude:,
  longitude:,
  elevation: DEFAULT_ELEVATION,
  utc_offset: 0,
  temperature: DEFAULT_TEMPERATURE,
  pressure: nil
)
  @latitude = latitude
  @longitude = longitude
  @elevation = elevation
  @utc_offset = utc_offset
  @temperature = temperature
  @pressure = pressure || compute_pressure
end

Instance Attribute Details

#elevationAstronoby::Distance (readonly)

Returns geographic elevation above sea level.

Returns:



20
21
22
# File 'lib/astronoby/observer.rb', line 20

def elevation
  @elevation
end

#latitudeAstronoby::Angle (readonly)

Returns geographic latitude.

Returns:



14
15
16
# File 'lib/astronoby/observer.rb', line 14

def latitude
  @latitude
end

#longitudeAstronoby::Angle (readonly)

Returns geographic longitude.

Returns:



17
18
19
# File 'lib/astronoby/observer.rb', line 17

def longitude
  @longitude
end

#pressureNumeric (readonly)

Returns atmospheric pressure in millibars.

Returns:

  • (Numeric)

    atmospheric pressure in millibars



29
30
31
# File 'lib/astronoby/observer.rb', line 29

def pressure
  @pressure
end

#temperatureNumeric (readonly)

Returns temperature in kelvins.

Returns:

  • (Numeric)

    temperature in kelvins



26
27
28
# File 'lib/astronoby/observer.rb', line 26

def temperature
  @temperature
end

#utc_offsetNumeric, String (readonly)

Returns offset from Coordinated Universal Time.

Returns:

  • (Numeric, String)

    offset from Coordinated Universal Time



23
24
25
# File 'lib/astronoby/observer.rb', line 23

def utc_offset
  @utc_offset
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns true if all attributes are equal.

Parameters:

Returns:

  • (Boolean)

    true if all attributes are equal



94
95
96
97
98
99
100
101
102
103
# File 'lib/astronoby/observer.rb', line 94

def ==(other)
  return false unless other.is_a?(self.class)

  @latitude == other.latitude &&
    @longitude == other.longitude &&
    @elevation == other.elevation &&
    @utc_offset == other.utc_offset &&
    @temperature == other.temperature &&
    @pressure == other.pressure
end

#earth_fixed_rotation_matrix_for(instant) ⇒ Matrix

Computes the Earth-fixed rotation matrix R₃(GAST) * W (polar motion) for a given instant.

Parameters:

Returns:

  • (Matrix)

    3x3 rotation matrix



88
89
90
# File 'lib/astronoby/observer.rb', line 88

def earth_fixed_rotation_matrix_for(instant)
  EarthRotation.matrix_for(instant) * polar_motion_matrix_for(instant)
end

#geocentric_positionAstronoby::Vector<Astronoby::Distance>

Returns the observer’s ECEF position vector (WGS-84 geodetic to ECEF).

Returns:



59
60
61
62
63
64
65
66
67
68
# File 'lib/astronoby/observer.rb', line 59

def geocentric_position
  @geocentric_position ||= begin
    n = earth_prime_vertical_radius_of_curvature
    x = (n + @elevation.m) * @latitude.cos * @longitude.cos
    y = (n + @elevation.m) * @latitude.cos * @longitude.sin
    z = (n * (1 - Constants::WGS84_ECCENTICITY_SQUARED) + @elevation.m) *
      @latitude.sin
    Distance.vector_from_meters([x, y, z])
  end
end

#geocentric_velocityAstronoby::Vector<Astronoby::Velocity>

Returns the observer’s ECEF velocity vector due to Earth rotation.

Returns:



73
74
75
76
77
78
79
80
81
# File 'lib/astronoby/observer.rb', line 73

def geocentric_velocity
  @geocentric_velocity ||= begin
    r = projected_radius
    vx = -Constants::EARTH_ANGULAR_VELOCITY_RAD_PER_S * r * @longitude.sin
    vy = Constants::EARTH_ANGULAR_VELOCITY_RAD_PER_S * r * @longitude.cos
    vz = 0.0
    Velocity.vector_from_mps([vx, vy, vz])
  end
end

#hashInteger

Returns hash value.

Returns:

  • (Integer)

    hash value



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/astronoby/observer.rb', line 107

def hash
  [
    self.class,
    @latitude,
    @longitude,
    @elevation,
    @utc_offset,
    @temperature,
    @pressure
  ].hash
end