Skip to content

psconvert: gs options passed via -C doesn't override internally hardcoded options  #8982

Closed

Description

@uliw

Edit by @seisman: The issue was initially reported to the PyGMT repository, but it turns out to be an GMT issue, so I transferred it here.

To reproduce the issue in the GMT CLI, try the following:

gmt psbasemap -R0/10/0/10 -JX10c -Baf > map.ps
gmt psconvert map.ps -C-dMaxBitmap=2000000 -S

The output is

gs -q -dNOPAUSE -dBATCH -dNOSAFER -dSCANCONVERTERTYPE=2 -dMaxBitmap=2000000 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=2 -dTextAlphaBits=4 -sDEVICE=jpeg -dJPEGQ=90 -g2480x3509 -r300 -sOutputFile='map.jpg' './psconvert_3324091d.eps'

Description of the problem

Specifying ghostcript options in the figure command like this:

fig.savefig("foo.pd",
            gs_option="-dMaxBitmap=2000000,
            ) 

will pass the option to the ghopstcript process. However it will do so in front of the default values, so that the custom options are nullified.

Minimal Complete Verifiable Example

I only noticed because the psconvert step fails with an error. If this can be traced without creating a ginormous plot file, the above commands should be sufficient.

Full error message

pygmt.exceptions.GMTCLibError: Module 'psconvert' failed with status code 79:
psconvert [ERROR]: System call [gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=20000000000, -dMaxBitmap=2147483647 -dUseFastColor=true '/home/uliw/.gmt/sessions/gmt_session.25132/gmt_1.ps-' 2> '/home/uliw/.gmt/sessions/gmt_session.25132/psconvert_25132c.bb'] returned error 256.

System information

PyGMT information:
  version: v0.18.0
System information:
  python: 3.14.3 | packaged by conda-forge | (main, Feb  9 2026, 21:56:02) [GCC 14.3.0]
  executable: /home/uliw/miniforge3/envs/p314/bin/python
  machine: Linux-6.19.2-1-default-x86_64-with-glibc2.42
Dependency information:
  numpy: 2.4.3
  pandas: 3.0.2
  xarray: 2026.2.0
  packaging: 26.0
  contextily: None
  geopandas: 1.1.3
  IPython: None
  pyarrow: None
  rioxarray: None
  gdal: 3.12.3
  ghostscript: 10.07.0
GMT library information:
  version: 6.6.0
  padding: 2
  share dir: /home/uliw/miniforge3/envs/p314/share/gmt
  plugin dir: /home/uliw/miniforge3/envs/p314/lib/gmt/plugins
  library path: /home/uliw/miniforge3/envs/p314/lib/libgmt.so
  cores: 32
  grid layout: rows
  image layout: 
  binary version: 6.6.0

Activity

  1. added
    bug
    on Apr 11, 2026
  2. weiji14 commented on Apr 12, 2026

    @weiji14
    Member

    Hmm yeah, so that -dMaxBitmap=2147483647 argument seems to be hardcoded in upstream GMT at https://github.com/GenericMappingTools/gmt/blame/9880a3118ebbcf7a1cb0115f832e8b07c2da47c9/src/psconvert.c#L1817.

    add_to_list (Ctrl->C.arg, "-dMaxBitmap=2147483647");	/* Add this as GS option to fix bug in GS */

    I'm trying to find context on what that 'bug in GS (ghostscript)' is, since it was made >10 years ago (cbd67e1), going back to at least GMT 5. It seems that @remkos originally used -dMaxBitmap=100000000 for just psconvert ... -TG in 70e792e, and that number got increased to 2147483647 = 2^31-1 at some point, and applied to all psconvert operations.

    Did you want to set a higher or lower dMaxBitmap? I see you mentioned -dMaxBitmap=2000000 first, but your error message shows -dMaxBitmap=20000000000. Either way, we probably need to handle this in GMT upstream, by unhardcoding the value somehow. cc @seisman.

  3. uliw commented on Apr 13, 2026

    @uliw
    Author

    I am trying to generate a high res map in poster format, but the process fails, even so the system has plenty of free memory. Reading https://ghostscript.readthedocs.io/en/latest/Use.html it seems however that this parameter is only relevant for onscreen display. I'll experiment with gmt directly and follow up.

  4. uliw commented on Apr 13, 2026

    @uliw
    Author

    Is there a way to keep the not yet converted ps-file, so I can try to run this via gmt call? I tried with setting pygmt.config(GMT_VERBOSE="d"), but it does remove the temp files.

    ygmt-session [DEBUG]: GMT_Call_Command string: gmt psconvert -A -E50 -Fna_unified -Qg2 -Qt2 -Tf
    pygmt-session [DEBUG]: Revised options: -A -E50 -Fna_unified -Qg2 -Qt2 -Tf
    psconvert [DEBUG]: Ghostscript executable full name:
    psconvert [DEBUG]: gmt_run_process_get_first_line: Pass to popen: [gs --version 2> /dev/null]
    psconvert [DEBUG]: gs --version 2> /dev/null was successful
    psconvert [DEBUG]: Ghostscript version: 10.07.0
    psconvert [DEBUG]: Use PS filename /home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps-
    psconvert [DEBUG]: Hidden PS file /home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps- found
    psconvert [DEBUG]: Complete partial PS file /home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps-
    psconvert [DEBUG]: Size of half-baked PS file = 4226838795.
    psconvert [DEBUG]: Fattened up PS file /home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps-
    psconvert [INFORMATION]: Processing /home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps-...
    psconvert [INFORMATION]: Find HiResBoundingBox ...
    psconvert [DEBUG]: Running: gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps-' 2> '/home/uliw/.gmt/sessions/gmt_session.66625/psconvert_66625c.bb'
    Error: /limitcheck in /----nostringval----
    Operand stack:
    
    Execution stack:
       %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1804   1   3   %oparray_pop   1803   1   3   %oparray_pop   1788   1   3   %oparray_pop   1659   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push
    Dictionary stack:
       --dict:749/1123(ro)(G)--   --dict:0/20(G)--   --dict:85/200(L)--   --dict:157/250(L)--
    Current allocation mode is local
    Last OS error: No such file or directory
    psconvert [ERROR]: System call [gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps-' 2> '/home/uliw/.gmt/sessions/gmt_session.66625/psconvert_66625c.bb'] returned error 256.
    psconvert [DEBUG]: Delete /home/uliw/.gmt/sessions/gmt_session.66625/psconvert_66625c.bb
    Traceback (most recent call last):
      File "/home/uliw/user/n_america/na_unified.py", line 134, in <module>
        fig.savefig("na_unified.pdf", dpi=50,
        ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
                    # resize="+m2c",
                    ^^^^^^^^^^^^^^^^
                    # gs_option="-dMaxBitmap=20000000000, -dMaxMemory=2000000000",
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    ) # Limit ghostscript memory)
                    ^
      File "/home/uliw/miniforge3/envs/py314/lib/python3.14/site-packages/pygmt/figure.py", line 254, in savefig
        self.psconvert(prefix=prefix, fmt=fmts[ext], crop=crop, **kwargs)
        ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/uliw/miniforge3/envs/py314/lib/python3.14/site-packages/pygmt/helpers/decorators.py", line 591, in new_module
        return module_func(*args, **kwargs)
      File "/home/uliw/miniforge3/envs/py314/lib/python3.14/site-packages/pygmt/src/psconvert.py", line 146, in psconvert
        lib.call_module(module="psconvert", args=build_arg_list(aliasdict))
        ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/uliw/miniforge3/envs/py314/lib/python3.14/site-packages/pygmt/clib/session.py", line 671, in call_module
        raise GMTCLibError(msg)
    pygmt.exceptions.GMTCLibError: Module 'psconvert' failed with status code 79:
    psconvert [ERROR]: System call [gs -q -dNOSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox -DPSL_no_pagefill -dMaxBitmap=2147483647 -dUseFastColor=true '/home/uliw/.gmt/sessions/gmt_session.66625/gmt_1.ps-' 2> '/home/uliw/.gmt/sessions/gmt_session.66625/psconvert_66625c.bb'] returned error 256.
    pygmt-session [DEBUG]: gmtinit_parse_map_annot_oblique: Converted separate,lon_horizontal,lat_horizontal,tick_extend to 14
    pygmt-session [DEBUG]: The PROJ_GEODESIC set to Vincenty
    pygmt-session [DEBUG]: Exit:  gmt_reload_settings
    pygmt-session [DEBUG]: Enter: gmtlib_plot_C_format
    pygmt-session [DEBUG]: Exit:  gmtlib_plot_C_format
    pygmt-session [DEBUG]: Enter: gmtinit_get_history
    pygmt-session [DEBUG]: gmtlib_get_graphics_item: Fig: 1 Subplot: 2 Panel: () Inset: 0
    pygmt-session [DEBUG]: Enter: gmt_hash_init
    pygmt-session [DEBUG]: Exit:  gmt_hash_init
    pygmt-session [DEBUG]: Exit:  gmtinit_get_history
    pygmt-session [DEBUG]: Initialize FFTW with 32 threads.
    pygmt-session [DEBUG]: GMT_Create_Session initialized GMT structure
    pygmt-session [DEBUG]: Shared Library # 0 (core). Path = /home/uliw/miniforge3/envs/py314/lib/libgmt.so
    pygmt-session [DEBUG]: Loading GMT plugins from: /home/uliw/miniforge3/envs/py314/lib/gmt/plugins
    pygmt-session [DEBUG]: Shared Library # 1 (supplements). Path = /home/uliw/miniforge3/envs/py314/lib/gmt/plugins/supplements.so
    pygmt-session [DEBUG]: GMT now running in modern mode [Session ID = 66625]
    pygmt-session [DEBUG]: GMT_Call_Command string: gmt end (null)
    pygmt-session [DEBUG]: Revised options: (null)
    [Session pygmt-session (29)]: Error returned from GMT API: GMT_ARG_IS_NULL (4)
    end [DEBUG]: End Workflow.  Session ID = 66625. Directory /home/uliw/.gmt/sessions/gmt_session.66625 removed.
    end [DEBUG]: Got session name as pygmt-session and default graphics formats as pdf
    end [INFORMATION]: Process GMT figure queue: 2 figures found
    end [INFORMATION]: Processing GMT figure #0 [pygmt-session pdf ]
    end [INFORMATION]: Processing GMT figure GenericMappingTools/pygmt#1 [53d8375088584870b08da59151691f05 - ]
    end [DEBUG]: GMT now running in modern mode [Session ID = 66625]
    end [DEBUG]: GMT_Call_Command string: gmt figure 53d8375088584870b08da59151691f05
    end [DEBUG]: Revised options: 53d8375088584870b08da59151691f05
    end [DEBUG]: Enter: gmtinit_get_history
    end [DEBUG]: gmtlib_get_graphics_item: Fig: 1 Subplot: 2 Panel: () Inset: 0
    end [DEBUG]: Enter: gmt_hash_init
    end [DEBUG]: Exit:  gmt_hash_init
    end [DEBUG]: Exit:  gmtinit_get_history
    end [INFORMATION]: Destroying the current workflow directory /home/uliw/.gmt/sessions/gmt_session.66625
    end [DEBUG]: Delete gmt.1.cpt
    end [DEBUG]: Delete gmt.1.legend
    end [DEBUG]: Delete gmt.canvas.1
    end [DEBUG]: Delete gmt.conf
    end [DEBUG]: Delete gmt.conf.1
    end [DEBUG]: Delete gmt.current
    end [DEBUG]: Delete gmt.figures
    end [DEBUG]: Delete gmt.frame.1
    end [DEBUG]: Delete gmt.history
    end [DEBUG]: Delete gmt.history.1
    end [DEBUG]: Delete gmt.layers.1
    end [DEBUG]: Delete gmt.session
    end [DEBUG]: Delete gmt_1.ps-
    
    
  5. weiji14 commented on Apr 13, 2026

    @weiji14
    Member

    I am trying to generate a high res map in poster format

    Ah, if that's the case... Have you set the dpi/-E parameter? E.g. for grdimage, it defaults to dpi=100, but you can increase that to 300 or 600. Also, psconvert has a dpi parameter, but you need to make sure your underlying map layers (especially the raster ones) are all high resolution before changing that.

  6. uliw commented on Apr 14, 2026

    @uliw
    Author

    I placed a breakpoint before calling psconvert to get access to the ps file. Using this GS immediately exits upon reading the file with a limitcheck. In my understanding, this is because some numbers in the ps file exceed the postscript specification. So this may have nothing todo with gmt/pygmt.

  7. seisman commented on Apr 16, 2026

    @seisman
    Member

    This is an upstream issue, so I'm transferring it to the upstream GMT repository.

    To reproduce the issue in GMT CLI, try:

    gmt psbasemap -R0/10/0/10 -JX10c -Baf > map.ps
    gmt psconvert map.ps -C-dMaxBitmap=2000000 -S
    

    The output is

    gs -q -dNOPAUSE -dBATCH -dNOSAFER -dSCANCONVERTERTYPE=2 -dMaxBitmap=2000000 -dMaxBitmap=2147483647 -dUseFastColor=true -dGraphicsAlphaBits=2 -dTextAlphaBits=4 -sDEVICE=jpeg -dJPEGQ=90 -g2480x3509 -r300 -sOutputFile='map.jpg' './psconvert_3324091d.eps'
    
  8. changed the title [-]pygmt.Figure.psconvert overwrites gs_option dMaxBitmap argument[/-] [+]psconvert: gs options passed via -C doesn't override internally hardcoded options [/+] on Apr 16, 2026
  9. github-actions commented on Apr 16, 2026

    @github-actions
    Contributor

    👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. We appreciate that you took the time to contribute!

    Please make sure you read our Contributing Guide and abide by our Code of Conduct.

  10. added a commit that references this issue on Apr 16, 2026
    aa610c1
  11. added a commit that references this issue on Apr 16, 2026
    ca5130f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions