Completed
Pull Request — master (#382)
by
unknown
01:40 queued 17s
created

test_skewt_shade_area()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
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
# Fixtures to make sure we have the right backend and consistent round
13
from metpy.testing import patch_round, 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
def test_skewt_with_grid_enabled():
57
    """Test using SkewT when gridlines are already enabled (#271)."""
58
    with plt.rc_context(rc={'axes.grid': True}):
59
        # Also tests when we don't pass in Figure
60
        SkewT()
61
62
p = np.linspace(1000, 100, 10)
63
T = np.linspace(20, -20, 10)
64
Tp = np.linspace(25, -30, 10)
65
66
67
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
68
def test_skewt_shade_cape_cin():
69
    """Test shading CAPE and CIN on a SkewT plot."""
70
    fig = plt.figure(figsize=(9, 9))
71
    skew = SkewT(fig)
72
    skew.plot(p, T, 'r')
73
    skew.plot(p, Tp, 'k')
74
    skew.shade_cape(p, T, Tp)
75
    skew.shade_cin(p, T, Tp)
76
    return fig
77
78
79
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
80
def test_skewt_shade_area():
81
    """Test shading areas on a SkewT plot."""
82
    fig = plt.figure(figsize=(9, 9))
83
    skew = SkewT(fig)
84
    skew.plot(p, T, 'r')
85
    skew.plot(p, Tp, 'k')
86
    skew.shade_area(p, T, Tp)
87
    return fig
88
89
90
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
91
def test_skewt_shade_area_kwargs():
92
    """Test shading areas on a SkewT plot with kwargs."""
93
    fig = plt.figure(figsize=(9, 9))
94
    skew = SkewT(fig)
95
    skew.plot(p, T, 'r')
96
    skew.plot(p, Tp, 'k')
97
    skew.shade_area(p, T, Tp, color='magenta')
98
    return fig
99
100
101 View Code Duplication
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
102
def test_hodograph_api():
103
    """Basic test of Hodograph API."""
104
    fig = plt.figure(figsize=(9, 9))
105
    ax = fig.add_subplot(1, 1, 1)
106
    hodo = Hodograph(ax, component_range=60)
107
    hodo.add_grid(increment=5, color='k')
108
    hodo.plot([1, 10], [1, 10], color='red')
109
    hodo.plot_colormapped(np.array([1, 3, 5, 10]), np.array([2, 4, 6, 11]),
110
                          np.array([0.1, 0.3, 0.5, 0.9]), cmap='Greys')
111
    return fig
112
113
114 View Code Duplication
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
115
def test_hodograph_api():
116
    """Basic test of Hodograph API."""
117
    fig = plt.figure(figsize=(9, 9))
118
    ax = fig.add_subplot(1, 1, 1)
119
    hodo = Hodograph(ax, component_range=60)
120
    hodo.add_grid(increment=5, color='k')
121
    hodo.plot([1, 10], [1, 10], color='red')
122
    hodo.plot_colormapped(np.array([1, 3, 5, 10]), np.array([2, 4, 6, 11]),
123
                          np.array([0.1, 0.3, 0.5, 0.9]), cmap='Greys')
124
    return fig
125
126
127
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
128
def test_hodograph_units():
129
    """Test passing unit-ed quantities to Hodograph."""
130
    fig = plt.figure(figsize=(9, 9))
131
    ax = fig.add_subplot(1, 1, 1)
132
    hodo = Hodograph(ax)
133
    u = np.arange(10) * units.kt
134
    v = np.arange(10) * units.kt
135
    hodo.plot(u, v)
136
    hodo.plot_colormapped(u, v, np.sqrt(u * u + v * v), cmap='Greys')
137
    return fig
138
139
140
def test_hodograph_alone():
141
    """Test to create Hodograph without specifying axes."""
142
    Hodograph()
143
144
145
@pytest.mark.mpl_image_compare(tolerance=0, remove_text=True)
146
def test_hodograph_plot_colormapped():
147
    """Test hodograph colored line with NaN values."""
148
    u = np.arange(5., 65., 5)
149
    v = np.arange(-5., -65., -5)
150
    u[3] = np.nan
151
    v[6] = np.nan
152
    fig = plt.figure(figsize=(9, 9))
153
    ax = fig.add_subplot(1, 1, 1)
154
    hodo = Hodograph(ax, component_range=80)
155
    hodo.add_grid(increment=20, color='k')
156
    hodo.plot_colormapped(u, v, np.hypot(u, v), cmap='Greys')
157
158
    return fig
159