You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
library(sf)
myurl="http://geocorp.co/wind/MWP_2017242_090W040N_3D3OT.tif"the_40n_file="./MWP_2017242_090W040N_3D3OT.tif"
download.file(myurl, the_40n_file, mode="wb")
myurl="http://geocorp.co/wind/MWP_2017242_090W030N_3D3OT.tif"the_30n_file="./MWP_2017242_090W030N_3D3OT.tif"
download.file(myurl, the_30n_file, mode="wb")
myurl="http://geocorp.co/wind/counties_florida.zip"
download.file(myurl, "counties_florida.zip", mode="wb")
unzip("counties_florida.zip")
the_florida_file="./counties_florida.shp"#read the shapefilesf_florida<-sf::st_read(the_florida_file, quiet=TRUE)
#transform st_florida to 4326sf_florida<-sf::st_transform(sf_florida, 4326)
#read th files with starsst_30n<-stars::read_stars(the_30n_file, quiet=TRUE, proxy=FALSE)
st_40n<-stars::read_stars(the_40n_file, quiet=TRUE, proxy=FALSE)
#convert the files to terrar_30n<-terra::rast(the_30n_file)
r_40n<-terra::rast(the_40n_file)
#mosaic the files the files with stars
system.time({
st_mosaic<-stars::st_mosaic(st_30n, st_40n)
})
#> user system elapsed #> 2.46 0.68 3.73
#plot st_mosaic
plot(st_mosaic)
#> downsample set to 10
#mosaic the files the files with terra
system.time({
r_mosaic<-terra::mosaic(r_30n, r_40n)
})
#> user system elapsed #> 1.57 1.39 5.19
#crop the files with stars#it is taking 16.89 hours#system.time({# st_crop <- sf::st_crop(st_mosaic, sf_florida)#})#system.time({# st_crop <- st_mosaic[sf_florida, as_points = T]#})# user system elapsed #21499.75 39246.67 60792.59 ##crop the files with terra
system.time({
r_crop<-terra::crop(r_mosaic, sf_florida)
})
#> user system elapsed #> 0.11 0.05 0.16
In my initial code, I was comparing two different types of crops. So the time comparison was not valid. If we compare the crop to the bounding box, stars is 1.41 times faster.
Croping a
stars
object takes 16.89 hours whileterra
takes 0.16 seconds. I just installedsf
andstars
from GitHub.plot(r_crop)
Created on 2024-07-04 with reprex v2.1.0
Session info
The text was updated successfully, but these errors were encountered: