| 1 |
"""Test the main Metar Library.""" |
| 2 |
import warnings |
| 3 |
from datetime import datetime, timedelta, timezone |
| 4 |
|
| 5 |
import pytest |
| 6 |
import metar |
| 7 |
from metar import Metar |
| 8 |
|
| 9 |
|
| 10 |
sta_time = "KEWR 101651Z " |
| 11 |
sta_time_mod = "KEWR 101651Z AUTO " |
| 12 |
sta_time_wind = "KEWR 101651Z 00000KT " |
| 13 |
|
| 14 |
today = datetime.now(timezone.utc) |
| 15 |
tomorrow = today + timedelta(days=1) |
| 16 |
|
| 17 |
|
| 18 |
def raisesParserError(code): |
| 19 |
"""Helper to test the a given code raises a Metar.ParserError.""" |
| 20 |
with pytest.raises(Metar.ParserError): |
| 21 |
Metar.Metar(code) |
| 22 |
|
| 23 |
|
| 24 |
def test_xlate_loc(): |
| 25 |
"""Test that xlate_loc does the right thing.""" |
| 26 |
Metar.debug = True |
| 27 |
report = Metar.Metar( |
| 28 |
"METAR KEWR 111851Z VRB03G19KT 2SM R04R/3000VP6000FT TSRA BR FEW015 " |
| 29 |
"BKN040CB BKN065 OVC200 22/22 A2987 RMK AO2 PK WND 29028/1817 WSHFT " |
| 30 |
"1812 TSB05RAB22 SLP114 FRQ LTGICCCCG TS OHD AND NW-N-E MOV NE " |
| 31 |
"P0013 T02270215" |
| 32 |
) |
| 33 |
mstring = str(report) |
| 34 |
assert mstring.find("thunderstorm overhead") > -1 |
| 35 |
|
| 36 |
|
| 37 |
def test_module(): |
| 38 |
"""Test that module level things are defined.""" |
| 39 |
assert hasattr(metar, "__version__") |
| 40 |
|
| 41 |
|
| 42 |
def test_issue114_multiplebecominggroups(): |
| 43 |
"""multiple BECMG (becoming) groups should be possible""" |
| 44 |
code = ( |
| 45 |
"METAR WSSS 280900Z 26009KT 180V350 0600 R20R/1900D R20C/1600D +TSRA FEW008 SCT013CB FEW015TCU 24/23 Q1010 " |
| 46 |
"BECMG FM0920 TL0930 3000 TSRA " |
| 47 |
"BECMG FM1000 TL1020 6000 NSW" |
| 48 |
) |
| 49 |
|
| 50 |
metar = Metar.Metar(code) |
| 51 |
assert metar.decode_completed |
| 52 |
assert len(metar._trend_groups) == 10 |
| 53 |
assert metar.trend() == "BECMG FM0920 TL0930 3000 TSRA BECMG FM1000 TL1020 6000 NSW" |
| 54 |
|
| 55 |
|
| 56 |
@pytest.mark.parametrize("trailstr", ["", "=", "= "]) |
| 57 |
def test_issue84_trimequals(trailstr): |
| 58 |
"""A trailing = in METAR should not trip up the ingest.""" |
| 59 |
code = ( |
| 60 |
"KABI 031752Z 30010KT 6SM BR FEW009 OVC036 02/01 A3003 RMK AO2 " |
| 61 |
"SLP176 60001 I%i003 T00170006 10017 21006 56017" |
| 62 |
) |
| 63 |
assert Metar.Metar("%s%s" % (code, trailstr)).decode_completed |
| 64 |
|
| 65 |
|
| 66 |
@pytest.mark.parametrize("hours", [1, 3, 6]) |
| 67 |
def test_issue77_ice_accretion(hours): |
| 68 |
"""Metar parser supports ice accretion data.""" |
| 69 |
report = Metar.Metar( |
| 70 |
( |
| 71 |
"KABI 031752Z 30010KT 6SM BR FEW009 OVC036 02/01 A3003 RMK AO2 " |
| 72 |
"SLP176 60001 I%i003 T00170006 10017 21006 56017" |
| 73 |
) |
| 74 |
% (hours,) |
| 75 |
) |
| 76 |
myattr = "ice_accretion_%ihr" % (hours,) |
| 77 |
assert abs(getattr(report, myattr).value("IN") - 0.03) < 0.001 |
| 78 |
assert str(report).find("Ice Accretion") > 0 |
| 79 |
|
| 80 |
|
| 81 |
def test_issue64_cloudkeyerror(): |
| 82 |
"""Lookup on CLOUD_TYPE should not keyerror.""" |
| 83 |
report = Metar.Metar( |
| 84 |
"METAR LOXZ 141420Z 08006KT 20KM VCSH FEW025SC SCT040SC BKN090AC " |
| 85 |
"21/14 Q1015 BECMG SCT090" |
| 86 |
) |
| 87 |
res = report.sky_conditions() |
| 88 |
ans = ( |
| 89 |
"a few stratocumulus at 2500 feet; scattered stratocumulus at " |
| 90 |
"4000 feet; broken altocumulus at 9000 feet" |
| 91 |
) |
| 92 |
assert res == ans |
| 93 |
mstring = report.string() |
| 94 |
assert mstring.find("altocumulus") > -1 |
| 95 |
|
| 96 |
|
| 97 |
def test_issue67_precip_text(): |
| 98 |
"""Check that precip_text is properly defined in present_weather.""" |
| 99 |
report = Metar.Metar( |
| 100 |
"METAR FSIA 220100Z AUTO 14014KT 120V180 9999 ///////// " "27/23 Q1010" |
| 101 |
) |
| 102 |
res = report.present_weather() |
| 103 |
assert res == "/////////" |
| 104 |
|
| 105 |
|
| 106 |
def test_issue40_runwayunits(): |
| 107 |
"""Check reported units on runway visual range.""" |
| 108 |
report = Metar.Metar( |
| 109 |
"METAR KPIT 091955Z COR 22015G25KT 3/4SM R28L/2600FT TSRA OVC010CB " |
| 110 |
"18/16 A2992 RMK SLP045 T01820159" |
| 111 |
) |
| 112 |
res = report.runway_visual_range() |
| 113 |
assert res == "on runway 28L, 2600 feet" |
| 114 |
res = report.runway_visual_range("M") |
| 115 |
assert res == "on runway 28L, 792 meters" |
| 116 |
|
| 117 |
def test_issue107_runwayunits(): |
| 118 |
"""Check reported units on runway visual range defaulting to meters.""" |
| 119 |
report = Metar.Metar( |
| 120 |
"METAR KPIT 091955Z COR 22015G25KT 3/4SM R28L/1500 TSRA OVC010CB " |
| 121 |
"18/16 A2992 RMK SLP045 T01820159" |
| 122 |
) |
| 123 |
res = report.runway_visual_range() |
| 124 |
assert res == "on runway 28L, 1500 meters" |
| 125 |
res = report.runway_visual_range("FT") |
| 126 |
assert res == "on runway 28L, 4921 feet" |
| 127 |
|
| 128 |
@pytest.mark.parametrize("RVR", ["R28L/////", "R28L/////FT", "R28L//////", "R28L/////N"]) |
| 129 |
def test_issue26_runway_slashes(RVR): |
| 130 |
"""Check RVR with slashes decoding.""" |
| 131 |
report = Metar.Metar( |
| 132 |
"METAR KPIT 091955Z COR 22015G25KT 3/4SM R28L/2600FT {} TSRA OVC010CB " |
| 133 |
"18/16 A2992 RMK SLP045 T1820160".format(RVR) |
| 134 |
) |
| 135 |
assert len(report.runway) == 1 |
| 136 |
|
| 137 |
def test_010_parseType_default(): |
| 138 |
"""Check default value of the report type.""" |
| 139 |
assert Metar.Metar("KEWR").type == "METAR" |
| 140 |
|
| 141 |
|
| 142 |
def test_011_parseType_legal(): |
| 143 |
"""Check parsing of the report type.""" |
| 144 |
assert Metar.Metar("METAR").type, "METAR" |
| 145 |
assert Metar.Metar("SPECI").type, "SPECI" |
| 146 |
assert Metar.Metar("METAR").correction is None |
| 147 |
assert Metar.Metar("METAR COR").correction == "COR" |
| 148 |
raisesParserError("TAF") |
| 149 |
|
| 150 |
|
| 151 |
def test_020_parseStation_legal(): |
| 152 |
"""Check parsing of the station code.""" |
| 153 |
assert Metar.Metar("KEWR").station_id == "KEWR" |
| 154 |
assert Metar.Metar("METAR KEWR").station_id == "KEWR" |
| 155 |
assert Metar.Metar("METAR COR KEWR").station_id == "KEWR" |
| 156 |
assert Metar.Metar("BIX1").station_id == "BIX1" |
| 157 |
assert Metar.Metar("K256").station_id == "K256" |
| 158 |
|
| 159 |
|
| 160 |
def test_021_parseStation_illegal(): |
| 161 |
"""Check rejection of illegal station codes.""" |
| 162 |
raisesParserError("1ABC") |
| 163 |
raisesParserError("METAR METAR") |
| 164 |
raisesParserError("METAR DC") |
| 165 |
raisesParserError("METAR A") |
| 166 |
raisesParserError("kewr") |
| 167 |
|
| 168 |
|
| 169 |
def test_030_parseTime_legal(): |
| 170 |
"""Check parsing of the time stamp.""" |
| 171 |
report = Metar.Metar("KEWR 101651Z") |
| 172 |
assert report.decode_completed |
| 173 |
assert report.time.day == 10 |
| 174 |
assert report.time.hour == 16 |
| 175 |
assert report.time.minute == 51 |
| 176 |
if today.day > 10 or (today.hour > 16 and today.day == 10): |
| 177 |
assert report.time.month == today.month |
| 178 |
if today.month > 1 or today.day > 10: |
| 179 |
assert report.time.year == today.year |
| 180 |
|
| 181 |
|
| 182 |
def test_031_parseTime_specify_year(): |
| 183 |
"""Check that the year can be specified.""" |
| 184 |
other_year = 2003 |
| 185 |
|
| 186 |
report = Metar.Metar("KEWR 101651Z", year=other_year) |
| 187 |
assert report.decode_completed |
| 188 |
assert report.time.year == other_year |
| 189 |
|
| 190 |
|
| 191 |
def test_032_parseTime_specify_month(): |
| 192 |
"""Check that the month can be specified.""" |
| 193 |
last_month = ((today.month - 2) % 12) + 1 |
| 194 |
|
| 195 |
report = Metar.Metar("KEWR 101651Z", month=last_month) |
| 196 |
assert report.decode_completed |
| 197 |
assert report.time.month == last_month |
| 198 |
|
| 199 |
|
| 200 |
def test_033_parseTime_auto_month(): |
| 201 |
"""Test assignment of time to previous month.""" |
| 202 |
|
| 203 |
|
| 204 |
last_month = today.replace(day=1) - timedelta(days=1) |
| 205 |
if last_month.day <= today.day: |
| 206 |
return |
| 207 |
|
| 208 |
report = Metar.Metar(f"KEWR {last_month.day:02.0f}1651Z") |
| 209 |
assert report.decode_completed |
| 210 |
assert report.time.day == last_month.day |
| 211 |
assert report.time.month == last_month.month |
| 212 |
assert report.time.year == last_month.year |
| 213 |
|
| 214 |
|
| 215 |
def test_034_parseTime_auto_year(): |
| 216 |
"""Check that year is adjusted if specified month is in the future.""" |
| 217 |
next_month = (today.month % 12) + 1 |
| 218 |
last_year = today.year - 1 |
| 219 |
|
| 220 |
report = Metar.Metar("KEWR 101651Z", month=next_month) |
| 221 |
assert report.decode_completed |
| 222 |
assert report.time.month == next_month |
| 223 |
if next_month > 1: |
| 224 |
assert report.time.year == last_year |
| 225 |
else: |
| 226 |
assert report.time.year == today.year |
| 227 |
|
| 228 |
|
| 229 |
def test_035_parseTime_suppress_auto_month(): |
| 230 |
"""Check that explicit month suppresses automatic month rollback.""" |
| 231 |
next_day = tomorrow.day |
| 232 |
if next_day > today.day: |
| 233 |
last_year = today.year - 1 |
| 234 |
|
| 235 |
timestr = "%02d1651Z" % (next_day) |
| 236 |
report = Metar.Metar("KEWR " + timestr, month=1) |
| 237 |
assert report.decode_completed |
| 238 |
assert report.time.day == next_day |
| 239 |
assert report.time.month == 1 |
| 240 |
if today.month > 1: |
| 241 |
assert report.time.year == today.year |
| 242 |
else: |
| 243 |
assert report.time.year == last_year |
| 244 |
|
| 245 |
|
| 246 |
def test_040_parseModifier_default(): |
| 247 |
"""Check default 'modifier' value.""" |
| 248 |
assert Metar.Metar("KEWR").mod == "AUTO" |
| 249 |
|
| 250 |
|
| 251 |
def test_041_parseModifier(): |
| 252 |
"""Check parsing of 'modifier' groups.""" |
| 253 |
assert Metar.Metar(sta_time + "AUTO").mod == "AUTO" |
| 254 |
assert Metar.Metar(sta_time + "COR").mod == "COR" |
| 255 |
|
| 256 |
|
| 257 |
def test_042_parseModifier_nonstd(): |
| 258 |
"""Check parsing of nonstandard 'modifier' groups.""" |
| 259 |
|
| 260 |
def report(mod_group): |
| 261 |
"""(Macro) Return Metar object from parsing the modifier group.""" |
| 262 |
return Metar.Metar(sta_time + mod_group) |
| 263 |
|
| 264 |
assert report("RTD").mod == "RTD" |
| 265 |
assert report("TEST").mod == "TEST" |
| 266 |
assert report("CCA").mod == "CCA" |
| 267 |
assert report("CCB").mod == "CCB" |
| 268 |
assert report("CCC").mod == "CCC" |
| 269 |
assert report("CCD").mod == "CCD" |
| 270 |
assert report("CCE").mod == "CCE" |
| 271 |
assert report("CCF").mod == "CCF" |
| 272 |
assert report("CCG").mod == "CCG" |
| 273 |
assert report("CORR").mod == "COR" |
| 274 |
assert report("FINO").mod == "NO DATA" |
| 275 |
assert report("NIL").mod == "NO DATA" |
| 276 |
|
| 277 |
|
| 278 |
def test_043_parseModifier_illegal(): |
| 279 |
"""Check rejection of illegal 'modifier' groups.""" |
| 280 |
raisesParserError(sta_time + "auto") |
| 281 |
raisesParserError(sta_time + "CCH") |
| 282 |
raisesParserError(sta_time + "MAN") |
| 283 |
|
| 284 |
|
| 285 |
def test_140_parseWind(): |
| 286 |
"""Check parsing of wind groups.""" |
| 287 |
report = Metar.Metar(sta_time + "09010KT") |
| 288 |
assert report.decode_completed |
| 289 |
assert report.wind_dir.value() == 90 |
| 290 |
assert report.wind_speed.value() == 10 |
| 291 |
assert report.wind_gust is None |
| 292 |
assert report.wind_dir_from is None |
| 293 |
assert report.wind_dir_from is None |
| 294 |
assert report.wind() == "E at 10 knots" |
| 295 |
|
| 296 |
report = Metar.Metar(sta_time + "09010MPS") |
| 297 |
assert report.decode_completed |
| 298 |
assert report.wind_speed.value() == 10 |
| 299 |
assert report.wind_speed.value("KMH") == 36 |
| 300 |
assert report.wind() == "E at 19 knots" |
| 301 |
assert report.wind("MPS") == "E at 10 mps" |
| 302 |
assert report.wind("KMH") == "E at 36 km/h" |
| 303 |
|
| 304 |
report = Metar.Metar(sta_time + "09010KMH") |
| 305 |
assert report.decode_completed |
| 306 |
assert report.wind_speed.value() == 10 |
| 307 |
assert report.wind() == "E at 5 knots" |
| 308 |
assert report.wind("KMH") == "E at 10 km/h" |
| 309 |
|
| 310 |
report = Metar.Metar(sta_time + "090010KT") |
| 311 |
assert report.decode_completed |
| 312 |
assert report.wind_dir.value() == 90 |
| 313 |
assert report.wind_speed.value() == 10 |
| 314 |
|
| 315 |
report = Metar.Metar(sta_time + "000000KT") |
| 316 |
assert report.decode_completed |
| 317 |
assert report.wind_dir.value() == 0 |
| 318 |
assert report.wind_speed.value() == 0 |
| 319 |
assert report.wind() == "calm" |
| 320 |
|
| 321 |
report = Metar.Metar(sta_time + "VRB03KT") |
| 322 |
assert report.decode_completed |
| 323 |
assert report.wind_dir is None |
| 324 |
assert report.wind_speed.value() == 3 |
| 325 |
assert report.wind() == "variable at 3 knots" |
| 326 |
|
| 327 |
report = Metar.Metar(sta_time + "VRB00KT") |
| 328 |
assert report.decode_completed |
| 329 |
assert report.wind() == "calm" |
| 330 |
|
| 331 |
report = Metar.Metar(sta_time + "VRB03G40KT") |
| 332 |
assert report.decode_completed |
| 333 |
assert report.wind_dir is None |
| 334 |
assert report.wind_speed.value() == 3 |
| 335 |
assert report.wind_gust.value() == 40 |
| 336 |
assert report.wind_dir_from is None |
| 337 |
assert report.wind_dir_to is None |
| 338 |
assert report.wind() == "variable at 3 knots, gusting to 40 knots" |
| 339 |
|
| 340 |
report = Metar.Metar(sta_time + "21010G30KT") |
| 341 |
assert report.decode_completed |
| 342 |
assert report.wind() == "SSW at 10 knots, gusting to 30 knots" |
| 343 |
|
| 344 |
report = Metar.Metar(sta_time + "21010KT 180V240") |
| 345 |
assert report.wind_dir.value() == 210 |
| 346 |
assert report.wind_speed.value() == 10 |
| 347 |
assert report.wind_gust is None |
| 348 |
assert report.wind_dir_from.value() == 180 |
| 349 |
assert report.wind_dir_to.value() == 240 |
| 350 |
assert report.wind() == "S to WSW at 10 knots" |
| 351 |
|
| 352 |
|
| 353 |
def test_141_parseWind_nonstd(): |
| 354 |
"""Check parsing of nonstandard wind groups.""" |
| 355 |
|
| 356 |
def report(wind_group): |
| 357 |
"""(Macro) Return Metar object from parsing the given wind group.""" |
| 358 |
return Metar.Metar(sta_time + wind_group) |
| 359 |
|
| 360 |
assert report("OOOOOKT").wind_speed.value() == 0 |
| 361 |
assert report("OOOOOKT").wind() == "calm" |
| 362 |
|
| 363 |
assert report("09010K").wind_speed.string() == "10 knots" |
| 364 |
assert report("09010T").wind_speed.string() == "10 knots" |
| 365 |
assert report("09010LT").wind_speed.string() == "10 knots" |
| 366 |
assert report("09010KTS").wind_speed.string() == "10 knots" |
| 367 |
|
| 368 |
assert report("09010").wind_speed.string() == "10 knots" |
| 369 |
|
| 370 |
assert report("VRBOOK").wind_speed.value() == 0 |
| 371 |
assert report("VRBOOK").wind() == "calm" |
| 372 |
|
| 373 |
assert report("///00KT").wind() == "calm" |
| 374 |
assert report("/////KT").wind() == "missing" |
| 375 |
assert report("000//KT").wind() == "missing" |
| 376 |
assert report("/////").wind() == "missing" |
| 377 |
|
| 378 |
assert report("09010G//KT").wind_gust is None |
| 379 |
assert report("09010GMKT").wind_gust is None |
| 380 |
assert report("09010GMMKT").wind_gust is None |
| 381 |
assert report("09010G7KT").wind_gust.value() == 7 |
| 382 |
|
| 383 |
assert report("MMM00KT").wind() == "calm" |
| 384 |
assert report("MMMMMKT").wind() == "missing" |
| 385 |
assert report("000MMKT").wind() == "missing" |
| 386 |
assert report("MMMMM").wind() == "missing" |
| 387 |
assert report("MMMMMGMMKT").wind() == "missing" |
| 388 |
assert report("MMMMMG01KT").wind() == "missing" |
| 389 |
|
| 390 |
|
| 391 |
def test_issue139_no_wind_unit(): |
| 392 |
"""Check the default wind speed units for international sites.""" |
| 393 |
report = Metar.Metar("CXXX 101651Z 09010G20") |
| 394 |
assert report.wind_speed.string() == "10 mps" |
| 395 |
|
| 396 |
|
| 397 |
def test_issue51_strict(): |
| 398 |
"""Check that setting strict=False prevents a ParserError""" |
| 399 |
with warnings.catch_warnings(record=True) as w: |
| 400 |
report = Metar.Metar(sta_time + "90010KT", strict=False) |
| 401 |
assert len(w) == 1 |
| 402 |
assert report.wind_speed is None |
| 403 |
|
| 404 |
|
| 405 |
def test_142_parseWind_illegal(): |
| 406 |
"""Check rejection of illegal wind groups.""" |
| 407 |
raisesParserError(sta_time + "90010KT") |
| 408 |
raisesParserError(sta_time + "9010KT") |
| 409 |
raisesParserError(sta_time + "09010 KT") |
| 410 |
raisesParserError(sta_time + "09010FPS") |
| 411 |
raisesParserError(sta_time + "09010MPH") |
| 412 |
raisesParserError(sta_time + "00///KT") |
| 413 |
raisesParserError(sta_time + "VAR10KT") |
| 414 |
raisesParserError(sta_time + "21010KT 180-240") |
| 415 |
raisesParserError(sta_time + "123UnME") |
| 416 |
|
| 417 |
|
| 418 |
def test_150_parseVisibility(): |
| 419 |
"""Check parsing of visibility groups.""" |
| 420 |
|
| 421 |
def report(vis_group): |
| 422 |
"""(Macro) Return Metar object for a report with the vis group.""" |
| 423 |
return Metar.Metar(sta_time + "09010KT " + vis_group) |
| 424 |
|
| 425 |
def report_nowind(vis_group): |
| 426 |
"""(Macro) Return Metar object for a report containing the given |
| 427 |
visibility group, without a preceeding wind group. |
| 428 |
""" |
| 429 |
return Metar.Metar(sta_time + vis_group) |
| 430 |
|
| 431 |
assert report("10SM").vis.value() == 10 |
| 432 |
assert report("10SM").vis_dir is None |
| 433 |
assert report("10SM").max_vis is None |
| 434 |
assert report("10SM").max_vis_dir is None |
| 435 |
assert report("10SM").visibility() == "10 miles" |
| 436 |
|
| 437 |
assert report("3/8SM").vis.value() == 0.375 |
| 438 |
assert report("3/8SM").vis_dir is None |
| 439 |
assert report("3/8SM").max_vis is None |
| 440 |
assert report("3/8SM").max_vis_dir is None |
| 441 |
assert report("3/8SM").visibility() == "3/8 miles" |
| 442 |
|
| 443 |
assert report("1 3/4SM").vis.value() == 1.75 |
| 444 |
assert report("1 3/4SM").vis_dir is None |
| 445 |
assert report("1 3/4SM").max_vis is None |
| 446 |
assert report("1 3/4SM").max_vis_dir is None |
| 447 |
assert report("1 3/4SM").visibility() == "1 3/4 miles" |
| 448 |
|
| 449 |
assert report("5000").vis.value() == 5000 |
| 450 |
assert report("5000").vis_dir is None |
| 451 |
assert report("5000").visibility() == "5000 meters" |
| 452 |
assert report("5000M").visibility() == "5000 meters" |
| 453 |
|
| 454 |
assert report_nowind("5000").vis.value() == 5000 |
| 455 |
assert report_nowind("1000W 3000").vis.value() == 1000 |
| 456 |
assert report_nowind("1000 3000NE").vis.value() == 1000 |
| 457 |
|
| 458 |
assert report("CAVOK").vis.value() == 10000 |
| 459 |
assert report("CAVOK").vis_dir is None |
| 460 |
assert report("CAVOK").max_vis is None |
| 461 |
assert report("CAVOK").max_vis_dir is None |
| 462 |
assert report("CAVOK").visibility(), "10000 meters" |
| 463 |
|
| 464 |
assert report("1000W 3000").vis.value() == 1000 |
| 465 |
assert report("1000W 3000").vis_dir.value() == 270 |
| 466 |
assert report("1000W 3000").max_vis.value() == 3000 |
| 467 |
assert report("1000W 3000").max_vis_dir is None |
| 468 |
assert report("1000W 3000").visibility() == "1000 meters to W; 3000 meters" |
| 469 |
|
| 470 |
assert report("1000 3000NE").vis.value() == 1000 |
| 471 |
assert report("1000 3000NE").vis_dir is None |
| 472 |
assert report("1000 3000NE").max_vis.value() == 3000 |
| 473 |
assert report("1000 3000NE").max_vis_dir.value() == 45 |
| 474 |
ans = "1000 meters; 3000 meters to NE" |
| 475 |
assert report("1000 3000NE").visibility() == ans |
| 476 |
|
| 477 |
assert report("5KM").vis.value() == 5 |
| 478 |
assert report("5KM").vis_dir is None |
| 479 |
assert report("5KM").visibility() == "5.0 km" |
| 480 |
|
| 481 |
assert report("5000E").vis.value() == 5000 |
| 482 |
assert report("5000E").visibility() == "5000 meters to E" |
| 483 |
|
| 484 |
assert report("7000NDV").vis.value() == 7000 |
| 485 |
assert report("7000NDV").vis_dir is None |
| 486 |
assert report("7000NDV").visibility() == "7000 meters" |
| 487 |
|
| 488 |
assert report("M1000").vis.value() == 1000 |
| 489 |
assert report("M1000").visibility() == "less than 1000 meters" |
| 490 |
|
| 491 |
assert report("P6000").vis.value() == 6000 |
| 492 |
assert report("P6000").visibility() == "greater than 6000 meters" |
| 493 |
|
| 494 |
|
| 495 |
def test_151_parseVisibility_direction(): |
| 496 |
"""Check parsing of compass headings visibility groups.""" |
| 497 |
|
| 498 |
def report(vis_group): |
| 499 |
"""(Macro) Return Metar object for a report given vis group.""" |
| 500 |
return Metar.Metar(sta_time + "09010KT " + vis_group) |
| 501 |
|
| 502 |
assert report("5000N").vis_dir.compass() == "N" |
| 503 |
assert report("5000N").vis_dir.value() == 0 |
| 504 |
assert report("5000NE").vis_dir.compass() == "NE" |
| 505 |
assert report("5000NE").vis_dir.value() == 45 |
| 506 |
assert report("5000E").vis_dir.compass() == "E" |
| 507 |
assert report("5000E").vis_dir.value() == 90 |
| 508 |
assert report("5000SE").vis_dir.compass() == "SE" |
| 509 |
assert report("5000SE").vis_dir.value() == 135 |
| 510 |
assert report("5000S").vis_dir.compass() == "S" |
| 511 |
assert report("5000S").vis_dir.value() == 180 |
| 512 |
assert report("5000SW").vis_dir.compass() == "SW" |
| 513 |
assert report("5000SW").vis_dir.value() == 225 |
| 514 |
assert report("5000W").vis_dir.compass() == "W" |
| 515 |
assert report("5000W").vis_dir.value() == 270 |
| 516 |
assert report("5000NW").vis_dir.compass() == "NW" |
| 517 |
assert report("5000NW").vis_dir.value() == 315 |
| 518 |
|
| 519 |
|
| 520 |
def test_152_parseVisibility_with_following_temperature(): |
| 521 |
"""Check parsing of visibility groups followed immediately by a group.""" |
| 522 |
|
| 523 |
def report(vis_group): |
| 524 |
"""(Macro) Return Metar object for a report given visibility group.""" |
| 525 |
return Metar.Metar(sta_time + "09010KT " + vis_group) |
| 526 |
|
| 527 |
assert report("CAVOK 02/01").vis.value() == 10000 |
| 528 |
assert report("CAVOK 02/01").vis_dir is None |
| 529 |
assert report("CAVOK 02/01").max_vis is None |
| 530 |
assert report("CAVOK 02/01").temp.value() == 2.0 |
| 531 |
assert report("CAVOK 02/01").dewpt.value() == 1.0 |
| 532 |
|
| 533 |
assert report("5000 02/01").vis.value() == 5000 |
| 534 |
assert report("5000 02/01").vis_dir is None |
| 535 |
assert report("5000 02/01").max_vis is None |
| 536 |
assert report("5000 02/01").temp.value() == 2.0 |
| 537 |
assert report("5000 02/01").dewpt.value() == 1.0 |
| 538 |
|
| 539 |
|
| 540 |
def test_290_ranway_state(): |
| 541 |
"""Check parsing of runway state groups.""" |
| 542 |
|
| 543 |
def report(runway_state): |
| 544 |
"""(Macro) Return Metar object for given runway state group""" |
| 545 |
sample_metar = ( |
| 546 |
"EGNX 191250Z VRB03KT 9999 -RASN FEW008 SCT024 " "BKN046 M01/M03 Q0989 " |
| 547 |
) |
| 548 |
return Metar.Metar(sample_metar + " " + runway_state) |
| 549 |
|
| 550 |
assert report("09690692 27550591").temp.value() == -1.0 |
| 551 |
assert report("09690692 27550591").remarks() == "" |
| 552 |
|
| 553 |
assert report("09SNOCLO").remarks() == "" |
| 554 |
assert report("09CLRD//").remarks() == "" |
| 555 |
|
| 556 |
assert report("R/SNOCLO").remarks() == "" |
| 557 |
assert report("R09/CLRD//").remarks() == "" |
| 558 |
|
| 559 |
assert report("R01R/SNOCLO ").remarks() == "" |
| 560 |
|
| 561 |
|
| 562 |
def test_300_parseTrend(): |
| 563 |
"""Check parsing of trend forecasts.""" |
| 564 |
|
| 565 |
def report(trend_group, remarks=""): |
| 566 |
"""(Macro) |
| 567 |
Return Metar object for a report containing the given trend |
| 568 |
forecast and remarks. |
| 569 |
""" |
| 570 |
sample_metar = sta_time + "09010KT 10SM -SN OVC020 23/05 Q1001" |
| 571 |
return Metar.Metar(sample_metar + " " + trend_group + " " + remarks) |
| 572 |
|
| 573 |
assert report("TEMPO FM0306 BKN030CU").trend() == "TEMPO FM0306 BKN030CU" |
| 574 |
assert report("TEMPO FM0306 BKN030CU").temp.value() == 23.0 |
| 575 |
assert report("TEMPO FM0306 BKN030CU").remarks() == "" |
| 576 |
|
| 577 |
assert report("BECMG 0306 VRB06KT").trend() == "BECMG 0306 VRB06KT" |
| 578 |
assert report("FCST AT0327 +FC").trend() == "FCST AT0327 +FC" |
| 579 |
|
| 580 |
assert report("TEMPO 0306 1/2SM").trend() == "TEMPO 0306 1/2SM" |
| 581 |
ans = "TEMPO FM0306 TL0345 01030G50KT" |
| 582 |
assert report(ans).trend() == ans |
| 583 |
|
| 584 |
assert report("TEMPO 0306 RMK 402500072").trend() == "TEMPO 0306" |
| 585 |
assert report("TEMPO 0306 RMK 402500072").max_temp_24hr.value() == 25.0 |
| 586 |
|
| 587 |
|
| 588 |
def test_snowdepth(): |
| 589 |
"""Check parsing of 4/ group snowdepth""" |
| 590 |
sample_metar = ( |
| 591 |
"KDOV 040558Z 23004KT 1 1/2SM R01/2800FT -SN BR " |
| 592 |
"OVC006 M01/M01 A3015 RMK AO2A SLP213 P0000 4/001 " |
| 593 |
"60010 T10071007 10017 " |
| 594 |
"21009 55016 VISNO RWY19 CHINO RWY19 $" |
| 595 |
) |
| 596 |
m = Metar.Metar(sample_metar) |
| 597 |
assert m.snowdepth.value() == 1 |
| 598 |
|
| 599 |
|
| 600 |
def test_310_parse_sky_conditions(): |
| 601 |
"""Check parsing of sky conditions.""" |
| 602 |
|
| 603 |
def report(sky_conditions): |
| 604 |
"""(Macro) Return Metar object for the given sky conditions.""" |
| 605 |
sample_metar = "{} 14005KT 6000 {} M05/M10 Q1018".format( |
| 606 |
sta_time, sky_conditions |
| 607 |
) |
| 608 |
return Metar.Metar(sample_metar) |
| 609 |
|
| 610 |
assert report("SCT030").sky_conditions() == "scattered clouds at 3000 feet" |
| 611 |
assert report("BKN001").sky_conditions() == "broken clouds at 100 feet" |
| 612 |
assert report("OVC008").sky_conditions() == "overcast at 800 feet" |
| 613 |
ans = "overcast cumulonimbus at 1000 feet" |
| 614 |
assert report("OVC010CB").sky_conditions() == ans |
| 615 |
ans = "scattered towering cumulus at 2000 feet" |
| 616 |
assert report("SCT020TCU").sky_conditions() == ans |
| 617 |
ans = "broken cumulonimbus at 1500 feet" |
| 618 |
assert report("BKN015CB").sky_conditions() == ans |
| 619 |
ans = "a few clouds at 3000 feet" |
| 620 |
assert report("FEW030").sky_conditions() == ans |
| 621 |
ans = "indefinite ceiling, vertical visibility to 100 feet" |
| 622 |
assert report("VV001").sky_conditions() == ans |
| 623 |
assert report("SKC").sky_conditions() == "clear" |
| 624 |
assert report("CLR").sky_conditions() == "clear" |
| 625 |
assert report("NSC").sky_conditions() == "clear" |
| 626 |
|
| 627 |
|
| 628 |
def test_not_strict_mode(): |
| 629 |
"""Test the strict attribute on parsing.""" |
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
code = "K9L2 100958Z AUTO 33006KT 10SM CLR M A3007 RMK AO2 SLPNO FZRANO $" |
| 634 |
raisesParserError(code) |
| 635 |
|
| 636 |
with warnings.catch_warnings(record=True) as w: |
| 637 |
report = Metar.Metar(code, strict=False) |
| 638 |
assert len(w) == 1 |
| 639 |
|
| 640 |
assert not report.decode_completed |
| 641 |
assert report.cycle == 10 |
| 642 |
assert report.mod == "AUTO" |
| 643 |
assert not report.recent |
| 644 |
assert report.station_id == "K9L2" |
| 645 |
assert report.vis.value() == 10 |
| 646 |
assert report.sky_conditions() == "clear" |
| 647 |
|
| 648 |
|
| 649 |
def test_cor_auto_mod(): |
| 650 |
"""Test parsing of a COR AUTO Metar.""" |
| 651 |
code = ( |
| 652 |
"METAR KADW 252356Z COR AUTO 10008KT 10SM CLR 19/11 A2986 " |
| 653 |
"RMK AO2 SLP117 T01880111 10230 20188 50004 $ COR 0007=" |
| 654 |
) |
| 655 |
m = Metar.Metar(code, year=2019) |
| 656 |
|
| 657 |
assert m.mod == 'COR AUTO' |
| 658 |
|
| 659 |
|
| 660 |
def test_slp_outside_remarks(): |
| 661 |
""" |
| 662 |
Test parsing of a METAR that lists sea level pressure after the altimeter |
| 663 |
setting instead of in the remarks. |
| 664 |
""" |
| 665 |
|
| 666 |
code = ( |
| 667 |
"METAR KCOF 191855Z 18015G22KT 7SM FEW049 SCT300 28/18 A3001 SLP162 " |
| 668 |
"RMK WND DATA ESTMD" |
| 669 |
) |
| 670 |
m = Metar.Metar(code, year=2007) |
| 671 |
m.press_sea_level.value() == 1016.2 |
| 672 |
|
| 673 |
def test_wind_after_sky(): |
| 674 |
""" |
| 675 |
Test parsing of a METAR that lists wind after the sky groups |
| 676 |
""" |
| 677 |
|
| 678 |
code = ( |
| 679 |
"METAR KCOF 281855Z FEW029TCU FEW040 SCT250 09008KT 7SM 32/25 A3008 " |
| 680 |
"RMK VIRGA E TCU NE AND DSNT ALQDS SLP186" |
| 681 |
) |
| 682 |
m = Metar.Metar(code, year=2007) |
| 683 |
|
| 684 |
assert m.wind_dir.value() == 90 |
| 685 |
assert m.wind_speed.value() == 8 |
| 686 |
|
| 687 |
def test_issue136_temperature(): |
| 688 |
raisesParserError("METAR EDDM 022150Z 26006KT CAVOK 201/16") |
| 689 |
|
| 690 |
|
| 691 |
def test_windshear_runway_identifier(): |
| 692 |
code = "METAR EDDH 300720Z WS R23" |
| 693 |
m = Metar.Metar(code, month=1, year=2022) |
| 694 |
assert len(m.windshear) == 1 |
| 695 |
assert m.windshear[0] == "23" |
| 696 |
|
| 697 |
code = "METAR EFHK 151350Z WS RWY22L" |
| 698 |
m = Metar.Metar(code) |
| 699 |
assert len(m.windshear) == 1 |
| 700 |
assert m.windshear[0] == "22L" |
| 701 |
|
| 702 |
|
| 703 |
def test_present_weather_others(): |
| 704 |
|
| 705 |
code = "VEIM 301200Z 16007KT 7000 PO SCT018 31/27 Q1007 NOSIG" |
| 706 |
m = Metar.Metar(code, month=8, year=2023) |
| 707 |
assert m.present_weather() == 'sand whirls' |
| 708 |
|
| 709 |
|
| 710 |
code = "VEIM 301200Z 16007KT 7000 SQ SCT018 31/27 Q1007 NOSIG" |
| 711 |
m = Metar.Metar(code, month=8, year=2023) |
| 712 |
assert m.present_weather() == 'squalls' |
| 713 |
|
| 714 |
|
| 715 |
code = "VEIM 301200Z 16007KT 7000 FC SCT018 31/27 Q1007 NOSIG" |
| 716 |
m = Metar.Metar(code, month=8, year=2023) |
| 717 |
assert m.present_weather() == 'funnel cloud' |
| 718 |
|
| 719 |
|
| 720 |
code = "VEIM 301200Z 16007KT 7000 SS SCT018 31/27 Q1007 NOSIG" |
| 721 |
m = Metar.Metar(code, month=8, year=2023) |
| 722 |
assert m.present_weather() == 'sandstorm' |
| 723 |
|
| 724 |
|
| 725 |
code = "VEIM 301200Z 16007KT 7000 DS SCT018 31/27 Q1007 NOSIG" |
| 726 |
m = Metar.Metar(code, month=8, year=2023) |
| 727 |
assert m.present_weather() == 'dust storm' |
| 728 |
|
| 729 |
|
| 730 |
code = "VEIM 301200Z 16007KT 7000 NSW SCT018 31/27 Q1007 NOSIG" |
| 731 |
m = Metar.Metar(code, month=8, year=2023) |
| 732 |
assert m.present_weather() == 'no significant weather' |