install.packages("sits", dependencies = TRUE)
Setup
This book contains reproducible code that can be run in both R and Python environments. The sits
package is primarily developed in R, with Python support provided through a wrapper that uses the R environment.
Configuring the base environment for R and Python
The R environment is the foundation for sits
and must be installed regardless of whether you plan to use R or Python interfaces.
To use this book, you need an R environment configured with the following tools: including:
- R Programming Language
- System Dependencies
- The
sits
R package - The
sitsdata
data package (for examples)
The sections below outline how you can install these tools.
Installing R
Download and install the latest version of R for your operating system:
Download the installer from CRAN Windows
Download from CRAN macOS
Use your distribution’s package manager or download from CRAN Linux
Install RStudio for R users
RStudio provides an integrated development environment (IDE) for R, available for Linux, macOS and Windows, offering a code editor, plot preview, debugging tools, package management, and more. You can download RStudio from the Posit website.
Installing RStudio is optional, as you can use R in any other IDE or code editor. However, it is recommended for R users as it offers a very easy-to-use environment and amazing integration with the R Package ecossystem.
Installing SITS in R
The sits
package is available through the Comprehensive R Archive Network (CRAN), which is the official distribution channel for R packages.
macOS and Windows users should install binary packages from CRAN. The installation process requires specific dependencies to be installed in the correct order.
Some dependencies from the sits
package may cause errors during installation, as they require compilation. If you encounter this issue, there are additional tools that can help. For source compilation on Windows, install Rtools. For macOS, follow the instructions at mac.r-project.org/tools/.
Linux installations require system-level dependencies to be installed first.
Step 1: Install system dependencies
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libudunits2-dev \
\
libgdal-dev \
libgeos-dev \
libproj-dev \
gdal-bin proj-bin
If you encounter PPA repository errors, install the required package first:
sudo apt-get install software-properties-common
Step 2: Install sits
install.packages("sits", dependencies = TRUE)
Step 1: Install system dependencies
sudo dnf install gdal \
\
gdal-devel \
proj-devel \
geos-devel \
sqlite-devel udunits2-devel
Step 2: Install sits
install.packages("sits", dependencies = TRUE)
For other Linux distributions, we recommend using Docker containers or following the distribution-specific GDAL installation guides.
Installing the R sitsdata package
Examples in this book use open data available in the sitsdata package. This package is freely available on GitHub, and can be installed in Linux, macOS and Windows, as follows:
1. Increase the network timeout time
options(timeout = 300) # Set network timeout to 5 minutes
2. Install sitsdata
devtools::install_github("e-sensing/sitsdata")
Configuring the Python environment
The Python API uses the R implementation, so R must be installed before setting up the Python environment.
The Python interface for sits
is as a wrapper around the R implementation. It gives Python users access to the all features of the sits
package. This section outlines the available options for installing it.
Prerequisites
To use sits
in Python, you must fill the following prerequisites:
- R environment, including dependencies.
- Arrow package in R
- Python 3.10 or higher
Install Python
Download and install the latest version of Python for your operating system:
Download the installer from the Python website
Download the installer from the Python website
Use your distribution’s package manager or download from the Python website
Installing arrow in R
To transfer objects between R and Python, the Apache Arrow is used. Therefore, to take advantage of its features, it must be installed in your R environment. You can install it using the following command:
install.packages('arrow')
Installing SITS in Python
The sits
package is available in the PyPi, and can be installing using the following tools:
In your terminal, run:
pip install pysits
In your terminal, run:
1. Create virtual environment
python -m venv venv
2. Activate environment
source venv/bin/activate # or .venv\Scripts\activate on Windows
3. Install pysits
pip install pysits
If you’d like to learn more about Python virtual environments, please refer to the official Python documentation on the topic.
Development versions
Apart from the official versions of sits
available on CRAN and PyPI, as described above, users who want to preview features planned for future releases have the option to install the development version.
Using the development version is recommended for advanced users or those comfortable with troubleshooting within the sits
ecosystem.
You can install development versions in R and Python, using the following commands:
In your terminal, run:
devtools::install_github("e-sensing/sits@dev", dependencies = TRUE)
In your terminal, run:
pip install git+https://github.com/e-sensing/pysits.git@dev
GPU Support for Deep Learning
For users working with deep learning models, sits
supports GPU acceleration through the torch package, which is already included as a dependency when you install sits
. This provides significant performance improvements for deep learning operations.
Automatic GPU detection:
The torch
package automatically detects available GPUs and utilizes them when possible, requiring no additional configuration in most cases.
System requirements:
- NVIDIA CUDA toolkit
- Compatible NVIDIA GPU
- Appropriate GPU drivers
GPU configuration:
To use GPU in sits
with torch
you must have an environment with proper configuration of the NVIDIA toolkit, including:
- CUDA installation: Ensure CUDA toolkit is properly installed and accessible
- Driver compatibility: Verify NVIDIA drivers are compatible with your CUDA version
For more details on GPU setup instructions and troubleshooting, refer to the torch documentation.