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

Wrap clip #1779

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Wrap clip #1779

wants to merge 12 commits into from

Conversation

maxrjones
Copy link
Member

Description of proposed changes

Following a couple comments at #1706, this PR suggests an implementation of GMT's clip module using a with statement/context manager. It uses the same style as the subplot and inset methods of pygmt.Figure. Here is an example:

import pygmt
x = [1, 1, 2, 3, 3, 1]
y = [1, 2, 2, 3, 1, 1]
fig = pygmt.Figure()
# Plot the original data
fig.plot(data="@tut_data.txt", style="c0.5c", color="red", frame=True, region=[0, 6, 0, 6], projection="X5c")
# Setup a clip path
with fig.clip(x=x, y=y, pen="1p"):
    # Plot the data with a green fill
    fig.plot(data="@tut_data.txt", style="c0.5c", color="green")
fig.show()

clip

To do:

  • Decide whether this function should remain as a context manager
  • Decide how to organize this function relative to other clipping modules in GMT
  • Add more robust tests (e.g., multiple clipping paths, geodataframe input, ogrfile, polygon clip + coast clip)

Fixes #

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 wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@maxrjones maxrjones added the feature Brand new feature label Mar 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2022

Summary of changed images

This is an auto-generated report of images that have changed on the DVC remote

Status Path
added pygmt/tests/baseline/test_clip.png

Image diff(s)

Added images

  • pygmt/tests/baseline/test_clip.png

Modified images

Path Old New

Report last updated at commit 5f67979

@seisman
Copy link
Member

seisman commented Mar 2, 2022

The -C documentation says

Remember to supply -X and -Y settings if you have moved since the clip started.

How can we revert the -X and -Y setttings in a context manager?

@maxrjones
Copy link
Member Author

The -C documentation says

Remember to supply -X and -Y settings if you have moved since the clip started.

How can we revert the -X and -Y setttings in a context manager?

Possibly we could use GMT_Get_Common on entry and exit to keep track of the -X -Y settings. But I wonder if in modern mode GMT could keep track of these settings internally. I will open an issue in the GMT repository for discussion.

@maxrjones
Copy link
Member Author

How can we revert the -X and -Y setttings in a context manager?

We might not have to do anything about this. See discussion/confusion at GenericMappingTools/gmt#6406.

@seisman seisman added this to the 0.7.0 milestone Mar 15, 2022
@maxrjones
Copy link
Member Author

The -C documentation says "Remember to supply -X and -Y settings if you have moved since the clip started." How can we revert the -X and -Y setttings in a context manager?

Paul and I could not figure out what this is in reference to and suspect it relates to obsolete behavior, so I removed this statement from the docs in GenericMappingTools/gmt#6450.

@seisman seisman modified the milestones: 0.7.0, 0.8.0 Jun 23, 2022
@seisman seisman modified the milestones: 0.8.0, 0.9.0 Dec 11, 2022
@maxrjones maxrjones marked this pull request as draft March 14, 2023 23:50
@maxrjones maxrjones mentioned this pull request Mar 14, 2023
36 tasks
@seisman seisman removed this from the 0.9.0 milestone Mar 19, 2023
@seisman seisman added this to the 0.10.0 milestone Mar 19, 2023
@weiji14 weiji14 removed this from the 0.10.0 milestone Aug 24, 2023
@seisman seisman added this to the 0.12.0 milestone Dec 11, 2023
@seisman seisman removed this from the 0.12.0 milestone Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Brand new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants