Title: | Interface to the 'MODIS Land Products Subsets' Web Services |
---|---|
Description: | Programmatic interface to the Oak Ridge National Laboratories 'MODIS Land Products Subsets' web services (<https://modis.ornl.gov/data/modis_webservice.html>). Allows for easy downloads of 'MODIS' time series directly to your R workspace or your computer. |
Authors: | Koen Hufkens [aut, cre] , BlueGreen Labs [cph, fnd] |
Maintainer: | Koen Hufkens <[email protected]> |
License: | AGPL-3 |
Version: | 1.1.5 |
Built: | 2024-10-31 04:07:31 UTC |
Source: | https://github.com/bluegreen-labs/modistools |
MODIS leaf area index (LAI) around the French town of Arcachon derived from the MODIS MOD15A2H product (band Lai_500m).
arcachon_lai
arcachon_lai
A MODISTools tidy data frame
MODIS land cover (IGBP) around the French town of Arcachon derived from the MODIS MCD12Q2 product (band LC_Type1).
arcachon_lc
arcachon_lc
A MODISTools tidy data frame
Lists all available bands for a MODIS Land Products Subset product.
mt_bands(product)
mt_bands(product)
product |
a valid MODIS product name |
A data frame of all available bands for a MODIS Land Products Subsets products
# list all available MODIS Land Products Subsets products bands <- mt_bands(product = "MCD12Q2") head(bands)
# list all available MODIS Land Products Subsets products bands <- mt_bands(product = "MCD12Q2") head(bands)
Lists all available dates for a MODIS Land Products Subset product at a particular location.
mt_batch_subset( df, product, band, start = "2000-01-01", end = format(Sys.time(), "%Y-%m-%d"), km_lr = 0, km_ab = 0, out_dir = tempdir(), internal = TRUE )
mt_batch_subset( df, product, band, start = "2000-01-01", end = format(Sys.time(), "%Y-%m-%d"), km_lr = 0, km_ab = 0, out_dir = tempdir(), internal = TRUE )
df |
a CSV file or data frame holding locations and their sitenames to batch process with column names site_name, lat, lon holding the respective sitenames, latitude and longitude. When providing a CSV make sure that the data are comma separated. |
product |
a valid MODIS product name |
band |
band to download |
start |
start date |
end |
end date |
km_lr |
km left-right to sample |
km_ab |
km above-below to sample |
out_dir |
location where to store all data |
internal |
should the data be returned as an internal data structure
|
A data frame combining meta-data and actual data values, data from different sites is concatenated into one large dataframe. Subsets can be created by searching on sitename.
mt_sites
mt_dates
mt_bands
mt_products
mt_subset
## Not run: # create data frame with a site_name, lat and lon column # holding the respective names of sites and their location df <- data.frame("site_name" = paste("test",1:2)) df$lat <- 40 df$lon <- -110 print(df) # test batch download subsets <- mt_batch_subset(df = df, product = "MOD11A2", band = "LST_Day_1km", internal = TRUE, start = "2004-01-01", end = "2004-03-31") # the same can be done using a CSV file with # a data structure similar to the dataframe above write.table(df, file.path(tempdir(),"my_sites.csv"), quote = FALSE, row.names = FALSE, col.names = TRUE, sep = ",") # test batch download form CSV subsets <- mt_batch_subset(df = file.path(tempdir(),"my_sites.csv"), product = "MOD11A2", band = "LST_Day_1km", internal = TRUE, start = "2004-01-01", end = "2004-03-31" ) head(subsets) ## End(Not run)
## Not run: # create data frame with a site_name, lat and lon column # holding the respective names of sites and their location df <- data.frame("site_name" = paste("test",1:2)) df$lat <- 40 df$lon <- -110 print(df) # test batch download subsets <- mt_batch_subset(df = df, product = "MOD11A2", band = "LST_Day_1km", internal = TRUE, start = "2004-01-01", end = "2004-03-31") # the same can be done using a CSV file with # a data structure similar to the dataframe above write.table(df, file.path(tempdir(),"my_sites.csv"), quote = FALSE, row.names = FALSE, col.names = TRUE, sep = ",") # test batch download form CSV subsets <- mt_batch_subset(df = file.path(tempdir(),"my_sites.csv"), product = "MOD11A2", band = "LST_Day_1km", internal = TRUE, start = "2004-01-01", end = "2004-03-31" ) head(subsets) ## End(Not run)
Converts lower-left sinusoidal coordinates to lat-lon sf bounding box
mt_bbox(xllcorner, yllcorner, cellsize, nrows, ncols, transform = TRUE)
mt_bbox(xllcorner, yllcorner, cellsize, nrows, ncols, transform = TRUE)
xllcorner |
lower left x coordinate as provided by
|
yllcorner |
lower left y coordinate as provided by
|
cellsize |
cell size provided by |
nrows |
cell size provided by |
ncols |
cell size provided by |
transform |
transform the bounding box from sin to lat long coordinates,
|
# Download some test data subset <- mt_subset(product = "MOD11A2", lat = 40, lon = -110, band = "LST_Day_1km", start = "2004-01-01", end = "2004-03-31", progress = FALSE) # convert sinusoidal to lat / lon lat_lon <- sin_to_ll(subset$xllcorner, subset$yllcorner) # bind with the original dataframe subset <- cbind(subset, lat_lon) # convert to bounding box bb <- apply(subset, 1, function(x){ mt_bbox(xllcorner = x['xllcorner'], yllcorner = x['yllcorner'], cellsize = x['cellsize'], nrows = x['nrows'], ncols = x['ncols']) }) head(bb)
# Download some test data subset <- mt_subset(product = "MOD11A2", lat = 40, lon = -110, band = "LST_Day_1km", start = "2004-01-01", end = "2004-03-31", progress = FALSE) # convert sinusoidal to lat / lon lat_lon <- sin_to_ll(subset$xllcorner, subset$yllcorner) # bind with the original dataframe subset <- cbind(subset, lat_lon) # convert to bounding box bb <- apply(subset, 1, function(x){ mt_bbox(xllcorner = x['xllcorner'], yllcorner = x['yllcorner'], cellsize = x['cellsize'], nrows = x['nrows'], ncols = x['ncols']) }) head(bb)
Lists all available dates for a MODIS Land Products Subset product at a particular location.
mt_dates(product, lat, lon, site_id, network)
mt_dates(product, lat, lon, site_id, network)
product |
a valid MODIS product name |
lat |
latitude in decimal degrees |
lon |
longitude in decimal degrees |
site_id |
site id (overides lat / lon) |
network |
the network for which to generate the site list, when not provided the complete list is provided |
A data frame of all available dates for a MODIS Land Products Subsets products at the given location.
# list all available MODIS Land Products Subsets products bands <- mt_dates(product = "MOD11A2", lat = 40, lon = -110) head(bands)
# list all available MODIS Land Products Subsets products bands <- mt_dates(product = "MOD11A2", lat = 40, lon = -110) head(bands)
Lists all available MODIS Land Products Subset products.
mt_products()
mt_products()
A data frame of all available MODIS Land Products Subsets products
# list all available MODIS Land Products Subsets products products <- mt_products() head(products)
# list all available MODIS Land Products Subsets products products <- mt_products() head(products)
Lists all available MODIS Land Products Subset pre-processed sites
mt_sites(network)
mt_sites(network)
network |
the network for which to generate the site list, when not provided the complete list is provided |
A data frame of all available MODIS Land Products Subsets pre-processed sites
# list all available MODIS Land Products Subsets products sites <- mt_sites() print(head(sites))
# list all available MODIS Land Products Subsets products sites <- mt_sites() print(head(sites))
Download a MODIS Land Products Subset product for a given point location buffered with a given amount of kilometers left-right, top-bottom for a given location (provided as latitude and longitude values).
mt_subset( product, band, lat, lon, start = "2000-01-01", end = format(Sys.time(), "%Y-%m-%d"), km_lr = 0, km_ab = 0, site_id, network, site_name = "sitename", out_dir = tempdir(), internal = TRUE, progress = TRUE )
mt_subset( product, band, lat, lon, start = "2000-01-01", end = format(Sys.time(), "%Y-%m-%d"), km_lr = 0, km_ab = 0, site_id, network, site_name = "sitename", out_dir = tempdir(), internal = TRUE, progress = TRUE )
product |
a valid MODIS product name |
band |
band or bands (as a character vector) to download |
lat |
latitude in decimal degrees |
lon |
longitude in decimal degrees |
start |
start date |
end |
end date |
km_lr |
km left-right to sample (rounded to the nearest integer) |
km_ab |
km above-below to sample (rounded to the nearest integer) |
site_id |
site id (overides lat / lon) |
network |
the network for which to generate the site list, when not provided the complete list is provided |
site_name |
arbitrary site name used in writing data to file (default = sitename) |
out_dir |
path where to store the data if writing to disk (default = tempdir()) |
internal |
should the data be returned as an internal data structure
|
progress |
show download progress |
A data frame combining meta-data and actual data values.
mt_sites
mt_dates
mt_bands
mt_products
mt_batch_subset
# list all available MODIS Land Products Subsets products # download data subset <- mt_subset(product = "MOD11A2", lat = 40, lon = -110, band = "LST_Day_1km", start = "2004-01-01", end = "2004-03-31", progress = FALSE) head(subset)
# list all available MODIS Land Products Subsets products # download data subset <- mt_subset(product = "MOD11A2", lat = 40, lon = -110, band = "LST_Day_1km", start = "2004-01-01", end = "2004-03-31", progress = FALSE) head(subset)
Convert tidy MODISTools data to a terra SpatRaster for easy spatial processing and plotting.
mt_to_terra(df, reproject = FALSE, method = "bilinear")
mt_to_terra(df, reproject = FALSE, method = "bilinear")
df |
a valid MODISTools data frame with a single band (filter for a
particular band using the dplyr |
reproject |
reproject output to lat / long (default = |
method |
character. Method used for estimating the new cell values of a SpatRaster. One of: near: nearest neighbor. This method is fast, and it can be the preferred method if the cell values represent classes. It is not a good choice for continuous values. This is used by default if the first layer of x is categorical. bilinear: bilinear interpolation. This is the default if the first layer of x is numeric (not categorical). cubic: cubic interpolation. cubicspline: cubic spline interpolation. |
A terra SpatRaster populated with the tidy dataframe values
# list all available MODIS Land Products Subsets products # download data LC <- mt_subset(product = "MCD12Q1", lat = 48.383662, lon = 2.610250, band = "LC_Type1", start = "2005-01-01", end = "2005-12-30", km_lr = 2, km_ab = 2, site_name = "testsite", internal = TRUE, progress = FALSE) head(LC) # convert to raster LC_r <- mt_to_terra(df = LC)
# list all available MODIS Land Products Subsets products # download data LC <- mt_subset(product = "MCD12Q1", lat = 48.383662, lon = 2.610250, band = "LC_Type1", start = "2005-01-01", end = "2005-12-30", km_lr = 2, km_ab = 2, site_name = "testsite", internal = TRUE, progress = FALSE) head(LC) # convert to raster LC_r <- mt_to_terra(df = LC)
A full description of the sinusoidal projection is provided on the lpdaac page: https://lpdaac.usgs.gov/dataset_discovery/modis and wikipedia: https://en.wikipedia.org/wiki/Sinusoidal_projection
sin_to_ll(x, y)
sin_to_ll(x, y)
x |
sinusoidal x coordinate (vector) |
y |
sinusoidal y coordinate (vector) |
# Download some test data subset <- mt_subset(product = "MOD11A2", lat = 40, lon = -110, band = "LST_Day_1km", start = "2004-01-01", end = "2004-03-31", progress = FALSE) # convert sinusoidal to lat / lon lat_lon <- sin_to_ll(subset$xllcorner, subset$yllcorner) # bind with the original dataframe subset <- cbind(subset, lat_lon) head(subset)
# Download some test data subset <- mt_subset(product = "MOD11A2", lat = 40, lon = -110, band = "LST_Day_1km", start = "2004-01-01", end = "2004-03-31", progress = FALSE) # convert sinusoidal to lat / lon lat_lon <- sin_to_ll(subset$xllcorner, subset$yllcorner) # bind with the original dataframe subset <- cbind(subset, lat_lon) head(subset)