Coder Social home page Coder Social logo

swiftmetar's Introduction

SwiftMETAR: A METAR and TAF parser for Swift

SwiftMETAR is a Swift library that parses aviation routine weather reports (METARs) and terminal aerodrome forecasts (TAF) into Swift data structures useful for machine interpretation. These products contain weather information of interest to pilots. METARs are textual hourly observations of current conditions within 5 miles of an airport, and TAFs are textual point forecasts of expected conditions within 5 miles of an airport, over a 24- to 28-hour period.

SwiftMETAR does not download METAR or TAF products from the Internet -- you'll have to do that yourself. Once you have the text product, SwiftMETAR will parse it into a METAR or TAF object that you can use to programmatically work with the weather information.

The design goal of SwiftMETAR is domain-restricted data as much as possible. Wherever possible, SwiftMETAR avoids representing data as open-ended types such as strings. Instead, enums and other types with small domains are preferred. This obviously has versatility implications -- namely, SwiftMETAR is more likely to generate parsing errors for malformed data, especially data that is keyed in by humans -- but it also results in a library that's more in harmony with the design goals of the Swift language itself (type safety, compile-time checks, etc.).

SwiftMETAR bases is parsing on Advisory Circular 00-45F, which is an American FAA publication. Some affordance has been made beyond AC00-45F to parse non-American variances as well (such as supporting QNH-values, visibility in meters, etc.), but this library has not been extensively tested with non-US products. Similarly, some affordance has been made for parsing TAFs at military airbases, but most of those will fail to parse for now.

Installation

Online API and tutorial documentation is available at https://riscfuture.github.io/SwiftMETAR/documentation/swiftmetar/

SwiftMETAR is a Swift Package Manager project. To use SwiftMETAR, simply add this project to your Package.swift file. Example:

// [...]
dependencies: [
    .package(url: "https://github.com/RISCfuture/SwiftMETAR/", .branch("main")),
]
// [...]

Usage

To parse a METAR in String format, simply call METAR.from. You will get back a struct that you can query for weather information:

let observation = try METAR.from(string: myString)
if let winds = observation.winds {
    switch winds {
        case let .direction(heading, speed, gust):
            switch speed {
                case let .knots(value):
                    print("Winds are \(heading) at \(speed) knots")
                // [...]
            }
        // [...]
    }
}

As you can see, many of the fields in a METAR (or TAF) struct are enums (or even nested enums as in the case of Wind). This is more cumbersome than working with strings but results in stronger guarantees about the format and integrity of the data.

For more information on how to use the METAR and TAF struct, see the documentation comments.

SwiftMETAR prefers DateComponents rather than Date objects generally, to preserve the original data (day-hour-minute) rather than generating timestamps. Both METAR and TAF have vars allowing you to retrieve these values as Dates, but the data is stored as components.

Documentation

Online API documentation and tutorials are available at https://riscfuture.github.io/SwiftMETAR/documentation/swiftmetar/

DocC documentation is available, including tutorials and API documentation. For Xcode documentation, you can run

swift package generate-documentation --target SwiftMETAR

to generate a docarchive at .build/plugins/Swift-DocC/outputs/SwiftMETAR.doccarchive. You can open this docarchive file in Xcode for browseable API documentation. Or, within Xcode, open the SwiftMETAR package in Xcode and choose Build Documentation from the Product menu.

Tests

Unit testing is done using Nimble and Quick. Simply test the SwiftMETAR target to run tests.

A SwiftMETAR_Gauntlet target is also available to do an end-to-end test with live data. This will download METARs and TAFs from the AWC server and attempt to parse them. Any failures will be logged with the failing string.

swiftmetar's People

Contributors

riscfuture avatar xxkrashxx avatar skajake avatar

Stargazers

Alberto Cantallops avatar Madison L.H. Wass avatar Michael Corrado avatar  avatar  avatar  avatar Indrajit Chakrabarty avatar Miro Markaravanes avatar Manolis avatar Serhii Londar avatar Alonso Holmes avatar

Watchers

 avatar James Cloos avatar William Dillon avatar Serhii Londar avatar  avatar

swiftmetar's Issues

Compiling for iOS fails

Hi! Thanks for this excellent library!

I tried to use it in a project that I wanted to compile for iOS and for Mac M1/M2 as an Made for iPad app.
I get this error when compiling:

image

It does relate to the NumericAnnex library, not to your code, but I was wondering if you could have an idea if it can be solved, or maybe if NumericAnnex could be totally replaced? It seems to me that you are only using the Ratio class of this library.

Thanks!

Parse "not determined" Clouds conditions

Summary

Parsing METARs w\ not determined cloud feature results in a corrupted parsing.

Expected Behavior

Cloud features such as:

  • BKN013///
  • //////TCU

Should:

  1. not break parsing;
  2. be reflected in a model somehow.

Current Behavior

All METAR features aft go to the RMK property.

Steps to Reproduce

Parse:

  1. METAR EGLL 042350Z AUTO 35010KT 320V020 5000 -RADZ BKN008/// OVC015/// //////CB 06/04 Q0993 TEMPO 4000 RADZ
  2. EGSS 042320Z AUTO 36008KT 4100 -RADZ OVC003/// //////TCU 07/06 Q0992

(these are real METAR issues by the authorities)

Parse directional visibility

Summary

Visibility could be provided with Cardinal direction.
Currently, unhandled case.

Expected Behavior

  • var visibility: Visibility -> var visibilities: [Visibility]
  • add direction to the Visibility
  • add backwards compatible convenience properties

Current Behavior

Parsing breaks.

Steps to Reproduce

  • Parse examples:
    • METAR LOWK 042250Z AUTO VRB02KT 9000 3600S BR FEW002 M01/M01 Q1011
    • ... (provide more?)
  • Visibility 3.6km in direction of South does not reflected in parsed structure.

(these are real METAR issues by the authorities)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.