Documentation for SingleFitter
Bases: CarbonFitter
A class for parametric and non-parametric inference of d14c data using a Carbon Box Model (CBM). Does parameter fitting, Monte Carlo sampling, plotting and more.
__init__(cbm, cbm_model, production_rate_units='atoms/cm^2/s', target_C_14=707.0, box='Troposphere', hemisphere='north', adaptive=True)
Initializes a SingleFitter Object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cbm |
CarbonBoxModel Object
|
Carbon Box Model |
required |
cbm_model |
str
|
CBM name. Must be one in: "Guttler15", "Miyake17", "Buntgen18", "Brehm21" |
required |
production_rate_units |
str
|
CBM production rate units. 'atoms/cm^2/s' by default |
'atoms/cm^2/s'
|
target_C_14 |
float
|
Target 14C content for equilibration. 707 by default |
707.0
|
box |
str
|
Box for calculating d14c. 'Troposphere' by default |
'Troposphere'
|
hemisphere |
str
|
CBM hemisphere. Must be one in: "north", "south". "north" by default |
'north'
|
load_data(file_name, oversample=1008, burnin_oversample=1, burnin_time=2000, num_offset=4, verbose=False)
Loads d14c data from a csv file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name |
str
|
Path to a csv file |
required |
oversample |
int
|
Number of samples per year in production. 1008 by default |
1008
|
burnin_oversample |
int
|
Number of samples per year in burn-in. 1 by default |
1
|
burnin_time |
int
|
Number of years in the burn-in period. 2000 by default |
2000
|
num_offset |
int
|
Number of data points used for normalization. 4 by default |
4
|
get_growth_vector(growth_season)
Converts the growing season of a tree from string to 12-digit binary vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
growth_season |
str
|
Growing season. Must have the format: "StartMonth-EndMonth" |
required |
Returns:
Type | Description |
---|---|
ndarray
|
12-digit binary vector |
compile_production_model(model=None)
Sets the production rate model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
str | callable
|
Built-in or custom model. Supported built-in model are: "simple_sinusoid", "flexible_sinusoid", "flexible_sinusoid_affine_variant", "control_points", "inverse_solver" |
None
|
interp_gp(tval, *args)
A Gaussian Process regression interpolator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tval |
ndarray
|
Output time sampling |
required |
args |
ndarray | float
|
Set of annually resolved control-points passed in as a ndarray |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Interpolation on tval |
interp_IS(tval, *args)
A linear interpolator for inverse solver.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tval |
ndarray
|
Output time sampling |
required |
args |
ndarray | float
|
Set of production rates on the same time sampling as self.time_data |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Interpolation on tval |
super_gaussian(t, start_time, duration, area)
Computes the density of a super gaussian of exponent 16. Used to emulates the spike in d14c data following the occurrence of a Miyake event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
ndarray
|
Time sampling |
required |
start_time |
float
|
Start time of a Miyake event |
required |
duration |
float
|
Duration of a Miyake event |
required |
area |
float
|
Total radiocarbon delivered by a Miyake event |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Production rate on t |
simple_sinusoid(t, *args)
A simple sinusoid production rate model. Tunable parameters are, Start time: start time
log_Duration: log10 duration
Phase: phase of the solar cycle
log_Area: log10 total radiocarbon delivered
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
ndarray
|
Time sampling |
required |
args |
ndarray
|
Tunable parameters. Must include, start time, duration, phase and area |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Production rate on t |
flexible_sinusoid(t, *args)
A flexible sinusoid production rate model. Tunable parameters are, Start time: start time
log_Duration: log10 duration
Phase: phase of the solar cycle
log_Area: log10 total radiocarbon delivered
log_Amplitude: log10 solar amplitude
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
ndarray
|
Time sampling |
required |
args |
ndarray
|
Tunable parameters. Must include, start time, duration, phase, area and amplitude |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Production rate on t |
flexible_sinusoid_affine_variant(t, *args)
A flexible sinusoid production rate model with a linear gradient. Tunable parameters are, Gradient: linear gradient
Start time: start time
log_Duration: log10 duration
Phase: phase of the solar cycle
log_Area: log10 total radiocarbon delivered
log_Amplitude: log10 solar amplitude
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
ndarray
|
Time sampling |
required |
args |
ndarray
|
Tunable parameters. Must include, gradient, start time, duration, phase, area and amplitude |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Production rate on t |
run_burnin(y0=None, params=())
Calculates the C14 content of all the boxes within a CBM for the burn-in period.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y0 |
ndarray
|
Initial contents of all boxes |
None
|
params |
ndarray
|
Parameters for the production rate model |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Value of each box in the CBM during the burn-in period |
run_event(y0=None, params=())
Calculates the C14 content of all the boxes within a CBM for the production period.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y0 |
ndarray
|
The initial contents of all boxes |
None
|
params |
ndarray
|
Parameters for self.production function |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Value of each box in the CBM during the production period |
dc14(params=())
Predict d14c on the time sampling from the data file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
Parameters for the production rate model |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Predicted d14c value |
dc14_fine(params=())
Predict d14c on a sub-annual time sampling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
Parameters for the production rate model |
()
|
Returns:
Type | Description |
---|---|
ndarray
|
Predicted d14c value |
log_likelihood(params=())
Computes the gaussian log-likelihood of production rate model parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
Parameters of the production rate model |
()
|
Returns:
Type | Description |
---|---|
float
|
Gaussian log-likelihood |
log_joint_likelihood(params, low_bounds, up_bounds)
Computes the log joint likelihood of production rate model parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
Production rate model parameters |
required |
low_bounds |
ndarray
|
Lower bound of params |
required |
up_bounds |
ndarray
|
Upper bound of params |
required |
Returns:
Type | Description |
---|---|
float
|
Log joint likelihood |
log_likelihood_gp(params)
Computes the Gaussian Process log-likelihood of a set of control-points. The Gaussian Process has a constant mean and a Matern-3/2 kernel with 1 year scale parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
An array of control-points. The first control point is also the mean of the Gaussian Process |
required |
Returns:
Type | Description |
---|---|
float
|
Gaussian Process log-likelihood |
log_joint_likelihood_gp(params, low_bounds, up_bounds)
Computes the log joint likelihood of a set of control-points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
An array of control-points |
required |
Returns:
Type | Description |
---|---|
float
|
Log joint likelihood |
neg_log_joint_likelihood_gp(params)
Computes the negative log joint likelihood of a set of control-points. Used as the objective function for fitting the set of control-points via numerical optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
An array of control-points |
required |
Returns:
Type | Description |
---|---|
float
|
Negative log joint likelihood |
grad_neg_log_joint_likelihood_gp(params=())
Computes the negative gradient of the log joint likelihood of a set of control-points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
ndarray
|
An array of control-points |
()
|
Returns:
Type | Description |
---|---|
float
|
Negative gradient of log joint likelihood |
fit_ControlPoints(low_bound=0)
Fits control-points by minimizing the negative log joint likelihood.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
low_bound |
int
|
The minimum value each control-point can take. 0 by default. |
0
|
Returns:
Type | Description |
---|---|
OptimizeResult
|
Scipy OptimizeResult object |