• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dbekaert / RAiDER / 1a16f90b-a2b4-48e1-87b0-09ef1ba1bd9c

05 Aug 2024 02:25AM UTC coverage: 48.631% (-4.6%) from 53.245%
1a16f90b-a2b4-48e1-87b0-09ef1ba1bd9c

push

circleci

web-flow
Merge pull request #674 from royagrace/update_tests

Update tests to get rid of extra files created when running tests

2930 of 6025 relevant lines covered (48.63%)

0.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.68
/tools/RAiDER/models/plotWeather.py
1
"""
2
This set of functions is designed to for plotting WeatherModel
3
class objects. It is not designed to be used on its own apart
4
from this class.
5
"""
6

7
import os
1✔
8
from RAiDER.interpolator import RegularGridInterpolator as Interpolator
1✔
9
from mpl_toolkits.axes_grid1 import make_axes_locatable as mal
1✔
10
import numpy as np
1✔
11
import matplotlib.pyplot as plt
1✔
12
import matplotlib as mpl
1✔
13
mpl.use('Agg')
1✔
14

15

16
def plot_pqt(weatherObj, savefig=True, z1=500, z2=15000):
1✔
17
    '''
18
    Create a plot with pressure, temp, and humidity at two heights
19
    '''
20

21
    # Get the interpolator
22

23
    intFcn_p = Interpolator((weatherObj._xs, weatherObj._ys, weatherObj._zs), weatherObj._p.swapaxes(0, 1))
×
24
    intFcn_e = Interpolator((weatherObj._xs, weatherObj._ys, weatherObj._zs), weatherObj._e.swapaxes(0, 1))
×
25
    intFcn_t = Interpolator((weatherObj._xs, weatherObj._ys, weatherObj._zs), weatherObj._t.swapaxes(0, 1))
×
26

27
    # get the points needed
28
    XY = np.meshgrid(weatherObj._xs, weatherObj._ys)
×
29
    x = XY[0]
×
30
    y = XY[1]
×
31
    z1a = np.zeros(x.shape) + z1
×
32
    z2a = np.zeros(x.shape) + z2
×
33
    pts1 = np.stack((x.flatten(), y.flatten(), z1a.flatten()), axis=1)
×
34
    pts2 = np.stack((x.flatten(), y.flatten(), z2a.flatten()), axis=1)
×
35

36
    p1 = intFcn_p(pts1)
×
37
    e1 = intFcn_e(pts1)
×
38
    t1 = intFcn_t(pts1)
×
39
    p2 = intFcn_p(pts2)
×
40
    e2 = intFcn_e(pts2)
×
41
    t2 = intFcn_t(pts2)
×
42

43
    # Now get the data to plot
44
    plots = [p1 / 1e2, e1 / 1e2, t1 - 273.15, p2 / 1e2, e2 / 1e2, t2 - 273.15]
×
45
    # titles = ('P (hPa)', 'E (hPa)'.format(z1), 'T (C)', '', '', '')
46
    titles = ('P (hPa)', 'E (hPa)', 'T (C)', '', '', '')
×
47

48
    # setup the plot
49
    f = plt.figure(figsize=(18, 14))
×
50
    f.suptitle(f'{weatherObj._Name} Pressure/Humidity/Temperature at height {z1}m and {z2}m (values should drop as elevation increases)')
×
51

52
    xind = int(np.floor(weatherObj._xs.shape[0] / 2))
×
53
    yind = int(np.floor(weatherObj._ys.shape[0] / 2))
×
54

55
    # loop over each plot
56
    for ind, plot, title in zip(range(len(plots)), plots, titles):
×
57
        sp = f.add_subplot(3, 3, ind + 1)
×
58
        im = sp.imshow(np.reshape(plot, x.shape),
×
59
                       cmap='viridis',
60
                       extent=[np.nanmin(x), np.nanmax(x), np.nanmin(y), np.nanmax(y)],
61
                       origin='lower')
62
        sp.plot(x[yind, xind], y[yind, xind], 'ko')
×
63
        divider = mal(sp)
×
64
        cax = divider.append_axes("right", size="4%", pad=0.05)
×
65
        plt.colorbar(im, cax=cax)
×
66
        sp.set_title(title)
×
67
        if ind == 0:
×
68
            sp.set_ylabel('{} m\n'.format(z1))
×
69
        if ind == 3:
×
70
            sp.set_ylabel('{} m\n'.format(z2))
×
71

72
    # add plots that show each variable with height
73
    zdata = weatherObj._zs[:] / 1000
×
74
    sp = f.add_subplot(3, 3, 7)
×
75
    sp.plot(weatherObj._p[yind, xind, :] / 1e2, zdata)
×
76
    sp.set_ylabel('Height (km)')
×
77
    sp.set_xlabel('Pressure (hPa)')
×
78

79
    sp = f.add_subplot(3, 3, 8)
×
80
    sp.plot(weatherObj._e[yind, xind, :] / 100, zdata)
×
81
    sp.set_xlabel('E (hPa)')
×
82

83
    sp = f.add_subplot(3, 3, 9)
×
84
    sp.plot(weatherObj._t[yind, xind, :] - 273.15, zdata)
×
85
    sp.set_xlabel('Temp (C)')
×
86

87
    plt.subplots_adjust(top=0.95, bottom=0.1, left=0.1, right=0.95, hspace=0.2,
×
88
                        wspace=0.3)
89

90
    if savefig:
×
91
        wd   = os.path.dirname(os.path.dirname(weatherObj._out_name))
×
92
        f    = f'{weatherObj._Name}_weather_hgt{z1}_and_{z2}m.pdf'
×
93
        plt.savefig(os.path.join(wd, f))
×
94
    return f
×
95

96

97
def plot_wh(weatherObj, savefig=True, z1=500, z2=15000):
1✔
98
    '''
99
    Create a plot with wet refractivity and hydrostatic refractivity,
100
    at two different heights
101
    '''
102

103
    # Get the interpolator
104
    intFcn_w = Interpolator((weatherObj._xs, weatherObj._ys, weatherObj._zs), weatherObj._wet_refractivity.swapaxes(0, 1))
×
105
    intFcn_h = Interpolator((weatherObj._xs, weatherObj._ys, weatherObj._zs), weatherObj._hydrostatic_refractivity.swapaxes(0, 1))
×
106

107
    # get the points needed
108
    XY = np.meshgrid(weatherObj._xs, weatherObj._ys)
×
109
    x = XY[0]
×
110
    y = XY[1]
×
111
    z1a = np.zeros(x.shape) + z1
×
112
    z2a = np.zeros(x.shape) + z2
×
113
    pts1 = np.stack((x.flatten(), y.flatten(), z1a.flatten()), axis=1)
×
114
    pts2 = np.stack((x.flatten(), y.flatten(), z2a.flatten()), axis=1)
×
115

116
    w1 = intFcn_w(pts1)
×
117
    h1 = intFcn_h(pts1)
×
118
    w2 = intFcn_w(pts2)
×
119
    h2 = intFcn_h(pts2)
×
120

121
    # Now get the data to plot
122
    plots = [w1, h1, w2, h2]
×
123

124
    # titles
125
    titles = ('Wet refractivity {}'.format(z1),
×
126
              'Hydrostatic refractivity {}'.format(z1),
127
              '{}'.format(z2),
128
              '{}'.format(z2))
129

130
    # setup the plot
131
    f = plt.figure(figsize=(14, 10))
×
132
    f.suptitle(f'{weatherObj._Name} Wet and Hydrostatic refractivity at height {z1}m and {z2}m')
×
133

134
    # loop over each plot
135
    for ind, plot, title in zip(range(len(plots)), plots, titles):
×
136
        sp = f.add_subplot(2, 2, ind + 1)
×
137
        im = sp.imshow(np.reshape(plot, x.shape), cmap='viridis',
×
138
                       extent=[np.nanmin(x), np.nanmax(x), np.nanmin(y), np.nanmax(y)], origin='lower')
139
        divider = mal(sp)
×
140
        cax = divider.append_axes("right", size="4%", pad=0.05)
×
141
        plt.colorbar(im, cax=cax)
×
142
        sp.set_title(title)
×
143
        if ind == 0:
×
144
            sp.set_ylabel('{} m\n'.format(z1))
×
145
        if ind == 2:
×
146
            sp.set_ylabel('{} m\n'.format(z2))
×
147

148
    if savefig:
×
149
        wd   = os.path.dirname(os.path.dirname(weatherObj._out_name))
×
150
        f    = f'{weatherObj._Name}_refractivity_hgt{z1}_and_{z2}m.pdf'
×
151
        plt.savefig(os.path.join(wd, f))
×
152
    return f
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc