Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from raster to terra #8

Open
ramarty opened this issue Mar 1, 2024 · 5 comments
Open

Migrate from raster to terra #8

ramarty opened this issue Mar 1, 2024 · 5 comments
Assignees

Comments

@ramarty
Copy link
Contributor

ramarty commented Mar 1, 2024

No description provided.

@ramarty ramarty self-assigned this Mar 1, 2024
@alexyshr
Copy link

If you will use terra::extract to update the function bm_extract. You can use points, points with radius (buffer), polygons, or polygons with radius (buffer) to extract the values. In addition, setting the parameters exact and weights to TRUE helps create a smoother time series (those parameters can be part of bm_extract).

   ...
   ...
   buffer <- 0.1

   #the geometry to extract time series (SF of points or polygons)
   the_geometry 

   #this variable is created from HDF5 files using terra::
   ntl_raster_terra
   ... 
   ...


  #check if the buffer is different from 0
  if (buffer != 0) {
    #before to use st_buffer we need set sf_use_s2 to FALSE
    temp <- sf_use_s2()
    sf_use_s2(FALSE)
    #make a buffer from initial geometry
    the_geometry <- sf::st_buffer(the_geometry, buffer)
    #return sf_use_s2 to the original value
    sf_use_s2(temp)
  } 


  #extract the values with terra
  values_df <- terra::extract(ntl_raster_terra,
    the_geometry, #this can be points or polygons
    fun = mean,
    exact = FALSE, #TRUE, exact fraction of cells
    weights = FALSE, #TRUE, approximate fraction of cells
    method = "simple",
    na.rm = TRUE,
    ID = FALSE
  )
  
#convert the values_df to long format
...
...

@alexyshr
Copy link

alexyshr commented Apr 8, 2024

Hi @ramarty

I have been working Black Marble data in HDF5 format with stars; it is faster than terra. I can share the code with you to evaluate if stars is a better option. Another option is that you implement functions using terra and I can contribute with the functions using stars, then after some use of the tools you can decide. Best

@ramarty
Copy link
Contributor Author

ramarty commented Apr 19, 2024

@alexyshr If you have some code to share that'd be great -- I think stars could be a good option for this, even with a set of parallel functions that use a stars approach

@alexyshr
Copy link

If already implemented different functions. I want to check the latest version you posted and I would love to contribute to the project. I can suggest (push-commit) small changes or new functionality and you can check and decide if leaving them as part of the package. Please let me know if we can work collaboratively. Thanks

@ramarty
Copy link
Contributor Author

ramarty commented Apr 21, 2024

@alexyshr This sounds great - and absolutely welcome contributions / would be great to work collaboratively here. The goal is to make the package as useful as possible to different workflows, so think your contributions would be particularly useful here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants