assess_spec() scans spectra for common quality-control issues and
returns one row for each issue found.
Usage
assess_spec(x, ...)
# Default S3 method
assess_spec(x, ...)
# S3 method for class 'OpenSpecy'
assess_spec(
x,
checks = c("high_tail", "silent_region", "co2_region", "missing_values",
"flat_spectrum", "negative_intensity", "low_snr"),
high_prob = 0.9,
artifact_ratio = 2,
tail_n = 5L,
silent_region = c(2420, 2550),
co2_region = c(2200, 2420),
snr_threshold = 4,
flat_tol = sqrt(.Machine$double.eps),
negative_tol = 0,
na.rm = TRUE,
report = c("issues", "all"),
snr_metric = "run_sig_over_noise",
spike_args = list(),
saturation = "auto",
saturation_min_run = NULL,
saturation_tolerance = sqrt(.Machine$double.eps),
...
)Arguments
- x
an
OpenSpecyobject.- checks
character; checks to run. Options include
"high_tail","silent_region","co2_region","missing_values","flat_spectrum","negative_intensity","low_snr","spike", and"saturation". Spike and saturation checks are opt-in.- high_prob
numeric; spectrum-wide quantile used as the high intensity threshold for the silent-region check.
- artifact_ratio
numeric; minimum ratio between the normalized maximum in a tail or carbon dioxide region and the normalized maximum outside both artifact regions required to flag an issue. The default
2flags a candidate at or above twice the control-region maximum.- tail_n
integer; number of points to check at each end of the spectrum.
- silent_region
numeric length two; wavenumber range expected to be mostly silent. The default is
c(2420, 2550)cm^-1.- co2_region
numeric length two; carbon dioxide wavenumber range.
- snr_threshold
numeric; spectra with run signal-to-noise below this value are flagged.
- flat_tol
numeric; maximum finite intensity range considered flat.
- negative_tol
numeric; minimum allowed intensity before a spectrum is flagged as negative.
- na.rm
logical; indicating whether missing values should be removed when calculating thresholds and metrics.
- report
character;
"issues"preserves the issue-only return contract, while"all"returns an explicit pass, warning, or error row for every requested check and spectrum.- snr_metric
character; signal-to-noise metric passed to
sig_noise()for the"low_snr"check.- spike_args
named list of arguments passed to the shared internal spike detector when
"spike"is requested.- saturation
"auto"or one finite numeric detector ceiling used by the"saturation"check.- saturation_min_run
integer or
NULL; minimum saturated run used by the shared detector.- saturation_tolerance
numeric; relative equality tolerance for automatic detector plateaus.
- ...
further arguments passed to
sig_noise()for the"low_snr"check.
Value
With report = "issues", a
data.table-class() with one row per issue found
and columns describing the spectrum, check, issue, likely cause, potential
fix, metric value, threshold, and region. If no issues are found, an empty
table with the same columns is returned. With report = "all", one
status row is returned for every requested spectrum/check pair, plus any
applicable batch-level error, with stable IDs and correction diagnostics.
Examples
data("raman_hdpe")
assess_spec(raman_hdpe)
#> Empty data.table (0 rows and 14 cols): spectrum_index,spectrum_id,check,issue,description,likely_cause...