mosmix

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: BSD-2-Clause Imports: 15 Imported by: 0

README

mosmix

Go package to parse mosmix weather predictions from DWD (Deutscher Wetterdienst)

API

The mosmix package provides the following functions to parse MOSMIX data:

Parse(r io.Reader) (*MOSMIX, error)

Parse reads MOSMIX data from the provided io.Reader and returns a MOSMIX struct.

package main

import (
	"fmt"
	"os"
	"github.com/incase/mosmix"
)

func main() {
	file, err := os.Open("path/to/your/mosmix.kml")
	if err != nil {
		panic(err)
	}
	defer file.Close()

	data, err := mosmix.Parse(file)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Parsed MOSMIX data: %+v\n", data)
}

ParseFile(filename string) (*MOSMIX, error)

ParseFile is a convenience function that opens the specified file, reads MOSMIX data from it, and returns a MOSMIX struct.

package main

import (
	"fmt"
	"github.com/sven/go/mosmix" // Assuming this is the correct import path
)

func main() {
	data, err := mosmix.ParseFile("path/to/your/mosmix.kml")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Parsed MOSMIX data: %+v\n", data)
}

func FetchLatestForecastForStation

func FetchLatestForecastForStation(stationID string) ([]*CuratedForecast, Coordinates, error)

FetchLatestForecastForStation fetches the latest MOSMIX forecast for a given station ID, parses it, and returns curated forecast data. Station lists can be found at: - https://wettwarn.de/mosmix/mosmix.html (Map) - https://www.dwd.de/DE/leistungen/met_verfahren_mosmix/mosmix_stationskatalog.html (List)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoForecastFound = errors.New("no forecast found")

Functions

func Distance added in v0.1.1

func Distance(lat1, lon1, lat2, lon2 float64) float64

Distance returns the distance between two points on earth (roughly, via Haversine formula)

func FetchLatestForecastForStation

func FetchLatestForecastForStation(stationID string) ([]*CuratedForecast, *Coordinates, error)

FetchLatestForecastForStation fetches the latest MOSMIX forecast for a given station ID, parses it, and returns curated forecast data. Station lists can be found at: - https://wettwarn.de/mosmix/mosmix.html (Map) - https://www.dwd.de/DE/leistungen/met_verfahren_mosmix/mosmix_stationskatalog.html (List)

func LoadDefaultStations added in v0.1.1

func LoadDefaultStations() error

func LoadStations added in v0.1.1

func LoadStations() error

LoadStations loads the list of stations from DWD This function exists to allow for updates if the list changes. But typically, users should just use the built-in list.

func ParseKMLFile

func ParseKMLFile(path string) ([]TimeSlotForecast, *Coordinates, error)

ParseKMLFile parses a KML file and returns time-pivoted forecast data.

Types

type Coordinates

type Coordinates struct {
	Latitude  float64
	Longitude float64
	Elevation float64
}

func NearestStation added in v0.1.1

func NearestStation(c *Coordinates) (string, *Coordinates, error)

NearestStation

func ParseCoordinates added in v0.1.3

func ParseCoordinates(coordStr string) (*Coordinates, error)

type CuratedForecast

type CuratedForecast struct {
	Time                 time.Time
	Temp2m               float64 // °C, Temperature 2m above surface
	ErrTemp2m            float64 // K, absolute error of temperature 2m above surface
	Temp5cm              float64 // °C, Temperature 5cm above surface
	CloudCoverTotal      float64 // %, Total cloud cover
	CloudCoverEff        float64 // %, Effective cloud cover
	CloudCoverLow        float64 // %, Low cloud cover (lower than 2 km)
	CloudCoverMid        float64 // %, Mid level cloud cover (2-7 km)
	CloudCoverHigh       float64 // %, High cloud cover (>7 km)
	CloudCoverBelow500ft float64 // %, Cloud cover below 500 ft.
	GlobalIrradiance     float64 // kJ/m2, Global Irradiance
	Visibility           float64 // m, Visibility
}

CuratedForecast holds a selection of forecast values for a given time slot.

func CurateForecasts

func CurateForecasts(timeSlots []TimeSlotForecast) []*CuratedForecast

CurateForecasts transforms raw TimeSlotForecasts into CuratedForecasts. It extracts only a subset of fields and handles missing values by assigning NaN. The fields are documented at: https://opendata.dwd.de/weather/lib/MetElementDefinition.xml

func GetNearestCurated

func GetNearestCurated(t time.Time, forecasts []*CuratedForecast) (*CuratedForecast, error)

func (CuratedForecast) String added in v0.1.1

func (cf CuratedForecast) String() string

type Document

type Document struct {
	ExtendedData struct {
		ProductDefinition ProductDefinition `xml:"https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd ProductDefinition"`
	} `xml:"ExtendedData"`
	Placemark Placemark `xml:"Placemark"`
}

type Forecast

type Forecast struct {
	ElementName string `xml:"elementName,attr"`
	Value       string `xml:"https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd value"`
}

type ForecastTimeSteps

type ForecastTimeSteps struct {
	TimeSteps []string `xml:"https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd TimeStep"`
}

type ForecastValue

type ForecastValue struct {
	Value float64
}

ForecastValue holds value of one element at a given time.

type Kml

type Kml struct {
	XMLName  xml.Name `xml:"http://www.opengis.net/kml/2.2 kml"`
	Document Document `xml:"Document"`
}

type MetElement

type MetElement struct {
	ShortName         string `xml:"ShortName"`
	UnitOfMeasurement string `xml:"UnitOfMeasurement"`
	Description       string `xml:"Description"`
}

MetElement holds the definition of a meteorological element.

type MetElementDefinition

type MetElementDefinition struct {
	XMLName     xml.Name     `xml:"MetElementDefinition"`
	MetElements []MetElement `xml:"MetElement"`
}

MetElementDefinition holds a list of meteorological element definitions.

func LoadMetElementDefinitions

func LoadMetElementDefinitions(path string) (*MetElementDefinition, error)

LoadMetElementDefinitioloads meteorological element definitions from an XML file. It reads from path, which is expected to contain the content of https://opendata.dwd.de/weather/lib/MetElementDefinition.xml

type Placemark

type Placemark struct {
	ExtendedData struct {
		Forecasts []Forecast `xml:"https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd Forecast"`
	} `xml:"ExtendedData"`
	Point Point `xml:"Point"`
}

type Point

type Point struct {
	Coordinates string `xml:"coordinates"`
}

type ProductDefinition

type ProductDefinition struct {
	ForecastTimeSteps ForecastTimeSteps `xml:"https://opendata.dwd.de/weather/lib/pointforecast_dwd_extension_V1_0.xsd ForecastTimeSteps"`
}

type Station added in v0.1.1

type Station struct {
	ID        string
	ICAO      string
	Name      string
	Lat       float64 // Degrees North, southern latitudes are negative
	Lon       float64 // Degrees East, western longitude are negative
	Elevation float64 // meters
}

func GetStation added in v0.1.7

func GetStation(id string) *Station

GetStation returns the specified station or nil.

type Stations added in v0.1.1

type Stations map[string]*Station

func (Stations) String added in v0.1.1

func (s Stations) String() string

type TimeSlotForecast

type TimeSlotForecast struct {
	Time   time.Time
	Values map[string]ForecastValue // map of element name to value
}

TimeSlotForecast holds all forecast elements for a given time slot.

Jump to

Keyboard shortcuts

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