View source: R/mf_import_data.R
| mf_import_data | R Documentation |
modisfast as a terra::SpatRaster objectImport datasets downloaded using modisfast as a terra::SpatRaster object
mf_import_data(
path,
collection,
output_class = "SpatRaster",
proj_epsg = NULL,
roi_mask = NULL,
vrt = FALSE,
verbose = "inform",
...
)
path |
Download root folder supplied to [mf_download_data()], or a folder containing the NetCDF files for one ROI and collection. |
collection |
Collection identifier, e.g. '"MOD11A1.061"', '"VNP43MA4.002"' or '"GPM_3IMERGDF.07"'. |
output_class |
character string. Output object class. Currently only "SpatRaster" implemented. |
proj_epsg |
numeric. EPSG of the desired projection for the output raster (default : source projection of the data). |
roi_mask |
|
vrt |
boolean. Import virtual raster instead of SpatRaster. Useful for very large files. (default : FALSE) |
verbose |
Character string: '"quiet"', '"inform"' (default), or '"debug"'. Controls progress messages. |
... |
not used |
a terra::SpatRast object
Although the data downloaded through modisfast could be imported with any netcdf-compliant R package (terra, stars, ncdf4, etc.), care must be taken. In fact, depending on the collection, some “issues” were raised. These issues are independent from modisfast : they result most of time of a lack of full implementation of the OPeNDAP framework by the data providers. Namely, these issues are :
for MODIS and VIIRS collections : CRS has to be provided
for GPM collections : EPSG:4326 is assigned to the grid
The function mf_import_data includes the processing that needs to be done at the data import phase in order to safely use the data as terra objects.
Also note that reprojecting over large ROIs using the argument proj_epsg might take long. In this case, setting the argument vrt to TRUE might be a solution.
## Not run:
### Configure an Earthdata bearer token for LP DAAC Cloud
Sys.setenv(EARTHDATA_TOKEN = "your Earthdata bearer token")
### Set-up parameters of interest
coll <- "VJ121A2.002"
bands <- c("LST_Day_1KM", "LST_Night_1KM")
time_range <- as.Date(c("2026-01-01", "2026-01-30"))
roi <- sf::st_as_sf(
data.frame(
id = "roi_test",
geom = "POLYGON ((-5.82 9.54, -5.42 9.55, -5.41 8.84, -5.81 8.84, -5.82 9.54))"
),
wkt = "geom", crs = 4326
)
### Get the URLs of the data
(urls_vj121a2 <- mf_get_url(
collection = coll,
variables = bands,
roi = roi,
time_range = time_range
))
### Download the data
res_dl <- mf_download_data(urls_vj121a2)
### Import the data as terra::SpatRast
modis_ts <- mf_import_data(dirname(res_dl$destfile[1]), collection = coll)
### Plot the data
terra::plot(modis_ts)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.