You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
grdimage -A -R crops but does not extend image #3106
If -R is used with -A and it crops the image, we get the cropped area back. However, if we use a -R setting that goes beyond the grid, we do not get extra NaN space back, just the same image. It seems to me that if we run
gmt grdmath -R0/20/0/20 -I0.1 X Y MUL = t.nc
gmt grdimage t.nc -JX5i -A1.png
gmt grdimage t.nc -JX5i -A2.png -R0/20/0/30
then image 1.png should be 201x201 while 2.png should be 301x201, but it is still 201x201.
Right now, grdimage -A assumes we want the grid (or a subset) to fit exactly in the image. The whole machinery of addressing the pixels assume the first plotted pixel is row = col = 0. However, this is a bad assumption. See the illustration below:
Here my fake grid is assumed to be geographic with bounds -20/20/10/20, but I am plotting it with -R-25/5/14.2573318521/23.9576963964+r -JL0/15/10/20/15c. This is the full area above in which my grid (gray) is partly clipped on the right side and there is extra space around elsewhere. The pixels are such that I want to fill in the squares. The white squares are outside the grid and should be NaN and hence black or transparent, while the black pixels should be set to color given by the projected grid at those points and the CPT table. The red box is the rectangular outline of the projected lon/lat grid to map units; it has several pixels that are NaN as well (white). The job is to loop over the grid nodes (pixels) inside the red box and assign color, leaving the white pixels outside the red box alone. This means the following changes:
The image that is allocated must match the dimensions of the entire plot (here the fat outline and all the pixels inside it)
The calculation of the image pixel needs to take into account a fixed offset due to the rows above the red box and a a per-row fixed offset due to the pixels to the left of the red box.
These offsets only apply when -A is used, not when PostScript is plotted.
I think with these changes we can return the correct image above.
The logic in the loop over the pixels in grdimage.c assumes we are only dealing with the red rectangle, so there is no offsets corresponding to the white areas.
Activity
PaulWessel commentedon May 3, 2020
Right now, grdimage -A assumes we want the grid (or a subset) to fit exactly in the image. The whole machinery of addressing the pixels assume the first plotted pixel is row = col = 0. However, this is a bad assumption. See the illustration below:
Here my fake grid is assumed to be geographic with bounds
-20/20/10/20, but I am plotting it with-R-25/5/14.2573318521/23.9576963964+r -JL0/15/10/20/15c. This is the full area above in which my grid (gray) is partly clipped on the right side and there is extra space around elsewhere. The pixels are such that I want to fill in the squares. The white squares are outside the grid and should be NaN and hence black or transparent, while the black pixels should be set to color given by the projected grid at those points and the CPT table. The red box is the rectangular outline of the projected lon/lat grid to map units; it has several pixels that are NaN as well (white). The job is to loop over the grid nodes (pixels) inside the red box and assign color, leaving the white pixels outside the red box alone. This means the following changes:I think with these changes we can return the correct image above.
PaulWessel commentedon May 23, 2020
The logic in the loop over the pixels in grdimage.c assumes we are only dealing with the red rectangle, so there is no offsets corresponding to the white areas.
grdimage: grdimage -A -R does not extend image (GenericMappingTools#9036