taf

package module
v0.0.0-...-cf76638 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

README

taf

Go Report Card Go Reference

This is a library and command-line tool that parses and decodes TAF forecasts.

TAF stands for Terminal Aerodrome Forecast. It's the weather forecast format used in aviation. TAF reports are useful as a free source of accurate weather.

Here's an example of a TAF report from JFK airport:

KJFK 212335Z 2200/2306 33012G18KT P6SM FEW060 BKN250
  FM220300 36014KT P6SM FEW060 SCT150
  FM221400 01015G21KT P6SM SCT060
  FM221900 04011KT P6SM SCT060
  FM230000 03007KT P6SM FEW060
  FM230300 35006KT P6SM FEW060

Try parsing it by installing the tafparser tool using

go install go.elara.ws/taf/cmd/tafparser@latest

and then running

tafparser <<EOF
KJFK 212335Z 2200/2306 33012G18KT P6SM FEW060 BKN250
  FM220300 36014KT P6SM FEW060 SCT150
  FM221400 01015G21KT P6SM SCT060
  FM221900 04011KT P6SM SCT060
  FM230000 03007KT P6SM FEW060
  FM230300 35006KT P6SM FEW060
EOF

That should return a JSON object containing all the decoded data from the TAF report.

You can also give the tafparser tool a file to read from using tafparser file.txt.

Units in TAF reports are inconsistent between different countries. tafparser can convert the units for you! Just pass it the units you want to use for speed and/or distance like so:

tafparser -s m/s -d m

This tells tafparser to convert all speed units to meters per second and distance units to meters.

tafparser can also fetch TAF reports for you using the aviationweather.gov site. Use the -i <identifier> flag to tell it to do that, like so:

tafparser -i EGLL

That should automatically fetch the report for London Heathrow and parse it.

Documentation

Index

Constants

View Source
const (
	TimeFormat  = "021504"
	ValidFormat = "0215"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	// Type specifies the nature of this weather change.
	Type ChangeType `json:"type,omitempty"`

	// Valid defines the period during which this change is applicable.
	Valid ValidPair `json:"valid,omitempty"`

	// Visibility describes the anticipated visibility conditions.
	Visibility Visibility `json:"visibility,omitempty"`

	// Wind describes the projected wind conditions.
	Wind Wind `json:"wind,omitempty"`

	// SkyCondition lists the expected sky conditions.
	SkyCondition []SkyCondition `json:"sky_condition,omitempty"`

	// Temperature lists the expected temperature values.
	Temperature []Temperature `json:"temperature,omitempty"`

	// Weather lists information about the expected weather conditions.
	Weather []Weather `json:"weather,omitempty"`

	// Flags contains special flags associated with the change.
	Flags []Flag `json:"flags,omitempty"`

	// Probability indicates the percent chance of this change occurring.
	Probability int `json:"probability,omitempty"`
}

Change represents a change in weather conditions within a forecast.

type ChangeType

type ChangeType string

ChangeType represents different types of changes in weather conditions.

const (
	// From indicates a rapid change.
	From ChangeType = "From"
	// Becoming indicates a slow or gradual change.
	Becoming ChangeType = "Becoming"
	// Temporary indicates that a change is expected to last generally less than an hour.
	Temporary ChangeType = "Temporary"
)

Change Types

type CloudType

type CloudType string

CloudType represents different types of cloud formations.

const (
	CumuloNimbus    CloudType = "CumuloNimbus"
	ToweringCumulus CloudType = "ToweringCumulus"
)

Cloud Types

type Descriptor

type Descriptor string

Descriptor represents descriptors for weather conditions, such as "Shallow" or "Showers".

const (
	Shallow      Descriptor = "Shallow"
	Patches      Descriptor = "Patches"
	LowDrifting  Descriptor = "LowDrifting"
	Blowing      Descriptor = "Blowing"
	Showers      Descriptor = "Showers"
	Thunderstorm Descriptor = "Thunderstorm"
	Freezing     Descriptor = "Freezing"
	Partial      Descriptor = "Partial"
)

Weather Descriptors

type Direction

type Direction struct {
	// Variable signifies if the wind direction is variable. When true, Value is set to zero.
	Variable bool `json:"variable,omitempty"`

	// Value specifies the wind direction in degrees.
	Value int `json:"value,omitempty"`
}

Direction describes the wind direction, which can be variable.

type Flag

type Flag string

Flag represents special flags for specific weather conditions.

const (
	// CeilingAndVisibilityOK indicates that visibility is over 10km, that
	// there are no significant clouds, and no significant weather
	CeilingAndVisibilityOK Flag = "CeilingAndVisibilityOK"
)

Flags

type Forecast

type Forecast struct {
	// ReportType represents the type of report this forecast describes.
	ReportType ReportType `json:"report_type,omitempty"`

	// Identifier holds the ICAO airport identifier for which this forecast was issued.
	Identifier string `json:"identifier,omitempty"`

	// Airport provides additional information about the airport for which this forecast was issued.
	Airport airports.Airport `json:"airport,omitempty"`

	// PublishTime indicates the time at which this forecast was issued.
	PublishTime time.Time `json:"publish_time,omitempty"`

	// Valid defines the period during which this forecast is applicable.
	Valid ValidPair `json:"valid,omitempty"`

	// Visibility describes the anticipated visibility conditions.
	Visibility Visibility `json:"visibility,omitempty"`

	// Wind describes the projected wind conditions.
	Wind Wind `json:"wind,omitempty"`

	// SkyCondition lists the expected sky conditions.
	SkyCondition []SkyCondition `json:"sky_condition,omitempty"`

	// Temperature lists the expected temperature values.
	Temperature []Temperature `json:"temperature,omitempty"`

	// Weather lists information about the expected weather conditions.
	Weather []Weather `json:"weather,omitempty"`

	// Probabilities contains the probabilities for potential conditions.
	Probabilities []*Probability `json:"probabilities,omitempty"`

	// Changes lists any expected changes in conditions.
	Changes []*Change `json:"changes,omitempty"`

	// Flags contains special flags associated with the forecast.
	Flags []Flag `json:"flags,omitempty"`

	// Remark contains remarks from the forecast.
	Remark string `json:"remark,omitempty"`
}

Forecast represents a Terminal Aerodrome Forecast (TAF) weather report for a specific airport.

func Decode

func Decode(r io.Reader) (*Forecast, error)

Decode decodes the data in a reader using default options and returns a Forecast

func DecodeFile

func DecodeFile(path string) (*Forecast, error)

DecodeFile decodes a TAF string and returns a Forecast. This is equivalent to opening a file and passing it to Decode().

func DecodeString

func DecodeString(s string) (*Forecast, error)

DecodeString decodes a TAF string and returns a Forecast. This is equivalent to Decode(strings.NewReader(s)).

func DecodeWithOptions

func DecodeWithOptions(r io.Reader, opts Options) (*Forecast, error)

DecodeWithOptions decodes the data in a reader and returns a Forecast

type Modifier

type Modifier string

Modifier represents modifiers for weather conditions, such as "Heavy" or "Light".

const (
	// Heavy indicates that weather conditions are expected to be severe.
	Heavy Modifier = "Heavy"
	// Light indicates that weather conditions are expected to be mild.
	Light Modifier = "Light"
)

Weather Modifiers

type Obscuration

type Obscuration string

Obscuration represents different types of atmospheric obscurations.

const (
	Mist        Obscuration = "Mist"
	Fog         Obscuration = "Fog"
	Smoke       Obscuration = "Smoke"
	Dust        Obscuration = "Dust"
	Sand        Obscuration = "Sand"
	Haze        Obscuration = "Haze"
	Spray       Obscuration = "Spray"
	VolcanicAsh Obscuration = "VolcanicAsh"
)

Atmospheric Obscuration Types

type Options

type Options struct {
	// If this is set, all distance units in the forecast
	// will be converted to the given unit
	DistanceUnit units.Distance

	// If this is set, all speed units in the forecast will
	// be converted to the given unit
	SpeedUnit units.Speed

	// The Year field is used to calculate the full date that this
	// report was published. If it's unset, the current year will be used.
	Year int

	// The Month field is used to calculate the full date that this
	// report was published. If it's unset, the current month will be used.
	Month time.Month
}

Options contains options for the decoder

type Phenomenon

type Phenomenon string

Phenomenon represents different atmospheric phenomena like whirls, squalls, etc.

const (
	Whirls      Phenomenon = "Whirls"
	Squalls     Phenomenon = "Squalls"
	FunnelCloud Phenomenon = "FunnelCloud"
	Sandstorm   Phenomenon = "Sandstorm"
	Duststorm   Phenomenon = "Duststorm"
)

Weather Phenomena

type Precipitation

type Precipitation string

Precipitation represents different types of precipitation.

const (
	Drizzle     Precipitation = "Drizzle"
	Rain        Precipitation = "Rain"
	Snow        Precipitation = "Snow"
	SnowGrains  Precipitation = "SnowGrains"
	IceCrystals Precipitation = "IceCrystals"
	IcePellets  Precipitation = "IcePellets"
	Hail        Precipitation = "Hail"
	SmallHail   Precipitation = "SmallHail"
	Unknown     Precipitation = "Unknown"
)

Precipitation Types

type Probability

type Probability struct {
	// Valid defines the period during which these potential conditions are applicable.
	Valid ValidPair `json:"valid,omitempty"`

	// Value indicates the percent chance of these conditions occurring.
	Value int `json:"value,omitempty"`

	// Visibility describes the anticipated visibility conditions.
	Visibility Visibility `json:"visibility,omitempty"`

	// Wind describes the projected wind conditions.
	Wind Wind `json:"wind,omitempty"`

	// SkyCondition lists the expected sky conditions.
	SkyCondition []SkyCondition `json:"sky_condition,omitempty"`

	// Temperature lists the expected temperature values.
	Temperature []Temperature `json:"temperature,omitempty"`

	// Weather lists information about the expected weather conditions.
	Weather []Weather `json:"weather,omitempty"`

	// Flags contains special flags associated with the potential conditions.
	Flags []Flag `json:"flags,omitempty"`
}

Probability represents the probability of potential conditions occurring within a forecast.

type ReportType

type ReportType string

ReportType represents different types of reports.

const (
	// Amended represents a report issued when the previous report is no longer accurate.
	Amended ReportType = "Amended"
	// Corrected represents a correction to a previous report.
	Corrected ReportType = "Corrected"
)

type SkyCondition

type SkyCondition struct {
	// Type specifies the nature of the expected sky condition.
	Type SkyConditionType `json:"type,omitempty"`

	// Altitude represents the altitude at which this sky condition is anticipated, in feet.
	Altitude int `json:"altitude,omitempty"`

	// CloudType defines the type of clouds expected in the sky.
	CloudType CloudType `json:"cloud_type,omitempty"`
}

SkyCondition represents the condition of the sky, including cloud cover and altitude.

type SkyConditionType

type SkyConditionType string

SkyConditionType represents different types of sky conditions in the forecast.

const (
	Few                SkyConditionType = "Few"
	Scattered          SkyConditionType = "Scattered"
	Broken             SkyConditionType = "Broken"
	Overcast           SkyConditionType = "Overcast"
	VerticalVisibility SkyConditionType = "VerticalVisibility"
	SkyClear           SkyConditionType = "SkyClear"
)

Sky Condition Types

type Temperature

type Temperature struct {
	// Type specifies if this temperature is a high or low value.
	Type TemperatureType `json:"type,omitempty"`

	// Value holds the anticipated temperature in degrees Celsius.
	Value int `json:"value,omitempty"`

	// Time indicates the expected time for this temperature.
	Time time.Time `json:"time,omitempty"`
}

Temperature represents temperature-related details in the forecast.

type TemperatureType

type TemperatureType string

TemperatureType represents different types of temperature data, like "High" or "Low".

const (
	High TemperatureType = "High"
	Low  TemperatureType = "Low"
)

Temperature Types

type ValidPair

type ValidPair struct {
	// From represents the time from which the data is valid.
	From time.Time `json:"from,omitempty"`

	// To indicates the time until which the data is valid.
	To time.Time `json:"to,omitempty"`

	// Duration contains the total duration for which the data remains valid
	Duration time.Duration `json:"duration,omitempty"`
}

ValidPair represents a time interval for which weather data is valid.

type Visibility

type Visibility struct {
	// Plus indicates whether visibility is expected to be greater than the specified value.
	Plus bool `json:"plus,omitempty"`

	// Value holds the visibility measurement. Its unit is determined by the Unit field.
	Value float64 `json:"value,omitempty"`

	// Unit specifies the unit of measurement for the visibility value.
	Unit units.Distance `json:"unit,omitempty"`
}

Visibility represents the visibility conditions in the forecast.

type Weather

type Weather struct {
	// Vicinity specifies if the described weather is occurring near the airport.
	Vicinity bool `json:"vicinity,omitempty"`

	// Modifier indicates the severity of the weather conditions.
	Modifier Modifier `json:"modifier,omitempty"`

	// Descriptor provides details about the specific type of expected weather.
	Descriptor Descriptor `json:"descriptor,omitempty"`

	// Precipitation indicates the anticipated type of precipitation.
	Precipitation Precipitation `json:"precipitation,omitempty"`

	// Obscuration describes any potential atmospheric obscurations expected.
	Obscuration Obscuration `json:"obscuration,omitempty"`

	// Phenomenon contains anticipated weather phenomena.
	Phenomenon Phenomenon `json:"phenomenon,omitempty"`
}

Weather represents various weather-related conditions in the forecast.

type Wind

type Wind struct {
	// Direction indicates the wind direction of the expected wind.
	Direction Direction `json:"direction,omitempty"`

	// WindShear specifies the altitude at which wind shear is expected.
	WindShear int `json:"wind_shear,omitempty"`

	// Speed represents the anticipated wind speed. The unit is determined by the Unit field.
	Speed int `json:"speed,omitempty"`

	// Gusts holds the projected gust speed. The unit is determined by the Unit field.
	Gusts int `json:"gusts,omitempty"`

	// Unit denotes the unit of measurement for wind and gust speeds.
	Unit units.Speed `json:"unit,omitempty"`
}

Wind represents wind-related information in a weather forecast.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL