stationxml

package
v0.0.0-...-f0b4dbc Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

README

FDSNStationXML

Automatically generate FDSN StationXML golang bindings from their respective Schema xsd files.

Documentation on the XML schema format can be found at https://docs.fdsn.org/projects/stationxml

Schemas Available

Usage

The modules provide a stationxml package and can be imported using:

import (
        github.com/geonet/internal/stationxml/v1.2
)

Update

The code to build the golang encodings is in the generate subdirectory with the actual commands in the doc.go file.

To add a new version, update the doc.go code to add a new generate line.

The schema files are expected to be found at:

    https://www.fdsn.org/xml/station/fdsn-station-1.2.xsd

with the appropriate version substitued.

Then in the current directory run:

    `go generate`

The doc.go file and generated code, in the versioned directories, should be commited to git.

Documentation

Overview

Automatically generate stationxml bindings from the schema files.

Index

Constants

View Source
const LaplaceRadiansSecondPzTransferFunction = "LAPLACE (RADIANS/SECOND)"

Variables

View Source
var ErrInvalidResponse = errors.New("attempt to correct the wrong type of response, biases require a polynomial response")

Functions

func Decode

func Decode(version string, data []byte) ([]byte, error)

Encode encodes the Root struct using the given Encoder.

func Decode10

func Decode10(data []byte) ([]byte, error)

func Decode11

func Decode11(data []byte) ([]byte, error)

func Decode12

func Decode12(data []byte) ([]byte, error)

func Encode10

func Encode10(r Root) ([]byte, error)

func Encode11

func Encode11(r Root) ([]byte, error)

func Encode12

func Encode12(r Root) ([]byte, error)

func ToSiteSurvey

func ToSiteSurvey(survey string) string

ToSiteSurey returns the survey notes fro a given survey method.

Types

type ApproximationBound

type ApproximationBound struct {
	Value float64 `xml:",chardata"`
}

type Channel

type Channel struct {
	LocationCode string

	Latitude  float64
	Longitude float64
	Elevation float64
	Survey    string
	Datum     string

	Streams []Stream
}

Channel forms the main part of a set of StationXML Channel elements

type CoefficientDenominator

type CoefficientDenominator struct {
	Number int     `xml:"number,attr"`
	Value  float64 `xml:",chardata"`
}

type CoefficientNumerator

type CoefficientNumerator struct {
	Number int     `xml:"number,attr"`
	Value  float64 `xml:",chardata"`
}

type CoefficientsType

type CoefficientsType struct {
	ResourceId  string `xml:"resourceId,attr,omitempty"`
	Name        string `xml:"name,attr,omitempty"`
	Description string `xml:"description,attr,omitempty"`

	InputUnits             Units  `xml:"InputUnits"`
	OutputUnits            Units  `xml:"OutputUnits"`
	CfTransferFunctionType string `xml:"CfTransferFunctionType"`

	Numerators   []CoefficientNumerator   `xml:"Numerator,omitempty"`
	Denominators []CoefficientDenominator `xml:"Denominator,omitempty"`
}

type DecimationType

type DecimationType struct {
	InputSampleRate float64 `xml:"InputSampleRate"`
	Factor          int     `xml:"Factor"`
	Offset          int     `xml:"Offset"`
	Delay           float64 `xml:"Delay"`
	Correction      float64 `xml:"Correction"`
}

type Decoder10

type Decoder10 struct{}

func (Decoder10) Decode

func (d Decoder10) Decode(data []byte) ([]byte, error)

type Decoder11

type Decoder11 struct{}

func (Decoder11) Decode

func (d Decoder11) Decode(data []byte) ([]byte, error)

type Decoder12

type Decoder12 struct{}

func (Decoder12) Decode

func (d Decoder12) Decode(data []byte) ([]byte, error)

type Encoder10

type Encoder10 struct{}

func (Encoder10) Channel

func (e Encoder10) Channel(root Root, network Network, channel Channel) []stationxml.ChannelType

func (Encoder10) MarshalRoot

func (e Encoder10) MarshalRoot(root Root) ([]byte, error)

func (Encoder10) Network

func (e Encoder10) Network(root Root, external External) stationxml.NetworkType

func (Encoder10) Response

func (e Encoder10) Response(response *ResponseType) *stationxml.ResponseType

func (Encoder10) Station

func (e Encoder10) Station(root Root, external External, network Network, station Station) stationxml.StationType

type Encoder11

type Encoder11 struct{}

func (Encoder11) Channel

func (e Encoder11) Channel(root Root, network Network, channel Channel) []stationxml.ChannelType

func (Encoder11) MarshalRoot

func (e Encoder11) MarshalRoot(root Root) ([]byte, error)

func (Encoder11) Network

func (e Encoder11) Network(root Root, external External) stationxml.NetworkType

func (Encoder11) Response

func (e Encoder11) Response(response *ResponseType) *stationxml.ResponseType

func (Encoder11) Station

func (e Encoder11) Station(root Root, external External, network Network, station Station) stationxml.StationType

type Encoder12

type Encoder12 struct{}

func (Encoder12) Channel

func (e Encoder12) Channel(root Root, network Network, channel Channel) []stationxml.ChannelType

func (Encoder12) MarshalRoot

func (e Encoder12) MarshalRoot(root Root) ([]byte, error)

func (Encoder12) Network

func (e Encoder12) Network(root Root, external External) stationxml.NetworkType

func (Encoder12) Response

func (e Encoder12) Response(response *ResponseType) *stationxml.ResponseType

func (Encoder12) Station

func (e Encoder12) Station(root Root, external External, network Network, station Station) stationxml.StationType

type Equipment

type Equipment struct {
	Type             string
	Description      string
	Manufacturer     string
	Model            string
	SerialNumber     string
	InstallationDate time.Time
	RemovalDate      time.Time
	Response         string
}

Equipment describes a StationXML Equipment element

type External

type External struct {
	Code        string
	Description string
	Restricted  bool

	StartDate time.Time
	EndDate   time.Time

	Networks []Network
}

External maps between an External Network and individal Networks.

type FirType

type FirType struct {
	ResourceId  string `xml:"resourceId,attr"`
	Name        string `xml:"name,attr,omitempty"`
	Description string `xml:"description,attr,omitempty"`

	InputUnits  Units  `xml:"InputUnits"`
	OutputUnits Units  `xml:"OutputUnits"`
	Symmetry    string `xml:"Symmetry"`

	NumeratorCoefficients []NumeratorCoefficient `xml:"NumeratorCoefficient"`
}

type Float

type Float struct {
	Value float64 `xml:",chardata"`
}

type InstrumentPolynomial

type InstrumentPolynomial struct {
	ResourceId  string `xml:"resourceId,attr,omitempty"`
	Name        string `xml:"name,attr"`
	Description string `xml:"description,attr,omitempty"`

	InputUnits  Units `xml:"InputUnits"`
	OutputUnits Units `xml:"OutputUnits"`

	ApproximationType       string             `xml:"ApproximationType"`
	FrequencyLowerBound     float64            `xml:"FrequencyLowerBound"`
	FrequencyUpperBound     float64            `xml:"FrequencyUpperBound"`
	ApproximationLowerBound ApproximationBound `xml:"ApproximationLowerBound"`
	ApproximationUpperBound ApproximationBound `xml:"ApproximationUpperBound"`
	MaximumError            float64            `xml:"MaximumError"`

	Coefficients []PolynomialCoefficient `xml:"Coefficient,omitempty"`
}

type InstrumentSensitivity

type InstrumentSensitivity struct {
	Value       float64 `xml:"Value"`
	Frequency   float64 `xml:"Frequency"`
	InputUnits  Units   `xml:"InputUnits"`
	OutputUnits Units   `xml:"OutputUnits"`
}

type Network

type Network struct {
	Code        string
	Description string
	Restricted  bool

	Stations []Station
}

Network forms the main part of a StationXML Network element.

type NumeratorCoefficient

type NumeratorCoefficient struct {
	I     int     `xml:"i,attr"`
	Value float64 `xml:",chardata"`
}

type PoleZero

type PoleZero struct {
	Number int `xml:"number,attr"`

	Real      Float `xml:"Real"`
	Imaginary Float `xml:"Imaginary"`
}

type PolesZerosType

type PolesZerosType struct {
	ResourceId  string `xml:"resourceId,attr"`
	Name        string `xml:"name,attr,omitempty"`
	Description string `xml:"description,attr,omitempty"`

	InputUnits  Units `xml:"InputUnits"`
	OutputUnits Units `xml:"OutputUnits"`

	PzTransferFunctionType string  `xml:"PzTransferFunctionType"`
	NormalizationFactor    float64 `xml:"NormalizationFactor"`
	NormalizationFrequency float64 `xml:"NormalizationFrequency"`

	Zeros []PoleZero `xml:"Zero"`
	Poles []PoleZero `xml:"Pole"`
}

func (PolesZerosType) Gain

func (pz PolesZerosType) Gain(freq float64) float64

Gain ccalculates the poles and zeros response gain at a given frequency

type PolynomialCoefficient

type PolynomialCoefficient struct {
	Number int     `xml:"number,attr"`
	Value  float64 `xml:",chardata"`
}

type PolynomialType

type PolynomialType struct {
	ResourceId  string `xml:"resourceId,attr,omitempty"`
	Name        string `xml:"name,attr,omitempty"`
	Description string `xml:"description,attr,omitempty"`

	InputUnits  Units `xml:"InputUnits"`
	OutputUnits Units `xml:"OutputUnits"`

	ApproximationType       string             `xml:"ApproximationType"`
	FrequencyLowerBound     float64            `xml:"FrequencyLowerBound"`
	FrequencyUpperBound     float64            `xml:"FrequencyUpperBound"`
	ApproximationLowerBound ApproximationBound `xml:"ApproximationLowerBound"`
	ApproximationUpperBound ApproximationBound `xml:"ApproximationUpperBound"`
	MaximumError            float64            `xml:"MaximumError"`

	Coefficients []PolynomialCoefficient `xml:"Coefficient,omitempty"`
}

func (PolynomialType) Value

func (p PolynomialType) Value(input float64) float64

type Response

type Response struct {
	Prefix        string
	Serial        string
	Frequency     float64
	ScaleFactor   float64
	ScaleBias     float64
	ScaleAbsolute float64
	GainFactor    float64
	GainBias      float64
	GainAbsolute  float64
	Telemetry     float64
	Preamp        float64
	// contains filtered or unexported fields
}

Response is used for building an instrument response based on sensor and datalogger pairs. It makes no assumption about the StationXML version, ideally it should encompass all required elements. The conversion from a bas Response to a particular version is done via encoding interfaces.

func NewResponse

func NewResponse(opts ...ResponseOpt) *Response

NewResponse builds a Response with the given options.

func (*Response) Coeffs

func (r *Response) Coeffs() []PolynomialCoefficient

Coeffs returns a slice of PolynomialCoeffiencent values present in the Response.

func (*Response) Config

func (r *Response) Config(opts ...ResponseOpt)

Config can be used to set extra Response options.

func (*Response) Derived

func (r *Response) Derived(data []byte) (*ResponseType, error)

Derived returns a ResponseType when there is only a single set of derived Response stages.

func (*Response) Marshal

func (r *Response) Marshal() ([]byte, error)

Marshal generates an XML encoded version of the Response as a ResponseType.

func (*Response) Normalise

func (r *Response) Normalise() error

Normalise adjusts the labels and stage gains of a Response.

func (*Response) Polynomial

func (r *Response) Polynomial() *PolynomialType

Polynomial finds the PolynomialType in the Response if one is present.

func (*Response) ResponseType

func (r *Response) ResponseType() (*ResponseType, error)

ResponseType builds a combined ResponseType from a Response.

func (*Response) Scale

func (r *Response) Scale() float64

Scale calculates the overall response scale factor.

func (*Response) SetCalibration

func (r *Response) SetCalibration(scale, bias, absolute float64)

SetCalibration is used to set a initial sensor reference gain, this overrides the default values.

func (*Response) SetDatalogger

func (r *Response) SetDatalogger(data []byte) error

SetDatalogger takes an XML encoded ResponseType that represents a Datalogger and adds it to the Response.

func (*Response) SetFrequency

func (r *Response) SetFrequency(frequency float64)

SetFrequency is used to set the overall reference frequency for the Response.

func (*Response) SetGain

func (r *Response) SetGain(scale, bias, absolute float64)

SetGain is used to adjusts the installed sensor gains, this is in addition to the default values.

func (*Response) SetPreamp

func (r *Response) SetPreamp(preamp float64)

SetPreamp is used to adjusts the datalogger gains, this is in addition to the default values.

func (*Response) SetPrefix

func (r *Response) SetPrefix(prefix string)

SetPrefix sets the label used to prefix Response element names.

func (*Response) SetSensor

func (r *Response) SetSensor(data []byte) error

SetSensor takes an XML encoded ResponseType that represents a Sensor and adds it to the Response.

func (*Response) SetSerial

func (r *Response) SetSerial(serial string)

SetSerial sets the label used to prefix Response equipment labels.

func (*Response) SetTelemetry

func (r *Response) SetTelemetry(gain float64)

SetTelemetry is used to adjusts the datalogger gains, this is in addition to the default values.

type ResponseOpt

type ResponseOpt func(*Response)

func Calibration

func Calibration(factor, bias, absolute float64) ResponseOpt

Calibration is used to set a initial sensor reference gain, this overrides the default values.

func Frequency

func Frequency(frequency float64) ResponseOpt

Frequency is used to set the overall reference frequency for the Response.

func Gain

func Gain(factor, bias, absolute float64) ResponseOpt

Gain is used to adjusts the installed sensor gains, this is in addition to the default values.

func Preamp

func Preamp(preamp float64) ResponseOpt

Preamp is used to adjusts the datalogger gains, this is in addition to the default values.

func Prefix

func Prefix(prefix string) ResponseOpt

Prefix sets the label used to prefix Response element names.

func Serial

func Serial(serial string) ResponseOpt

Serial sets the label used to prefix Response equipment labels.

func Telemetry

func Telemetry(gain float64) ResponseOpt

Telemetry is used to adjusts the sensor and datalogger connection gain, this is in addition to the default values.

type ResponseStageType

type ResponseStageType struct {
	Number int `xml:"number,attr"`

	Coefficients *CoefficientsType `xml:"Coefficients,omitempty"`
	Decimation   *DecimationType   `xml:"Decimation,omitempty"`
	FIR          *FirType          `xml:"FIR,omitempty"`
	PolesZeros   *PolesZerosType   `xml:"PolesZeros,omitempty"`
	Polynomial   *PolynomialType   `xml:"Polynomial,omitempty"`

	StageGain *StageGain `xml:"StageGain,omitempty"`
}

func (*ResponseStageType) Clone

clone two responses to avoid shared backing arrays

type ResponseType

type ResponseType struct {
	XMLName    xml.Name `xml:"Response"`
	ResourceId string   `xml:"resourceId,attr,omitempty"`

	InstrumentSensitivity *InstrumentSensitivity `xml:"InstrumentSensitivity,omitempty"`
	InstrumentPolynomial  *InstrumentPolynomial  `xml:"InstrumentPolynomial,omitempty"`

	Stages []ResponseStageType `xml:"Stage,omitempty"`
	// contains filtered or unexported fields
}

ResponseType is a struct that mimics the StationXML ResponseType element, but is not constrained to a particular version.

func NewResponseType

func NewResponseType(data []byte) (*ResponseType, error)

func (ResponseType) Marshal

func (r ResponseType) Marshal() ([]byte, error)

func (*ResponseType) PolynomialCoefficients

func (r *ResponseType) PolynomialCoefficients() []PolynomialCoefficient

func (*ResponseType) PolynomialType

func (r *ResponseType) PolynomialType() *PolynomialType

func (*ResponseType) Scale

func (r *ResponseType) Scale() float64

func (*ResponseType) Unmarshal

func (r *ResponseType) Unmarshal(data []byte) error

type Root

type Root struct {
	Source string
	Sender string
	Module string
	Create bool

	Externals []External
}

Root describes the standard StationXML layout which can be used as the barebones for building version specific encoders.

func (Root) ExternalCode

func (r Root) ExternalCode() string

ExternalCode returns the network code of the first External entry in the Root structure, this is aimed at building single entry file names.

func (Root) MarshalVersion

func (r Root) MarshalVersion(version string) ([]byte, error)

Encode encodes the Root struct using the given Encoder.

func (Root) NetworkCode

func (r Root) NetworkCode() string

NetworkCode returns the network code of the first Network entry in the Root structure, this is aimed at building single entry file names.

func (Root) Single

func (r Root) Single(code string) (Root, bool)

Single builds a Root structure for the given station code.

func (Root) StationCode

func (r Root) StationCode() string

StationCode returns the station code of the first Station entry in the Root structure, this is aimed at building single entry file names.

func (Root) Write

func (r Root) Write(wr io.Writer, version string) error

Write encodes and writes the output from the given Encoder for a Root struct.

func (Root) WriteFile

func (r Root) WriteFile(path string, version string) error

WriteFile encodes and stores the output from the given Encoder for a Root struct.

type StageGain

type StageGain struct {
	Value     float64 `xml:"Value"`
	Frequency float64 `xml:"Frequency"`
}

type Station

type Station struct {
	Code        string
	Name        string
	Description string

	Latitude  float64
	Longitude float64
	Elevation float64
	Survey    string
	Datum     string

	StartDate time.Time
	EndDate   time.Time

	CreationDate    time.Time
	TerminationDate time.Time

	Channels []Channel
}

Station forms the main part of a StationXML Station element.

type Stream

type Stream struct {
	Code string

	SamplingRate float64
	Triggered    bool
	Types        string

	Vertical float64
	Azimuth  float64
	Dip      float64

	Datalogger Equipment
	Sensor     Equipment

	StartDate time.Time
	EndDate   time.Time

	Response *ResponseType
}

Stream forms the main part of an individual StationXML Channel element

type Units

type Units struct {
	Name        string `xml:"Name"`
	Description string `xml:"Description,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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