This vignette walks through each step of the data preparation process, from raw ROXAS / ROXAS AI output files to the files for a TRIA submission.
Step 1: Locate ROXAS files
Set the path to a folder containing the ROXAS or ROXAS AI output
files of your QWA dataset. Files may be organised in subdirectories.
get_roxas_files() checks that all required files are
present for each image and returns a data frame of their full file
paths.
For ROXAS, the required files per image are:
- Cells output (
{IMAGEID}_Output_Cells.txt) - Rings output (
{IMAGEID}_Output_Rings.txt) - Settings file (
{IMAGEID}_ROXAS_Settings.txt) - Image file (
{IMAGEID}.jpg; also.jpeg,.png,.bmp,.tiff)
For ROXAS AI, the required files per image are:
- Cells table (
{IMAGEID}.cells_table.csvor.txt) - Rings table (
{IMAGEID}.rings_table.csvor.txt) - Metadata file (
{IMAGEID}.metadata.json) - Image file (
{IMAGEID}.scan.jpg; also.jpeg,.png,.bmp,.tiff)
roxas_version <- "roxas" # or "roxas_ai"
path_in <- "path/to/ROXAS_data"
files <- get_roxas_files(path_in, roxas_version)Step 2: Extract the data structure
QWA data are organised hierarchically: each analysed image was taken of a microsection/slide, each slide was cut from a woodpiece (e.g. a core or a wedge), and each woodpiece was sampled from a tree of a certain species at a specific site. Typically, some or all of this information is encoded in the image file names. Fonti et al. (2025) recommend the naming convention:
{site}_{species}_{tree/woodpiece}_{slide}_{image}
e.g. S22_LADE_L08b_1_2.jpg is the second image of the
first slide from woodpiece b of the Larix decidua tree
L08 at site S22.
extract_data_structure() extracts this hierarchy using a
regular expression with named
groups. Each named group (site, species,
tree, woodpiece, slide,
image) that appears in the pattern is extracted and used to
construct the full hierarchical labels. Not all groups need to be in the
pattern: If, for example, all images belong to the same site and/or
species, the site_label and/or species_code
arguments can be supplied instead of including
site/species groups in the pattern. Or if each
tree was cored exactly once, there may not be a specific woodpiece
identifier, and it can be left out of the pattern.
Adapt the pattern to match your naming convention using named regex
groups. Supported group names: site, species, tree, woodpiece, slide,
image. Example below assumes the common convention
{site}_{species}_{tree}_{slide}_{image} with alphanumeric
components and one woodpiece per tree (no separate woodpiece
identifier). If your naming includes a woodpiece identifier, you can add
it (e.g. by including “(?extract_data_structure() for more information.
pattern <- "(?<site>[[:alnum:]]+)_(?<species>[[:alnum:]]+)_(?<tree>[[:alnum:]]+)_(?<slide>[[:alnum:]]+)_(?<image>[[:alnum:]]+)"
df_structure <- extract_data_structure(files, pattern)
# or:
# pattern <- "(?<tree>[[:alnum:]]+)_(?<slide>[[:alnum:]]+)_(?<image>[[:alnum:]]+)"
# df_structure <- extract_data_structure(
# files, pattern, site_label = "S22", species_code = "LADE")Always inspect the result with
View(df_structure) before proceeding to confirm that all
labels were extracted correctly and the hierarchy is consistent.
Step 3: Collect metadata
From the ROXAS or ROXAS AI files
collect_settings_data() reads the per-image ROXAS
settings (or ROXAS AI metadata) and the image files: their EXIF data for
classic ROXAS, their actual file size for ROXAS AI. The result is
combined with the data structure from Step 2 into a
QWAimages object using build_QWAimages().
Passing the data structure directly, the ROXAS version is
auto-detected from the settings file names, and the image files are read
from the fname_image column.
df_settings <- collect_settings_data(df_structure)Alternatively, the settings and image file paths can be supplied individually, and the version can be set explicitly:
df_settings <- collect_settings_data(files_settings = df_structure$fname_settings,
files_images = df_structure$fname_image,
roxas_version = "roxas")For classic ROXAS, meas_created_at is read as a raw
character string, as its format depends on the locale. Convert it
explicitly to POSIXct with the format(s) of your locale,
and address any conversion warnings before overwriting the column in
df_settings. As all timestamps in rxs2tria, it is kept as
local clock time (stored as UTC, the default of
lubridate::parse_date_time()).
# for ROXAS only (ROXAS AI has standardised timestamps, so already converted)
settings_date_orders <- c("%d.%m.%Y %H:%M:%S", "%d/%m/%Y %H:%M") # adjust to your locale
if (roxas_version == "roxas") {
meas_created_at_converted <- lubridate::parse_date_time(
df_settings$meas_created_at,
orders = settings_date_orders
)
df_settings$meas_created_at <- meas_created_at_converted
}Combine the extracted data into one object:
rxs_images <- build_QWAimages(df_structure, df_settings)
rm(df_structure, df_settings)
rxs_images # prints a summary of the image-level metadatarxs_images is a QWAimages object: a tibble
subclass holding the per-image metadata (file paths, image EXIF data,
and ROXAS settings), with the roxas_version stored as an
attribute. It can be saved to a compressed CSV for later use:
write_QWAimages(rxs_images, "path/to/output_data/example_dataset_QWAimages.csv.gz")
# rxs_images <- read_QWAimages("path/to/output_data/example_dataset_QWAimages.csv.gz")Additional metadata for TRIA submission (Step 3b)
To provide the site-, tree-, woodpiece-, slide-, and dataset-level
metadata required for a TRIA submission, use the interactive metadata
Shiny app. It takes a QWAimages object as its starting
point and guides you through filling in the required fields. The output
is a full QWAmetadata object, which is exported as a
.json file. Partially completed submissions can be reloaded
and continued at any time.
launch_metadata_app()
# After exporting and closing the app, optionally read the result back:
# QWA_meta <- read_QWAmetadata("path/to/output_data/example_dataset_QWAmetadata.json")See vignette("metadata-app") for a full walkthrough of
the app.
Step 4: Read and clean the measurement data
collect_raw_data() reads the cell and ring measurement
tables from all ROXAS output files, combines them, and performs initial
cleaning: negative values and error codes are replaced with
NA, the dating is checked for gaps or future years, and a
warning is issued if CWT estimates appear to be missing (relevant for
conifer data).
complete_QWAdata() then adds derived cell and ring
measures (e.g. total cell area, relative wall thickness, cell diameters,
earlywood/latewood classification and widths) and computes ring quality
flags:
-
incomplete_ring: ring at the inner or outer image border where the true ring boundary is not visible; MRW is unreliable or unavailable. -
missing_ring: no cells detected; ring was added manually during crossdating (typically a wedging ring). -
duplicate_ring: the same year appears in more than one image due to overlapping slides from the same woodpiece. -
exclude_dupl:TRUEfor the duplicate ring(s) not selected as the preferred source (ranked by cell count, penalising incomplete and missing rings). -
exclude_issues: rings to exclude from analyses, initialised fromincomplete_ring. Missing rings are not excluded, as their zero width is a valid measurement; setexclude_issuesafterwards to use a different rule.
QWA_data <- collect_raw_data(rxs_images)
# or if you already loaded the full metadata from json after completing Step 3:
# QWA_data <- collect_raw_data(QWA_meta$images)
QWA_data <- complete_QWAdata(QWA_data, rxs_images)
# to also exclude missing rings:
# QWA_data$rings$exclude_issues <- QWA_data$rings$incomplete_ring | QWA_data$rings$missing_ring
QWA_data # prints an overview including ring flag countsStep 5: Save the QWA data
write_QWAdata() saves the QWAdata object to
two (optionally compressed) CSV files following the naming convention
{dataset_name}_QWAcells.csv(.gz) and
{dataset_name}_QWArings.csv(.gz). Explicit file names can
also be provided (see ?write_QWAdata).
path_out <- "path/to/output_data"
dataset_name <- "example_dataset"
write_QWAdata(QWA_data, dir = path_out, dataset_name = dataset_name)
# QWA_data <- read_QWAdata(dir = path_out, dataset_name = dataset_name)At this stage you have the minimal components required for a TRIA
submission: the QWAmetadata .json file (from
Step 3b) and the two QWAdata .csv files. The
following steps are optional but recommended for a more complete
submission.
Step 6: Assess the measurements data quality (optional)
Compute radial profiles (Step 6a)
Cell measurements can be aggregated across the ring width into
position bins, producing a QWAprofile object. Two binning
schemes are available:
- Sector profiles: divide each ring into n bins of equal relative width (0–100% of ring width). Comparable across rings of different absolute widths.
- Band profiles: sliding window of fixed absolute width and step size (in µm). Meaningful when absolute radial position matters (e.g. density gradients in µm from the cambium).
Both support computing means and optional quantiles per bin. With
apply_exclusions = TRUE, the cells of excluded rings
(exclude_dupl, exclude_issues) are removed
before aggregating; tissue = "affected" removes only the
earlywood or latewood cells of rings whose affected_tissue
is "ew" or "lw". Use these after flagging
rings in Step 6b.
prf_sector <- calculate_sector_profiles(QWA_data,
n_sectors = 5,
sel_cell_params = c("la", "cwttan"),
quant_probs = c(0.1, 0.5, 0.9))
# prf_band <- calculate_band_profiles(QWA_data,
# bandwidth = 50, stepsize = 25,
# sel_cell_params = c("la", "cwttan"),
# quant_probs = c(0.1, 0.5, 0.9))
# After flagging rings (Step 6b), recalculate with exclusions applied:
# prf_sector <- calculate_sector_profiles(QWA_data, n_sectors = 5,
# sel_cell_params = c("la", "cwttan"),
# apply_exclusions = TRUE, tissue = "affected")
# Save and reload:
# write_QWAprofile(prf_sector, "path/to/output_data/example_dataset_QWAprofile_sector5.csv.gz")
# prf_sector <- read_QWAprofile("path/to/output_data/example_dataset_QWAprofile_sector5.csv.gz")Visualise measurement series and flag rings (Step 6b)
The flags Shiny app provides an interactive overview of the ring measurements and allows you to annotate individual rings with data quality flags (e.g. compression wood, cracks) and discrete feature flags (e.g. blue rings, frost rings).
The app takes as input (loaded from file or from the current R environment):
- The
$ringscomponent of aQWAdataobject (required). - A sector
QWAprofile(optional) — plotted alongside the ring time series to aid visual inspection. - A
QWAimagesobject (optional) — used to display image-level comments and to allow opening image files directly from the app.
The output is the QWAdata$rings data frame with
additional columns for the flags, comment and
affected_tissue. If image-level comments were reviewed, the
app also saves the image metadata with the comment_handled
column. The rings can be saved to file and read back to update the
QWAdata object:
launch_flags_app()
# To update QWA_data$rings with the edited output:
# QWA_data$rings <- read_QWAdata(
# file_rings = "path/to/output_data/example_dataset_edited_QWArings.csv")$rings
# QWA_data$rings <- df_rings_edited # or directly from a data frame in the env
# write_QWAdata(QWA_data, dir = path_out, dataset_name = dataset_name, overwrite = TRUE)extract_ring_measures() returns the ring measurements
without the excluded rings, as input for further analyses:
df_meas <- extract_ring_measures(QWA_data$rings)See vignette("flags-app") for a full walkthrough of the
app.
Update images (Step 6c)
update_QWAdata() synchronises a QWAdata
object with a QWAimages object: images new in
rxs_images are read and added, images no longer in
rxs_images are removed, and images listed in
imgs_to_reread are read again from their raw data files.
This avoids reprocessing the entire dataset. Duplicate-ring flags are
recalculated for all woodpiece-years affected by these changes. Added
and re-read images are new data: inspect their flags again (Step 6b) or
re-apply any custom rule for exclude_issues.
Re-analysed images
If data processing reveals issues in the raw data and you re-analyse one or more images with ROXAS or ROXAS AI:
- Replace the output files in
path_inwith the newly generated files. - Re-read the settings/metadata for those images in the
QWAimagesobject (no need to repeat Steps 1 and 2):
rxs_images <- update_QWAimages(rxs_images,
imgs_to_reread = c("IMAGELABEL1", "IMAGELABEL2"),
settings_date_orders = settings_date_orders) # same as defined in Step 3
# if a QWAmetadata object exists, update it as well (keeps the values
# entered in the metadata app):
# QWA_meta <- update_QWAmetadata(QWA_meta, rxs_images)- Update the
QWAdataobject. For the re-read images, derived measures and automatic flags are recalculated. By default, any manual edits made in the flags app for these images are also reset. Setreset_manual_flags = FALSEto keep them only if the re-analysis was minor and the dating was not affected:
QWA_data <- update_QWAdata(QWA_data, meta = rxs_images,
imgs_to_reread = c("IMAGELABEL1", "IMAGELABEL2"))- Review
only_ewandimg_commentof the re-analysed images in the metadata app, e.g. a comment noting that the image needs re-analysis.
Added or removed images
To add images, there are two options:
- Rerun Steps 1–3 on the updated
path_into rebuildrxs_images. Anyonly_ewandimg_commentvalues entered in the metadata app are then missing fromrxs_images(update_QWAmetadata()below fills them in). - Run Steps 1–3 on a separate folder containing only the new images to
obtain
rxs_images_new, and combine it with the existing object. This keeps existing values. Both objects must have the same ROXAS version and distinct image labels:
rxs_images <- combine_QWAimages(rxs_images, rxs_images_new)To remove images, filter them from rxs_images:
Then update the QWAdata object:
QWA_data <- update_QWAdata(QWA_data, meta = rxs_images)If a QWAmetadata object exists, update it as well. This
replaces its images and adds or removes the corresponding rows (and
updates the counts) in the sites, trees, woodpieces and slides tables,
keeping the existing metadata. Any only_ew and
img_comment values missing or NA in
rxs_images are filled from QWA_meta$images, so
this also recovers them after a rebuild. Complete any added rows in the
metadata app.
QWA_meta <- update_QWAmetadata(QWA_meta, rxs_images)Combining datasets
Two datasets prepared separately, e.g. from different input folders,
can be combined with combine_QWAimages(),
combine_QWAdata() and combine_QWAmetadata().
Both must have the same ROXAS version and distinct image labels. Where
both contain the same entry (e.g. a shared site or author), the first
object takes precedence. Duplicate-ring flags are recalculated for
woodpiece-years with rings from both datasets.
rxs_images <- combine_QWAimages(rxs_images_1, rxs_images_2)
QWA_data <- combine_QWAdata(QWA_data_1, QWA_data_2)
QWA_meta <- combine_QWAmetadata(QWA_meta_1, QWA_meta_2)After any of these updates, save the data again:
write_QWAdata(QWA_data, dir = path_out, dataset_name = dataset_name, overwrite = TRUE)Step 7: Compile supplementary files (optional)
A TRIA submission must include at minimum the
QWAmetadata .json and the QWAdata
.csv(.gz) files. If you want to provide additional
(supplementary) files (original images, annotated images, raw ROXAS /
ROXAS AI output, reference series .rwl files, etc.) these
should be submitted in a single zip alongside a standalone supplementary
CSV listing all the files in the zip.
Not all files may be eligible as supporting material for a TRIA
dataset, and it is important to track which file pertains to which image
or slide, etc. For this purpose, compile_supplementary()
scans a directory (including nested subfolders) and returns a table with
one row per file it finds. For each file it infers the
resource_type from the file name and sets the hierarchy
level it belongs to (linked_level). Files are also matched
to their linked_label (e.g. the image_label)
using a QWAimages object, where possible.
suppl_res <- compile_supplementary("path/to/supplementary_files", rxs_images = rxs_images)
# or rxs_images = QWA_meta$imagesEvery file gets a status ("ok",
"review", or "ignore") and the console reports
whether the supplementary path is ready for submission, or which files
still need attention. Review the table, add a description
for files where the resource_type could not be inferred,
and complete any linked_label values that were not filled
automatically. Then write it to a CSV to submit alongside the
supplementary zip:
suppl_res
vroom::vroom_write(suppl_res, "path/to/output_data/example_dataset_supplementary_files.csv",
delim = ",", na = "")See vignette("supplementary") for more details on this
step, including how to recompile_supplementary() after
making edits, and how to run a final check_supplementary()
once you are done.
Step 8: Check and submit your data
Before submitting, check the files as they will be submitted,
i.e. after the metadata app and any edits in the flags app. Each check
warns about issues the TRIA admins would ask you to fix and returns
TRUE (invisibly) if none were found; with
strict = TRUE, it aborts on the first issue instead.
check_QWAmetadata() and check_QWAdata() check
each object on its own, check_consistency() checks that
they match each other, and check_supplementary() checks the
supplementary manifest against the final zip. Radial profiles are not
submitted; check_QWAprofile() checks them before
analysis.
QWA_meta <- read_QWAmetadata("path/to/output_data/example_dataset_QWAmetadata.json")
QWA_data <- read_QWAdata(dir = path_out, dataset_name = dataset_name)
check_QWAmetadata(QWA_meta) # includes the images, see ?check_QWAimages
check_QWAdata(QWA_data)
check_consistency(meta = QWA_meta, data = QWA_data)
# if submitting supplementary files (Step 7), against the final zip:
# check_supplementary(suppl_res, "path/to/supplementary_data.zip",
# rxs_images = QWA_meta$images)Once all checks pass, and you are ready to share your prepared data
files with us, email tria@wsl.ch—either
with a link to the files on a file transfer service of your choice, or
asking for an invite link to WSL’s own one. See
vignette("submission") for what to upload and what happens
to your files once we receive them.