Forums

Issue plotting WRF Data with Lambert Projection -Coastlines overlay not being displayed on top of data

I recently started using python via jupyter on windows to plot netCDF data. However I am having issues plotting output data I have from a WRF run that uses Lambert Conformal projection. I cannot seem to get the coastlines to be overlayed and lined up with the data plot i.e. the coastlines overlay either does not show up at all or is slightly offset from the data.Could this be due to the Lambert projection of the data causing issues?

Here is the link to access the WRF output nc file I was using: https://drive.google.com/file/d/1s-0RLcaqIG0OoFEZtsE6_1xsE9B0DM1_/view?usp=sharing

This is the output i get when running the code: https://drive.google.com/file/d/1Jb2_jvmgNyTp-CVIuC-LvAEZ43RwRtJu/view?usp=sharing

I also don't seem to be able to use 'Dataset' on the WRF output files I am using, eg. ncfile = Dataset("wrfout_d01_2016-10-07_00_00_00"). This normally results in the following error:

61 lons = wrfnc.variables[lonvar][:] 663 # Need to check all times --> 664 for i in py3range(lats.shape[-3]): 665 start_idxs = [0] * len(lats.shape) # PyNIO does not support ndim 666 start_idxs[-3] = i IndexError: tuple index out of range

I am quite new to all this so apologies if these are silly questions.

Below is the code I have tried to use. Any assistance in resolving this errors would be appreciated.

from netCDF4 import Dataset
import xarray as xr
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

ds = xr.open_dataset("output_mean.nc")
temp2 = ds.T2[0,:,:]
temp2

fig = plt.figure(figsize=(5, 5))
ax1 = plt.axes(projection=ccrs.LambertConformal())
ax1.coastlines()

temp2.plot(ax=ax1, cmap='jet', transform=ccrs.LambertConformal())

ax1.set_extent([-140, -75, 17, 45], crs=ccrs.PlateCarree())

ax1.coastlines()

plt.show()

This is a forum for PythonAnywhere support, so it's unlikely that you will get much help here. A more focussed forum may be a better bet for you.