Class: Astronoby::RootFinder

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

Constant Summary collapse

MIN_SAMPLES_PER_PERIOD =
20
BISECTION_TOLERANCE_DAYS =
1e-5

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of RootFinder.

Parameters:

  • value_at (#call)

    callable mapping a Julian Date (Terrestrial Time) to a Float

  • period (Float)

    the characteristic period of the quantity in days

  • samples_per_period (Integer) (defaults to: 60)

    number of samples per period



12
13
14
15
16
# File 'lib/astronoby/root_finder.rb', line 12

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

#roots(start_jd, end_jd, accept: nil) ⇒ Array<Float>

Returns root times in Julian Date (Terrestrial Time), sorted by time.

Parameters:

  • start_jd (Float)

    start time in Julian Date (Terrestrial Time)

  • end_jd (Float)

    end time in Julian Date (Terrestrial Time)

  • accept (#call, nil) (defaults to: nil)

    optional predicate on a located root (a Julian Date)

Returns:

  • (Array<Float>)

    root times in Julian Date (Terrestrial Time), sorted by time



24
25
26
27
28
# File 'lib/astronoby/root_finder.rb', line 24

def roots(start_jd, end_jd, accept: nil)
  brackets = find_brackets(start_jd, end_jd)
  located = brackets.map { |a, b| bisect(a, b) }
  located.select { |jd| accept.nil? || accept.call(jd) }
end