From f06aadf8180e48ac5ecf6f7fc25fedebe0713b3d Mon Sep 17 00:00:00 2001 From: RLumSK Date: Sat, 14 Sep 2024 13:06:58 +0200 Subject: [PATCH] plot_RLum.Data.Spectrum() + ad support for light arguments + fx cause of index warning + ad NEWS + up docu --- NEWS.Rmd | 142 +------------------------ NEWS.md | 187 +-------------------------------- R/plot_RLum.Data.Spectrum.R | 46 ++++---- man/plot_RLum.Data.Spectrum.Rd | 11 +- 4 files changed, 34 insertions(+), 352 deletions(-) diff --git a/NEWS.Rmd b/NEWS.Rmd index a64c70785..2d029749c 100644 --- a/NEWS.Rmd +++ b/NEWS.Rmd @@ -13,147 +13,11 @@ header-includes: ## Bugfixes - -## Internals - - - -# Changes in version 0.9.25 (2024-09-12) - -**This package version requires R >= 4.3** - -## New functions -* `read_HeliosOSL2R()`: New import function to support the new zero rad Helios luminescence reader -and its `.osl` file format. The output is an `RLum.Analysis-class` object. - -## Bugfixes - -### `analyse_baSAR()` -* Fix #183 addressing an edge-case crash when the function was called on -an object containing no records of the appropriate type (#184, @mcol). - -### `analyse_FadingMeasurements()` -* Add `...` support to disable the blue trend line via `plot.trend = FALSE` -* Fix #175 to deal gracefully with the case when the size of Lx and Tx -doesn't match (#192, @mcol). - -### `analyse_portableOSL()` -* Function did not respect argument `main`; fixed. - -### `convert_Wavelength2Energy()` -* Fix #133 addressing cases where R throws an uncontained error when R drops -the object structure in very rare cases (#134; thanks @mcol) - -### `calc_Huntley2006()` -* Improve success rate of GOK fitting of the unfaded data using a two step approach: first -an exponential fit is applied then this values are used as start parameters. - -### `calc_Statistics()` -* The skewness and kurtosis depended on number of MC samples (#122); fixed with #123 (thanks to @mcol) - -### `calc_TLLxTxRatio()` -* Function crashed for `Tx.data.background = NULL` (#129); fixed with #130 thanks to @mcol - -### `calc_WodaFuchs2008()` -* The function now officially supports numeric vectors and single-column -data frames as input (#200). -* The function computed the number of breaks for the histogram incorrectly -(#197, fixed with #198). -* The function now supports more types of `RLum.Results` objects without -crashing, although if the object contains only one data point it will stop -immediately to avoid problems with `nls()` (#199, fixed in #219). - -### `extract_IrradiationTimes()` -* If a BIN/BINX-file is provided, the function will now check that it contains the -same amount of data as the corresponding XSYG file a bit earlier than before, -thus avoiding a possible crash (#228, fixed in #229). - -### `fit_CWCurve()` -* Argument `output.path` has been removed, and a warning is raised when -attempting to use it (#207, fixed in #209). - -### `fit_EmissionSpectra()` -* Parameter `input_scale` was not correctly propagated when the function would -self-call (#160, @mcol). - -### `fit_OSLLifeTimes()` -* The validation of the minimum dataset size didn't account for the use of -the `signal.range` argument (#182, fixed by #195, @mcol). - -### `fit_SurfaceExposure()` -* Fix #162 to remove a dimension mismatch if the input data contained `NA`s, -which would generate unexpected warnings (#163, @mcol). -* The function doesn't stop anymore with an error if called on an -`RLum.Results` object (#165, @mcol). - -### `plot_AbanicoPlot()` -* Argument `plot.ratio` will now throw an error on non-positive numerical -values (#221, fixed in #222). -* The function doesn't crash anymore when setting `interactive = TRUE` (#220, -fixed in #233). - -### `plot_DetPlot()` -* Argument `signal.integral.max` is now enforced to be greater than -`signal.integral.min`, as otherwise the computation of the number of channels -would produce `Inf` (#203, fixed in #206). -* Fix a crash when using option `analyse_function = "analyse_pIRIRSequence"` -(#210, fixed in #211). - -### `plot_GrowthCurve()` -* The function now calculates the relative saturation (`n/N`) using the ratio -of the two integrates. The value is part of the output table. -* Argument `na.rm` has been removed: as of version 0.9.23, it was defunct -and only accepted `TRUE` as valid value and produced an error otherwise, -so there is no effective change in behaviour (#137, fixed in #214). - -### `plot_Histogram()` -* The function doesn't crash anymore when setting `interactive = TRUE` (#186, -fixed in #231). - -### `plot_KDE()` -* It now officially supports numeric vectors and single-column data frames, -for which it assumes that the De error at each measurement is 10^-9 (#189, -fixed in #194, @mcol). - -### `plot_NRt()` -* The function reports an helpful message rather than crashing when applied -to an object of unexpected type or when there is a mismatch in time values -(#177, fixed with #179 by @mcol). - -### `plot_RadialPlot()` -* The function doesn't crash anymore when a single-column data frame is -provided (#191, fixed in #212). - -### `plot_RLum.Data.Analysis()` -* The function now supports all arguments from `plot_RLum.Data.Spectrum()`; before it -had only basic functionality for `RLum.Data.Spectrum-class` data. - ### `plot_RLum.Data.Spectrum()` -* The plot function can now handle non-increasing column values for plotting (with a warning). +* Add support for `lphi` and `ltheta` light direction arguments for `plot.type = "persp"`. +* Fix the reason for the unclear warning `In col.unique == col : longer object length is not a multiple of shorter object length` -### `read_BIN2R()` -* `ignore.RECTYPE` now supports numeric values, e.g., 128. Records for this type -will be ignored during import. -* BINX-files with `RECTYPE = 128` will not crash anymore, thanks for asking Anna-Maartje Boer and replying Karsten Bracht. -* The function now stops graciously when attempting to read an empty file -(#225, fixed in #226). - -### `read_PSL2R()` -* The function is out of the beta status, hence the flag was removed. -* The `RLum.Analysis-class` object returned by the function gained a new element `Sequence`, which is a data frame. -with the measured sequence. This way, if the original sequence was lost, it can still be extracted from the `.psl` data. -* If no `.psl` file was found the function got trapped in an infinite loop (#127); fixed with #128 (thanks to @mcol) - -### `read_XSYG2R()` -* Fix spectrometer data import for basically broken files. +## Internals -### `read_Daybreak2R()` -* Fix #135 to improve detection of non-ASCII files (#140, @mcol). -### `Risoe.BINfileData2RLum.Analysis()` -* Fix a crash when reading an empty Risoe.BINfileData input (#215, fixed in -#224). -## Internals -* New internal function + tests added `.get_named_list_element()`. It just does what -the names says. diff --git a/NEWS.md b/NEWS.md index 802381e63..ee2194533 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,194 +5,17 @@ -# Changes in version 0.9.25.9000 (2024-09-13) +# Changes in version 0.9.25.9000 (2024-09-14) ## New functions ## Bugfixes -## Internals - -# Changes in version 0.9.25 (2024-09-12) - -**This package version requires R \>= 4.3** - -## New functions - -- `read_HeliosOSL2R()`: New import function to support the new zero rad - Helios luminescence reader and its `.osl` file format. The output is - an `RLum.Analysis-class` object. - -## Bugfixes - -### `analyse_baSAR()` - -- Fix \#183 addressing an edge-case crash when the function was called - on an object containing no records of the appropriate type (#184, - @mcol). - -### `analyse_FadingMeasurements()` - -- Add `...` support to disable the blue trend line via - `plot.trend = FALSE` -- Fix \#175 to deal gracefully with the case when the size of Lx and Tx - doesn’t match (#192, @mcol). - -### `analyse_portableOSL()` - -- Function did not respect argument `main`; fixed. - -### `convert_Wavelength2Energy()` - -- Fix \#133 addressing cases where R throws an uncontained error when R - drops the object structure in very rare cases (#134; thanks @mcol) - -### `calc_Huntley2006()` - -- Improve success rate of GOK fitting of the unfaded data using a two - step approach: first an exponential fit is applied then this values - are used as start parameters. - -### `calc_Statistics()` - -- The skewness and kurtosis depended on number of MC samples (#122); - fixed with \#123 (thanks to @mcol) - -### `calc_TLLxTxRatio()` - -- Function crashed for `Tx.data.background = NULL` (#129); fixed with - \#130 thanks to @mcol - -### `calc_WodaFuchs2008()` - -- The function now officially supports numeric vectors and single-column - data frames as input (#200). -- The function computed the number of breaks for the histogram - incorrectly (#197, fixed with \#198). -- The function now supports more types of `RLum.Results` objects without - crashing, although if the object contains only one data point it will - stop immediately to avoid problems with `nls()` (#199, fixed in - \#219). - -### `extract_IrradiationTimes()` - -- If a BIN/BINX-file is provided, the function will now check that it - contains the same amount of data as the corresponding XSYG file a bit - earlier than before, thus avoiding a possible crash (#228, fixed in - \#229). - -### `fit_CWCurve()` - -- Argument `output.path` has been removed, and a warning is raised when - attempting to use it (#207, fixed in \#209). - -### `fit_EmissionSpectra()` - -- Parameter `input_scale` was not correctly propagated when the function - would self-call (#160, @mcol). - -### `fit_OSLLifeTimes()` - -- The validation of the minimum dataset size didn’t account for the use - of the `signal.range` argument (#182, fixed by \#195, @mcol). - -### `fit_SurfaceExposure()` - -- Fix \#162 to remove a dimension mismatch if the input data contained - `NA`s, which would generate unexpected warnings (#163, @mcol). -- The function doesn’t stop anymore with an error if called on an - `RLum.Results` object (#165, @mcol). - -### `plot_AbanicoPlot()` - -- Argument `plot.ratio` will now throw an error on non-positive - numerical values (#221, fixed in \#222). -- The function doesn’t crash anymore when setting `interactive = TRUE` - (#220, fixed in \#233). - -### `plot_DetPlot()` - -- Argument `signal.integral.max` is now enforced to be greater than - `signal.integral.min`, as otherwise the computation of the number of - channels would produce `Inf` (#203, fixed in \#206). -- Fix a crash when using option - `analyse_function = "analyse_pIRIRSequence"` (#210, fixed in \#211). - -### `plot_GrowthCurve()` - -- The function now calculates the relative saturation (`n/N`) using the - ratio of the two integrates. The value is part of the output table. -- Argument `na.rm` has been removed: as of version 0.9.23, it was - defunct and only accepted `TRUE` as valid value and produced an error - otherwise, so there is no effective change in behaviour (#137, fixed - in \#214). - -### `plot_Histogram()` - -- The function doesn’t crash anymore when setting `interactive = TRUE` - (#186, fixed in \#231). - -### `plot_KDE()` - -- It now officially supports numeric vectors and single-column data - frames, for which it assumes that the De error at each measurement is - 10^-9 (#189, fixed in \#194, @mcol). - -### `plot_NRt()` - -- The function reports an helpful message rather than crashing when - applied to an object of unexpected type or when there is a mismatch in - time values (#177, fixed with \#179 by @mcol). - -### `plot_RadialPlot()` - -- The function doesn’t crash anymore when a single-column data frame is - provided (#191, fixed in \#212). - -### `plot_RLum.Data.Analysis()` - -- The function now supports all arguments from - `plot_RLum.Data.Spectrum()`; before it had only basic functionality - for `RLum.Data.Spectrum-class` data. - ### `plot_RLum.Data.Spectrum()` -- The plot function can now handle non-increasing column values for - plotting (with a warning). - -### `read_BIN2R()` - -- `ignore.RECTYPE` now supports numeric values, e.g., 128. Records for - this type will be ignored during import. -- BINX-files with `RECTYPE = 128` will not crash anymore, thanks for - asking Anna-Maartje Boer and replying Karsten Bracht. -- The function now stops graciously when attempting to read an empty - file (#225, fixed in \#226). - -### `read_PSL2R()` - -- The function is out of the beta status, hence the flag was removed. -- The `RLum.Analysis-class` object returned by the function gained a new - element `Sequence`, which is a data frame. with the measured sequence. - This way, if the original sequence was lost, it can still be extracted - from the `.psl` data. -- If no `.psl` file was found the function got trapped in an infinite - loop (#127); fixed with \#128 (thanks to @mcol) - -### `read_XSYG2R()` - -- Fix spectrometer data import for basically broken files. - -### `read_Daybreak2R()` - -- Fix \#135 to improve detection of non-ASCII files (#140, @mcol). - -### `Risoe.BINfileData2RLum.Analysis()` - -- Fix a crash when reading an empty Risoe.BINfileData input (#215, fixed - in \#224). +- Add support for `lphi` and `ltheta` light direction arguments for + `plot.type = "persp"`. +- Fix the reason for the unclear warning + `In col.unique == col : longer object length is not a multiple of shorter object length` ## Internals - -- New internal function + tests added `.get_named_list_element()`. It - just does what the names says. diff --git a/R/plot_RLum.Data.Spectrum.R b/R/plot_RLum.Data.Spectrum.R index 297eabf26..cfefe01b6 100644 --- a/R/plot_RLum.Data.Spectrum.R +++ b/R/plot_RLum.Data.Spectrum.R @@ -32,6 +32,8 @@ #' - `shade`: default is `0.4` #' - `phi`: default is `15` #' - `theta`: default is `-30` +#' - `lphi`: default is `15` +#' - `ltheta`: default is `-30` #' - `expand`: default is `1` #' - `axes`: default is `TRUE` #' - `box`: default is `TRUE`; accepts `"alternate"` for a custom plot design @@ -56,7 +58,7 @@ #'-`frames`: pick the frames to be plotted (depends on the binning!). Check without #' this setting before plotting. #' -#' '**`plot.type = "image"` or `plot.type = "contour" ** +#'**`plot.type = "image"` or `plot.type = "contour"`** #' #' These plot types use the R functions [graphics::image] or [graphics::contour]. #' The advantage is that many plots can be arranged conveniently using standard @@ -158,7 +160,7 @@ #' #' @note Not all additional arguments (`...`) will be passed similarly! #' -#' @section Function version: 0.6.8 +#' @section Function version: 0.6.9 #' #' @author #' Sebastian Kreutzer, Institute of Geography, Heidelberg University (Germany) @@ -346,6 +348,12 @@ plot_RLum.Data.Spectrum <- function( theta <- if("theta" %in% names(extraArgs)) {extraArgs$theta} else {-30} + lphi <- if("lphi" %in% names(extraArgs)) {extraArgs$lphi} else + {15} + + ltheta <- if("ltheta" %in% names(extraArgs)) {extraArgs$ltheta} else + {-30} + r <- if("r" %in% names(extraArgs)) {extraArgs$r} else {10} @@ -570,7 +578,6 @@ plot_RLum.Data.Spectrum <- function( #set colour palette col <- unlist(sapply(1:length(x), function(i){ - if(x[i] >= col.violet[1] & x[i] < col.violet[2]){"#EE82EE"} else if(x[i] >= col.blue[1] & x[i] < col.blue[2]){"#0000FF"} else if(x[i] >= col.green[1] & x[i] < col.green[2]){"#00FF00"} @@ -592,8 +599,7 @@ plot_RLum.Data.Spectrum <- function( c(790, ifelse(max(xlim) >= 800, max(xlim), 800)) #set colour palette - col <- unlist(sapply(1:length(x), function(i){ - + col <- unlist(lapply(1:length(x), function(i){ if(x[i] >= col.violet[1] & x[i] < col.violet[2]){"#EE82EE"} else if(x[i] >= col.blue[1] & x[i] < col.blue[2]){"#0000FF"} else if(x[i] >= col.green[1] & x[i] < col.green[2]){"#00FF00"} @@ -610,39 +616,30 @@ plot_RLum.Data.Spectrum <- function( ##if only one colour value, then skip gradient calculation as it causes ##an error if(length(col.unique) > 1){ - ##set colour function for replacement colfunc <- colorRampPalette(col.unique) ##get index for colour values to be cut from the current palette - col.unique.index <- - vapply(col.unique, function(i) { - max(which(col == i)) - - }, numeric(1)) + col.unique.index <- vapply(col.unique, function(i) which.max(col == i), numeric(1)) ##remove last index (no colour gradient needed), for energy axis use the first value col.unique.index <- col.unique.index[-length(col.unique.index)] ##set borders for colour gradient recalculation - col.unique.index.min <- col.unique.index - (50/bin.rows) - col.unique.index.max <- col.unique.index + (50/bin.rows) + col.unique.index.min <- floor(col.unique.index - (50/bin.rows)) + col.unique.index.max <- ceiling(col.unique.index + (50/bin.rows)) ##set negative values to the lowest index col.unique.index.min[col.unique.index.min<=0] <- 1 ##build up new index sequence (might be better) - col.gradient.index <- as.vector(unlist(( - sapply(1:length(col.unique.index.min), function(j){ - + col.gradient.index <- unlist(lapply(seq_along(col.unique.index.min), function(j){ seq(col.unique.index.min[j],col.unique.index.max[j], by = 1) - })))) - + })) ##generate colour ramp and replace values - col.new <- colfunc(length(col.gradient.index)) - col[col.gradient.index] <- col.new + col[col.gradient.index] <- colfunc(length(col.gradient.index)) ##correct for overcharged colour values (causes zebra colour pattern) if (diff(c(length(col), nrow(temp.xyz))) < 0) { @@ -663,13 +660,13 @@ plot_RLum.Data.Spectrum <- function( # Do log scaling if needed ------------------------------------------------- ##x - if(grepl("x", log)==TRUE){x <- log10(x)} + if(grepl("x", log)[1]) x <- log10(x) ##y - if(grepl("y", log)==TRUE){y <- log10(y)} + if(grepl("y", log)[1]) y <- log10(y) ##z - if(grepl("z", log)==TRUE){temp.xyz <- log10(temp.xyz)} + if(grepl("z", log)[1]) temp.xyz <- log10(temp.xyz) # PLOT -------------------------------------------------------------------- @@ -703,6 +700,8 @@ if(plot){ axes = if(box[1] == "alternate") FALSE else axes, phi = phi, theta = theta, + ltheta = ltheta, + lphi = lphi, xlab = xlab, ylab = ylab, zlab = zlab, @@ -1123,7 +1122,6 @@ if(plot){ } # Return ------------------------------------------------------------------ - ## add some attributes attr(temp.xyz, "colour") <- col attr(temp.xyz, "pmat") <- pmat diff --git a/man/plot_RLum.Data.Spectrum.Rd b/man/plot_RLum.Data.Spectrum.Rd index 26b7cdc16..0f61536c8 100644 --- a/man/plot_RLum.Data.Spectrum.Rd +++ b/man/plot_RLum.Data.Spectrum.Rd @@ -135,6 +135,8 @@ Arguments that will be passed to \link[graphics:persp]{graphics::persp}: \item \code{shade}: default is \code{0.4} \item \code{phi}: default is \code{15} \item \code{theta}: default is \code{-30} +\item \code{lphi}: default is \code{15} +\item \code{ltheta}: default is \code{-30} \item \code{expand}: default is \code{1} \item \code{axes}: default is \code{TRUE} \item \code{box}: default is \code{TRUE}; accepts \code{"alternate"} for a custom plot design @@ -160,7 +162,7 @@ All frames plotted in one frame. -\code{frames}: pick the frames to be plotted (depends on the binning!). Check without this setting before plotting. -'**\code{plot.type = "image"} or `plot.type = "contour" ** +\strong{\code{plot.type = "image"} or \code{plot.type = "contour"}} These plot types use the R functions \link[graphics:image]{graphics::image} or \link[graphics:contour]{graphics::contour}. The advantage is that many plots can be arranged conveniently using standard @@ -188,7 +190,7 @@ summed up. To select a transect use the \code{xlim} argument, e.g. Not all additional arguments (\code{...}) will be passed similarly! } \section{Function version}{ - 0.6.8 + 0.6.9 } \examples{ @@ -261,10 +263,5 @@ plot_RLum.Data.Spectrum( } \author{ Sebastian Kreutzer, Institute of Geography, Heidelberg University (Germany) -, RLum Developer Team} - -\section{How to cite}{ -Kreutzer, S., 2024. plot_RLum.Data.Spectrum(): Plot function for an RLum.Data.Spectrum S4 class object. Function version 0.6.8. In: Kreutzer, S., Burow, C., Dietze, M., Fuchs, M.C., Schmidt, C., Fischer, M., Friedrich, J., Mercier, N., Philippe, A., Riedesel, S., Autzen, M., Mittelstrass, D., Gray, H.J., Galharret, J., Colombo, M., 2024. Luminescence: Comprehensive Luminescence Dating Data Analysis. R package version 0.9.25. https://r-lum.github.io/Luminescence/ } - \keyword{aplot}