Figure.clip_xxx: A consistent API for clipping by polygon, land, water, solar, and mask
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- backend-api-design
Research direction
Start by reviewing the proof of concept in #3878 and POC PR #4703, then compare the four API designs against the listed GMT clipping modes. Done means the project settles on an API and defines coverage for polygon, land, water, mask, DCW, and solar clipping.
Written by the indexing model from the issue text.
Description
GMT supports several related clipping operations:
| Description | Activate | Deactivate | User input |
|---|---|---|---|
| Clip land areas | coast -G |
coast -Q |
No |
| Clip water areas | coast -S |
coast -Q |
No |
| Clip by polygon | clip |
clip -C |
(x, y) coordinates |
| Clip by mask | mask |
mask -C |
(x, y) coordinates |
| Clip by a country or region code | coast -E+c |
coast -Q |
No |
| Clip by solar terminators | solar -G |
clip -C |
No |
For every mode, subsequent plotting commands are clipped until the path is explicitly ended. This stateful behavior makes clipping a natural fit for context managers.
Possible API designs:
-
Low-level begin/end methods
fig.begin_clip(data=polygon) fig.plot(...) fig.end_clip()This closely mirrors GMT, but requires users to end clipping explicitly and can leave a clip path active after an exception.
-
A single context-manager method with a mode
with fig.clip(mode="polygon", data=polygon): ... with fig.clip(mode="land"): ... with fig.clip(mode="dcw", code="US"): ...This has a compact API, but each mode wraps a different GMT module and accepts different parameters. Documenting and validating this mixed argument set could become complicated.
-
A
clipnamespacewith fig.clip.polygon(data=polygon): ... with fig.clip.land(): ...This groups related functionality neatly, but may be challenging to expose and document correctly. See the proof of concept in #3878.
-
Explicit context-manager methods
with fig.clip_polygon(data=polygon): ... with fig.clip_land(): ... with fig.clip_water(): ...This one is much easier to document that option 4. A POC PR is at #4703.
I feel option 4 is the best API design.
- Dominant language
- Python
- Stars
- 882
- Forks
- 261
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 29
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from GenericMappingTools/pygmt
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
GenericMappingTools/pygmt#5014 · 1 comment ·
Maintainers usually reply within 1 day
-
discussions documentation
Difficulty 1/5 Under an hour Newbie friendliness 78/100
GenericMappingTools/pygmt#4992 ·
Maintainers usually reply within 1 day
-
Improve reporting the GMT version via "pygmt.show_versions()"Possibly taken @yvonnefroehlich claimed this 114 days ago. Openmaintenance
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
GenericMappingTools/pygmt#4812 · 4 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
GenericMappingTools/pygmt#4765 ·
Maintainers usually reply within 1 day
-
Add an AGENTS.md filePossibly taken A pull request linked to this issue is open or already merged. Opendiscussions
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
GenericMappingTools/pygmt#4677 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
All issues in GenericMappingTools/pygmt
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TigreGotico/orthography2ipa#2950 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Unstructured-IO/unstructured#4876 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
openfoodfacts/openfoodfacts-python#579 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
fairagro/m4.2_sql_to_arc#388 ·
Maintainers usually reply within 1 day