The goals of this notebook are:
1. To check the original contour data of Triadica sebifera.
2. To check contours reconstructed from oriented true EFD normalization for all samples.
Output figures of this notebook are not included in the manuscript, but they are saved in the results/ directory.
The following object is masked from 'package:stats':
filter
source("R/normalization.R")source("R/compare_contours.R")# color palette for colorblind-friendly visualizationpalette("Okabe-Ito")# set the data directory from environment variable (.Renviron)data_dir<-Sys.getenv("PROJECT_DATA_DIR")
Load contour data
Load the contour data from the CSV files in the data/contour_triadica_sebifera/ directory. There are 30 samples.
# file paths of contour CSV filesfile_paths_xy<-list.files(file.path(data_dir, "data/contour_triadica_sebifera"), full.names =TRUE, pattern ="\\.csv$")# extract sample IDs from file namesid_name<-file_path_sans_ext(basename(file_paths_xy))# load contour data into a list of matricesxy_list<-lapply(file_paths_xy, function(fp){#cat("File:", fp, "\n")df<-read.csv(fp)df<-df[, c("x", "y")]df<-as.matrix(df)storage.mode(df)<-"double"# if the contour is not closed, add the first point to the end to close itif(!all(df[1, ]==df[nrow(df), ])){df<-rbind(df, df[1, ])}return(df)})# assign names to the list of contoursnames(xy_list)<-id_name
Load oriented true normalized EFD coefficients
Load the oriented true normalized EFD coefficients from the CSV files in the data/coefficients_efd_normalized_triadica_sebifera/ directory. These data are generated with LeafContourEFD.
# file paths of EFD coefficient CSV filesfile_paths<-list.files(file.path(data_dir, "data/coefficients_efd_normalized_triadica_sebifera"), full.names =TRUE, pattern ="\\.csv$")# load EFD coefficients into a list of data framesef_list<-lapply(file_paths, function(fp){#cat("File:", fp, "\n")df<-read.csv(fp)return(df)})
Visualize the original contours and the contours reconstructed from oriented true EFD normalization
Overlay the original contour and the reconstructed contour from Oriented True EFD normalization.
---title: "Contour check for *Triadica sebifera*"---The goals of this notebook are: 1. To check the original contour data of *Triadica sebifera*. 2. To check contours reconstructed from oriented true EFD normalization for all samples. Output figures of this notebook are not included in the manuscript, but they are saved in the `results/` directory.## Setup```{r}#| label: setuplibrary(tools)library(Momocs)source("R/normalization.R")source("R/compare_contours.R")# color palette for colorblind-friendly visualizationpalette("Okabe-Ito")# set the data directory from environment variable (.Renviron)data_dir <-Sys.getenv("PROJECT_DATA_DIR")```## Load contour dataLoad the contour data from the CSV files in the `data/contour_triadica_sebifera/` directory.There are 30 samples.```{r}#| label: load_contours# file paths of contour CSV filesfile_paths_xy <-list.files(file.path(data_dir, "data/contour_triadica_sebifera"),full.names =TRUE,pattern ="\\.csv$")# extract sample IDs from file namesid_name <-file_path_sans_ext(basename(file_paths_xy))# load contour data into a list of matricesxy_list <-lapply(file_paths_xy, function(fp) {#cat("File:", fp, "\n") df <-read.csv(fp) df <- df[, c("x", "y")] df <-as.matrix(df)storage.mode(df) <-"double"# if the contour is not closed, add the first point to the end to close itif (!all(df[1, ] == df[nrow(df), ])) { df <-rbind(df, df[1, ]) }return(df)})# assign names to the list of contoursnames(xy_list) <- id_name```## Load oriented true normalized EFD coefficientsLoad the oriented true normalized EFD coefficients from the CSV files in the `data/coefficients_efd_normalized_triadica_sebifera/` directory.These data are generated with LeafContourEFD.```{r}#| label: load_coefficients# file paths of EFD coefficient CSV filesfile_paths <-list.files(file.path(data_dir, "data/coefficients_efd_normalized_triadica_sebifera"),full.names =TRUE,pattern ="\\.csv$")# load EFD coefficients into a list of data framesef_list <-lapply(file_paths, function(fp) {#cat("File:", fp, "\n") df <-read.csv(fp)return(df)})```## Visualize the original contours and the contours reconstructed from oriented true EFD normalizationOverlay the original contour and the reconstructed contour from Oriented True EFD normalization.```{r}#| label: compare_contourslayout(matrix(seq_along(xy_list), nrow =5, byrow =TRUE))for (i inseq_along(xy_list)) {compare_contour_oriented_true_EFD_normalization(original = xy_list[[i]],ef_normalized = ef_list[[i]],label = i,nb.h =5,mar =c(0, 0, 0, 0),lwd =3,cex.text =5 )}``````{r}#| label: save_comparison_plots#| eval: false#| code-fold: true#| code-summary: "Save the plot as SVG file"save_dir <-"results"dir.create(save_dir, showWarnings =FALSE)save_file_name <-"supplementary_compare_contours_oriented_true_efd_normalized_triadica_sebifera.svg"svg(file.path(save_dir, save_file_name), bg ="transparent")layout(matrix(seq_along(xy_list), nrow =5, byrow =TRUE))for (i inseq_along(xy_list)) {compare_contour_oriented_true_EFD_normalization(original = xy_list[[i]],ef_normalized = ef_list[[i]],label = i,nb.h =5,mar =c(0, 0, 0, 0),lwd =3,cex.text =5 )}dev.off()```