ms

package
v0.0.0-...-e45c2a7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 8 Imported by: 2

README

ms

import "github.com/GeoNet/kit/seis/ms"

Overview

The ms module has been writen as a lightweight replacement for some parts of the libmseed C library.

Index

Package files

blockette.go btime.go decode.go doc.go header.go record.go steim.go unpack.go

Constants

const (
    BlocketteHeaderSize = 4
    Blockette1000Size   = 4
    Blockette1001Size   = 4
)
const BTimeSize = 10

BTimeSize is the fixed size of an encoded BTime.

const RecordHeaderSize = 48

RecordHeaderSize is the miniseed block fixed header length.

func EncodeBTime

func EncodeBTime(at BTime) []byte

EncodeBTime converts a BTime into a byte slice.

func EncodeBlockette1000

func EncodeBlockette1000(blk Blockette1000) []byte

EncodeBlockette1000 converts a Blockette1000 into a byte slice.

func EncodeBlockette1001

func EncodeBlockette1001(blk Blockette1001) []byte

func EncodeBlocketteHeader

func EncodeBlocketteHeader(hdr BlocketteHeader) []byte

EncodeBlocketteHeader converts a BlocketteHeader into a byte slice.

func EncodeRecordHeader

func EncodeRecordHeader(hdr RecordHeader) []byte

EncodeRecordHeader converts a RecordHeader into a byte slice.

type BTime

type BTime struct {
    Year   uint16
    Doy    uint16
    Hour   uint8
    Minute uint8
    Second uint8
    Unused byte
    S0001  uint16
}

BTime is the SEED Representation of Time.

func DecodeBTime
func DecodeBTime(data []byte) BTime

DecodeBTime returns a BTime from a byte slice.

func NewBTime
func NewBTime(t time.Time) BTime

NewBTime builds a BTime from a time.Time.

func (BTime) Marshal
func (b BTime) Marshal() ([]byte, error)
func (BTime) Time
func (b BTime) Time() time.Time

Time converts a BTime into a time.Time.

func (*BTime) Unmarshal
func (b *BTime) Unmarshal(data []byte) error

type Blockette1000

type Blockette1000 struct {
    Encoding     uint8
    WordOrder    uint8
    RecordLength uint8
    Reserved     uint8
}

Blockette1000 is a Data Only Seed Blockette (excluding header).

func DecodeBlockette1000
func DecodeBlockette1000(data []byte) Blockette1000

DecodeBlockette1000 returns a Blockette1000 from a byte slice.

func (Blockette1000) Marshal
func (b Blockette1000) Marshal() ([]byte, error)

Marshal converts a Blockette1000 into a byte slice.

func (*Blockette1000) Unmarshal
func (b *Blockette1000) Unmarshal(data []byte) error

Unmarshal converts a byte slice into the Blockette1000

type Blockette1001

type Blockette1001 struct {
    TimingQuality uint8
    MicroSec      int8 //Increased accuracy for starttime
    Reserved      uint8
    FrameCount    uint8
}

Blockette1001 is a "Data Extension Blockette" (excluding header).

func DecodeBlockette1001
func DecodeBlockette1001(data []byte) Blockette1001

DecodeBlockette1001 returns a Blockette1001 from a byte slice.

func (Blockette1001) Marshal
func (b Blockette1001) Marshal() ([]byte, error)

Marshal converts a Blockette1001 into a byte slice.

func (*Blockette1001) Unmarshal
func (b *Blockette1001) Unmarshal(data []byte) error

Unmarshal converts a byte slice into the Blockette1001

type BlocketteHeader

type BlocketteHeader struct {
    BlocketteType uint16
    NextBlockette uint16 // Byte of next blockette, 0 if last blockette
}

BlocketteHeader stores the header of each miniseed blockette.

func DecodeBlocketteHeader
func DecodeBlocketteHeader(data []byte) BlocketteHeader

DecodeBlocketteHeader returns a BlocketteHeader from a byte slice.

func (BlocketteHeader) Marshal
func (h BlocketteHeader) Marshal() ([]byte, error)

Marshal converts a BlocketteHeader into a byte slice.

func (*BlocketteHeader) Unmarshal
func (h *BlocketteHeader) Unmarshal(data []byte) error

Unmarshal converts a byte slice into the BlocketteHeader

type Encoding

type Encoding uint8
const (
    EncodingASCII      Encoding = 0
    EncodingInt32      Encoding = 3
    EncodingIEEEFloat  Encoding = 4
    EncodingIEEEDouble Encoding = 5
    EncodingSTEIM1     Encoding = 10
    EncodingSTEIM2     Encoding = 11
)

type Record

type Record struct {
    RecordHeader

    B1000 Blockette1000 //If Present
    B1001 Blockette1001 //If Present

    Data []byte
}

func NewRecord
func NewRecord(buf []byte) (*Record, error)

NewMSRecord decodes and unpacks the record samples from a byte slice and returns a Record pointer, or an empty pointer and an error if it could not be decoded.

func (Record) BlockSize
func (m Record) BlockSize() int

PacketSize returns the length of the packet

func (Record) ByteOrder
func (m Record) ByteOrder() WordOrder

ByteOrder returns the miniseed data byte order.

func (Record) Bytes
func (m Record) Bytes() ([]byte, error)
func (Record) Encoding
func (m Record) Encoding() Encoding

Encoding returns the miniseed data format encoding.

func (Record) EndTime
func (m Record) EndTime() time.Time

EndTime returns the calculated time of the last sample.

func (Record) Float64s
func (m Record) Float64s() ([]float64, error)
func (Record) Int32s
func (m Record) Int32s() ([]int32, error)
func (Record) SampleType
func (m Record) SampleType() SampleType

SampleType returns the type of samples decoded, or UnknownType if no data has been decoded.

func (Record) StartTime
func (m Record) StartTime() time.Time

StartTime returns the calculated time of the first sample.

func (Record) String
func (m Record) String() string

String implements the Stringer interface and provides a short summary of the miniseed record header.

func (Record) Strings
func (m Record) Strings() ([]string, error)
func (*Record) Unpack
func (m *Record) Unpack(buf []byte) error

Unpack decodes the record from a byte slice.

type RecordHeader

type RecordHeader struct {
    SequenceNumber [6]byte // ASCII String representing a 6 digit number

    DataQualityIndicator byte // ASCII: D, R, Q or M
    ReservedByte         byte // ASCII: Space

    // These are ascii strings
    StationIdentifier  [5]byte // ASCII: Left justify and pad with spaces
    LocationIdentifier [2]byte // ASCII: Left justify and pad with spaces
    ChannelIdentifier  [3]byte // ASCII: Left justify and pad with spaces
    NetworkIdentifier  [2]byte // ASCII: Left justify and pad with spaces

    RecordStartTime      BTime  // Start time of record
    NumberOfSamples      uint16 // Number of Samples in the data block which may or may not be unpacked.
    SampleRateFactor     int16  // >0: Samples/Second <0: Second/Samples 0: Seconds/Sample, ASCII/OPAQUE DATA records
    SampleRateMultiplier int16  // >0: Multiplication Factor <0: Division Factor

    // Flags are bit masks
    ActivityFlags    byte
    IOAndClockFlags  byte
    DataQualityFlags byte

    NumberOfBlockettesThatFollow uint8 // Total number of blockettes that follow

    TimeCorrection  int32  // 0.0001 second units
    BeginningOfData uint16 // Offset in bytes to the beginning of data.
    FirstBlockette  uint16 // Offset in bytes to the first data blockette in the data record.
}

func DecodeRecordHeader
func DecodeRecordHeader(data []byte) RecordHeader

DecodeRecordHeader returns a RecordHeader from a byte slice.

func (RecordHeader) Channel
func (h RecordHeader) Channel() string
func (RecordHeader) Correction
func (h RecordHeader) Correction() time.Duration
func (RecordHeader) IsValid
func (h RecordHeader) IsValid() bool

IsValid performs a simple consistency check of the RecordHeader contents.

func (RecordHeader) Less
func (h RecordHeader) Less(hdr RecordHeader) bool

Less can be used for sorting record blocks.

func (RecordHeader) Location
func (h RecordHeader) Location() string
func (RecordHeader) Marshal
func (h RecordHeader) Marshal() ([]byte, error)
func (RecordHeader) Network
func (h RecordHeader) Network() string
func (RecordHeader) SampleCount
func (h RecordHeader) SampleCount() int

SampleCount returns the number of samples in the record, independent of whether they are decoded or not.

func (RecordHeader) SamplePeriod
func (h RecordHeader) SamplePeriod() time.Duration

SamplePeriod converts the sample rate into a time interval, or zero.

func (RecordHeader) SampleRate
func (h RecordHeader) SampleRate() float64

SampleRate returns the decoded header sampling rate in samples per second.

func (RecordHeader) SeqNumber
func (h RecordHeader) SeqNumber() int
func (*RecordHeader) SetChannel
func (h *RecordHeader) SetChannel(s string)
func (*RecordHeader) SetCorrection
func (h *RecordHeader) SetCorrection(correction time.Duration, applied bool)
func (*RecordHeader) SetLocation
func (h *RecordHeader) SetLocation(s string)
func (*RecordHeader) SetNetwork
func (h *RecordHeader) SetNetwork(s string)
func (*RecordHeader) SetSeqNumber
func (h *RecordHeader) SetSeqNumber(no int)
func (*RecordHeader) SetStartTime
func (h *RecordHeader) SetStartTime(t time.Time)
func (*RecordHeader) SetStation
func (h *RecordHeader) SetStation(s string)
func (RecordHeader) SrcName
func (h RecordHeader) SrcName(quality bool) string
func (RecordHeader) StartTime
func (h RecordHeader) StartTime() time.Time
func (RecordHeader) Station
func (h RecordHeader) Station() string
func (*RecordHeader) Unmarshal
func (h *RecordHeader) Unmarshal(data []byte) error

type SampleType

type SampleType byte
const (
    UnknownType SampleType = 0
    ByteType    SampleType = 'a'
    IntegerType SampleType = 'i'
    FloatType   SampleType = 'f'
    DoubleType  SampleType = 'd'
)

type WordOrder

type WordOrder uint8
const (
    LittleEndian WordOrder = 0
    BigEndian    WordOrder = 1
)

Generated by godoc2md

Documentation

Overview

The ms module has been writen as a lightweight replacement for some parts of the libmseed C library.

Index

Constants

View Source
const (
	BlocketteHeaderSize = 4
	Blockette1000Size   = 4
	Blockette1001Size   = 4
)
View Source
const BTimeSize = 10

BTimeSize is the fixed size of an encoded BTime.

View Source
const RecordHeaderSize = 48

RecordHeaderSize is the miniseed block fixed header length.

Variables

This section is empty.

Functions

func EncodeBTime

func EncodeBTime(at BTime) []byte

EncodeBTime converts a BTime into a byte slice.

func EncodeBlockette1000

func EncodeBlockette1000(blk Blockette1000) []byte

EncodeBlockette1000 converts a Blockette1000 into a byte slice.

func EncodeBlockette1001

func EncodeBlockette1001(blk Blockette1001) []byte

func EncodeBlocketteHeader

func EncodeBlocketteHeader(hdr BlocketteHeader) []byte

EncodeBlocketteHeader converts a BlocketteHeader into a byte slice.

func EncodeRecordHeader

func EncodeRecordHeader(hdr RecordHeader) []byte

EncodeRecordHeader converts a RecordHeader into a byte slice.

Types

type BTime

type BTime struct {
	Year   uint16
	Doy    uint16
	Hour   uint8
	Minute uint8
	Second uint8
	Unused byte
	S0001  uint16
}

BTime is the SEED Representation of Time.

func DecodeBTime

func DecodeBTime(data []byte) BTime

DecodeBTime returns a BTime from a byte slice.

func NewBTime

func NewBTime(t time.Time) BTime

NewBTime builds a BTime from a time.Time.

func (BTime) Marshal

func (b BTime) Marshal() ([]byte, error)

func (BTime) Time

func (b BTime) Time() time.Time

Time converts a BTime into a time.Time.

func (*BTime) Unmarshal

func (b *BTime) Unmarshal(data []byte) error

type Blockette1000

type Blockette1000 struct {
	Encoding     uint8
	WordOrder    uint8
	RecordLength uint8
	Reserved     uint8
}

Blockette1000 is a Data Only Seed Blockette (excluding header).

func DecodeBlockette1000

func DecodeBlockette1000(data []byte) Blockette1000

DecodeBlockette1000 returns a Blockette1000 from a byte slice.

func (Blockette1000) Marshal

func (b Blockette1000) Marshal() ([]byte, error)

Marshal converts a Blockette1000 into a byte slice.

func (*Blockette1000) Unmarshal

func (b *Blockette1000) Unmarshal(data []byte) error

Unmarshal converts a byte slice into the Blockette1000

type Blockette1001

type Blockette1001 struct {
	TimingQuality uint8
	MicroSec      int8 //Increased accuracy for starttime
	Reserved      uint8
	FrameCount    uint8
}

Blockette1001 is a "Data Extension Blockette" (excluding header).

func DecodeBlockette1001

func DecodeBlockette1001(data []byte) Blockette1001

DecodeBlockette1001 returns a Blockette1001 from a byte slice.

func (Blockette1001) Marshal

func (b Blockette1001) Marshal() ([]byte, error)

Marshal converts a Blockette1001 into a byte slice.

func (*Blockette1001) Unmarshal

func (b *Blockette1001) Unmarshal(data []byte) error

Unmarshal converts a byte slice into the Blockette1001

type BlocketteHeader

type BlocketteHeader struct {
	BlocketteType uint16
	NextBlockette uint16 // Byte of next blockette, 0 if last blockette
}

BlocketteHeader stores the header of each miniseed blockette.

func DecodeBlocketteHeader

func DecodeBlocketteHeader(data []byte) BlocketteHeader

DecodeBlocketteHeader returns a BlocketteHeader from a byte slice.

func (BlocketteHeader) Marshal

func (h BlocketteHeader) Marshal() ([]byte, error)

Marshal converts a BlocketteHeader into a byte slice.

func (*BlocketteHeader) Unmarshal

func (h *BlocketteHeader) Unmarshal(data []byte) error

Unmarshal converts a byte slice into the BlocketteHeader

type Encoding

type Encoding uint8
const (
	EncodingASCII      Encoding = 0
	EncodingInt32      Encoding = 3
	EncodingIEEEFloat  Encoding = 4
	EncodingIEEEDouble Encoding = 5
	EncodingSTEIM1     Encoding = 10
	EncodingSTEIM2     Encoding = 11
)

type Record

type Record struct {
	RecordHeader

	B1000 Blockette1000 //If Present
	B1001 Blockette1001 //If Present

	Data []byte
}

func NewRecord

func NewRecord(buf []byte) (*Record, error)

NewMSRecord decodes and unpacks the record samples from a byte slice and returns a Record pointer, or an empty pointer and an error if it could not be decoded.

func (Record) BlockSize

func (m Record) BlockSize() int

PacketSize returns the length of the packet

func (Record) ByteOrder

func (m Record) ByteOrder() WordOrder

ByteOrder returns the miniseed data byte order.

func (Record) Bytes

func (m Record) Bytes() ([]byte, error)

func (Record) Encoding

func (m Record) Encoding() Encoding

Encoding returns the miniseed data format encoding.

func (Record) EndTime

func (m Record) EndTime() time.Time

EndTime returns the calculated time of the last sample.

func (Record) Float64s

func (m Record) Float64s() ([]float64, error)

func (Record) Int32s

func (m Record) Int32s() ([]int32, error)

func (Record) SampleType

func (m Record) SampleType() SampleType

SampleType returns the type of samples decoded, or UnknownType if no data has been decoded.

func (Record) StartTime

func (m Record) StartTime() time.Time

StartTime returns the calculated time of the first sample.

func (Record) String

func (m Record) String() string

String implements the Stringer interface and provides a short summary of the miniseed record header.

func (Record) Strings

func (m Record) Strings() ([]string, error)

func (*Record) Unpack

func (m *Record) Unpack(buf []byte) error

Unpack decodes the record from a byte slice.

type RecordHeader

type RecordHeader struct {
	SequenceNumber [6]byte // ASCII String representing a 6 digit number

	DataQualityIndicator byte // ASCII: D, R, Q or M
	ReservedByte         byte // ASCII: Space

	// These are ascii strings
	StationIdentifier  [5]byte // ASCII: Left justify and pad with spaces
	LocationIdentifier [2]byte // ASCII: Left justify and pad with spaces
	ChannelIdentifier  [3]byte // ASCII: Left justify and pad with spaces
	NetworkIdentifier  [2]byte // ASCII: Left justify and pad with spaces

	RecordStartTime      BTime  // Start time of record
	NumberOfSamples      uint16 // Number of Samples in the data block which may or may not be unpacked.
	SampleRateFactor     int16  // >0: Samples/Second <0: Second/Samples 0: Seconds/Sample, ASCII/OPAQUE DATA records
	SampleRateMultiplier int16  // >0: Multiplication Factor <0: Division Factor

	// Flags are bit masks
	ActivityFlags    byte
	IOAndClockFlags  byte
	DataQualityFlags byte

	NumberOfBlockettesThatFollow uint8 // Total number of blockettes that follow

	TimeCorrection  int32  // 0.0001 second units
	BeginningOfData uint16 // Offset in bytes to the beginning of data.
	FirstBlockette  uint16 // Offset in bytes to the first data blockette in the data record.
}

func DecodeRecordHeader

func DecodeRecordHeader(data []byte) RecordHeader

DecodeRecordHeader returns a RecordHeader from a byte slice.

func (RecordHeader) Channel

func (h RecordHeader) Channel() string

func (RecordHeader) Correction

func (h RecordHeader) Correction() time.Duration

func (RecordHeader) IsValid

func (h RecordHeader) IsValid() bool

IsValid performs a simple consistency check of the RecordHeader contents.

func (RecordHeader) Less

func (h RecordHeader) Less(hdr RecordHeader) bool

Less can be used for sorting record blocks.

func (RecordHeader) Location

func (h RecordHeader) Location() string

func (RecordHeader) Marshal

func (h RecordHeader) Marshal() ([]byte, error)

func (RecordHeader) Network

func (h RecordHeader) Network() string

func (RecordHeader) SampleCount

func (h RecordHeader) SampleCount() int

SampleCount returns the number of samples in the record, independent of whether they are decoded or not.

func (RecordHeader) SamplePeriod

func (h RecordHeader) SamplePeriod() time.Duration

SamplePeriod converts the sample rate into a time interval, or zero.

func (RecordHeader) SampleRate

func (h RecordHeader) SampleRate() float64

SampleRate returns the decoded header sampling rate in samples per second.

func (RecordHeader) SeqNumber

func (h RecordHeader) SeqNumber() int

func (*RecordHeader) SetChannel

func (h *RecordHeader) SetChannel(s string)

func (*RecordHeader) SetCorrection

func (h *RecordHeader) SetCorrection(correction time.Duration, applied bool)

func (*RecordHeader) SetLocation

func (h *RecordHeader) SetLocation(s string)

func (*RecordHeader) SetNetwork

func (h *RecordHeader) SetNetwork(s string)

func (*RecordHeader) SetSeqNumber

func (h *RecordHeader) SetSeqNumber(no int)

func (*RecordHeader) SetStartTime

func (h *RecordHeader) SetStartTime(t time.Time)

func (*RecordHeader) SetStation

func (h *RecordHeader) SetStation(s string)

func (RecordHeader) SrcName

func (h RecordHeader) SrcName(quality bool) string

func (RecordHeader) StartTime

func (h RecordHeader) StartTime() time.Time

func (RecordHeader) Station

func (h RecordHeader) Station() string

func (*RecordHeader) Unmarshal

func (h *RecordHeader) Unmarshal(data []byte) error

type SampleType

type SampleType byte
const (
	UnknownType SampleType = 0
	ByteType    SampleType = 'a'
	IntegerType SampleType = 'i'
	FloatType   SampleType = 'f'
	DoubleType  SampleType = 'd'
)

type WordOrder

type WordOrder uint8
const (
	LittleEndian WordOrder = 0
	BigEndian    WordOrder = 1
)

Jump to

Keyboard shortcuts

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