When attempting to use the addArea() function with some LPJ-Guess outputs, I get the following error:
Error in DGVMTools::addArea(agg, lon_centres = lons, lat_centres = lats) :
In addArea(), not all latitudes in the data are present in the supplied in the 'latitude_centres' argument.
My dataset here is a gridded lpj-guess output of LAI over Australia, and the coordinates I passed into the function were simply all unique coordinates in my gridlist. After some investigation, I think the problem comes down to the fact that my gridlist doesn't contain an evenly-spaced sequence of latitudes (note the missing -40.5° and -39.5° - these are ocean gridcells at all longitudes if your grid is a small box around Australia):
I think the problem is caused by the use of extract.seq() in addArea(). In this gridlist, less than half of the latitudes are unevenly spaced, so extract.seq() returns a full sequence. Is there a reason to do this? If I'm reading things correctly, it seems that returning a full sequence for an unevenly-spaced grid will always result in an error in addArea(). That said, I'm not certain what the function should output in my case - should it account for the presence of oceans, or simply assume that there are some large gridcells in that area?
I tried changing the addArea() function to use sort(unique()) instead of extract.seq(), which appears to work on some level (I no longer get the error), though I'm not sure if the output should be considered "correct" around the affected area (the bass strait in my case).
If it helps, here is a reproducible example which demonstrates the problem:
When attempting to use the
addArea()
function with some LPJ-Guess outputs, I get the following error:My dataset here is a gridded lpj-guess output of LAI over Australia, and the coordinates I passed into the function were simply all unique coordinates in my gridlist. After some investigation, I think the problem comes down to the fact that my gridlist doesn't contain an evenly-spaced sequence of latitudes (note the missing -40.5° and -39.5° - these are ocean gridcells at all longitudes if your grid is a small box around Australia):
I think the problem is caused by the use of
extract.seq()
inaddArea()
. In this gridlist, less than half of the latitudes are unevenly spaced, soextract.seq()
returns a full sequence. Is there a reason to do this? If I'm reading things correctly, it seems that returning a full sequence for an unevenly-spaced grid will always result in an error inaddArea()
. That said, I'm not certain what the function should output in my case - should it account for the presence of oceans, or simply assume that there are some large gridcells in that area?I tried changing the
addArea()
function to usesort(unique())
instead ofextract.seq()
, which appears to work on some level (I no longer get the error), though I'm not sure if the output should be considered "correct" around the affected area (the bass strait in my case).If it helps, here is a reproducible example which demonstrates the problem:
mlai.out.gz