From ba1ad9191600b3319b520cd8d9a0323bc58ba808 Mon Sep 17 00:00:00 2001 From: "J.R. Leeman" Date: Wed, 23 Aug 2017 09:16:49 -0600 Subject: [PATCH 1/4] Add Wyoming upper air capability. --- siphon/__init__.py | 2 +- siphon/simplewebservice/__init__.py | 4 + siphon/simplewebservice/wyoming.py | 119 ++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 siphon/simplewebservice/__init__.py create mode 100644 siphon/simplewebservice/wyoming.py diff --git a/siphon/__init__.py b/siphon/__init__.py index 23d0bc0fa..331d0bcf5 100644 --- a/siphon/__init__.py +++ b/siphon/__init__.py @@ -8,4 +8,4 @@ __version__ = get_versions()['version'] del get_versions -__all__ = ['catalog', 'testing', 'http_util'] +__all__ = ['catalog', 'testing', 'http_util', 'upperair'] diff --git a/siphon/simplewebservice/__init__.py b/siphon/simplewebservice/__init__.py new file mode 100644 index 000000000..e3c5136b7 --- /dev/null +++ b/siphon/simplewebservice/__init__.py @@ -0,0 +1,4 @@ +# Copyright (c) 2013-2015 University Corporation for Atmospheric Research/Unidata. +# Distributed under the terms of the MIT License. +# SPDX-License-Identifier: MIT +"""Contains functionality for retreiving simple web sevice data.""" diff --git a/siphon/simplewebservice/wyoming.py b/siphon/simplewebservice/wyoming.py new file mode 100644 index 000000000..46e2a23ef --- /dev/null +++ b/siphon/simplewebservice/wyoming.py @@ -0,0 +1,119 @@ +# Copyright (c) 2013-2015 University Corporation for Atmospheric Research/Unidata. +# Distributed under the terms of the MIT License. +# SPDX-License-Identifier: MIT +"""Read upper air data from the Wyoming archives.""" + +from ..http_util import HTTPEndPoint +from io import BytesIO, StringIO +import numpy as np +import pandas as pd +from metpy.calc import get_wind_components +from bs4 import BeautifulSoup + + +class WyomingUpperAir(HTTPEndPoint): + """Download and parse data from the University of Wyoming's upper air archive.""" + + def __init__(self): + super(WyomingUpperAir, self).__init__('http://weather.uwyo.edu/cgi-bin/sounding') + + + @classmethod + def request_data(cls, time, site_id, **kwargs): + r"""Retrieve upper air observations from the Wyoming archive. + + Parameters + ---------- + time : datetime + The date and time of the desired observation. + + site_id : str + The three letter ICAO identifier of the station for which data should be + downloaded. + + kwargs + Arbitrary keyword arguments to use to initialize source + + Returns + ------- + :class:`pandas.DataFrame` containing the data + + """ + endpoint = cls() + df = endpoint._get_data(time, site_id, **kwargs) + return df + + + def _get_data(self, time, site_id, region='naconf'): + r"""Download and parse upper air observations from an online archive. + + Parameters + ---------- + time : datetime + The date and time of the desired observation. + + site_id : str + The three letter ICAO identifier of the station for which data should be + downloaded. + + region + Region to request data from + + Returns + ------- + :class:`pandas.DataFrame` containing the data + + """ + raw_data = self._get_data_raw(time, site_id, region) + col_names = ['pressure', 'height', 'temperature', 'dewpoint', 'direction', 'speed'] + df = pd.read_fwf(raw_data, skiprows=5, usecols=[0, 1, 2, 3, 6, 7], names=col_names) + df['u_wind'], df['v_wind'] = get_wind_components(df['speed'], + np.deg2rad(df['direction'])) + + # Drop any rows with all NaN values for T, Td, winds + df = df.dropna(subset=('temperature', 'dewpoint', 'direction', 'speed', + 'u_wind', 'v_wind'), how='all').reset_index(drop=True) + + # Add unit dictionary + df.units = {'pressure': 'hPa', + 'height': 'meter', + 'temperature': 'degC', + 'dewpoint': 'degC', + 'direction': 'degrees', + 'speed': 'knot', + 'u_wind': 'knot', + 'v_wind': 'knot'} + return df + + + def _get_data_raw(self, time, site_id, region='naconf'): + """Download data from the University of Wyoming's upper air archive. + + Parameters + ---------- + time : datetime + Date and time for which data should be downloaded + site_id : str + Site id for which data should be downloaded + region : str + The region in which the station resides. Defaults to `naconf`. + + Returns + ------- + a file-like object from which to read the data + + """ + path = ('?region={region}&TYPE=TEXT%3ALIST' + '&YEAR={time:%Y}&MONTH={time:%m}&FROM={time:%d%H}&TO={time:%d%H}' + '&STNM={stid}').format(region=region, time=time, stid=site_id) + + resp = self.get_path(path) # This will become self.get_query(query) + # See if the return is valid, but has no data + if resp.text.find('Can\'t') != -1: + raise ValueError( + 'No data available for {time:%Y-%m-%d %HZ} from region {region} ' + 'for station {stid}.'.format(time=time, region=region, + stid=site_id)) + + soup = BeautifulSoup(resp.text, 'html.parser') + return StringIO(soup.find_all('pre')[0].contents[0]) From d76f5205ac764324624cd597f96aef0ca4c6d7f4 Mon Sep 17 00:00:00 2001 From: "J.R. Leeman" Date: Thu, 24 Aug 2017 16:05:30 -0600 Subject: [PATCH 2/4] Move get_wind_components to _tools --- siphon/_tools.py | 29 +++++++++++++++++++++++++++++ siphon/simplewebservice/wyoming.py | 15 +++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 siphon/_tools.py diff --git a/siphon/_tools.py b/siphon/_tools.py new file mode 100644 index 000000000..50e8c1449 --- /dev/null +++ b/siphon/_tools.py @@ -0,0 +1,29 @@ +# Copyright (c) 2013-2015 University Corporation for Atmospheric Research/Unidata. +# Distributed under the terms of the MIT License. +# SPDX-License-Identifier: MIT +"""Tools for data conversion and presentation.""" + +import numpy as np + + +def get_wind_components(speed, wdir): + r"""Calculate the U, V wind vector components from the speed and direction. + + Parameters + ---------- + speed : array_like + The wind speed (magnitude) + wdir : array_like + The wind direction, specified as the direction from which the wind is + blowing, with 0 being North. + + Returns + ------- + u, v : tuple of array_like + The wind components in the X (East-West) and Y (North-South) + directions, respectively. + + """ + u = -speed * np.sin(wdir) + v = -speed * np.cos(wdir) + return u, v diff --git a/siphon/simplewebservice/wyoming.py b/siphon/simplewebservice/wyoming.py index 46e2a23ef..b521559b1 100644 --- a/siphon/simplewebservice/wyoming.py +++ b/siphon/simplewebservice/wyoming.py @@ -3,21 +3,22 @@ # SPDX-License-Identifier: MIT """Read upper air data from the Wyoming archives.""" -from ..http_util import HTTPEndPoint -from io import BytesIO, StringIO +from io import StringIO + +from bs4 import BeautifulSoup import numpy as np import pandas as pd -from metpy.calc import get_wind_components -from bs4 import BeautifulSoup +from .._tools import get_wind_components +from ..http_util import HTTPEndPoint class WyomingUpperAir(HTTPEndPoint): """Download and parse data from the University of Wyoming's upper air archive.""" def __init__(self): + """Set up endpoint.""" super(WyomingUpperAir, self).__init__('http://weather.uwyo.edu/cgi-bin/sounding') - @classmethod def request_data(cls, time, site_id, **kwargs): r"""Retrieve upper air observations from the Wyoming archive. @@ -43,7 +44,6 @@ def request_data(cls, time, site_id, **kwargs): df = endpoint._get_data(time, site_id, **kwargs) return df - def _get_data(self, time, site_id, region='naconf'): r"""Download and parse upper air observations from an online archive. @@ -85,7 +85,6 @@ def _get_data(self, time, site_id, region='naconf'): 'v_wind': 'knot'} return df - def _get_data_raw(self, time, site_id, region='naconf'): """Download data from the University of Wyoming's upper air archive. @@ -107,7 +106,7 @@ def _get_data_raw(self, time, site_id, region='naconf'): '&YEAR={time:%Y}&MONTH={time:%m}&FROM={time:%d%H}&TO={time:%d%H}' '&STNM={stid}').format(region=region, time=time, stid=site_id) - resp = self.get_path(path) # This will become self.get_query(query) + resp = self.get_path(path) # See if the return is valid, but has no data if resp.text.find('Can\'t') != -1: raise ValueError( From 4d41875446010138995c19ba065d0c318ebe9897 Mon Sep 17 00:00:00 2001 From: "J.R. Leeman" Date: Tue, 12 Sep 2017 07:16:39 -0600 Subject: [PATCH 3/4] Add tests for Wyoming upper air. --- .../tests/fixtures/wyoming_high_alt_sounding | 191 ++++++++++++++++++ siphon/tests/fixtures/wyoming_sounding | 90 +++++++++ siphon/tests/test_wyoming.py | 51 +++++ 3 files changed, 332 insertions(+) create mode 100644 siphon/tests/fixtures/wyoming_high_alt_sounding create mode 100644 siphon/tests/fixtures/wyoming_sounding create mode 100644 siphon/tests/test_wyoming.py diff --git a/siphon/tests/fixtures/wyoming_high_alt_sounding b/siphon/tests/fixtures/wyoming_high_alt_sounding new file mode 100644 index 000000000..72806e092 --- /dev/null +++ b/siphon/tests/fixtures/wyoming_high_alt_sounding @@ -0,0 +1,191 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [Siphon (0.5.0+16.g57e50cd)] + method: GET + uri: http://weather.uwyo.edu/cgi-bin/sounding/?region=naconf&TYPE=TEXT%3ALIST&YEAR=2010&MONTH=12&FROM=0912&TO=0912&STNM=BOI + response: + body: {string: "\nUniversity of Wyoming - Radiosonde Data\n\n\n

72681 BOI Boise Observations at 12Z 09 Dec 2010

\n
\n-----------------------------------------------------------------------------\n
+        \  PRES   HGHT   TEMP   DWPT   RELH   MIXR   DRCT   SKNT   THTA   THTE   THTV\n
+        \   hPa     m      C      C      %    g/kg    deg   knot     K      K      K
+        \n-----------------------------------------------------------------------------\n
+        1000.0    185                                                               \n
+        \ 925.0    822                                                               \n
+        \ 919.0    874   -0.1   -0.2     99   4.12    240      3  279.7  291.3  280.4\n
+        \ 909.0    962    1.2    0.9     98   4.51    218      4  281.9  294.7  282.7\n
+        \ 890.0   1133    5.4    3.9     90   5.72    176      6  288.0  304.4  289.0\n
+        \ 880.7   1219    5.1    2.2     82   5.12    155      7  288.5  303.3  289.4\n
+        \ 879.0   1235    5.0    1.9     80   5.02    160      7  288.6  303.1  289.5\n
+        \ 862.0   1395    4.8    1.9     81   5.12    213      4  290.0  304.9  290.9\n
+        \ 850.0   1509    3.8    1.2     83   4.93    250      2  290.1  304.5  291.0\n
+        \ 839.0   1615    3.0    1.0     87   4.93    265      5  290.4  304.8  291.2\n
+        \ 818.0   1820    1.8   -2.3     74   3.97    294     11  291.2  302.9  291.9\n
+        \ 817.1   1829    1.7   -2.2     75   4.01    295     11  291.2  303.1  291.9\n
+        \ 803.0   1969    0.4    0.0     97   4.79    281     12  291.2  305.3  292.1\n
+        \ 786.6   2134   -0.8   -1.1     98   4.49    265     14  291.6  304.9  292.4\n
+        \ 758.0   2429   -3.1   -3.2     99   4.00    260     18  292.3  304.2  293.0\n
+        \ 757.2   2438   -3.1   -3.3     99   3.98    260     18  292.4  304.2  293.1\n
+        \ 732.0   2705   -4.3   -6.4     85   3.25    256     20  293.9  303.8  294.5\n
+        \ 728.5   2743   -4.6   -6.7     85   3.18    255     20  293.9  303.6  294.5\n
+        \ 700.0   3056   -7.5   -9.6     85   2.65    260     27  294.1  302.3  294.6\n
+        \ 668.0   3418  -10.9  -13.1     84   2.10    263     32  294.3  300.8  294.7\n
+        \ 656.0   3558  -12.3  -13.6     90   2.05    264     34  294.2  300.6  294.6\n
+        \ 652.0   3604  -13.1  -15.6     81   1.75    265     34  293.9  299.3  294.2\n
+        \ 647.4   3658  -12.9  -17.0     72   1.57    265     35  294.6  299.6  294.9\n
+        \ 646.0   3675  -12.9  -17.4     69   1.52    265     35  294.9  299.7  295.1\n
+        \ 641.0   3734  -12.7  -22.7     43   0.97    266     36  295.7  298.9  295.9\n
+        \ 631.0   3854  -13.9  -25.9     36   0.74    267     37  295.7  298.2  295.8\n
+        \ 625.0   3926  -14.1  -32.1     20   0.42    267     38  296.3  297.7  296.4\n
+        \ 616.0   4036  -14.7  -34.7     17   0.33    268     39  296.8  298.0  296.9\n
+        \ 611.0   4098  -14.1  -38.1     11   0.24    269     40  298.2  299.1  298.2\n
+        \ 606.0   4161  -14.5  -50.5      3   0.06    269     41  298.4  298.7  298.5\n
+        \ 598.0   4261  -14.7                         270     42  299.4         299.4\n
+        \ 597.5   4267  -14.7                         270     42  299.4         299.4\n
+        \ 551.0   4877  -17.9                         265     56  302.6         302.6\n
+        \ 546.0   4945  -18.3                         266     57  302.9         302.9\n
+        \ 518.0   5338  -19.3                         273     61  306.3         306.3\n
+        \ 507.8   5486  -20.2                         275     62  307.0         307.0\n
+        \ 500.0   5600  -20.9                         275     63  307.5         307.5\n
+        \ 467.0   6096  -24.4                         270     70  309.3         309.3\n
+        \ 437.0   6577  -27.7                         272     79  310.9         310.9\n
+        \ 433.0   6643  -27.3                         272     80  312.3         312.3\n
+        \ 400.0   7210  -28.7                         275     90  317.6         317.6\n
+        \ 395.0   7300  -28.7                         276     92  318.8         318.8\n
+        \ 394.0   7318  -28.7                         276     92  319.0         319.0\n
+        \ 377.5   7620  -31.1                         280     98  319.7         319.7\n
+        \ 337.0   8418  -37.5                         280    102  321.5         321.5\n
+        \ 302.9   9144  -43.7                         280    105  322.7         322.7\n
+        \ 300.0   9210  -44.3                         280    105  322.8         322.8\n
+        \ 297.0   9278  -45.1                         280    105  322.6         322.6\n
+        \ 250.0  10410  -54.5                         280    109  324.9         324.9\n
+        \ 246.0  10513  -55.5                         280    111  324.9         324.9\n
+        \ 240.0  10668  -56.6                         280    114  325.5         325.5\n
+        \ 235.0  10801  -57.6                         280    114  326.0         326.0\n
+        \ 221.0  11188  -60.5                         280    113  327.3         327.3\n
+        \ 217.8  11278  -60.5                         280    112  328.7         328.7\n
+        \ 204.0  11687  -60.5                         280     97  334.9         334.9\n
+        \ 200.0  11810  -61.1                         280     93  335.9         335.9\n
+        \ 197.5  11887  -61.3                         280     88  336.7         336.7\n
+        \ 183.0  12360  -62.5                         277     93  342.2         342.2\n
+        \ 170.4  12802  -61.8                         275     97  350.5         350.5\n
+        \ 169.0  12851  -61.7                         275     95  351.4         351.4\n
+        \ 164.0  13037  -62.5                         276     89  353.1         353.1\n
+        \ 155.0  13386  -60.9                         279     78  361.6         361.6\n
+        \ 150.0  13590  -61.3                         280     71  364.3         364.3\n
+        \ 147.0  13716  -60.5                         275     66  367.7         367.7\n
+        \ 146.0  13758  -60.3                         275     66  368.8         368.8\n
+        \ 128.0  14573  -61.9                         275     68  380.1         380.1\n
+        \ 123.0  14819  -60.9                         275     68  386.3         386.3\n
+        \ 119.0  15024  -61.1                         275     69  389.6         389.6\n
+        \ 116.0  15183  -59.7                         275     69  395.0         395.0\n
+        \ 115.0  15240  -57.9                         275     69  399.4         399.4\n
+        \ 115.0  15237  -57.9                         275     69  399.3         399.3\n
+        \ 113.0  15348  -57.7                         276     64  401.7         401.7\n
+        \ 107.0  15690  -59.1                         280     50  405.4         405.4\n
+        \ 100.0  16110  -62.1                         285     32  407.5         407.5\n
+        \  90.8  16703  -63.9                         285     54  415.3         415.3\n
+        \  89.9  16764  -63.8                         285     56  416.7         416.7\n
+        \  85.5  17069  -63.1                         270     35  423.9         423.9\n
+        \  82.6  17284  -62.7                         266     41  429.1         429.1\n
+        \  80.2  17467  -61.3                         263     47  435.6         435.6\n
+        \  77.5  17678  -57.1                         260     53  448.6         448.6\n
+        \  76.7  17747  -55.7                         266     51  452.9         452.9\n
+        \  73.9  17983  -55.2                         285     46  458.7         458.7\n
+        \  70.5  18288  -54.6                         290     24  466.4         466.4\n
+        \  70.0  18330  -54.5                         290     28  467.4         467.4\n
+        \  68.5  18469  -53.5                         269     20  472.5         472.5\n
+        \  67.2  18593  -54.4                         250     12  473.1         473.1\n
+        \  60.8  19228  -59.1                         295     15  476.4         476.4\n
+        \  58.1  19507  -59.7                         315     16  481.1         481.1\n
+        \  55.4  19812  -60.4                         330     19  486.3         486.3\n
+        \  52.7  20117  -61.1                         310     21  491.6         491.6\n
+        \  51.9  20217  -61.3                         321     17  493.3         493.3\n
+        \  50.9  20338  -59.5                         333     13  500.3         500.3\n
+        \  50.0  20450  -60.5                         345      9  500.5         500.5\n
+        \  47.8  20726  -62.3                         335     13  502.7         502.7\n
+        \  46.1  20953  -63.7                         322     16  504.5         504.5\n
+        \  43.3  21336  -59.7                         300     20  523.4         523.4\n
+        \  43.1  21370  -59.3                         297     19  525.1         525.1\n
+        \  41.3  21641  -59.9                         270     11  530.0         530.0\n
+        \  40.3  21790  -60.3                         282     13  532.8         532.8\n
+        \  39.3  21946  -59.0                         295     16  539.8         539.8\n
+        \  38.6  22061  -58.1                         298     16  545.0         545.0\n
+        \  35.9  22519  -57.1                         309     14  559.0         559.0\n
+        \  35.7  22555  -57.3                         310     14  559.5         559.5\n
+        \  34.0  22860  -58.6                         300      2  563.7         563.7\n
+        \  33.9  22881  -58.7                         301      3  564.0         564.0\n
+        \  30.9  23470  -58.4                         325     17  580.1         580.1\n
+        \  30.0  23650  -58.3                         340     12  585.1         585.1\n
+        \  29.4  23774  -58.3                         340     11  588.4         588.4\n
+        \  26.7  24384  -58.5                           0      9  604.6         604.6\n
+        \  25.7  24621  -58.5                         318      7  611.0         611.0\n
+        \  24.0  25052  -56.5                         243      4  628.9         628.9\n
+        \  23.1  25298  -56.8                         200      2  634.9         634.9\n
+        \  22.4  25489  -57.1                         239      5  639.6         639.6\n
+        \  21.2  25838  -54.7                         311     10  657.0         657.0\n
+        \  21.0  25908  -54.7                         325     11  658.9         658.9\n
+        \  20.0  26213  -54.9                           0     12  667.5         667.5\n
+        \  20.0  26210  -54.9                         355     12  667.4         667.4\n
+        \  18.8  26606  -54.1                         358     12  681.8         681.8\n
+        \  17.3  27127  -54.1                         355     13  697.8         697.8\n
+        \  16.5  27432  -54.1                         340     11  707.3         707.3\n
+        \  16.3  27521  -54.1                         347     12  710.1         710.1\n
+        \  15.8  27737  -54.6                           5     15  715.5         715.5\n
+        \  14.3  28346  -55.9                         310      2  730.9         730.9\n
+        \  14.1  28446  -56.1                         313      3  733.4         733.4\n
+        \  12.4  29261  -54.6                         340     14  766.0         766.0\n
+        \  11.8  29566  -54.0                         345     26  778.5         778.5\n
+        \  11.7  29637  -53.9                         342     25  781.4         781.4\n
+        \  10.5  30329  -55.7                         316     18  799.3         799.3\n
+        \  10.2  30480  -55.0                         310     16  807.3         807.3\n
+        \  10.0  30640  -54.3                         320     21  815.8         815.8\n
+        \   9.5  30970  -52.7                         318     21  833.9         833.9\n
+        \   8.3  31839  -53.9                         313     20  862.0         862.0\n
+        \   7.7  32309  -56.1                         310     20  871.6         871.6\n
+        \   7.5  32485  -56.9                                     875.1         875.1\n

Station + information and sounding indices

\n                         Station
+        identifier: BOI\n                             Station number: 72681\n                           Observation
+        time: 101209/1200\n                           Station latitude: 43.56\n                          Station
+        longitude: -116.21\n                          Station elevation: 874.0\n                            Showalter
+        index: 5.01\n                               Lifted index: 7.90\n    LIFT computed
+        using virtual temperature: 7.80\n                                SWEAT index:
+        81.40\n                                    K index: 23.80\n                         Cross
+        totals index: 22.10\n                      Vertical totals index: 24.70\n
+        \                       Totals totals index: 46.80\n      Convective Available
+        Potential Energy: 0.00\n             CAPE using virtual temperature: 0.00\n
+        \                     Convective Inhibition: 0.00\n             CINS using
+        virtual temperature: 0.00\n                     Bulk Richardson Number: 0.00\n
+        \         Bulk Richardson Number using CAPV: 0.00\n  Temp [K] of the Lifted
+        Condensation Level: 274.79\nPres [hPa] of the Lifted Condensation Level: 869.51\n
+        \    Mean mixed layer potential temperature: 286.02\n              Mean mixed
+        layer mixing ratio: 5.01\n              1000 hPa to 500 hPa thickness: 5415.00\nPrecipitable
+        water [mm] for entire sounding: 11.09\n
\n

Description of the \ndata columns\nor sounding + indices.\n\n

\n

\n\n\n
\n
\n

This server lost its data drive on\nMarch + 11. Most of the functionality has been restored.

\n
\nInterested + in graduate studies in atmospheric science?\nCheck out our program at the\nUniversity of Wyoming\n\n
\nQuestions about the weather data provided by + this site can be\naddressed to \nLarry + Oolman (ldoolman@uwyo.edu)\n
\n\n\n\n"} + headers: + Accept-Ranges: [bytes] + Connection: [close] + Content-Length: ['13324'] + Content-Type: [text/html; charset=UTF-8] + Date: ['Tue, 12 Sep 2017 13:16:07 GMT'] + ETag: ['"22e0185-340c-558fdab6b1fc8"'] + Last-Modified: ['Tue, 12 Sep 2017 13:03:29 GMT'] + Server: [Apache/2.2.15 (Red Hat)] + status: {code: 200, message: OK} +version: 1 diff --git a/siphon/tests/fixtures/wyoming_sounding b/siphon/tests/fixtures/wyoming_sounding new file mode 100644 index 000000000..896ec8b40 --- /dev/null +++ b/siphon/tests/fixtures/wyoming_sounding @@ -0,0 +1,90 @@ +interactions: +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Connection: [keep-alive] + User-Agent: [Siphon (0.5.0+16.g57e50cd)] + method: GET + uri: http://weather.uwyo.edu/cgi-bin/sounding/?region=naconf&TYPE=TEXT%3ALIST&YEAR=1999&MONTH=05&FROM=0400&TO=0400&STNM=OUN + response: + body: {string: "\nUniversity of Wyoming - Radiosonde Data\n\n\n

72357 OUN Norman Observations at 00Z 04 May 1999

\n
\n-----------------------------------------------------------------------------\n
+        \  PRES   HGHT   TEMP   DWPT   RELH   MIXR   DRCT   SKNT   THTA   THTE   THTV\n
+        \   hPa     m      C      C      %    g/kg    deg   knot     K      K      K
+        \n-----------------------------------------------------------------------------\n
+        1000.0     -7                                                               \n
+        \ 959.0    345   22.2   19.0     82  14.64    160     18  298.9  341.8  301.5\n
+        \ 931.3    610   20.2   17.5     84  13.66    165     40  299.4  339.5  301.9\n
+        \ 925.0    671   19.8   17.1     84  13.44    165     38  299.6  339.0  302.0\n
+        \ 899.3    914   18.4   16.9     91  13.63    175     39  300.5  340.7  303.0\n
+        \ 892.0    984   18.0   16.8     93  13.68    178     39  300.8  341.2  303.3\n
+        \ 867.9   1219   17.4   14.3     82  11.99    190     38  302.6  338.3  304.8\n
+        \ 850.0   1397   17.0   12.5     75  10.82    195     38  303.9  336.5  305.9\n
+        \ 814.0   1766   15.4    5.4     51   6.95    204     37  306.0  327.4  307.3\n
+        \ 807.9   1829   15.4    1.2     38   5.19    205     37  306.7  323.0  307.7\n
+        \ 790.0   2019   15.6  -11.4     14   2.03    211     40  308.9  315.6  309.2\n
+        \ 779.2   2134   14.6  -11.2     16   2.09    215     42  309.0  315.9  309.4\n
+        \ 751.3   2438   12.0  -10.8     19   2.24    215     42  309.5  316.9  309.9\n
+        \ 724.3   2743    9.4  -10.4     24   2.40    220     40  309.9  317.8  310.3\n
+        \ 700.0   3028    7.0  -10.0     29   2.57    220     37  310.2  318.6  310.7\n
+        \ 655.0   3568    2.2  -16.8     23   1.58    220     37  310.7  316.1  311.0\n
+        \ 647.5   3658    1.4  -16.7     25   1.61    220     37  310.8  316.3  311.1\n
+        \ 599.4   4267   -4.2  -15.8     40   1.87    225     39  311.4  317.6  311.7\n
+        \ 554.7   4877   -9.7  -15.0     65   2.16    220     38  311.8  319.0  312.2\n
+        \ 550.0   4943  -10.3  -14.9     69   2.20    220     38  311.8  319.1  312.2\n
+        \ 500.0   5670  -14.9  -18.9     72   1.73    225     36  314.8  320.7  315.1\n
+        \ 472.5   6096  -17.6  -21.0     75   1.52    235     43  316.6  321.8  316.9\n
+        \ 449.0   6480  -20.1  -22.9     78   1.36    235     42  318.1  322.9  318.4\n
+        \ 400.0   7330  -26.7  -30.1     73   0.79    235     40  320.2  323.1  320.4\n
+        \ 383.7   7620  -29.1  -32.6     72   0.65    235     40  320.8  323.2  321.0\n
+        \ 336.4   8534  -36.8  -40.6     68   0.33    235     47  322.6  323.9  322.7\n
+        \ 321.9   8839  -39.4  -43.3     66   0.26    240     36  323.2  324.2  323.2\n
+        \ 308.1   9144  -41.9  -46.0     65   0.20    240     37  323.7  324.5  323.7\n
+        \ 300.0   9330  -43.5  -47.6     64   0.17    245     38  323.9  324.6  324.0\n
+        \ 269.0  10049  -49.0  -53.2     62   0.10    245     73  326.2  326.6  326.2\n
+        \ 268.6  10058  -49.1  -53.2     62   0.10    250     70  326.2  326.6  326.2\n
+        \ 251.0  10505  -52.5  -56.7     60   0.07                327.5  327.8  327.5\n

Station + information and sounding indices

\n                         Station
+        identifier: OUN\n                             Station number: 72357\n                           Observation
+        time: 990504/0000\n                           Station latitude: 35.18\n                          Station
+        longitude: -97.44\n                          Station elevation: 345.0\n                            Showalter
+        index: -6.51\n                               Lifted index: -8.04\n    LIFT
+        computed using virtual temperature: -8.51\n                                SWEAT
+        index: 555.49\n                                    K index: 27.40\n                         Cross
+        totals index: 27.40\n                      Vertical totals index: 31.90\n
+        \                       Totals totals index: 59.30\n      Convective Available
+        Potential Energy: 2252.27\n             CAPE using virtual temperature: 2381.91\n
+        \                     Convective Inhibition: -120.55\n             CINS using
+        virtual temperature: -64.57\n                   Level of Free Convection:
+        712.90\n             LFCT using virtual temperature: 745.24\n                     Bulk
+        Richardson Number: 24.15\n          Bulk Richardson Number using CAPV: 25.54\n
+        \ Temp [K] of the Lifted Condensation Level: 290.20\nPres [hPa] of the Lifted
+        Condensation Level: 895.98\n     Mean mixed layer potential temperature: 299.46\n
+        \             Mean mixed layer mixing ratio: 13.85\n              1000 hPa
+        to 500 hPa thickness: 5677.00\nPrecipitable water [mm] for entire sounding:
+        26.86\n
\n

Description of the \ndata + columns\nor sounding indices.\n\n

\n

\n\n\n
\n
\n

This server lost its data drive on\nMarch + 11. Most of the functionality has been restored.

\n
\nInterested + in graduate studies in atmospheric science?\nCheck out our program at the\nUniversity of Wyoming\n\n
\nQuestions about the weather data provided by + this site can be\naddressed to \nLarry + Oolman (ldoolman@uwyo.edu)\n
\n\n\n\n"} + headers: + Accept-Ranges: [bytes] + Connection: [close] + Content-Length: ['5490'] + Content-Type: [text/html; charset=UTF-8] + Date: ['Tue, 12 Sep 2017 13:16:07 GMT'] + ETag: ['"22e0181-1572-558fdab4f65d6"'] + Last-Modified: ['Tue, 12 Sep 2017 13:03:27 GMT'] + Server: [Apache/2.2.15 (Red Hat)] + status: {code: 200, message: OK} +version: 1 diff --git a/siphon/tests/test_wyoming.py b/siphon/tests/test_wyoming.py new file mode 100644 index 000000000..8f16c9904 --- /dev/null +++ b/siphon/tests/test_wyoming.py @@ -0,0 +1,51 @@ +# Copyright (c) 2017 University Corporation for Atmospheric Research/Unidata. +# Distributed under the terms of the MIT License. +# SPDX-License-Identifier: MIT +"""Test Wyoming upper air dataset access.""" + +from datetime import datetime + +from numpy.testing import assert_almost_equal + +from siphon.simplewebservice.wyoming import WyomingUpperAir +from siphon.testing import get_recorder + + +recorder = get_recorder(__file__) + + +@recorder.use_cassette('wyoming_sounding') +def test_wyoming(): + """Test that we are properly parsing data from the wyoming archive.""" + df = WyomingUpperAir.request_data(datetime(1999, 5, 4, 0), 'OUN') + + assert_almost_equal(df['pressure'][5], 867.9, 2) + assert_almost_equal(df['height'][5], 1219., 2) + assert_almost_equal(df['temperature'][5], 17.4, 2) + assert_almost_equal(df['dewpoint'][5], 14.3, 2) + assert_almost_equal(df['u_wind'][5], 6.60, 2) + assert_almost_equal(df['v_wind'][5], 37.42, 2) + assert_almost_equal(df['speed'][5], 38.0, 1) + assert_almost_equal(df['direction'][5], 190.0, 1) + + assert(df.units['pressure'] == 'hPa') + assert(df.units['height'] == 'meter') + assert(df.units['temperature'] == 'degC') + assert(df.units['dewpoint'] == 'degC') + assert(df.units['u_wind'] == 'knot') + assert(df.units['v_wind'] == 'knot') + assert(df.units['speed'] == 'knot') + assert(df.units['direction'] == 'degrees') + + +@recorder.use_cassette('wyoming_high_alt_sounding') +def test_high_alt_wyoming(): + """Test Wyoming data that starts at pressure less than 925 hPa.""" + df = WyomingUpperAir.request_data(datetime(2010, 12, 9, 12), 'BOI') + + assert_almost_equal(df['pressure'][2], 890.0, 2) + assert_almost_equal(df['height'][2], 1133., 2) + assert_almost_equal(df['temperature'][2], 5.4, 2) + assert_almost_equal(df['dewpoint'][2], 3.9, 2) + assert_almost_equal(df['u_wind'][2], -0.42, 2) + assert_almost_equal(df['v_wind'][2], 5.99, 2) From 7c8e8877579f0a44b7dc90b830868ab838475bf1 Mon Sep 17 00:00:00 2001 From: "J.R. Leeman" Date: Tue, 12 Sep 2017 07:34:20 -0600 Subject: [PATCH 4/4] Add beautifulsoup4 as a dependency --- environment.yml | 1 + setup.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 2de560fc0..b6005bf34 100755 --- a/environment.yml +++ b/environment.yml @@ -31,3 +31,4 @@ dependencies: - matplotlib - xarray - cartopy + - beautifulsoup4 diff --git a/setup.py b/setup.py index ca817efe5..44394162b 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ ver = versioneer.get_version() # Need to conditionally add enum support for older Python -dependencies = ['numpy>=1.8', 'protobuf>=3.0.0a3', 'requests>=1.2'] +dependencies = ['numpy>=1.8', 'protobuf>=3.0.0a3', 'requests>=1.2', 'beautifulsoup4>=4.6'] if sys.version_info < (3, 4): dependencies.append('enum34')