Skip to content

pygmt.grdmask: Create mask grid from polygons or point coverage(required arguments)#4463

Open
Chuan1937 wants to merge 74 commits intomainfrom
grdmask1
Open

pygmt.grdmask: Create mask grid from polygons or point coverage(required arguments)#4463
Chuan1937 wants to merge 74 commits intomainfrom
grdmask1

Conversation

@Chuan1937
Copy link
Member

Replace #4428

Chuan1937 and others added 30 commits February 25, 2026 20:55
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
@Chuan1937 Chuan1937 self-assigned this Mar 21, 2026
@Chuan1937 Chuan1937 added the feature Brand new feature label Mar 21, 2026
@Chuan1937 Chuan1937 added this to the 0.19.0 milestone Mar 21, 2026
@Chuan1937 Chuan1937 linked an issue Mar 21, 2026 that may be closed by this pull request
26 tasks
@Chuan1937 Chuan1937 moved this to Ongoing maintenance in PyGMT: Wrapping GMT modules Mar 21, 2026
Chuan1937 and others added 7 commits March 22, 2026 18:40
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Co-authored-by: Dongdong Tian <seisman.info@gmail.com>
Chuan1937 and others added 3 commits March 22, 2026 19:38
edge, description="edge", reason=f"edge={edge!r} requires inside={edge!r}."
)

if inside in _inside_modes and edge in _inside_modes and inside != edge:
Copy link
Member

Choose a reason for hiding this comment

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

I feel this check is the same as the one above. Am I misunderstanding something?

Copy link
Member Author

Choose a reason for hiding this comment

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

You understood correctly; the code you're writing now does contain duplicates. It's likely a mistake made while trying to solve formatting issues. The real intention was to check that when inside is a character pattern (like z or id), edge must be None or exactly the same as inside, preventing users from sending arbitrary numbers to edge.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've corrected it

Copy link
Member

Choose a reason for hiding this comment

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

Actually, I meant if we should delete this check.

Copy link
Member Author

Choose a reason for hiding this comment

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

No. The first protection is that edge has a special value ("z"/"id"), but inside doesn't match.
The second protection is that inside has a special value, but edge provides a value that doesn't match.

Copy link
Member

Choose a reason for hiding this comment

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

Why not just check both cases like below:

if (inside in _inside_modes or edge in _inside_modes) and inside != edge:
    ...

Copy link
Member Author

Choose a reason for hiding this comment

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

But it will rejects a valid case: inside set to z/id with edge unset (None).

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me think of a simpler and clearer way to express it.

def _alias_option_N( # noqa: N802
outside: float | None = None,
edge: float | Literal["z", "id"] | None = None,
inside: float | Literal["z", "id"] | None = None,
Copy link
Member

Choose a reason for hiding this comment

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

It's almost done, but we still miss one parameter:

use -Np to use a running number as polygon ID; optionally append start of the sequence [0].

Not sure what the most suitable name for it is yet. Maybe id_start?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Brand new feature

Projects

Status: Ongoing maintenance

Development

Successfully merging this pull request may close these issues.

pygmt.grdmask: Create mask grid from polygons or point coverage

2 participants