Package 'luna'

Title: Tools for Satellite Remote Sensing (Earth Observation) Data Processing
Description: Tools for acquiring and (pre-) processing satellite remote sensing data. Including for downloading data from NASA such as LANDSAT and MODIS.
Authors: Robert J. Hijmans [cre, aut] (ORCID: <https://orcid.org/0000-0001-5872-2872>), Aniruddha Ghosh [aut], Alex Mandel [ctb], Benson Kenduiywo [ctb], Jakob Schwalb-Willmann [ctb]
Maintainer: Robert J. Hijmans <[email protected]>
License: GPL (>=3)
Version: 0.4-1
Built: 2026-06-06 23:13:17 UTC
Source: https://github.com/rspatial/luna

Help Index


Tools for Satellite Remote Sensing (Earth Observation) Data Processing

Description

Tools for acquiring and (pre-) processing satellite remote sensing data. Including for downloading data from NASA such as LANDSAT and MODIS.


Gapfill and filter time series satellite data

Description

Estimate missing values using smooth gap-filled time series data with a two-stage Savitzky-Golay smoothing filter.

Usage

filterVI(x, ...)

  fillVI(x, method = "natural")

Arguments

x

numeric or SpatRaster representing time series signal to be filtered

method

type of spline to be used. Possible values are "fmm", "natural", "periodic", "monoH.FC" and "hyman"

...

additional arguments: method: as above p1: filter order for first pass n1: filter length for first pass (must be odd) p2: filter order for inner passes n2: filter length for inner passes (must be odd)

Details

Performs smoothing of time series data using a two pass Savitzky-Golay smoothing filter. Second pass is an iterative method to minimize the difference between actual and fitted values that are significantly lower than the actual values. Missing values designated as NA are automatically interpolated with spline. For more details on the arguments see splinefun and sgolayfilt.

Value

Filtered signal of length(x)

Examples

# apply on single pixel
#vi <- ....
#s <- filterVI(vi)

# for time series raster 
#fevi <- app(evi, filterVI)

Find and download AVHRR NDVI Climate Data Record (CDR)

Description

Find and download AVHRR NDVI CDR global layers for a time period. The function returned is list of filenames that may have been downloaded.

Usage

getAVHRR(start_date, end_date, path, download=FALSE, overwrite=FALSE, update=FALSE, quiet=FALSE, ...)

Arguments

start_date

character. Start date for the data requested formatted yyyy-m-d

end_date

Character. end date for the data requested formatted yyyy-m-d

path

character. Path to download data to

download

logical. If TRUE, the files are downloaded. If FALSE (the default), only the file names that match the date range are returned

overwrite

logical. If TRUE, existing files are overwritten

update

logical. If TRUE, the cached index of available AVHRR NDVI CDR files is refreshed

quiet

logical. If TRUE, messages and the download progress bar are suppressed

...

Additional arguments passed to download.file (for example method)

Value

Character vector of file names pointing to the downloaded files

Examples

## Not run: 
  start <- "2019-05-17" 
  end <- "2019-05-23"
  path <- tempdir()
  ff <- getAVHRR(start, end, path, download=FALSE)

## End(Not run)

Download CGLS products

Description

Download data provided by the Copernicus Global Land Service (https://land.copernicus.eu/global/) You need to register at https://land.copernicus.eu/global/ and create a username and password.

See https://land.copernicus.eu/global/products/ for a product overview and product details and see https://land.copernicus.vgt.vito.be/manifest/ for an overview for data availability.

Usage

getCGLS(product, start_date, end_date, resolution="1km", 
		version=1, path, username, password, ...)

Arguments

product

character. For example: "fapar", "fcover", "lai", "ndvi", "ssm", "swi", "lst"

resolution

character. one of "1km", "300m" or "100m"

version

positive integer. product version

start_date

character or Date. Start date for the data requested formatted yyyy-m-d

end_date

Character or Date. End date for the data requested formatted yyyy-m-d

path

character. Path name indicating where to store the data

username

character. EOSDIS user name (see Details)

password

character. EOSDIS password (see Details)

...

Additional arguments passed to download.file)

Value

SpatRaster

See Also

getNASA


download from Earth Explorer

Description

Find and download Earth Explorer data

Usage

getEE(product, ids, path, username, password, ...)

Arguments

product

character. Supported products can be found using getProducts

ids

entity IDs

path

character. Path name indicating where to store the data

username

character. EOSDIS user name (see Details)

password

character. EOSDIS password (see Details)

...

Additional arguments. None implemented

Details

This function is an R interface to the Earth Explores system. Access is free, but it requires a "Earthdata" account. If you do not have an account, you can sign up here: https://urs.earthdata.nasa.gov/users/new

Value

Character vector of file names pointing to the downloaded files

See Also

getLandsat


Download data from ERS

Description

Find and download ERS data

Usage

getERS(scenes, path, username, password, overwrite=FALSE, ...)

Arguments

scenes

character

path

character. Path name indicating where to store the data

username

character. User name

password

character. Password

overwrite

logical. If TRUE, existing files are overwritten

...

additional arguments. None implemented

Value

Character vector of file names pointing to the downloaded files

See Also

getLandsat


Find and download Landsat products

Description

Find and (optionally) download Landsat scenes for a specific product, area, and time period.

The function searches the USGS Landsat STAC catalog at https://landsatlook.usgs.gov/stac-server/. It is the successor to the old, NASA CMR-based implementation of getLandsat(): NASA CMR no longer indexes USGS Landsat granules, so the previous default product "Landsat_8_OLI_TIRS_C1" (Landsat 8 Collection 1) and the AWS public S3 bucket landsat-pds are both retired.

When download = FALSE (the default), getLandsat() returns a character vector of asset URLs that match the search and the optional bands filter. These can be inspected, filtered, or downloaded with any tool of your choice.

When download = TRUE, the function logs in to EROS using the supplied USGS Earthdata Login credentials, downloads each asset, and returns a vector of file paths. Downloads are validated against authentication-failure HTML pages so that no broken file is ever saved silently.

Usage

getLandsat(product = "landsat-c2l1", start_date, end_date, aoi,
	download = FALSE, path,
	username, password,
	bands = NULL,
	limit = 1000, overwrite = FALSE,
	verbose = TRUE, ...)

Arguments

product

character. STAC collection id. One of "landsat-c2l1" (Level-1, all sensors), "landsat-c2l2-sr" (Level-2 Surface Reflectance), or "landsat-c2l2-st" (Level-2 Surface Temperature). Legacy CMR short names such as "Landsat_8_OLI_TIRS_C1" are translated to "landsat-c2l1" with a message.

start_date

character or Date. Start date for the search, formatted yyyy-m-d.

end_date

character or Date. End date for the search, formatted yyyy-m-d.

aoi

numeric vector of four elements (xmin, xmax, ymin, ymax) encompassing the area of interest. Or a SpatExtent or any object from which an extent can be extracted.

download

logical. If TRUE the matching assets are downloaded to path.

path

character. Directory in which to store downloaded files.

username

character. USGS Earthdata Login user name (only required when download = TRUE).

password

character. USGS Earthdata Login password (only required when download = TRUE).

bands

optional character vector of asset keys (e.g. c("blue","green","red","nir08")) to restrict the result. The match is case-insensitive. If NULL (the default) all assets of every matching scene are returned, including band TIFs and metadata files such as MTL.txt and ANG.txt.

limit

positive integer. Maximum number of scenes to retrieve from the STAC search.

overwrite

logical. If TRUE, existing files are re-downloaded.

verbose

logical. If FALSE, progress bars and per-file messages are suppressed.

...

Additional arguments. The legacy server and version arguments are accepted for backwards compatibility but ignored, with a warning.

Details

Landsat data are distributed by USGS, not NASA. To download data you need a USGS Earthdata Login account; you can sign up for free at https://ers.cr.usgs.gov/register. The same Earthdata Login can be used with NASA EOSDIS (see getNASA).

For programmatic access at scale, also consider the official USGS M2M API (https://m2m.cr.usgs.gov/) or the rstac package, which both target the same STAC catalog.

Value

A character vector. When download = FALSE, asset URLs that match the search and any bands filter. When download = TRUE, the local file paths of successfully downloaded assets.

See Also

getProducts, getNASA

Examples

## Not run: 
sdate <- "2019-05-01"
edate <- "2019-05-30"
area  <- c(33, 34, -5, -4)
dir   <- tempdir()

# list all assets for matching scenes
urls <- getLandsat("landsat-c2l1", start_date = sdate, end_date = edate,
                   aoi = area, download = FALSE)
head(urls)

# only the four optical bands of every matching scene
urls <- getLandsat("landsat-c2l1", start_date = sdate, end_date = edate,
                   aoi = area, download = FALSE,
                   bands = c("blue", "green", "red", "nir08"))

# download a Surface Reflectance scene (requires Earthdata Login credentials)
# files <- getLandsat("landsat-c2l2-sr",
#                     start_date = sdate, end_date = edate,
#                     aoi = area, download = TRUE,
#                     username = "your_user", password = "your_pwd",
#                     bands = c("blue", "green", "red", "nir08"),
#                     path = dir)

## End(Not run)

Obsolete

Description

Obsolete. See getNASA

Usage

getModis(...)

Arguments

...

Arguments passed to getNASA


Find and download NASA products

Description

Find and download NASA data for a specific product, area, and time period. The function returned is list of filenames that may have been downloaded.

It is important to fist consult getProducts to discover what products and version numbers are available, and which server to use.

Usage

getNASA(product, start_date, end_date, aoi, version=NULL, download=FALSE, path, 
	username, password, server="LPDAAC_ECS", limit=100000, overwrite=FALSE,
	verbose=TRUE, ...)

Arguments

product

character. Supported products can be found using getProducts

start_date

character. Start date for the data requested formatted yyyy-m-d

end_date

Character. end date for the data requested formatted yyyy-m-d

aoi

numeric vector of four elements (minimum longitude, maximum longitude, minimum latitude, maximum latitude) encompassing the area of interest. It can also be a SpatExtent, or any object from which an extent can be extracted

version

character. product version number

download

logical. If TRUE data will be downloaded unless it is present in the download directory

path

character. Path name indicating where to store the data

username

character. EOSDIS user name (see Details)

password

character. EOSDIS password (see Details)

server

character. The server to download the data from

limit

positive integer

overwrite

logical. If TRUE, existing files are overwritten

verbose

logical. If FALSE, progress bars and other messages printed during downloading are suppressed

...

Additional arguments. These can be product specific. See Details)

Details

This function is an R interface to the EOSDIS system. Access is free, but it requires a "Earthdata" account. If you do not have an account, you can sign up here: https://urs.earthdata.nasa.gov/users/new

In addition to having an account, before you can download a particular product you must accept its End User License Agreement (EULA). The EULA is presented when you first try to download a product through the EOSDIS web interface, and can also be reviewed under your profile at https://urs.earthdata.nasa.gov/. If your credentials are wrong or you have not accepted the EULA, downloads will fail with an authentication error rather than silently saving an HTML error page as if it were data.

If no data is available between start_date and end_date, files for the closest dates are returned.

Value

Character vector of file names pointing to the downloaded files (if download=TRUE)

See Also

getProducts, getLandsat

Examples

product <- "MOD09A1"
# information about the product
getProducts(product)
sdate <- "2019-05-17" 
edate <- "2019-05-23"
area <- c(33, 34, -5, -4)
path <- tempdir()
# list available tiles
f <- getNASA(product = product,
            start_date = sdate, end_date = edate,
            aoi = area, download = FALSE, path=path)
f

# get the date from the filenames
modisDate(f)

# to download the tiles, set download = TRUE
# and provide your credentials 

usr <- "your user name"
pwd <- "your password"
#f <- getNASA(product = product, username=urs, password=pwd,
#            start_date = sdate, end_date = edate,
#            aoi = area, download = TRUE, path=path)

Find NASA product names

Description

Find available products in NASA's Common Metadata Repository (CMR) that can be downloaded. See getNASA for further use.

Usage

getProducts(product, ...)

Arguments

product

character

...

additional arguments. None implemented

Value

character

See Also

getNASA

Examples

# list of all available MODIS products
getProducts("^MOD|^MYD|^MCD")

Multiple Endmember Spectral Mixture Analysis (Spectral Unmixing)

Description

mesma performs a multiple endmember spectral mixture analysis on a multiband raster image.

For unmixing, a non-negative least squares (NNLS) regression which is using a sequential coordinate-wise algorithm (SCA) based on Franc et al. (2005).

Usage

## S4 method for signature 'SpatRaster'
mesma(x, em, iterate=400, tolerance=0.00000001, ...)

Arguments

x

SpatRaster. Usually representing a hyperspectral remotely sensed image

em

matrix or data.frame with spectral endmembers. Rows represent a single endmember of a class, columns represent the spectral bands (i.e. columns correspond to number of bands in img). The number of rows needs to be > 1

iterate

integer. Set maximum iteration per pixel. Processing time could increase the more iterations are made possible

tolerance

numeric. Tolerance limit representing a nearly zero minimal number

...

further arguments passed to writeRaster

Value

SpatRaster with one layer per end-member, with each value representing the estimated presence probability of the end-member per pixel (0 to 1), and an RMSE layer.

Note

Depending on iterate and tolerance settings, the sum of estimated presence probabilities per pixel varies around 1.

Author(s)

Jakob Schwalb-Willmann

References

Franc, V., Hlaváč, V., & Navara, M. (2005). Sequential coordinate-wise algorithm for the non-negative least squares problem. In: International Conference on Computer Analysis of Images and Patterns (pp. 407-414). Berlin, Heidelberg.

Examples

lsat <- rast(system.file("ex/lsat.tif", package="luna"))

# endmember spectra: water and land
em_names <- c("water", "land")
pts <- data.frame(class=em_names, cell = c(47916,5294))
em <- lsat[pts$cell]
rownames(em) <- em_names

# unmix the image for water and land
probs <- mesma(lsat, em)

# take a look
hist(probs$water)
plot(probs$water, col = c("white","blue"))
hist(probs$land)
plot(probs$land, col = c("white","brown"))

MODIS mask

Description

Create a "mask" for a MODIS image based your selection of bad quality pixels, using the Quality Assessment (QA) band.

Usage

modis_mask(x, bits, qmat, ...)

Arguments

x

SpatRaster

bits

single integer value: 16 or 32

qmat

three-column matrix of data.frame. The first and second columns are positive integers (or character representation thereof) indicating the start and end bits (starting counting at one, not at zero!). The third column has the patterns to be rejected, stored as comma-separated characters. See example

...

additional arguments, none implemented

Value

SpatRaster

Examples

## Not run: 
f <- "MOD09A1.A2011009.h21v08.006.2015216112834.hdf"
mod <- rast(f)
shortnames <- substr(names(mod), 86, 120)
names(mod) <- shortnames

qc <- mod[[12]]

from <- c(1,3,11,12) #,16)
to   <- c(2,6,11,14) #,17)
reject <- c("10,11", "1100,1101,1110,1111", "1", "000,110,111") # "11")

qmat <- cbind(from, to, reject)

m <- modis_mask(qc, 16, qmat)
plot(m)

## End(Not run)

Extract the date from a MODIS filename

Description

Extract the date that is encoded in a MODIS filename

Usage

modisDate(filename)

Arguments

filename

character. MODIS product filenames

Value

data.frame

See Also

getNASA

Examples

modisDate("MOD09A1.A2019137.h21v09.006.2019150085736.hdf")

Get the extent of a MODIS tile

Description

Get the extent of a MODIS tile from the h (horizontal; column number) and v (vertical; row number) identifier in the filename

Usage

modisExtent(f=NULL, h, v)

Arguments

f

character. filename that includes a h12v09 pattern

h

integer between 0 and 35

v

integer between 0 and 17

Value

SpatExtent

See Also

modisDate

Examples

f <- "MOD09A1.A2019137.h21v09.006.2019150085736.hdf"
modisExtent(f)

modisExtent(h=21, v=9)

Panchromatic sharpening

Description

Panchromatic band sharpening of lower resolution satellite images.

Usage

## S4 method for signature 'SpatRaster,SpatRaster'
panSharpen(x, p, method="Brovey", weights=NULL, filename="", overwrite=FALSE, ...)

Arguments

x

SpatRaster with layers (bands) to be sharpened

p

SpatRaster with a single panchromatic layer at a higher spatial resolution than x

method

character. Either "Brovey" or "HSI"

weights

optional vector of weights for the "Brovey" method. The weights should have a length equal to nlyr(x) and they should normally add up to 1

filename

character. Output filename

overwrite

logical. If TRUE, existing files are overwritten

...

additional arguments for writing files as in writeRaster

Value

SpatRaster


NASA product information

Description

Get complete product information in the corresponding product website. The information is displayed in the default browser. See getProducts for available options of products.

Usage

productInfo(product, ...)

Arguments

product

character

...

additional arguments (non implemented

See Also

getProducts

Examples

## Not run: 
# MODIS in LP DAAC with version information
productInfo(product = "MCD18A1")
# Without any version or server information
productInfo(product = "LANDSAT_SURFACE_REFLECTANCE_L8_OLI_TIRS")

## End(Not run)