Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure.grdimage does not respect shading=None #1852

Closed
MarkWieczorek opened this issue Mar 28, 2022 · 5 comments · Fixed by #1857
Closed

Figure.grdimage does not respect shading=None #1852

MarkWieczorek opened this issue Mar 28, 2022 · 5 comments · Fixed by #1857
Labels
bug Something isn't working
Milestone

Comments

@MarkWieczorek
Copy link
Contributor

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.

@MarkWieczorek MarkWieczorek added the bug Something isn't working label Mar 28, 2022
@seisman
Copy link
Member

seisman commented Mar 28, 2022

Likely a duplicate of #1665.

@weiji14
Copy link
Member

weiji14 commented Mar 28, 2022

Yes, this seems related to the bug mentioned at #1665 (comment). A workaround to keep you going would be to use shading=False for now.

Also @MarkWieczorek, could you please post the output of python -c "import pygmt; pygmt.show_versions()" so that we have a record on which PyGMT version this is a problem on?

@MarkWieczorek
Copy link
Contributor Author

And this, I think: #1815

@MarkWieczorek
Copy link
Contributor Author

pyGMT information:
  version: v0.6.0
System information:
  python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:23:20)  [Clang 12.0.1 ]
  executable: /opt/miniconda3/envs/testing/bin/python
  machine: macOS-12.2.1-x86_64-i386-64bit
Dependency information:
  numpy: 1.22.3
  pandas: 1.4.1
  xarray: 2022.3.0
  netCDF4: 1.5.8
  packaging: 21.3
  ghostscript: 9.54.0
  gmt: 6.3.0
GMT library information:
  binary dir: /opt/miniconda3/envs/testing/bin
  cores: 24
  grid layout: rows
  library path: /opt/miniconda3/envs/testing/lib/libgmt.dylib
  padding: 2
  plugin dir: /opt/miniconda3/envs/testing/lib/gmt/plugins
  share dir: /opt/miniconda3/envs/testing/share/gmt
  version: 6.3.0

@MarkWieczorek
Copy link
Contributor Author

shading=False works for now. It is just that this isn't consistent with the documentation, so this should probably get fixed at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants