Skip to content

Better auto-resolution selection for grids and images - #5887

Merged
PaulWessel merged 6 commits into
masterfrom
better-auto-res
Oct 22, 2021
Merged

PaulWessel merged 6 commits into
masterfrom
better-auto-res

Conversation

@PaulWessel

Copy link
Copy Markdown
Contributor

Description of proposed changes

I have been tinkering with how to determine a suitable remote grid image resolution that would work well with all projections. My initial attempts (in master) examined both longitude and diagonal degree range for a map. However, longitudes are difficult as the longitude range can suddenly jump from a small range to 360 if a pole enters the region. So this PR only considers the latitude range (Y) relative to the map height (H). Then, the required number of grid nodes per degree is computed via N_f = L * dpi / D, where dpi is the desired dots-per-inch needed. We then use the next higher actual N_r of the nearest grid resolution. I am testing this with a zoom from 100,000 km altitude to 10 km altitude over a fixed point (Vienna). The movie script is

#!/usr/bin/env bash
lat=47.8095
lon=13.0550
dpc=100
cat << EOF > pre.sh
gmt begin
	gmt math -T1/5/720+n 10 T POW -o1 -I = altitude.txt
	gmt makecpt -Cgeo -H > topo.cpt
gmt end
EOF
cat << EOF > main.sh
gmt begin
	gmt grdimage @earth_relief -Rd -JG$lon/$lat/14.9c+z\${MOVIE_COL0}+v60 -Yc -Xc -B0 -Ctopo.cpt -I+d --GMT_GRAPHICS_DPU=${dpc}c --MAP_FRAME_PEN=faint
	echo $lon $lat | gmt plot -SE-10 -Gred@50
	L=\$(gmt grdcut @earth_relief -Rd -JG$lon/$lat/14.9c+z\${MOVIE_COL0}+v60 -D+t --GMT_GRAPHICS_DPU=${dpc}c)
	echo \${L} | gmt text -F+cTR+jTR+f8p
	echo "altitude = \${MOVIE_COL0} L = \${L}"
gmt end
EOF
gmt movie main.sh -Sbpre.sh -NZoom_Relief_${dpc}c -Taltitude.txt -C15cx15cx100 -D24 -H8 -M0,png -Fmp4 -Lc0+f12p+t"Altitude = %6.1lf km" -V

The movie can be seen on YouTube. Via debug dump I have captured both N_f and N_r and for this wide range of altitudes it looks like this:

summary

As you can see, the selected grid resolution (blue) is always equal or higher than the required, until we run out of even higher resolutions after 1 arc second around 25 km altitude. Please view the movie and see how it transitions between resolutions. Since the data sets are not always exactly the same you will notice the jumps to the better data but it is pretty good I think. Remember that making a movie with variable resolution like this is the most extreme case of this. Static plots will not experience this of course.

Given the stability that using Y brings to computing the required nodes per degree, I recommend you approve this PR.

@PaulWessel PaulWessel added the enhancement Improving an existing feature label Oct 21, 2021
@PaulWessel PaulWessel added this to the 6.3.0 milestone Oct 21, 2021
@PaulWessel PaulWessel self-assigned this Oct 21, 2021

@maxrjones maxrjones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Probably can remove the commented print statement before merging.

@PaulWessel
PaulWessel merged commit 8cd237b into master Oct 22, 2021
@PaulWessel
PaulWessel deleted the better-auto-res branch October 22, 2021 01:14
@PaulWessel

Copy link
Copy Markdown
Contributor Author

Forgot to remote the printf of course, will do in next PR.

@Esteban82

Copy link
Copy Markdown
Member

Question. Now GMT can calculate a proper dpi for the output raster?

@PaulWessel

Copy link
Copy Markdown
Contributor Author

I think so, it is better than it was earlier. Using the height and latitude range is more stable. But it is a relatively new feature so we may learn more as we use it more. Let me know if you run into anything.

@Esteban82

Copy link
Copy Markdown
Member

I just wonder if it could be used for grdview -Qi. The default value is 100 dpi.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Oh, I see. Given there is now GMT_GRAPHICS_DPU [300i] perhaps that should be the default . Is that what you meant?

@Esteban82

Esteban82 commented Oct 27, 2021 •

Copy link
Copy Markdown
Member

Mmm, I think yes.

@PaulWessel

Copy link
Copy Markdown
Contributor Author

Thinking about this some more. There is a difference:

  1. The GMT_GRAPHICS_DPU is used to determine the grid resolution of remote grids or images needed to yield an image of that resolution or highbher, given the domain and projection and map size
  2. The -Qi is used in the scanline conversion from the 3-D surface to a 2-D image representation

In fact, if you were to make a 3-D grdview plot of @earth_relief then the grid resolution we compute is probably only approximately correct, and then -Qi comes along. So I am not sure, but -Qi100 default was set a decade or more ago when we felt it took "too long" to rasterize. Maybe @joa-quim have any thoughts on this?

This branch was previously deployed

1 inactive deployment
Preview — d867001b Deployed Oct 21, 2021 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improving an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants