怀俄明大学探空资料下载

文摘   科学   2024-07-05 08:00   北京  

前言

诸多气象学子不晓得在哪里获取探空资料,怀俄明大学的网址提供了便利。而国内的探空站点在新网址可以下载。

网址为https://weather.uwyo.edu/upperair/bufrraob.shtml

本项目旨在通过Python编程语言,实现从怀俄明大学官网下载探空资料的功能。具体地说,我们将使用Python的urllib库来获取探空数据文件,并将其保存到本地文件中。同时,我们还将解决可能出现的SSL证书验证问题。下载脚本参考了https://blog.csdn.net/weixin_43750300/article/details/130250491

优化点:将老网址替换为新网址,并对ssl验证导致的下载失败进行修复

希望本项目能够为需要获取气象探测数据的人提供便利,同时也为Python初学者提供一个实践的机会。

import sslimport urllib.request
url = 'https://weather.uwyo.edu/cgi-bin/bufrraob.py?src=bufr&datetime=2022-01-18%2000:00:00&id=54511&type=TEXT:LIST'context = ssl._create_unverified_context()response = urllib.request.urlopen(url, context=context)html = response.read().decode('utf-8')print(html)fname = 'test.txt'file = open(fname, 'w')file.write(str(html))file.close()

<HTML>
<HEAD>
<TITLE>Wyoming Weather Web</TITLE>

<link rel="stylesheet" href="/resources/weather.css" type="text/css">

</HEAD>

<BODY>
<link rel="stylesheet" href="/resources/weather.css" type="text/css">
<div id="masthead">
<table style="min-width:1005px; max-width:2400px;" width="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td><div id="logo-container">
<img lay-src="/images/uwlogo.png" border="0"></div></td>
<td valign="top" align="right">
<table>
<tr>
<td valign="top" align="right"><div id="wywx"><a href="/index.shtml">
Wyoming Weather Web</A></div></td>
</tr>
<tr>
<td valign="top" align="right" width="600">
<div id="depts">
<a href="http://www.uwyo.edu/atsc">Atmospheric Science</A> |
<a href="http://www.uwyo.edu/ceas">Engineering and Applied Science</A> |
<a href="http://www.uwyo.edu/">UWyo Home</A>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>

<!-- left menu -->
<div id="leftmenu">
<P/>
<P/>
<UL>
<LI><a href="/wyoming/">Wyoming</a></LI>
<LI><a href="/cities/">US Cities</a></LI>
<LI><a href="/surface/">Surface</a></LI>
<LI><a href="/upperair/">Upper Air</a></LI>
<UL>
<LI><A HREF="/upperair/sounding.html" TARGET="_top">TEMP Soundings</A></LI>
<LI><A HREF="/upperair/bufrraob.shtml" TARGET="_top">BUFR Soundings</A></LI>
</UL>
<LI><a href="/models/fcst/">Models</a></LI>
</UL>
<p>Other data for station: 54511</p>
<ul>
<li><a href="/cgi-bin/bufrraob.py?datetime=2022-01-17 12:00:00&id=54511&type=TEXT:LIST">1200Z Jan 17</a></li>
<li><a href="/cgi-bin/bufrraob.py?datetime=2022-01-18 12:00:00&id=54511&type=TEXT:LIST">1200Z Jan 18</a></li>
<li><a href="/cgi-bin/bufrraob.py?datetime=2022-01-18 00:00:00&id=54511&type=TEXT:CSV">Comma Separated Values</a></li>
<li><a href="/cgi-bin/bufrraob.py?datetime=2022-01-18 00:00:00&id=54511&type=PNG:SKEWT">Skew-T PNG image</a></li>
<li><a href="/cgi-bin/bufrraob.py?datetime=2022-01-18 00:00:00&id=54511&type=PNG:STUVE">Stuve PNG image</a></li>
<li><a href="/cgi-bin/bufrraob.py?datetime=2022-01-18 00:00:00&id=54511&type=PNG:STUVE10">Stuve PNG image to 10 hPa</a></li>
<li><a href="/cgi-bin/bufrraob.py?datetime=2022-01-18 00:00:00&id=54511&type=INVENTORY">Inventory for year</a></li>
</ul>
</div>

<!-- main menu -->
<div id="maincolumn">
<H1>Observations for Station 54511 starting 2315Z 17 Jan 2022</H1>
<H3>BEIJING, CHINA</H3>
<BR/><I>Latitude: 39.930 Longitude: 116.280</I>
<PRE>
-----------------------------------------------------------------------------
PRES HGHT TEMP DWPT RELH MIXR DRCT SPED THTA THTE THTV
hPa m C C % g/kg deg m/s K K K
-----------------------------------------------------------------------------
1022.5 34 -8.3 -13.9 64 1.28 33 1.9 263.2 266.7 263.4
1019.9 52 -6.4 -12.9 60 1.39 42 1.7 265.3 269.1 265.5
1013.4 101 -4.7 -12.2 56 1.48 67 1.4 267.4 271.6 267.7
1005.4 164 -4.4 -13.2 50 1.38 98 0.9 268.3 272.2 268.6
1004.6 169 -4.4 -13.2 50 1.38 100 0.9 268.4 272.3 268.6
1000.0 209 -4.3 -12.9 51 1.42 118 1.2 268.9 272.9 269.1
999.0 214 -4.2 -12.7 52 1.44 120 1.3 269.0 273.1 269.3
976.7 394 -4.5 -13.5 49 1.38 199 2.8 270.5 274.4 270.7
970.5 446 -4.0 -13.5 48 1.39 221 3.3 271.5 275.4 271.7
955.4 570 -3.3 -12.8 48 1.50 224 5.0 273.4 277.7 273.6
936.9 723 -3.8 -13.4 47 1.45 227 7.1 274.4 278.6 274.7
925.0 824 -4.2 -13.8 47 1.42 231 7.7 275.0 279.1 275.2
910.1 961 -4.6 -13.8 49 1.45 236 8.5 275.9 280.1 276.1
905.4 1004 -4.7 -14.4 47 1.39 238 8.7 276.2 280.2 276.4
896.5 1084 -4.9 -16.0 41 1.23 244 8.1 276.8 280.4 277.0
889.1 1150 -4.3 -15.5 41 1.29 248 7.6 278.0 281.9 278.3
878.4 1240 -5.1 -16.4 41 1.21 255 6.9 278.2 281.8 278.4
868.1 1335 -4.8 -18.9 32 0.99 261 6.2 279.4 282.4 279.6
852.9 1463 -5.8 -21.0 29 0.84 268 5.2 279.8 282.4 279.9
850.0 1489 -5.7 -21.2 28 0.83 269 5.0 280.2 282.7 280.3
842.1 1557 -5.8 -21.8 27 0.80 273 4.5 280.8 283.3 280.9
839.9 1577 -5.9 -22.2 26 0.77 274 4.3 280.9 283.3 281.0
815.3 1808 -6.7 -24.4 23 0.65 295 5.0 282.5 284.5 282.6
807.7 1879 -7.3 -25.1 23 0.62 302 5.2 282.6 284.5 282.7
790.9 2034 -8.7 -26.6 22 0.55 290 5.7 282.8 284.5 282.9
778.8 2155 -9.0 -27.6 21 0.51 281 6.2 283.7 285.3 283.8
776.1 2180 -9.3 -28.2 20 0.48 279 6.3 283.7 285.2 283.8
749.5 2456 -11.5 -30.4 19 0.41 268 8.6 284.1 285.4 284.2
747.2 2482 -11.4 -30.5 19 0.41 267 8.8 284.5 285.8 284.5
745.1 2507 -10.9 -30.5 18 0.41 269 9.1 285.2 286.6 285.3
737.9 2587 -10.7 -31.7 16 0.37 275 10.1 286.3 287.5 286.3
719.7 2784 -11.1 -33.6 14 0.31 290 12.5 287.9 288.9 287.9
716.5 2818 -11.2 -33.2 14 0.33 291 12.8 288.1 289.2 288.2
704.5 2944 -12.0 -33.9 14 0.31 293 13.5 288.6 289.7 288.7
700.0 2989 -11.7 -33.4 15 0.33 293 13.8 289.5 290.6 289.6
691.4 3088 -10.6 -32.9 14 0.35 295 14.4 291.7 292.9 291.8
691.0 3094 -10.6 -32.9 14 0.35 295 14.4 291.8 293.0 291.9
671.4 3317 -11.5 -33.8 14 0.33 296 15.3 293.2 294.3 293.3
634.6 3749 -14.3 -37.4 12 0.24 294 16.9 294.8 295.6 294.8
633.9 3760 -14.3 -37.4 12 0.24 294 16.9 294.9 295.7 294.9
625.7 3858 -14.4 -38.1 11 0.23 297 17.1 295.8 296.6 295.9
607.4 4077 -16.3 -39.1 12 0.21 304 17.6 296.2 296.9 296.2
600.0 4162 -16.8 -34.9 19 0.33 305 17.4 296.6 297.8 296.7
581.4 4407 -18.8 -30.3 36 0.53 306 16.8 297.0 298.8 297.1
580.1 4425 -18.9 -30.3 36 0.53 306 16.8 297.1 298.8 297.1
575.1 4490 -19.4 -30.4 37 0.53 305 17.1 297.2 299.0 297.3
559.9 4685 -20.8 -31.6 37 0.49 302 17.8 297.8 299.5 297.9
553.1 4781 -21.1 -32.8 34 0.44 300 18.2 298.5 300.0 298.6
551.0 4804 -21.1 -33.1 33 0.43 300 18.1 298.8 300.3 298.9
543.0 4910 -22.0 -34.3 32 0.39 300 17.7 299.0 300.4 299.1
533.9 5029 -23.1 -33.2 39 0.44 299 17.3 299.2 300.7 299.2
501.0 5491 -26.5 -33.8 50 0.44 300 16.8 300.5 302.0 300.6
500.0 5505 -26.6 -33.8 51 0.44 300 16.9 300.5 302.1 300.6
495.1 5585 -27.0 -34.0 51 0.44 299 16.9 300.9 302.4 301.0
477.6 5852 -29.4 -36.1 52 0.37 296 17.2 301.1 302.3 301.1
476.5 5872 -29.6 -36.3 52 0.36 296 17.2 301.0 302.3 301.1
451.9 6253 -32.0 -39.0 50 0.29 299 19.9 302.6 303.6 302.6
451.5 6259 -32.0 -39.0 50 0.29 299 20.0 302.7 303.7 302.7
428.8 6616 -35.2 -41.9 50 0.23 305 20.2 303.1 303.9 303.1
427.6 6635 -35.3 -42.0 50 0.22 305 20.2 303.2 304.0 303.2
400.0 7078 -38.1 -45.7 45 0.16 302 21.7 305.4 306.0 305.4
394.7 7171 -38.8 -46.5 44 0.15 302 22.0 305.6 306.2 305.7
392.8 7210 -39.2 -46.9 44 0.14 302 22.2 305.5 306.1 305.6
360.7 7778 -44.7 -51.2 48 0.10 302 23.6 305.7 306.1 305.7
349.9 7986 -45.9 -52.3 48 0.09 303 24.0 306.8 307.1 306.8
345.0 8076 -46.5 -53.3 46 0.08 303 23.9 307.2 307.5 307.2
330.6 8373 -49.3 -56.5 43 0.06 303 23.8 307.1 307.3 307.1
323.4 8509 -50.7 -57.9 42 0.05 304 23.4 307.1 307.3 307.1
314.2 8709 -51.7 -59.1 41 0.04 306 22.8 308.3 308.4 308.3
311.7 8761 -51.4 -59.0 40 0.04 307 22.7 309.4 309.6 309.4
307.4 8851 -51.1 -58.7 40 0.05 307 22.2 311.0 311.2 311.1
301.3 8968 -51.8 -59.5 39 0.04 307 21.5 311.8 312.0 311.9
300.0 8990 -51.7 -59.4 39 0.04 307 21.4 312.4 312.5 312.4
291.9 9157 -51.3 -59.3 38 0.04 307 20.5 315.4 315.6 315.4
285.7 9286 -51.2 -59.5 36 0.04 305 19.8 317.5 317.7 317.5
274.2 9565 -53.0 -61.7 34 0.03 302 18.3 318.6 318.8 318.6
271.4 9619 -53.6 -62.3 34 0.03 302 17.9 318.7 318.8 318.7
268.6 9700 -53.6 -62.4 33 0.03 303 17.4 319.6 319.8 319.6
261.9 9863 -54.6 -63.5 32 0.03 304 16.3 320.5 320.6 320.5
258.3 9952 -54.6 -63.6 32 0.03 305 15.7 321.7 321.9 321.8
257.3 9972 -54.8 -63.9 31 0.03 305 15.6 321.8 321.9 321.8
250.0 10164 -55.7 -64.9 31 0.02 304 15.8 323.1 323.2 323.1
242.3 10381 -56.4 -65.7 30 0.02 303 16.1 325.0 325.1 325.0
241.0 10422 -56.6 -66.0 30 0.02 302 16.4 325.2 325.3 325.2
233.0 10641 -55.9 -65.5 29 0.02 298 18.3 329.4 329.5 329.4
227.2 10792 -56.3 -66.0 28 0.02 295 19.6 331.2 331.3 331.2
221.3 10948 -56.4 -66.2 28 0.02 295 19.8 333.5 333.6 333.5
219.5 11010 -54.4 -64.4 28 0.03 295 19.9 337.4 337.5 337.4
207.6 11345 -55.2 -65.6 26 0.03 296 21.0 341.5 341.7 341.5
201.9 11516 -54.4 -65.1 26 0.03 297 22.1 345.5 345.7 345.5
200.0 11585 -54.7 -65.5 25 0.03 297 22.5 346.0 346.1 346.0
197.0 11669 -55.5 -66.3 25 0.03 297 22.8 346.2 346.3 346.2
193.2 11797 -54.9 -66.0 24 0.03 296 23.1 349.1 349.2 349.1
185.4 12039 -56.2 -67.5 23 0.02 295 23.7 351.1 351.2 351.1
184.4 12067 -56.2 -67.5 23 0.02 294 23.8 351.7 351.8 351.7
179.1 12237 -54.6 -66.3 22 0.03 290 23.9 357.2 357.4 357.2
173.4 12465 -53.8 -65.7 22 0.03 285 24.1 361.9 362.0 361.9
171.2 12557 -53.6 -65.6 22 0.03 283 25.3 363.5 363.7 363.5
169.1 12621 -54.3 -66.4 21 0.03 282 26.1 363.6 363.8 363.7
162.1 12891 -54.1 -66.5 20 0.03 276 29.6 368.4 368.6 368.4
161.5 12919 -53.7 -66.2 20 0.03 276 29.7 369.5 369.6 369.5
153.5 13253 -55.3 -68.0 19 0.03 278 30.3 372.1 372.3 372.1
152.2 13317 -55.0 -67.8 19 0.03 278 30.4 373.6 373.7 373.6
150.0 13425 -54.8 -67.7 19 0.03 279 29.3 375.5 375.6 375.5
149.5 13450 -54.8 -67.7 19 0.03 279 29.1 375.8 376.0 375.8
143.2 13723 -56.4 -69.5 18 0.02 280 26.3 377.7 377.8 377.7
142.2 13776 -56.6 -69.7 18 0.02 280 26.0 378.1 378.2 378.1
139.0 13895 -55.5 -68.9 17 0.03 279 25.6 382.5 382.6 382.5
134.6 14122 -55.5 -69.0 17 0.03 277 24.7 386.0 386.2 386.0
129.1 14393 -56.0 -69.7 16 0.02 279 24.8 389.7 389.9 389.8
119.8 14865 -54.6 -68.7 16 0.03 285 25.5 400.7 400.9 400.7
110.7 15317 -55.7 -70.1 15 0.03 289 25.4 407.8 408.0 407.8
109.1 15403 -56.2 -70.6 15 0.03 289 25.3 408.6 408.7 408.6
105.9 15596 -55.4 -70.0 15 0.03 288 25.0 413.6 413.7 413.6
101.3 15921 -56.6 -71.2 14 0.03 287 24.3 416.6 416.7 416.6
100.0 16006 -56.3 -71.0 14 0.03 287 24.1 418.7 418.8 418.7
</PRE>

<div id="footer">
<p/>
<HR SIZE="1">
<I>Interested in graduate studies in atmospheric science?
Check out our program at the
<a href="http://www.uwyo.edu/atsc/howtoapply/"
target=_top>University of Wyoming
</a></I>
<HR SIZE="1"><FONT SIZE="-1">
Questions about the weather data provided by this site can be
addressed to <A HREF="mailto:ldoolman@uwyo.edu">
Larry Oolman (ldoolman@uwyo.edu)</A></FONT>
<HR SIZE="1">
</div>

</div>
</BODY>
</HTML>

循环下载脚本

In [14]:

import urllib.requestimport osimport calendarimport sslurl0 = 'https://weather.uwyo.edu/cgi-bin/bufrraob.py?'stids = ['54511']hrs = '00'hre = '12'hr = ['00', '12']
for stname in stids: path = './' if os.path.isdir(path): pass else: os.mkdir(path) for y in range(2022, 2022): yr = str(y) for m in range(1, 2): if m < 10: mn = '0' + str(m) else: mn = str(m) day_num = calendar.monthrange(y, m)[1] for d in range(1, day_num+1): if d < 10: dy = "0" + str(d) else: dy = str(d) for h in hr: url = url0 + 'src=bufr&datetime=' + yr + '-' + mn + '-' + dy + '%20' + h + ':00:00&id=' + stname + '&type=TEXT:LIST' try: print(url) context = ssl._create_unverified_context() response = urllib.request.urlopen(url, context=context) html = response.read().decode('utf-8') # resp = urllib.request.urlopen(url) # html = resp.read() fname = path + stname + '-' + yr + mn + dy + h + '.txt' file = open(fname, 'w') file.write(str(html)) file.close() print(fname) except Exception: print("下载失败")

完结撒花

你说这格式不好整啊

别急,请看另一篇文章

气python风雨
主要发一些涉及大气科学的Python文章与个人学习备忘录
 最新文章