From 08c64e399a6f62bfe2145613c6251b96a8a6c2ab Mon Sep 17 00:00:00 2001 From: Koen Hufkens Date: Sun, 18 Dec 2022 15:12:30 +0100 Subject: [PATCH 1/6] fixing terra support --- R/coordinate_conversion.R | 19 ++++--- R/mt_batch_subset.R | 2 +- R/mt_to_raster.R | 110 -------------------------------------- R/mt_to_terra.R | 14 +++-- 4 files changed, 22 insertions(+), 123 deletions(-) delete mode 100644 R/mt_to_raster.R diff --git a/R/coordinate_conversion.R b/R/coordinate_conversion.R index 1c20f18..697e3e9 100644 --- a/R/coordinate_conversion.R +++ b/R/coordinate_conversion.R @@ -38,14 +38,17 @@ sin_to_ll <- function(x, y){ } # convert to sf object - coords <- sf::st_as_sf(x = data.frame(as.numeric(x), - as.numeric(y), - stringsAsFactors = FALSE), - coords = c("as.numeric.x.", "as.numeric.y."), - crs = "+proj=sinu +a=6371007.181 +b=6371007.181 +units=m") + coords <- suppressWarnings( + sf::st_as_sf( + x = data.frame(as.numeric(x), + as.numeric(y), + stringsAsFactors = FALSE), + coords = c("as.numeric.x.", "as.numeric.y."), + crs = "+proj=sinu +a=6371007.181 +b=6371007.181 +units=m +type=crs" + )) # reproject coordinates - coords <- sf::st_transform(coords, "+init=epsg:4326") + coords <- sf::st_transform(coords, crs = 4326) # unravel the sf dataframe into a normal one coords <- as.data.frame(do.call("rbind", lapply(coords$geometry, unlist))) @@ -134,7 +137,9 @@ mt_bbox <- function( # projection etc. p <- sf::st_linestring(m) p <- sf::st_cast(p, "POLYGON") - p <- sf::st_sfc(p, crs = "+proj=sinu +a=6371007.181 +b=6371007.181 +units=m") + p <- suppressWarnings( + sf::st_sfc(p, crs = "+proj=sinu +a=6371007.181 +b=6371007.181 +units=m +type=crs") + ) # a full description of the sinusoidal projection is provided on the # lpdaac page: diff --git a/R/mt_batch_subset.R b/R/mt_batch_subset.R index 581deec..2dd9708 100644 --- a/R/mt_batch_subset.R +++ b/R/mt_batch_subset.R @@ -26,7 +26,7 @@ #' @export #' @examples #' -#' \donttest{ +#' \dontrun{ #' # 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)) diff --git a/R/mt_to_raster.R b/R/mt_to_raster.R deleted file mode 100644 index 8f56246..0000000 --- a/R/mt_to_raster.R +++ /dev/null @@ -1,110 +0,0 @@ -#' Convert tidy MODISTools data to raster (stack) -#' -#' Convert tidy MODISTools data to a raster (stack) -#' -#' @param df a valid MODISTools data frame with a single band (filter for a -#' particular band using the dplyr \code{filter()} function or base \code{subset()} -#' @param reproject reproject output to lat / long (default = \code{FALSE}) -#' @return A raster stack populated with the tidy dataframe values -#' @seealso \code{\link[MODISTools]{mt_subset}} -#' \code{\link[MODISTools]{mt_batch_subset}} -#' @export -#' @examples -#' -#' \donttest{ -#' # 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_raster(df = LC) -#'} -#' -#' @importFrom raster stack - -mt_to_raster <- function( - df, - reproject = FALSE - ){ - - # trap empty function - if(missing(df)){ - stop("No data provided") - } - - # check if data frame - if(!is.data.frame(df)){ - stop("Data is not a data frame") - } - - # check if MODISTools data frame - # (introduce class?) - if(!any(names(df) %in% "modis_date")){ - stop("Data is not a MODISTools data frame") - } - - # check if there are multiple bands stop - # ask for a subset with a single band - if(length(unique(df$band)) != 1){ - stop("Multiple bands in data frame, filter for a single band first!") - } - - # find unique dates for which data should exist - dates <- unique(df$calendar_date) - - # convert scale to 1 if not available - # should not change the numeric value of a band - df$scale[df$scale == "Not Available"] <- 1 - - # loop over all dates, format rasters and return - r <- do.call("stack", - lapply(dates, function(date){ - # stuff values into raster - m <- matrix(as.numeric(df$value[df$calendar_date == date]) * - as.numeric(df$scale[df$calendar_date == date]), - df$nrows[1], - df$ncols[1], - byrow = TRUE) - - # convert to raster and return - return(raster::raster(m)) - }) - ) - - # get bounding box - bb <- MODISTools::mt_bbox( - xllcorner = df$xllcorner[1], - yllcorner = df$yllcorner[1], - cellsize = df$cellsize[1], - nrows = df$nrows[1], - ncols = df$ncols[1], - transform = FALSE) - - # convert to Spatial object (easier to get extent) - bb <- sf::as_Spatial(bb) - - # assign extent + projection bb to raster - raster::extent(r) <- raster::extent(bb) - raster::projection(r) <- raster::projection(bb) - names(r) <- as.character(dates) - - # reproject to lat long when desired - if(reproject){ - r <- raster::projectRaster(r, crs = "+init=epsg:4326") - } - - # return the data - return(r) -} diff --git a/R/mt_to_terra.R b/R/mt_to_terra.R index ad75143..8d55931 100644 --- a/R/mt_to_terra.R +++ b/R/mt_to_terra.R @@ -1,6 +1,7 @@ #' Convert tidy MODISTools data to terra SpatRaster #' -#' Convert tidy MODISTools data to a terra SpatRaster +#' Convert tidy MODISTools data to a terra SpatRaster for easy +#' spatial processing and plotting. #' #' @param df a valid MODISTools data frame with a single band (filter for a #' particular band using the dplyr \code{filter()} function or base \code{subset()} @@ -70,12 +71,14 @@ mt_to_terra <- function( # loop over all dates, format rasters and return r <- do.call("c", lapply(dates, function(date){ + # stuff values into raster m <- matrix(as.numeric(df$value[df$calendar_date == date]) * as.numeric(df$scale[df$calendar_date == date]), df$nrows[1], df$ncols[1], - byrow = TRUE) + byrow = TRUE + ) # convert to raster and return return(terra::rast(m)) @@ -89,21 +92,22 @@ mt_to_terra <- function( cellsize = df$cellsize[1], nrows = df$nrows[1], ncols = df$ncols[1], - transform = FALSE) + transform = FALSE + ) # convert to Spatial object (easier to get extent) bb <- sf::as_Spatial(bb) # assign extent + projection bb to raster terra::ext(r) <- terra::ext(bb) - terra::crs(r) <- as.character(terra::crs(bb)) + terra::crs(r) <- bb@proj4string@projargs names(r) <- as.character(dates) # reproject to lat long when desired if(reproject){ r <- terra::project( r, - "epsg:4326" + crs = 4326 ) } From fff762597cdc123216a9a7b7ec0e1471f34ab41c Mon Sep 17 00:00:00 2001 From: Koen Hufkens Date: Sun, 18 Dec 2022 15:12:42 +0100 Subject: [PATCH 2/6] docs --- DESCRIPTION | 5 +- NAMESPACE | 2 - NEWS.md | 4 + README.Rmd | 4 +- README.md | 78 +-- docs/404.html | 2 +- docs/CONDUCT.html | 2 +- docs/LICENSE-text.html | 2 +- docs/articles/index.html | 2 +- docs/articles/modistools-vignette.html | 562 +++++++++++-------- docs/authors.html | 2 +- docs/index.html | 275 ++++----- docs/news/index.html | 10 +- docs/pkgdown.yml | 6 +- docs/reference/arcachon_lai.html | 4 +- docs/reference/arcachon_lc.html | 4 +- docs/reference/index.html | 6 +- docs/reference/mt_bands.html | 25 +- docs/reference/mt_batch_subset.html | 145 +++-- docs/reference/mt_bbox.html | 124 ++-- docs/reference/mt_dates.html | 29 +- docs/reference/mt_products.html | 42 +- docs/reference/mt_sites.html | 23 +- docs/reference/mt_subset.html | 103 ++-- docs/reference/mt_to_terra.html | 164 ++++++ docs/reference/sin_to_ll.html | 66 ++- docs/sitemap.xml | 3 + man/mt_to_raster.Rd | 48 -- man/mt_to_terra.Rd | 3 +- tests/testthat/test_coordinate_conversions.R | 46 +- 30 files changed, 1007 insertions(+), 784 deletions(-) create mode 100644 docs/reference/mt_to_terra.html delete mode 100644 man/mt_to_raster.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 63a614f..d757d49 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ Imports: httr, utils, sf, - raster, + sp, terra, stats, memoise, @@ -26,13 +26,12 @@ Imports: License: AGPL-3 LazyData: true ByteCompile: true -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.1 Suggests: knitr, rmarkdown, covr, testthat, - rgdal, ggplot2, dplyr VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index ca09939..b826e53 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,9 +7,7 @@ export(mt_dates) export(mt_products) export(mt_sites) export(mt_subset) -export(mt_to_raster) export(mt_to_terra) export(sin_to_ll) importFrom(memoise,memoise) -importFrom(raster,stack) importFrom(terra,rast) diff --git a/NEWS.md b/NEWS.md index e79bab2..c96ae96 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# MODISTools 1.1.3 + +* removing {raster} dependencies + # MODISTools 1.1.2 * removing parallel processing in batch tool due to timeout issues diff --git a/README.Rmd b/README.Rmd index 7dbaf1d..f87c3f8 100644 --- a/README.Rmd +++ b/README.Rmd @@ -158,6 +158,8 @@ Hufkens (2022). The MODISTools package: an interface to the MODIS Land Products ## Acknowledgements -Original development was supported by the UK Natural Environment Research Council (NERC; grants NE/K500811/1 and NE/J011193/1), and the Hans Rausing Scholarship. Refactoring was supported through the Belgian Science Policy office COBECORE project (BELSPO; grant BR/175/A3/COBECORE). Logo design elements are taken from the FontAwesome library according to [these terms](https://fontawesome.com/license), where the globe element was inverted and intersected. +Original development was supported by the UK Natural Environment Research Council (NERC; grants NE/K500811/1 and NE/J011193/1), and the Hans Rausing Scholarship. Refactoring was supported through the Belgian Science Policy office COBECORE project (BELSPO; grant BR/175/A3/COBECORE). Logo design elements are taken from the FontAwesome library according to [these terms](https://fontawesome.com/license), where the globe element was inverted and intersected. Continued support for MODISTools is provided by [BlueGreen Labs](https://bluegreenlabs.org). + + [![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org) diff --git a/README.md b/README.md index 469f086..35da290 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ library("MODISTools") ### Downloading MODIS time series To extract a time series of modis data for a given location and its -direct environment use the mt\_subset() function. +direct environment use the mt_subset() function.
@@ -69,21 +69,21 @@ detailed parameter description (click to expand)

-| Parameter | Description | -|------------|---------------------------------------------------------------------------------------------------------------------------------| -| product | a MODIS product | -| band | a MODIS product band (if NULL all bands are downloaded) | -| lat | latitude of the site | -| lon | longitude of the site | -| start | start year of the time series (data start in 1980) | -| end | end year of the time series (current year - 2 years, use force = TRUE to override) | -| internal | logical, TRUE or FALSE, if true data is imported into R workspace otherwise it is downloaded into the current working directory | -| out\_dir | path where to store the data when not used internally, defaults to tempdir() | -| km\_lr | force “out of temporal range” downloads (integer) | -| km\_ab | suppress the verbose output (integer) | -| site\_name | a site identifier | -| site\_id | a site\_id for predefined locations (not required) | -| progress | logical, TRUE or FALSE (show download progress) | +| Parameter | Description | +|-----------|---------------------------------------------------------------------------------------------------------------------------------| +| product | a MODIS product | +| band | a MODIS product band (if NULL all bands are downloaded) | +| lat | latitude of the site | +| lon | longitude of the site | +| start | start year of the time series (data start in 1980) | +| end | end year of the time series (current year - 2 years, use force = TRUE to override) | +| internal | logical, TRUE or FALSE, if true data is imported into R workspace otherwise it is downloaded into the current working directory | +| out_dir | path where to store the data when not used internally, defaults to tempdir() | +| km_lr | force “out of temporal range” downloads (integer) | +| km_ab | suppress the verbose output (integer) | +| site_name | a site identifier | +| site_id | a site_id for predefined locations (not required) | +| progress | logical, TRUE or FALSE (show download progress) |

@@ -124,9 +124,9 @@ print(str(subset)) #> $ modis_date : chr "A2004001" "A2004009" "A2004017" "A2004025" ... #> $ calendar_date: chr "2004-01-01" "2004-01-09" "2004-01-17" "2004-01-25" ... #> $ tile : chr "h09v05" "h09v05" "h09v05" "h09v05" ... -#> $ proc_date : chr "2015212185706" "2015212201022" "2015212213103" "2015213005429" ... +#> $ proc_date : chr "2020168005635" "2020168010833" "2020168012220" "2020168013617" ... #> $ pixel : int 1 1 1 1 2 2 2 2 3 3 ... -#> $ value : int 13135 13120 13350 13354 13123 13100 13324 13331 13098 13069 ... +#> $ value : int 13148 13160 13398 13412 13153 13140 13370 13388 13131 13096 ... #> NULL ``` @@ -134,7 +134,7 @@ The output format is a *tidy* data frame, as shown above. When witten to a csv with the parameter `internal = FALSE` this will result in a flat file on disk. -Note that when a a region is defined using km\_lr and km\_ab multiple +Note that when a a region is defined using km_lr and km_ab multiple pixels might be returned. These are indexed using the `pixel` column in the data frame containing the time series data. The remote sensing values are listed in the `value` column. When no band is specified all @@ -149,7 +149,7 @@ When a large selection of locations is needed you might benefit from using the batch download function `mt_batch_subset()`, which provides a wrapper around the `mt_subset()` function in order to speed up large download batches. This function has a similar syntax to `mt_subset()` -but requires a data frame defining site names (site\_name) and locations +but requires a data frame defining site names (site_name) and locations (lat / lon) (or a comma delimited file with the same structure) to specify a list of download locations. @@ -191,15 +191,15 @@ print(str(subsets)) #> $ modis_date : chr "A2004001" "A2004009" "A2004017" "A2004025" ... #> $ calendar_date: chr "2004-01-01" "2004-01-09" "2004-01-17" "2004-01-25" ... #> $ tile : chr "h09v05" "h09v05" "h09v05" "h09v05" ... -#> $ proc_date : chr "2015212185706" "2015212201022" "2015212213103" "2015213005429" ... +#> $ proc_date : chr "2020168005635" "2020168010833" "2020168012220" "2020168013617" ... #> $ pixel : int 1 1 1 1 1 1 1 1 -#> $ value : int 13098 13062 13297 13323 13098 13062 13297 13323 +#> $ value : int 13129 13102 13343 13364 13129 13102 13343 13364 #> NULL ``` ### Listing products -To list all available products use the mt\_products() function. +To list all available products use the mt_products() function. ``` r products <- mt_products() @@ -209,27 +209,27 @@ head(products) #> 2 ECO4ESIPTJPL #> 3 ECO4WUE #> 4 GEDI03 -#> 5 MCD12Q1 -#> 6 MCD12Q2 -#> description -#> 1 Daily Surface Weather Data (Daymet) on a 1-km Grid for North America, Version 4 -#> 2 ECOSTRESS Evaporative Stress Index PT-JPL (ESI) Daily L4 Global 70 m -#> 3 ECOSTRESS Water Use Efficiency (WUE) Daily L4 Global 70 m -#> 4 GEDI Gridded Land Surface Metrics (LSM) L3 1km EASE-Grid, Version 2 -#> 5 MODIS/Terra+Aqua Land Cover Type (LC) Yearly L3 Global 500 m SIN Grid -#> 6 MODIS/Terra+Aqua Land Cover Dynamics (LCD) Yearly L3 Global 500 m SIN Grid +#> 5 GEDI04_B +#> 6 MCD12Q1 +#> description +#> 1 Daily Surface Weather Data (Daymet) on a 1-km Grid for North America, Version 4 R1 +#> 2 ECOSTRESS Evaporative Stress Index PT-JPL (ESI) Daily L4 Global 70 m +#> 3 ECOSTRESS Water Use Efficiency (WUE) Daily L4 Global 70 m +#> 4 GEDI Gridded Land Surface Metrics (LSM) L3 1km EASE-Grid, Version 2 +#> 5 GEDI Gridded Aboveground Biomass Density (AGBD) L4B 1km EASE-Grid, Version 2 +#> 6 MODIS/Terra+Aqua Land Cover Type (LC) Yearly L3 Global 500 m SIN Grid #> frequency resolution_meters #> 1 1 day 1000 #> 2 Varies 70 #> 3 Varies 70 #> 4 One time 1000 -#> 5 1 year 500 +#> 5 One time 1000 #> 6 1 year 500 ``` ### Listing bands -To list all available bands for a given product use the mt\_bands() +To list all available bands for a given product use the mt_bands() function. ``` r @@ -254,7 +254,7 @@ head(bands) ### listing dates To list all available dates (temporal coverage) for a given product and -location use the mt\_dates() function. +location use the mt_dates() function. ``` r dates <- mt_dates(product = "MOD11A2", lat = 42, lon = -110) @@ -281,6 +281,10 @@ Hans Rausing Scholarship. Refactoring was supported through the Belgian Science Policy office COBECORE project (BELSPO; grant BR/175/A3/COBECORE). Logo design elements are taken from the FontAwesome library according to [these terms](https://fontawesome.com/license), -where the globe element was inverted and intersected. +where the globe element was inverted and intersected. Continued support +for MODISTools is provided by [BlueGreen +Labs](https://bluegreenlabs.org). -[![ropensci\_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org) + + +[![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org) diff --git a/docs/404.html b/docs/404.html index 820bfef..d8a2950 100644 --- a/docs/404.html +++ b/docs/404.html @@ -100,7 +100,7 @@

Page not found (404)

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/CONDUCT.html b/docs/CONDUCT.html index 9e42e42..1cc0ac3 100644 --- a/docs/CONDUCT.html +++ b/docs/CONDUCT.html @@ -81,7 +81,7 @@

Contributor Code of Conduct

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index db44052..abead70 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -737,7 +737,7 @@

License

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/index.html b/docs/articles/index.html index 9d82aee..e254512 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -72,7 +72,7 @@

All vignettes

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/modistools-vignette.html b/docs/articles/modistools-vignette.html index 343b87f..e61bf33 100644 --- a/docs/articles/modistools-vignette.html +++ b/docs/articles/modistools-vignette.html @@ -79,9 +79,10 @@
-

Note the band names (listed in band column) you want to download, this variable will need to be passed in the final download statement.

+

Note the band names (listed in band column) you want to download, +this variable will need to be passed in the final download +statement.

-

Similarly you can list all available dates (temporal coverage) for a given product and location defined using a latitude and longitude with the mt_dates() function.

+

Similarly you can list all available dates (temporal coverage) for a +given product and location defined using a latitude and longitude with +the mt_dates() function.

-dates <- mt_dates(product = "MOD13Q1", lat = 42, lon = -110)
-head(dates)
-#>   modis_date calendar_date
-#> 1   A2000049    2000-02-18
-#> 2   A2000065    2000-03-05
-#> 3   A2000081    2000-03-21
-#> 4   A2000097    2000-04-06
-#> 5   A2000113    2000-04-22
-#> 6   A2000129    2000-05-08
+dates <- mt_dates(product = "MOD13Q1", lat = 42, lon = -110) +head(dates) +#> modis_date calendar_date +#> 1 A2000049 2000-02-18 +#> 2 A2000065 2000-03-05 +#> 3 A2000081 2000-03-21 +#> 4 A2000097 2000-04-06 +#> 5 A2000113 2000-04-22 +#> 6 A2000129 2000-05-08

Downloading MODIS time series

-

Once you decide on which data to download using the above functions you can use these parameters to download a time series using the mt_subset() function. The below query downloads MOD15A2H based leaf area index (LAI) data for the year 2014 for an area around the Arcachon basin in the south west of France. We will also download land cover data (MCD12Q1, IGBP) at a similar scale. The location is named ‘arcachon’. The output is saved to a variables called subset and LC in the R workspace (as defined by the parameter internal = TRUE, when set to FALSE the data is written to file). Keep in mind that this operation might take a while.

+

Once you decide on which data to download using the above functions +you can use these parameters to download a time series using the +mt_subset() function. The below query downloads MOD15A2H +based leaf area index (LAI) data for the year 2014 for an area around +the Arcachon basin in the south west of France. We will also download +land cover data (MCD12Q1, IGBP) at a similar scale. The location is +named ‘arcachon’. The output is saved to a variables called subset and +LC in the R workspace (as defined by the parameter internal = TRUE, when +set to FALSE the data is written to file). Keep in mind that this +operation might take a while.

-# download the MODIS land cover (IGBP) and NDVI data
-# for a region around the French city and basin of Arcachon
-arcachon_lai <- mt_subset(product = "MOD15A2H",
-                    lat = 44.656286,
-                    lon =  -1.174748,
-                    band = "Lai_500m",
-                    start = "2004-01-01",
-                    end = "2004-12-30",
-                    km_lr = 20,
-                    km_ab = 20,
-                    site_name = "arcachon",
-                    internal = TRUE,
-                    progress = FALSE)
-
-arcachon_lc <- mt_subset(product = "MCD12Q1",
-  lat = 44.656286,
-  lon =  -1.174748,
-  band = "LC_Type1",
-  start = "2004-01-01",
-  end = "2004-3-20",
-  km_lr = 20,
-  km_ab = 20,
-  site_name = "arcachon",
-  internal = TRUE,
-  progress = FALSE)
-

The output format is a tidy data frame, as shown above. When witten to a csv with the parameter internal = FALSE this will result in a flat file on disk.

+# download the MODIS land cover (IGBP) and NDVI data +# for a region around the French city and basin of Arcachon +arcachon_lai <- mt_subset(product = "MOD15A2H", + lat = 44.656286, + lon = -1.174748, + band = "Lai_500m", + start = "2004-01-01", + end = "2004-12-30", + km_lr = 20, + km_ab = 20, + site_name = "arcachon", + internal = TRUE, + progress = FALSE) + +arcachon_lc <- mt_subset(product = "MCD12Q1", + lat = 44.656286, + lon = -1.174748, + band = "LC_Type1", + start = "2004-01-01", + end = "2004-3-20", + km_lr = 20, + km_ab = 20, + site_name = "arcachon", + internal = TRUE, + progress = FALSE)
+

The output format is a tidy data frame, as shown above. When +witten to a csv with the parameter internal = FALSE this +will result in a flat file on disk.

-head(arcachon_lai)
-#>      xllcorner  yllcorner      cellsize nrows ncols     band   units scale
-#> 1.1 -111658.35 4946789.87 463.312716528    81    81 Lai_500m m^2/m^2   0.1
-#> 2.1 -111658.35 4946789.87 463.312716528    81    81 Lai_500m m^2/m^2   0.1
-#> 3.1 -111658.35 4946789.87 463.312716528    81    81 Lai_500m m^2/m^2   0.1
-#> 4.1 -111658.35 4946789.87 463.312716528    81    81 Lai_500m m^2/m^2   0.1
-#> 5.1 -111658.35 4946789.87 463.312716528    81    81 Lai_500m m^2/m^2   0.1
-#> 6.1 -111658.35 4946789.87 463.312716528    81    81 Lai_500m m^2/m^2   0.1
-#>     latitude longitude     site  product      start        end complete
-#> 1.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30     TRUE
-#> 2.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30     TRUE
-#> 3.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30     TRUE
-#> 4.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30     TRUE
-#> 5.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30     TRUE
-#> 6.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30     TRUE
-#>     modis_date calendar_date   tile     proc_date pixel value
-#> 1.1   A2004001    2004-01-01 h17v04 2015085012715     1   254
-#> 2.1   A2004009    2004-01-09 h17v04 2015085075443     1   254
-#> 3.1   A2004017    2004-01-17 h17v04 2015085081742     1   254
-#> 4.1   A2004025    2004-01-25 h17v04 2015112185738     1   254
-#> 5.1   A2004033    2004-02-02 h17v04 2015085192313     1   254
-#> 6.1   A2004041    2004-02-10 h17v04 2015086043310     1   254
-head(arcachon_lc)
-#>      xllcorner  yllcorner      cellsize nrows ncols     band units
-#> 1.1 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.2 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.3 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.4 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.5 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.6 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#>             scale latitude longitude     site product      start       end
-#> 1.1 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.2 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.3 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.4 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.5 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.6 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#>     complete modis_date calendar_date   tile     proc_date pixel value
-#> 1.1     TRUE   A2004001    2004-01-01 h17v04 2018054103350     1    17
-#> 1.2     TRUE   A2004001    2004-01-01 h17v04 2018054103350     2    17
-#> 1.3     TRUE   A2004001    2004-01-01 h17v04 2018054103350     3    17
-#> 1.4     TRUE   A2004001    2004-01-01 h17v04 2018054103350     4    17
-#> 1.5     TRUE   A2004001    2004-01-01 h17v04 2018054103350     5    17
-#> 1.6     TRUE   A2004001    2004-01-01 h17v04 2018054103350     6    17
-

Note that when a a region is defined using km_lr and km_ab multiple pixels might be returned. These are indexed using the pixel column in the data frame containing the time series data. The remote sensing values are listed in the value column. When no band is specified all bands of a given product are returned, be mindful of the fact that different bands might require different multipliers to represent their true values.

-

When a large selection of locations is needed you might benefit from using the batch download function mt_batch_subset(), which provides a wrapper around the mt_subset() function in order to speed up large download batches. This function has a similar syntax to mt_subset() but requires a data frame defining site names (site_name) and locations (lat / lon) (or a comma delimited file with the same structure) to specify a list of download locations.

+head(arcachon_lai) +#> xllcorner yllcorner cellsize nrows ncols band units scale +#> 1.1 -111658.35 4946789.87 463.312716528 81 81 Lai_500m m^2/m^2 0.1 +#> 2.1 -111658.35 4946789.87 463.312716528 81 81 Lai_500m m^2/m^2 0.1 +#> 3.1 -111658.35 4946789.87 463.312716528 81 81 Lai_500m m^2/m^2 0.1 +#> 4.1 -111658.35 4946789.87 463.312716528 81 81 Lai_500m m^2/m^2 0.1 +#> 5.1 -111658.35 4946789.87 463.312716528 81 81 Lai_500m m^2/m^2 0.1 +#> 6.1 -111658.35 4946789.87 463.312716528 81 81 Lai_500m m^2/m^2 0.1 +#> latitude longitude site product start end complete +#> 1.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30 TRUE +#> 2.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30 TRUE +#> 3.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30 TRUE +#> 4.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30 TRUE +#> 5.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30 TRUE +#> 6.1 44.65629 -1.174748 arcachon MOD15A2H 2004-01-01 2004-12-30 TRUE +#> modis_date calendar_date tile proc_date pixel value +#> 1.1 A2004001 2004-01-01 h17v04 2015085012715 1 254 +#> 2.1 A2004009 2004-01-09 h17v04 2015085075443 1 254 +#> 3.1 A2004017 2004-01-17 h17v04 2015085081742 1 254 +#> 4.1 A2004025 2004-01-25 h17v04 2015112185738 1 254 +#> 5.1 A2004033 2004-02-02 h17v04 2015085192313 1 254 +#> 6.1 A2004041 2004-02-10 h17v04 2015086043310 1 254 +head(arcachon_lc) +#> xllcorner yllcorner cellsize nrows ncols band units +#> 1.1 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.2 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.3 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.4 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.5 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.6 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> scale latitude longitude site product start end +#> 1.1 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.2 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.3 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.4 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.5 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.6 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> complete modis_date calendar_date tile proc_date pixel value +#> 1.1 TRUE A2004001 2004-01-01 h17v04 2018054103350 1 17 +#> 1.2 TRUE A2004001 2004-01-01 h17v04 2018054103350 2 17 +#> 1.3 TRUE A2004001 2004-01-01 h17v04 2018054103350 3 17 +#> 1.4 TRUE A2004001 2004-01-01 h17v04 2018054103350 4 17 +#> 1.5 TRUE A2004001 2004-01-01 h17v04 2018054103350 5 17 +#> 1.6 TRUE A2004001 2004-01-01 h17v04 2018054103350 6 17 +

Note that when a a region is defined using km_lr and km_ab multiple +pixels might be returned. These are indexed using the pixel +column in the data frame containing the time series data. The remote +sensing values are listed in the value column. When no band +is specified all bands of a given product are returned, be mindful of +the fact that different bands might require different multipliers to +represent their true values.

+

When a large selection of locations is needed you might benefit from +using the batch download function mt_batch_subset(), which +provides a wrapper around the mt_subset() function in order +to speed up large download batches. This function has a similar syntax +to mt_subset() but requires a data frame defining site +names (site_name) and locations (lat / lon) (or a comma delimited file +with the same structure) to specify a list of download locations.

-# 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), stringsAsFactors = FALSE)
-df$lat <- 40
-df$lon <- -110
-
-# an example batch download data frame
-head(df)
-#>   site_name lat  lon
-#> 1    test 1  40 -110
-#> 2    test 2  40 -110
+# 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), stringsAsFactors = FALSE) +df$lat <- 40 +df$lon <- -110 + +# an example batch download data frame +head(df) +#> site_name lat lon +#> 1 test 1 40 -110 +#> 2 test 2 40 -110
-# test batch download
-subsets <- mt_batch_subset(df = df,
-                     product = "MOD13Q1",
-                     band = "250m_16_days_NDVI",
-                     km_lr = 1,
-                     km_ab = 1,
-                     start = "2004-01-01",
-                     end = "2004-12-30",
-                     internal = TRUE)
+# test batch download +subsets <- mt_batch_subset(df = df, + product = "MOD13Q1", + band = "250m_16_days_NDVI", + km_lr = 1, + km_ab = 1, + start = "2004-01-01", + end = "2004-12-30", + internal = TRUE)

Worked example using LAI values around the bay of Arcachon

-

The below example processes the data downloaded above to look at differences in the seasonal changes in leaf area index (LAI, or the amount of leaves per unit ground area) for the Arcachon bay in south-west France. To do this we merge the land cover and LAI data on a pixel by pixel basis.

+

The below example processes the data downloaded above to look at +differences in the seasonal changes in leaf area index (LAI, or the +amount of leaves per unit ground area) for the Arcachon bay in +south-west France. To do this we merge the land cover and LAI data on a +pixel by pixel basis.

-# merge land cover and lai data
-arcachon <- arcachon_lc %>%
-  rename("lc" = "value") %>%
-  select("lc","pixel") %>%
-  right_join(arcachon_lai, by = "pixel")
-

Then, filter out all non valid values (> 100), only select evergreen and deciduous land cover classes (1 and 5, or, ENF and DBF respectivelly), convert them to more readable labels, and across these land cover classes take the median per acquisition date.

+# merge land cover and lai data +arcachon <- arcachon_lc %>% + rename("lc" = "value") %>% + select("lc","pixel") %>% + right_join(arcachon_lai, by = "pixel")
+

Then, filter out all non valid values (> 100), only select +evergreen and deciduous land cover classes (1 and 5, or, ENF and DBF +respectivelly), convert them to more readable labels, and across these +land cover classes take the median per acquisition date.

-# create a plot of the data - accounting for the multiplier (scale) component
-arcachon <- arcachon %>%
-  filter(value <= 100,
-         lc %in% c("1","5")) %>% # retain everything but fill values
-  mutate(lc = ifelse(lc == 1, "ENF","DBF")) %>%
-  group_by(lc, calendar_date) %>% # group by lc and date
-  summarize(doy = as.numeric(format(as.Date(calendar_date)[1],"%j")),
-            lai_mean = median(value * as.double(scale)))
-#> `summarise()` has grouped output by 'lc'. You can override using the `.groups`
-#> argument.
-

Finally, the plot will show you the seasonal time series of LAI for both land cover classes (ENF and DBF). Note the difference in timing and amplitude between both these forest types, where the evergreen (ENF) pixels show lower LAI values and a more gradual seasonal pattern compared to the deciduous trees.

+# create a plot of the data - accounting for the multiplier (scale) component +arcachon <- arcachon %>% + filter(value <= 100, + lc %in% c("1","5")) %>% # retain everything but fill values + mutate(lc = ifelse(lc == 1, "ENF","DBF")) %>% + group_by(lc, calendar_date) %>% # group by lc and date + summarize(doy = as.numeric(format(as.Date(calendar_date)[1],"%j")), + lai_mean = median(value * as.double(scale))) +#> `summarise()` has grouped output by 'lc'. You can override using the `.groups` +#> argument. +

Finally, the plot will show you the seasonal time series of LAI for +both land cover classes (ENF and DBF). Note the difference in timing and +amplitude between both these forest types, where the evergreen (ENF) +pixels show lower LAI values and a more gradual seasonal pattern +compared to the deciduous trees.

-# plot LAI by date and per land cover class
-ggplot(arcachon, aes(x = doy, y = lai_mean)) +
-  geom_point() +
-  geom_smooth(span = 0.3, method = "loess") +
-  labs(x = "day of year (DOY)",
-       y = "leaf area index (LAI)") +
-  theme_minimal() +
-  facet_wrap(~ lc)
-#> `geom_smooth()` using formula 'y ~ x'
+# plot LAI by date and per land cover class +ggplot(arcachon, aes(x = doy, y = lai_mean)) + + geom_point() + + geom_smooth(span = 0.3, method = "loess") + + labs(x = "day of year (DOY)", + y = "leaf area index (LAI)") + + theme_minimal() + + facet_wrap(~ lc) +#> `geom_smooth()` using formula = 'y ~ x'

Conversion of corner coordinates

-

Corner coordinates of the pixel area extracted are provided, these can be used to calculate the coverage of the extracted area. Coordinates are provided in the original sinusoidal grid coordinates and first have to be transformed into latitude longitude (for convenience).

+

Corner coordinates of the pixel area extracted are provided, these +can be used to calculate the coverage of the extracted area. Coordinates +are provided in the original sinusoidal grid coordinates and first have +to be transformed into latitude longitude (for convenience).

-# convert the coordinates
-lat_lon <- sin_to_ll(arcachon_lc$xllcorner, arcachon_lc$yllcorner)
-#> Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
-#> deprecated. It might return a CRS with a non-EPSG compliant axis order.
-
-# bind with the original dataframe
-subset <- cbind(arcachon_lc, lat_lon)
-
-head(subset)
-#>      xllcorner  yllcorner      cellsize nrows ncols     band units
-#> 1.1 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.2 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.3 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.4 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.5 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#> 1.6 -111658.35 4946789.87 463.312716528    81    81 LC_Type1 class
-#>             scale latitude longitude     site product      start       end
-#> 1.1 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.2 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.3 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.4 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.5 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#> 1.6 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20
-#>     complete modis_date calendar_date   tile     proc_date pixel value
-#> 1.1     TRUE   A2004001    2004-01-01 h17v04 2018054103350     1    17
-#> 1.2     TRUE   A2004001    2004-01-01 h17v04 2018054103350     2    17
-#> 1.3     TRUE   A2004001    2004-01-01 h17v04 2018054103350     3    17
-#> 1.4     TRUE   A2004001    2004-01-01 h17v04 2018054103350     4    17
-#> 1.5     TRUE   A2004001    2004-01-01 h17v04 2018054103350     5    17
-#> 1.6     TRUE   A2004001    2004-01-01 h17v04 2018054103350     6    17
-#>     longitude_ll latitude_ll
-#> 1.1    -1.407572     44.4875
-#> 1.2    -1.407572     44.4875
-#> 1.3    -1.407572     44.4875
-#> 1.4    -1.407572     44.4875
-#> 1.5    -1.407572     44.4875
-#> 1.6    -1.407572     44.4875
-

Together with meta-data regarding cell size, number of columns and rows the bounding box of the extracted data can be calculated.

+# convert the coordinates +lat_lon <- sin_to_ll(arcachon_lc$xllcorner, arcachon_lc$yllcorner) +#> Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is +#> deprecated. It might return a CRS with a non-EPSG compliant axis order. + +# bind with the original dataframe +subset <- cbind(arcachon_lc, lat_lon) + +head(subset) +#> xllcorner yllcorner cellsize nrows ncols band units +#> 1.1 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.2 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.3 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.4 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.5 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> 1.6 -111658.35 4946789.87 463.312716528 81 81 LC_Type1 class +#> scale latitude longitude site product start end +#> 1.1 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.2 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.3 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.4 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.5 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> 1.6 Not Available 44.65629 -1.174748 arcachon MCD12Q1 2004-01-01 2004-3-20 +#> complete modis_date calendar_date tile proc_date pixel value +#> 1.1 TRUE A2004001 2004-01-01 h17v04 2018054103350 1 17 +#> 1.2 TRUE A2004001 2004-01-01 h17v04 2018054103350 2 17 +#> 1.3 TRUE A2004001 2004-01-01 h17v04 2018054103350 3 17 +#> 1.4 TRUE A2004001 2004-01-01 h17v04 2018054103350 4 17 +#> 1.5 TRUE A2004001 2004-01-01 h17v04 2018054103350 5 17 +#> 1.6 TRUE A2004001 2004-01-01 h17v04 2018054103350 6 17 +#> longitude_ll latitude_ll +#> 1.1 -1.407572 44.4875 +#> 1.2 -1.407572 44.4875 +#> 1.3 -1.407572 44.4875 +#> 1.4 -1.407572 44.4875 +#> 1.5 -1.407572 44.4875 +#> 1.6 -1.407572 44.4875
+

Together with meta-data regarding cell size, number of columns and +rows the bounding box of the extracted data can be calculated.

-# convert to bounding box
-bb <- apply(arcachon_lc, 1, function(x){
-  mt_bbox(xllcorner = x['xllcorner'],
-          yllcorner = x['yllcorner'],
-           cellsize = x['cellsize'],
-           nrows = x['nrows'],
-           ncols = x['ncols'])
-})
-
-# plot one bounding box
-plot(bb[[1]])
-
-# add the location of the queried coordinate within the polygon
-points(arcachon_lc$longitude[1],
-       arcachon_lc$latitude[1],
-       pch = 20,
-       col = "red")
-

+# convert to bounding box +bb <- apply(arcachon_lc, 1, function(x){ + mt_bbox(xllcorner = x['xllcorner'], + yllcorner = x['yllcorner'], + cellsize = x['cellsize'], + nrows = x['nrows'], + ncols = x['ncols']) +}) +#> Error in sf::st_sfc(p, crs = CRS): is.numeric(crs) || is.character(crs) || inherits(crs, "crs") is not TRUE + +# plot one bounding box +plot(bb[[1]]) +#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'bb' not found + +# add the location of the queried coordinate within the polygon +points(arcachon_lc$longitude[1], + arcachon_lc$latitude[1], + pch = 20, + col = "red") +#> Error in plot.xy(xy.coords(x, y), type = type, ...): plot.new has not been called yet

Conversion to (gridded) raster data

-

Although the package is often used to deal with single pixel locations the provisions to download a small region of interest defined by kilometers left-right (west-east) or top-bottom (north-south) allows you to grab small geographic regions for further analysis. The default tidy dataframe format isn’t ideal for visualizing this inherently spatial data. Therefore a helper function mt_to_raster() is available to convert the tidy dataframe to a gridded (georeferenced) raster format.

-

Below a small region (20x20km) is downloaded around the seaside town of Arcachon, France for the MODIS land cover product (MCD12Q1). The data is converted using mt_to_raster() with a reproject parameter set to true to plot latitude and longitude coordinates (instead of the default sinusoidal ones).

+

Although the package is often used to deal with single pixel +locations the provisions to download a small region of interest defined +by kilometers left-right (west-east) or top-bottom (north-south) allows +you to grab small geographic regions for further analysis. The default +tidy dataframe format isn’t ideal for visualizing this inherently +spatial data. Therefore a helper function mt_to_raster() is +available to convert the tidy dataframe to a gridded (georeferenced) +raster format.

+

Below a small region (20x20km) is downloaded around the seaside town +of Arcachon, France for the MODIS land cover +product (MCD12Q1). The data is converted using +mt_to_raster() with a reproject parameter set to true to +plot latitude and longitude coordinates (instead of the default +sinusoidal ones).

-# convert to raster, when reproject is TRUE
-# the data is reprojected to lat / lon if FALSE
-# the data is shown in its original sinuidal projection
-LC_r <- mt_to_raster(df = arcachon_lc, reproject = TRUE)
-
-# plot the raster data as a map
-plot(LC_r)
-

+# convert to raster, when reproject is TRUE +# the data is reprojected to lat / lon if FALSE +# the data is shown in its original sinuidal projection +LC_r <- mt_to_raster(df = arcachon_lc, reproject = TRUE) +#> Error in mt_to_raster(df = arcachon_lc, reproject = TRUE): could not find function "mt_to_raster" + +# plot the raster data as a map +plot(LC_r) +#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'plot': object 'LC_r' not found
@@ -386,7 +460,7 @@

Conversion to (gridded) raster data

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/authors.html b/docs/authors.html index a7e3b61..c4ce64d 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -90,7 +90,7 @@

Citation

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/index.html b/docs/index.html index 94a3466..bd7e3f9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -96,22 +96,22 @@

stable release

To install the current stable release use a CRAN repository:

+install.packages("MODISTools") +library("MODISTools")

development release

To install the development releases of the package run the following commands:

-if(!require(devtools)){install.package("devtools")}
-devtools::install_github("khufkens/MODISTools")
-library("MODISTools")
+if(!require(devtools)){install.package("devtools")} +devtools::install_github("khufkens/MODISTools") +library("MODISTools")

Vignettes are not rendered by default, if you want to include additional documentation please use:

-if(!require(devtools)){install.package("devtools")}
-devtools::install_github("khufkens/MODISTools", build_vignettes = TRUE)
-library("MODISTools")
+if(!require(devtools)){install.package("devtools")} +devtools::install_github("khufkens/MODISTools", build_vignettes = TRUE) +library("MODISTools")
@@ -127,8 +127,8 @@

Downloading MODIS time series - - + + Parameter @@ -189,45 +189,45 @@

Downloading MODIS time series
-# load the library
-library(MODISTools)
-
-# download data
-subset <- mt_subset(product = "MOD11A2",
-                    lat = 40,
-                    lon = -110,
-                    band = "LST_Day_1km",
-                    start = "2004-01-01",
-                    end = "2004-02-01",
-                    km_lr = 1,
-                    km_ab = 1,
-                    site_name = "testsite",
-                    internal = TRUE,
-                    progress = FALSE)
-print(str(subset))
-#> 'data.frame':    36 obs. of  21 variables:
-#>  $ xllcorner    : chr  "-9370963.05" "-9370963.05" "-9370963.05" "-9370963.05" ...
-#>  $ yllcorner    : chr  "4445948.79" "4445948.79" "4445948.79" "4445948.79" ...
-#>  $ cellsize     : chr  "926.625433055834" "926.625433055834" "926.625433055834" "926.625433055834" ...
-#>  $ nrows        : int  3 3 3 3 3 3 3 3 3 3 ...
-#>  $ ncols        : int  3 3 3 3 3 3 3 3 3 3 ...
-#>  $ band         : chr  "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" ...
-#>  $ units        : chr  "Kelvin" "Kelvin" "Kelvin" "Kelvin" ...
-#>  $ scale        : chr  "0.02" "0.02" "0.02" "0.02" ...
-#>  $ latitude     : num  40 40 40 40 40 40 40 40 40 40 ...
-#>  $ longitude    : num  -110 -110 -110 -110 -110 -110 -110 -110 -110 -110 ...
-#>  $ site         : chr  "testsite" "testsite" "testsite" "testsite" ...
-#>  $ product      : chr  "MOD11A2" "MOD11A2" "MOD11A2" "MOD11A2" ...
-#>  $ start        : chr  "2004-01-01" "2004-01-01" "2004-01-01" "2004-01-01" ...
-#>  $ end          : chr  "2004-02-01" "2004-02-01" "2004-02-01" "2004-02-01" ...
-#>  $ complete     : logi  TRUE TRUE TRUE TRUE TRUE TRUE ...
-#>  $ modis_date   : chr  "A2004001" "A2004009" "A2004017" "A2004025" ...
-#>  $ calendar_date: chr  "2004-01-01" "2004-01-09" "2004-01-17" "2004-01-25" ...
-#>  $ tile         : chr  "h09v05" "h09v05" "h09v05" "h09v05" ...
-#>  $ proc_date    : chr  "2015212185706" "2015212201022" "2015212213103" "2015213005429" ...
-#>  $ pixel        : int  1 1 1 1 2 2 2 2 3 3 ...
-#>  $ value        : int  13135 13120 13350 13354 13123 13100 13324 13331 13098 13069 ...
-#> NULL

+# load the library +library(MODISTools) + +# download data +subset <- mt_subset(product = "MOD11A2", + lat = 40, + lon = -110, + band = "LST_Day_1km", + start = "2004-01-01", + end = "2004-02-01", + km_lr = 1, + km_ab = 1, + site_name = "testsite", + internal = TRUE, + progress = FALSE) +print(str(subset)) +#> 'data.frame': 36 obs. of 21 variables: +#> $ xllcorner : chr "-9370963.05" "-9370963.05" "-9370963.05" "-9370963.05" ... +#> $ yllcorner : chr "4445948.79" "4445948.79" "4445948.79" "4445948.79" ... +#> $ cellsize : chr "926.625433055834" "926.625433055834" "926.625433055834" "926.625433055834" ... +#> $ nrows : int 3 3 3 3 3 3 3 3 3 3 ... +#> $ ncols : int 3 3 3 3 3 3 3 3 3 3 ... +#> $ band : chr "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" ... +#> $ units : chr "Kelvin" "Kelvin" "Kelvin" "Kelvin" ... +#> $ scale : chr "0.02" "0.02" "0.02" "0.02" ... +#> $ latitude : num 40 40 40 40 40 40 40 40 40 40 ... +#> $ longitude : num -110 -110 -110 -110 -110 -110 -110 -110 -110 -110 ... +#> $ site : chr "testsite" "testsite" "testsite" "testsite" ... +#> $ product : chr "MOD11A2" "MOD11A2" "MOD11A2" "MOD11A2" ... +#> $ start : chr "2004-01-01" "2004-01-01" "2004-01-01" "2004-01-01" ... +#> $ end : chr "2004-02-01" "2004-02-01" "2004-02-01" "2004-02-01" ... +#> $ complete : logi TRUE TRUE TRUE TRUE TRUE TRUE ... +#> $ modis_date : chr "A2004001" "A2004009" "A2004017" "A2004025" ... +#> $ calendar_date: chr "2004-01-01" "2004-01-09" "2004-01-17" "2004-01-25" ... +#> $ tile : chr "h09v05" "h09v05" "h09v05" "h09v05" ... +#> $ proc_date : chr "2020168005635" "2020168010833" "2020168012220" "2020168013617" ... +#> $ pixel : int 1 1 1 1 2 2 2 2 3 3 ... +#> $ value : int 13148 13160 13398 13412 13153 13140 13370 13388 13131 13096 ... +#> NULL

The output format is a tidy data frame, as shown above. When witten to a csv with the parameter internal = FALSE this will result in a flat file on disk.

Note that when a a region is defined using km_lr and km_ab multiple pixels might be returned. These are indexed using the pixel column in the data frame containing the time series data. The remote sensing values are listed in the value column. When no band is specified all bands of a given product are returned, be mindful of the fact that different bands might require different multipliers to represent their true values. To list all available products, bands for particular products and temporal coverage see function descriptions below.

@@ -237,110 +237,110 @@

Batch downloading MODIS time series

When a large selection of locations is needed you might benefit from using the batch download function mt_batch_subset(), which provides a wrapper around the mt_subset() function in order to speed up large download batches. This function has a similar syntax to mt_subset() but requires a data frame defining site names (site_name) and locations (lat / lon) (or a comma delimited file with the same structure) to specify a list of download locations.

Below an example is provided on how to batch download data for a data frame of given site names and locations (lat / lon).

-# 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
-  
-# test batch download
-subsets <- mt_batch_subset(df = df,
-                     product = "MOD11A2",
-                     band = "LST_Day_1km",
-                     internal = TRUE,
-                     start = "2004-01-01",
-                     end = "2004-02-01")
-
-print(str(subsets))
-#> 'data.frame':    8 obs. of  21 variables:
-#>  $ xllcorner    : chr  "-9370036.35" "-9370036.35" "-9370036.35" "-9370036.35" ...
-#>  $ yllcorner    : chr  "4446875.49" "4446875.49" "4446875.49" "4446875.49" ...
-#>  $ cellsize     : chr  "926.625433055834" "926.625433055834" "926.625433055834" "926.625433055834" ...
-#>  $ nrows        : int  1 1 1 1 1 1 1 1
-#>  $ ncols        : int  1 1 1 1 1 1 1 1
-#>  $ band         : chr  "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" ...
-#>  $ units        : chr  "Kelvin" "Kelvin" "Kelvin" "Kelvin" ...
-#>  $ scale        : chr  "0.02" "0.02" "0.02" "0.02" ...
-#>  $ latitude     : num  40 40 40 40 40 40 40 40
-#>  $ longitude    : num  -110 -110 -110 -110 -110 -110 -110 -110
-#>  $ site         : chr  "test 1" "test 1" "test 1" "test 1" ...
-#>  $ product      : chr  "MOD11A2" "MOD11A2" "MOD11A2" "MOD11A2" ...
-#>  $ start        : chr  "2004-01-01" "2004-01-01" "2004-01-01" "2004-01-01" ...
-#>  $ end          : chr  "2004-02-01" "2004-02-01" "2004-02-01" "2004-02-01" ...
-#>  $ complete     : logi  TRUE TRUE TRUE TRUE TRUE TRUE ...
-#>  $ modis_date   : chr  "A2004001" "A2004009" "A2004017" "A2004025" ...
-#>  $ calendar_date: chr  "2004-01-01" "2004-01-09" "2004-01-17" "2004-01-25" ...
-#>  $ tile         : chr  "h09v05" "h09v05" "h09v05" "h09v05" ...
-#>  $ proc_date    : chr  "2015212185706" "2015212201022" "2015212213103" "2015213005429" ...
-#>  $ pixel        : int  1 1 1 1 1 1 1 1
-#>  $ value        : int  13098 13062 13297 13323 13098 13062 13297 13323
-#> NULL
+# 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 + +# test batch download +subsets <- mt_batch_subset(df = df, + product = "MOD11A2", + band = "LST_Day_1km", + internal = TRUE, + start = "2004-01-01", + end = "2004-02-01") + +print(str(subsets)) +#> 'data.frame': 8 obs. of 21 variables: +#> $ xllcorner : chr "-9370036.35" "-9370036.35" "-9370036.35" "-9370036.35" ... +#> $ yllcorner : chr "4446875.49" "4446875.49" "4446875.49" "4446875.49" ... +#> $ cellsize : chr "926.625433055834" "926.625433055834" "926.625433055834" "926.625433055834" ... +#> $ nrows : int 1 1 1 1 1 1 1 1 +#> $ ncols : int 1 1 1 1 1 1 1 1 +#> $ band : chr "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" "LST_Day_1km" ... +#> $ units : chr "Kelvin" "Kelvin" "Kelvin" "Kelvin" ... +#> $ scale : chr "0.02" "0.02" "0.02" "0.02" ... +#> $ latitude : num 40 40 40 40 40 40 40 40 +#> $ longitude : num -110 -110 -110 -110 -110 -110 -110 -110 +#> $ site : chr "test 1" "test 1" "test 1" "test 1" ... +#> $ product : chr "MOD11A2" "MOD11A2" "MOD11A2" "MOD11A2" ... +#> $ start : chr "2004-01-01" "2004-01-01" "2004-01-01" "2004-01-01" ... +#> $ end : chr "2004-02-01" "2004-02-01" "2004-02-01" "2004-02-01" ... +#> $ complete : logi TRUE TRUE TRUE TRUE TRUE TRUE ... +#> $ modis_date : chr "A2004001" "A2004009" "A2004017" "A2004025" ... +#> $ calendar_date: chr "2004-01-01" "2004-01-09" "2004-01-17" "2004-01-25" ... +#> $ tile : chr "h09v05" "h09v05" "h09v05" "h09v05" ... +#> $ proc_date : chr "2020168005635" "2020168010833" "2020168012220" "2020168013617" ... +#> $ pixel : int 1 1 1 1 1 1 1 1 +#> $ value : int 13129 13102 13343 13364 13129 13102 13343 13364 +#> NULL

Listing products

To list all available products use the mt_products() function.

-products <- mt_products()
-head(products)
-#>        product
-#> 1       Daymet
-#> 2 ECO4ESIPTJPL
-#> 3      ECO4WUE
-#> 4       GEDI03
-#> 5      MCD12Q1
-#> 6      MCD12Q2
-#>                                                                       description
-#> 1 Daily Surface Weather Data (Daymet) on a 1-km Grid for North America, Version 4
-#> 2            ECOSTRESS Evaporative Stress Index PT-JPL (ESI) Daily L4 Global 70 m
-#> 3                       ECOSTRESS Water Use Efficiency (WUE) Daily L4 Global 70 m
-#> 4             GEDI Gridded Land Surface Metrics (LSM) L3 1km EASE-Grid, Version 2
-#> 5           MODIS/Terra+Aqua Land Cover Type (LC) Yearly L3 Global 500 m SIN Grid
-#> 6      MODIS/Terra+Aqua Land Cover Dynamics (LCD) Yearly L3 Global 500 m SIN Grid
-#>   frequency resolution_meters
-#> 1     1 day              1000
-#> 2    Varies                70
-#> 3    Varies                70
-#> 4  One time              1000
-#> 5    1 year               500
-#> 6    1 year               500
+products <- mt_products() +head(products) +#> product +#> 1 Daymet +#> 2 ECO4ESIPTJPL +#> 3 ECO4WUE +#> 4 GEDI03 +#> 5 GEDI04_B +#> 6 MCD12Q1 +#> description +#> 1 Daily Surface Weather Data (Daymet) on a 1-km Grid for North America, Version 4 R1 +#> 2 ECOSTRESS Evaporative Stress Index PT-JPL (ESI) Daily L4 Global 70 m +#> 3 ECOSTRESS Water Use Efficiency (WUE) Daily L4 Global 70 m +#> 4 GEDI Gridded Land Surface Metrics (LSM) L3 1km EASE-Grid, Version 2 +#> 5 GEDI Gridded Aboveground Biomass Density (AGBD) L4B 1km EASE-Grid, Version 2 +#> 6 MODIS/Terra+Aqua Land Cover Type (LC) Yearly L3 Global 500 m SIN Grid +#> frequency resolution_meters +#> 1 1 day 1000 +#> 2 Varies 70 +#> 3 Varies 70 +#> 4 One time 1000 +#> 5 One time 1000 +#> 6 1 year 500

Listing bands

To list all available bands for a given product use the mt_bands() function.

-bands <- mt_bands(product = "MOD11A2")
-head(bands)
-#>               band                          description valid_range fill_value
-#> 1   Clear_sky_days               Day clear-sky coverage    1 to 255          0
-#> 2 Clear_sky_nights             Night clear-sky coverage    1 to 255          0
-#> 3    Day_view_angl View zenith angle of day observation    0 to 130        255
-#> 4    Day_view_time        Local time of day observation    0 to 240        255
-#> 5          Emis_31                   Band 31 emissivity    1 to 255          0
-#> 6          Emis_32                   Band 32 emissivity    1 to 255          0
-#>    units scale_factor add_offset
-#> 1   <NA>         <NA>       <NA>
-#> 2   <NA>         <NA>       <NA>
-#> 3 degree            1        -65
-#> 4    hrs          0.1          0
-#> 5   <NA>        0.002       0.49
-#> 6   <NA>        0.002       0.49
+bands <- mt_bands(product = "MOD11A2") +head(bands) +#> band description valid_range fill_value +#> 1 Clear_sky_days Day clear-sky coverage 1 to 255 0 +#> 2 Clear_sky_nights Night clear-sky coverage 1 to 255 0 +#> 3 Day_view_angl View zenith angle of day observation 0 to 130 255 +#> 4 Day_view_time Local time of day observation 0 to 240 255 +#> 5 Emis_31 Band 31 emissivity 1 to 255 0 +#> 6 Emis_32 Band 32 emissivity 1 to 255 0 +#> units scale_factor add_offset +#> 1 <NA> <NA> <NA> +#> 2 <NA> <NA> <NA> +#> 3 degree 1 -65 +#> 4 hrs 0.1 0 +#> 5 <NA> 0.002 0.49 +#> 6 <NA> 0.002 0.49

listing dates

To list all available dates (temporal coverage) for a given product and location use the mt_dates() function.

-dates <- mt_dates(product = "MOD11A2", lat = 42, lon = -110)
-head(dates)
-#>   modis_date calendar_date
-#> 1   A2000049    2000-02-18
-#> 2   A2000057    2000-02-26
-#> 3   A2000065    2000-03-05
-#> 4   A2000073    2000-03-13
-#> 5   A2000081    2000-03-21
-#> 6   A2000089    2000-03-29
+dates <- mt_dates(product = "MOD11A2", lat = 42, lon = -110) +head(dates) +#> modis_date calendar_date +#> 1 A2000049 2000-02-18 +#> 2 A2000057 2000-02-26 +#> 3 A2000065 2000-03-05 +#> 4 A2000073 2000-03-13 +#> 5 A2000081 2000-03-21 +#> 6 A2000089 2000-03-29
@@ -351,7 +351,8 @@

References

Acknowledgements

-

Original development was supported by the UK Natural Environment Research Council (NERC; grants NE/K500811/1 and NE/J011193/1), and the Hans Rausing Scholarship. Refactoring was supported through the Belgian Science Policy office COBECORE project (BELSPO; grant BR/175/A3/COBECORE). Logo design elements are taken from the FontAwesome library according to these terms, where the globe element was inverted and intersected.

+

Original development was supported by the UK Natural Environment Research Council (NERC; grants NE/K500811/1 and NE/J011193/1), and the Hans Rausing Scholarship. Refactoring was supported through the Belgian Science Policy office COBECORE project (BELSPO; grant BR/175/A3/COBECORE). Logo design elements are taken from the FontAwesome library according to these terms, where the globe element was inverted and intersected. Continued support for MODISTools is provided by BlueGreen Labs.

+

ropensci_footer

@@ -409,7 +410,7 @@

Dev status

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/news/index.html b/docs/news/index.html index 382c5eb..a60ab54 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -58,14 +58,18 @@

Changelog

- + +
  • removing {raster} dependencies
  • +
+
+
  • removing parallel processing in batch tool due to timeout issues
  • set error = TRUE on vignette to prevent stopping during render
  • correct batch downloading, missing argument in apply()
-
  • added raster conversion function mt_to_raster() +
    • added raster conversion function mt_to_raster()
    • force integer values on buffer values
    • removed keywords
    • @@ -102,7 +106,7 @@
-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index ae25b94..99d5259 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,7 +1,7 @@ -pandoc: 2.11.4 -pkgdown: 2.0.2 +pandoc: '2.18' +pkgdown: 2.0.6 pkgdown_sha: ~ articles: modistools-vignette: modistools-vignette.html -last_built: 2022-04-04T09:15Z +last_built: 2022-12-18T11:23Z diff --git a/docs/reference/arcachon_lai.html b/docs/reference/arcachon_lai.html index e0ab493..95f84cc 100644 --- a/docs/reference/arcachon_lai.html +++ b/docs/reference/arcachon_lai.html @@ -65,7 +65,7 @@

arcachon_lai

-
arcachon_lai
+
arcachon_lai
@@ -85,7 +85,7 @@

Format

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/arcachon_lc.html b/docs/reference/arcachon_lc.html index 81a7a08..b1a5c26 100644 --- a/docs/reference/arcachon_lc.html +++ b/docs/reference/arcachon_lc.html @@ -65,7 +65,7 @@

arcachon_lc

-
arcachon_lc
+
arcachon_lc
@@ -85,7 +85,7 @@

Format

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/index.html b/docs/reference/index.html index d92f37f..b4f51a4 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -97,9 +97,9 @@

All functions

Download MODIS Land Products subsets

-

mt_to_raster()

+

mt_to_terra()

-

Convert tidy MODISTools data to raster (stack)

+

Convert tidy MODISTools data to terra SpatRaster

sin_to_ll()

@@ -117,7 +117,7 @@

All functions
-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_bands.html b/docs/reference/mt_bands.html index 346d85f..4a33bd8 100644 --- a/docs/reference/mt_bands.html +++ b/docs/reference/mt_bands.html @@ -63,17 +63,20 @@

Download all available bands

-
mt_bands(product)
+
mt_bands(product)

Arguments

product

a valid MODIS product name

+

Value

-

A data frame of all available bands for a MODIS Land + + +

A data frame of all available bands for a MODIS Land Products Subsets products

@@ -84,11 +87,11 @@

See also

Examples

-

-# \donttest{
-# list all available MODIS Land Products Subsets products
-bands <- mt_bands(product = "MCD12Q2")
-head(bands)
+    

+# \donttest{
+# list all available MODIS Land Products Subsets products
+bands <- mt_bands(product = "MCD12Q2")
+head(bands)
 #>                         band    description               units    valid_range
 #> 1      Dormancy.Num_Modes_01 Onset_Dormancy days since 1-1-1970 11138 to 32766
 #> 2      Dormancy.Num_Modes_02 Onset_Dormancy days since 1-1-1970 11138 to 32766
@@ -103,9 +106,9 @@ 

Examples

#> 4 32767 0.0001 #> 5 32767 0.1 #> 6 32767 0.1 - -# } - + +# } +
@@ -120,7 +123,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_batch_subset.html b/docs/reference/mt_batch_subset.html index c88df84..0066a36 100644 --- a/docs/reference/mt_batch_subset.html +++ b/docs/reference/mt_batch_subset.html @@ -65,17 +65,17 @@

Batch download MODIS Land Products subsets

-
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
+)
@@ -85,27 +85,46 @@

Arguments

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 TRUE or FALSE (default = TRUE)

+

Value

-

A data frame combining meta-data and actual data values, data from + + +

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.

@@ -119,44 +138,68 @@

See also

Examples

-

-if (FALSE) {
-# 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)
-}
+    

+# \donttest{
+# 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)
+#>   site_name lat  lon
+#> 1    test 1  40 -110
+#> 2    test 2  40 -110
+
+# 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)
+#>       xllcorner  yllcorner         cellsize nrows ncols        band  units
+#> 1.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
+#> 2.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
+#> 3.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
+#> 4.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
+#> 5.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
+#> 6.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
+#>     scale latitude longitude   site product      start        end complete
+#> 1.1  0.02       40      -110 test 1 MOD11A2 2004-01-01 2004-03-31     TRUE
+#> 2.1  0.02       40      -110 test 1 MOD11A2 2004-01-01 2004-03-31     TRUE
+#> 3.1  0.02       40      -110 test 1 MOD11A2 2004-01-01 2004-03-31     TRUE
+#> 4.1  0.02       40      -110 test 1 MOD11A2 2004-01-01 2004-03-31     TRUE
+#> 5.1  0.02       40      -110 test 1 MOD11A2 2004-01-01 2004-03-31     TRUE
+#> 6.1  0.02       40      -110 test 1 MOD11A2 2004-01-01 2004-03-31     TRUE
+#>     modis_date calendar_date   tile     proc_date pixel value
+#> 1.1   A2004001    2004-01-01 h09v05 2020168005635     1 13129
+#> 2.1   A2004009    2004-01-09 h09v05 2020168010833     1 13102
+#> 3.1   A2004017    2004-01-17 h09v05 2020168012220     1 13343
+#> 4.1   A2004025    2004-01-25 h09v05 2020168013617     1 13364
+#> 5.1   A2004033    2004-02-02 h09v05 2020168015053     1 13364
+#> 6.1   A2004041    2004-02-10 h09v05 2020168022045     1 13272
+# }
 
@@ -171,7 +214,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_bbox.html b/docs/reference/mt_bbox.html index e87ab4c..a4e7d60 100644 --- a/docs/reference/mt_bbox.html +++ b/docs/reference/mt_bbox.html @@ -63,7 +63,7 @@

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)
@@ -71,18 +71,29 @@

Arguments

xllcorner

lower left x coordinate as provided by mt_subset

+ +
yllcorner

lower left y coordinate as provided by mt_subset

+ +
cellsize

cell size provided by mt_subset

+ +
nrows

cell size provided by mt_subset

+ +
ncols

cell size provided by mt_subset

+ +
transform

transform the bounding box from sin to lat long coordinates, TRUE or FALSE (default = TRUE)

+

See also

@@ -92,83 +103,38 @@

See also

Examples

-

-# \donttest{
-# 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)
-#> Warning: GDAL Message 1: +init=epsg:XXXX syntax is deprecated. It might return a CRS with a non-EPSG compliant axis order.
-
-# 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)
-#> $`1.1`
-#> Geometry set for 1 feature 
-#> Geometry type: POLYGON
-#> Dimension:     XY
-#> Bounding box:  xmin: -110.0023 ymin: 39.99167 xmax: -109.978 ymax: 40
-#> Geodetic CRS:  WGS 84
-#> POLYGON ((-109.9889 39.99167, -110.0023 40, -10...
-#> 
-#> $`2.1`
-#> Geometry set for 1 feature 
-#> Geometry type: POLYGON
-#> Dimension:     XY
-#> Bounding box:  xmin: -110.0023 ymin: 39.99167 xmax: -109.978 ymax: 40
-#> Geodetic CRS:  WGS 84
-#> POLYGON ((-109.9889 39.99167, -110.0023 40, -10...
-#> 
-#> $`3.1`
-#> Geometry set for 1 feature 
-#> Geometry type: POLYGON
-#> Dimension:     XY
-#> Bounding box:  xmin: -110.0023 ymin: 39.99167 xmax: -109.978 ymax: 40
-#> Geodetic CRS:  WGS 84
-#> POLYGON ((-109.9889 39.99167, -110.0023 40, -10...
-#> 
-#> $`4.1`
-#> Geometry set for 1 feature 
-#> Geometry type: POLYGON
-#> Dimension:     XY
-#> Bounding box:  xmin: -110.0023 ymin: 39.99167 xmax: -109.978 ymax: 40
-#> Geodetic CRS:  WGS 84
-#> POLYGON ((-109.9889 39.99167, -110.0023 40, -10...
-#> 
-#> $`5.1`
-#> Geometry set for 1 feature 
-#> Geometry type: POLYGON
-#> Dimension:     XY
-#> Bounding box:  xmin: -110.0023 ymin: 39.99167 xmax: -109.978 ymax: 40
-#> Geodetic CRS:  WGS 84
-#> POLYGON ((-109.9889 39.99167, -110.0023 40, -10...
-#> 
-#> $`6.1`
-#> Geometry set for 1 feature 
-#> Geometry type: POLYGON
-#> Dimension:     XY
-#> Bounding box:  xmin: -110.0023 ymin: 39.99167 xmax: -109.978 ymax: 40
-#> Geodetic CRS:  WGS 84
-#> POLYGON ((-109.9889 39.99167, -110.0023 40, -10...
-#> 
-# }
+    

+# \donttest{
+# 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)
+#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("character"), new("standardGeneric", .Data = function (x,     ...) standardGeneric("crs"), generic = structure("crs", package = "terra"),     package = "terra", group = list(), valueClass = character(0),     signature = "x", default = NULL, skeleton = (function (x,         ...)     stop(gettextf("invalid call in method dispatch to '%s' (no default method)",         "crs"), domain = NA))(x, ...)), <environment>): unable to find an inherited method for function ‘crs’ for signature ‘"character"’
+
+# bind with the original dataframe
+subset <- cbind(subset, lat_lon)
+#> Error in data.frame(..., check.names = FALSE): object 'lat_lon' not found
+
+# 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'])
+})
+#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("character"), new("standardGeneric", .Data = function (x,     ...) standardGeneric("crs"), generic = structure("crs", package = "terra"),     package = "terra", group = list(), valueClass = character(0),     signature = "x", default = NULL, skeleton = (function (x,         ...)     stop(gettextf("invalid call in method dispatch to '%s' (no default method)",         "crs"), domain = NA))(x, ...)), <environment>): unable to find an inherited method for function ‘crs’ for signature ‘"character"’
+
+head(bb)
+#> Error in head(bb): object 'bb' not found
+# }
 
@@ -183,7 +149,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_dates.html b/docs/reference/mt_dates.html index 2e9596d..8977ba7 100644 --- a/docs/reference/mt_dates.html +++ b/docs/reference/mt_dates.html @@ -65,26 +65,37 @@

Download all available dates

-
mt_dates(product, lat, lon, site_id, network)
+
mt_dates(product, lat, lon, site_id, network)

Arguments

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

+

Value

-

A data frame of all available dates for a MODIS Land + + +

A data frame of all available dates for a MODIS Land Products Subsets products at the given location.

@@ -95,11 +106,11 @@

See also

Examples

-

-# \donttest{
-# list all available MODIS Land Products Subsets products
-bands <- mt_dates(product = "MOD11A2", lat = 40, lon = -110)
-head(bands)
+    

+# \donttest{
+# list all available MODIS Land Products Subsets products
+bands <- mt_dates(product = "MOD11A2", lat = 40, lon = -110)
+head(bands)
 #>   modis_date calendar_date
 #> 1   A2000049    2000-02-18
 #> 2   A2000057    2000-02-26
@@ -107,7 +118,7 @@ 

Examples

#> 4 A2000073 2000-03-13 #> 5 A2000081 2000-03-21 #> 6 A2000089 2000-03-29 -# } +# }
@@ -122,7 +133,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_products.html b/docs/reference/mt_products.html index 3e43ab3..9b1c654 100644 --- a/docs/reference/mt_products.html +++ b/docs/reference/mt_products.html @@ -63,12 +63,14 @@

Download all available products

-
mt_products()
+
mt_products()

Value

-

A data frame of all available MODIS Land Products Subsets products

+ + +

A data frame of all available MODIS Land Products Subsets products

See also

@@ -78,34 +80,34 @@

See also

Examples

-

-# \donttest{
-# list all available MODIS Land Products Subsets products
-products <- mt_products()
-head(products)
+    

+# \donttest{
+# list all available MODIS Land Products Subsets products
+products <- mt_products()
+head(products)
 #>        product
 #> 1       Daymet
 #> 2 ECO4ESIPTJPL
 #> 3      ECO4WUE
 #> 4       GEDI03
-#> 5      MCD12Q1
-#> 6      MCD12Q2
-#>                                                                       description
-#> 1 Daily Surface Weather Data (Daymet) on a 1-km Grid for North America, Version 4
-#> 2            ECOSTRESS Evaporative Stress Index PT-JPL (ESI) Daily L4 Global 70 m
-#> 3                       ECOSTRESS Water Use Efficiency (WUE) Daily L4 Global 70 m
-#> 4             GEDI Gridded Land Surface Metrics (LSM) L3 1km EASE-Grid, Version 2
-#> 5           MODIS/Terra+Aqua Land Cover Type (LC) Yearly L3 Global 500 m SIN Grid
-#> 6      MODIS/Terra+Aqua Land Cover Dynamics (LCD) Yearly L3 Global 500 m SIN Grid
+#> 5     GEDI04_B
+#> 6      MCD12Q1
+#>                                                                          description
+#> 1 Daily Surface Weather Data (Daymet) on a 1-km Grid for North America, Version 4 R1
+#> 2               ECOSTRESS Evaporative Stress Index PT-JPL (ESI) Daily L4 Global 70 m
+#> 3                          ECOSTRESS Water Use Efficiency (WUE) Daily L4 Global 70 m
+#> 4                GEDI Gridded Land Surface Metrics (LSM) L3 1km EASE-Grid, Version 2
+#> 5       GEDI Gridded Aboveground Biomass Density (AGBD) L4B 1km EASE-Grid, Version 2
+#> 6              MODIS/Terra+Aqua Land Cover Type (LC) Yearly L3 Global 500 m SIN Grid
 #>   frequency resolution_meters
 #> 1     1 day              1000
 #> 2    Varies                70
 #> 3    Varies                70
 #> 4  One time              1000
-#> 5    1 year               500
+#> 5  One time              1000
 #> 6    1 year               500
-# }
-
+# }
+
 
@@ -120,7 +122,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_sites.html b/docs/reference/mt_sites.html index 49363c5..f26825c 100644 --- a/docs/reference/mt_sites.html +++ b/docs/reference/mt_sites.html @@ -63,7 +63,7 @@

Download all available fixed sites

-
mt_sites(network)
+
mt_sites(network)
@@ -71,10 +71,13 @@

Arguments

network

the network for which to generate the site list, when not provided the complete list is provided

+

Value

-

A data frame of all available MODIS Land Products Subsets + + +

A data frame of all available MODIS Land Products Subsets pre-processed sites

@@ -85,11 +88,11 @@

See also

Examples

-

-# \donttest{
-# list all available MODIS Land Products Subsets products
-sites <- mt_sites()
-print(head(sites))
+    

+# \donttest{
+# list all available MODIS Land Products Subsets products
+sites <- mt_sites()
+print(head(sites))
 #>                   siteid                sitename network latitude longitude
 #> 1  ae_abudhabi_abu_dhabi            AE Abu Dhabi AERONET 24.47611  54.32889
 #> 2     ae_abudhabi_al_ain     AE Abu Dhabi Al Ain AERONET 24.24217  55.70517
@@ -104,8 +107,8 @@ 

Examples

#> 4 AbuDhabi United Arab Emirates #> 5 AbuDhabi United Arab Emirates #> 6 AbuDhabi United Arab Emirates -# } - +# } +
@@ -120,7 +123,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_subset.html b/docs/reference/mt_subset.html index 4eaa73b..d2b2406 100644 --- a/docs/reference/mt_subset.html +++ b/docs/reference/mt_subset.html @@ -69,62 +69,91 @@

Download MODIS Land Products subsets

-
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
+)

Arguments

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 TRUE or FALSE (default = TRUE)

+ +
progress

show download progress

+

Value

-

A data frame combining meta-data and actual data values.

+ + +

A data frame combining meta-data and actual data values.

See also

@@ -136,18 +165,18 @@

See also

Examples

-

-# \donttest{
-# 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)
+    

+# \donttest{
+# 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)
 #>       xllcorner  yllcorner         cellsize nrows ncols        band  units
 #> 1.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
 #> 2.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
@@ -163,13 +192,13 @@ 

Examples

#> 5.1 0.02 40 -110 sitename MOD11A2 2004-01-01 2004-03-31 TRUE #> 6.1 0.02 40 -110 sitename MOD11A2 2004-01-01 2004-03-31 TRUE #> modis_date calendar_date tile proc_date pixel value -#> 1.1 A2004001 2004-01-01 h09v05 2015212185706 1 13098 -#> 2.1 A2004009 2004-01-09 h09v05 2015212201022 1 13062 -#> 3.1 A2004017 2004-01-17 h09v05 2015212213103 1 13297 -#> 4.1 A2004025 2004-01-25 h09v05 2015213005429 1 13323 -#> 5.1 A2004033 2004-02-02 h09v05 2015213090158 1 13315 -#> 6.1 A2004041 2004-02-10 h09v05 2015213165253 1 13227 -# } +#> 1.1 A2004001 2004-01-01 h09v05 2020168005635 1 13129 +#> 2.1 A2004009 2004-01-09 h09v05 2020168010833 1 13102 +#> 3.1 A2004017 2004-01-17 h09v05 2020168012220 1 13343 +#> 4.1 A2004025 2004-01-25 h09v05 2020168013617 1 13364 +#> 5.1 A2004033 2004-02-02 h09v05 2020168015053 1 13364 +#> 6.1 A2004041 2004-02-10 h09v05 2020168022045 1 13272 +# }
@@ -184,7 +213,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/mt_to_terra.html b/docs/reference/mt_to_terra.html new file mode 100644 index 0000000..4e0c5c9 --- /dev/null +++ b/docs/reference/mt_to_terra.html @@ -0,0 +1,164 @@ + +Convert tidy MODISTools data to terra SpatRaster — mt_to_terra • MODISTools + + +
+
+ + + +
+
+ + +
+

Convert tidy MODISTools data to a terra SpatRaster for easy +spatial processing and plotting.

+
+ +
+
mt_to_terra(df, reproject = FALSE)
+
+ +
+

Arguments

+
df
+

a valid MODISTools data frame with a single band (filter for a +particular band using the dplyr filter() function or base subset()

+ + +
reproject
+

reproject output to lat / long (default = FALSE)

+ +
+
+

Value

+ + +

A terra SpatRaster populated with the tidy dataframe values

+
+
+

See also

+ +
+ +
+

Examples

+

+# \donttest{
+# 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)
+#>     xllcorner  yllcorner      cellsize nrows ncols     band units         scale
+#> 1.1 190884.84 5378134.05 463.312716528     9     9 LC_Type1 class Not Available
+#> 1.2 190884.84 5378134.05 463.312716528     9     9 LC_Type1 class Not Available
+#> 1.3 190884.84 5378134.05 463.312716528     9     9 LC_Type1 class Not Available
+#> 1.4 190884.84 5378134.05 463.312716528     9     9 LC_Type1 class Not Available
+#> 1.5 190884.84 5378134.05 463.312716528     9     9 LC_Type1 class Not Available
+#> 1.6 190884.84 5378134.05 463.312716528     9     9 LC_Type1 class Not Available
+#>     latitude longitude     site product      start        end complete
+#> 1.1 48.38366   2.61025 testsite MCD12Q1 2005-01-01 2005-12-30     TRUE
+#> 1.2 48.38366   2.61025 testsite MCD12Q1 2005-01-01 2005-12-30     TRUE
+#> 1.3 48.38366   2.61025 testsite MCD12Q1 2005-01-01 2005-12-30     TRUE
+#> 1.4 48.38366   2.61025 testsite MCD12Q1 2005-01-01 2005-12-30     TRUE
+#> 1.5 48.38366   2.61025 testsite MCD12Q1 2005-01-01 2005-12-30     TRUE
+#> 1.6 48.38366   2.61025 testsite MCD12Q1 2005-01-01 2005-12-30     TRUE
+#>     modis_date calendar_date   tile     proc_date pixel value
+#> 1.1   A2005001    2005-01-01 h18v04 2022153213513     1     5
+#> 1.2   A2005001    2005-01-01 h18v04 2022153213513     2     5
+#> 1.3   A2005001    2005-01-01 h18v04 2022153213513     3     5
+#> 1.4   A2005001    2005-01-01 h18v04 2022153213513     4     5
+#> 1.5   A2005001    2005-01-01 h18v04 2022153213513     5     5
+#> 1.6   A2005001    2005-01-01 h18v04 2022153213513     6     5
+
+# convert to raster
+LC_r <- mt_to_terra(df = LC)
+#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("character"), new("standardGeneric", .Data = function (x,     ...) standardGeneric("crs"), generic = structure("crs", package = "terra"),     package = "terra", group = list(), valueClass = character(0),     signature = "x", default = NULL, skeleton = (function (x,         ...)     stop(gettextf("invalid call in method dispatch to '%s' (no default method)",         "crs"), domain = NA))(x, ...)), <environment>): unable to find an inherited method for function ‘crs’ for signature ‘"character"’
+# }
+
+
+
+ +
+ + +
+ +
+

Site built with pkgdown 2.0.6.

+
+ +
+ + + + + + + + diff --git a/docs/reference/sin_to_ll.html b/docs/reference/sin_to_ll.html index 286e239..f01d40c 100644 --- a/docs/reference/sin_to_ll.html +++ b/docs/reference/sin_to_ll.html @@ -71,15 +71,18 @@

Convert sinusoidal coordinates to lat / lon

-
sin_to_ll(x, y)
+
sin_to_ll(x, y)

Arguments

x

sinusoidal x coordinate (vector)

+ +
y

sinusoidal y coordinate (vector)

+

See also

@@ -88,23 +91,25 @@

See also

Examples

-

-# \donttest{
-# 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)
+    

+# \donttest{
+# 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)
+#> Error in (function (classes, fdef, mtable) {    methods <- .findInheritedMethods(classes, fdef, mtable)    if (length(methods) == 1L)         return(methods[[1L]])    else if (length(methods) == 0L) {        cnames <- paste0("\"", vapply(classes, as.character,             ""), "\"", collapse = ", ")        stop(gettextf("unable to find an inherited method for function %s for signature %s",             sQuote(fdef@generic), sQuote(cnames)), domain = NA)    }    else stop("Internal error in finding inherited methods; didn't return a unique method",         domain = NA)})(list("character"), new("standardGeneric", .Data = function (x,     ...) standardGeneric("crs"), generic = structure("crs", package = "terra"),     package = "terra", group = list(), valueClass = character(0),     signature = "x", default = NULL, skeleton = (function (x,         ...)     stop(gettextf("invalid call in method dispatch to '%s' (no default method)",         "crs"), domain = NA))(x, ...)), <environment>): unable to find an inherited method for function ‘crs’ for signature ‘"character"’
+
+# bind with the original dataframe
+subset <- cbind(subset, lat_lon)
+#> Error in data.frame(..., check.names = FALSE): object 'lat_lon' not found
+head(subset)
 #>       xllcorner  yllcorner         cellsize nrows ncols        band  units
 #> 1.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
 #> 2.1 -9370036.35 4446875.49 926.625433055834     1     1 LST_Day_1km Kelvin
@@ -119,21 +124,14 @@ 

Examples

#> 4.1 0.02 40 -110 sitename MOD11A2 2004-01-01 2004-03-31 TRUE #> 5.1 0.02 40 -110 sitename MOD11A2 2004-01-01 2004-03-31 TRUE #> 6.1 0.02 40 -110 sitename MOD11A2 2004-01-01 2004-03-31 TRUE -#> modis_date calendar_date tile proc_date pixel value longitude_ll -#> 1.1 A2004001 2004-01-01 h09v05 2015212185706 1 13098 -109.9889 -#> 2.1 A2004009 2004-01-09 h09v05 2015212201022 1 13062 -109.9889 -#> 3.1 A2004017 2004-01-17 h09v05 2015212213103 1 13297 -109.9889 -#> 4.1 A2004025 2004-01-25 h09v05 2015213005429 1 13323 -109.9889 -#> 5.1 A2004033 2004-02-02 h09v05 2015213090158 1 13315 -109.9889 -#> 6.1 A2004041 2004-02-10 h09v05 2015213165253 1 13227 -109.9889 -#> latitude_ll -#> 1.1 39.99167 -#> 2.1 39.99167 -#> 3.1 39.99167 -#> 4.1 39.99167 -#> 5.1 39.99167 -#> 6.1 39.99167 -# } +#> modis_date calendar_date tile proc_date pixel value +#> 1.1 A2004001 2004-01-01 h09v05 2020168005635 1 13129 +#> 2.1 A2004009 2004-01-09 h09v05 2020168010833 1 13102 +#> 3.1 A2004017 2004-01-17 h09v05 2020168012220 1 13343 +#> 4.1 A2004025 2004-01-25 h09v05 2020168013617 1 13364 +#> 5.1 A2004033 2004-02-02 h09v05 2020168015053 1 13364 +#> 6.1 A2004041 2004-02-10 h09v05 2020168022045 1 13272 +# }
@@ -148,7 +146,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index b2dddfb..dfd4a39 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -63,6 +63,9 @@ /reference/mt_to_raster.html + + /reference/mt_to_terra.html + /reference/mt_write.html diff --git a/man/mt_to_raster.Rd b/man/mt_to_raster.Rd deleted file mode 100644 index edaf45c..0000000 --- a/man/mt_to_raster.Rd +++ /dev/null @@ -1,48 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/mt_to_raster.R -\name{mt_to_raster} -\alias{mt_to_raster} -\title{Convert tidy MODISTools data to raster (stack)} -\usage{ -mt_to_raster(df, reproject = FALSE) -} -\arguments{ -\item{df}{a valid MODISTools data frame with a single band (filter for a -particular band using the dplyr \code{filter()} function or base \code{subset()}} - -\item{reproject}{reproject output to lat / long (default = \code{FALSE})} -} -\value{ -A raster stack populated with the tidy dataframe values -} -\description{ -Convert tidy MODISTools data to a raster (stack) -} -\examples{ - -\donttest{ -# 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_raster(df = LC) -} - -} -\seealso{ -\code{\link[MODISTools]{mt_subset}} -\code{\link[MODISTools]{mt_batch_subset}} -} diff --git a/man/mt_to_terra.Rd b/man/mt_to_terra.Rd index 56eea9d..53660c3 100644 --- a/man/mt_to_terra.Rd +++ b/man/mt_to_terra.Rd @@ -16,7 +16,8 @@ particular band using the dplyr \code{filter()} function or base \code{subset()} A terra SpatRaster populated with the tidy dataframe values } \description{ -Convert tidy MODISTools data to a terra SpatRaster +Convert tidy MODISTools data to a terra SpatRaster for easy +spatial processing and plotting. } \examples{ diff --git a/tests/testthat/test_coordinate_conversions.R b/tests/testthat/test_coordinate_conversions.R index f39d581..41900d7 100644 --- a/tests/testthat/test_coordinate_conversions.R +++ b/tests/testthat/test_coordinate_conversions.R @@ -47,44 +47,6 @@ test_that("test coordinate transforms",{ ) }) -# test raster conversions -test_that("test raster conversion",{ - skip_on_cran() - subset <- mt_subset( - product = "MOD11A2", - lat = 40, - lon = -110, - band = "LST_Day_1km", - start = "2004-01-01", - end = "2004-03-31", - progress = FALSE - ) - - multi_band <- mt_subset(product = "MCD12Q1", - lat = 48.383662, - lon = 2.610250, - band = c("LC_Type1","LC_Type2"), - start = "2005-01-01", - end = "2005-06-30", - km_lr = 2, - km_ab = 2, - site_name = "testsite", - internal = TRUE, - progress = FALSE) - - # good conversion into stack - expect_silent(mt_to_raster(subset)) - - # multi-band error - expect_error(mt_to_raster(multi_band)) - - # not a data frame - expect_error(mt_to_raster(df = "not a dataframe")) - - # missing input - expect_error(mt_to_raster()) -}) - # test raster conversions test_that("test terra conversion",{ skip_on_cran() @@ -111,15 +73,15 @@ test_that("test terra conversion",{ progress = FALSE) # good conversion into stack - expect_silent(mt_to_raster(subset)) + expect_silent(mt_to_terra(subset)) # multi-band error - expect_error(mt_to_raster(multi_band)) + expect_error(mt_to_terra(multi_band)) # not a data frame - expect_error(mt_to_raster(df = "not a dataframe")) + expect_error(mt_to_terra(df = "not a dataframe")) # missing input - expect_error(mt_to_raster()) + expect_error(mt_to_terra()) }) From 5035efc83e383b6195087c96544bad9a0190f5cc Mon Sep 17 00:00:00 2001 From: Koen Hufkens Date: Sun, 18 Dec 2022 15:18:24 +0100 Subject: [PATCH 3/6] knitr settings --- DESCRIPTION | 2 +- vignettes/modistools-vignette.Rmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d757d49..a749ba0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ ByteCompile: true RoxygenNote: 7.2.1 Suggests: knitr, - rmarkdown, + markdown, covr, testthat, ggplot2, diff --git a/vignettes/modistools-vignette.Rmd b/vignettes/modistools-vignette.Rmd index ef47213..8d79847 100644 --- a/vignettes/modistools-vignette.Rmd +++ b/vignettes/modistools-vignette.Rmd @@ -5,7 +5,7 @@ date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{MODISTools} - %\VignetteEngine{knitr::rmarkdown} + %\VignetteEngine{knitr::knitr} %\VignetteEncoding{UTF-8} --- From eebea040a096665e673eae35b630dd4a5f21a0cb Mon Sep 17 00:00:00 2001 From: Koen Hufkens Date: Sun, 18 Dec 2022 15:30:47 +0100 Subject: [PATCH 4/6] removing last raster reference --- vignettes/modistools-vignette.Rmd | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vignettes/modistools-vignette.Rmd b/vignettes/modistools-vignette.Rmd index 8d79847..f1bc741 100644 --- a/vignettes/modistools-vignette.Rmd +++ b/vignettes/modistools-vignette.Rmd @@ -18,7 +18,7 @@ knitr::opts_chunk$set( # load the library library(MODISTools) -library(raster) +library(terra) library(rgdal) library(ggplot2) library(dplyr) @@ -76,9 +76,11 @@ arcachon_lai <- mt_subset(product = "MOD15A2H", km_ab = 20, site_name = "arcachon", internal = TRUE, - progress = FALSE) + progress = FALSE + ) -arcachon_lc <- mt_subset(product = "MCD12Q1", +arcachon_lc <- mt_subset( + product = "MCD12Q1", lat = 44.656286, lon = -1.174748, band = "LC_Type1", @@ -88,7 +90,8 @@ arcachon_lc <- mt_subset(product = "MCD12Q1", km_ab = 20, site_name = "arcachon", internal = TRUE, - progress = FALSE) + progress = FALSE + ) ``` The output format is a *tidy* data frame, as shown above. When witten to a csv with the parameter `internal = FALSE` this will result in a flat file on disk. @@ -210,7 +213,7 @@ Below a small region (20x20km) is downloaded around the seaside town of Arcachon # convert to raster, when reproject is TRUE # the data is reprojected to lat / lon if FALSE # the data is shown in its original sinuidal projection -LC_r <- mt_to_raster(df = arcachon_lc, reproject = TRUE) +LC_r <- mt_to_terra(df = arcachon_lc, reproject = TRUE) # plot the raster data as a map plot(LC_r) From e334fcd8953932c8c0b3826d80fc03652cb70232 Mon Sep 17 00:00:00 2001 From: Koen Hufkens Date: Sun, 18 Dec 2022 15:33:31 +0100 Subject: [PATCH 5/6] removing rgdal --- vignettes/modistools-vignette.Rmd | 1 - 1 file changed, 1 deletion(-) diff --git a/vignettes/modistools-vignette.Rmd b/vignettes/modistools-vignette.Rmd index f1bc741..a4eb859 100644 --- a/vignettes/modistools-vignette.Rmd +++ b/vignettes/modistools-vignette.Rmd @@ -19,7 +19,6 @@ knitr::opts_chunk$set( # load the library library(MODISTools) library(terra) -library(rgdal) library(ggplot2) library(dplyr) library(sf) From 2ab6726708357e255c566bdb0a536e807dcc7398 Mon Sep 17 00:00:00 2001 From: Koen Hufkens Date: Sun, 18 Dec 2022 15:41:35 +0100 Subject: [PATCH 6/6] sp dependency --- NAMESPACE | 1 + R/mt_to_terra.R | 1 + man/mt_batch_subset.Rd | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index b826e53..09db7f3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,5 +9,6 @@ export(mt_sites) export(mt_subset) export(mt_to_terra) export(sin_to_ll) +import(sp) importFrom(memoise,memoise) importFrom(terra,rast) diff --git a/R/mt_to_terra.R b/R/mt_to_terra.R index 8d55931..94d56f6 100644 --- a/R/mt_to_terra.R +++ b/R/mt_to_terra.R @@ -33,6 +33,7 @@ #' LC_r <- mt_to_terra(df = LC) #'} #' @importFrom terra rast +#' @import sp mt_to_terra <- function( df, diff --git a/man/mt_batch_subset.Rd b/man/mt_batch_subset.Rd index 59f6d3a..e163aad 100644 --- a/man/mt_batch_subset.Rd +++ b/man/mt_batch_subset.Rd @@ -50,7 +50,7 @@ at a particular location. } \examples{ -\donttest{ +\dontrun{ # 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))