cartopy: `Spilhaus` projection not working correctly when plotting raster data
I’m trying to plot raster data over a Spilhaus projection but I’m getting some artefacts
This code is MWE to produce the image
import xarray as xr
import fsspec
import pandas as pd
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import numpy as np
import time
from aiohttp.client_exceptions import ServerDisconnectedError
date = pd.Timestamp("2024-01-01")
url = f"https://www.star.nesdis.noaa.gov/pub/socd/mecb/crw/data/5km/v3.1_op/nc/v1.0/daily/sst/{date.year}/coraltemp_v3.1_{date.strftime('%Y%m%d')}.nc"
while True:
try:
file = fsspec.open_local(
f"simplecache::{url}", simplecache={"cache_storage": "/tmp/"}
)
ds = xr.open_dataset(file, engine="netcdf4").squeeze()
break
except ServerDisconnectedError:
time.sleep(0.5)
# Set up the figure and the projection for the plot
fig, ax = plt.subplots(
figsize=(10, 10),
subplot_kw={
"projection": ccrs.Spilhaus()
},
)
ax.add_feature(
cfeature.LAND.with_scale("110m"), edgecolor="black" , linewidth=0.25, zorder=2
)
lon2d, lat2d = np.meshgrid(ds["lon"].values, ds["lat"].values)
ax.pcolormesh(
lon2d,
lat2d,
ds["analysed_sst"].values,
transform=ccrs.PlateCarree(),
)
when trying with imshow I get this instead, I guess the data is not properly rotated (but no artefacts).
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 16 (10 by maintainers)
Sorry, sloppy choice of words on my part. The data isn’t masked within Cartopy because we need to transform everything to see where it ends up in the map projection and enable setting smaller/larger limits. So what you are doing to speed things up makes sense when that is possible.
To clarify what I meant though, in pcolormesh we do “mask” some cells that cross the dateline of projections and wrap around the left to right side of the map. Those show up as these streaks that you see here and we try to hide them and instead draw those point with a
pcolor()call for just those “masked” cells. That is something to try here, do apcolor()call instead ofpcolormesh()and see if that fixes those streaks or not.