crp2a / BayLum

Chronological Bayesian models integrated for Optically Stimulated Luminescence (OSL) Dating
https://crp2a.github.io/BayLum/
GNU General Public License v3.0
9 stars 1 forks source link

Generate_DataFile_MG(): regeneration doses are off #17

Closed baumbuddy closed 3 years ago

baumbuddy commented 3 years ago

Expected behaviour

To extract the proper regen-doses to pair with LxTx values.

Observed behaviour

In my own sample all regen-doses take the value of the test dose. In the FER1 example case it varies between one or two values per aliquot.

Running mini example

library(BayLum)

# path to project folder
Path = paste0(system.file("extdata/", package = "BayLum"), "/")

# foldername of sample
FolderNames = "FER1"

# generate datafile
GD = Generate_DataFile_MG(Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1)

# check LxTx vs regeneration dose plots
LT_RegenDose(GD, Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1, SG = F)

pic1

One possible solution

Problem seems to arise when index numbers are extracted for all relevent Lx and Tx in line 246:

ind <- object@METADATA[(object@METADATA[["POSITION"]] %in% XLS_file[[2]]) & object@METADATA[["SEL"]], "ID"]

This is fixed if above is replaced with:

ind = unlist(lapply(1:J[bf], function(x) {
        object@METADATA[(object@METADATA[["POSITION"]] %in% XLS_file[[x,2]]) & object@METADATA[["SEL"]], "ID"]
      }))

My solution also requires a change to lines 303-307, which should be replaced with:

      ITemps = matrix(data = NA, nrow = J[bf], ncol = K[bf])
      for (j in 1:J[bf]) {  
        first = (j-1)*Nb_measurement+1
        last = first+Nb_measurement-1
        index = ind[first[bf]:last[bf]]
        index = index[c(TRUE,FALSE)]
        index = index[(1:K[bf]+1)]
        ITemps[j, ] = object@METADATA[index, "IRR_TIME"]
      }

Now we get:

# generate datafile
GD = Generate_DataFile_MG(Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1)

# check LxTx vs regeneration dose plots
LT_RegenDose(GD, Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1, SG = F)

Rplot2

But I haven't done a lot to check how this may break compatibility for other setups.

RLumSK commented 3 years ago

Dear @IMHarly: Would you mind double-checking whether this problem still occurs in the development version of BayLum you can download directly here from GitHub? I had in mind that I had fixed this already: https://github.com/crp2a/BayLum/blob/master/NEWS.md with commit 618f83e99f41bb207edd62c14acd9285bbe18966.

baumbuddy commented 3 years ago

@RLumSK : Problem solved. And you didn't even have to do anything.

RLumSK commented 3 years ago

@IMHarly: Great, but just for the record: Was it related to the fix or a completely different problem on your end? Because the problem I had corrected before was real and happened for all measurements with option run 1 at one time.

baumbuddy commented 3 years ago

@RLumSK It was related to the fix. My sample is indeed run 1 at a time.

RLumSK commented 3 years ago

@IMHarly: Great and thanks!