Description
Description of the problem
The surface
gridding function doesn't allow passing in a python list to region
(e.g. [245, 255, 20, 30]
). This is actually an oversight on my part since I wrapped the function in #245 😨.
Full code that generated the error adapted from tests_surface.py
import pygmt
from pygmt.datasets import load_sample_bathymetry
ship_data = load_sample_bathymetry()
data = ship_data.values # convert pandas.DataFrame to numpy.ndarray
pygmt.surface(data=data, spacing="5m", region=[245, 255, 20, 30])
Full error message
-R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
Append r if giving lower left and upper right coordinates
-Rg or -Rd for global domain
-R<grdfile> to take the domain from a grid file
surface [ERROR]: Offending option -R245
surface [ERROR]: Option -R given more than once
surface [ERROR]: Syntax error -R option. Correct syntax:
-R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
Append r if giving lower left and upper right coordinates
-Rg or -Rd for global domain
-R<grdfile> to take the domain from a grid file
surface [ERROR]: Offending option -R255
surface [ERROR]: Option -R given more than once
surface [ERROR]: Syntax error -R option. Correct syntax:
-R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
Append r if giving lower left and upper right coordinates
-Rg or -Rd for global domain
-R<grdfile> to take the domain from a grid file
surface [ERROR]: Offending option -R20
surface [ERROR]: Option -R given more than once
surface [ERROR]: Syntax error -R option. Correct syntax:
-R<xmin>/<xmax>/<ymin>/<ymax>[/<zmin>/<zmax>]
Append r if giving lower left and upper right coordinates
-Rg or -Rd for global domain
-R<grdfile> to take the domain from a grid file
surface [ERROR]: Offending option -R30
---------------------------------------------------------------------------
GMTCLibError Traceback (most recent call last)
<ipython-input-6-918159e76c71> in <module>
----> 1 pygmt.surface(data=data, spacing="5m", region=[245, 255, 20, 30])
~/miniconda/envs/pygmt/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
181 if alias in kwargs:
182 kwargs[arg] = kwargs.pop(alias)
--> 183 return module_func(*args, **kwargs)
184
185 new_module.aliases = aliases
~/miniconda/envs/pygmt/pygmt/gridding.py in surface(x, y, z, data, **kwargs)
83 outfile = kwargs["G"]
84 arg_str = " ".join([infile, build_arg_string(kwargs)])
---> 85 lib.call_module(module="surface", args=arg_str)
86
87 if outfile == tmpfile.name: # if user did not set outfile, return DataArray
~/miniconda/envs/pygmt/pygmt/clib/session.py in call_module(self, module, args)
488 raise GMTCLibError(
489 "Module '{}' failed with status code {}:\n{}".format(
--> 490 module, status, self._error_message
491 )
492 )
GMTCLibError: Module 'surface' failed with status code 71:
surface [ERROR]: Syntax error -R option. Correct syntax:
surface [ERROR]: Offending option -R245
surface [ERROR]: Option -R given more than once
surface [ERROR]: Syntax error -R option. Correct syntax:
surface [ERROR]: Offending option -R255
surface [ERROR]: Option -R given more than once
surface [ERROR]: Syntax error -R option. Correct syntax:
surface [ERROR]: Offending option -R20
surface [ERROR]: Option -R given more than once
surface [ERROR]: Syntax error -R option. Correct syntax:
surface [ERROR]: Offending option -R30
Solution
This will be a relatively straightforward fix, and I'd be happy for someone new-ish wanting to contribute to PyGMT to submit a Pull Request (and learn from it). We can guide you through the process on how to add a Python decorator to fix the issue, and update the unit tests so that the problem won't surface 😉 again in the future.
Before you start, read up on our CONTRIBUTING.md. Also, please leave a comment below if you decide to start working on this!!
Anyhow, first part is to add a python decorator @kwargs_to_strings(R="sequence")
after @use_alias
and before def surface
here:
Lines 18 to 20 in cdcdf70
Make sure that you add a line to import kwargs_to_string
near the top of gridding.py
file, or it won't work!
What the decorator does is to convert a list like [245, 255, 20, 30]
into a slash separated string like "245/255/20/30"
, the code for it which is found at here.
Secondly, you'll need to edit the unit test file to capture this change at https://github.com/GenericMappingTools/pygmt/edit/master/pygmt/tests/test_surface.py. Change all the lines mentioning region="245/255/20/30"
to region=[245, 255, 20, 30]
.
That should be the bulk of it! Feel free to ask for help in the comments below if you encounter any issues, and good luck!
System information
- Operating system: Linux
- Python installation (Anaconda, system, ETS): Miniconda
- Version of GMT: 6.0.0rc4
- Version of Python: 3.7
- Version of this package: cdcdf70
- If using conda, paste the output of
conda list
below:
output of conda list
# Name Version Build Channel _libgcc_mutex 0.1 main alabaster 0.7.12 py_0 conda-forge apipkg 1.5 pypi_0 pypi appdirs 1.4.3 py_1 conda-forge asn1crypto 1.2.0 py37_0 conda-forge astroid 2.3.2 py37_0 conda-forge atk 2.32.0 haf93ef1_0 conda-forge atomicwrites 1.3.0 py_0 conda-forge attrs 19.3.0 py_0 conda-forge babel 2.7.0 py_0 conda-forge backcall 0.1.0 py_0 conda-forge black 19.3b0 py_0 conda-forge bleach 3.1.0 py_0 conda-forge boost-cpp 1.70.0 h8e57a91_2 conda-forge bzip2 1.0.8 h516909a_1 conda-forge ca-certificates 2019.9.11 hecc5488_0 conda-forge cairo 1.16.0 hfb77d84_1002 conda-forge certifi 2019.9.11 py37_0 conda-forge cffi 1.13.0 py37h8022711_0 conda-forge cfitsio 3.470 hb60a0a2_2 conda-forge cftime 1.0.3.4 py37hd352d35_1001 conda-forge chardet 3.0.4 py37_1003 conda-forge chrpath 0.16 h14c3975_1001 conda-forge click 7.0 py_0 conda-forge coverage 4.5.4 py37h516909a_0 conda-forge cryptography 2.7 py37h72c5cf5_0 conda-forge curl 7.65.3 hf8cf82a_0 conda-forge cycler 0.10.0 py_1 conda-forge dbus 1.13.6 he372182_0 conda-forge dcw-gmt 1.1.4 1001 conda-forge decorator 4.4.0 py_0 conda-forge defusedxml 0.6.0 py_0 conda-forge docutils 0.15.2 py37_0 conda-forge entrypoints 0.3 py37_1000 conda-forge execnet 1.7.1 pypi_0 pypi expat 2.2.5 he1b5a44_1004 conda-forge ffmpeg 4.2 h167e202_0 conda-forge fftw 3.3.8 nompi_h7f3a6c3_1109 conda-forge flake8 3.7.8 py37_1 conda-forge fontconfig 2.13.1 h86ecdb6_1001 conda-forge freetype 2.10.0 he983fc9_1 conda-forge freexl 1.0.5 h14c3975_1002 conda-forge fribidi 1.0.5 h516909a_1002 conda-forge gdal 3.0.1 py37hbb6b9fb_9 conda-forge gdk-pixbuf 2.36.12 h7a26e22_1003 conda-forge geos 3.7.2 he1b5a44_2 conda-forge geotiff 1.5.1 hfa9ff18_4 conda-forge gettext 0.19.8.1 hc5be6a0_1002 conda-forge ghostscript 9.22 hf484d3e_1001 conda-forge giflib 5.1.7 h516909a_1 conda-forge glib 2.58.3 h6f030ca_1002 conda-forge gmp 6.1.2 hf484d3e_1000 conda-forge gmt 6.0.0rc4 hbdec4b4_1 conda-forge/label/dev gnuplot 5.2.7 h0fb2448_3 conda-forge gnutls 3.6.5 hd3a4fd2_1002 conda-forge gobject-introspection 1.58.2 py37h5503ade_1002 conda-forge graphicsmagick 1.3.33 h40aeb3c_0 conda-forge graphite2 1.3.13 hf484d3e_1000 conda-forge gshhg-gmt 2.3.7 1002 conda-forge gst-plugins-base 1.14.5 h0935bb2_0 conda-forge gstreamer 1.14.5 h36ae1b5_0 conda-forge gtk2 2.24.32 h586f36d_1 conda-forge harfbuzz 2.4.0 h9f30f68_3 conda-forge hdf4 4.2.13 h9a582f1_1002 conda-forge hdf5 1.10.5 nompi_h3c11f04_1103 conda-forge icu 64.2 he1b5a44_1 conda-forge idna 2.8 py37_1000 conda-forge imagesize 1.1.0 py_0 conda-forge importlib_metadata 0.23 py37_0 conda-forge ipykernel 5.1.2 py37h5ca1d4c_0 conda-forge ipython 7.8.0 py37h5ca1d4c_0 conda-forge ipython_genutils 0.2.0 py_1 conda-forge ipywidgets 7.5.1 py_0 conda-forge isort 4.3.21 py37_0 conda-forge jedi 0.15.1 py37_0 conda-forge jinja2 2.10.3 py_0 conda-forge jpeg 9c h14c3975_1001 conda-forge json-c 0.13.1 h14c3975_1001 conda-forge jsonschema 3.1.1 py37_0 conda-forge jupyter 1.0.0 py_2 conda-forge jupyter_client 5.3.3 py37_1 conda-forge jupyter_console 6.0.0 py_0 conda-forge jupyter_core 4.5.0 py_0 conda-forge kealib 1.4.10 h58c409b_1005 conda-forge kiwisolver 1.1.0 py37hc9558a2_0 conda-forge krb5 1.16.3 h05b26f9_1001 conda-forge lame 3.100 h14c3975_1001 conda-forge lazy-object-proxy 1.4.2 py37h516909a_0 conda-forge libblas 3.8.0 14_openblas conda-forge libcblas 3.8.0 14_openblas conda-forge libclang 9.0.0 hc9558a2_1 conda-forge libcurl 7.65.3 hda55be3_0 conda-forge libdap4 3.20.4 hd3bb157_0 conda-forge libedit 3.1.20170329 hf8c457e_1001 conda-forge libffi 3.2.1 he1b5a44_1006 conda-forge libgcc-ng 9.1.0 hdf63c60_0 libgd 2.2.5 h82918c6_1006 conda-forge libgdal 3.0.1 hcf75f94_9 conda-forge libgfortran-ng 7.3.0 hdf63c60_2 conda-forge libiconv 1.15 h516909a_1005 conda-forge libkml 1.3.0 h4fcabce_1010 conda-forge liblapack 3.8.0 14_openblas conda-forge libllvm9 9.0.0 hc9558a2_2 conda-forge libnetcdf 4.6.2 h303dfb8_1003 conda-forge libopenblas 0.3.7 h6e990d7_2 conda-forge libpng 1.6.37 hed695b0_0 conda-forge libpq 11.5 hd9ab2ff_1 conda-forge libsodium 1.0.17 h516909a_0 conda-forge libspatialite 4.3.0a hcf5492f_1031 conda-forge libssh2 1.8.2 h22169c7_2 conda-forge libstdcxx-ng 9.1.0 hdf63c60_0 libtiff 4.0.10 h57b8799_1003 conda-forge libuuid 2.32.1 h14c3975_1000 conda-forge libwebp 1.0.2 h99fbfcb_2 conda-forge libxcb 1.13 h14c3975_1002 conda-forge libxkbcommon 0.9.0 hebb1f50_0 conda-forge libxml2 2.9.9 hee79883_5 conda-forge lz4-c 1.8.3 he1b5a44_1001 conda-forge markupsafe 1.1.1 py37h14c3975_0 conda-forge matplotlib 3.1.1 py37_1 conda-forge matplotlib-base 3.1.1 py37he7580a8_1 conda-forge mccabe 0.6.1 py_1 conda-forge mistune 0.8.4 py37h14c3975_1000 conda-forge more-itertools 7.2.0 py_0 conda-forge nbconvert 5.6.0 py37_1 conda-forge nbformat 4.4.0 py_1 conda-forge nbsphinx 0.4.3 py_0 conda-forge ncurses 6.1 hf484d3e_1002 conda-forge netcdf4 1.5.1.2 py37h73a1b54_1 conda-forge nettle 3.4.1 h1bed415_1002 conda-forge nose 1.3.7 py37_1002 conda-forge notebook 6.0.1 py37_0 conda-forge nspr 4.20 hf484d3e_1000 conda-forge nss 3.47 he751ad9_0 conda-forge numpy 1.17.2 py37h95a1406_0 conda-forge numpydoc 0.9.1 py_0 conda-forge olefile 0.46 py_0 conda-forge openh264 1.8.0 hdbcaa40_1000 conda-forge openjpeg 2.3.1 h21c5421_1 conda-forge openssl 1.1.1c h516909a_0 conda-forge packaging 19.2 py_0 conda-forge pandas 0.25.2 py37hb3f55d8_0 conda-forge pandoc 2.7.3 0 conda-forge pandocfilters 1.4.2 py_1 conda-forge pango 1.42.4 ha030887_1 conda-forge parso 0.5.1 py_0 conda-forge pcre 8.43 he1b5a44_0 conda-forge pexpect 4.7.0 py37_0 conda-forge pickleshare 0.7.5 py37_1000 conda-forge pillow 6.2.0 py37h6b7be26_0 conda-forge pip 19.3.1 py37_0 conda-forge pixman 0.38.0 h516909a_1003 conda-forge pluggy 0.13.0 py37_0 conda-forge poppler 0.67.0 ha967d66_7 conda-forge poppler-data 0.4.9 1 conda-forge postgresql 11.5 hc63931a_1 conda-forge proj 6.2.0 hc80f0dc_1 conda-forge prometheus_client 0.7.1 py_0 conda-forge prompt_toolkit 2.0.10 py_0 conda-forge pthread-stubs 0.4 h14c3975_1001 conda-forge ptyprocess 0.6.0 py_1001 conda-forge py 1.8.0 py_0 conda-forge pycodestyle 2.5.0 py_0 conda-forge pycparser 2.19 py37_1 conda-forge pyflakes 2.1.1 py_0 conda-forge pygments 2.4.2 py_0 conda-forge pylint 2.4.3 py37_0 conda-forge pyopenssl 19.0.0 py37_0 conda-forge pyparsing 2.4.2 py_0 conda-forge pyqt 5.12.3 py37hcca6a23_0 conda-forge pyqt5-sip 4.19.18 pypi_0 pypi pyqtwebengine 5.12.1 pypi_0 pypi pyrsistent 0.15.4 py37h516909a_0 conda-forge pysocks 1.7.1 py37_0 conda-forge pytest 5.2.1 py37_0 conda-forge pytest-cov 2.8.1 py_0 conda-forge pytest-forked 1.0.2 pypi_0 pypi pytest-mpl 0.10 py_0 conda-forge python 3.7.3 h33d41f4_1 conda-forge python-dateutil 2.8.0 py_0 conda-forge pytz 2019.3 py_0 conda-forge pyzmq 18.1.0 py37h1768529_0 conda-forge qt 5.12.5 h0c104cb_0 conda-forge qtconsole 4.5.5 py_0 conda-forge readline 8.0 hf8c457e_0 conda-forge requests 2.22.0 py37_1 conda-forge send2trash 1.5.0 py_0 conda-forge setuptools 41.4.0 py37_0 conda-forge six 1.12.0 py37_1000 conda-forge snowballstemmer 2.0.0 py_0 conda-forge sphinx 1.8.5 py37_0 conda-forge sphinx-gallery 0.4.0 py37_0 conda-forge sphinx_rtd_theme 0.4.3 py_0 conda-forge sphinxcontrib-websupport 1.1.2 py_0 conda-forge sqlite 3.30.1 hcee41ef_0 conda-forge tbb 2018.0.5 h2d50403_0 conda-forge terminado 0.8.2 py37_0 conda-forge testpath 0.4.2 py_1001 conda-forge tiledb 1.6.2 h69c774e_1 conda-forge tk 8.6.9 hed695b0_1003 conda-forge toml 0.10.0 py_0 conda-forge tornado 6.0.3 py37h516909a_0 conda-forge traitlets 4.3.3 py37_0 conda-forge tzcode 2019a h516909a_1002 conda-forge urllib3 1.25.6 py37_0 conda-forge wcwidth 0.1.7 py_1 conda-forge webencodings 0.5.1 py_1 conda-forge wheel 0.33.6 py37_0 conda-forge widgetsnbextension 3.5.1 py37_0 conda-forge wrapt 1.11.2 py37h516909a_0 conda-forge x264 1!152.20180806 h14c3975_0 conda-forge xarray 0.14.0 py_0 conda-forge xerces-c 3.2.2 h8412b87_1004 conda-forge xorg-kbproto 1.0.7 h14c3975_1002 conda-forge xorg-libice 1.0.10 h516909a_0 conda-forge xorg-libsm 1.2.3 h84519dc_1000 conda-forge xorg-libx11 1.6.9 h516909a_0 conda-forge xorg-libxau 1.0.9 h14c3975_0 conda-forge xorg-libxdmcp 1.1.3 h516909a_0 conda-forge xorg-libxext 1.3.4 h516909a_0 conda-forge xorg-libxrender 0.9.10 h516909a_1002 conda-forge xorg-libxt 1.2.0 h516909a_0 conda-forge xorg-renderproto 0.11.1 h14c3975_1002 conda-forge xorg-xextproto 7.3.0 h14c3975_1002 conda-forge xorg-xproto 7.0.31 h14c3975_1007 conda-forge xz 5.2.4 h14c3975_1001 conda-forge zeromq 4.3.2 he1b5a44_2 conda-forge zipp 0.6.0 py_0 conda-forge zlib 1.2.11 h516909a_1006 conda-forge zstd 1.4.0 h3b9ef0a_0 conda-forge