Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable downsampling of basemap in facets? #895

Open
SebKrantz opened this issue Jun 28, 2024 · 4 comments
Open

Disable downsampling of basemap in facets? #895

SebKrantz opened this issue Jun 28, 2024 · 4 comments

Comments

@SebKrantz
Copy link

SebKrantz commented Jun 28, 2024

I'm using tm_basemap("Esri.WorldGrayCanvas", zoom = 4) as a basemap. The resolution on large geographies is ok-isch. When using tm_facet_wrap(), the resolution of the basemap decreases, and tmap displays a message "SpatRaster object downsampled to 204 by 224 cells.". I understand that this may be a good idea for memory reasons, but in many cases it really makes the basemap unintelligible. It would be great if the resolution of the map could be increased in general, and if it could be kept for facets. Thanks!

@mtennekes
Copy link
Member

The option raster.max.cells controls this. It is the upperbound for the total number of cells, so the total over all facets. If the number of cells is larger, then it is downsampled. This is intentionally to prevent system crashes and the reduce computation time significantly.

However, I agree that the maps should be as sharp as possible.

The current value is 1e6, which is definitely too small, also for a single map without facets. So 1e7 corresponds to roughly 3000 by 3000, and 1e8 10,000 by 10,000. What would be a good default value in your opinion, @SebKrantz (cc @Nowosad)?

You can play around with this value as follows:

tmap_options(raster.max.cells = 1e6)
tm_shape(World[169,]) +
	tm_borders(col = "red") +
	tm_basemap("Esri.WorldImagery", zoom = 4)

@Nowosad
Copy link
Member

Nowosad commented Jul 3, 2024

My general thinking is that raster.max.cells should relate to each panel separately (that would be my expectation as a user). Currently, when you have one panel, the map is fine; but when you have 10 panels, all of them do not look good -- their resolution is too low...

@SebKrantz
Copy link
Author

Sorry for the late response. I Agree with @Nowosad. For facet plots increasing it makes a big difference. For single plots, using tm_basemap("Esri.WorldGrayCanvas", zoom = 4) in my application, I actually don't find a huge difference. The text is still not very sharp even if I set tmap_options(raster.max.cells = 1e8).

@mtennekes
Copy link
Member

I see the argument, but I don't fully agree. Imho, there is a use-case balance between:

  • exploratory (as fast as possible, possible at the expense of quality)
  • HQ (best quality, at the expense of running time).

I see faceting as a powerful tool for exploration. However, if the running time for printing a basemap is say 3 seconds per map, the running time of say 10 facets is too much (let alone if there are many more facets), unless the aim is to produce print-ready HQ maps.

Therefore, setting raster.max.cells to each panel would ruin the possibility to explore spatial data via facets. On the other hand, I agree that it is easier to understand and probably more intuitive. However, ideally, the standard user should not have to bother about raster.max.cells. It should be set to a lowest resolution for which the perceived quality still (almost) as good as the original resolution. At least, for the standard user. For users who aim for HQ, it should not be downscaled at all.

The difficulty is that the sharpness not only depends on the (downsampled) resolution, but also on the screen and the source of the files. (E.g., is the text in your application still not sharp when setting tmap_options(raster.max.cells = Inf), @SebKrantz ? If not there may be an issue with the source files, or with the device).

Just an idea: we could add something like this:

tmap_prioritize("speed")      # downscaling to make sure the running time is below x seconds
tmap_prioritize("balance") # something in between
tmap_prioritize("quality") # no downscaling

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants