Class: Radiocarbon::CalDate

Inherits:
Object
  • Object
show all
Defined in:
lib/radiocarbon/cal_date.rb

Overview

Represents a calibrated radiocarbon dates.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(c14_date, curve = "IntCal20") ⇒ CalDate

Returns a new instance of CalDate.



11
12
13
14
15
16
17
18
19
# File 'lib/radiocarbon/cal_date.rb', line 11

def initialize(c14_date, curve = "IntCal20")
  @c14_date = c14_date

  if Radiocarbon::CURVES.include?(curve.upcase)
    @curve = curve
  else
    raise "'#{curve}' is not a supported calibration curve"
  end
end

Instance Attribute Details

#c14_dateObject

C14Date

Uncalibrated radiocarbon date



9
10
11
# File 'lib/radiocarbon/cal_date.rb', line 9

def c14_date
  @c14_date
end

#curveObject

String

Name of the calibration curve used, see Radiocarbon::CURVES



6
7
8
# File 'lib/radiocarbon/cal_date.rb', line 6

def curve
  @curve
end

Instance Method Details

#pdist(min_p = 1e-5) ⇒ Object

Generates the probability distribution of the calibrated age over the entire calibration curve.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/radiocarbon/cal_date.rb', line 25

def pdist(min_p = 1e-5)
  cd = curve_data

  p = cd[1].zip(cd[2]).map { |x, error|
    c14_date.dnorm(x, error)
  }

  if (min_p > 0)
    pdist = cd[0].zip(p).filter { |yr,p| p >= min_p }.transpose
    { yr: pdist[0], p: pdist[1] }
  else
    { yr: cd[0], p: p }
  end
end