Implement auto resolution for remote grids for plotting modules#5753
Implement auto resolution for remote grids for plotting modules#5753PaulWessel merged 22 commits intomasterfrom
Conversation
If not present and a plot then we can determine the "best" resolution for the user given a default dpi.
|
Once this is tested and approved we should update all examples where we make plots with remote files to make it simpler. |
|
Very nice feature!! I already have an script with a zoom effect. I tested it. It looks good. The grids from 15m to 02m were used. @PaulWessel with this script I got the message I got the warning message of the forum. Zoom_Relief.mp4 |
|
Thanks, I fixed the issue that made the lower altitudes take a very long time (specially 500 and up). Now I can do 500/8000 but when I get even closer and need 03s and eventually 01s I have an issue of not finding (?) or downloading tiles. So more testing. I think making anim16 doing a zoom from "outer space" all the way down to 1 s resolution would be nice so your script is a good start. |
|
I try to run the same script but with @earth_day and and it tries to download earth_day_30s_p (which doesn't exist, right?) Error message: |
|
The first frames with earth_day look blurry. Zoom_day2.mp4 |
|
This is a fantastic feature. Does this mean that, for plotting purposes, one is discouraged to set the resolution, and instead let gmt decide? Also, I would like to emphasize how great the remote grids and auto download that gmt offers is and has been for me; it substantially reduces the friction of making (good) maps. |
|
Once we are happy with how it works, I would say definitively. I doubt most GMT users could figure out a suitable resolution so they use too high a resolution to make sure it looks good. But yes, there may be times when you
|
|
It would be nice to have a way to query the auto-resolution determination without actually downloading anything. In additional to potential benefits for users, this would enable testing of the feature without slowing things down with more images-based tests and a larger cache. This sub-feature could be added as a new option or modifier for grdcut, since this is currently the recommend way for getting a grid from the remotes. |
|
As you know, we can use grdcut with -R -J now to extract a rectangular encompassing grid given an oblique area. Of course, until now we would do this with a known resolution. Seems the only thing I need to allow for is to let grdcut, if both -R -J are given, to allow the missing resolution. The rest will happen as it does for grdimage. As for an option or modifier to just report the region and resolution: That is a good idea which would also be helpful even for the old oblique -R -J case. Given available options, perhaps -D for dry-run is OK? (I dont like -I for inquiry (used in histogram) since -I should really be saved for grid increments if we can help it.) |
Sounds good |
|
So adding a -D works something like this: The first message will be a -Vi message once this is done. What do we want the second line to be? A -R string like coast -E sends to stdout? A notice like this to stderr? Since presumably both -R and -I are interesting here so we write -Rw/e/s/n -Iinc? Thoughts? If anyone is hoping to script things to recover the two settings then it is hard if it is a stderr message. Or, -D could take a filename where to write the info, either instead of the message or in addition to it. |
I think the default should be stdout. There could be a +ttxtfile modifier for instead writing to file and perhaps +i for increment only. Here's how I would imagine the output: |
SI, please. We should not need to set a dump output grid ( -D+n for externals (and others) like |
Yes, per PROJ_LENGTH_UNIT setting. This is just temporary (and because internal values are in inches).
No grid output via -D was considered. I mean did we want to write the information (text) to a file via D, or to stdout. Did you means something else?
That I like. We can emulate grdinfo -C on this without the baggage. |
Yes, my bad, I meant the -Gt.grd in your example. I take it to mean nothing an only please the parser for the mandatory -G, but this can be avoided. |
|
My thinking was that -D means -G is not allowed (or could be ignored). The only tricky thing is that the new stuff happens in gmt_init_module before parse so I am fishing the -D inside there. But then grdcut itself basically exits after parse. However, for some of the other modes of grdcut we may also wish to know the new region without getting a grid, so then I would need to know if I wrote stuff during gmt_init_module or not. We'll see. I think teh changed KEYS will be
and then a special check in GMT_Encode_Options to turn off implicit output (-G) if -D is given. This is to enable external usage like
to receive the dataset and not a grid. |
|
Any other concerns with this PR? |
|
Still need to batptize -D. |
|
Federico's comment about earth_day still needs to be addressed: #5753 (comment) |
OK, I am doing a similar zoom-in from 800 km to 10 km and because of #5763 I am not there yet. I will try to work on that one - we can let this one wait a bit longer. It is possible the algorithm could be a bit more generous when lower-resolution grids/images are selected to avoid this. |
maxrjones
left a comment
There was a problem hiding this comment.
Apart from the earth_day comment, the only other issue that remains is adding a test that includes each remote dataset type using grdcut -D.
Co-authored-by: Meghan Jones <meghanj@alum.mit.edu>
Co-authored-by: Meghan Jones <meghanj@alum.mit.edu>
|
Test checking the result of grdcut -D has been added, @meghanrjones. |
Great, thanks! It doesn't seem that merging in the code from #5776 fixed the earth_day resolution issue. |
|
Now that I have correct -R I can look at that to see if the algorithm needs improvement. |
Description of proposed changes
So far, the user has needed to specify which resolution they want for a remote grid. Unfortunately, knowing what is a good resolution when the goal is to make a map that will be 15 cm is not straightforward, so users tend to select too high resolutions given the size of their plots, resulting in extra download and processing time, plus bloated plots. This PR implements a feature for plotting where the resolution of a remote grid is optional. If so, we compute the resolution that is most compatible with an anticipated dots-per-unit of the plotted image. For non-plotting purposes (e.g., grdmath, grdproject, grdsample, ...) the user must specify the resolution. The key benefit of this PR is the huge simplification in making maps that uses the GMT remote grids for backgrounds in that no matter what the plot region, projection, and size is selected, the result will look good.
I have implemented a simple algorithm for this. Given -R -J I can compute two different representative lengths from the plot:
Then, given the desired dots-per-unit (new GMT default GMT_GRAPHICS_DPU [300i) we seek to find a grid whose number of nodes per degree, n, is the closest to satisfying this equation:
L * dpi = n * D.If the user has a reason to prefer a particular grid registration then they can still append _g or _p, but if no such version exist it will generate an error as no files can be found.
Here is a few examples of such a plots:
etc. Please try to break it. For now I am printing out an information line so we can see how it decides, e.g.
I encourage you to play with the regions, plot size, and desired DPU to see how it affects the result, and let me know if you cind some combination that works poorly.
Note if I do
gmt grdimage @earth_night_g -Rg -JH0/15c -B -png tit will give an error since there are no gridline version of these images...
Note: In causing this to fail I noticed that when a one-liner code fails in gmt_init_module and returns NULL, there is no place to terminate the modern session and the next modern one-liner will say
gmt [ERROR]: Cannot run a one-liner modern command within an existing modern mode sessionThe solution to that is to use the new terminate function I wrote for #5739 which is not completed, so this will go away later.