Example #1
0
def test_projection_object():
    """Test that we can pass a custom map projection."""
    data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))

    contour = ContourPlot()
    contour.data = data
    contour.level = 700 * units.hPa
    contour.field = 'Temperature'

    panel = MapPanel()
    panel.area = (-110, -60, 25, 55)
    panel.projection = ccrs.Mercator()
    panel.layers = [cfeature.LAKES]
    panel.plots = [contour]

    pc = PanelContainer()
    pc.panel = panel
    pc.draw()

    return pc.figure
Example #2
0
def test_declarative_events():
    """Test that resetting traitlets properly propagates."""
    data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))

    contour = ContourPlot()
    contour.data = data
    contour.field = 'Temperature'
    contour.level = 850 * units.hPa
    contour.contours = 30
    contour.linewidth = 1
    contour.linecolor = 'red'

    img = ImagePlot()
    img.data = data
    img.field = 'v_wind'
    img.level = 700 * units.hPa
    img.colormap = 'hot'
    img.image_range = (3000, 5000)

    panel = MapPanel()
    panel.area = 'us'
    panel.proj = 'lcc'
    panel.layers = ['coastline', 'borders', 'states']
    panel.plots = [contour, img]

    pc = PanelContainer()
    pc.size = (8, 8)
    pc.panels = [panel]
    pc.draw()

    # Update some properties to make sure it regenerates the figure
    contour.linewidth = 2
    contour.linecolor = 'green'
    contour.level = 700 * units.hPa
    contour.field = 'Specific_humidity'
    img.field = 'Geopotential_height'
    img.colormap = 'plasma'

    return pc.figure
Example #3
0
def test_declarative_contour():
    """Test making a contour plot."""
    data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))

    contour = ContourPlot()
    contour.data = data
    contour.field = 'Temperature'
    contour.level = 700 * units.hPa
    contour.contours = 30
    contour.linewidth = 1
    contour.linecolor = 'red'

    panel = MapPanel()
    panel.area = 'us'
    panel.proj = 'lcc'
    panel.layers = ['coastline', 'borders', 'usstates']
    panel.plots = [contour]

    pc = PanelContainer()
    pc.size = (8, 8)
    pc.panels = [panel]
    pc.draw()

    return pc.figure
Example #4
0
    get_test_data('spc_day1otlk_20210317_1200_lyr.geojson'))

###########################
# Preview the data.
day1_outlook

###########################
# Plot the shapes from the 'geometry' column. Give the shapes their fill and stroke color by
# providing the 'fill' and 'stroke' columns. Use text from the 'LABEL' column as labels for the
# shapes.
geo = PlotGeometry()
geo.geometry = day1_outlook['geometry']
geo.fill = day1_outlook['fill']
geo.stroke = day1_outlook['stroke']
geo.labels = day1_outlook['LABEL']
geo.label_fontsize = 'large'

###########################
# Add the geometry plot to a panel and container.
panel = MapPanel()
panel.title = 'SPC Day 1 Convective Outlook (Valid 12z Mar 17 2021)'
panel.plots = [geo]
panel.area = [-120, -75, 25, 50]
panel.projection = 'lcc'
panel.layers = ['lakes', 'land', 'ocean', 'states', 'coastline', 'borders']

pc = PanelContainer()
pc.size = (12, 8)
pc.panels = [panel]
pc.show()
Example #5
0
narr = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))

###########################
# Create a contour plot of temperature
contour = ContourPlot()
contour.data = narr
contour.field = 'Temperature'
contour.level = 850 * units.hPa
contour.linecolor = 'red'
contour.contours = 15

###########################
# Create an image plot of Geopotential height
img = ImagePlot()
img.data = narr
img.field = 'Geopotential_height'
img.level = 850 * units.hPa

###########################
# Plot the data on a map
panel = MapPanel()
panel.area = 'us'
panel.layers = ['coastline', 'borders', 'states', 'rivers', 'ocean', 'land']
panel.title = 'NARR Example'
panel.plots = [contour, img]

pc = PanelContainer()
pc.size = (10, 8)
pc.panels = [panel]
pc.show()
Example #6
0
###########################
# Create a contour plot of temperature
contour = ContourPlot()
contour.data = narr
contour.field = 'Temperature'
contour.level = 850 * units.hPa
contour.linecolor = 'red'
contour.contours = 15

###########################
# Create an image plot of Geopotential height
img = ImagePlot()
img.data = narr
img.field = 'Geopotential_height'
img.level = 850 * units.hPa


###########################
# Plot the data on a map
panel = MapPanel()
panel.area = 'us'
panel.layers = ['coastline', 'borders', 'states', 'rivers', 'ocean', 'land']
panel.title = 'NARR Example'
panel.plots = [contour, img]

pc = PanelContainer()
pc.size = (10, 8)
pc.panels = [panel]
pc.show()
Example #7
0
def test_declarative_plot_geometry_polygons():
    """Test that `PlotGeometry` correctly plots MultiPolygon and Polygon objects."""
    from shapely.geometry import MultiPolygon, Polygon

    # MultiPolygons and Polygons to plot
    slgt_risk_polygon = MultiPolygon([
        Polygon([
            (-87.43, 41.86),
            (-91.13, 41.39),
            (-95.24, 40.99),
            (-97.47, 40.4),
            (-98.39, 41.38),
            (-96.54, 42.44),
            (-94.02, 44.48),
            (-92.62, 45.48),
            (-89.49, 45.91),
            (-86.38, 44.92),
            (-86.26, 43.37),
            (-86.62, 42.45),
            (-87.43, 41.86),
        ]),
        Polygon([
            (-74.02, 42.8),
            (-72.01, 43.08),
            (-71.42, 42.77),
            (-71.76, 42.29),
            (-72.73, 41.89),
            (-73.89, 41.93),
            (-74.4, 42.28),
            (-74.02, 42.8),
        ])
    ])
    enh_risk_polygon = Polygon([(-87.42, 43.67), (-88.44, 42.65),
                                (-90.87, 41.92), (-94.63, 41.84),
                                (-95.13, 42.22), (-95.23, 42.54),
                                (-94.79, 43.3), (-92.81, 43.99),
                                (-90.62, 44.55), (-88.51, 44.61),
                                (-87.42, 43.67)])

    # Plot geometry, set colors and labels
    geo = PlotGeometry()
    geo.geometry = [slgt_risk_polygon, enh_risk_polygon]
    geo.stroke = ['#DDAA00', '#FF6600']
    geo.fill = None
    geo.labels = ['SLGT', 'ENH']
    geo.label_facecolor = ['#FFE066', '#FFA366']
    geo.label_edgecolor = ['#DDAA00', '#FF6600']
    geo.label_fontsize = 'large'

    # Place plot in a panel and container
    panel = MapPanel()
    panel.area = [-125, -70, 20, 55]
    panel.projection = 'lcc'
    panel.title = ' '
    panel.layers = ['coastline', 'borders', 'usstates']
    panel.plots = [geo]

    pc = PanelContainer()
    pc.size = (12, 12)
    pc.panels = [panel]
    pc.draw()

    return pc.figure