Ejemplo n.º 1
0
def test_latlon():
    """Test our handling of lat/lon information."""
    data = xr.open_dataset(get_test_data('irma_gfs_example.nc', as_file_obj=False))

    img = ImagePlot()
    img.data = data
    img.field = 'Temperature_isobaric'
    img.level = 500 * units.hPa
    img.time = datetime(2017, 9, 5, 15, 0, 0)

    contour = ContourPlot()
    contour.data = data
    contour.field = 'Geopotential_height_isobaric'
    contour.level = img.level
    contour.time = img.time

    panel = MapPanel()
    panel.projection = 'lcc'
    panel.area = 'us'
    panel.plots = [img, contour]

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

    return pc.figure
Ejemplo n.º 2
0
def test_global():
    """Test that we can set global extent."""
    data = xr.open_dataset(GiniFile(get_test_data('NHEM-MULTICOMP_1km_IR_20151208_2100.gini')))

    img = ImagePlot()
    img.data = data
    img.field = 'IR'

    panel = MapPanel()
    panel.area = 'global'
    panel.plots = [img]

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

    return pc.figure
Ejemplo n.º 3
0
def test_declarative_image():
    """Test making an image plot."""
    data = xr.open_dataset(GiniFile(get_test_data('NHEM-MULTICOMP_1km_IR_20151208_2100.gini')))

    img = ImagePlot()
    img.data = data.metpy.parse_cf('IR')
    img.colormap = 'Greys_r'

    panel = MapPanel()
    panel.title = 'Test'
    panel.plots = [img]

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

    assert panel.ax.get_title() == 'Test'

    return pc.figure
Ejemplo n.º 4
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
Ejemplo n.º 5
0
def test_declarative_contour_options():
    """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'
    contour.linestyle = 'dashed'
    contour.clabels = True

    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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def test_declarative_barb_gfs_knots():
    """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.plot_units = 'knot'

    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
Ejemplo n.º 8
0
def test_colorfill_no_colorbar(cfeature):
    """Test that we can use ContourFillPlot."""
    data = xr.open_dataset(get_test_data('narr_example.nc', as_file_obj=False))

    contour = FilledContourPlot()
    contour.data = data
    contour.level = 700 * units.hPa
    contour.field = 'Temperature'
    contour.colormap = 'coolwarm'
    contour.colorbar = None

    panel = MapPanel()
    panel.area = (-110, -60, 25, 55)
    panel.layers = [cfeature.STATES]
    panel.plots = [contour]

    pc = PanelContainer()
    pc.panel = panel
    pc.size = (8, 8)
    pc.draw()

    return pc.figure
Ejemplo n.º 9
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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def test_declarative_plot_geometry_points(ccrs):
    """Test that `PlotGeometry` correctly plots Point and MultiPoint objects."""
    from shapely.geometry import MultiPoint, Point

    # Points and MultiPoints to plot
    irma_track = [Point(-74.7, 21.8), Point(-76.0, 22.0), Point(-77.2, 22.1)]
    irma_track_shadow = MultiPoint([
        Point(-64.7, 18.25),
        Point(-66.0, 18.85),
        Point(-67.7, 19.45),
        Point(-69.0, 19.85),
        Point(-70.4, 20.45),
        Point(-71.8, 20.85),
        Point(-73.2, 21.25),
        Point(-74.7, 21.55),
        Point(-76.0, 21.75),
        Point(-77.2, 21.85),
        Point(-78.3, 22.05),
        Point(-79.3, 22.45),
        Point(-80.2, 22.85),
        Point(-80.9, 23.15),
        Point(-81.3, 23.45),
        Point(-81.5, 24.25),
        Point(-81.7, 25.35),
        Point(-81.7, 26.55),
        Point(-82.2, 27.95),
        Point(-82.7, 29.35),
        Point(-83.5, 30.65),
        Point(-84.4, 31.65)
    ])

    # Plot geometry, set colors and labels
    geo = PlotGeometry()
    geo.geometry = irma_track + [irma_track_shadow]
    geo.fill = 'blue'
    geo.stroke = None
    geo.marker = '^'
    geo.labels = ['Point', 'Point', 'Point', 'Irma Track']
    geo.label_edgecolor = None
    geo.label_facecolor = None

    # Place plot in a panel and container
    panel = MapPanel()
    panel.area = [-85, -65, 17, 30]
    panel.projection = ccrs.PlateCarree()
    panel.layers = ['states', 'coastline', 'borders']
    panel.plots = [geo]

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

    return pc.figure
Ejemplo n.º 12
0
def test_declarative_upa_obs_convert_barb_units():
    """Test making a full upperair observation plot."""
    data = pd.read_csv(get_test_data('UPA_obs.csv', as_file_obj=False))
    data.units = ''
    data.units = {
        'pressure': 'hPa',
        'height': 'meters',
        'temperature': 'degC',
        'dewpoint': 'degC',
        'direction': 'degrees',
        'speed': 'knots',
        'station': None,
        'time': None,
        'u_wind': 'knots',
        'v_wind': 'knots',
        'latitude': 'degrees',
        'longitude': 'degrees'
    }

    obs = PlotObs()
    obs.data = data
    obs.time = datetime(1993, 3, 14, 0)
    obs.level = 500 * units.hPa
    obs.fields = ['temperature', 'dewpoint', 'height']
    obs.locations = ['NW', 'SW', 'NE']
    obs.formats = [None, None, lambda v: format(v, '.0f')[:3]]
    obs.vector_field = ('u_wind', 'v_wind')
    obs.vector_field_length = 7
    obs.vector_plot_units = 'm/s'
    obs.reduce_points = 0

    # Panel for plot with Map features
    panel = MapPanel()
    panel.layout = (1, 1, 1)
    panel.area = (-124, -72, 20, 53)
    panel.projection = 'lcc'
    panel.layers = ['coastline', 'borders', 'states', 'land']
    panel.plots = [obs]

    # Bringing it all together
    pc = PanelContainer()
    pc.size = (15, 10)
    pc.panels = [panel]

    pc.draw()

    obs.level = 300 * units.hPa

    return pc.figure
Ejemplo n.º 13
0
def test_declarative_sfc_obs_full(ccrs):
    """Test making a full surface observation plot."""
    data = pd.read_csv(get_test_data('SFC_obs.csv', as_file_obj=False),
                       infer_datetime_format=True,
                       parse_dates=['valid'])

    obs = PlotObs()
    obs.data = data
    obs.time = datetime(1993, 3, 12, 13)
    obs.time_window = timedelta(minutes=15)
    obs.level = None
    obs.fields = ['tmpf', 'dwpf', 'emsl', 'cloud_cover', 'wxsym']
    obs.locations = ['NW', 'SW', 'NE', 'C', 'W']
    obs.colors = ['red', 'green', 'black', 'black', 'blue']
    obs.formats = [
        None, None, lambda v: format(10 * v, '.0f')[-3:], 'sky_cover',
        'current_weather'
    ]
    obs.vector_field = ('uwind', 'vwind')
    obs.reduce_points = 1

    # Panel for plot with Map features
    panel = MapPanel()
    panel.layout = (1, 1, 1)
    panel.area = (-124, -72, 20, 53)
    panel.area = 'il'
    panel.projection = ccrs.PlateCarree()
    panel.layers = ['coastline', 'borders', 'states']
    panel.plots = [obs]

    # Bringing it all together
    pc = PanelContainer()
    pc.size = (10, 10)
    pc.panels = [panel]

    pc.draw()

    return pc.figure
Ejemplo n.º 14
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
Ejemplo n.º 15
0
def test_declarative_plot_geometry_lines(ccrs):
    """Test that `PlotGeometry` correctly plots MultiLineString and LineString objects."""
    from shapely.geometry import LineString, MultiLineString

    # LineString and MultiLineString to plot
    irma_fcst = LineString([(-52.3, 16.9), (-53.9, 16.7), (-56.2, 16.6),
                            (-58.6, 17.0), (-61.2, 17.8), (-63.9, 18.7),
                            (-66.8, 19.6), (-72.0, 21.0), (-76.5, 22.0)])
    irma_fcst_shadow = MultiLineString([
        LineString([(-52.3, 17.15), (-53.9, 16.95), (-56.2, 16.85),
                    (-58.6, 17.25), (-61.2, 18.05), (-63.9, 18.95),
                    (-66.8, 19.85), (-72.0, 21.25), (-76.5, 22.25)]),
        LineString([(-52.3, 16.65), (-53.9, 16.45), (-56.2, 16.35),
                    (-58.6, 16.75), (-61.2, 17.55), (-63.9, 18.45),
                    (-66.8, 19.35), (-72.0, 20.75), (-76.5, 21.75)])
    ])

    # Plot geometry, set colors and labels
    geo = PlotGeometry()
    geo.geometry = [irma_fcst, irma_fcst_shadow]
    geo.fill = None
    geo.stroke = 'green'
    geo.labels = ['Irma', '+/- 0.25 deg latitude']
    geo.label_facecolor = None

    # Place plot in a panel and container
    panel = MapPanel()
    panel.area = [-85, -45, 12, 25]
    panel.projection = ccrs.PlateCarree()
    panel.layers = ['coastline', 'borders', 'usstates']
    panel.title = 'Hurricane Irma Forecast'
    panel.plots = [geo]

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

    return pc.figure
Ejemplo n.º 16
0
def test_ndim_error_scalar(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))

    contour = ContourPlot()
    contour.data = data
    contour.field = 'Temperature'
    contour.level = None

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

    pc = PanelContainer()
    pc.panel = panel

    with pytest.raises(ValueError):
        pc.draw()
Ejemplo n.º 17
0
def test_projection_object(ccrs, cfeature):
    """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
Ejemplo n.º 18
0
def test_declarative_multiple_sfc_obs_change_units(ccrs):
    """Test making a surface observation plot."""
    data = parse_metar_file(get_test_data('metar_20190701_1200.txt',
                                          as_file_obj=False),
                            year=2019,
                            month=7)

    obs = PlotObs()
    obs.data = data
    obs.time = datetime(2019, 7, 1, 12)
    obs.time_window = timedelta(minutes=15)
    obs.level = None
    obs.fields = [
        'air_temperature', 'dew_point_temperature', 'air_pressure_at_sea_level'
    ]
    obs.locations = ['NW', 'W', 'NE']
    obs.colors = ['red', 'green', 'black']
    obs.reduce_points = 0.75
    obs.plot_units = ['degF', 'degF', None]

    # Panel for plot with Map features
    panel = MapPanel()
    panel.layout = (1, 1, 1)
    panel.projection = ccrs.PlateCarree()
    panel.area = 'in'
    panel.layers = ['states']
    panel.plots = [obs]

    # Bringing it all together
    pc = PanelContainer()
    pc.size = (12, 12)
    pc.panels = [panel]

    pc.draw()

    return pc.figure
Ejemplo n.º 19
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.projection = 'lcc'
    panel.layers = ['coastline', 'borders', 'states']
    panel.plots = [contour, img]

    pc = PanelContainer()
    pc.size = (8, 8.0)
    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'
    img.colorbar = 'horizontal'

    return pc.figure
Ejemplo n.º 20
0
def test_declarative_barb_earth_relative():
    """Test making a contour plot."""
    import numpy as np
    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 = np.arange(0, 20000, 120).tolist()

    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
Ejemplo n.º 21
0
def test_declarative_contour_cam():
    """Test making a contour plot with CAM data."""
    data = xr.open_dataset(get_test_data('CAM_test.nc', as_file_obj=False))

    contour = ContourPlot()
    contour.data = data
    contour.field = 'PN'
    contour.time = datetime.strptime('2020-11-29 00:00', '%Y-%m-%d %H:%M')
    contour.level = 1000 * units.hPa
    contour.linecolor = 'black'
    contour.contours = list(range(0, 1200, 4))

    panel = MapPanel()
    panel.plots = [contour]
    panel.layout = (1, 1, 1)
    panel.layers = ['coastline', 'borders', 'states', 'land']
    panel.plots = [contour]

    pc = PanelContainer()
    pc.panels = [panel]
    pc.draw()

    return pc.figure
Ejemplo n.º 22
0
def test_declarative_station_plot_fontsize():
    """Test adjusting the font size for station plots in PlotObs."""
    data = parse_metar_file(get_test_data('metar_20190701_1200.txt',
                                          as_file_obj=False),
                            year=2019,
                            month=7)
    obs = PlotObs()
    obs.data = data
    obs.time = datetime(2019, 7, 1, 12)
    obs.time_window = timedelta(minutes=15)
    obs.level = None
    obs.fields = [
        'cloud_coverage', 'air_temperature', 'dew_point_temperature',
        'air_pressure_at_sea_level', 'current_wx1_symbol'
    ]
    obs.plot_units = [None, 'degF', 'degF', None, None]
    obs.locations = ['C', 'NW', 'SW', 'NE', 'W']
    obs.formats = [
        'sky_cover', None, None, lambda v: format(v * 10, '.0f')[-3:],
        'current_weather'
    ]
    obs.reduce_points = 3
    obs.vector_field = ['eastward_wind', 'northward_wind']
    obs.fontsize = 8

    panel = MapPanel()
    panel.area = 'centus'
    panel.projection = 'lcc'
    panel.layers = ['coastline', 'borders', 'usstates']
    panel.plots = [obs]

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

    return pc.figure
Ejemplo n.º 23
0
def test_declarative_figsize():
    """Test having an all float figsize."""
    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.projection = 'lcc'
    panel.layers = ['coastline', 'borders', 'usstates']
    panel.plots = [contour]

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

    return pc.figure
Ejemplo n.º 24
0
def test_attribute_error_no_suggest():
    """Test that a mistyped attribute name raises an exception w/o a fix."""
    with pytest.raises(AttributeError) as excinfo:
        panel = MapPanel()
        panel.galaxy = 'Andromeda'
    assert 'Perhaps you meant' not in str(excinfo.value)
Ejemplo n.º 25
0
def test_attribute_error_suggest():
    """Test that a mistyped attribute name raises an exception with fix."""
    with pytest.raises(AttributeError) as excinfo:
        panel = MapPanel()
        panel.pots = []
    assert "Perhaps you meant 'plots'?" in str(excinfo.value)
Ejemplo n.º 26
0
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]
Ejemplo n.º 27
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()
Ejemplo n.º 28
0
#  Distributed under the terms of the BSD 3-Clause License.
#  SPDX-License-Identifier: BSD-3-Clause
"""
Simple Plotting
===============

Demonstrate the use of MetPy's simplified plotting interface.

Plots a sample satellite image file.
"""

import xarray as xr

from metpy.cbook import get_test_data
from metpy.io import GiniFile
from metpy.plots import ImagePlot, MapPanel, PanelContainer

data = xr.open_dataset(GiniFile(get_test_data('NHEM-MULTICOMP_1km_IR_20151208_2100.gini')))

img = ImagePlot()
img.data = data
img.field = 'IR'
img.colormap = 'Greys_r'

panel = MapPanel()
panel.plots = [img]

pc = PanelContainer()
pc.panels = [panel]
pc.show()
Ejemplo n.º 29
0
wind_geo = PlotGeometry()
wind_geo.geometry = wind_data['geometry']
wind_geo.fill = wind_data['fill']
wind_geo.stroke = 'none'

###########################
# Plot the cities from the 'geometry' column, marked with diamonds ('D'). Label each point
# with the name of the city, and it's probability of tropical-storm-force winds on the line
# below. Points are set to plot in white and the font color is set to black.
city_geo = PlotGeometry()
city_geo.geometry = cities['geometry']
city_geo.marker = 'D'
city_geo.labels = cities['NAME'] + '\n(' + cities['PERCENTAGE'] + ')'
city_geo.fill = 'white'
city_geo.label_facecolor = 'black'

###########################
# Add the geometry plots to a panel and container. Finally, we are left with a complete plot of
# wind speed probabilities, along with some select cities and their specific probabilities.
panel = MapPanel()
panel.title = 'NHC 5-Day Tropical-Storm-Force Wind Probabilities (Valid 12z Aug 20 2021)'
panel.plots = [wind_geo, city_geo]
panel.area = [-90, -52, 27, 48]
panel.projection = 'mer'
panel.layers = ['lakes', 'land', 'ocean', 'states', 'coastline', 'borders']

pc = PanelContainer()
pc.size = (12, 10)
pc.panels = [panel]
pc.show()
Ejemplo n.º 30
0
#  SPDX-License-Identifier: BSD-3-Clause
"""
Simple Plotting
===============

Demonstrate the use of MetPy's simplified plotting interface.

Plots a sample satellite image file.
"""

import xarray as xr

from metpy.cbook import get_test_data
from metpy.io import GiniFile
from metpy.plots import ImagePlot, MapPanel, PanelContainer

data = xr.open_dataset(
    GiniFile(get_test_data('NHEM-MULTICOMP_1km_IR_20151208_2100.gini')))

img = ImagePlot()
img.data = data
img.field = 'IR'
img.colormap = 'Greys_r'

panel = MapPanel()
panel.plots = [img]

pc = PanelContainer()
pc.panels = [panel]
pc.show()
Ejemplo n.º 31
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()
Ejemplo n.º 32
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()