Export and save a grid with pyGMT

Hi, I would like to know how can I save and export a grid I just created with pyGMT? in .grd or .nc. For example I created this mask grid and I want to export it from pyGMT and load in pyGMT and GMT.

mask = pygmt.grdlandmask(region=region, spacing="03m", maskvalues=[1, 0], resolution="f")



  • outgrid (str or None) – Name of the output netCDF grid file

Those are just convention extensions. They are not formats specifiers. The tradition in GMT is to use .grd (emphasizing that it is a grid) when saving a single layer and .nc for cubes (multi-layered). But even that is just a mild convention.

1 Like

Hello @Anagabrielamantilla,

You can utilize it in any GMT script, and if desired, manipulate this GRD file later with Python and Xarray to add attributes or change variable names. Occasionally, I harness the capabilities of GMT/PyGMT’s “surface” function to interpolate within a GRD file, subsequently treating it as a NetCDF file. This process poses no issue whatsoever.

thank you so much!