MagicForrest / DGVMTools

R package for processing, analysing and visualising ouput from Dynamic Global Vegetation Models (DGVMs)
GNU General Public License v3.0
26 stars 22 forks source link

plotSpatial with non standard grid #81

Closed anthoni-p closed 1 year ago

anthoni-p commented 1 year ago

Hi Matthew,

Any idea, why a spatial plot looks so strange for an approx. 2.0x2.0 gridlist aa.run.path="~/test/" aa.src=defineSource("DAGT v0.32 AnnAlloc","DAGT v0.32 AnnAlloc",aa.run.path,format=GUESS) anpp.out.aa=getField(aa.src,"anpp",first.year = 1961,last.year = 1990) anpp.out.aa.area.mean=aggregateYears(anpp.out.aa,method="mean") plotSpatial(anpp.out.aa.area.mean,"Total")

image

image.plot on the data looks ok: image

If you need an example anpp.out.gz it can be downloaded here: https://nextcloud.imk-ifu.kit.edu/s/2oY2XTGGACFt7BA

all the best, Peter

MagicForrest commented 1 year ago

That is a weird one. Something definitely funny going on there, I have only seen patterns like that with uneven grid spacings.

A possible workaround could be to set tile=TRUE in the plotSpatial() call. Could you give that a go?

anthoni-p commented 1 year ago

yea with tile=TRUE, looks better: image

anthoni-p commented 1 year ago

Another tidbit with that non-standard grid: aa.src=defineSource("DAGT v0.32 AnnAlloc","DAGT v0.32 AnnAlloc",aa.run.path,format=GUESS) anpp.out.aa=getField(aa.src,"anpp",first.year = 1961,last.year = 1990) anpp.out.aa.ts2=aggregateSpatial(anpp.out.aa,method="mean")

method mean produces numbers:

Data: Year BNE BINE BNS TeNE TeBS IBS TeBE TrBE TrIBE TrBR C3G C4G Total 1: 1961 0.04967960 0.02249394 0.008204527 0.0004327674 0.03832282 0.01013339 0.02734250 0.09288736 0.03039585 0.03719240 0.04707842 0.01933360 0.3835158

method w.sum produces NA everywhere. I guess it isn't able to calculate a correct area.

anpp.out.aa.ts=aggregateSpatial(anpp.out.aa,method="w.sum") .... Year BNE BINE BNS TeNE TeBS IBS TeBE TrBE TrIBE TrBR C3G C4G Total 1: 1961 NA NA NA NA NA NA NA NA NA NA NA NA NA

but seems like only for some area data are NA calculated

test.area=addArea(anpp.out.aa, unit = "m^2") Data: Lon Lat Year BNE BINE BNS TeNE TeBS IBS TeBE TrBE TrIBE TrBR C3G C4G Total Area 1: -179.25 66.25 1961 0 0 0 0 0 0 0 0 0 0 0 0 0 11205066447 2: -179.25 66.25 1962 0 0 0 0 0 0 0 0 0 0 0 0 0 11205066447 .... 111329: 178.25 68.25 1989 0 0 0 0 0 0 0 0 0 0 0 0 0 NA 111330: 178.25 68.25 1990 0 0 0 0 0 0 0 0 0 0 0 0 0 NA

anthoni-p commented 1 year ago

Propable has to do with the not exactly 2.0x2.0 grid. I tried to make a gridlist that runs quicker (has just 3711 gridpoints), but around the 0,0 lines, something didn't work out as well: Lon: -5.25 -3.25 -1.25 0.25 2.25 4.25 Lat: -5.25 -3.25 -1.25 0.25 2.25 4.25 So there is a 1.5 spacing from -1.25 to 0.25.

MagicForrest commented 1 year ago

That explains it. DGVMTools (or better said the ggplot2 geom_xxx() functions on which it relies) doesn't like grid points that don't fall on the main grid. That was my initial thought, but I didn't pick it up when I eyeballed your file.

I assume that when you fix your grid this problem will go away, so I'll close the issue. Let me know if it doesn't. And I should maybe put mention of this somewhere in the docs...