GarrettLab / HabitatConnectivity

geohabnet R package
https://garrettlab.github.io/HabitatConnectivity/
GNU General Public License v3.0
7 stars 4 forks source link

Using data from CroplandCROS #87

Open AaronPlex opened 9 months ago

AaronPlex commented 9 months ago

Here is a code template to download data from CroplandCROS (high spatial resolution = 30 m times 30 m), to transform it into a spatRaster that can be used in geohabnet, and start assembling our vignette.

You can download a GeoTIFF file from CroplandCROS, and check their user guide if needed.

  1. First, choose your crop, area of interest (AOI), and year.
  2. Then, make sure to use Web Mercator (WGS 84) and DPI = 96 to export.
  3. Check that you get a compressed (zipped) folder with all information including (but not only) the tif file called "clipped".
  4. Read the clipped.tif file in R and check that a coordinate reference system (crs) comes with the file.
  5. Plot the spatRaster and check what are the values of each pixel. There is only one integer, but that value just represents 'presence' (e.g., 56) or absence' (NA).
  6. Transform crs to the one used and accepted by geohabnet.
  7. Generate a map of cropland density at a coarser resolution by summing all small pixels into larger pixels (i.e., aggregating pixels or reducing spatial resolution).
  8. Finally save the resulting spatRaster to be the input in geohabnet. Pending is how to convert it into a map of host density instead of host abundance as this is the same issue as the one using data from GBIF.

Here is the code I used that worked: library(terra) r<-rast("clipped.tif") plot(r) v<-72 r<-r/v plot(r)

r<-project(r, "+proj=longlat +datum=WGS84") f<-40 a<-aggregate(r, fact = f, fun="sum", na.rm = TRUE) / (f*f) plot(a)

writeRaster(a, "FloridaCitrus01.tif")

*The project() and aggregate() functions took about 15 minutes the first and 5 minutes the second as the dataset is at high resolution.

krishnakeshav commented 9 months ago

fyi, @GarrettLab , @manoj044 , @jrobledob , @Romaric20