pygmt: Setting frame=None gives unexpected results

Description of the problem

I am just getting started with pygmt and ran through the first example in the docs.

I wanted to play a bit with the example and tried to deactivate the frame

Full code that generated the error When I modify

fig.basemap(region=[-90, -70, 0, 20], projection="M15c", frame=True)

to

fig.basemap(region=[-90, -70, 0, 20], projection="M15c", frame=None)

I get this rather cryptic error

Full error message

basemap [ERROR]: Must specify at least one of -A, -B, -D, -L, -T
---------------------------------------------------------------------------
GMTCLibError                              Traceback (most recent call last)
/tmp/ipykernel_493/1135014409.py in <module>
----> 1 fig.basemap(region=[-90, -70, 0, 20], projection="M15c", frame=None)

/srv/conda/envs/notebook/lib/python3.8/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
    584                     )
    585                     warnings.warn(msg, category=SyntaxWarning, stacklevel=2)
--> 586             return module_func(*args, **kwargs)
    587 
    588         new_module.aliases = aliases

/srv/conda/envs/notebook/lib/python3.8/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
    724                         kwargs[arg] = separators[fmt].join(f"{item}" for item in value)
    725             # Execute the original function and return its output
--> 726             return module_func(*args, **kwargs)
    727 
    728         return new_module

/srv/conda/envs/notebook/lib/python3.8/site-packages/pygmt/src/basemap.py in basemap(self, **kwargs)
     82         )
     83     with Session() as lib:
---> 84         lib.call_module("basemap", build_arg_string(kwargs))

/srv/conda/envs/notebook/lib/python3.8/site-packages/pygmt/clib/session.py in call_module(self, module, args)
    498         )
    499         if status != 0:
--> 500             raise GMTCLibError(
    501                 f"Module '{module}' failed with status code {status}:\n{self._error_message}"
    502             )

GMTCLibError: Module 'basemap' failed with status code 72:
basemap [ERROR]: Must specify at least one of -A, -B, -D, -L, -T

Since None is the default for the frame kwarg I am a bit confused here. Is frame=True always required?

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PyGMT information:
  version: v0.5.0
System information:
  python: 3.8.12 | packaged by conda-forge | (default, Sep 29 2021, 19:52:28)  [GCC 9.4.0]
  executable: /srv/conda/envs/notebook/bin/python
  machine: Linux-5.4.120+-x86_64-with-glibc2.10
Dependency information:
  numpy: 1.21.2
  pandas: 1.3.3
  xarray: 0.19.0
  netCDF4: 1.5.7
  packaging: 21.0
  ghostscript: 9.54.0
  gmt: 6.2.0
GMT library information:
  binary dir: /srv/conda/envs/notebook/bin
  cores: 4
  grid layout: rows
  library path: /srv/conda/envs/notebook/lib/libgmt.so
  padding: 2
  plugin dir: /srv/conda/envs/notebook/lib/gmt/plugins
  share dir: /srv/conda/envs/notebook/share/gmt
  version: 6.2.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

Actually, I might do 2 PRs

  1. Refactor args_in_kwargs in #1815 which should fix the problem in basemap, coast, grdgradient, etc that use args_in_kwargs.
  2. Replace if "I" in kwargs with kwargs.get("I") is not None to fix #1852 and other functions that do that.

I may have got a generic solution for the bug fix in #1815 by modifying the args_in_kwargs function, but needs a bit more testing and handling of edge cases.

I don’t think your solution in #1815 is general, because sometimes we don’t use args_in_kwagrs, instead, we simply check if "B" in kwargs or similar. I think a more general solution is dealing with frame=None (i.e. removing kwargs["B"] if it’s None) in the @use_alias decorator.

I think we should refactor those cases that use logic like if "B" in kwargs" to use get rather than adding more functionality to the use_alias decorator.

I’m OK with the .get method, but we must be very careful not to use if "B" in kwargs when writing new codes.