User Tools

Site Tools


tutorials:analyse-structure

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorials:analyse-structure [2025/06/27 17:03] ttutorials:analyse-structure [2025/06/30 16:51] (current) t
Line 1: Line 1:
-====== A simple people's guide on structural data analysis integrating R ====== +====== Structural QSM-based data analysis integrating R ====== 
-There exists the rare case that you might want to conduct some statistical analysis on the structure of your simulated or measured plant outside of XL and GroIMP. GroIMP's query system is principally a very powerful tool for the data subsetting part of such analysis (finding parts of your structure that follow some topological relationships), but it can be hard to apply advanced statistical methods directly in GroIMP.+Sometimes, you might want to conduct some statistical analysis on the structure of your simulated or measured plant outside of XL and GroIMP. GroIMP's query system is principally a very powerful tool for the data subsetting part of such analysis (finding parts of your structure that follow some topological relationships), but it can be hard to apply advanced statistical methods directly in GroIMP.
  
 Here, we present an example on how to export structures from GroIMP and how to analyze them in R. There, the rTwig library allows for convenient analysis of QSM-like structures, which we will export from GroIMP. Here, we present an example on how to export structures from GroIMP and how to analyze them in R. There, the rTwig library allows for convenient analysis of QSM-like structures, which we will export from GroIMP.
Line 9: Line 9:
  
 ===== Requirements ===== ===== Requirements =====
-  * GroIMP "qsm" plugin+  * GroIMP "qsm" [[user-guide:pluginmanager|plugin]]
   * GroIMP "fastrakReader" plugin when working with FASTRAK data (use version 0.8 with GroIMP version 2.2)   * GroIMP "fastrakReader" plugin when working with FASTRAK data (use version 0.8 with GroIMP version 2.2)
   * Some recent version of R   * Some recent version of R
Line 15: Line 15:
  
 ===== GroIMP import & export===== ===== GroIMP import & export=====
-As always in GroIMP, you can import your file using Object -> Insert File / Insert File to RGG. The difference is that if you insert to RGG, the file will be imported under the RGG Root instead of under Node.0. For our example here, both are equivalent.+As always in GroIMP, you can import your file using Object -> Insert File / Insert File to RGG. The difference is that if you insert to RGG, the file will be imported under the RGG Root instead of under Node.0. For our example here, always use "Insert File" (not under RGG), even though both can be used.
 ==== Import: FASTRAK ==== ==== Import: FASTRAK ====
 Importing FASTRAK data in .xml format requires the fastrakReader plugin. Importing FASTRAK data in .xml format requires the fastrakReader plugin.
Line 41: Line 41:
 ]} ]}
 </code> </code>
 +
 +=== Correct FASTRAK Topology ===
 +If you want to retain correct branch orders (0 = stem and so on) in the exported structure, you will need to manually correct the imported data. This is a workaround for a current issue with the QSM export, which will be resolved in the future.
 +
 +1. Open the 2D Graph and select the edge connecting Node.0 with the first node of your Fastrak structure:
 +
 +{{:tutorials:fastrak-graph.png?400|}}
 +
 +2. In the attribute editor, change the edge type from branch to successor:
 +
 +{{:tutorials:change-edge.png?400|}}
 +
 +That's it! 
 +
 +==== Import: DTD ====
 +DTD files can be imported in exactly the same way as FASTRAK files, but no special plugin is required.
  
 ==== Import: QSM ==== ==== Import: QSM ====
Line 87: Line 103:
  
 tree_metrics() provides some useful aggregations that are similar to GroIMP queries, like for example the aggregation of individual cylinder segments into branches. tree_metrics() provides some useful aggregations that are similar to GroIMP queries, like for example the aggregation of individual cylinder segments into branches.
-The actual analysis to perform will however heavily depend on the type of your data source and how the data was collected (e.g. biologically meaningful shoot-based data vs. pure geometry acquisitions)+The actual analysis to perform will however heavily depend on the type of your data source and how the data was collected (e.g. biologically meaningful shoot-based data vs. pure geometry acquisitions). Supposing you have Fastrak data where every cylinder segment represents a yearly shoot, you could e.g. analyze the yearly apical growth of the stem on several spruce trees like this, just using the raw QSM data:
  
 +<code sas>
 +library(dplyr)
 +library(ggplot2)
 +
 +folder_path <- "D:/groimp/tiny_trees_analysis_example/f_qsms"
 +file_list <- list.files(path = folder_path, pattern = "\\.qsm$", full.names = TRUE)
 +qsm_list <- list()
 +for (file in file_list) {
 +  cyl_data <- read.csv(file)
 +  tree_id <- tools::file_path_sans_ext(basename(file))
 +  qsm <- reconstruct_qsm(
 +    cylinder = cyl_data,
 +    id = "id", parent = "parent", radius = "raw_radius",
 +    branch_order = "branch_order",
 +    start_x = "start_x", start_y = "start_y", start_z = "start_z",
 +    end_x = "end_x", end_y = "end_y", end_z = "end_z") %>
 +    mutate(tree_id = tree_id)
 +  qsm_list[[tree_id]] <- qsm
 +}
 +
 +stem_list <- lapply(qsm_list, function(qsm){
 +  qsm %>
 +    filter(branch_order == 0) %>%
 +    arrange(base_distance) %>
 +    mutate(year = 1:nrow(.))})
 +
 +all_stems <- bind_rows(stem_list)
 +all_years <- sort(unique(all_stems$year))
 +all_stems %>%  
 +  ggplot(., aes(x = year, y=length)) +
 +    geom_point(aes(color = tree_id)) + 
 +    geom_smooth(method = "lm") +
 +    ggtitle("Yearly apical shoot lengths") +
 +    xlab("Year") + ylab("Shoot length [m]") + 
 +    scale_x_continuous(breaks = all_years) +
 +    theme_minimal()
 +</code>
  
 +{{:tutorials:yearly_shoots_tiny_spruce.png?400|}}
  
tutorials/analyse-structure.1751036615.txt.gz · Last modified: 2025/06/27 17:03 by t