Class: Astronoby::ExtremumFinder

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

Constant Summary collapse

PHI =
(1 + Math.sqrt(5)) / 2
INVPHI =
1 / PHI
GOLDEN_SECTION_TOLERANCE =
1e-5
MIN_SAMPLES_PER_PERIOD =
20
DUPLICATE_THRESHOLD_DAYS =
0.5
BOUNDARY_BUFFER_DAYS =
0.01

Instance Method Summary collapse

Constructor Details

#initialize(value_at:, period:, samples_per_period: 60) ⇒ ExtremumFinder

Returns a new instance of ExtremumFinder.

Parameters:

  • value_at (#call)

    callable mapping a Julian Date (Terrestrial Time) to a comparable value

  • period (Float)

    the characteristic period of the quantity in days, used to scale the sampling density

  • samples_per_period (Integer) (defaults to: 60)

    number of samples per period



18
19
20
21
22
# File 'lib/astronoby/extremum_finder.rb', line 18

def initialize(value_at:, period:, samples_per_period: 60)
  @value_at = value_at
  @period = period
  @samples_per_period = samples_per_period
end

Instance Method Details

#extrema(start_jd, end_jd, type: :maximum) ⇒ Array<Hash>

Returns extrema as {jd: Float, value: Comparable}, sorted by time.

Parameters:

  • start_jd (Float)

    start time in Julian Date (Terrestrial Time)

  • end_jd (Float)

    end time in Julian Date (Terrestrial Time)

  • type (Symbol) (defaults to: :maximum)

    :maximum or :minimum

Returns:

  • (Array<Hash>)

    extrema as {jd: Float, value: Comparable}, sorted by time



29
30
31
32
33
34
# File 'lib/astronoby/extremum_finder.rb', line 29

def extrema(start_jd, end_jd, type: :maximum)
  candidates = find_candidates(start_jd, end_jd, type)
  refined = candidates.map { |candidate| refine(candidate, type) }.compact
  refined = remove_duplicates(refined)
  filter_boundary_artifacts(refined, start_jd, end_jd)
end