GenericMappingTools/pygmt

Fail to make the Tile maps due to psconvert [ERROR]

zkn365 opened this issue · 3 comments

Description of the problem

Fail to generate tile maps with the demo script of pygmt.
https://www.pygmt.org/latest/gallery/maps/tilemaps.html#sphx-glr-gallery-maps-tilemaps-py

Anyone can help?
Error:
File "C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\workspace-map-ekjYw_mI-py3.10\lib\site-packages\pygmt\clib\session.py", line 659, in call_module
raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module 'psconvert' failed with status code 79:
psconvert [ERROR]: No hidden PS file C:/Users/User/.gmt/sessions/gmt_session.ad04e157a7eb49efaee6f9811253a247/gmt_1.ps- found

Minimal Complete Verifiable Example

import contextily
import pygmt
pygmt.show_versions()
fig = pygmt.Figure()
fig.tilemap(
    region=[-157.84, -157.8, 21.255, 21.285],
    projection="M12c",
    # Set level of details (0-22)
    # Higher levels mean a zoom level closer to the Earth's
    # surface with more tiles covering a smaller
    # geographic area and thus more details and vice versa
    # Please note, not all zoom levels are always available
    zoom=14,
    # Use tiles from OpenStreetMap tile server
    source="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
    frame="afg",
)
fig.savefig("pygmt_Tile_Maps.png",V='d')

Full error message

ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db
ERROR 1: PROJ: proj_create_from_database: Cannot find proj.db
Warning 1: PROJ: proj_create_from_database: Cannot find proj.db
Warning 1: The definition of projected CRS EPSG:3857 got from GeoTIFF keys is not the same as the one from the EPSG registry, which may cause issues during reprojection operations. Set GTIFF_SRS_SOURCE configuration option to EPSG to use official parameters (overriding the ones from GeoTIFF keys), or to GEOKEYS to use custom values from GeoTIFF keys and drop the EPSG code.
Warning 1: PROJ: proj_create_from_database: Cannot find proj.db
Warning 1: The definition of projected CRS EPSG:3857 got from GeoTIFF keys is not the same as the one from the EPSG registry, which may cause issues during reprojection operations. Set GTIFF_SRS_SOURCE configuration option to EPSG to use official parameters (overriding the ones from GeoTIFF keys), or to GEOKEYS to use custom values from GeoTIFF keys and drop the EPSG code.
Warning 1: PROJ: proj_create_from_database: Cannot find proj.db
Warning 1: The definition of projected CRS EPSG:3857 got from GeoTIFF keys is not the same as the one from the EPSG registry, which may cause issues during reprojection operations. Set GTIFF_SRS_SOURCE configuration option to EPSG to use official parameters (overriding the ones from GeoTIFF keys), or to GEOKEYS to use custom values from GeoTIFF keys and drop the EPSG code.
Warning 1: PROJ: proj_create_from_database: Cannot find proj.db
Warning 1: The definition of projected CRS EPSG:3857 got from GeoTIFF keys is not the same as the one from the EPSG registry, which may cause issues during reprojection operations. Set GTIFF_SRS_SOURCE configuration option to EPSG to use official parameters (overriding the ones from GeoTIFF keys), or to GEOKEYS to use custom values from GeoTIFF keys and drop the EPSG code.
grdimage [WARNING]: (w - x_min) must equal (NX + eps) * x_inc), where NX is an integer and |eps| <= 0.0001.
grdimage [WARNING]: w reset from -517.84 to -524.595191276
grdimage [WARNING]: (n - y_min) must equal (NY + eps) * y_inc), where NY is an integer and |eps| <= 0.0001.
grdimage [WARNING]: n reset from 21.285 to 23.9333155621
grdimage (gmt_api.c:4834(gmtapi_import_image)): Could not reallocate memory [17154804629.42 Gb, 18419831213156680330 items of 1 bytes]
grdimage (gmt_api.c:4834(gmtapi_import_image)): gmt_M_memory [realloc] called
[Session pygmt-session (5)]: Error returned from GMT API: GMT_MEMORY_ERROR (25)
[Session pygmt-session (5)]: Error returned from GMT API: GMT_MEMORY_ERROR (25)
C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\workspace-map-ekjYw_mI-py3.10\lib\site-packages\pygmt\figure.py:372: SyntaxWarning: Short-form parameter (V) is not recommended. Use long-form parameter 'verbose' instead.
  self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
pygmt-session [DEBUG]: Revised options: -A -Fpygmt_Tile_Maps -Qg2 -Qt2 -Tg -Vd
psconvert [DEBUG]: Ghostscript executable full name:
psconvert [DEBUG]: gmt_run_process_get_first_line: Pass to popen: ["C:\Program Files\gs\gs10.01.0\bin\gswin64c.exe" --version 2> NUL]
psconvert [DEBUG]: "C:\Program Files\gs\gs10.01.0\bin\gswin64c.exe" --version 2> NUL was successful
psconvert [DEBUG]: Ghostscript version: 10.01.0
psconvert [DEBUG]: Use PS filename C:/Users/User/.gmt/sessions/gmt_session.16d956324ae74f22b9644cf4ab519d0d/gmt_1.ps-
psconvert [ERROR]: No hidden PS file C:/Users/User/.gmt/sessions/gmt_session.16d956324ae74f22b9644cf4ab519d0d/gmt_1.ps- found
Traceback (most recent call last):
  File "C:\cloud_workspace\workspace_map\pygmt_maps\pygmt_Tile_Maps.py", line 51, in <module>
    fig.savefig("pygmt_Tile_Maps.png",V='d')
  File "C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\workspace-map-ekjYw_mI-py3.10\lib\site-packages\pygmt\figure.py", line 372, in savefig
    self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
  File "C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\workspace-map-ekjYw_mI-py3.10\lib\site-packages\pygmt\helpers\decorators.py", line 609, in new_module
    return module_func(*args, **kwargs)
  File "C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\workspace-map-ekjYw_mI-py3.10\lib\site-packages\pygmt\helpers\decorators.py", line 773, in new_module
    return module_func(*bound.args, **bound.kwargs)
  File "C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\workspace-map-ekjYw_mI-py3.10\lib\site-packages\pygmt\figure.py", line 252, in psconvert
    lib.call_module(module="psconvert", args=build_arg_list(kwargs))
  File "C:\Users\User\AppData\Local\pypoetry\Cache\virtualenvs\workspace-map-ekjYw_mI-py3.10\lib\site-packages\pygmt\clib\session.py", line 659, in call_module
    raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module 'psconvert' failed with status code 79:
psconvert [ERROR]: No hidden PS file C:/Users/User/.gmt/sessions/gmt_session.16d956324ae74f22b9644cf4ab519d0d/gmt_1.ps- found

System information

The version output:
PyGMT information:
  version: v0.12.0
System information:
  python: 3.10.12 | packaged by Anaconda, Inc. | (main, Jul  5 2023, 19:01:18) [MSC v.1916 64 bit (AMD64)]
  executable: C:\Users\user\AppData\Local\Scripts\python.exe
  machine: Windows-10-10.0.22631-SP0
Dependency information:
  numpy: 2.0.0
  pandas: 2.2.2
  xarray: 2024.6.0
  netCDF4: 1.7.1
  packaging: 24.1
  contextily: 1.6.0
  geopandas: 0.14.4
  ipython: None
  rioxarray: 0.15.5
  ghostscript: None
GMT library information:
  binary version: 6.5.0
  cores: 8
  grid layout: rows
  image layout: 
  library path: C:/programs/gmt6/bin/gmt_w64.dll
  padding: 2
  plugin dir: C:/programs/gmt6/bin/gmt_plugins
  share dir: C:/programs/gmt6/share
  version: 6.5.0

👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.

Solution: add pyproj path to system

import os
os.environ['PROJ_LIB'] = rf'C:\py3.10\Lib\site-packages\pyproj\proj_dir\share\proj'

add above codes to the top of the codes

So it's a PROJ configuration error. Not something we can fix on the PyGMT side. xref: https://proj.org/en/9.4/faq.html#why-am-i-getting-the-error-cannot-find-proj-db

Closing the issue.