def test_skewt_gridspec(): 'Test using SkewT on a sub-plot' with style.context(test_style): fig = make_figure(figsize=(9, 9)) gs = GridSpec(1, 2) hide_tick_labels(SkewT(fig, subplot=gs[0, 1]).ax) return fig
def test_stationlayout_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]) 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_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_simple_layout(): 'Test metpy\'s simple layout for station plots' setup_font() 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_nws_layout(): 'Test metpy\'s NWS layout for station plots' setup_font() 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_hodograph_units(): 'Test passing unit-ed quantities to Hodograph' fig = make_figure(figsize=(9, 9)) ax = fig.add_subplot(1, 1, 1) hodo = Hodograph(ax) u = np.arange(10) * units.kt v = np.arange(10) * units.kt hodo.plot(u, v) hodo.plot_colormapped(u, v, np.sqrt(u * u + v * v), cmap='Greys') hide_tick_labels(ax) return fig
def test_hodograph_api(): 'Basic test of Hodograph API' fig = make_figure(figsize=(9, 9)) ax = fig.add_subplot(1, 1, 1) hodo = Hodograph(ax, component_range=60) hodo.add_grid(increment=5, color='k') hodo.plot([1, 10], [1, 10], color='red') hodo.plot_colormapped(np.array([1, 3, 5, 10]), np.array([2, 4, 6, 11]), np.array([0.1, 0.3, 0.5, 0.9]), cmap='Greys') hide_tick_labels(ax) return fig
def test_hodograph_api(): 'Basic test of Hodograph API' with style.context(test_style): fig = make_figure(figsize=(9, 9)) ax = fig.add_subplot(1, 1, 1) hodo = Hodograph(ax, component_range=60) hodo.add_grid(increment=5, color='k') hodo.plot([1, 10], [1, 10], color='red') hodo.plot_colormapped(np.array([1, 3, 5, 10]), np.array([2, 4, 6, 11]), np.array([0.1, 0.3, 0.5, 0.9]), cmap='Greys') hide_tick_labels(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
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
def test_scattertext_patheffect_empty(): """Test scattertext with empty strings and PathEffects (Issue #245).""" strings = ['abc', '', 'def'] x, y = np.arange(6).reshape(2, 3) fig = make_figure() ax = fig.add_subplot(1, 1, 1) ax.scattertext(x, y, strings, color='white', path_effects=[ mpatheffects.withStroke(linewidth=1, foreground='black') ]) # Need to trigger a render with TemporaryFile('wb') as fobj: fig.savefig(fobj)
def test_skewt_api(): 'Test the SkewT api' fig = make_figure(figsize=(9, 9)) skew = SkewT(fig) # Plot the data using normal plotting functions, in this case using # log scaling in Y, as dictated by the typical meteorological plot p = np.linspace(1000, 100, 10) t = np.linspace(20, -20, 10) u = np.linspace(-10, 10, 10) skew.plot(p, t, 'r') skew.plot_barbs(p, u, u) # Add the relevant special lines skew.plot_dry_adiabats() skew.plot_moist_adiabats() skew.plot_mixing_lines() hide_tick_labels(skew.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_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_skewt_subplot(): 'Test using SkewT on a sub-plot' with style.context(test_style): fig = make_figure(figsize=(9, 9)) hide_tick_labels(SkewT(fig, subplot=(2, 2, 1)).ax) return fig