Highlighting a single ll_to_xy grid point + showing all grid points on WRF map

Hi everyone,

I’m trying to highlight a single grid point on a WRF map. Plotting by lat/lon works fine:

ax = plt.axes(projection=cart_proj)
ax.plot(lon_value,
lat_value,
color="red",
marker="o",
markersize=3,
transform=ccrs.PlateCarree()
)


But when I convert the same location using:

xy_mmh = ll_to_xy(wrf_in, lat_value, lon_value)

I’m not sure how to plot only this grid‑index point on the map.
What is the correct way to display the point returned by ll_to_xy?


My second question:
How can I show all grid points on the map (e.g., a surface plot of terrain height with the full grid overlaid)?

There’s no need for full scripts — just the specific commands for each task would be greatly appreciated.

Hopefully my questions are clear — I’d appreciate answers to these two parts separately.


Best regards,
 
Hi everyone,

I’m trying to highlight a single grid point on a WRF map. Plotting by lat/lon works fine:

ax = plt.axes(projection=cart_proj)
ax.plot(lon_value,
lat_value,
color="red",
marker="o",
markersize=3,
transform=ccrs.PlateCarree()
)


But when I convert the same location using:

xy_mmh = ll_to_xy(wrf_in, lat_value, lon_value)

I’m not sure how to plot only this grid‑index point on the map.
What is the correct way to display the point returned by ll_to_xy?


My second question:
How can I show all grid points on the map (e.g., a surface plot of terrain height with the full grid overlaid)?

There’s no need for full scripts — just the specific commands for each task would be greatly appreciated.

Hopefully my questions are clear — I’d appreciate answers to these two parts separately.


Best regards,

Hi Ehsan,

Yes, `ll_to_xy()` returns the nearest WRF grid indices as `(x, y)`. I use this approach in several of my own WRF-Python scripts.

For your first question, I would use the returned indices to get the latitude and longitude of the actual WRF grid point, then plot that location:
Python:
xy = wrf.ll_to_xy(wrf_in, lat_value, lon_value)

x = int(xy[0])
y = int(xy[1])

ter = wrf.getvar(wrf_in, "ter")
lats, lons = wrf.latlon_coords(ter)

grid_lat = wrf.to_np(lats[y, x])
grid_lon = wrf.to_np(lons[y, x])

ax.plot(
    grid_lon,
    grid_lat,
    marker="o",
    color="red",
    markersize=5,
    transform=ccrs.PlateCarree()
)
The important distinction is that `x` and `y` are array indices, not longitude and latitude coordinates. Your original `ax.plot(lon_value, lat_value, ...)` plots the requested location, while the code above plots the actual WRF grid point selected by `ll_to_xy()`.

For your second question, you can overlay all WRF mass-grid points using the latitude and longitude arrays:
Python:
ax.scatter(
    wrf.to_np(lons),
    wrf.to_np(lats),
    s=2,
    color="black",
    transform=ccrs.PlateCarree()
)
For a large domain, I would probably subsample the grid so the map does not become too crowded:
Code:
skip = 5

ax.scatter(
    wrf.to_np(lons)[::skip, ::skip],
    wrf.to_np(lats)[::skip, ::skip],
    s=2,
    color="black",
    transform=ccrs.PlateCarree()
)
If you are working with a moving nest, also make sure to pass the appropriate `timeidx` to `ll_to_xy()`, since the same latitude and longitude can map to a different grid index as the domain moves.

Hope this helps.
 
Back
Top