---
title: rintcal
output:
  html_vignette:
    toc: true
    toc_depth: 3
    number_sections: true
vignette: >
  %\VignetteIndexEntry{rintcal}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

# Introduction

The international IntCal group provides ratified radiocarbon calibration curves such as IntCal20 (for northern hemisphere terrestrial radiocarbon dates; Reimer et al. 2020[^1]), Marine20 (for marine dates; Heaton et al. 2020[^2]) and SHCal20 (Hogg et al. 2020[^3]). This package provides these curves, as well as previous iterations (IntCal13, Marine13, SHCal13, IntCal09, Marine09, IntCal04, Marine04, SHCal04, IntCal98, Marine98), Arnold and Libby's first curve[^4], and postbomb curves (Levin and Kromer 2004[^5], Santos et al. 2015[^6], Andrews et al. 2016[^7], Hua et al. 2021[^8] and Emmenegger et al. 2024[^9]). 

# Installation

On first usage of the package, it has to be installed: 

```{r, eval=FALSE}
install.packages('rintcal')
``` 

If you have a recent version of `rbacon`, `rplum`, `coffee`, `rice` or `clam` installed on your computer, `rintcal` will probably have been installed as well. Sometimes new versions of these packages appear, so please re-issue the above command regularly to remain up-to-date, or use:

```{r, eval=FALSE}
update.packages()
``` 

To obtain access to the calibration curves, first the package has to be loaded:

```{r}
library(rintcal)
```

# Calibration curves

## Loading curves

Now you can load a calibration curve into the memory, for example the default curve IntCal20, and check the first and last few entries:

```{r}
ic20 <- ccurve()
head(ic20)
tail(ic20)
```

The files have three columns: cal BP, the corresponding IntCal C14 BP ages, and the uncertainties (1 standard deviation). 

To see more detail of each rintcal function, place a question-mark before the function name, e.g.:

```{r, eval=FALSE}
?ccurve
```

To get a list of available curves and associated files (and where they can be found):

```{r}
list.ccurves()
```

### Libby's curve

Legacy calibration data such as Arnold & Libby (1951) can be compared with the latest calibration curves. Only included here are those radiocarbon dates of Arnold and Libby which come with independent (historical, archaeological or dendrochronological) age estimates. Note that Arnold and Libby did not define their 'calendar years' explicitly, so the ages have to be taken with a degree of caution.

```{r, fig.width=5, fig.asp=1}
libby <- read.table(file.path(system.file(package = 'rintcal'), "extdata/Arnold_Libby_1951.txt"), header=T, sep=",")
plot(libby[,2], libby[,4], xlab="'cal' BP", ylab="C14 BP", pch=20) # plot the radiocarbon dates and their known calendar ages
segments(libby[,2]-libby[,3], libby[,4], libby[,2]+libby[,3], libby[,4]) # calendar error bars (not all are quantified)
segments(libby[,2], libby[,4]-libby[,5], libby[,2], libby[,4]+libby[,5]) # radiocarbon error bars
abline(0, 1, lty=2)
ic20 <- ccurve() # add the IntCal20 curve
ic20.pol <- cbind(c(ic20[,1], rev(ic20[,1])), c(ic20[,2]-ic20[,3], rev(ic20[,2]+ic20[,3])))
polygon(ic20.pol, col="darkgreen", border=NA)
```

## Curve data

To look at the data underlying the IntCal curves, we can open the IntCal20 dataset downloaded from intchron.org and extract any relevant information, for example to check how many Irish oaks are in the dataset:

```{r}
intcal <- intcal.read.data()
IrishOaks <- intcal.data.frames(intcal, taxon="Quercus sp.", country="Ireland")
length(IrishOaks)
```

Or plot a Bristlecone Pine series, one with single-ring radiocarbon dates that show a very abrupt change in radiocarbon age (Miyake Event):

```{r, fig.width=4, fig.asp=.8}
Bristle <- intcal.data.frames(intcal, taxon="Pinus longaeva")
Bristle_yearly <- Bristle[[20]]$data[,c(8,14,15)]
plot(Bristle_yearly[,1], Bristle_yearly[,2], xlab="cal BP", ylab="C14 BP")
segments(Bristle_yearly[,1], Bristle_yearly[,2]-Bristle_yearly[,3], Bristle_yearly[,1], Bristle_yearly[,2]+Bristle_yearly[,3])
```

The data underlying parts of the IntCal calibration curve can be visualised, for example from 500 to 0 cal BP:

```{r, fig.width=5, fig.asp=1}
intcal.data(0, 500)
```

Want to plot only some specific datasets over a period of time? 

```{r, fig.width=5, fig.asp=1}
dat <- intcal.data(20e3, 25e3)
unique(dat$set)
dat <- intcal.data(20e3, 25e3, select.sets=c(109, 120), data.cols=c(1,2))
```


It is also possible to plot the data in other `realms` such as pMC (`p`), F<sup>14</sup>C (`F`) or &Delta;<sup>14</sup>C (`d`), e.g.:

```{r, fig.width=5, fig.asp=1}
intcal.data(20e3, 25e3, realm="d")
```

## Manipulations

You can also combine calibration curves, e.g. a 40%:60% mix of Intcal20 and Marine20 with a 100+-20 year offset for the latter. If save is set to TRUE, the resulting curve will be saved with the name mixed.14C, in a folder together with the calibration curves. The name of this folder is listed, and it can be changed by specifying the option 'cc.dir'.

```{r}
mydir <- tempdir()
# new.ccdir(mydir)
mix.ccurves(0.4, cc1="IntCal20", cc2="Marine20", offset=cbind(100, 20), save=TRUE, cc.dir=mydir)
```

To glue prebomb and postbomb calibration curves into one and store it as a variable in your session (for example, IntCal20 and the NH1 postbomb curve):

```{r, fig.width=4, fig.asp=.8}
glued <- glue.ccurves("IntCal20", "NH1")
plot(glued[1:650,1:2], xlab="cal BP", ylab="C-14 BP", pch=".")
```

[^1]: Reimer et al., 2020. The IntCal20 Northern Hemisphere radiocarbon age calibration curve (0-55 cal kBP). *Radiocarbon* 62, 725-757 <http://dx.doi.org/10.1017/RDC.2020.41>

[^2]: Heaton et al., 2020. Marine20 - the marine radiocarbon age calibration curve (0-55,000 cal BP). *Radiocarbon* 62, 779-820 <http://dx.doi.org/10.1017/RDC.2020.68>

[^3]: Hogg et al., 2020. SHCal20 Southern Hemisphere calibration, 0-55,000 years cal BP. *Radiocarbon* 62, 759-778 <http://dx.doi.org/10.1017/RDC.2020.59>

[^4]: Arnold & Libby, 1951. Radiocarbon dates. *Science* 113, p. 111-120 <http://dx.doi.org/10.1126/science.113.2927.111>

[^5]: Levin & Kromer, 2004. The tropospheric 14CO2 level in mid-latitudes of the Northern Hemisphere (1959-2003), *Radiocarbon* 46, 1261-1272 <http://dx.doi.org/10.1017/S0033822200033130>

[^6]: Santos et al., 2015. Annual growth rings in a sample of Parana pine (*Araucaria angustifolia*): Toward improving the 14C calibration curve for the Southern Hemisphere. *Quaternary Geochronology* 25, 96-103 <http://dx.doi.org/10.1016/j.quageo.2014.10.004>

[^7]: Andrews et al., 2016. Bomb radiocarbon and the Hawaiian Archipelago: Coral, otoliths and seawater. *Radiocarbon* 58, 531-548 <http://dx.doi.org/10.1017/RDC.2016.32>

[^8]: Hua et al., 2021. Atmospheric radiocarbon for the period 1950-2019. *Radiocarbon* 64, 723-745 <http://dx.doi.org/10.1017/RDC.2021.95>

[^9]: Emmenegger et al., 2024. ICOS ATC 14C Release analysed by ICOS CRL from Jungfraujoch (6.0 m), 2015-09-21–2023-10-02. *ICOS RI*,
 <https://hdl.handle.net/11676/6c_RZ7NHc2dnZv7d84BMY_YY>
