You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pygmt.grdfill: Interpolate across holes in a grid #3768
This option has different long names across the GMT ecosystem.
PyGMT: aliased to no_data. [Need to note that common option -d is aliased to nodata]
GMT.jl: aliased to nodata or hole
GMT: aliased to hole or hole_value
This option "sets the node value used to identify a point as a member of a hole [Default is NaN].". Personally, I feel hole is a better name than no_data.
-A
This option specifie the hole-filling algorithm to use. Currently it's aliased to mode and can be used like (please refer to the docs for the actual meanings of these arguments):
mode="c100"
mode="ganother_grid.nc"
mode="n0.5"
mode="s0.3"
The syntax is not Pythonic, since we have to specify numbers in a string, and for the mode="ganother_grid.nc" case, the "another grid" must be a string, and can't accept a xarray.DataArray object.
In my mind, there are two possible ways to make it more Pythonic:
Two parameters mode and value.
mode specifies the filling method. Valid values are "constant", "grid", "neighbor", "spline"
value has different meanings for different filling methods, e.g., value=100, value="another_grid.nc", value=0.5, value=0.3
Four exclusive parameters
constantfill=100
gridfill="anonter_grid.nc" or gridfill=xrgrid
neighborfill=True or neighborfill=0.5: 0.5 is the search radius, and True means the default radius
splinefill=True/splinefill=0.3: 0.3 is the spline tension, True means no tension.
The -L option is still not implemented yet. Now let's focus on this option.
Behaviors in GMT
-L
Just list the rectangular subregions west east south north of each hole. No grid fill takes place and -G is ignored. Optionally, append p to instead write closed polygons for all subregions.
So, there are two possible usage for this option:
-L: output the bounds (in the form of (w, e, s, n)) of the holes
-Lp: output the closed polygons (rectangles) based on the bounds (not the exact polygons of holes)
Need to note that -Lp write the coordinates of based on the bounds, not the exact outlines of holes:
gmt begin map
gmt grdimage @earth_relief_20m_holes.grd -Baf
gmt grdfill @earth_relief_20m_holes.grd -Lp | gmt plot -W1p
gmt end show
The PyGMT syntax
For -L, the outputs are bounds in the form of (w, e, s, n), which fit well with a 2-D numpy array.
For -Lp, the outputs are multi-segment files, which PyGMT doesn't support well yet.
Since the closed polygons can be created from the bounds, I think -Lp has a low priority and we don't even have to implement it.
Then, we need to decide the parameter name for -L. GMT and GMT.jl alias -L to list, but list is a bad name in the Python world. So, what about dump or inquire (xref: #896)?
Activity
seisman commentedon Mar 11, 2025
Here are my thoughts on finalizing the wrapper.
-NThis option has different long names across the GMT ecosystem.
no_data. [Need to note that common option-dis aliased tonodata]nodataorholeholeorhole_valueThis option "sets the node value used to identify a point as a member of a hole [Default is NaN].". Personally, I feel
holeis a better name thanno_data.-AThis option specifie the hole-filling algorithm to use. Currently it's aliased to
modeand can be used like (please refer to the docs for the actual meanings of these arguments):mode="c100"mode="ganother_grid.nc"mode="n0.5"mode="s0.3"The syntax is not Pythonic, since we have to specify numbers in a string, and for the
mode="ganother_grid.nc"case, the "another grid" must be a string, and can't accept a xarray.DataArray object.In my mind, there are two possible ways to make it more Pythonic:
Two parameters
modeandvalue.modespecifies the filling method. Valid values are"constant","grid","neighbor","spline"valuehas different meanings for different filling methods, e.g.,value=100,value="another_grid.nc",value=0.5,value=0.3Four exclusive parameters
constantfill=100gridfill="anonter_grid.nc"orgridfill=xrgridneighborfill=Trueorneighborfill=0.5: 0.5 is the search radius, and True means the default radiussplinefill=True/splinefill=0.3: 0.3 is the spline tension, True means no tension.I prefer the 2nd option.
What do others think?
seisman commentedon Mar 27, 2025
The
-Loption is still not implemented yet. Now let's focus on this option.Behaviors in GMT
So, there are two possible usage for this option:
-L: output the bounds (in the form of (w, e, s, n)) of the holes-Lp: output the closed polygons (rectangles) based on the bounds (not the exact polygons of holes)Here are examples to understand the outputs:
Need to note that
-Lpwrite the coordinates of based on the bounds, not the exact outlines of holes:The PyGMT syntax
-L, the outputs are bounds in the form of (w, e, s, n), which fit well with a 2-D numpy array.-Lp, the outputs are multi-segment files, which PyGMT doesn't support well yet.Since the closed polygons can be created from the bounds, I think
-Lphas a low priority and we don't even have to implement it.Then, we need to decide the parameter name for
-L. GMT and GMT.jl alias-Ltolist, butlistis a bad name in the Python world. So, what aboutdumporinquire(xref: #896)?[-]pygmt.grdfill: Interpolate across holes in a grid[/-][+]grdfill: Interpolate across holes in a grid[/+][-]grdfill: Interpolate across holes in a grid[/-][+]pygmt.grdfill: Interpolate across holes in a grid[/+]