buoy

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ALL                       = 0
	INTERNATIONAL_PARTNERS    = 1
	IOOS_PARTNERS             = 2
	MARINE_METAR              = 3
	NDBC_METEOROLOGICAL_OCEAN = 4
	NERRS                     = 5
	NOS_CO_OPS                = 6
	SHIPS                     = 7
	TAO                       = 8
	TSUNAMI                   = 9

	// NOAASourcesURL is the URL where all of the source data is supplied as KML
	NOAASourcesURL = "https://www.ndbc.noaa.gov/kml/marineobs_as_kml.php?sort=pgm"
)

Variables

View Source
var (
	// NauticalRegex is a regular expression to find values between the parentheses
	NauticalRegex = regexp.MustCompile(`\((.*?)\)`)
)
View Source
var (
	SourceTypeMap = map[int]string{
		INTERNATIONAL_PARTNERS:    "International Partners",
		IOOS_PARTNERS:             "IOOS Partners",
		MARINE_METAR:              "Marine METAR",
		NDBC_METEOROLOGICAL_OCEAN: "NDBC Meteorological/Ocean",
		NERRS:                     "NERRS",
		NOS_CO_OPS:                "NOS/CO-OPS",
		SHIPS:                     "Ships",
		TAO:                       "TAO",
		TSUNAMI:                   "Tsunami",
	}
)

Functions

func ParseLocation

func ParseLocation(locationData string) (*loc.Point, error)

ParseLocation parses the latitude and longitude values out of string that can be retrieved from the KML

func ParseWinds

func ParseWinds(windData string) (float64, float64, error)

ParseWinds converts the string wind information that can be retrieved from KML into the wind speed and gust information

func RemoveEmpty

func RemoveEmpty(values []string) []string

RemoveEmpty is a helper function that removes empty string values from the original list

func SourceTypeAsString

func SourceTypeAsString(sourceType int) (string, error)

SourceTypeAsString will convert the source type to a readable string. In the event that ALL is passed, then all strings are returned as a single string with a comma as a delimiter

Types

type Buoy

type Buoy struct {
	// Station is the station ID or ID of the buoy
	Station string `json:"station"`

	// Description is the string description for the Buoy
	// +optional
	Description string `json:"description,omitempty"`

	// Location is the geographical location of the buoy
	// +optional
	Location location.Point `json:"location,omitempty"`

	// Present is the current BuoyData associated with this Buoy
	// +optional
	Present *BuoyData `json:"data,omitempty"`

	// Past is a list of BuoyData structs that are from the Past
	// Deprecated: the past variable is still provided for user assistance, but
	// the value is considered deprecated and abandoned
	// +optional
	Past []*BuoyData `json:"past,omitempty"`

	// Determines whether the data stored in this stuct is considered valid
	// +optional
	Valid bool `json:"valid,omitempty"`
}

Buoy represents a NOAA buoy.

func CreateBuoy

func CreateBuoy(stationID string) (*Buoy, error)

CreateBuoy will provide a full workup for a specific buoy. When the buoy with matching station is not found, an error is returned.

func ParseCData

func ParseCData(cdata string) (*Buoy, error)

ParseCData will parse the CDATA string that is pulled from the KML. On success, the returned Buoy structure should be altered as it will indicate that it was auto-filled. The Station and Description will need to be set to reflect valid Buoy information.

func (*Buoy) FillBuoy

func (b *Buoy) FillBuoy() error

FillBuoy will fill a Buoy struct with the data parsed from the web

func (*Buoy) GetCurrentData

func (b *Buoy) GetCurrentData(root *soup.Root, search []string) error

GetCurrentData parses the current data for a buoy from the NOAA website

func (*Buoy) Hash

func (b *Buoy) Hash() uint64

Hash returns the hashed string as an integer from Buoy

func (*Buoy) SetData

func (b *Buoy) SetData(data *BuoyData) error

SetData sets the current data and moves the current data to the past

type BuoyData

type BuoyData struct {
	// Year is the year the information was retrieved
	Year int `json:"year,omitempty"`

	// Month is the month the information was retrieved
	Month int `json:"mm,omitempty"`

	// Day is the day the information was retrieved
	Day int `json:"dd,omitempty"`

	// time of day that the information was retrieved
	Time *nt.NauticalTime `json:"time,omitempty"`

	// Wind Direction as a string: example `sse`
	WindDirection string `json:"wdir,omitempty"`

	// Wind Speed in knots
	WindSpeed float64 `json:"wspd,omitempty"`

	// Gust speed in knots
	Gust float64 `json:"gst,omitempty"`

	// Mean Wind Direction is the average wind direction
	MeanWindDirection string `json:"mwd,omitempty"`

	// Mean wind speed over a 10-minute period
	WindSpeed10Min float64 `json:"wspd10m,omitempty"`

	// Mean wind speed over a 20-minute period
	WindSpeed20Min float64 `json:"wspd20m,omitempty"`

	// Wave height in feet
	WaveHeight float64 `json:"wvht,omitempty"`

	// Dominant Wave Period in seconds
	DominantWavePeriod float64 `json:"dpd,omitempty"`

	// Average Wave Period in seconds
	AverageWavePeriod float64 `json:"apd,omitempty"`

	// Wind Wave Height in feet
	WindWaveHeight float64 `json:"wwh,omitempty"`

	// Wind Wave Period in seconds
	WindWavePeriod float64 `json:"wwp,omitempty"`

	// Direction of Waves due to wind
	WindWaveDirection string `json:"wwd,omitempty"`

	// Swell Height in feet
	SwellHeight float64 `json:"swh,omitempty"`

	// Swell Period in seconds
	SwellPeriod float64 `json:"swp,omitempty"`

	// Direction of Waves of the Swell
	SwellDirection string `json:"swd,omitempty"`

	// PSI
	Pressure float64 `json:"pres,omitempty"`

	// PSI
	PressureTendency float64 `json:"ptdy,omitempty"`

	// Deg F
	AirTemperature float64 `json:"atmp,omitempty"`

	// Deg F
	WaterTemperature float64 `json:"wtmp,omitempty"`

	// Deg F
	DewPoint float64 `json:"dewp,omitempty"`

	// Deg F
	OceanTemperature float64 `json:"otmp,omitempty"`

	Chill string `json:"chill,omitempty"`

	Heat string `json:"heat,omitempty"`

	// PSU
	Salinity float64 `json:"sal,omitempty"`

	PH string `json:"ph,omitempty"`

	// Oxygen percent in water
	OxygenPercent float64 `json:"o2pct,omitempty"`

	// Oxygen parts per million
	OxygenPPM float64 `json:"o2ppm,omitempty"`

	// Feet
	Depth float64 `json:"depth,omitempty"`

	NauticalMiles float64 `json:"nmi,omitempty"`

	// Nautical Miles
	Visibility float64 `json:"vis,omitempty"`

	// Feet
	Tide float64 `json:"tide,omitempty"`

	// Other features that Don't fit in other categories
	Steepness string `json:"steepness,omitempty"`
	Clcon     string `json:"clcon,omitempty"`
	Turb      string `json:"turb,omitempty"`
	Cond      string `json:"cond,omitempty"`
	SRad1     string `json:"srad1,omitempty"`
	SWRad     string `json:"swrad,omitempty"`
	LWRad     string `json:"lwrad,omitempty"`
}

BuoyData contains the scientific data associated with a Buoy

func (*BuoyData) EpochTime

func (bd *BuoyData) EpochTime() (int64, error)

EpochTime will convert the current time information in this BuoyData struct to the epoch time format

type LocationSign

type LocationSign struct {
	LLType string
	Sign   float64
}

LocationSign contains the type (Latitude vs Longitude) and the sign/multiplier

type NauticalDate

type NauticalDate struct {
	Month int
	Day   int
	Year  int
	Time  *nt.NauticalTime
}

NauticalDate is an extension of NauticalTime where the date information is also provided

func ParseTime

func ParseTime(timeData string) (*NauticalDate, error)

ParseTime parses the time data out of cdata retrieved from KML data.

type Placemark

type Placemark struct {
	// Name is the name tag in the Placemark that should match the
	// name of a Buoy
	Name string `xml:"name"`
	// Description is the description tag of the Placemark that should
	// match the description of the Buoy
	Description string `xml:"description"`
	// Placement is the location of the buoy
	Placement location.Point `xml:"LookAt"`
}

Placemark is the xml structure for a Buoy. It is a very different format than the normal Buoy

type Source

type Source struct {
	// Name of the Source corresponding to Source Type
	Name string `json:"name" xml:"name"`

	// Description for the Source
	Description string `json:"description,omitempty" xml:"description"`

	// Map of Buoys that are contained or associated with[in] this Source
	Buoys map[uint64]*Buoy `json:"buoys,omitempty"`

	// Placemarks are the xml version of the Buoy information. These
	// require additional parsing, so they are NOT interchangeable with
	// the Buoy Structs
	Placemarks []Placemark `xml:"Placemark"`
}

Source represents a group of buoys. The Source also contains details about the grouping such as a description of why/how the buoys are grouped.

func FilterSourcesByType

func FilterSourcesByType(sources []*Source, sourceType int) ([]*Source, error)

FilterSourcesByType filters out the unwanted source types

func GetBuoySources

func GetBuoySources() ([]*Source, error)

GetBuoySources will parse and create sources from the NOAA link: https://www.ndbc.noaa.gov/kml/marineobs_by_pgm.kml

func (*Source) AddBuoy

func (s *Source) AddBuoy(buoy *Buoy) error

AddBuoy will add a buoy to the struct

func (*Source) Contains

func (s *Source) Contains(hash uint64) bool

Contains determines if the hash of the buoy is contained in this struct.

func (*Source) GetBuoy

func (s *Source) GetBuoy(station string) (*Buoy, error)

GetBuoy will get a buoy from the station Id of the Buoy

func (*Source) GetBuoys

func (s *Source) GetBuoys() []*Buoy

GetBuoys will return all Buoy structs. This is not the same as the Map, as it returns a list of Buoy Structs without the keys in the map

func (*Source) String

func (s *Source) String() string

String returns the string representation of the Source

type XMLDoc

type XMLDoc struct {
	Sources []Source `xml:"Document>Folder>Folder"`
}

XMLDoc assists in the xml/kml parsing. The struct represents the entry point of the document.

Jump to

Keyboard shortcuts

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