Skip to content

Figure.grdimage does not respect shading=None #1852

Closed
@MarkWieczorek

Description

@MarkWieczorek

Description of the problem

Figure.grdimage() crashes when specifying the option shading=None. According to the docstring, shading=None is the default value, so this is weird. For the script I am using, I need to always specify something for shading (either nothing, or a file), so this breaks everything for me. This appears to have been broken since version 0.4

Full code that generated the error

This works

fig = pygmt.Figure()
fig.grdimage(grid="@earth_relief_01d_g")

fig = pygmt.Figure()
fig.grdimage(grid="@earth_relief_01d_g", shading="@earth_relief_01d_g+d")

This doesn't

fig = pygmt.Figure()
fig.grdimage(grid="@earth_relief_01d_g", shading=None)

Full error message

---------------------------------------------------------------------------
GMTInvalidInput                           Traceback (most recent call last)
Input In [10], in <cell line: 4>()
      1 import pygmt
      3 fig = pygmt.Figure()
----> 4 fig.grdimage(grid="@earth_relief_01d_g", shading=None)

File /opt/miniconda3/envs/testing/lib/python3.9/site-packages/pygmt/helpers/decorators.py:585, in use_alias.<locals>.alias_decorator.<locals>.new_module(*args, **kwargs)
    580         msg = (
    581             f"Short-form parameter ({short_param}) is not recommended. "
    582             f"Use long-form parameter '{long_alias}' instead."
    583         )
    584         warnings.warn(msg, category=SyntaxWarning, stacklevel=2)
--> 585 return module_func(*args, **kwargs)

File /opt/miniconda3/envs/testing/lib/python3.9/site-packages/pygmt/helpers/decorators.py:725, in kwargs_to_strings.<locals>.converter.<locals>.new_module(*args, **kwargs)
    723             kwargs[arg] = separators[fmt].join(f"{item}" for item in value)
    724 # Execute the original function and return its output
--> 725 return module_func(*args, **kwargs)

File /opt/miniconda3/envs/testing/lib/python3.9/site-packages/pygmt/src/grdimage.py:169, in grdimage(self, grid, **kwargs)
    166 file_context = lib.virtualfile_from_data(check_kind="raster", data=grid)
    167 with contextlib.ExitStack() as stack:
    168     # shading using an xr.DataArray
--> 169     if "I" in kwargs and data_kind(kwargs["I"]) == "grid":
    170         shading_context = lib.virtualfile_from_grid(kwargs["I"])
    171         kwargs["I"] = stack.enter_context(shading_context)

File /opt/miniconda3/envs/testing/lib/python3.9/site-packages/pygmt/helpers/utils.py:69, in data_kind(data, x, y, z, required_z)
     19 """
     20 Check what kind of data is provided to a module.
     21
   (...)
     66 'grid'
     67 """
     68 if data is None and x is None and y is None:
---> 69     raise GMTInvalidInput("No input data provided.")
     70 if data is not None and (x is not None or y is not None or z is not None):
     71     raise GMTInvalidInput("Too much data. Use either data or x and y.")

GMTInvalidInput: No input data provided.

System information

macos and ubuntu.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions