Grdclip vs clip

My goal is to plot a subsurface contour of a variable in the ocean, as well as the land and the continental shelf/slope area at that water depth. In order to do that, I would need to clip my data along the isobath of 500m, for example.

Below is my code to grdclip both the land and my variable contour. Unfortunately, it is not working. I only see the plot for the contour, and can not really see the land part properly (no land contour color). Is that because grdclip does not really cut a hole on the image as clip does? What would be the solution then? Many thanks!

# grdclip the land:
    G_land = grdclip("@earth_relief_10m", low=[-500 NaN]);
    coast(region=(180,320,10,80));
    grdimage!(G_land, shade=true, cmap=:geo, coast=true);

# grdclip the variable contour:
    E_grid = mat2grid(Array(transpose(E)), x=lon, y=lat); # E is a grid data set of the global ocean:

    mask1 = grdclip(E_grid, low=[-500 1], high=[-500 NaN]);
    G2_clip = G2 * mask1;

    cpt = makecpt(cmap=:jet, range=(0,5,0.02));
    grdimage!(G2_clip, coast=true, color=cpt, frame=(annot=45,grid=45,title="test"), show=1);

grdclip doesn’t do anything to images. As its name indicates it only operates on grids.
When we have programs/scripts that don’t work we have to debug them. For short scripts the best technique is to verify the result after each step. Doing this shows that the first call to grdimage produces a correct result, so grdclip is working fine.

Isn’t this indicating that you are mixing meters and kilometers?

mask1 = grdclip(E_grid, low=[-500 1], high=[-500 NaN]);
cpt = makecpt(cmap=:jet, range=(0,5,0.02));
grdimage!(G2_clip, coast=true, color=cpt, frame=(annot=45,grid=45,title="test"), show=1);

Thanks for the reply, Joaquim.

I was able to fix the issue with some help from a friend. I turns out that the reason it was not plotting properly was because I did not use the -Q argument, or nan_alpha=true for GMT.jl. What that argument does is to make the part of the image where the grid value is NaN transparent.

Now, it has been working beautifully.

Nice :slight_smile: