{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "kernelspec": { "name": "ir", "display_name": "R", "language": "R" }, "language_info": { "name": "R" }, "colab": { "provenance": [] } }, "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Module 0 · Check your Colab setup\n", "**SoilFER Training** · [Course page](https://training.yigini.net/modules/00-welcome/)\n", "\n", "1. The runtime must be **R**: *Runtime → Change runtime type → R*.\n", "2. Run the **Setup** cell (≈1–3 minutes), then the check cells, with **Shift + Enter**.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "# ==== SoilFER · Colab setup (run first, once per session) ==================\n", "options(repos = c(CRAN = \"https://cloud.r-project.org\"), timeout = 3600)\n", "root <- \"/content/SoilFER-Training-Resources\"\n", "\n", "# 1. Training project (scripts, small data, outputs, assignments)\n", "if (!dir.exists(root))\n", " system(paste(\"git clone --depth 1 https://github.com/SoilFER/SoilFER-Training-Resources\", root))\n", "\n", "# 2. R packages — Colab's R runtime installs CRAN binaries through apt (r2u), so this is fast\n", "pkgs <- c(\"terra\", \"sf\", \"tidyverse\", \"readxl\")\n", "need <- setdiff(pkgs, rownames(installed.packages()))\n", "if (length(need)) install.packages(need)\n", "\n", "# 3. Course rasters + MIR spectra (Google Drive folder of the SoilFER training, ≈1.2 GB)\n", "td <- file.path(root, \"01_data/module1/training_data\")\n", "if (!file.exists(file.path(td, \"MIR_KANSAS_data.xlsx\"))) {\n", " system(\"python3 -m pip -q install gdown\")\n", " system(\"python3 -m gdown --folder --quiet https://drive.google.com/drive/folders/1K7tq9zX5HsqbqWcNoT27WtfPtehcKBCu -O /content/soilfer_drive\")\n", " f <- list.files(\"/content/soilfer_drive\", recursive = TRUE, full.names = TRUE)\n", " file.copy(f, td, overwrite = FALSE)\n", "}\n", "\n", "setwd(root)\n", "cat(\"Ready. Working folder:\", getwd(), \"\\n\")\n", "missing <- setdiff(pkgs, rownames(installed.packages()))\n", "if (length(missing)) message(\"Not installed: \", paste(missing, collapse = \", \"))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. R and the spatial packages" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "R.version.string\n", "library(terra); library(sf); library(tidyverse); library(readxl)\n", "cat(\"terra\", as.character(packageVersion(\"terra\")), \"| GDAL\", sf::sf_extSoftVersion()[[\"GDAL\"]], \"\\n\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. The training project and data" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "list.files()\n", "list.files(\"01_data/module1/training_data\", pattern = \"\\\\.(tif|xlsx)$\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Soil data: KSSL topsoil table" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "kssl <- read_csv(\"03_outputs/module1/KSSL_DSM_0-30.csv\", show_col_types = FALSE)\n", "glimpse(kssl)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. A first map: elevation and soil sampling points" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "dem <- rast(\"01_data/module1/training_data/DEM_KANSAS.tif\")\n", "pts <- vect(kssl, geom = c(\"lon\", \"lat\"), crs = \"EPSG:4326\")\n", "pts <- project(pts, crs(dem))\n", "plot(dem, main = \"Kansas: elevation and KSSL sampling points\")\n", "points(pts, pch = 20, cex = .5)\n", "cat(\"All good, you are ready for Module 1.\\n\")\n" ] } ] }