GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
757 stars 219 forks source link

Bounding box / map size not computed correctly #449

Closed MarkWieczorek closed 4 years ago

MarkWieczorek commented 4 years ago

Problem:

Portions of maps are cut off because the bounding box is too small, or the map size is too large.

Here are two examples, one of which is taken directly from the basemap doc string:

fig = pygmt.Figure()
fig.basemap(region=[0, 360, -90, 90], projection='W7i', frame=True)
fig.show(method='external')

fig = pygmt.Figure()
fig.basemap(projection='A0/0/2i', frame='g30', region='g')
fig.show(method='external')

And here are the results basemap example

I am using pygmt version 'v0.1.1' on macos with Python 3.7. I don't recall that this was a problem in the pre-v0.1 releases.

seisman commented 4 years ago

@MarkWieczorek What's your ghostscript version (i.e., output of gs --version)?

MarkWieczorek commented 4 years ago

v9.50

seisman commented 4 years ago

I can't reproduce your issue with PyGMT v0.1.1 + Python 3.7.6 on macOS.

Please try if the command line version works for you:

gmt basemap -R0/360/-90/90 -JW7i -B -Vd -pdf map
MarkWieczorek commented 4 years ago

That command works fine....

MarkWieczorek commented 4 years ago

I just tried reinstalling python, gmt and gs (via brew), and updated xcode, but all to no avail. The command line version works fine, but the pygmt still crops the image.

seisman commented 4 years ago

That's weird. Please try the code below and post the output:

import pygmt
pygmt.print_clib_info()
fig = pygmt.Figure()
fig.basemap(region=[0, 360, -90, 90], projection='W7i', frame=True)
fig.savefig("map.pdf", V='d')
MarkWieczorek commented 4 years ago
In [1]: import pygmt
   ...: pygmt.print_clib_info()
   ...: fig = pygmt.Figure()
   ...: fig.basemap(region=[0, 360, -90, 90], projection='W7i', frame=True)
   ...: fig.savefig("map.pdf", V='d')
Loaded libgmt:
  binary dir: /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS
  cores: 8
  grid layout: rows
  library path: /usr/local/Cellar/gmt/6.0.0_5/lib/libgmt.dylib
  padding: 2
  plugin dir: /usr/local/Cellar/gmt/6.0.0_5/lib/gmt/plugins
  share dir: /usr/local/Cellar/gmt/6.0.0_5/share/gmt
  version: 6.0.0
psconvert [DEBUG]: gmt_check_executable: Pass to popen: [gs --version 2> /dev/null]
psconvert [DEBUG]: gs --version 2> /dev/null was successful
psconvert [DEBUG]: Use PS filename /Users/lunokhod/.gmt/sessions/gmt6.18885/gmt_1.ps-
psconvert [DEBUG]: Hidden PS file /Users/lunokhod/.gmt/sessions/gmt6.18885/gmt_1.ps- found
psconvert [DEBUG]: Complete partial PS file /Users/lunokhod/.gmt/sessions/gmt6.18885/gmt_1.ps-
psconvert [DEBUG]: Size of half-baked PS file = 26447.
psconvert [DEBUG]: Fattened up PS file /Users/lunokhod/.gmt/sessions/gmt6.18885/gmt_1.ps-
psconvert [INFORMATION]: Processing /Users/lunokhod/.gmt/sessions/gmt6.18885/gmt_1.ps-...
psconvert [INFORMATION]: Find HiResBoundingBox ...
psconvert [DEBUG]: Running: gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/Users/lunokhod/.gmt/sessions/gmt6.18885/gmt_1.ps-' 2> '/Users/lunokhod/.gmt/sessions/gmt6.18885/psconvert_18885c.bb'
psconvert [INFORMATION]: Figure dimensions: Width: 235.764 points [8.31723 cm]  Height: 502.974 points [17.7438 cm]
psconvert [DEBUG]: Delete /Users/lunokhod/.gmt/sessions/gmt6.18885/psconvert_18885c.bb
psconvert [INFORMATION]: [0 339.03 235.764 842.004]...
psconvert [INFORMATION]: Convert to PDF...
psconvert [DEBUG]: Running: gs -q -dNOPAUSE -dBATCH -dNOSAFER -dPDFSETTINGS=/prepress -dDownsampleColorImages=false -dDownsampleGrayImages=false -dDownsampleMonoImages=false -dUseFlateCompression=true -dEmbedAllFonts=true -dSubsetFonts=true -dMonoImageFilter=/FlateEncode -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dSCANCONVERTERTYPE=2 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=1 -dTextAlphaBits=1 -sDEVICE=pdfwrite  -g5030x2358 -r720 -sOutputFile='map.pdf' '/Users/lunokhod/.gmt/sessions/gmt6.18885/psconvert_18885d.eps'
psconvert [DEBUG]: Delete /Users/lunokhod/.gmt/sessions/gmt6.18885/psconvert_18885d.eps
psconvert [DEBUG]: Final input buffer length was 256
psconvert (gmtlib_free_tmp_arrays): tried to free unallocated memory
seisman commented 4 years ago

This is what I have. I don't understand the differences. @PaulWessel Any thoughts?

Loaded libgmt:
  binary dir: /Users/seisman/.anaconda/bin
  cores: 8
  grid layout: rows
  library path: /Users/seisman/local/GMT-6.0.0/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/seisman/local/GMT-6.0.0/lib/gmt/plugins
  share dir: /Users/seisman/local/GMT-6.0.0/share
  version: 6.0.0
psconvert [DEBUG]: gmt_check_executable: Pass to popen: [gs --version 2> /dev/null]
psconvert [DEBUG]: gs --version 2> /dev/null was successful
psconvert [DEBUG]: Use PS filename /Users/seisman/.gmt/sessions/gmt6.55086/gmt_1.ps-
psconvert [DEBUG]: Hidden PS file /Users/seisman/.gmt/sessions/gmt6.55086/gmt_1.ps- found
psconvert [DEBUG]: Complete partial PS file /Users/seisman/.gmt/sessions/gmt6.55086/gmt_1.ps-
psconvert [DEBUG]: Size of half-baked PS file = 26448.
psconvert [DEBUG]: Fattened up PS file /Users/seisman/.gmt/sessions/gmt6.55086/gmt_1.ps-
psconvert [INFORMATION]: Processing /Users/seisman/.gmt/sessions/gmt6.55086/gmt_1.ps-...
psconvert [INFORMATION]: Find HiResBoundingBox ...
psconvert [DEBUG]: Running: gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/Users/seisman/.gmt/sessions/gmt6.55086/gmt_1.ps-' 2> '/Users/seisman/.gmt/sessions/gmt6.55086/psconvert_55086c.bb'
psconvert [INFORMATION]: Figure dimensions: Width: 545.904 points [19.2583 cm]  Height: 253.512 points [8.94334 cm]
psconvert [DEBUG]: Delete /Users/seisman/.gmt/sessions/gmt6.55086/psconvert_55086c.bb
psconvert [INFORMATION]: [338.994 359.244 884.898 612.756]...
psconvert [INFORMATION]: Convert to PDF...
psconvert [DEBUG]: Running: gs -q -dNOPAUSE -dBATCH -dNOSAFER -dPDFSETTINGS=/prepress -dDownsampleColorImages=false -dDownsampleGrayImages=false -dDownsampleMonoImages=false -dUseFlateCompression=true -dEmbedAllFonts=true -dSubsetFonts=true -dMonoImageFilter=/FlateEncode -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dSCANCONVERTERTYPE=2 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=1 -dTextAlphaBits=1 -sDEVICE=pdfwrite  -g5460x2536 -r720 -sOutputFile='map.pdf' '/Users/seisman/.gmt/sessions/gmt6.55086/psconvert_55086d.eps'
psconvert [DEBUG]: Delete /Users/seisman/.gmt/sessions/gmt6.55086/psconvert_55086d.eps
psconvert [DEBUG]: Final input buffer length was 256
psconvert (gmtlib_free_tmp_arrays): tried to free unallocated memory

@MarkWieczorek If you have a "gmt.conf" in your home directory or elsewhere, perhaps you can move it to other places and try again.

PaulWessel commented 4 years ago

No, other that a gmt.conf with a PS_MEDIA in it causing trouble?

MarkWieczorek commented 4 years ago

The gmt.conf file seems to be the cause of the problem, but there is still some kind of weird bug.

  1. If I delete the gmt.conf file in my ~/.gmt directory, everything works as expected.
  2. However, if I create a new virgin gmt.conf file with the command gmt defaults -D > gmt.conf I run into the same problem.

This seems to indicate to me that the configuration parameters that are somehow hardcoded into gmt are not in fact the same as those that are created with gmt defaults -D

seisman commented 4 years ago

gmt defaults -D print the current GMT default settings. If you have a "gmt.conf" somewhere, gmt defaults -D may load and print settings in that "gmt.conf". Running gmt defaults -D -Vd > gmt.conf can tell you if you still have another "gmt.conf" file anywhere.

BTW, gmt defaults -Ds and gmt defaults -Du will print the system default settings in SI and US units, respectively. You can also check the differences among the "gmt.conf" files generated by the three commands.

MarkWieczorek commented 4 years ago

In waiting for this issue to be resolved, I will delete the default gmt.conf whenever using pygmt.

seisman commented 4 years ago

Now I can reproduce your issue with GMT 6.0.0, but not with the lastest GMT master branch. I believe it is a GMT 6.0.0 bug, and was possibly fixed in https://github.com/GenericMappingTools/gmt/pull/2120 and https://github.com/GenericMappingTools/gmt/pull/2100.

As GMT 6.1.0 is planned to be released on June 1st, 2020, and PyGMT is mostly likely to bump its minimum required GMT version to 6.1.0 due to the bug in plot() (#255), I don't think we'll try to find a workaround on the PyGMT side.

MarkWieczorek commented 4 years ago

I can wait until June 1!

seisman commented 4 years ago

FYI, you can run brew install gmt --HEAD to build and install the GMT master branch via homebrew.

seisman commented 4 years ago

I believe this is also a upstream GMT bug, fixed in GMT 6.1.0. Closing the issue. Feel free to re-open it if you still have the same problem.