Grid point to surface

Hi Guys. I used grid command to make some grid point to show my data on a map.
df = pygmt.blockmean(data=data, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing)

convert to grid

#grid = pygmt.surface(data=df, region=region, spacing=spacing)
grid = pygmt.xyz2grd(data=df, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing, registration=“p”)

Grid spacing is 01s which I guess is the lowest but the problem is that the data are shown as a point. I want to hame a uniform surface. How can I have the surface not point from grdimage?

fig.grdimage(
grid=grid,
region=[-123, -121, 37, 38.5],
#transparency=50,
cmap=True,
nan_transparent=True,
frame=[“af”, “+tMean earthquake depth inside each block”],

cmap=“batlow”,

)

Please, format your code with triple back-ticks.

Screen Shot 2022-11-08 at 9.57.08 AM [quote=“mtabbakhha, post:1, topic:3422”]
cmap=“batlow”,
[/quote]

it still doesn’t work. I just see the points not any surface. You see the point? I wanted to be a continues not just the points.

Thanks so much for your help.

I meant, format your code when you post it.

df = pygmt.blockmean(data=data, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing)
# convert to grid
#grid = pygmt.surface(data=df, region=region, spacing=spacing)
grid = pygmt.xyz2grd(data=df, region=[-122.8, -121.4, 37.0, 38.4], spacing=spacing, registration="p")

Grid spacing is 01s which I guess is the lowest but the problem is that the data are shown as a point. I want to hame a uniform surface. How can I have the surface not point from grdimage?

fig.grdimage(
    grid=grid,
    region=[-123, -121, 37, 38.5],
#transparency=50,
    cmap=True,
    nan_transparent=True,
    frame=["af", "+tMean earthquake depth inside each block"],
  #  cmap="batlow",
)

But regarding your question, sorry, I don’t PyGMT.

Hello @mtabbakhha,

I am wondering whether pygmt.blockmean is the appropriate function for your purpose.
It sounds like you want to interpolate your data somehow? But I am not sure, as your posted figure already contains a grid with color-coding for the elevation in your study region. Plotting another color-coded grid on top appears not reasonable to me. Maybe you can explain in more detail what you want to accomplish :wink:.

pygmt.blockmean calculates the mean within blocks/bins with side lengths defined by the spacing parameter. For details, please have a look at the documentation pygmt.blockmean — PyGMT.
If you select a small value for the spacing parameter (“01s”), the blocks plotted by pygmt.Figure.grdimage are also small.

Please see a PyGMT gallery example for orientation, in which I modified the spacing parameter:

# source: https://www.pygmt.org/latest/gallery/histograms/blockm.html#sphx-glr-gallery-histograms-blockm-py
# last access: 2022/11/09
# modified: only left plot, changed spacing parameter

import pygmt

# Load sample data
data = pygmt.datasets.load_sample_data(name="japan_quakes")
# Select only needed columns
data = data[["longitude", "latitude", "depth_km"]]

# Set the region for the plot
region = [130, 152.5, 32.5, 52.5]
# Define spacing in x and y direction (150 by 150 minute blocks)
spacing = "100m"  # <<< original "150m"

fig = pygmt.Figure()

# Calculate mean depth in km from all events within 150x150 minute
# bins using blockmean
df = pygmt.blockmean(data=data, region=region, spacing=spacing)
# convert to grid
grd = pygmt.xyz2grd(data=df, region=region, spacing=spacing)

fig.grdimage(
    grid=grd,
    region=region,
    frame=["af", "+tMean earthquake depth inside each block"],
    cmap="batlow",
)
# plot slightly transparent landmasses on top
fig.coast(land="darkgray", transparency=40)
# plot original data points
fig.plot(
    x=data.longitude,
    y=data.latitude,
    style="c0.3c",
    color="white",
    pen="1p,black",
)
fig.colorbar(frame="x+lkm")

fig.show()
#fig.savefig(fname="block_mean_spacing_" + spacing + ".png")

output figures:
original: spacing=“150m”

modified: spacing=“100m”

modified: spacing=“50m”