Skip to content

Commit

Permalink
Merge branch 'main' into results/direct-neigbours
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobdanel authored Jan 22, 2024
2 parents 4adfe79 + d274223 commit ecc1030
Show file tree
Hide file tree
Showing 10 changed files with 269 additions and 7 deletions.
4 changes: 2 additions & 2 deletions R/jsd_from_vec.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @export
#'
lfa_jsd_from_vec <- function(x, y) {
x.d = density(x)
y.d = density(y)
x.d = density(x, na.rm = TRUE)
y.d = density(y, na.rm = TRUE)
return(lfa::lfa_jsd(x.d$y, y.d$y))
}
4 changes: 2 additions & 2 deletions R/kld_from_vec.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @export
#'
lfa_kld_from_vec <- function(x, y) {
x.d = density(x)
y.d = density(y)
x.d = density(x, na.rm = TRUE)
y.d = density(y, na.rm = TRUE)
return(lfa::lfa_kld(x.d$y, y.d$y))
}
2 changes: 1 addition & 1 deletion diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions results/appendix/build_quantitativ_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def build_quantitativ_results(distribution_name = "detections",distribution_name
```{{r}}
#| warning: false
#| code-fold: true
#| results: hide
{preprocessing}
value_column <- {value_column}
```
Expand Down Expand Up @@ -133,5 +134,13 @@ def main():
preprocessing_nearest_avg= preprocessing_nearest+ "\n" +"""names <- paste0("Neighbor_",1:100)
data$avg = rowMeans(dplyr::select(as.data.frame(data),names))"""
write_file("nearest_avg.qmd", build_quantitativ_results("nearest-neighbor-avg", "Distribution of average nearest neighbor distances", '"avg"', header_size=4, preprocessing=preprocessing_nearest_avg))


preprocessing_number_of_returns = """data <- sf::st_read("data/tree_properties.gpkg")
neighbors <- lfa::lfa_get_neighbor_paths() |> lfa::lfa_combine_sf_obj(lfa::lfa_get_all_areas())
data = sf::st_join(data,neighbors, join = sf::st_within)"""

write_file("number_of_returns.qmd", build_quantitativ_results("number-of-returns", "Distribution of the number of returns", '"number_of_returns"', header_size=3, preprocessing=preprocessing_number_of_returns))

if __name__ == "__main__":
main()
218 changes: 218 additions & 0 deletions results/appendix/number_of_returns.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
### Distribution of the number of returns


```{r}
#| warning: false
#| code-fold: true
#| results: hide
data <- sf::st_read("data/tree_properties.gpkg")
neighbors <- lfa::lfa_get_neighbor_paths() |> lfa::lfa_combine_sf_obj(lfa::lfa_get_all_areas())
data = sf::st_join(data,neighbors, join = sf::st_within)
value_column <- "number_of_returns"
```



#### Kullback-Leibler-Divergence



```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-kld_specie
#| tbl-cap: "Kullback-Leibler-Divergence between the researched species Beech, Oak, Pine and Spruce for the atrribute number-of-returns"
kld_results_specie <- lfa::lfa_run_test_asymmetric(data,value_column,"specie",lfa::lfa_kld_from_vec)
lfa::lfa_generate_result_table_tests(kld_results_specie,"Kullback-Leibler-Divergence between species")
```



```{r}
#| warning: false
colMeans(kld_results_specie, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-kld-beech
#| tbl-cap: "Kullback-Leibler-Divergence between the researched areas which have the dominante specie beech for the atrribute number-of-returns"
specie <- data[data$specie=="beech",]
kld_results_beech <- lfa::lfa_run_test_asymmetric(specie,value_column,"area",lfa::lfa_kld_from_vec)
lfa::lfa_generate_result_table_tests(kld_results_beech,"Kullback-Leibler-Divergence between areas with beech")
```



```{r}
#| warning: false
colMeans(kld_results_beech, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-kld-oak
#| tbl-cap: "Kullback-Leibler-Divergence between the researched areas which have the dominante specie oak for the atrribute number-of-returns"
specie <- data[data$specie=="oak",]
kld_results_oak <- lfa::lfa_run_test_asymmetric(specie,value_column,"area",lfa::lfa_kld_from_vec)
lfa::lfa_generate_result_table_tests(kld_results_oak,"Kullback-Leibler-Divergence between areas with oak")
```



```{r}
#| warning: false
colMeans(kld_results_oak, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-kld-pine
#| tbl-cap: "Kullback-Leibler-Divergence between the researched areas which have the dominante specie pine for the atrribute number-of-returns"
specie <- data[data$specie=="pine",]
kld_results_pine <- lfa::lfa_run_test_asymmetric(specie,value_column,"area",lfa::lfa_kld_from_vec)
lfa::lfa_generate_result_table_tests(kld_results_pine,"Kullback-Leibler-Divergence between areas with pine")
```



```{r}
#| warning: false
colMeans(kld_results_pine, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-kld-spruce
#| tbl-cap: "Kullback-Leibler-Divergence between the researched areas which have the dominante specie spruce for the atrribute number-of-returns"
specie <- data[data$specie=="spruce",]
kld_results_spruce <- lfa::lfa_run_test_asymmetric(specie,value_column,"area",lfa::lfa_kld_from_vec)
lfa::lfa_generate_result_table_tests(kld_results_spruce,"Kullback-Leibler-Divergence between areas with spruce")
```



```{r}
#| warning: false
colMeans(kld_results_spruce, na.rm = TRUE) |> mean()
```




#### Jensen-Shannon Divergence



```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-jsd_specie
#| tbl-cap: "Jensen-Shannon Divergence between the researched species Beech, Oak, Pine and Spruce for the atrribute number-of-returns"
jsd_results_specie <- lfa::lfa_run_test_symmetric(data,value_column,"specie",lfa::lfa_jsd_from_vec)
lfa::lfa_generate_result_table_tests(jsd_results_specie,"Jensen-Shannon Divergence between species")
```



```{r}
#| warning: false
colMeans(jsd_results_specie, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-jsd-beech
#| tbl-cap: "Jensen-Shannon Divergence between the researched areas which have the dominante specie beech for the atrribute number-of-returns"
specie <- data[data$specie=="beech",]
jsd_results_beech <- lfa::lfa_run_test_symmetric(specie,value_column,"area",lfa::lfa_jsd_from_vec)
lfa::lfa_generate_result_table_tests(jsd_results_beech,"Jensen-Shannon Divergence between areas with beech")
```



```{r}
#| warning: false
colMeans(jsd_results_beech, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-jsd-oak
#| tbl-cap: "Jensen-Shannon Divergence between the researched areas which have the dominante specie oak for the atrribute number-of-returns"
specie <- data[data$specie=="oak",]
jsd_results_oak <- lfa::lfa_run_test_symmetric(specie,value_column,"area",lfa::lfa_jsd_from_vec)
lfa::lfa_generate_result_table_tests(jsd_results_oak,"Jensen-Shannon Divergence between areas with oak")
```



```{r}
#| warning: false
colMeans(jsd_results_oak, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-jsd-pine
#| tbl-cap: "Jensen-Shannon Divergence between the researched areas which have the dominante specie pine for the atrribute number-of-returns"
specie <- data[data$specie=="pine",]
jsd_results_pine <- lfa::lfa_run_test_symmetric(specie,value_column,"area",lfa::lfa_jsd_from_vec)
lfa::lfa_generate_result_table_tests(jsd_results_pine,"Jensen-Shannon Divergence between areas with pine")
```



```{r}
#| warning: false
colMeans(jsd_results_pine, na.rm = TRUE) |> mean()
```




```{r}
#| warning: false
#| code-fold: true
#| label: tbl-number-of-returns-jsd-spruce
#| tbl-cap: "Jensen-Shannon Divergence between the researched areas which have the dominante specie spruce for the atrribute number-of-returns"
specie <- data[data$specie=="spruce",]
jsd_results_spruce <- lfa::lfa_run_test_symmetric(specie,value_column,"area",lfa::lfa_jsd_from_vec)
lfa::lfa_generate_result_table_tests(jsd_results_spruce,"Jensen-Shannon Divergence between areas with spruce")
```



```{r}
#| warning: false
colMeans(jsd_results_spruce, na.rm = TRUE) |> mean()
```

1 change: 1 addition & 0 deletions results/appendix/z_values.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
```{r}
#| warning: false
#| code-fold: true
#| results: hide
data <- lfa::lfa_get_detections()
value_column <- "Z"
```
Expand Down
5 changes: 3 additions & 2 deletions results/report.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ This report documents the analysis of forest data for different tree species.
# Results
{{< include results/researched-areas.qmd >}}
{{< include results/z-distribution.qmd >}}
{{< include results/number_of_returns.qmd >}}


{{< include results/nearest-neighbors.qmd >}}


|specie |area | density (1/m²)|
|:------|:-------------------|---------:|
Expand Down Expand Up @@ -77,6 +76,8 @@ This report documents the analysis of forest data for different tree species.
{{< include appendix/nearest_1.qmd >}}
{{< include appendix/nearest_100.qmd >}}
{{< include appendix/nearest_avg.qmd >}}
{{< include appendix/number_of_returns.qmd >}}


## Documentation
{{< include appendix/package-docs/docs.qmd >}}
Expand Down
33 changes: 33 additions & 0 deletions results/results/number_of_returns.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Distribution of number of returns per detected tree.

```{r}
#| code-fold: true
#| warning: false
#| results: hide
data <- sf::st_read("data/tree_properties.gpkg")
neighbors <- lfa::lfa_get_neighbor_paths() |> lfa::lfa_combine_sf_obj(lfa::lfa_get_all_areas())
data = sf::st_join(data,neighbors, join = sf::st_within)
```
Examining the distribution of LiDAR returns per tree is the focus of our current investigation. Initial analysis involves the study of density graphs representing the distribution of LiDAR returns. The density curves for each species exhibit distinct peaks corresponding to their respective species, providing a clear differentiation in LiDAR return patterns. Notably, there is an exception observed in the Brilon patch (Spruce), where the curve deviates, possibly indicative of variations in forest age. A noteworthy trend is the divergent shape of density curves between coniferous and deciduous trees. Conifers exhibit steeper curves, indicating lower density for higher return values compared to deciduous trees. This disparity underscores the potential of LiDAR data to distinguish between tree types based on return density characteristics. In the case of Beech trees, the peaks' heights vary among different curves, suggesting nuanced variations within the species. Despite these differences, all species consistently peak in similar regions, emphasizing the overarching similarities in LiDAR return patterns across diverse tree species.

```{r}
#| code-fold: true
#| warning: false
#| label: fig-density-number-returns
#| fig-cap: Density of the amount of LiDAR returns per detectected tree. Splitted by the different researched areas and grouped by the dominant specie in this area.
lfa::lfa_create_density_plots(data, value_column = "number_of_returns", category_column1 = "area", category_column2 = "specie", title = "Density of the distribution of LiDAR returns per individual tree", xlims = c(0,10000))
```

Currently, our investigation focuses on boxplots representing each patch. We observe significant size variations among plots within the same species. Notably, numerous outliers are present above the box in each patch. For Pines, the boxes exhibit a notable similarity. However, the box for Brilon is entirely shifted from other boxes associated with patches featuring Spruce forest.

```{r}
#| code-fold: true
#| warning: false
#| label: fig-boxplot-number-returns
#| fig-cap: Boxplots of the the amount of LiDAR returns per detectected tree. Splitted by the different researched areas and grouped by the dominant specie in this area.
lfa::lfa_create_boxplot(data, value_column = "number_of_returns", category_column1 = "area", category_column2 = "specie", title = "Boxplots of the distribution of LiDAR returns per individual tree")
```

Overall, our analysis reveals very low results for both Kullback-Leibler Divergence (KLD) and Jensen-Shannon Divergence (JSD) metrics across different species. Within species, there is high explainability observed for the different LiDAR return curves between patches.

This suggests that the number of returns alone may not be a robust predictor for identifying the dominant species in a forest. However, the curves indicate a clear potential for distinguishing between conifers (Pine and Spruce) and deciduous trees (Beech and Oak) based on the number of returns. This observation is further supported by the JSD scores, as detailed in @tbl-number-of-returns-jsd_specie.

0 comments on commit ecc1030

Please sign in to comment.