A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

smapr

An R package for acquisition and processing of NASA (Soil Moisture Active-Passive) SMAP data.
https://github.com/ropensci/smapr

Category: Natural Resources
Sub Category: Soil and Land

Keywords

acquisition extract-data nasa peer-reviewed r r-package raster rstats smap-data soil-mapping soil-moisture soil-moisture-sensor

Last synced: about 23 hours ago
JSON representation

Repository metadata

An R package for acquisition and processing of NASA SMAP data

README.Rmd

          ---
title: "smapr"
output: github_document
---

[![codecov](https://codecov.io/gh/ropensci/smapr/branch/master/graph/badge.svg)](https://codecov.io/gh/ropensci/smapr)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/smapr)](https://cran.r-project.org/package=smapr)
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
[![](http://cranlogs.r-pkg.org/badges/grand-total/smapr)](http://cran.rstudio.com/web/packages/smapr/index.html) 
[![](https://badges.ropensci.org/231_status.svg)](https://github.com/ropensci/onboarding/issues/231)
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)


```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/"
)
```


An R package for acquisition and processing of [NASA (Soil Moisture Active-Passive) SMAP data](http://smap.jpl.nasa.gov/)

## Installation

To install smapr from CRAN: 

```{r cran-installation, eval = FALSE}
install.packages("smapr")
```

To install the development version from GitHub:

```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("ropensci/smapr")
```

#### Docker instructions (alternative to a local installation)

If a local installation is not possible for some reason, we have made a Docker 
image available with smapr and all its dependencies.

```
docker run -d -p 8787:8787 earthlab/smapr
```

In a web browser, navigate to localhost:8787 and log in with 
username: rstudio, password: rstudio.


## Authentication

Access to the NASA SMAP data requires authentication through NASA's Earthdata 
portal. 
If you do not already have a username and password through Earthdata, you can 
register for an account here: https://urs.earthdata.nasa.gov/
You cannot use this package without an Earthdata account. 

Once you have an account, you need to pass your Earthdata username (`ed_un`) 
and password (`ed_pw`) as environmental variables that can be read from within 
your R session. 
There are a couple of ways to do this: 

### Recommended approach

Use `set_smap_credentials('yourusername', 'yourpasswd')`. 
This will save your credentials by default, overwriting existing credentials if 
`overwrite = TRUE`. 

#### Alternative approaches

- Use `Sys.setenv()` interactively in your R session to set your username and 
password (not including the `<` and `>`):

```{r, eval = FALSE}
Sys.setenv(ed_un = "", ed_pw = "")
```

- Create a text file `.Renviron` in your home directory, which contains your 
username and password. 
If you don't know what your home directory is, execute `normalizePath("~/")` in 
the R console and it will be printed.
Be sure to include a new line at the end of the file or R will fail silently 
when loading it.

Example `.Renviron file` (note the new line at the end!):

```
ed_un=slkdjfsldkjfs
ed_pw=dlfkjDD124^

```

Once this file is created, restart your R session and you should now be able to 
access these environment variables (e.g., via `Sys.getenv("ed_un")`).



# SMAP data products

Multiple SMAP data products are provided by the NSIDC, and these products vary 
in the amount of processing. 
Currently, smapr primarily supports level 3 and level 4 data products, 
which represent global daily composite and global three hourly modeled data 
products, respectively. 
There are a wide variety of data layers available in SMAP products, including surface soil moisture, root zone soil moisture, freeze/thaw status, surface temperature, vegetation water content, vegetation opacity, net ecosystem carbon exchange, soil temperature, and evapotranspiration. 
NSIDC provides documentation for all SMAP data products on their 
[website](https://nsidc.org/data/smap/smap-data.html), and we provide a summary 
of data products supported by smapr below. 

| Dataset id | Description                                         | Resolution |
|------------|-----------------------------------------------------|------------|
| SPL2SMAP_S | SMAP/Sentinel-1 Radiometer/Radar Soil Moisture      | 3 km       |
| SPL3FTA    | Radar Northern Hemisphere Daily Freeze/Thaw State   | 3 km       |
| SPL3SMA    | Radar Global Daily Soil Moisture                    | 3 km       |
| SPL3SMP    | Radiometer Global Soil Moisture                     | 36 km      |
| SPL3SMAP   | Radar/Radiometer Global Soil Moisture               | 9 km       |
| SPL4SMAU   | Surface/Rootzone Soil Moisture Analysis Update      | 9 km       | 
| SPL4SMGP   | Surface/Rootzone Soil Moisture Geophysical Data     | 9 km       |
| SPL4SMLM   | Surface/Rootzone Soil Moisture Land Model Constants | 9 km       |
| SPL4CMDL   | Carbon Net Ecosystem Exchange                       | 9 km       |

## Typical workflow

At a high level, most workflows follow these steps:

1. Find SMAP data with `find_smap()`
2. Download data with `download_smap()`
3. List data contents with `list_smap()`
4. Extract data with `extract_smap()`

Each of these steps are outlined below:

### Finding SMAP data

Data are hosted on a server by the National Snow and Ice Data Center. 
The `find_smap()` function searches for specific data products and returns a 
data frame of available data.
As data mature and pass checks, versions advance. 
At any specific time, not all versions of all datasets for all dates may exist. 
For the most up to date overview of dataset versions, see the NSIDC SMAP data 
version [webpage](https://nsidc.org/data/smap/smap-data.html).

```{r find-data}
library(smapr)
library(terra)
available_data <- find_smap(id = "SPL3SMAP", date = "2015-05-25", version = 3)
str(available_data)
```

### Downloading and inspecting SMAP data

Given a data frame produced by `find_smap`, `download_smap` downloads the data 
onto the local file system. 
Unless a directory is specified as an argument, the data are stored in the 
user's cache. 

```{r download-data}
downloads <- download_smap(available_data)
str(downloads)
```

The SMAP data are provided in HDF5 format, and in any one file there are 
actually multiple data sets, including metadata. 
The `list_smap` function allows users to inspect the contents of downloaded 
data at a high level (`all = FALSE`) or in depth (`all = TRUE`). 

```{r list-data}
list_smap(downloads, all = FALSE)
```

To see all of the data fields, set `all = TRUE`. 

### Extracting gridded data products

The `extract_smap` function extracts gridded data products 
(e.g., global soil moisture). 
If more than one file has been downloaded and passed into the first argument, `extract_smap` extracts data for each file

```{r extract-data, fig.align='center', fig.width=8, fig.height=7}
sm_raster <- extract_smap(downloads, "Soil_Moisture_Retrieval_Data/soil_moisture")
plot(sm_raster, main = "Level 3 soil moisture: May 25, 2015")
```

The path "Soil_Moisture_Retrieval_Data/soil_moisture" was determined from the 
output of `list_smap(downloads, all = TRUE)`, which lists all of the data 
contained in SMAP data files. 

### Saving GeoTIFF output

The data can be saved as a GeoTIFF using the `writeRaster` function 
from the terra pacakge. 

```{r}
writeRaster(sm_raster, "sm_raster.tif")
```

```{r, echo = FALSE, results='hide'}
# cleanup
file.remove("sm_raster.tif")
```


## Meta

* Please [report any issues or bugs](https://github.com/ropensci/smapr/issues),
after reading our contribution [guidelines](CONTRIBUTING.md), and the 
[Contributor Code of Conduct](CONDUCT.md). 
* License: GPL-3
* See `citation("smapr")` in R to cite this package in publications. 

[![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org)

        

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 6 days ago

Total Commits: 258
Total Committers: 5
Avg Commits per committer: 51.6
Development Distribution Score (DDS): 0.062

Commits in past year: 8
Committers in past year: 1
Avg Commits per committer in past year: 8.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Max Joseph m****h@g****m 242
Max Joseph m****h@p****m 8
matt-oak m****k@l****m 5
Zach Schira Z****a 2
rOpenSci Bot m****t@g****m 1

Committer domains:


Issue and Pull Request metadata

Last synced: 2 days ago

Total issues: 44
Total pull requests: 37
Average time to close issues: about 2 months
Average time to close pull requests: about 14 hours
Total issue authors: 20
Total pull request authors: 3
Average comments per issue: 1.16
Average comments per pull request: 0.89
Merged pull request: 36
Bot issues: 0
Bot pull requests: 0

Past year issues: 2
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 2
Past year pull request authors: 0
Past year average comments per issue: 1.0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/ropensci/smapr

Top Issue Authors

  • mbjoseph (23)
  • thiagoveloso (2)
  • rsbivand (2)
  • RomanChapman (1)
  • Vinit-Sehgal (1)
  • ferguskeatinge (1)
  • djaiswal (1)
  • matt-oak (1)
  • rnelson26 (1)
  • wsn19930220 (1)
  • MDunsker (1)
  • MxNl (1)
  • mingsnu (1)
  • bappa10085 (1)
  • nithya255 (1)

Top Pull Request Authors

  • mbjoseph (31)
  • matt-oak (5)
  • zschira (1)

Top Issue Labels

  • enhancement (16)
  • documentation (7)
  • bug (3)
  • help wanted (2)
  • wontfix (1)

Top Pull Request Labels


Package metadata

cran.r-project.org: smapr

Acquisition and Processing of NASA Soil Moisture Active-Passive (SMAP) Data

  • Homepage: https://github.com/ropensci/smapr
  • Status: removed
  • Documentation: http://cran.r-project.org/web/packages/smapr/smapr.pdf
  • Licenses: GPL-3
  • Latest release: 0.2.1 (published about 6 years ago)
  • Last Synced: 2025-04-25T12:31:07.810Z (2 days ago)
  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 427 Last month
  • Docker Downloads: 34
  • Rankings:
    • Forks count: 3.202%
    • Stargazers count: 4.911%
    • Average: 19.77%
    • Dependent repos count: 24.282%
    • Dependent packages count: 27.826%
    • Downloads: 38.628%
  • Maintainers (1)

Dependencies

DESCRIPTION cran
  • R >= 3.2.5 depends
  • hdf5r * imports
  • httr >= 1.1.0 imports
  • rappdirs >= 0.3.1 imports
  • raster >= 2.5 imports
  • rvest * imports
  • xml2 * imports
  • covr * suggests
  • knitr * suggests
  • rgdal * suggests
  • rmarkdown * suggests
  • roxygen2 * suggests
  • sp * suggests
  • testthat * suggests
  • utils * suggests
.github/workflows/tic.yml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v2 composite
  • pat-s/always-upload-cache v3 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-tinytex v2 composite

Score: 12.237958834392495