Closed
Description
Description of the desired feature
In GMT, geographical coordinates can be given in floating points or many different geographical formats (e.g., 23:30:30E
), but PyGMT doesn't support these common geographical formats yet.
Here is a script to show what it looks like:
import pygmt
fig = pygmt.Figure()
fig.basemap(region=[-10, 10, -10, 10], projection='M10c', frame=True)
fig.plot(x=5.0, y=5.0, style='c0.5c', color='red')
fig.plot(x='3:30W', y='5:30W', style='c0.5c', color='blue')
fig.show()
Expected output:
Actual output
Traceback (most recent call last):
File "/Users/seisman/Gits/gmt/pygmt/pygmt/clib/session.py", line 728, in _check_dtype_and_dim
array = np.asarray(array, dtype=np.datetime64)
File "/Users/seisman/.anaconda/lib/python3.8/site-packages/numpy/core/_asarray.py", line 85, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: Error parsing datetime string "3:30W" at position 1
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "test.py", line 6, in <module>
fig.plot(x='3:30W', y='5:30W', style='c0.5c', color='blue')
File "/Users/seisman/Gits/gmt/pygmt/pygmt/helpers/decorators.py", line 270, in new_module
return module_func(*args, **kwargs)
File "/Users/seisman/Gits/gmt/pygmt/pygmt/helpers/decorators.py", line 411, in new_module
return module_func(*args, **kwargs)
File "/Users/seisman/Gits/gmt/pygmt/pygmt/base_plotting.py", line 720, in plot
with file_context as fname:
File "/Users/seisman/.anaconda/lib/python3.8/contextlib.py", line 113, in __enter__
return next(self.gen)
File "/Users/seisman/Gits/gmt/pygmt/pygmt/clib/session.py", line 1174, in virtualfile_from_vectors
self.put_vector(dataset, column=col, vector=array)
File "/Users/seisman/Gits/gmt/pygmt/pygmt/clib/session.py", line 778, in put_vector
gmt_type = self._check_dtype_and_dim(vector, ndim=1)
File "/Users/seisman/Gits/gmt/pygmt/pygmt/clib/session.py", line 730, in _check_dtype_and_dim
raise GMTInvalidInput(
pygmt.exceptions.GMTInvalidInput: Unsupported numpy data type '<class 'numpy.str_'>'.
Possible solutions
Here are two possible solutions in my mind:
- Currently,
GMT_Put_Vector
doesn't support string-like geographical coordinates. It could be a missing feature of the GMT API. With the new data type added, PyGMT still needs to determine if a string is a valid geographical coordinate before passing to GMT. - PyGMT may provide a utility function to convert these geographical formats into floating points data. In this case, we don't need the feature in the GMT API. However, if I understand it correctly, geographical coordinates like
3:30W
is still a little different from floating points-3.5
. For3:30W
, GMT knows the input is geographical coordinates and may have more automatic settings for geographical coordinates.
Are you willing to help implement and maintain this feature? Yes, but contributions are welcome.