def test_declarative_barb_earth_relative(): """Test making a contour plot.""" data = xr.open_dataset(get_test_data('NAM_test.nc', as_file_obj=False)) contour = ContourPlot() contour.data = data contour.field = 'Geopotential_height_isobaric' contour.level = 300 * units.hPa contour.linecolor = 'red' contour.linestyle = '-' contour.linewidth = 2 contour.contours = range(0, 20000, 120) barb = BarbPlot() barb.data = data barb.level = 300 * units.hPa barb.time = datetime(2016, 10, 31, 12) barb.field = ['u-component_of_wind_isobaric', 'v-component_of_wind_isobaric'] barb.skip = (5, 5) barb.color = 'black' barb.barblength = 6.5 barb.earth_relative = False panel = MapPanel() panel.area = (-124, -72, 20, 53) panel.projection = 'lcc' panel.layers = ['coastline', 'borders', 'usstates'] panel.plots = [contour, barb] pc = PanelContainer() pc.size = (8, 8) pc.panels = [panel] pc.draw() return pc.figure
def test_copy(): """Test that the copy method works for all classes in `declarative.py`.""" # Copies of plot objects objects = [ImagePlot(), ContourPlot(), FilledContourPlot(), BarbPlot(), PlotObs(), PlotGeometry()] for obj in objects: obj.time = datetime.now() copied_obj = obj.copy() assert obj is not copied_obj assert obj.time == copied_obj.time # Copies of MapPanel and PanelContainer obj = MapPanel() obj.title = 'Sample Text' copied_obj = obj.copy() assert obj is not copied_obj assert obj.title == copied_obj.title obj = PanelContainer() obj.size = (10, 10) copied_obj = obj.copy() assert obj is not copied_obj assert obj.size == copied_obj.size # Copies of plots in MapPanels should not point to same location in memory obj = MapPanel() obj.plots = [PlotObs(), PlotGeometry(), BarbPlot(), FilledContourPlot(), ContourPlot(), ImagePlot()] copied_obj = obj.copy() for i in range(len(obj.plots)): assert obj.plots[i] is not copied_obj.plots[i]
def test_declarative_barb_scale(): """Test making a contour plot.""" data = xr.open_dataset(get_test_data('GFS_test.nc', as_file_obj=False)) barb = BarbPlot() barb.data = data barb.level = 300 * units.hPa barb.field = ['u-component_of_wind_isobaric', 'v-component_of_wind_isobaric'] barb.skip = (3, 3) barb.earth_relative = False barb.scale = 2 panel = MapPanel() panel.area = 'us' panel.projection = 'data' panel.layers = ['coastline', 'borders', 'usstates'] panel.plots = [barb] pc = PanelContainer() pc.size = (8, 8) pc.panels = [panel] pc.draw() barb.level = 700 * units.hPa return pc.figure
def test_declarative_barb_options(): """Test making a contour plot.""" data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False)) barb = BarbPlot() barb.data = data barb.level = 300 * units.hPa barb.field = ['u_wind', 'v_wind'] barb.skip = (10, 10) barb.color = 'blue' barb.pivot = 'tip' barb.barblength = 6.5 panel = MapPanel() panel.area = 'us' panel.projection = 'data' panel.layers = ['coastline', 'borders', 'usstates'] panel.plots = [barb] pc = PanelContainer() pc.size = (8, 8) pc.panels = [panel] pc.draw() return pc.figure
def test_ndim_error_vector(cfeature): """Make sure we get a useful error when the field is not set.""" data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False)) barbs = BarbPlot() barbs.data = data barbs.field = ['u_wind', 'v_wind'] barbs.level = None panel = MapPanel() panel.area = (-110, -60, 25, 55) panel.projection = 'lcc' panel.plots = [barbs] pc = PanelContainer() pc.panel = panel with pytest.raises(ValueError): pc.draw()
def test_no_field_error_barbs(): """Make sure we get a useful error when the field is not set.""" data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False)) barbs = BarbPlot() barbs.data = data barbs.level = 700 * units.hPa with pytest.raises(TraitError): barbs.draw()