User Tools

Site Tools


tutorials:analyse-structure

This is an old revision of the document!


A simple people's guide on structural 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.

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.

Note that there are also the GROGRA Functions for structural analysis. These work directly in GroIMP and can provide similar outputs like rTwig, but they are not documented as well. Nonetheless, their wiki article here may give you some ideas on the types of analysis you can conduct, irrespective of the tools you use.

There are two typical data origins for structures that people want to analyze: Manually measured FASTRAK data and plants generated in GroIMP. This article covers both of these sources. There is also a third possible data source, which are QSMs. These can also be imported and analyzed in GroIMP. For example, GroIMP could be used to interactively correct QSM topologies.

Requirements

  • GroIMP “qsm” plugin
  • GroIMP “fastrakReader” plugin when working with FASTRAK data (use version 0.8 with GroIMP version 2.2)
  • Some recent version of R
  • R-library “rTwig” (rTwig documentation on github)

GroIMP import & export

Import: FASTRAK

When using FASTRAK data, you can open a new RGG project and simply import your file using Object → Insert File / Insert File to RGG. This requires the fastrakReader plugin. 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. Note that your data might be scaled in an unexpected way relative to your GroIMP project. In the picture below is an example of FASTRAK data inserted in a New RGG project, note the size of the FASTRAK tree relative to the “A” of New RGG.

If you want to delete this structure, you can do Edit → Clear Project Graph (which will remove everything, not only the thing you just imported).

Using the color() method below, you can color your measured FASTRAK data based on branch orders:

As you can see, there is a possible measurement error here: One branch is colored in blue, which means it is of order 3, but it should probably be order 2. This is because the fastrakReader has to infer the topology of the structure based on the relative position of segments to each other. In this case, this segment happens to start closer to the other branch than to its actual mother segment:

public void color (){
	[	(*f:F,(count((*f ((<)*<+)+F*))==0)*) ::> f.setShader(RED);    //all F of order 0
		(*f:F,(count((*f ((<)*<+)+F*))==1)*) ::> f.setShader(YELLOW); //all F of order 1]
		(*f:F,(count((*f ((<)*<+)+F*))==2)*) ::> f.setShader(GREEN);
		(*f:F,(count((*f ((<)*<+)+F*))==3)*) ::> f.setShader(BLUE);
		(*f:F,(count((*f ((<)*<+)+F*))==4)*) ::> f.setShader(BLACK);
]}

Import: QSM

To import a QSM in GroIMP, you need to provide it as a comma-separated file with .qsm extension which contains these columns: start_x,start_y,start_z,end_x,end_y,end_z,id,parent,raw_radius,length,branch_order,branch. This is consistent with the rTwig naming convention. The intended usage pipeline is to standardize QSMs from various QSM tool origins in rTwig, then you can simply export the required variables from the $cylinder data as a table.

Export

Export from GroIMP as .qsm is provided by the qsm plugin. Under View → Export → complete scene you need to specify a file name and select text/qsm as filetype. The resulting file is simply a comma separated table which contains information for every cylinder in your scene:

tutorials/analyse-structure.1751032696.txt.gz · Last modified: 2025/06/27 15:58 by t