Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMFW() a function to compute the "half-maximum full-width" of peaks in spectra #36

Open
4 tasks
aphalo opened this issue Nov 26, 2024 · 1 comment
Open
4 tasks
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@aphalo
Copy link
Owner

aphalo commented Nov 26, 2024

This function is rather easy to implement with existing functions. A first cut at the code for a single peak is below. This could be made an S3 method for generic_spct but probably not needed, while support for multiple peaks in a single spectrum much more important.

HMFW <-
  function(
    x,
    span = NULL,
    ignore_threshold = 0,
    strict = TRUE,
    na.rm = FALSE,
    refine.wl = FALSE,
    method = "spline",
    ...) {
    stopifnot(is.any_spct(x))
    peaks.found <- peaks(x = x,
                         ignore_threshold = ignore_threshold,
                         span = span, 
                         strict = strict,
                         na.rm = na.rm)
    if (nrow(peaks.found) == 0) {
      return(NA_real_)
    } else if (nrow(peaks.found) == 1) {
      wavelengths <- wls_at_target(x = x,
                                   target = "0.5max",
                                   interpolate = refine.wl,
                                   na.rm = na.rm)[["w.length"]]
      if (length(wavelengths) == 2) {
        return(diff(wavelengths))
      } else {
        return(NA_real_)
      }
    } else {
      message("Not implemented yet for multiple peaks")
    }
  }
  • Add function
  • Add unit tests
  • Document help page
  • Mention in User Guide
@aphalo aphalo added the enhancement New feature or request label Nov 26, 2024
@aphalo aphalo self-assigned this Nov 26, 2024
@aphalo aphalo added this to the v0.12.0 milestone Nov 26, 2024
@aphalo aphalo modified the milestones: v0.12.0, v0.12.1 Dec 6, 2024
@aphalo
Copy link
Owner Author

aphalo commented Dec 6, 2024

While wls_at_target() does the job of finding HM values these are not referenced to the nearest peaks. It could be better to make the finding of the HMFW wavelengths and widths and option in peaks() rather than creating a new function. The HMFW of a peak must be computed relative to each peak's maximum, not the global maximum as done by wls_at_target().

So this is not as simple as using the code chunk above. So, moved to a future Milestone. It has to be implemented after or at the same time as #29 and #30 are addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant