Example #1
0
def test_barb_sounding_plot():
    sonde_ds = arm.read_netcdf(sample_files.EXAMPLE_TWP_SONDE_WILDCARD)
    BarbDisplay = TimeSeriesDisplay({'sonde_darwin': sonde_ds})
    BarbDisplay.plot_time_height_xsection_from_1d_data('rh',
                                                       'pres',
                                                       cmap='coolwarm_r',
                                                       vmin=0,
                                                       vmax=100,
                                                       num_time_periods=25)
    BarbDisplay.plot_barbs_from_spd_dir('deg', 'wspd', 'pres', num_barbs_x=20)
    sonde_ds.close()
    return BarbDisplay.fig
Example #2
0
def test_errors():
    files = sample_files.EXAMPLE_MET_WILDCARD
    obj = arm.read_netcdf(files)

    display = TimeSeriesDisplay(obj)
    display.axes = None
    with np.testing.assert_raises(RuntimeError):
        display.day_night_background()

    display = TimeSeriesDisplay({'met': obj, 'met2': obj})
    with np.testing.assert_raises(ValueError):
        display.plot('temp_mean')
    with np.testing.assert_raises(ValueError):
        display.qc_flag_block_plot('qc_temp_mean')
    with np.testing.assert_raises(ValueError):
        display.plot_barbs_from_spd_dir('wdir_vec_mean', 'wspd_vec_mean')
    with np.testing.assert_raises(ValueError):
        display.plot_barbs_from_u_v('wdir_vec_mean', 'wspd_vec_mean')

    del obj.attrs['_file_dates']

    data = np.empty(len(obj['time'])) * np.nan
    lat = obj['lat'].values
    lon = obj['lon'].values
    obj['lat'].values = data
    obj['lon'].values = data

    display = TimeSeriesDisplay(obj)
    display.plot('temp_mean')
    display.set_yrng([0, 0])
    with np.testing.assert_warns(RuntimeWarning):
        display.day_night_background()
    obj['lat'].values = lat
    with np.testing.assert_warns(RuntimeWarning):
        display.day_night_background()
    obj['lon'].values = lon * 100.
    with np.testing.assert_warns(RuntimeWarning):
        display.day_night_background()
    obj['lat'].values = lat * 100.
    with np.testing.assert_warns(RuntimeWarning):
        display.day_night_background()

    obj.close()

    # Test some of the other errors
    obj = arm.read_netcdf(files)
    del obj['temp_mean'].attrs['units']
    display = TimeSeriesDisplay(obj)
    display.axes = None
    with np.testing.assert_raises(RuntimeError):
        display.set_yrng([0, 10])
    with np.testing.assert_raises(RuntimeError):
        display.set_xrng([0, 10])
    display.fig = None
    display.plot('temp_mean', add_nan=True)

    assert display.fig is not None
    assert display.axes is not None

    with np.testing.assert_raises(AttributeError):
        display = TimeSeriesDisplay([])

    fig, ax = matplotlib.pyplot.subplots()
    display = TimeSeriesDisplay(obj)
    display.add_subplots((2, 2), figsize=(15, 10))
    display.assign_to_figure_axis(fig, ax)
    assert display.fig is not None
    assert display.axes is not None

    obj = arm.read_netcdf(files)
    display = TimeSeriesDisplay(obj)
    obj.clean.cleanup()
    display.axes = None
    display.fig = None
    display.qc_flag_block_plot('atmos_pressure')
    assert display.fig is not None
    assert display.axes is not None

    matplotlib.pyplot.close(fig=display.fig)
Example #3
0
# Add second plot of Ozone. Use variable long name for plot axes title
# and add background color to indicate when sun is shining and solar noon.
var_name = 'ozone'
my_disp.plot(
    var_name,
    dsname='ozone',
    subplot_index=(1, ),
    set_title=f"NOAA GML {location} {ozone_obj[var_name].attrs['long_name']}",
    day_night_background=True)

# Add a wind barb plot from Met datastream. Because the wind speeds are low modify
# the barb thresholds. Currently there is no legend for barbs, that is something
# that will be added in the future.
axes = my_disp.plot_barbs_from_spd_dir(
    'wind_direction',
    'wind_speed',
    dsname='met',
    subplot_index=(2, ),
    set_title=f"NOAA GML {location} Wind Barbs",
    day_night_background=True,
    barb_increments={
        'half': 1,
        'full': 2,
        'flag': 3
    })
axes.set_ylim(0, 2)

plt.subplots_adjust(hspace=0.4)
plt.show()