![]() ![]() ![]() Update: Added a small note about considering temporal resolution when using the approxNA function. The raster has 'NAD83 / Conus Albers (EPSG:5070)' whereas the vector has 'lon/lat WGS 84 (EPSG:4326)' You can project the SpatVector to make them match (avoid projecting raster data if at all possible). Full Disclaimer: I have not used this before and not sure how it work (or how fast it'll process). The SpatRaster and SpatVector should have the same Coordinate Reference System. Id do it with some ifelse replacement of the values in the raster: Start with a blank raster: > F raster(a) Then where a<0. library (raster) r <- raster (ncol10, nrow10) values (r) <- rnorm (100) x <- clamp (r, useValuesFALSE) y <- reclassify (r, cbind (-Inf, 0, NA), rightFALSE) Note the rightFALSE to not set cells that are zero to NA. 1 Does your code do what you want it to Are you asking if this works or if this is the best method It can be easier to tell if your code is working if you make your rasters smaller - much smaller - so you can tell by looking if the output raster is as expected. It uses a combination of a moving window to look at neighboring cells and a matrix of weights to interpolate missing data. With the raster package, the memory-safe way to do this is to use reclassify or clamp. If you don't have several layers, you could try to using the focal function, also from the raster package. It seems for me that this is a task for the raster calculator (set value of pixels <0 to 'nodata') or a reclassification (set value of pixels. I need to set all pixel with a value of 0 and smaler (<0) to 'nodata' (for later raster calculations and to reduce the filesize). You would only need to specify the RasterBrick or RasterStack object, as the default method is set to linear (the other option is constant), while the default options for all the other arguments seem to work pretty well, too. I have a DEM raster with pixel values between about 3000 and -0.0003. In using Rasterio, you’ll encounter two different kinds of masks. If you've got several soil layers of the same place with very fine temporal resolution (hours/days/weeks), it could work. Nodata masks allow you to identify regions of valid data values. This does imply that coarse temporal resolution between raster layers would lead to less accurate interpolations of missing data. ![]() Consider a copy of the test data opened in r+ (update) mode. hours, a few days, a week), such as Chlorophyll concentration or sea surface temperature (which is what I use and why it worked for me). Writing a mask that applies to all dataset bands is just as straightforward: pass an ndarray with True (or values that evaluate to True to indicate valid data and False to indicate no data to writemask (). The reason is that it will use the information in the other raster layers to interpolate what an NA might be, so it works well for raster data that changes across time, and if the time between raster layers is very short (i.e. The approxNA function from the raster package works if you have several Raster objects in a RasterBrick or RasterStack, rather than an individual raster. It's nearly a year old but thought I'd throw in another option. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |