Statistics for an asymmetric raster-cell neighborhood are required.
The application is modelling direct solar insolation over year-long time steps while accounting for local shading effects of vegetation for an ecosystem energy balance. Consider for instance that at certain times of year, the sun will be directly overhead. In this case, direct rays from the sun will trace a right-to-left (east-to-west) path. In the image below, the black box is the target cell and the grey boxes are the daily path of the sun.
However, during other times of the year, the Earth tilts. When this happens, the direct rays entering the black square will be filtered through vegetation in a direction that is dependent on if the black square is located in the northern or southern hemisphereseason and this will have an important shading effect that must be considered. In the grid below, the black squarethis shading effect induced by Earth's tilt is located in the southern hemisphere and therepresented as grey squares representwith the cells in whichblack square again the vegetation can have a shading effecttarget cell.
The focal() function from terra can be used to calculate statistics for matrices, and according to the documentation, rows and/or columns of 'NA' can be added to modulate what window is used to generate statistics from. I am not certain how to create such a window.
In addition, focal() results in a statistic for a center cell. What this means is that, in the second image above where seasonal shading effect occur, the black cell would (by focal) be shifted up one. This needs to be adjusted or accounted for.