Skip to content

Commit

Permalink
Bump README
Browse files Browse the repository at this point in the history
 - suggest venv, do not suggest miniconda
  • Loading branch information
brownag committed Nov 21, 2023
1 parent db9f23b commit 8a29c8b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
21 changes: 16 additions & 5 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ If you specify field capacity water content, you must specify bulk density. If y

If you are using this package for the first time you will need to have Python installed and you will need to download the necessary modules.

You can set up {reticulate} to install modules into a virtual or Conda environment. {reticulate} offers `reticulate::install_python()` and `reticulate::install_miniconda()` to download and set up Python/Conda if you have not yet done so.
You can set up {reticulate} to install modules into a virtual environment. {reticulate} offers `reticulate::install_python()` to download and set up Python if you have not yet done so.

For example, install a recent version of Python, and create a virtual environment called `"r-reticulate"`

```{r, eval = FALSE}
# download latest python 3.10.x
reticulate::install_python(version = "3.10:latest")
reticulate::virtualenv_create("r-reticulate")
```

### Finding the `python` binaries

Expand All @@ -90,17 +98,19 @@ rosettaPTF::find_python()

The first attempt makes use of `Sys.which()` to find installations available in the user path directory.

<!--
`find_python()` also provides an option for using ArcGIS Pro Conda environments--which may be needed for users who cannot install Conda by some other means. To use this option specify the `arcpy_path` argument or the `rosettaPTF.arcpy_path` option to locate both the ArcGIS Pro Conda environment and Python binaries in _C:/Program Files/ArcGIS/Pro/bin/Python_, for example:
```{r, eval=FALSE}
rosettaPTF::find_python(arcpy_path = "C:/Program Files/ArcGIS/Pro/bin/Python")
```
-->

If automatic configuration via `find_python()` fails (returns `NULL`) you can manually set a path to the `python` executable with the {reticulate} `RETICULATE_PYTHON` environment variable: `Sys.setenv(RETICULATE_PYTHON = "path/to/python")` or `reticulate::use_python("path/to/python")`

### Install `rosetta-soil` Python Module

The {rosettaPTF} `install_rosetta()` method wraps `reticulate::py_install("rosetta-soil")`.
The {rosettaPTF} `install_rosetta()` method wraps `reticulate::py_install("rosetta-soil")`. You may not need to install the `rosetta-soil` module if your environment is set up, as {reticulate} will install/upgrade dependencies of packages as specified in the package configuration section of the DESCRIPTION file.

You can use `install_rosetta()` to install into custom environments by specifying `envname` as needed. After installing a new version of the module you should restart your R session.

Expand Down Expand Up @@ -165,11 +175,12 @@ soildata <- resprop[complete.cases(resprop), c("mukey", varnames)]
system.time(resrose <- run_rosetta(soildata[,varnames]))
# transfer mukey to result
resrose$mukey <- soildata$mukey
resprop$mukey <- as.numeric(resprop$mukey)
resrose$mukey <- as.numeric(soildata$mukey)
# merge property (input) and rosetta parameters (output) into RAT
levels(res) <- merge(cats(res)[[1]], resprop, by = "mukey", all.x = TRUE)
levels(res) <- merge(cats(res)[[1]], resrose, by = "mukey", all.x = TRUE)
levels(res) <- merge(cats(res)[[1]], resprop, by.x = "ID", by.y = "mukey", all.x = TRUE, sort = FALSE)
levels(res) <- merge(cats(res)[[1]], resrose, by.x = "ID", by.y = "mukey", all.x = TRUE, sort = FALSE)
# convert categories based on mukey to numeric values
res2 <- catalyze(res)
Expand Down
56 changes: 33 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,24 @@ also specify bulk density and field capacity water content.
If you are using this package for the first time you will need to have
Python installed and you will need to download the necessary modules.

You can set up {reticulate} to install modules into a virtual or Conda
environment. {reticulate} offers `reticulate::install_python()` and
`reticulate::install_miniconda()` to download and set up Python/Conda if
you have not yet done so.
You can set up {reticulate} to install modules into a virtual
environment. {reticulate} offers `reticulate::install_python()` to
download and set up Python if you have not yet done so.

For example, install a recent version of Python, and create a virtual
environment called `"r-reticulate"`

``` r
# download latest python 3.10.x
reticulate::install_python(version = "3.10:latest")
reticulate::virtualenv_create("r-reticulate")
```

### Finding the `python` binaries

``` r
rosettaPTF::find_python()
#> [1] "C:/Users/Andrew/Documents/.virtualenvs/r-reticulate/Scripts/python.exe"
#> [1] "C:/Users/Andrew/OneDrive/Documents/.virtualenvs/r-reticulate/Scripts/python.exe"
```

`find_python()` provides heuristics for setting up {reticulate} to use
Expand All @@ -122,16 +130,14 @@ Python in commonly installed locations.
The first attempt makes use of `Sys.which()` to find installations
available in the user path directory.

`find_python()` also provides an option for using ArcGIS Pro Conda
environments–which may be needed for users who cannot install Conda by
some other means. To use this option specify the `arcpy_path` argument
or the `rosettaPTF.arcpy_path` option to locate both the ArcGIS Pro
Conda environment and Python binaries in *C:/Program
Files/ArcGIS/Pro/bin/Python*, for example:
<!--
`find_python()` also provides an option for using ArcGIS Pro Conda environments--which may be needed for users who cannot install Conda by some other means. To use this option specify the `arcpy_path` argument or the `rosettaPTF.arcpy_path` option to locate both the ArcGIS Pro Conda environment and Python binaries in _C:/Program Files/ArcGIS/Pro/bin/Python_, for example:
``` r
```r
rosettaPTF::find_python(arcpy_path = "C:/Program Files/ArcGIS/Pro/bin/Python")
```
-->

If automatic configuration via `find_python()` fails (returns `NULL`)
you can manually set a path to the `python` executable with the
Expand All @@ -142,16 +148,19 @@ you can manually set a path to the `python` executable with the
### Install `rosetta-soil` Python Module

The {rosettaPTF} `install_rosetta()` method wraps
`reticulate::py_install("rosetta-soil")`.
`reticulate::py_install("rosetta-soil")`. You may not need to install
the `rosetta-soil` module if your environment is set up, as {reticulate}
will install/upgrade dependencies of packages as specified in the
package configuration section of the DESCRIPTION file.

You can use `install_rosetta()` to install into custom environments by
specifying `envname` as needed. After installing a new version of the
module you should restart your R session.

``` r
rosettaPTF::install_rosetta()
#> Using virtual environment "C:/Users/Andrew/Documents/.virtualenvs/r-reticulate" ...
#> + "C:/Users/Andrew/Documents/.virtualenvs/r-reticulate/Scripts/python.exe" -m pip install --upgrade --no-user "rosetta-soil"
#> Using virtual environment "C:/Users/Andrew/OneDrive/Documents/.virtualenvs/r-reticulate" ...
#> + "C:/Users/Andrew/OneDrive/Documents/.virtualenvs/r-reticulate/Scripts/python.exe" -m pip install --upgrade --no-user rosetta-soil
#> [1] TRUE
```

Expand Down Expand Up @@ -227,7 +236,7 @@ results (1:1 with `mukey`).
``` r
library(soilDB)
library(terra)
#> terra 1.6.17
#> terra 1.7.55
library(rosettaPTF)

# obtain mukey map from SoilWeb Web Coverage Service (800m resolution SSURGO derived)
Expand All @@ -246,14 +255,15 @@ soildata <- resprop[complete.cases(resprop), c("mukey", varnames)]
# run Rosetta on the mapunit-level aggregate data
system.time(resrose <- run_rosetta(soildata[,varnames]))
#> user system elapsed
#> 0.2 0.0 0.2
#> 0.19 0.03 0.22

# transfer mukey to result
resrose$mukey <- soildata$mukey
resprop$mukey <- as.numeric(resprop$mukey)
resrose$mukey <- as.numeric(soildata$mukey)

# merge property (input) and rosetta parameters (output) into RAT
levels(res) <- merge(cats(res)[[1]], resprop, by = "mukey", all.x = TRUE)
levels(res) <- merge(cats(res)[[1]], resrose, by = "mukey", all.x = TRUE)
levels(res) <- merge(cats(res)[[1]], resprop, by.x = "ID", by.y = "mukey", all.x = TRUE, sort = FALSE)
levels(res) <- merge(cats(res)[[1]], resrose, by.x = "ID", by.y = "mukey", all.x = TRUE, sort = FALSE)

# convert categories based on mukey to numeric values
res2 <- catalyze(res)
Expand All @@ -262,7 +272,7 @@ res2 <- catalyze(res)
plot(res2, "log10_Ksat_mean")
```

<img src="man/figures/README-unnamed-chunk-9-1.png" width="100%" />
<img src="man/figures/README-unnamed-chunk-10-1.png" width="100%" />

### *SpatRaster* (terra) Input Example

Expand All @@ -287,13 +297,13 @@ res3 <- rast(list(
# SpatRaster to data.frame interface (one call on all cells)
system.time(test2 <- run_rosetta(res3))
#> user system elapsed
#> 41.98 9.25 49.46
#> 51.77 5.69 56.06

# make a plot of the predicted Ksat (identical to mukey-based results)
plot(test2, "log10_Ksat_mean")
```

<img src="man/figures/README-unnamed-chunk-10-1.png" width="100%" />
<img src="man/figures/README-unnamed-chunk-11-1.png" width="100%" />

You will notice the results for Ksat distribution are identical since
the same input values were used, but the latter approach took longer to
Expand Down
Binary file modified man/figures/README-unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added man/figures/README-unnamed-chunk-11-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed man/figures/README-unnamed-chunk-9-1.png
Binary file not shown.

0 comments on commit 8a29c8b

Please sign in to comment.