netcdf SST data does not appear on the map when I try to make a polar stereographic map in matplotlib.pyplot and Catroopy

20 Views Asked by At

I have NetCDF Sea Surface temperature data. I have made a subset of data where the latitude range is between 55oN to 90oN. When I use the code with PlateCarree projection it works fine but when I use polar stereographic projection, the data does not appear on the map. Here is my code:

# Necessary packages:
import cartopy.crs as ccrs           # for projection
import cartopy.feature as cfeature   # for projection
import matplotlib.pyplot as plt      # for plotting
import warnings
warnings.filterwarnings("ignore")

# Extract latitude, Longitude and SST data:
lat = ds_subset['lat'].values
lon = ds_subset['lon'].values
sst_data = ds_subset['SST'].values


# Create meshgrid for latitude and longitude:
lon_grid, lat_grid = np.meshgrid(lon, lat)


# Set mpping crs to Cartopy's north polar seterographic:
crs_epsg = ccrs.NorthPolarStereo(central_longitude = -15)
#crs_epsg = ccrs.PlateCarree()

# Set Figure Size:
fig = plt.figure(figsize = [10, 10])

# Set the map projection and associated boundries:
ax = plt.axes(projection = crs_epsg)
ax.set_extent([-3850000.0, 3750000.0, -5350000, 5850000.0],crs_epsg)
ax.coastlines()
ax.add_feature(cfeature.LAND)


# set the data crs
cs = ax.pcolormesh(lon_grid, lat_grid, sst_data[5,:,:],
                  cmap=plt.cm.jet, transform=crs_epsg, vmin=np.min(sst_data), vmax=np.max(sst_data), shading='auto')
fig.colorbar(cs, ax=ax, location='bottom', shrink =0.8)
ax.set_title('SST')

plt.show()

I have tried using lat and lon instead of grid values. It works with PlateCarre but not with polarStereographic again. What can be the issue?

0

There are 0 best solutions below