Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete rewrite of the Ecology chapter #771

Merged
merged 81 commits into from
Apr 18, 2022
Merged

Complete rewrite of the Ecology chapter #771

merged 81 commits into from
Apr 18, 2022

Conversation

jannes-m
Copy link
Collaborator

@jannes-m jannes-m commented Apr 14, 2022

Hello everyone,

in this PR I have:

  • converted everything from mlr to mlr3
  • replaced raster by terra
  • replaced RQGIS by qgisprocess
  • adjusted the text accordingly
  • updated the exercises accordingly

To keep in mind:

  • this branch only works with the github version of spDataLarge
  • DESCRIPTION file of geocompkg needs to be udpated (mlr3packages and alike are still missing) -> should I put in a corresponding geocompkg PR (would be probably the best solution)?
  • before merging this branch, we should merge rewrite_cv since rewrite_eco is a child branch of rewrite_cv. The only thing I haven’t done in rewrite_cv apart from a few other minor things is to run mlr3::benchmark() because it will probably take ages to finish...

@Robinlovelace Robinlovelace marked this pull request as ready for review April 15, 2022 19:12
@Robinlovelace
Copy link
Collaborator

Many thanks @jannes-m this looks like an impressive piece of work. Will take a look now.

@Robinlovelace
Copy link
Collaborator

First step: fix merge conflicts with the main branch. I'll give that a go now but may need your assistance @jannes-m if there are any ambiguities..

@Robinlovelace
Copy link
Collaborator

Seems this will merge it:

git checkout main
git merge --no-ff rewrite_eco
git push origin main

@@ -116,7 +116,7 @@ With a wide range of packages, R also supports advanced geospatial statistics\in
\index{R!language}
New integrated development environments (IDEs\index{IDE}) such as RStudio\index{RStudio} have made R more user-friendly for many, easing map making with a panel dedicated to interactive visualization.

At its core, R is an object-oriented, [functional programming language](http://adv-r.had.co.nz/Functional-programming.html) [@wickham_advanced_2019], and was specifically designed as an interactive interface to other software [@chambers_extending_2016].
At its core, R is an object-oriented, [functional programming language](https://adv-r.hadley.nz/fp.html) [@wickham_advanced_2019], and was specifically designed as an interactive interface to other software [@chambers_extending_2016].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -6,21 +6,25 @@ This chapter assumes proficiency with geographic data analysis\index{geographic
A familiarity with generalized linear models (GLM)\index{GLM} and machine learning\index{machine learning} is highly recommended [for example from @zuur_mixed_2009;@james_introduction_2013].

The chapter uses the following packages:^[
Package **kernlab**, **pROC**, **RSAGA**\index{RSAGA (package)} and **spDataLarge** must also be installed although these do not need to be attached.
Packages **GGally**, **lgr**, **kernlab**, **ml3measures**, **paradox**, **pROC**, **progressr** and **spDataLarge** must also be installed although these do not need to be attached.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

library(sf)
library(raster)
library(terra)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

library(mlr)
library(parallelMap)
```{r 12-spatial-cv-1-2, eval=FALSE}
library(future)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New dependency I think. We should update geocompkg DESCRIPTION if so.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See PR here: geocompx/geocompkg#32

@@ -69,83 +73,64 @@ Spatial CV\index{cross-validation!spatial CV} alleviates this problem and is the
## Case study: Landslide susceptibility {#case-landslide}

This case study is based on a dataset of landslide locations in Southern Ecuador, illustrated in Figure \@ref(fig:lsl-map) and described in detail in @muenchow_geomorphic_2012.
A subset of the dataset used in that paper is provided in the **RSAGA**\index{RSAGA (package)} package, which can be loaded as follows:
A subset of the dataset used in that paper is provided in the **spDataLarge**\index{spDataLarge (package)} package, which can be loaded as follows:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

library(dplyr)
library(mlr3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment: I suggest not loading all of these, some can be used with pkg::fun().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably won't work. For example, you need to attach mlr3spatiotempcv to make available the spatial partitioning stuff used in mlr3::rsmp(). Equally, you need to attach mlr3learners and mlr3extralearners to make available additional learners. And the autoplot() function will only work with benchmark results if you have previoulsy attached mlr3viz to make the autoplot(). And there are more examples.

@@ -40,7 +47,7 @@ In this chapter we will demonstrate ecological applications of some of the techn
This case study will involve analyzing the composition and the spatial distribution of the vascular plants on the southern slope of Mt. Mongón, a *lomas* mountain near Casma on the central northern coast of Peru (Figure \@ref(fig:study-area-mongon)).

```{r study-area-mongon, echo=FALSE, fig.cap="The Mt. Mongón study area, from Muenchow, Schratz, and Brenning (2017).", out.width="60%", fig.scap="The Mt. Mongón study area."}
knitr::include_graphics("figures/study-area-mongon.png")
knitr::include_graphics("figures/15_study_area_mongon.png")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

dplyr::pull(dem)
# rotating NMDS in accordance with altitude (proxy for humidity)
rotnmds = MDSrotate(nmds, elev)
rotnmds = vegan::MDSrotate(nmds, elev)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

library(ranger)
library(sf)
library(terra)
library(tree)
library(vegan)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to load it if we're using it below with vegan::?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not

library(progressr)
library(qgisprocess)
library(terra)
library(tictoc)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New dep. See geocompx/geocompkg#32

@Robinlovelace
Copy link
Collaborator

These are major changes but they are clearly good ones. I would err on the side of merging soon and tidying up early? Thoughts welcome @jannes-m and @Nowosad, there are a few suggestions in my comments above that may be worth conversation but overall pretty non-controversial stuff. Really happy to see this moving forward.

@jannes-m
Copy link
Collaborator Author

First step: fix merge conflicts with the main branch. I'll give that a go now but may need your assistance @jannes-m if there are any ambiguities..

Acutally, there shouldn't be any merge conflicts with the main branch since I harmonized with the main branch regularly but well, you never know....

@jannes-m
Copy link
Collaborator Author

Robin, thanks for your review! I have polished further chapters 12 and 15. And I think we can merge, and fix soon if something goes amiss as you have proposed!

@jannes-m
Copy link
Collaborator Author

FYI: will compile the book locally and try to resolve all issues occurring in chapters 12 and 14. Will try to do so this night.

@jannes-m
Copy link
Collaborator Author

mmh, there are still problems when trying to read mlr3 benchmark output results via readRDS() when knitting. Not yet sure how to solve this since it works when running readRDS() on the same files in the console. Probably I need to ask the mlr3 team and in the meantime we hard-code the results (though this is neither elegant nor reproducible). But now I need to get some sleep...

@jannes-m
Copy link
Collaborator Author

ok, I think I have found a better solution. I will implement it in the coming days.

@Robinlovelace Robinlovelace merged commit 92c3492 into main Apr 18, 2022
@Robinlovelace Robinlovelace deleted the rewrite_eco branch April 18, 2022 14:41
@Robinlovelace
Copy link
Collaborator

Thanks for this mega PR Jannes, great to have it merged to keep the momentum going. We can do post merge fixes!

@Nowosad plans to do a post merge review, should be easier with reference to the updated version online.

@jannes-m jannes-m mentioned this pull request Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants