View source: R/proxiscout_write_model.R
| proxiscout_write_model | R Documentation |
Serializes a model of class spectral_model (including its
preprocessing recipe) into a JSON format that can be imported into
the NeoSpectra NIR Hub and deployed on ProxiScout sensors (see Details).
proxiscout_write_model(object, file = NULL)
object |
an object of class |
file |
an optional character string with the path (including file name)
where the JSON output should be written. If |
The JSON output produced by this function can be imported into the NeoSpectra NIR Hub and used within a ProxiScout application. Once imported, the NeoSpectra Scan mobile app linked to a ProxiScout sensor can access the model and use it to compute and display spectral predictions.
The JSON pipeline always begins with two hardware-specific steps that are
added automatically, regardless of the preprocessing recipe in object:
(1) scaling raw reflectance from the 0–100 range reported by the sensor to
the 0–1 range, and (2) averaging repeated scans of the same sample. These
steps precede any user-defined preprocessing.
Constraints and supported preprocessing steps:
The first step in the preprocessing recipe of object must be
prep_resample, as wavenumber alignment with the ProxiScout
hardware grid is required.
All predictor wavenumbers in object must match the hardware
wavenumbers returned by get_proxiscout_wavenumbers within a
tolerance of 0.1 \mjeqn\mathrmcm^-1cm^-1.
prep_derivative and prep_smooth are
supported only when algorithm = "savitzky-golay".
prep_transform is supported only with
to = "absorbance"; using to = "reflectance" generates a
warning and the step is skipped in the JSON output.
prep_wav_trim is handled implicitly through wavenumber
selection and does not produce an explicit JSON step.
If file = NULL (default), the JSON string is returned
visibly so it can be inspected or assigned to a variable. If file
is specified, the JSON string is written to that file and returned
invisibly (i.e. it is not printed to the console, following the standard
R convention for functions called primarily for their side effect).
Leonardo Ramirez-Lopez and Claudio Orellano
calibrate, get_proxiscout_wavenumbers,
prep_resample
data("proximateCannabis")
control <- calibration_control(
validation_type = "kfold", number = 3, folds = "sequential"
)
recipe <- preprocess_recipe(
prep_resample(grid = "proxiscout"),
prep_snv(),
prep_derivative(m = 1, w = 11, p = 2, algorithm = "savitzky-golay"),
device = "proxiscout"
)
model <- calibrate(
THCA ~ spc,
data = proximateCannabis, preprocess = recipe,
method = fit_plsr(10), control = control, verbose = FALSE
)
json_model <- proxiscout_write_model(model)
json_model
proxiscout_write_model(model, file = file.path(tempdir(), "my_model.json"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.