iem

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2023 License: MIT Imports: 10 Imported by: 0

README

Go IEM Weather SDK

SDK for Iowa State University Environment Mesonet API

APIS

This SDK currently covers the following APIs

Documentation

Index

Constants

View Source
const (
	OnlyComma WeatherDataQueryFormat = "onlycomma"
	OnlyTDF   WeatherDataQueryFormat = "onlytdf"
	Comma     WeatherDataQueryFormat = "comma"
	TDF       WeatherDataQueryFormat = "tdf"

	Yes WeatherDataQueryYesNo = "yes"
	No  WeatherDataQueryYesNo = "no"

	MissingM     WeatherDataQueryMissing = "M"
	MissingNull  WeatherDataQueryMissing = "null"
	MissingEmpty WeatherDataQueryMissing = "empty"

	TraceT     WeatherDataQueryTrace = "T"
	TraceNull  WeatherDataQueryTrace = "null"
	TraceEmpty WeatherDataQueryTrace = "empty"
	TraceFloat WeatherDataQueryTrace = "0.0001"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func NewClientWithOptions

func NewClientWithOptions(opts ...ClientOption) *Client

func (*Client) Networks

func (c *Client) Networks() NetworkService

func (*Client) Stations

func (c *Client) Stations() StationService

func (*Client) Weather

func (c *Client) Weather() WeatherService

type ClientOption

type ClientOption func(*Client)

func WithNetworkService

func WithNetworkService(service NetworkService) ClientOption

func WithWeatherService

func WithWeatherService(service WeatherService) ClientOption

type IEMNetowrkJsonResposne

type IEMNetowrkJsonResposne struct {
	Data []*Network `json:"data"`
}

type IEMNetworkService

type IEMNetworkService struct {
	// contains filtered or unexported fields
}

func (*IEMNetworkService) GetNetworks

func (s *IEMNetworkService) GetNetworks(ctx context.Context) ([]*Network, error)

type IEMNotFoundError

type IEMNotFoundError struct {
	Detail string `json:"detail"`
	Code   int    `json:"code"`
}

func (IEMNotFoundError) Error

func (err IEMNotFoundError) Error() string

type IEMStationService

type IEMStationService struct {
	// contains filtered or unexported fields
}

func (*IEMStationService) GetStation

func (s *IEMStationService) GetStation(ctx context.Context, stationId string) (*Station, error)

func (*IEMStationService) GetStations

func (s *IEMStationService) GetStations(ctx context.Context, networkId string) ([]*Station, error)

type IEMStationsJsonResponse

type IEMStationsJsonResponse struct {
	Data []*Station
}

type IEMWeatherData

type IEMWeatherData struct {
	Station string `json:"station"` // Station recorded at (station)

	Time *time.Time `json:"time"` // Time recorded at (valid)

	Lon float64 `json:"lon,omitempty"` // Longitude recorded at (lon)
	Lat float64 `json:"lat,omitempty"` // Latitude recorded at (lat)

	Elevation string `json:"elevation,omitempty"` // Elevation recorded at (elev)

	TemperatureF float64 `json:"tmpf,omitempty"` // Air Temperature [F] (tempf)
	TemperatureC float64 `json:"tmpc,omitempty"` // Air Temperature [C] (tempc)

	DewPointF float64 `json:"dwpf,omitempty"` // Dew Point [F] (dwpf)
	DewPointC float64 `json:"dwpc,omitempty"` // Dew Point [C] (dwpc)

	RelativeHumidity float64 `json:"relh,omitempty"` // Relative humidity [%] (relh)

	Feel float64 `json:"feel,omitempty"` // Heat Index/Wind Chil [F] (feel)

	WindDirection  float64 `json:"drct,omitempty"` // Wind Direction [deg] (drct)
	WindSpeedKnots float64 `json:"sknt,omitempty"` // Wind Speed [knots] (sknt)
	WindSpeedMPH   float64 `json:"sped,omitempty"` // Wind Speed [mph] (sped)

	WindGustKnots float64 `json:"gust,omitempty"`     // Wind Gust [knots] (gust)
	WindGustMPH   float64 `json:"gust_mph,omitempty"` // Wind Gust [mph] (gust_mph)

	PeakWindGustKnots float64    `json:"peak_wind_gust,omitempty"` // Peak Wind Gust [knots] (peak_wind_gust)
	PeakWindGustMPH   float64    `json:"peak_wind_mph,omitempty"`  // Peak Wind Gust [mph] (peak_wind_mph)
	PeakWindDirection float64    `json:"peak_wind_drct,omitempty"` // Peak Wind Direction [deg] (peak_wind_drct)
	PeakWindTime      *time.Time `json:"peak_wind_time,omitempty"` // Peak Wind Time (peak_wind_time)

	Altimeter float64 `json:"alti,omitempty"` // Altimeter [inches] (alti)

	SeaLevelPressure float64 `json:"mslp,omitempty"` // Sea Level Pressure [mb] (mslp)

	PrecipMM   float64 `json:"p01m,omitempty"` // 1 hour Precipitation [mm] (p01m)
	PrecipInch float64 `json:"p01i,omitempty"` // 1 hour Precipitation [inch] (po1i)

	Visibility float64 `json:"vsby,omitempty"` // Visibility [miles] (vsby)

	CloudCoverageL1 string `json:"skyc1,omitempty"` // Cloud Coverage Level 1 (skyc1)
	CloudCoverageL2 string `json:"skyc2,omitempty"` // Cloud Coverage Level 2 (skyc2)
	CloudCoverageL3 string `json:"skyc3,omitempty"` // Cloud Coverage Level 3 (skyc3)

	CloudHeightL1 float64 `json:"skyl1,omitempty"` // Cloud Height Level 1 [ft] (skyl1)
	CloudHeightL2 float64 `json:"skyl2,omitempty"` // Cloud Height Level 2 [ft] (skyl2)
	CloudHeightL3 float64 `json:"skyl3,omitempty"` // Cloud Height Level 3 [ft] (skyl3)

	PresentWeatherCodes string `json:"wxcodes,omitempty"` // Present Weather Code(s)

	IceAccretion1HR float64 `json:"ice_accretion_1hr,omitempty"` // Ice Accretion 1 Hour (ice_accretion_1hr)
	IceAccretion3HR float64 `json:"ice_accretion_3hr,omitempty"` // Ice Accretion 3 Hour (ice_accretion_3hr)
	IceAccretion6HR float64 `json:"ice_accretion_6hr,omitempty"` // Ice Accretion 6 Hour (ice_accretion_6hr)

	SnowDepth float64 `json:"snowdepth,omitempty"` // Snow Depth (4-group) [inch] (snowdepth)

	METAR string `json:"metar,omitempty"` // Raw METAR (metar)
}

IEMWeatherData represents a weather reading at a station at a time Properties are present depending on the query used to fetch weather data

func ParseWeatherData

func ParseWeatherData(reader io.Reader, query *WeatherDataQueryBuilder) ([]*IEMWeatherData, error)

Parse weather data from a io.Reader that reads CSV data based on a WeatherDataQueryBuilder

type IEMWeatherService

type IEMWeatherService struct {
	// contains filtered or unexported fields
}

func (*IEMWeatherService) Get

type Network

type Network struct {
	Index int    `json:"index"`
	Id    string `json:"id"`
	Name  string `json:"name"`
	Tz    string `json:"tzname"`
	// Extent string `json"extent"`
	WindroseUpdate time.Time `json:"windrose_update"`
}

type NetworkService

type NetworkService interface {
	GetNetworks(ctx context.Context) ([]*Network, error)
}

type Station

type Station struct {
	Index         int       `json:"index"`
	Id            string    `json:"id"`
	Synop         float64   `json:"synop"`
	Name          string    `json:"name"`
	State         string    `json:"state"`
	Country       string    `json:"country"`
	Elevation     float64   `json:"elevation"`
	Network       string    `json:"network"`
	Online        bool      `json:"online"`
	Params        string    `json:"params"`
	County        string    `json:"county"`
	PlotName      string    `json:"plot_name"`
	ClimateSite   string    `json:"climate_site"`
	Latitude      float64   `json:"latitude"`
	Longitude     float64   `json:"longitude"`
	Timezone      string    `json:"tzname"`
	ArchiveBegins time.Time `json:"archive_begin"`
}

type StationService

type StationService interface {
	GetStation(ctx context.Context, stationId string) (*Station, error)
	GetStations(ctx context.Context, networkId string) ([]*Station, error)
}

type TestWeatherService

type TestWeatherService struct{}

func (*TestWeatherService) GetWeatherAtStation

func (s *TestWeatherService) GetWeatherAtStation(ctx context.Context, query *WeatherDataQueryBuilder) ([]*IEMWeatherData, error)

type WeatherDataData

type WeatherDataData string
const (
	All                 WeatherDataData = "all"                // All Available
	TempF               WeatherDataData = "tmpf"               // Air Temperature [F]
	TempC               WeatherDataData = "tmpc"               // Air Temperature [C]
	DewPointF           WeatherDataData = "dwpf"               // Dew Point [F]
	DewPointC           WeatherDataData = "dwpc"               // Dew Point [C]
	RelativeHumidity    WeatherDataData = "relh"               // Relative Humidity [%]
	Feel                WeatherDataData = "feel"               // Heat Index/Wind Chill [F]
	WindDirection       WeatherDataData = "drct"               // Wind Direction
	WindSpeedKnots      WeatherDataData = "sknt"               // Wind Speed [knots]
	WindSpeedMPH        WeatherDataData = "sped"               // Wind Speed [mph]
	Altimeter           WeatherDataData = "alti"               // Altimeter [inches]
	SeaLevelPressure    WeatherDataData = "mslp"               // Sea Level Pressure [mb]
	PrecipMM            WeatherDataData = "p01m"               // 1 hour Precipitation [mm]
	PrecipInch          WeatherDataData = "p01i"               // 1 hour Precipitation [inch]
	Visibility          WeatherDataData = "vsby"               // Visibility [miles]
	WindGustKnots       WeatherDataData = "gust"               // Wind Gust [knots]
	WindGustMPH         WeatherDataData = "gust_mph"           // Wind Gust [mph]
	CloudCoverageL1     WeatherDataData = "skyc1"              // Cloud Coverage Level 1
	CloudCoverageL2     WeatherDataData = "skyc2"              // Cloud Coverage Level 2
	CloudCoverageL3     WeatherDataData = "skyc3"              // Cloud Coverage Level 3
	CloudHeightL1       WeatherDataData = "skyl1"              // Cloud Height Level 1 [ft]
	CloudHeightL2       WeatherDataData = "skyl2"              // Cloud Height Level 2 [ft]
	CloudHeightL3       WeatherDataData = "skyl3"              // Cloud Height Level 3 [ft]
	PresentWeatherCodes WeatherDataData = "wxcodes"            // Present Weather Code(s)
	IceAccretion1HR     WeatherDataData = "ice_accretion_1hr"  // Ice Accretion 1 Hour
	IceAccretion3HR     WeatherDataData = "ice_accretion_3hr"  // Ice Accretion 3 Hour
	IceAccretion6HR     WeatherDataData = "ice_accretion_6hr"  // Ice Accretion 6 Hour
	PeakWindGustKnots   WeatherDataData = "peak_wind_gust"     // Peak Wind Gust [knots]
	PeakWindGustMPH     WeatherDataData = "peak_wind_gust_mph" // Peak Wind Gust [MPH]
	PeakWindDirection   WeatherDataData = "peak_wind_drct"     // Peak Wind Direction [deg]
	PeakWindTime        WeatherDataData = "peak_wind_time"     // Peak Wind Time
	SnowDepth           WeatherDataData = "snowdepth"          // Snow Depth (4-group) [inch]
	METAR               WeatherDataData = "metar"              // Raw METAR
)

type WeatherDataQueryBuilder

type WeatherDataQueryBuilder struct {
	// contains filtered or unexported fields
}

WeatherDataQueryBuilder represents the url query sent to the IEM API when requesting weather data for stations

func NewWeatherDataQuery

func NewWeatherDataQuery() *WeatherDataQueryBuilder

Creates a new WeatherDataQueryBuilder with defaults set to optional fields

func (*WeatherDataQueryBuilder) BuildUrl

func (b *WeatherDataQueryBuilder) BuildUrl() (url.Values, error)

Creates url.Values with validated data from query builder

func (*WeatherDataQueryBuilder) Data

Appends data to query builder.data

func (*WeatherDataQueryBuilder) Elevation

Sets query builder elev property (defaults to false)

func (*WeatherDataQueryBuilder) End

Sets query builder end date (defaults to today)

func (*WeatherDataQueryBuilder) Format

Sets query builder format (defaults to Etc/UTC)

func (*WeatherDataQueryBuilder) LatLon

Sets query builder latlon property (defaults to false)

func (*WeatherDataQueryBuilder) Missing

Sets query builder missing property (defaults to M)

func (*WeatherDataQueryBuilder) ReportType

func (b *WeatherDataQueryBuilder) ReportType(types ...int) *WeatherDataQueryBuilder

Sets query builder report_type property (defaults to {3, 4})

func (*WeatherDataQueryBuilder) Start

Sets query builder start date (defaults to today)

func (*WeatherDataQueryBuilder) Stations

func (b *WeatherDataQueryBuilder) Stations(stations ...string) *WeatherDataQueryBuilder

Appends stations to builder.station

func (*WeatherDataQueryBuilder) Timezone

Sets query builder end date (defaults to Etc/UTC)

func (*WeatherDataQueryBuilder) Trace

Sets query builder trace property (defaults to T)

type WeatherDataQueryBuilderError

type WeatherDataQueryBuilderError struct {
	// contains filtered or unexported fields
}

func (WeatherDataQueryBuilderError) Error

type WeatherDataQueryFormat

type WeatherDataQueryFormat string

type WeatherDataQueryMissing

type WeatherDataQueryMissing string

type WeatherDataQueryTrace

type WeatherDataQueryTrace string

type WeatherDataQueryYesNo

type WeatherDataQueryYesNo string

type WeatherService

type WeatherService interface {
	Get(ctx context.Context, query *WeatherDataQueryBuilder) ([]*IEMWeatherData, error)
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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