Completed
Pull Request — master (#258)
by Ryan
01:13
created

test_skewt_size()   A

Complexity

Conditions 2

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 21
loc 21
rs 9.3142
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
5
import numpy as np
6
from matplotlib import style
7
from matplotlib.gridspec import GridSpec
8
import pytest
9
10
from metpy.plots.skewt import *  # noqa: F403
11
from metpy.testing import hide_tick_labels, make_figure, test_style
12
from metpy.units import units
13
14
15 View Code Duplication
@pytest.mark.mpl_image_compare
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
16
def test_skewt_api():
17
    'Test the SkewT api'
18
    with style.context(test_style):
19
        fig = make_figure(figsize=(9, 9))
20
        skew = SkewT(fig)
21
22
        # Plot the data using normal plotting functions, in this case using
23
        # log scaling in Y, as dictated by the typical meteorological plot
24
        p = np.linspace(1000, 100, 10)
25
        t = np.linspace(20, -20, 10)
26
        u = np.linspace(-10, 10, 10)
27
        skew.plot(p, t, 'r')
28
        skew.plot_barbs(p, u, u)
29
30
        # Add the relevant special lines
31
        skew.plot_dry_adiabats()
32
        skew.plot_moist_adiabats()
33
        skew.plot_mixing_lines()
34
        hide_tick_labels(skew.ax)
35
36
        return fig
37
38
39 View Code Duplication
@pytest.mark.mpl_image_compare(savefig_kwargs={'bbox_inches': 'tight'})
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
40
def test_skewt_size():
41
    'Test that figure sizes are not inflated by ticks (#158)'
42
    with style.context(test_style):
43
        fig = make_figure(figsize=(9, 9))
44
        skew = SkewT(fig)
45
46
        # Plot the data using normal plotting functions, in this case using
47
        # log scaling in Y, as dictated by the typical meteorological plot
48
        p = np.linspace(1000, 100, 10)
49
        t = np.linspace(20, -20, 10)
50
        u = np.linspace(-10, 10, 10)
51
        skew.plot(p, t, 'r')
52
        skew.plot_barbs(p, u, u)
53
54
        # Add the relevant special lines
55
        skew.plot_dry_adiabats()
56
        skew.plot_moist_adiabats()
57
        skew.plot_mixing_lines()
58
59
        return fig
60
61
62
@pytest.mark.mpl_image_compare
63
def test_skewt_subplot():
64
    'Test using SkewT on a sub-plot'
65
    with style.context(test_style):
66
        fig = make_figure(figsize=(9, 9))
67
        hide_tick_labels(SkewT(fig, subplot=(2, 2, 1)).ax)
68
        return fig
69
70
71
@pytest.mark.mpl_image_compare
72
def test_skewt_gridspec():
73
    'Test using SkewT on a sub-plot'
74
    with style.context(test_style):
75
        fig = make_figure(figsize=(9, 9))
76
        gs = GridSpec(1, 2)
77
        hide_tick_labels(SkewT(fig, subplot=gs[0, 1]).ax)
78
        return fig
79
80
81
@pytest.mark.mpl_image_compare
82
def test_hodograph_api():
83
    'Basic test of Hodograph API'
84
    with style.context(test_style):
85
        fig = make_figure(figsize=(9, 9))
86
        ax = fig.add_subplot(1, 1, 1)
87
        hodo = Hodograph(ax, component_range=60)
88
        hodo.add_grid(increment=5, color='k')
89
        hodo.plot([1, 10], [1, 10], color='red')
90
        hodo.plot_colormapped(np.array([1, 3, 5, 10]), np.array([2, 4, 6, 11]),
91
                              np.array([0.1, 0.3, 0.5, 0.9]), cmap='Greys')
92
        hide_tick_labels(ax)
93
        return fig
94
95
96
@pytest.mark.mpl_image_compare
97
def test_hodograph_units():
98
    'Test passing unit-ed quantities to Hodograph'
99
    with style.context(test_style):
100
        fig = make_figure(figsize=(9, 9))
101
        ax = fig.add_subplot(1, 1, 1)
102
        hodo = Hodograph(ax)
103
        u = np.arange(10) * units.kt
104
        v = np.arange(10) * units.kt
105
        hodo.plot(u, v)
106
        hodo.plot_colormapped(u, v, np.sqrt(u * u + v * v), cmap='Greys')
107
        hide_tick_labels(ax)
108
        return fig
109