ISAAKiel / oxcAAR

R Package - Interaction with Oxcal
GNU General Public License v2.0
21 stars 4 forks source link

Loss of information when transforming to rcarbon caldate #37

Open MartinHinz opened 3 years ago

MartinHinz commented 3 years ago

Remarks of @nevrome regarding PR ggplot branch, should be considered before merging rcarbon-sync-branch

Not sure if this is perfectly clean.

> my_uncal_dates <- data.frame(bp=c(5000,4500,4000),
                             std=c(45,35,25),
                             names=c("Date 1", "Date 2", "Date 3")
                             )
> my_cal_dates <- oxcalCalibrate(my_uncal_dates$bp, my_uncal_dates$std, my_uncal_dates$names)
> as.CalDates(my_cal_dates) %>% str()
List of 3
 $ metadata :'data.frame':    3 obs. of  11 variables:
  ..$ DateID    : chr [1:3] "Date 1" "Date 2" "Date 3"
  ..$ CRA       : num [1:3] 5000 4500 4000
  ..$ Error     : num [1:3] 45 35 25
  ..$ Details   : logi [1:3] NA NA NA
  ..$ CalCurve  : chr [1:3] "data" "data" "data"
  ..$ ResOffsets: logi [1:3] NA NA NA
  ..$ ResErrors : logi [1:3] NA NA NA
  ..$ StartBP   : logi [1:3] NA NA NA
  ..$ EndBP     : logi [1:3] NA NA NA
  ..$ Normalised: logi [1:3] TRUE TRUE TRUE
  ..$ CalEPS    : num [1:3] 0 0 0
 $ grids    :List of 3
  ..$ Date 1:Classes ‘calGrid’ and 'data.frame':  545 obs. of  2 variables:
  .. ..$ calBP : num [1:545] 6009 6008 6007 6006 6005 ...
  .. ..$ PrDens: num [1:545] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ Date 2:Classes ‘calGrid’ and 'data.frame':  635 obs. of  2 variables:
  .. ..$ calBP : num [1:635] 5474 5473 5472 5471 5470 ...
  .. ..$ PrDens: num [1:635] 0 0 0 0 0 ...
  ..$ Date 3:Classes ‘calGrid’ and 'data.frame':  585 obs. of  2 variables:
  .. ..$ calBP : num [1:585] 4814 4813 4812 4811 4810 ...
  .. ..$ PrDens: num [1:585] 0 0 0 0 0 ...
 $ calmatrix: logi NA
 - attr(*, "class")= chr [1:2] "CalDates" "list"
> rcarbon::calibrate(c(5000,4500,4000), errors=c(45,35,25)) %>% str()
[1] "Calibrating radiocarbon ages..."
  |=====================================================================================================| 100%
[1] "Done."
List of 3
 $ metadata :'data.frame':    3 obs. of  12 variables:
  ..$ DateID    : chr [1:3] "1" "2" "3"
  ..$ CRA       : num [1:3] 5000 4500 4000
  ..$ Error     : num [1:3] 45 35 25
  ..$ Details   : logi [1:3] NA NA NA
  ..$ CalCurve  : chr [1:3] "intcal20" "intcal20" "intcal20"
  ..$ ResOffsets: num [1:3] 0 0 0
  ..$ ResErrors : num [1:3] 0 0 0
  ..$ StartBP   : num [1:3] 55000 55000 55000
  ..$ EndBP     : num [1:3] 0 0 0
  ..$ Normalised: logi [1:3] TRUE TRUE TRUE
  ..$ F14C      : logi [1:3] FALSE FALSE FALSE
  ..$ CalEPS    : num [1:3] 1e-05 1e-05 1e-05
 $ grids    :List of 3
  ..$ 1:Classes ‘calGrid’ and 'data.frame':   336 obs. of  2 variables:
  .. ..$ calBP : num [1:336] 5922 5921 5920 5919 5918 ...
  .. ..$ PrDens: num [1:336] 1.11e-05 1.29e-05 1.49e-05 1.77e-05 2.10e-05 ...
  ..$ 2:Classes ‘calGrid’ and 'data.frame':   443 obs. of  2 variables:
  .. ..$ calBP : num [1:443] 5432 5431 5430 5429 5428 ...
  .. ..$ PrDens: num [1:443] 1.10e-05 1.27e-05 1.47e-05 1.42e-05 1.37e-05 ...
  ..$ 3:Classes ‘calGrid’ and 'data.frame':   270 obs. of  2 variables:
  .. ..$ calBP : num [1:270] 4611 4610 4609 4608 4607 ...
  .. ..$ PrDens: num [1:270] 1.19e-05 1.35e-05 1.91e-05 2.14e-05 2.14e-05 ...
 $ calmatrix: logi NA
 - attr(*, "class")= chr [1:2] "CalDates" "list"

There is some factual loss of information, e.g. in the CalCurve field.

MartinHinz commented 3 years ago

also:

lapply(lapply(lapply(lapply(lapply - really? There must be a better readable way to express this!

joeroe commented 3 years ago

@MartinHinz A while back I added some functions to stratigraphr for converting between rcarbon::CalDatesoxcAAR::oxcAARCalibratedDateBchron::BchronCalibratedDates and my own vctrs-based class, which I've now decided would make more sense as a standalone package. They include a rough draft of a framework for translating the various metadata formats each use, which perhaps could be helpful as a basis for solving this issue?