resp

package
v0.0.0-...-c82d20f Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

README

RESPONSE FILES

The goal of the resp directory is to build a golang source module that allows easy instrument response information discovery for downstream programs but primarily to build stationxml representations of the meta information.

ResponseType

The ResponseType is a struct that mimics the StationXML ResponseType element, but is not constrained to any particular version. For this reason it can be used to load base XML files which can then be used to construct the full response needed for StationXML.

The location of the base XML files can be found in:

  • auto -- where the original response files have been converted into an XML equivalent.
  • files -- where response files have been handcrafted as needed.
  • nrl -- where responses derived from the NRL (Nominal Response Library) can be stored.

Files found in any of the locations can be used in the channel and component configurations by removing the .xml suffix.

References

  • Mary E. Templeton (2017): IRIS Library of Nominal Response for Seismic Instruments. Incorporated Research Institutions for Seismology. Dataset. https://doi.org/10.17611/S7159Q

Documentation

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 List

func List() ([]string, error)

List returns a slice representation of generic embeded stationxml responses.

func ListBase

func ListBase(base string) ([]string, error)

ListBase returns a list of generic stationxml responses in the embedded files if no base directory given.

func ListDir

func ListDir(path string) ([]string, error)

ListDir returns a slice of generic stationxml responses stored in the given directory.

func ListFS

func ListFS(fsys fs.FS) ([]string, error)

ListFS returns a slice representation of generic stationxml responses in the given file system.

func Lookup

func Lookup(response string) ([]byte, error)

Lookup returns a byte slice representation of a generic embeded stationxml Response if present.

func LookupBase

func LookupBase(base string, response string) ([]byte, error)

LookupBase returns a byte slice representation of a generic stationxml Response either stored in a given directory or in the embedded files if no base directory given.

func LookupDir

func LookupDir(path string, response string) ([]byte, error)

LookupDir returns a byte slice representation of a generic stationxml Response if stored in the given directory.

func LookupFS

func LookupFS(fsys fs.FS, response string) ([]byte, error)

LookupFS returns a byte slice representation of a generic stationxml Response if present in the given file system.

Types

type ApproximationBound

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

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 FirType

type FirType 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"`
	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 InstrumentResponse

type InstrumentResponse 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
}

InstrumentResponse 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 base Response to a particular version is done via encoding interfaces.

func NewInstrumentResponse

func NewInstrumentResponse(opts ...InstrumentResponseOpt) *InstrumentResponse

NewInstrumentResponse builds a Response with the given options.

func (*InstrumentResponse) Coeffs

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

func (*InstrumentResponse) Config

func (r *InstrumentResponse) Config(opts ...InstrumentResponseOpt)

Config can be used to set extra Response options.

func (*InstrumentResponse) Derived

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

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

func (*InstrumentResponse) Marshal

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

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

func (*InstrumentResponse) Normalise

func (r *InstrumentResponse) Normalise() error

Normalise adjusts the labels and stage gains of a Response.

func (*InstrumentResponse) Polynomial

func (r *InstrumentResponse) Polynomial() *PolynomialType

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

func (*InstrumentResponse) ResponseType

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

ResponseType builds a combined ResponseType from a Response.

func (*InstrumentResponse) Scale

func (r *InstrumentResponse) Scale() float64

Scale calculates the overall response scale factor.

func (*InstrumentResponse) SetCalibration

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

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

func (*InstrumentResponse) SetDatalogger

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

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

func (*InstrumentResponse) SetFrequency

func (r *InstrumentResponse) SetFrequency(frequency float64)

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

func (*InstrumentResponse) SetGain

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

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

func (*InstrumentResponse) SetPreamp

func (r *InstrumentResponse) SetPreamp(preamp float64)

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

func (*InstrumentResponse) SetPrefix

func (r *InstrumentResponse) SetPrefix(prefix string)

SetPrefix sets the label used to prefix Response element names.

func (*InstrumentResponse) SetSensor

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

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

func (*InstrumentResponse) SetSerial

func (r *InstrumentResponse) SetSerial(serial string)

SetSerial sets the label used to prefix Response equipment labels.

func (*InstrumentResponse) SetTelemetry

func (r *InstrumentResponse) SetTelemetry(gain float64)

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

type InstrumentResponseOpt

type InstrumentResponseOpt func(*InstrumentResponse)

func Calibration

func Calibration(factor, bias, absolute float64) InstrumentResponseOpt

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

func Frequency

func Frequency(frequency float64) InstrumentResponseOpt

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

func Gain

func Gain(factor, bias, absolute float64) InstrumentResponseOpt

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

func Preamp

func Preamp(preamp float64) InstrumentResponseOpt

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

func Prefix

func Prefix(prefix string) InstrumentResponseOpt

Prefix sets the label used to prefix Response element names.

func Serial

func Serial(serial string) InstrumentResponseOpt

Serial sets the label used to prefix Response equipment labels.

func Telemetry

func Telemetry(gain float64) InstrumentResponseOpt

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

type InstrumentSensitivity

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

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,omitempty"`
	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 Resp

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

func NewResp

func NewResp(base string) *Resp

func (*Resp) Info

func (r *Resp) Info(responses ...string) (*ResponseInfo, error)

Info builds a ResponseInfo for the given response base and sensor, database and stream collection details.

func (*Resp) Lookup

func (r *Resp) Lookup(response string) ([]byte, error)

func (*Resp) Type

func (r *Resp) Type(response string) (*ResponseType, error)

type ResponseInfo

type ResponseInfo struct {
	Sensitivity float64
	Gain        float64
	Bias        float64
	Input       string
	Output      string
}

ResponseInfo is used to store simplified conversion details.

type ResponseStageType

type ResponseStageType struct {
	Number     int    `xml:"number,attr"`
	ResourceId string `xml:"resourceId,attr,omitempty"`

	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) Frequency

func (r *ResponseType) Frequency() float64

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) SetFrequency

func (r *ResponseType) SetFrequency(freq float64)

func (*ResponseType) Unmarshal

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

type StageGain

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

type Units

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

Jump to

Keyboard shortcuts

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