Skip to main content

Decode TAF files

Project description

Decode TAF

tests PyPI - Version License

463267a9-1d75-4edf-b8e0-38b98977111b~3.jpg

Convert a TAF string to a data structure.

>>> import detaf
>>> bulletin = """
... TAF EGAA 081058Z 0812/0912 14010KT 9999 BKN015
... TEMPO 0812/0906 6000 BKN008
... PROB30 TEMPO 0906/0912 BKN008
... """
>>> detaf.parse(bulletin)
TAF(
  version=<Version.ORIGINAL: 'ORIGINAL'>,
  icao_identifier='EGAA',
  issue_time=issue(day=8, hour=10, minute=58),
  weather_conditions=[
    WeatherCondition(
      period=period(begin=dayhour(day=8, hour=12), end=dayhour(day=9, hour=12)),
      probability=None,
      change=None,
      phenomena=[Wind(direction=140, speed=10, gust=None), Visibility(distance=9999)]),
      ...

Easy to traverse data structure, suitable for any template engine.

>>> taf = detaf.parse(bulletin)
>>> for cnd in taf.weather_conditions:
...     for phenom in cnd.phenomena:
...         print(cnd.period, phenom)
...
period(begin=dayhour(day=8, hour=12), end=dayhour(day=9, hour=12)) Wind(direction=140, speed=10, gust=None)
period(begin=dayhour(day=8, hour=12), end=dayhour(day=9, hour=12)) Visibility(distance=9999)
period(begin=dayhour(day=8, hour=12), end=dayhour(day=9, hour=12)) Cloud(description=<CloudDescription.BROKEN: 'BKN'>, height=1500)
period(begin=dayhour(day=8, hour=12), end=dayhour(day=9, hour=6)) Visibility(distance=6000)
period(begin=dayhour(day=8, hour=12), end=dayhour(day=9, hour=6)) Cloud(description=<CloudDescription.BROKEN: 'BKN'>, height=800)
period(begin=dayhour(day=9, hour=6), end=dayhour(day=9, hour=12)) Cloud(description=<CloudDescription.BROKEN: 'BKN'>, height=800)

Render TAF encodings and Python objects

Detaf enables partial encoding, to make it easier to annotate parts of the report. For example, to add tooltips or syntax highlighting.

The encoder detaf.encode is polymorphic, to make it easier to selectively render TAF snippets or Python data.

>>> import detaf
>>> bulletin = """TAF EIDW 081700Z 0818/0918 14010KT 4000 -DZ BKN007
... BECMG 0818/0820 9999 NSW SCT010 BKN015
... BECMG 0901/0903 15005KT
... BECMG 0907/0909 13010KT
... TEMPO 0907/0918 BKN012
... PROB30 TEMPO 0907/0912 4000 -DZ BKN008"""
>>> taf = detaf.decode(bulletin)
>>>
>>> html = ""
>>> for cnd in taf.weather_conditions:
...     html += f"<div>{detaf.encode(cnd)}</div>\n"
...
>>> print(html)
<div>0818/0918 14010KT 4000 -DZ BKN007</div>
<div>BECMG 0818/0820 9999 NSW SCT010 BKN015</div>
<div>BECMG 0901/0903 15005KT</div>
<div>BECMG 0907/0909 13010KT</div>
<div>TEMPO 0907/0918 BKN012</div>
<div>PROB30 TEMPO 0907/0912 4000 -DZ BKN008</div>

Or a single weather condition list of weather phenomena.

>>> for ph in taf.weather_conditions[1].phenomena:
...     print(f"<li>{detaf.encode(ph)}</li>")
...
<li>9999</li>
<li>NSW</li>
<li>SCT010</li>
<li>BKN015</li>

The ability to map back and forth from a data structure to TAF encoding allows hypermedia driven applications to interpret TAF reports.

# Even more mix/match rendering
>>> for cnd in taf.weather_conditions:
...     for ph in cnd.phenomena:
...         if isinstance(ph, detaf.Visibility):
...             print(detaf.encode(cnd.period), ph)
...
0818/0918 Visibility(distance=4000)
0818/0820 Visibility(distance=9999)
0907/0912 Visibility(distance=4000)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

detaf-0.3.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

detaf-0.3.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file detaf-0.3.0.tar.gz.

File metadata

  • Download URL: detaf-0.3.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.20.1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for detaf-0.3.0.tar.gz
Algorithm Hash digest
SHA256 fd92062cdf0c3a9895d0fb830a83dda26d97d92bf99fdc2e366a07f5ebcc73ba
MD5 6c8643198d783cca6c849430ffa6e362
BLAKE2b-256 b6c579a7a17ae66d5a649c1e659c322a8b07a71f8818dac134b565eb07efd730

See more details on using hashes here.

File details

Details for the file detaf-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: detaf-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.20.1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for detaf-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e480c0a19107ad637175bbbde906544d6f7dd27a3e7842d1a54cfd7a63010678
MD5 b56f57b7a5fb41ab5d3148c2c193563e
BLAKE2b-256 4ea23112e2ec195313ec3a155facf5b6c7a2156d7521fd1ba71b62fb35a8d245

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page