import matplotlib.pyplot as plt
import cartopy.crs as ccrs
from cartopy.feature import ShapelyFeature
from cartopy.io.shapereader import Reader
from cartopy.feature import NaturalEarthFeature,COLORS
from matplotlib.cm import get_cmap
from matplotlib.colors import from_levels_and_colors
import matplotlib.ticker as mticker
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
from netCDF4 import Dataset
from xarray import DataArray
from wrf import getvar, interplevel, vertcross, vinterp, ALL_TIMES, CoordPair, xy_to_ll,\
ll_to_xy, to_np, get_cartopy, latlon_coords, cartopy_xlim, cartopy_ylim
warnings.filterwarnings('ignore')
wrf_file = ["wrfout_d01_2020-03-01_00.nc",
"wrfout_d01_2021-03-01_00.nc",
"wrfout_d01_2022-03-01_00.nc"]
wrf_files = [os.path.abspath(os.path.join(wrf_dir,f)) for f in wrf_file]
if not os.path.exists(f):
raise ValueError("{} does not exist."
"check for typos or incorrect directory.".format(f))
def multiple_wrf_files():
file_path = single_wrf_file()
wrf_f = Dataset(file_path)
terrain = getvar(wrf_f, "ter", timeidx = 0)
cart_proj = get_cartopy(terrain)
lats, lons = latlon_coords(terrain)
extent = [70, 140, 10,60]
cart_proj = get_cartopy(terrain)
china = "/china-boundary/china-boundary.shp"
fig = plt.figure(figsize=(10,8))
geo_axes = plt.axes(projection=cart_proj)
cmap = cartopy.feature.ShapelyFeature(Reader(china).geometries(), crs=ccrs.PlateCarree(), edgecolor="r", facecolor="none")
geo_axes.add_feature(cmap, linewidth=1)
levels = np.arange(1, 8000, 500)
plt.contour(to_np(lons), to_np(lats), to_np(terrain),
levels=levels, colors="black", transform = ccrs.PlateCarree())
plt.contourf(to_np(lons), to_np(lats),
to_np(terrain), levels=levels,
transform=ccrs.PlateCarree(),
gl = geo_axes.gridlines(draw_labels = True, linestyle=":", crs=ccrs.PlateCarree(), linewidth=1, color="grey", x_inline=False, y_inline=False)
gl.xlocator = mticker.FixedLocator(np.arange(70,140,10))
gl.ylocator = mticker.FixedLocator(np.arange(10,60,10))
gl.xlabel_style ={"size":10, "color":"black"}
gl.ylabel_style ={"size":10, "color":"black"}
plt.colorbar(ax=geo_axes, shrink=0.58)

