Station Plot
Make a station plot, complete with sky cover and weather symbols.
The station plot itself is pretty straightforward, but there is a bit of code to perform the data-wrangling (hopefully that situation will improve in the future). Certainly, if you have existing point data in a format you can work with trivially, the station plot will be simple.
import cartopy.crs as ccrs import cartopy.feature as cfeature import matplotlib.pyplot as plt
from metpy.calc import reduce_point_density from metpy.cbook import get_test_data from metpy.io import metar from metpy.plots import add_metpy_logo, current_weather, sky_cover, StationPlot
The setup
First read in the data. We use the metar reader because it simplifies a lot of tasks, like dealing with separating text and assembling a pandas dataframe https://thredds.ucar.edu/thredds/catalog/noaaport/text/metar/catalog.html
data = metar.parse_metar_file(get_test_data('metar_20190701_1200.txt', as_file_obj=False))
data = data.dropna(how='any', subset=['wind_direction', 'wind_speed'])
This sample data has way too many stations to plot all of them. The number of stations plotted will be reduced using reduce_point_density.
proj = ccrs.LambertConformal(central_longitude=-95, central_latitude=35, standard_parallels=[35])
point_locs = proj.transform_points(ccrs.PlateCarree(), data['longitude'].values, data['latitude'].values) data = data[reduce_point_density(point_locs, 300000.)]
The payoff
plt.rcParams['savefig.dpi'] = 255
fig = plt.figure(figsize=(20, 10)) add_metpy_logo(fig, 1100, 300, size='large') ax = fig.add_subplot(1, 1, 1, projection=proj)
ax.add_feature(cfeature.LAND) ax.add_feature(cfeature.OCEAN) ax.add_feature(cfeature.LAKES) ax.add_feature(cfeature.COASTLINE) ax.add_feature(cfeature.STATES) ax.add_feature(cfeature.BORDERS)
ax.set_extent((-118, -73, 23, 50))
stationplot = StationPlot(ax, data['longitude'].values, data['latitude'].values, clip_on=True, transform=ccrs.PlateCarree(), fontsize=12)
stationplot.plot_parameter('NW', data['air_temperature'].values, color='red') stationplot.plot_parameter('SW', data['dew_point_temperature'].values, color='darkgreen')
stationplot.plot_parameter('NE', data['air_pressure_at_sea_level'].values, formatter=lambda v: format(10 * v, '.0f')[-3:])
stationplot.plot_symbol('C', data['cloud_coverage'].values, sky_cover)
stationplot.plot_symbol('W', data['current_wx1_symbol'].values, current_weather)
stationplot.plot_barb(data['eastward_wind'].values, data['northward_wind'].values)
stationplot.plot_text((2, 0), data['station_id'].values)
plt.show()
Station Plot
Total running time of the script: ( 0 minutes 20.711 seconds)
Download Python source code: Station_Plot.py
Download Jupyter notebook: Station_Plot.ipynb
Gallery generated by Sphinx-Gallery