Completed
Push — master ( b6f686...3e0e7c )
by Ryan
01:31
created

test_hodograph_alone()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
dl 0
loc 3
rs 10
1
# Copyright (c) 2008-2015 MetPy Developers.
2
# Distributed under the terms of the BSD 3-Clause License.
3
# SPDX-License-Identifier: BSD-3-Clause
4
"""Tests for the `skewt` module."""
5
6
from matplotlib.gridspec import GridSpec
7
import matplotlib.pyplot as plt
8
import numpy as np
9
import pytest
10
11
from metpy.plots import Hodograph, SkewT
12
# Fixture to make sure we have the right backend
13
from metpy.testing import set_agg_backend  # noqa: F401
14
from metpy.units import units
15
16
17
@pytest.mark.mpl_image_compare(tolerance=0.021, remove_text=True)
18
def test_skewt_api():
19
    """Test the SkewT API."""
20
    fig = plt.figure(figsize=(9, 9))
21
    skew = SkewT(fig)
22
23
    # Plot the data using normal plotting functions, in this case using
24
    # log scaling in Y, as dictated by the typical meteorological plot
25
    p = np.linspace(1000, 100, 10)
26
    t = np.linspace(20, -20, 10)
27
    u = np.linspace(-10, 10, 10)
28
    skew.plot(p, t, 'r')
29
    skew.plot_barbs(p, u, u)
30
31
    # Add the relevant special lines
32
    skew.plot_dry_adiabats()
33
    skew.plot_moist_adiabats()
34
    skew.plot_mixing_lines()
35
36
    return fig
37
38
39
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
40
def test_skewt_subplot():
41
    """Test using SkewT on a sub-plot."""
42
    fig = plt.figure(figsize=(9, 9))
43
    SkewT(fig, subplot=(2, 2, 1))
44
    return fig
45
46
47
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
48
def test_skewt_gridspec():
49
    """Test using SkewT on a sub-plot."""
50
    fig = plt.figure(figsize=(9, 9))
51
    gs = GridSpec(1, 2)
52
    SkewT(fig, subplot=gs[0, 1])
53
    return fig
54
55
56
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
57
def test_hodograph_api():
58
    """Basic test of Hodograph API."""
59
    fig = plt.figure(figsize=(9, 9))
60
    ax = fig.add_subplot(1, 1, 1)
61
    hodo = Hodograph(ax, component_range=60)
62
    hodo.add_grid(increment=5, color='k')
63
    hodo.plot([1, 10], [1, 10], color='red')
64
    hodo.plot_colormapped(np.array([1, 3, 5, 10]), np.array([2, 4, 6, 11]),
65
                          np.array([0.1, 0.3, 0.5, 0.9]), cmap='Greys')
66
    return fig
67
68
69
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
70
def test_hodograph_units():
71
    """Test passing unit-ed quantities to Hodograph."""
72
    fig = plt.figure(figsize=(9, 9))
73
    ax = fig.add_subplot(1, 1, 1)
74
    hodo = Hodograph(ax)
75
    u = np.arange(10) * units.kt
76
    v = np.arange(10) * units.kt
77
    hodo.plot(u, v)
78
    hodo.plot_colormapped(u, v, np.sqrt(u * u + v * v), cmap='Greys')
79
    return fig
80
81
82
def test_hodograph_alone():
83
    """Test to create Hodograph without specifying axes."""
84
    Hodograph()
85