3

I'm new to the package stars for R and am trying to do basic spatial operations with curvilinear data. I am using netCDF climate data. I am able to read the netcdf into r along with a shapefile I would like to use to specify the area in which I want to conduct analyses. I have tried to crop the file directly using st_crop() but receive the following error:

Warning message:
In st_crop.stars(test, wrst) : crop only crops regular grids

I then tried to warp the stars object using code like this:

warp <- test %>% st_set_crs(3338) %>% st_warp(st_as_stars(st_bbox(), dx = 2))

but I get this error:

Error in colrow_from_xy(pts, x, NA_outside = TRUE) : 
  colrow_from_xy not supported for curvilinear objects

Do I need to 'flatten' my curvilinear grid in order to conduct analyses in a given region? If so, how do I do that? Or, conversely, if I am able to conduct operations like st_crop() or the equivalent of raster operations calc() or stackApply() using a curvilinear grid, can someone point me in the right direction? Thanks so much.

NorthLattitude
  • 201
  • 1
  • 12
  • You most likely need to regrid the netcdf file to a latlon grid covering the required domain. An option in R is rcdo, which I was once developing: https://github.com/r4ecology/rcdo. – Robert Wilson Jun 09 '21 at 05:21
  • @RobertWilson thank you - I will look into this. However, your GitHub page says the package will not work on Windows platforms, which is what I use. Has that changed with the newer versions of CDO or your package? – NorthLattitude Jun 09 '21 at 18:11

1 Answers1

4

Well I figured it out and it was quite simple. I was able to subset the stars object using the shapefile with this simple code: test[wrst]. No warping or resampling necessary.

NorthLattitude
  • 201
  • 1
  • 12