Code Monkey home page Code Monkey logo

gamma's Introduction

gamma

R-CMD-check codecov

r-universe CRAN Version CRAN checks CRAN Downloads

Project Status: Active – The project has reached a stable, usable state and is being actively developed.

DOI CRAN DOI

SWH

Overview

gamma is intended to process in-situ gamma-ray spectrometry measurements for luminescence dating. This package allows to import, inspect and (automatically) correct the energy scale of the spectrum. It provides methods for estimating the gamma dose rate by the use of a calibration curve. This package only supports Canberra CNF and TKA files.

The gammaShiny package provides an enhanced graphical user interface for the main applications of gamma.

To cite gamma in publications use:

  Lebrun B, Frerebeau N, Paradol G, Guérin G, Mercier N, Tribolo C,
  Lahaye C, Rizza M (2020). "gamma: An R Package for Dose Rate
  Estimation from In-Situ Gamma-Ray Spectrometry Measurements."
  _Ancient TL_, *38*(2), 1-5.

  Frerebeau N, Lebrun B, Paradol G, Kreutzer S (2024). _gamma: Dose
  Rate Estimation from in-Situ Gamma-Ray Spectrometry_. Université
  Bordeaux Montaigne, Pessac, France. doi:10.32614/CRAN.package.gamma
  <https://doi.org/10.32614/CRAN.package.gamma>, R package version
  1.0.5.9000.

Installation

You can install the released version of gamma from CRAN with:

install.packages("gamma")

And the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("crp2a/gamma")

Usage

## A minimal example
library(gamma)

## Find the full path to the spectrum file
spc_file <- system.file("extdata/LaBr.CNF", package = "gamma")
## Import the spectrum
spectrum <- read(spc_file)

## Set the expected channel/energy peaks for the energy scale calibration
## Spectrum pre-processing and peak detection
peaks <- spectrum |>
  signal_slice() |>
  signal_stabilize(f = sqrt) |>
  signal_smooth(method = "savitzky", m = 21) |>
  signal_correct(method = "SNIP", n = 100) |>
  peaks_find()

## Set the energy values (in keV)
set_energy(peaks) <- c(238, NA, NA, NA, 1461, NA, NA, 2615)

## Calibrate the energy scale
calib <- energy_calibrate(spectrum, peaks)

## Inspect peaks
plot(calib, peaks)

## Estimate the gamma dose rate of a set of spectra
## You may want to give extra attention to the energy calibration step
spc_file <- system.file("extdata/BDX_LaBr_1/test", package = "gamma")
spectra <- read(spc_file)

## Load the calibration curve for the dose rate estimation
## As this curve is instrument specific, you will have to build your own
## See help(fit_dose)
data("BDX_LaBr_1", package = "gamma")
plot(BDX_LaBr_1)

## Estimate the gamma dose rate
(doses <- dose_predict(BDX_LaBr_1, spectra))
name signal_Ni signal_err_Ni dose_Ni dose_err_Ni signal_NiEi signal_err_NiEi dose_NiEi dose_err_NiEi dose_final dose_err_final
20110523204008 8.604666 0.2691316 252.2866 10.372500 7626.493 8.747617 220.6747 5.495079 236.4806 11.366900
20110523210008 8.775092 0.2166075 257.3316 9.354274 7577.302 7.021326 219.1303 5.454610 238.2309 10.495729
20110527205316 8.445976 0.1546491 247.5890 8.012680 7064.449 5.009961 203.0288 5.052359 225.3089 9.198048
20130809172451 30.218479 0.2549754 892.1003 24.967288 27667.473 8.089989 849.8817 21.142124 870.9910 32.614162
20130813181639 36.062314 0.2853286 1065.0899 29.644785 33243.050 9.028097 1024.9325 25.496544 1045.0112 39.010062
20160717175757 19.190250 0.3635398 565.6418 18.510895 16419.873 11.495584 496.7518 12.361511 531.1968 21.838611
20160717181052 16.303659 0.2837191 480.1928 15.297869 14033.831 9.033011 421.8396 10.496701 451.0162 18.231817
20160717182601 16.896441 0.2557337 497.7403 15.269850 14493.495 8.131459 436.2712 10.854933 467.0058 18.446627

Contributing

Please note that the gamma project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Acknowledgements

This work received a state financial support managed by the Agence Nationale de la Recherche (France) through the program Investissements d’avenir (ref. 10-LABX-0052 and 11-IDEX-0001).

gamma's People

Contributors

nfrerebeau avatar rlumsk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gamma's Issues

plot not produced

Describe the bug
When exporting a plot from the "import" tab, the folowing error message is displayed, with no plot produced

Warning: Error in ggsave: impossible de trouver la fonction "ggsave"
  [No stack trace available]

Export graph in "energy calibration tab"

Is your feature request related to a problem? Please describe.
It is not possible to export graph on the "energy calibration" tab

Describe the solution you'd like
A button to be able to export the graph.

Describe alternatives you've considered
A screenshot is a terrible alternative ^^

Possibility to energy-calibrate more than one spectrum at a time

At the moment, when trying to energy-calibrate multiple spectra at a time (formal class "GammaSpetra") using the function energy_calibrate(), one receives the following error message:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘energy_calibrate’ for signature ‘"GammaSpectra", "PeakPosition"

Is it possible to enable this functionality?
Thank you!

Enhancement of the export plot option

It would be really cool to have a "publication-ready" plot export option. I mean by that a standardized export of plot with the following pre-defined settings :

  1. A more exploitable (and fixed) plot size.
  2. A relevant font size (8pt ?).

Enhancement of the import section

In order to improve the user experience here are some feature request for this section :

  • change tab section to : " 1 - file import"
  • allow user to display one or more spectra on the plot (tick box ?)

"Select a calibration curve" improvement

To prevent users from forgetting to select the relevant calibration curve, it would be desirable that no calibration curve be selected by default.
This would force the user to knowingly select the correct curve so that the dose rate table does not remain empty.

Enhancement of the zoom function

Is your feature request related to a problem? Please describe.
There is actually no way to know that we can perform zoom on the plot of the energy calibration tab, moreover, once we have zoomed, there is no way to go back to the full view (or it is so unnatural that I was not able to find how to do it).

Describe the solution you'd like
Change the cursor to a magnifying glass when hoovering the plot, and put a "reset zoom" button

Export table

Is your feature request related to a problem? Please describe.
A table is displayed in the Shiny interface, tab "import", but it is not possible to export it

Describe the solution you'd like
A button allowing us to export this table as a .csv file

Add zoom ability to plot of the import tab

Is your feature request related to a problem? Please describe.
There is no possibility to zoomon the plot of the import tab

Describe the solution you'd like
Add the same zoom function on this tab as in the energy calibration tab

"geom_pointrange" function not found

Describe the bug
No plot is produced in the dose rate estimation tab. Instead, thie message is displayed : "Error: impossible to find the function "geom_pointrange"

Screenshots
Capture d’écran 2019-11-14 à 16 43 26

Enhancement of the Dose rate section

In order to improve the user experience here are some feature request for this section :

  • Change tab name to : "3 - Dose rate calculation"
  • add measurement time value in the table
  • add the ability display only selected samples in the table
  • add the ability to control the number of significant digits displayed
  • add the ability to export the results as .xls

Peak position of expected peaks not shown.

Describe the bug

The plot method for the PeakPosition-class seems to always just return the observed peak positions and not the expected peak positions. This might be correct, but then I would expect that the calibration is applied automatically when plotting. This is not the case. We can use the vignette example to reproduce the issue:

To Reproduce

library(gamma)

tka_test <- system.file("extdata/LaBr.TKA", package = "gamma")
spc_tka <- read(tka_test)

pks <- spc_tka |>
  signal_slice() |>
  signal_stabilize(f = sqrt) |>
  signal_smooth(method = "savitzky", m = 21) |>
  signal_correct(method = "SNIP", decreasing = TRUE, n = 100) |>
  peaks_find()

# Set the energy values (in keV)
set_energy(pks) <- c(238, NA, NA, NA, 1461, NA, NA, 2615)

# Calibrate the energy scale
cal <- energy_calibrate(spc_tka, pks)

# Plot spectrum
plot(cal, pks)

image

Expected behavior

I would expect that after the peaks are known, the energy peaks are shown correctly:

# Plot spectrum
plot(cal, pks)

image

Additional context

Personally I think that this line:

gamma/R/plot.R

Line 122 in 33e0d9e

peak_energy <- pks$energy_observed

Should be modified to:

peak_energy <- if (all(is.na(pks$energy_expected))) pks$energy_observed else pks$energy_expected

This obviously depends on the wanted behaviour, which is not entirely clear to me. I can generate a PR if needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.