def test_stationlayout_api(): """Test the StationPlot API.""" setup_font() with style.context(test_style): fig = make_figure(figsize=(9, 9)) # testing data x = np.array([1, 5]) y = np.array([2, 4]) data = dict() data['temp'] = np.array([32., 212.]) * units.degF data['u'] = np.array([2, 0]) * units.knots data['v'] = np.array([0, 5]) * units.knots data['stid'] = ['KDEN', 'KSHV'] data['cover'] = [3, 8] # Set up the layout layout = StationPlotLayout() layout.add_barb('u', 'v', units='knots') layout.add_value('NW', 'temp', fmt='0.1f', units=units.degC, color='darkred') layout.add_symbol('C', 'cover', sky_cover, color='magenta') layout.add_text((0, 2), 'stid', color='darkgrey') layout.add_value('NE', 'dewpt', color='green') # This should be ignored # Make the plot sp = StationPlot(fig.add_subplot(1, 1, 1), x, y, fontsize=12) layout.plot(sp, data) sp.ax.set_xlim(0, 6) sp.ax.set_ylim(0, 6) hide_tick_labels(sp.ax) return fig
def test_nws_layout(): """Test metpy's NWS layout for station plots.""" setup_font() with style.context(test_style): fig = make_figure(figsize=(3, 3)) # testing data x = np.array([1]) y = np.array([2]) data = dict() data['air_temperature'] = np.array([77]) * units.degF data['dew_point_temperature'] = np.array([71]) * units.degF data['air_pressure_at_sea_level'] = np.array([999.8]) * units('mbar') data['eastward_wind'] = np.array([15.]) * units.knots data['northward_wind'] = np.array([15.]) * units.knots data['cloud_coverage'] = [7] data['present_weather'] = [80] data['high_cloud_type'] = [1] data['medium_cloud_type'] = [3] data['low_cloud_type'] = [2] data['visibility_in_air'] = np.array([5.]) * units.mile data['tendency_of_air_pressure'] = np.array([-0.3]) * units('mbar') data['tendency_of_air_pressure_symbol'] = [8] # Make the plot sp = StationPlot(fig.add_subplot(1, 1, 1), x, y, fontsize=12, spacing=16) nws_layout.plot(sp, data) sp.ax.set_xlim(0, 3) sp.ax.set_ylim(0, 3) hide_tick_labels(sp.ax) return fig
def test_simple_layout(): """Test metpy's simple layout for station plots.""" setup_font() with style.context(test_style): fig = make_figure(figsize=(9, 9)) # testing data x = np.array([1, 5]) y = np.array([2, 4]) data = dict() data['air_temperature'] = np.array([32., 212.]) * units.degF data['dew_point_temperature'] = np.array([28., 80.]) * units.degF data['air_pressure_at_sea_level'] = np.array([29.92, 28.00]) * units.inHg data['eastward_wind'] = np.array([2, 0]) * units.knots data['northward_wind'] = np.array([0, 5]) * units.knots data['cloud_coverage'] = [3, 8] data['present_weather'] = [65, 75] data['unused'] = [1, 2] # Make the plot sp = StationPlot(fig.add_subplot(1, 1, 1), x, y, fontsize=12) simple_layout.plot(sp, data) sp.ax.set_xlim(0, 6) sp.ax.set_ylim(0, 6) hide_tick_labels(sp.ax) return fig
def test_station_plot_replace(): 'Test that locations are properly replaced' setup_font() fig = make_figure(figsize=(3, 3)) # testing data x = np.array([1]) y = np.array([1]) # Make the plot sp = StationPlot(fig.add_subplot(1, 1, 1), x, y, fontsize=16) sp.plot_barb([20], [0]) sp.plot_barb([5], [0]) sp.plot_parameter('NW', [10.5], color='red') sp.plot_parameter('NW', [20], color='blue') sp.ax.set_xlim(-3, 3) sp.ax.set_ylim(-3, 3) hide_tick_labels(sp.ax) return fig
def test_stationplot_api(): 'Test the StationPlot api' setup_font() fig = make_figure(figsize=(9, 9)) # testing data x = np.array([1, 5]) y = np.array([2, 4]) # Make the plot sp = StationPlot(fig.add_subplot(1, 1, 1), x, y, fontsize=16) sp.plot_barb([20, 0], [0, -50]) sp.plot_text('E', ['KOKC', 'ICT'], color='blue') sp.plot_parameter('NW', [10.5, 15], color='red') sp.plot_symbol('S', [5, 7], high_clouds, color='green') sp.ax.set_xlim(0, 6) sp.ax.set_ylim(0, 6) hide_tick_labels(sp.ax) return fig
def test_station_layout_odd_data(): """Test more corner cases with data passed in.""" setup_font() fig = make_figure(figsize=(9, 9)) # Set up test layout layout = StationPlotLayout() layout.add_barb('u', 'v') layout.add_value('W', 'temperature', units='degF') # Now only use data without wind and no units data = dict(temperature=[25.]) # Make the plot sp = StationPlot(fig.add_subplot(1, 1, 1), [1], [2], fontsize=12) layout.plot(sp, data) assert True