예제 #1
0
def test_plot_bar_and_class_map(pytestconfig):
    m = class_map(30, 10, 20, 8)
    fig, ax = plt.subplots(1, 2)
    data = init_class_data(m,
                           ax=ax[0],
                           colorbar_settings={
                               'ax': ax,
                               'location': 'bottom'
                           })
    plot_class_map(data=data, ax=ax[0])
    bar(data=data, ax=ax[1])
예제 #2
0
def test_no_args():
    # Custom errors as not required if data keyword argument given.

    with pytest.raises(TypeError) as e:
        bar()
    assert "bar() missing 1 required positional argument: 'class_map'" == str(
        e.value)

    with pytest.raises(TypeError) as e:
        plot_class_map()
    assert "plot_class_map() missing 1 required positional argument: 'class_map'" == str(
        e.value)
예제 #3
0
class_map = c(t, x, y, n)  # 3D array of classifications (t, y, x)

#%%
# Next, we shall import :func:`mcalf.visualisation.bar`.

from mcalf.visualisation import bar

#%%
# We can now simply plot the 3D array.
# By default, the first dimension of a 3D array will be averaged to
# produce a time average, selecting the most common classification
# at each (x, y) coordinate.
# This means the percentage abundances will correspond to the
# most common classification at each coordinate.

bar(class_map)

#%%
# Instead, the percentage abundances can be determined for the whole
# 3D array of classifications by setting ``reduce=True``.
# This skips the averaging process.

bar(class_map, reduce=False)

#%%
# Alternatively, a 2D array can be passed to the function.
# If a 2D array is passed, no averaging is needed, and
# the ``reduce`` parameter is ignored.

#%%
# A narrower range of classifications to be plotted can be
               colorbar_settings={
                   'ax': fig.axes,
                   'label': 'classification',
               })

#%%
# The function :func:`mcalf.visualisation.init_class_data`` is
# intended to be an internal function for generating data that
# is common to multiple plotting functions. However, it may be
# used externally if necessary.

from mcalf.visualisation import init_class_data, bar

fig, ax = plt.subplots(1, 2, constrained_layout=True)

data = init_class_data(class_map, resolution=(0.25, 0.25), ax=ax[1])

bar(data=data, ax=ax[0])
plot_class_map(data=data, ax=ax[1], show_colorbar=False)

#%%
# The following example should be equivalent to the example above,

fig, ax = plt.subplots(1, 2, constrained_layout=True)

bar(class_map, ax=ax[0])
plot_class_map(class_map,
               ax=ax[1],
               show_colorbar=False,
               resolution=(0.25, 0.25))
예제 #5
0
def test_bar_allbad(pytestconfig):
    m = class_map(30, 10, 20, 8)
    m[:] = -1
    bar(m)
예제 #6
0
def test_bar_reduce(pytestconfig):
    m = class_map(30, 10, 20, 8)
    bar(m, reduce=False)
예제 #7
0
def test_bar_range(pytestconfig):
    m = class_map(30, 10, 20, 8)
    bar(m, vmin=2, vmax=4)
예제 #8
0
def test_bar(pytestconfig):
    m = class_map(30, 10, 20, 8)
    bar(m)