Calculating weighted values of precipitation annually
Hi there,I am currently trying to calculate "weighted" spatial annual global values for precipitation using the object "RCP1pctCO2Mean", which is a raster brick. I need to do this for each of the 138 years (i.e. 138 layers) of global precipitation data that I have. The idea would be to somehow apply weights to each grid cell value for each year by using the cosine of its latitude (which means grid cells at the equator would have a weight of 1 (i.e. the cosine of 0 degrees is 1), and the poles would have a value of 1 (as the cosine of 90 is 1)). The idea would also then be to make a time series of these values, from Year 1 to Year 138, after all newly derived grid cell values are averaged for each year, creating 138 (weighted) averages)). The object "RCP1pctCO2Mean" looks like this:
class : RasterBrick
dimensions : 64, 128, 8192, 140 (nrow, ncol, ncell, nlayers)
resolution : 2.8125, 2.789327 (x, y)
extent : -181.4062, 178.5938, -89.25846, 89.25846 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : C:/Users/Travis/Documents/Other documents/All netCDF files/netcdffiles/MaxPrecIPSLIPSL-CM5B-LR1pctCO2.nc
names : X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, ...
z-value : 1, 140 (min, max)
varname : onedaymax
Here is what I have done so far:
newraster <- rasterToPoints(RCP1pctCO2Mean) #Not sure if this is necessary?
I then proceeded to do assign weights like this:
weight <- cos(newraster*(pi/180))
However, this yields strange but identical precipitation values (i.e. all values are 0.97 to 0.99, which is odd) across each grid cell for each layer. I am not sure what I am doing incorrectly (if there is anything incorrect) - could it be that the "pi/180" is not necessary? Also, once this is done, how to revert to a raster stack with the new values?
I also saw another function, called "getWeights", but I am not sure how relevant this is. I am not sure about its associated package, but I was thinking about using it like this
weight <- getWeights(newraster, f = (newraster) cos(newraster))
Would this approach apply the weights appropriately?
I would greatly appreciate any help with this!!!!Thanks,
[[alternative HTML version deleted]]