pygmt: The "incols" (-i) parameter doesn't works for vector input correctly
Description of the problem
Using the incols parameter does not allow to swap columns (seems like the parameter is ignored at all so far). I believe it’s an upstream GMT bug. This was discovered in https://github.com/GenericMappingTools/pygmt/pull/1303#discussion_r642213335.
Full code that generated the error
import pygmt
import numpy as np
# generate sample data
region = [10, 70, -5, 10]
x, y = np.meshgrid(
np.linspace(region[0], region[1]), np.linspace(region[2], region[3])
)
x = x.flatten()
y = y.flatten()
z = (x - 0.5 * (region[0] + region[1])) ** 2 + 4 * y ** 2
z = np.exp(-z / 10 ** 2 * np.log(2))
# generate dataframe
data = np.array([x, y, z]).T
# correct figure
fig1 = pygmt.Figure()
fig1.contour(data=data,
projection="X10c",
frame="a",
pen=True)
fig1.show()
# generate second dataframe, switch x and y from here onwards to simulate
# different column order
data = np.array([y, x, z]).T
# wrong figure
fig2 = pygmt.Figure()
fig2.contour(data=data,
incols=[1, 0, 2], # use incols to assign column order
projection="X10c",
frame="a",
pen=True)
fig2.show()
Full output
| fig1: expected | fig2: actual (wrong) |
|---|---|
![]() |
![]() |
System information
Please paste the output of python -c "import pygmt; pygmt.show_versions()":
PyGMT information:
version: v0.2.2.dev80+g132757a
System information:
python: 3.6.12 | packaged by conda-forge | (default, Dec 9 2020, 00:36:02) [GCC 9.3.0]
executable: /home/mgrund/anaconda3/envs/pygmt/bin/python
machine: Linux-4.4.0-19041-Microsoft-x86_64-with-debian-buster-sid
Dependency information:
numpy: 1.19.4
pandas: 1.1.5
xarray: 0.16.2
netCDF4: 1.5.6
packaging: 20.8
ghostscript: 9.53.3
gmt: 6.2.0rc1
GMT library information:
binary dir: /home/mgrund/anaconda3/envs/pygmt/bin
cores: 8
grid layout: rows
library path: /home/mgrund/anaconda3/envs/pygmt/lib/libgmt.so
padding: 2
plugin dir: /home/mgrund/anaconda3/envs/pygmt/lib/gmt/plugins
share dir: /home/mgrund/anaconda3/envs/pygmt/share/gmt
version: 6.2.0rc1
@PaulWessel @meghanrjones could you please check if you can debug it?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 24 (24 by maintainers)
Commits related to this issue
- Ensure external vector is scaled via -I on rec-by-rec parsing See https://github.com/GenericMappingTools/pygmt/issues/1313 for details. This PR ensures the record-by-record reading of external vecto... — committed to GenericMappingTools/gmt by PaulWessel 3 years ago
- Ensure external vectors are scaled via -i (#5291) * Ensure external vector is scaled via -I on rec-by-rec parsing See https://github.com/GenericMappingTools/pygmt/issues/1313 for details. This PR... — committed to GenericMappingTools/gmt by PaulWessel 3 years ago
- Figure.contour: Remove parameter "columns", use "incols" instead Also modified the original deprecation test into a regression test for https://github.com/GenericMappingTools/pygmt/issues/1313 — committed to GenericMappingTools/pygmt by weiji14 2 years ago


I think to use
incolsPaul would need to build from this branch (https://github.com/GenericMappingTools/pygmt/pull/1303) and that the master branch usescolumnsas the alias name. Rather than checkout out that branch and building, you could just changeincols=tocolumns=ori=.Yes, I think this is an upstream bug, but it only affects wrappers, that’s why the GMT tests pass.
Here is a modified example based on @michaelgrund’s example:
As you can see, passing “YXZ” data and using
incols=[1, 0, 2]works well for file input, but not for an array input.