MagicForrest / DGVMTools

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

Restraining plotSpatialComparison to a few pixels #33

Closed antonycastro closed 3 years ago

antonycastro commented 5 years ago

Dear Mathew,

as you know, I am comparing field data points against LPJ-Guess simulations. Please find the case attached.

Since I started using NetCDF inputs, I manage to get no errors until using the compareLayers function. But depending on how I set the coordinates filtering, I can get two types of error when trying to plot it with:

print(plotSpatialComparison(vegC.briennen.comparison))

The type of error depends on the logical vector "specific_coords" which filters the pixels. If it is TRUE, I need to only compare 1 pixel and get the error:

Error in grid.Call.graphics(C_setviewport, vp, TRUE) : non-finite location and/or size for viewport

... If it is FALSE, then I produce a map with 3 pixels. But the pixel size is many degrees bigger than the 0.5° size I was expecting.

Also, I would prefer to keep the plotSpatialComparison outputs "x and y limits" fixed to the maximum coordinates of the Brienen points dataset or Katrin coordinates (depending on the logical vector "specific_coords"). So when the users use different periods, the stored plots and objects are easily comparable. Like it occurs automatically at the file: Reproduce_comparison_spatial_saatchi_function.R

How should I proceed?

Looking forward, best regards

Antony

case: https://www.dropbox.com/s/168f8prbb7stiu7/Magic_Forrest.zip?dl=0

MagicForrest commented 5 years ago

Hi Antony,

To answer your last point first: x and y limits in plotSpatialComparison(). You should be able to fix the x and y limits on a plotSpatialComparisons() plot by using the xlim and ylim arguments. Did you try this? That feature is not yet clearly documented for plotSpatialComparison() but basically the '...' argument allows passing of additional arguments from the function that you called to any function called by that function. In this case arguments given to plotSpatialComparison() are passed through to plotSpatial(). It is a handy feature of R, but I should indeed highlight it in the documentation.

You first point is trickier. I think I can implement something there, but it will take a bit of time (and won't happen in the next couple of weeks). In most uses cases up to now, plotSpatial() (and plotSpatialComparison()) has always been called on regular grids so the default pixel size (calculated by ggplot2) has always been totally sensible. However, for sparsely populated grids this doesn't always work out so well. Another user has recently mentioned a similar issue, so it seems like controlling the plotted gridcell size will be a useful feature. So I will get to it.

Finally, plotting only a single gridcell on a map might be even trickier to deal with. But is is definitely a case that can come up (even though a single data point could just as well be represented by a number), especially when one is making plots in loops etc. So I'll give it a go.

Thanks for providing scripts as always (it is very helpful). In this case I didn't run them because I think I understood your issues from your description (and I am a bit pushed for time at the moment). But if I misunderstood something then let me know and I will run your code.

antonycastro commented 5 years ago

Hi Matthew,

Thank you very much. Later on, I will share you my work in case you want to check the application case we have been preparing :)

I did not know about the "..." argument. It made it work.

Regarding the second point, I don´t know if it helps, but always when the pixels change the size I get the warning:

1: In f(...) : Raster pixels are placed at uneven horizontal intervals and will be shifted. Consider using geom_tile() instead.

All the best, Antony

MagicForrest commented 5 years ago

Hi Antony,

I'm glad the xlim and ylim worked out.

However I will re-open the issue to remind me to address the pixel size issue later ;-)

MagicForrest commented 3 years ago

Hi Antony. This is rather later, but in case you are interested I have added a "pixel.size" argument to plotSpatial(). This allows precise control of the plotted square size in the case of a disjointed or otherwise unevenly spaced collection of sites.

To try it out, check out the branch "Format-NetCDF-devel" (yeah, my branch names got a bit skew-whiff) or the next release (v0.10) when it comes.