Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sequence_space converter in kwargs_to_string #325

Merged
merged 4 commits into from
Oct 10, 2019

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Sep 7, 2019

Description of proposed changes

Introduce new 'sequence_space' converter for transforming a Python list or tuple into a space separated string. Useful in cases for e.g. when multiple file inputs can be passed into some module.

For example:

@kwargs_to_string(files="sequence_space")
def module(*args, **kwargs):
    ...

>>> module(files=["data1.txt", "data2.txt"]
{'files': 'data1.txt data2.txt'}

Fixes #322

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Introduce new 'sequence_space' converter for transforming a Python list or tuple into a space separated string. Useful in cases for e.g. when multiple file inputs can be passed into some module. Also added a doctest example into the kwargs_to_string function.
pygmt/helpers/decorators.py Outdated Show resolved Hide resolved
@weiji14
Copy link
Member Author

weiji14 commented Oct 9, 2019

While working on grdview in #330, I've also been thinking about how to handle the -Ggrd_r -Ggrd_g -Ggrd_b case. The way I've implemented it in https://github.com/GenericMappingTools/pygmt/pull/330/files#diff-d304eb8534d09d80d3ec5bd2ba1f26b8R330-R336 actually allows drapegrid="red.nc -Ggreen.nc -Gblue.nc" since I didn't wrap it in a dummy_context but that's more a hack than an elegant solution...

Might open another PR on this so that users can do drapegrid=["red.nc", "green.nc", "blue.nc"] and the script will parse it to -Gred.nc -Ggreen.nc -Gblue.nc.

@seisman
Copy link
Member

seisman commented Oct 9, 2019

It should already works, as we already can have multiple -B options.

import pygmt
fig = pygmt.Figure()
fig.basemap(region="0/10/0/10", projection="X10c", frame=["xaf", "yaf", "+tTitle"])
fig.show()

@weiji14
Copy link
Member Author

weiji14 commented Oct 9, 2019

Wow, I never knew that worked! Must have missed that in one of the tutorials 😱

Copy link
Member

@seisman seisman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Feel free to merge it @weiji14

@weiji14 weiji14 merged commit c024489 into GenericMappingTools:master Oct 10, 2019
@weiji14 weiji14 deleted the decorator/sequence_space branch October 10, 2019 01:10
weiji14 referenced this pull request in weiji14/pygmt Oct 25, 2019
Using the sequence_space processor in #325 to allow for passing in a list of textfiles to be plotted! Problem with that `text` would consider a numpy matrix as a list to be parsed, so the code was updated to fix that.

Unit tests and docstrings updated. Strangely enough, the 'projection'/'-J' argument doesn't seem to be required anymore? Also regenerated baseline plots to use their rightful name...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to handle one or more file inputs
2 participants