| 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-07-10 06:23:57 UTC |
| Source: | https://github.com/rspatial/luna |
Tools for acquiring and (pre-) processing satellite remote sensing data. Including for downloading data from NASA such as LANDSAT and MODIS.
Validate a NASA Earthdata Login (URS) username/password against https://urs.earthdata.nasa.gov/ and return a session object that can be passed to getNASA via its auth argument.
A successful call confirms up front that the credentials are correct, so subsequent getNASA(download = TRUE, auth = ...) calls will fail fast on auth errors rather than appearing to succeed when files happen to be cached on disk (issue #40).
earthdataLogin(username, password, verbose = TRUE)earthdataLogin(username, password, verbose = TRUE)
username |
character. Earthdata Login user name. Sign up at https://urs.earthdata.nasa.gov/users/new. |
password |
character. Earthdata Login password. |
verbose |
logical. If |
Validation is performed by issuing a HTTP GET request to https://urs.earthdata.nasa.gov/api/users/tokens with HTTP Basic authentication. The endpoint is read-only (it returns a list of the user's existing API tokens, if any) and reliably returns HTTP 200 for valid credentials and HTTP 401 for invalid ones.
The returned session object holds the paths to a temporary netrc file and cookie jar that the rest of luna uses to authenticate downloads. Both files are removed when the session is garbage-collected or when R exits.
In addition to a working Earthdata Login account, downloading a particular product requires that you have accepted that product's End User License Agreement (EULA) at https://urs.earthdata.nasa.gov/. Authentication can succeed (so earthdataLogin() returns a session) while subsequent downloads of an EULA-restricted product still fail with HTTP 401/403; in that case the failure is reported by getNASA().
An earthdata_session object (an environment) with elements username, netrc_file, cookie_file, validated, and created.
## Not run: auth <- earthdataLogin("my_user", "my_password") auth # prints a one-line summary # reuse the same session for many downloads, without re-authenticating f <- getNASA(product = "MOD09A1", start_date = "2019-05-17", end_date = "2019-05-23", aoi = c(33, 34, -5, -4), download = TRUE, path = tempdir(), auth = auth) ## End(Not run)## Not run: auth <- earthdataLogin("my_user", "my_password") auth # prints a one-line summary # reuse the same session for many downloads, without re-authenticating f <- getNASA(product = "MOD09A1", start_date = "2019-05-17", end_date = "2019-05-23", aoi = c(33, 34, -5, -4), download = TRUE, path = tempdir(), auth = auth) ## End(Not run)
Validate a USGS Earthdata Login username/password against https://ers.cr.usgs.gov/ and return a session object that can be passed to getLandsat via its auth argument.
Although USGS uses the same "Earthdata Login" credentials as NASA, the actual authentication flow for Landsat downloads is different: USGS requires an interactive form-login on ers.cr.usgs.gov that establishes a session cookie. erosLogin() performs that flow once and stores the resulting curl handle in the session object, so subsequent getLandsat(download = TRUE, auth = ...) calls reuse the same authenticated session.
erosLogin(username, password, verbose = TRUE)erosLogin(username, password, verbose = TRUE)
username |
character. USGS Earthdata Login user name. Sign up at https://ers.cr.usgs.gov/register. |
password |
character. USGS Earthdata Login password. |
verbose |
logical. If |
Authentication is performed by GETting the EROS login page, scraping the CSRF token from its HTML form, and POSTing a form-encoded request with the supplied credentials. Success is confirmed by checking that the resulting HTML contains a "Sign Out" link.
The session holds a libcurl handle whose cookies authenticate subsequent download requests against landsatlook.usgs.gov. The session attempts a logout when the object is garbage-collected.
If the EROS UI changes such that the login flow stops working, erosLogin() fails with an informative error. In that case consider using the rstac package or downloading manually from https://earthexplorer.usgs.gov/.
An eros_session object (an environment) with elements username, handle, validated, and created.
## Not run: auth <- erosLogin("my_user", "my_password") auth # prints a one-line summary # reuse the session across multiple Landsat scenes f <- getLandsat(product = "landsat-c2l1", start_date = "2019-05-01", end_date = "2019-05-31", aoi = c(33, 34, -5, -4), bands = c("blue", "green", "red", "nir08"), download = TRUE, path = tempdir(), auth = auth) ## End(Not run)## Not run: auth <- erosLogin("my_user", "my_password") auth # prints a one-line summary # reuse the session across multiple Landsat scenes f <- getLandsat(product = "landsat-c2l1", start_date = "2019-05-01", end_date = "2019-05-31", aoi = c(33, 34, -5, -4), bands = c("blue", "green", "red", "nir08"), download = TRUE, path = tempdir(), auth = auth) ## End(Not run)
Estimate missing values using smooth gap-filled time series data with a two-stage Savitzky-Golay smoothing filter.
filterVI(x, ...) fillVI(x, method = "natural")filterVI(x, ...) fillVI(x, method = "natural")
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:
|
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.
Filtered signal of length(x)
# apply on single pixel #vi <- .... #s <- filterVI(vi) # for time series raster #fevi <- app(evi, filterVI)# apply on single pixel #vi <- .... #s <- filterVI(vi) # for time series raster #fevi <- app(evi, filterVI)
Find and download AVHRR NDVI CDR global layers for a time period. The function returned is list of filenames that may have been downloaded.
getAVHRR(start_date, end_date, path, download=FALSE, overwrite=FALSE, update=FALSE, quiet=FALSE, ...)getAVHRR(start_date, end_date, path, download=FALSE, overwrite=FALSE, update=FALSE, quiet=FALSE, ...)
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 |
overwrite |
logical. If |
update |
logical. If |
quiet |
logical. If |
... |
Additional arguments passed to |
Character vector of file names pointing to the downloaded files
## Not run: start <- "2019-05-17" end <- "2019-05-23" path <- tempdir() ff <- getAVHRR(start, end, path, download=FALSE) ## End(Not run)## Not run: start <- "2019-05-17" end <- "2019-05-23" path <- tempdir() ff <- getAVHRR(start, end, path, download=FALSE) ## End(Not run)
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.
getCGLS(product, start_date, end_date, resolution="1km", version=1, path, username, password, ...)getCGLS(product, start_date, end_date, resolution="1km", version=1, path, username, password, ...)
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) |
SpatRaster
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 authentication session (or, deprecated, raw username/password), 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.
getLandsat(product = "landsat-c2l1", start_date, end_date, aoi, download = FALSE, path, username, password, auth = NULL, bands = NULL, limit = 1000, overwrite = FALSE, verbose = TRUE, ...)getLandsat(product = "landsat-c2l1", start_date, end_date, aoi, download = FALSE, path, username, password, auth = NULL, bands = NULL, limit = 1000, overwrite = FALSE, verbose = TRUE, ...)
product |
character. STAC collection id. One of |
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 ( |
download |
logical. If |
path |
character. Directory in which to store downloaded files. |
username |
character. USGS Earthdata Login user name. Deprecated - prefer creating an |
password |
character. USGS Earthdata Login password. Deprecated - see |
auth |
an |
bands |
optional character vector of asset keys (e.g. |
limit |
positive integer. Maximum number of scenes to retrieve from the STAC search. |
overwrite |
logical. If |
verbose |
logical. If |
... |
Additional arguments. The legacy |
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), but the actual authentication flow is different - USGS requires an interactive form-login on ers.cr.usgs.gov.
Authentication. The recommended way to supply credentials is to call erosLogin once and pass the returned session via auth:
auth <- erosLogin("my_user", "my_password")
getLandsat(..., download = TRUE, auth = auth)
erosLogin() validates the credentials up front, so authentication errors are caught immediately rather than only when a download is attempted, and the session can be reused across many getLandsat() calls without re-authenticating. The username/password arguments are still accepted for backwards compatibility but are deprecated and may emit a warning. They are ignored when auth is supplied.
Caching. When download = TRUE and an asset already exists in path (and overwrite = FALSE), getLandsat() re-uses the local copy and does not contact USGS. With verbose = TRUE this is announced as a "reading from cache: ..." message. Use erosLogin to validate credentials independently of the cache.
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.
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.
erosLogin, getProducts, getNASA
## 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) # auth <- erosLogin("your_user", "your_pwd") # files <- getLandsat("landsat-c2l2-sr", # start_date = sdate, end_date = edate, # aoi = area, download = TRUE, auth = auth, # bands = c("blue", "green", "red", "nir08"), # path = dir) ## End(Not run)## 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) # auth <- erosLogin("your_user", "your_pwd") # files <- getLandsat("landsat-c2l2-sr", # start_date = sdate, end_date = edate, # aoi = area, download = TRUE, auth = auth, # bands = c("blue", "green", "red", "nir08"), # path = dir) ## End(Not run)
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.
getNASA(product, start_date, end_date, aoi, version=NULL, download=FALSE, path, username, password, auth=NULL, server="LPDAAC_ECS", limit=100000, overwrite=FALSE, pattern=NULL, verbose=TRUE, ...)getNASA(product, start_date, end_date, aoi, version=NULL, download=FALSE, path, username, password, auth=NULL, server="LPDAAC_ECS", limit=100000, overwrite=FALSE, pattern=NULL, verbose=TRUE, ...)
product |
character. Supported products can be found using |
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 |
path |
character. Path name indicating where to store the data |
username |
character. NASA Earthdata Login user name. Deprecated - prefer creating an |
password |
character. NASA Earthdata Login password. Deprecated - see |
auth |
an |
server |
character. The server to download the data from |
limit |
positive integer |
overwrite |
logical. If |
pattern |
optional character vector of regular expressions. Granules whose filename does not match any of the patterns are dropped. The match is case-insensitive and uses |
verbose |
logical. If |
... |
Additional arguments. These can be product specific. See 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.
Authentication. The recommended way to supply credentials is to call earthdataLogin once and pass the returned session object via auth:
auth <- earthdataLogin("my_user", "my_password")
getNASA(..., download = TRUE, auth = auth)
earthdataLogin() validates the credentials up front against URS, so authentication errors are caught immediately rather than only when a download is attempted. The session can be reused across many getNASA() calls without re-authenticating.
The username/password arguments are still accepted for backwards compatibility but are deprecated and may emit a warning. They are ignored when auth is supplied.
Caching. When download = TRUE and a granule already exists in path (and overwrite = FALSE), getNASA() re-uses the local copy and does not contact Earthdata. With verbose = TRUE this is announced as a "reading from cache: ..." message, so it is clear that no download (and no credential check) was performed for that file. Use earthdataLogin to validate credentials independently of the cache.
If no data is available between start_date and end_date, files for the closest dates are returned.
NASA periodically retires older product collections in favor of new ones (for example, MOD17A3H was superseded by MOD17A3HGF). When the requested product/version cannot be found, getNASA reports the available alternatives in the cached collection list and suggests similar product short names; consult getProducts for the full inventory.
Character vector of file names pointing to the downloaded files (if download=TRUE)
earthdataLogin, getProducts, getLandsat
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 via an explicit Earthdata Login session #auth <- earthdataLogin("your_user", "your_password") #f <- getNASA(product = product, auth = auth, # start_date = sdate, end_date = edate, # aoi = area, download = TRUE, path=path) # Daymet bundles several variables (tmin, tmax, prcp, srad, vp, swe, dayl) # under a single collection; use `pattern` to download only the ones you # want instead of all of them: #f <- getNASA(product = "Daymet_Daily_V4R1_2129", server = "ORNL_CLOUD", # start_date = "2020-06-29", end_date = "2020-07-01", # aoi = area, pattern = c("tmin", "tmax"), # download = TRUE, auth = auth, path = path)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 via an explicit Earthdata Login session #auth <- earthdataLogin("your_user", "your_password") #f <- getNASA(product = product, auth = auth, # start_date = sdate, end_date = edate, # aoi = area, download = TRUE, path=path) # Daymet bundles several variables (tmin, tmax, prcp, srad, vp, swe, dayl) # under a single collection; use `pattern` to download only the ones you # want instead of all of them: #f <- getNASA(product = "Daymet_Daily_V4R1_2129", server = "ORNL_CLOUD", # start_date = "2020-06-29", end_date = "2020-07-01", # aoi = area, pattern = c("tmin", "tmax"), # download = TRUE, auth = auth, path = path)
Find available products in NASA's Common Metadata Repository (CMR) that can be downloaded. See getNASA for further use.
getProducts(product, ...)getProducts(product, ...)
product |
character |
... |
additional arguments. None implemented |
character
# list of all available MODIS products getProducts("^MOD|^MYD|^MCD")# list of all available MODIS products getProducts("^MOD|^MYD|^MCD")
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).
## S4 method for signature 'SpatRaster' mesma(x, em, iterate=400, tolerance=0.00000001, ...)## S4 method for signature 'SpatRaster' mesma(x, em, iterate=400, tolerance=0.00000001, ...)
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 |
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 |
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.
Depending on iterate and tolerance settings, the sum of estimated presence probabilities per pixel varies around 1.
Jakob Schwalb-Willmann
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.
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"))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"))
Create a "mask" for a MODIS image based your selection of bad quality pixels, using the Quality Assessment (QA) band.
modis_mask(x, bits, qmat, ...)modis_mask(x, bits, qmat, ...)
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 |
SpatRaster
## 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)## 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 that is encoded in a MODIS filename
modisDate(filename)modisDate(filename)
filename |
character. MODIS product filenames |
data.frame
modisDate("MOD09A1.A2019137.h21v09.006.2019150085736.hdf")modisDate("MOD09A1.A2019137.h21v09.006.2019150085736.hdf")
Get the extent of a MODIS tile from the h (horizontal; column number) and v (vertical; row number) identifier in the filename
modisExtent(f=NULL, h, v)modisExtent(f=NULL, h, v)
f |
character. filename that includes a h12v09 pattern |
h |
integer between 0 and 35 |
v |
integer between 0 and 17 |
SpatExtent
f <- "MOD09A1.A2019137.h21v09.006.2019150085736.hdf" modisExtent(f) modisExtent(h=21, v=9)f <- "MOD09A1.A2019137.h21v09.006.2019150085736.hdf" modisExtent(f) modisExtent(h=21, v=9)
Sharpen multispectral imagery using a higher-resolution panchromatic band. Three transforms are supported: "Brovey", "HSI", and "PCA".
## S4 method for signature 'SpatRaster,SpatRaster' panSharpen(x, p, method="Brovey", weights=NULL, filename="", overwrite=FALSE, ...)## S4 method for signature 'SpatRaster,SpatRaster' panSharpen(x, p, method="Brovey", weights=NULL, filename="", overwrite=FALSE, ...)
x |
SpatRaster with the multispectral layers (bands) to be sharpened. |
p |
Single-layer SpatRaster with the panchromatic band, at higher spatial resolution than |
method |
character. One of |
weights |
optional numeric vector of weights, one per layer of |
filename |
character. Optional output file. When supplied, the result is written via |
overwrite |
logical. If |
... |
additional arguments for |
x is first resampled to the geometry of p.
Brovey. For each multispectral band , the Brovey transform returns . Without weights, is the per-pixel mean of the multispectral bands. With weights, is the weighted sum, equivalent to the algorithm used by GDAL's gdal_pansharpen.py (the default GDAL pansharpening method).
HSI The implementation follows the additive (also called fast) IHS formulation: substituting the intensity component with a pan band that has been histogram-matched to is algebraically equivalent to , where is the pan band linearly rescaled so its mean and standard deviation match those of .
PCA. The multispectral stack is forward-projected onto its principal components using prcomp; the first principal component (the dominant variance direction, analogous to a data-driven intensity) is then replaced with the pan band rescaled to its mean and sd, and the inverse rotation is applied to recover sharpened bands. Columns of the rotation matrix are flipped so that each component's loadings sum positively. PCA pan-sharpening is data-driven and well-suited to multispectral inputs with more than 3 bands, where Brovey and IHS rely on heuristic intensity definitions.
If you want behaviour equivalent to gdal_pansharpen.py, use method = "Brovey" with weights reflecting the spectral overlap of each multispectral band with the panchromatic band; for sensors where the pan band covers the visible plus NIR (e.g. Landsat 8 OLI band 8) typical weights are roughly c(R=0.21, G=0.27, B=0.42, NIR=0.10).
SpatRaster with the same number of layers as x, at the resolution of p.
library(terra) f <- system.file("ex/lsat.tif", package = "luna") ms <- rast(f)[[1:3]] # B (B1), G (B2), R (B3) # Synthesise a higher-resolution "panchromatic" band for the example. # In practice, `p` would be the actual sensor pan band. pan <- disagg(mean(rast(f)[[1:4]]), 2) # Brovey (GDAL default) b1 <- panSharpen(ms, pan, method = "Brovey") # Weighted Brovey, matching gdal_pansharpen.py semantics b2 <- panSharpen(ms, pan, method = "Brovey", weights = c(0.42, 0.27, 0.21)) # Additive IHS (works for any number of bands) h <- panSharpen(ms, pan, method = "HSI") # PCA (data-driven; recommended for >3 bands) pc <- panSharpen(ms, pan, method = "PCA") # Compare resolutions res(ms) res(pan) res(b1)library(terra) f <- system.file("ex/lsat.tif", package = "luna") ms <- rast(f)[[1:3]] # B (B1), G (B2), R (B3) # Synthesise a higher-resolution "panchromatic" band for the example. # In practice, `p` would be the actual sensor pan band. pan <- disagg(mean(rast(f)[[1:4]]), 2) # Brovey (GDAL default) b1 <- panSharpen(ms, pan, method = "Brovey") # Weighted Brovey, matching gdal_pansharpen.py semantics b2 <- panSharpen(ms, pan, method = "Brovey", weights = c(0.42, 0.27, 0.21)) # Additive IHS (works for any number of bands) h <- panSharpen(ms, pan, method = "HSI") # PCA (data-driven; recommended for >3 bands) pc <- panSharpen(ms, pan, method = "PCA") # Compare resolutions res(ms) res(pan) res(b1)
Get complete product information in the corresponding product website. The information is displayed in the default browser. See getProducts for available options of products.
productInfo(product, ...)productInfo(product, ...)
product |
character |
... |
additional arguments (non implemented |
## 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)## 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)