def test_station_layout_names(): 'Test getting station layout names' layout = StationPlotLayout() layout.add_barb('u', 'v') layout.add_text('E', 'stid') layout.add_value('W', 'temp') layout.add_symbol('C', 'cover', lambda x: x) assert sorted(layout.names()) == ['cover', 'stid', 'temp', 'u', 'v']
def test_station_layout_replace(): 'Test that layout locations are replaced' layout = StationPlotLayout() layout.add_text('E', 'temperature') layout.add_value('E', 'dewpoint') assert 'E' in layout assert layout['E'][0] is StationPlotLayout.PlotTypes.value assert layout['E'][1] == 'dewpoint'
def test_layout_str(): """Test layout string representation.""" layout = StationPlotLayout() layout.add_barb('u', 'v') layout.add_text('E', 'stid') layout.add_value('W', 'temp') layout.add_symbol('C', 'cover', lambda x: x) assert str(layout) == ('{C: (symbol, cover, ...), E: (text, stid, ...), ' 'W: (value, temp, ...), barb: (barb, (\'u\', \'v\'), ...)}')
def test_layout_str(): 'Test layout string representation' layout = StationPlotLayout() layout.add_barb('u', 'v') layout.add_text('E', 'stid') layout.add_value('W', 'temp') layout.add_symbol('C', 'cover', lambda x: x) assert str(layout) == ('{C: (symbol, cover, ...), E: (text, stid, ...), ' 'W: (value, temp, ...), barb: (barb, (\'u\', \'v\'), ...)}')
def test_station_layout_replace(): """Test that layout locations are replaced.""" layout = StationPlotLayout() layout.add_text('E', 'temperature') layout.add_value('E', 'dewpoint') assert 'E' in layout assert layout['E'][0] is StationPlotLayout.PlotTypes.value assert layout['E'][1] == 'dewpoint'
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_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_station_layout_names(): """Test getting station layout names.""" layout = StationPlotLayout() layout.add_barb('u', 'v') layout.add_text('E', 'stid') layout.add_value('W', 'temp') layout.add_symbol('C', 'cover', lambda x: x) assert sorted(layout.names()) == ['cover', 'stid', 'temp', 'u', 'v']
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