Description Usage Arguments Value Examples
Find hot and cold patches in a numeric matrix or raster, and calculate patch statistics.
1 2 3 4 5 6 7 8 | get_patches(
img,
id = NULL,
style = "C",
img_proj = NULL,
img_extent = NULL,
return_vals = c("df", "patches", "pstats")
)
|
img |
A numeric temperature matrix (such as that returned from
|
id |
The image ID (optional). Useful when iterating over numerous images. |
style |
Style to use when calculating neighbourhood weights using
|
img_proj |
Spatial projection. Optional, but necessary for geographic data to plot correctly. |
img_extent |
Spatial extent. Optional, but necessary for geographic data to plot correctly. |
return_vals |
Which values to return? Any combination of the dataframe
( |
A list containing:
df |
A dataframe with one row for each pixel, and variables denoting:
the pixel value (val); the spatial location of the pixel (x and y);
its patch classification (G_bin) into a hot (1), cold (-1) or no patch (0)
according to the Z value (see |
patches |
A SpatialPolygonsDataFrame of hot and cold patches, named
according to |
pstats |
A dataframe with patch statistics for hot patches and cold
patches, respectively. See |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ## Not run:
# FLIR temperature matrix ----------------------------------------
# Find hot and cold patches
flir_results <-
get_patches(img = flir11835$flir_matrix,
id = flir11835$photo_no)
# Look at the results for individual pixels
head(flir_results$df)
# Look at the patch statistics for hot and cold patches
flir_results$pstats
# Plot the patches
sp::plot(flir_results$patches)
# Plot using ThermStats::plot_patches
plot_patches(df = flir_results$df,
patches = flir_results$patches,
print_plot = TRUE,
save_plot = FALSE)
# Plot using landscapemetrics package
flir_patch_rast <- raster::rasterFromXYZ(flir_results$df[,c("x", "y", "G_bin")])
if (requireNamespace("landscapemetrics", quietly = TRUE)){
show_landscape(flir_patch_rast)
show_patches(flir_patch_rast, class = "all", labels = FALSE)
show_cores(flir_patch_rast, class = c(1, -1), labels = FALSE)
}
# Worldclim2 temperature raster ----------------------------------
# Dataset 'sulawesi_temp' represents mean January temperature for
# the island of Sulawesi
# Define projection and extent
img_proj <- raster::projection(sulawesi_temp)
img_extent <- raster::extent(sulawesi_temp)
# Find hot and cold patches
worldclim_results <-
get_patches(img = sulawesi_temp,
id = "sulawesi",
img_proj = img_proj,
img_extent = img_extent)
# Look at the results for individual pixels
head(worldclim_results$df)
# Look at the patch statistics for hot and cold patches
worldclim_results$pstats
# Plot the patches
sp::plot(worldclim_results$patches)
# Plot using ThermStats::plot_patches
plot_patches(df = worldclim_results$df,
patches = worldclim_results$patches,
print_plot = TRUE,
save_plot = FALSE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.