GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
747 stars 216 forks source link

fig.coast() with just dcw kwarg fails #903

Closed liamtoney closed 3 years ago

liamtoney commented 3 years ago

Description of the problem

Using fig.coast(dcw=...) fails, asking for additional kwargs. I have to add another kwarg, like water='white', to get things to plot. I believe that dcw alone should be enough.

Full code that generated the error

import pygmt

fig = pygmt.Figure()
fig.coast(region='US', projection='S232.7435/90/8i', frame=['af', 'EWSn'], dcw='US+gred')
fig.show()

Expected output

out

Full error message

---------------------------------------------------------------------------
GMTInvalidInput                           Traceback (most recent call last)
<ipython-input-10-bd3570a700d7> in <module>
      2 
      3 fig = pygmt.Figure()
----> 4 fig.coast(region='US', projection='S232.7435/90/8i', frame=['af', 'EWSn'], dcw='US+gred')
      5 fig.show()

/opt/miniconda3/envs/roses/lib/python3.7/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
    279                 if alias in kwargs:
    280                     kwargs[arg] = kwargs.pop(alias)
--> 281             return module_func(*args, **kwargs)
    282 
    283         new_module.aliases = aliases

/opt/miniconda3/envs/roses/lib/python3.7/site-packages/pygmt/helpers/decorators.py in new_module(*args, **kwargs)
    423                         kwargs[arg] = separators[fmt].join(f"{item}" for item in value)
    424             # Execute the original function and return its output
--> 425             return module_func(*args, **kwargs)
    426 
    427         return new_module

/opt/miniconda3/envs/roses/lib/python3.7/site-packages/pygmt/src/coast.py in coast(self, **kwargs)
    191         raise GMTInvalidInput(
    192             """At least one of the following arguments must be specified:
--> 193             lakes, land, water, rivers, borders, Q, or shorelines"""
    194         )
    195     with Session() as lib:

GMTInvalidInput: At least one of the following arguments must be specified:
            lakes, land, water, rivers, borders, Q, or shorelines

System information

Please paste the output of python -c "import pygmt; pygmt.show_versions()":

PyGMT information:
  version: v0.0.0
System information:
  python: 3.7.9 | packaged by conda-forge | (default, Feb 13 2021, 19:53:10)  [Clang 11.0.1 ]
  executable: /opt/miniconda3/envs/roses/bin/python
  machine: Darwin-20.3.0-x86_64-i386-64bit
Dependency information:
  numpy: 1.16.2
  pandas: 1.1.5
  xarray: 0.15.0
  netCDF4: 1.5.3
  packaging: 20.9
  ghostscript: 9.53.3
  gmt: 6.1.1
GMT library information:
  binary dir: /opt/miniconda3/envs/roses/bin
  cores: 8
  grid layout: rows
  library path: /opt/miniconda3/envs/roses/lib/libgmt.dylib
  padding: 2
  plugin dir: /opt/miniconda3/envs/roses/lib/gmt/plugins
  share dir: /opt/miniconda3/envs/roses/share/gmt
  version: 6.1.1
willschlitzer commented 3 years ago

Will GMT coast just accept the E argument with no other land/water colors set? The GMTInvalidError input was likely put in to prevent an error coming back from the GMT API.

seisman commented 3 years ago

gmt coast -EUS+gred -pdf map works, so confirm it as a bug.

willschlitzer commented 3 years ago

Sounds good. Looks like we need to just do a quick update to the error raising.

Less than 12 hours since v0.3.0 released and we're already coming up for changes in v0.3.1! 😂

seisman commented 3 years ago

Running gmt coast without extra options gives the following error messages:

$ gmt coast -pdf map
coast [ERROR]: Must specify -R option
coast [ERROR]: Must specify at least one of -C, -G, -S, -I, -N, -Q and -W

It doesn't mention -E, so also a tiny upstream bug.

seisman commented 3 years ago

Reopen the issue because this is also an upstream bug (if I understand it correctly).

The fix is similar and easy. Just need to update these lines in GMT's pscoast.c: https://github.com/GenericMappingTools/gmt/blob/19db042fc2f1bf09136029bd801ea73f0b6dd30d/src/pscoast.c#L606-L609

@willschlitzer Do you want to try it?

willschlitzer commented 3 years ago

@seisman Just submitted the PR

joa-quim commented 3 years ago

Curious. I went see what I do in Julia and your command jut works (gives the map you show). But probably because under the hood I always add a -Da if option -D is not used. Though this option has no effect with DCW countries

julia> coast(region="US", projection="S232.7435/90/8i", dcw="US+gred", show=1, Vd=2)
"pscoast  -EUS+gred -Vq -RUS -JS232.7435/90/8i -Baf -BWSen -Da -P -K > C:\\TMP\\GMTjl_tmp.ps"