Skip to content

uint8 datatype issue #1960

@De-Guo

Description

@De-Guo

Description of the problem

I read an image of uint8 datatype with rioxarray.open_rasterio and plot with pygmt raise errors.

If I convert datatype to float, my script runs fluently.

Full error message

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3552, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-cbda221bbf05>", line 1, in <module>
    runfile('D:/NutSync/code/funcs_lib_dg/plot_func/plot_raster_pygmt.py', wdir='D:/NutSync/code/funcs_lib_dg/plot_func')
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/NutSync/code/funcs_lib_dg/plot_func/plot_raster_pygmt.py", line 307, in <module>
    xrd = main()
  File "D:/NutSync/code/funcs_lib_dg/plot_func/plot_raster_pygmt.py", line 301, in main
    rastr_plot.plot_raster_grid(figname=figname)
  File "D:/NutSync/code/funcs_lib_dg/plot_func/plot_raster_pygmt.py", line 99, in plot_raster_grid
    cmap=cpt
  File "C:\ProgramData\Anaconda3\lib\site-packages\pygmt\helpers\decorators.py", line 586, in new_module
    return module_func(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pygmt\helpers\decorators.py", line 726, in new_module
    return module_func(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pygmt\src\grdimage.py", line 173, in grdimage
    fname = stack.enter_context(file_context)
  File "C:\ProgramData\Anaconda3\lib\contextlib.py", line 427, in enter_context
    result = _cm_type.__enter__(cm)
  File "C:\ProgramData\Anaconda3\lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pygmt\clib\session.py", line 1341, in virtualfile_from_grid
    self.put_matrix(gmt_grid, matrix)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pygmt\clib\session.py", line 895, in put_matrix
    raise GMTCLibError(f"Failed to put matrix of type {matrix.dtype}.")
pygmt.exceptions.GMTCLibError: Failed to put matrix of type uint8.

System information

I use pygmt 0.5.0 with python 3.7.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImproving an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions