# Grdmask

**URL:** <https://forum.generic-mapping-tools.org/t/grdmask/3905>\
**Category:** Q&A\
**Created:** [May 5, 2023, 4:02am UTC](https://forum.generic-mapping-tools.org/t/grdmask/3905 "2023-05-05T04:02:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dowchu](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@dowchu](https://forum.generic-mapping-tools.org/u/dowchu)\
**Post date:** [May 5, 2023, 4:02am UTC](https://forum.generic-mapping-tools.org/t/grdmask/3905/1 "2023-05-05T04:02:19Z")

</div>

In pygmt I am having problem with grdmask. When I run pygmt.grdmask, it says module not recognized. It appears grdmask is not available in pygmt; pygmt.grdlandmask is working but i need grdmask. Any help will be appreciated.

---

<div class="post-metadata">

**Author:** ![yvonnefroehlich](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/yvonnefroehlich/32/5064_2.png) [@yvonnefroehlich](https://forum.generic-mapping-tools.org/u/yvonnefroehlich)\
**Post date:** [May 5, 2023, 2:54pm UTC](https://forum.generic-mapping-tools.org/t/grdmask/3905/2 "2023-05-05T14:54:54Z")

</div>

Hello @dowchu,

welcome to the GMT forum 🙂.

So far, `grdmask` is unfortunately not wrapped in PyGMT. If you like, you can open an `New issue` with a feature request on GitHub at [Issues · GenericMappingTools/pygmt · GitHub](https://github.com/GenericMappingTools/pygmt/issues). Maybe someone has time to work on this.

In the meanwhile, you can try using [`pygmt.clib.Session`](https://www.pygmt.org/v0.9.0/api/generated/pygmt.clib.Session.html) and [`pygmt.clib.Session.call_module`](https://www.pygmt.org/v0.9.0/api/generated/pygmt.clib.Session.call_module.html). This allows you to use any GMT module within PyGMT.

I have no experience with `grdmask`, however I tried to rewrite the first example in the GMT documentation at [grdmask — GMT 6.7.0 documentation](https://docs.generic-mapping-tools.org/dev/grdmask.html#examples). Maybe this can serve as an orientation.

_Code example_:  
Please place the file `coastlines.txt` in your working directory:  
[coastlines.txt](https://forum.generic-mapping-tools.org/uploads/short-url/rPeBazQ9bb6Vdw1Db1mLbPGBxRm.txt) (57 Bytes)

```python
import pygmt as gmt
from pygmt.clib import Session

# Source: https://docs.generic-mapping-tools.org/dev/grdmask.html#examples
# Last access: 2023/05/05

# To set all nodes inside and on the polygon coastline_*.xy to 0,
# and outside points to 1, do
# gmt grdmask coastline_*.xy -R-60/-40/-40/-30 -I5m -N1/0/0 -Gland_mask.nc=nb -V

with Session() as lib:

    lib.call_module(
        "grdmask",
        "{} \
        -R-60/-40/-40/-30 \
        -I5m \
        -N1/0/0 \
        -Gland_mask.nc=nb" \
        .format("coastlines.txt")
    )

# Plot output grid via PyGMT
fig = gmt.Figure()

fig.grdimage(
    grid="land_mask.nc",
    projection="M10c",
    frame=True,
    cmap="vik",
)
       
fig.colorbar()
           
fig.show()
# fig.savefig(fname="grdmask_in_pygmt.png")

```

_Output figure_:

 ![grdmask_in_pygmt](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/c/cdcef3aae790a7bb57d057bfe167fcfdf1902785.png)

---

<div class="post-metadata">

**Author:** ![dowchu](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@dowchu](https://forum.generic-mapping-tools.org/u/dowchu)\
**Post date:** [May 5, 2023, 4:35pm UTC](https://forum.generic-mapping-tools.org/t/grdmask/3905/3 "2023-05-05T16:35:08Z")

</div>

Thank you…much appreciated
