sinex

package
v0.0.0-...-d1957c9 Latest Latest
Warning

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

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

README

Decode SINEX files

SINEX - Solution (Software/technique) INdependent EXchange Format

The format description is available at https://www.iers.org/IERS/EN/Organization/AnalysisCoordinator/SinexFormat/sinex.html.

So far decoding is implemented for the following blocks:

  • FILE/REFERENCE
  • SITE/ID
  • SITE/RECEIVER
  • SITE/ANTENNA
  • SOLUTION/ESTIMATE
Install
$ go get -u github.com/de-bkg/gognss
Decode estimates
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/de-bkg/gognss/pkg/sinex"
)

func main() {
	r, err := os.Open("path/to/sinexfile")
	if err != nil {
		log.Fatal(err)
	}
	defer r.Close()

	dec, err := sinex.NewDecoder(r)
	if err != nil {
		log.Fatal(err)
	}

	// Get the header
	hdr := dec.Header

	// Iterate over blocks.
	var estimates []sinex.Estimate
	for name, err := range dec.Blocks() {
		if err != nil {
			log.Fatal(err)
		}

  	// Decode all SOLUTION/ESTIMATE records.
		if name == sinex.BlockSolEstimate {
			for _, err := range dec.BlockLines() { // Reads the next line into buffer.
				if err != nil {
					log.Fatal(err)
				}

				var est sinex.Estimate
				err := dec.Decode(&est)
				if err != nil {
					log.Fatal(err)
				}

				// Do something with est.
				fmt.Printf("%s: %.5f\n", est.SiteCode, est.Value)
				estimates = append(estimates, est)
			}
		}
	}

	// Iterate over coordinates for each station and epoch, based on estimates.
	for rec := range AllStationCoordinates(estimates) {
		fmt.Printf("%v\n", rec)
	}
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotfound is returned if the block was not found. See also ErrMandatoryBlockNotFound.
	ErrNotfound = errors.New("not found")

	// ErrMandatoryBlockNotFound is returned if a mandatory block is missing.
	ErrMandatoryBlockNotFound = errors.New("mandatory block not found")
)

General Static Errors.

Functions

func AllStationCoordinates

func AllStationCoordinates(estimates []Estimate) iter.Seq[StationCoordinates]

AllStationCoordinates returns an iterator over Estimates that yields the coordinates for each station and epoch.

func Unmarshal

func Unmarshal(in string, out Unmarshaler) error

Unmarshal in to out.

Types

type Antenna

type Antenna struct {
	SiteCode  SiteCode             // 4-char site code, e.g. WTZR.
	PointCode string               // A 2-char code identifying physical monument within a site.
	SolID     string               // Solution ID at a Site/Point code for which the parameter is estimated.
	ObsTech   ObservationTechnique // Technique(s) used to generate the SINEX solution.
	*gnss.Antenna
}

Antenna for GNSS.

func (*Antenna) UnmarshalSINEX

func (ant *Antenna) UnmarshalSINEX(in string) error

Unmarshall a SITE/ANTENNA record.

type Blockname

type Blockname = string
const (
	BlockFileReference     Blockname = "FILE/REFERENCE"                  // Information on the Organization, point of contact, etc.
	BlockFileComment       Blockname = "FILE/COMMENT"                    // General comments about the SINEX data file.
	BlockInputHistory      Blockname = "INPUT/HISTORY"                   // Information about the source of the information used to create the current SINEX file.
	BlockInputFiles        Blockname = "INPUT/FILES"                     // Source data files.
	BlockInputAck          Blockname = "INPUT/ACKNOWLEDGEMENTS"          // Defines the agency codes contributing to the SINEX file.
	BlockNutationData      Blockname = "NUTATION/DATA"                   // VLBI: contains the nutation model used in the analysis procedure.
	BlockPrecessionData    Blockname = "PRECESSION/DATA"                 // VLBI: contains the precession model used in the analysis procedure.
	BlockSourceID          Blockname = "SOURCE/ID"                       // VLBI: contains information about the radio sources estimated in the analysis.
	BlockSiteID            Blockname = "SITE/ID"                         // General information for each site containing estimated parameters.
	BlockSiteData          Blockname = "SITE/DATA"                       // Relationship between the estimated station parameters and in the input files.
	BlockSiteReceiver      Blockname = "SITE/RECEIVER"                   // GNSS: The receiver used at each site during the observation period.
	BlockSiteAntenna       Blockname = "SITE/ANTENNA"                    // GNSS: The antennas used at each site during the observation period.
	BlockSiteGPSPhaseCen   Blockname = "SITE/GPS_PHASE_CENTER"           // GPS: phase center offsets for the antennas.
	BlockSiteGalPhaseCen   Blockname = "SITE/GAL_PHASE_CENTER"           // Galileo: phase center offsets for the antennas.
	BlockSiteEcc           Blockname = "SITE/ECCENTRICITY"               // Antenna eccentricities from the Marker to the Antenna Reference Point (ARP).
	BlockSatelliteID       Blockname = "SATELLITE/ID"                    // List of GNSS satellites used.
	BlockSatellitePhaseCen Blockname = "SATELLITE/PHASE_CENTER"          // GNSS satellite antenna phase center corrections.
	BlockSolEpochs         Blockname = "SOLUTION/EPOCHS"                 // List of observation timespan for each solution, site and point for which parameters have been estimated.
	BlockBiasEpochs        Blockname = "BIAS/EPOCHS"                     // List of epochs of bias parameters for each Site Code/Point Code/Solution Number/Bias Type (SPNB) combination
	BlockSolStatistics     Blockname = "SOLUTION/STATISTICS"             // Statistical information about the solution.
	BlockSolEstimate       Blockname = "SOLUTION/ESTIMATE"               // Estimated values and standard deviations of all solution parameters.
	BlockSolApriori        Blockname = "SOLUTION/APRIORI"                // Apriori information for estimated parameters.
	BlockSolMatrixEst      Blockname = "SOLUTION/MATRIX_ESTIMATE"        // The estimate matrix.
	BlockSolMatrixApr      Blockname = "SOLUTION/MATRIX_APRIORI"         // The apriori matrix.
	BlockSolNormalEquVec   Blockname = "SOLUTION/NORMAL_EQUATION_VECTOR" // Vector of the right hand side of the unconstrained (reduced) normal equation.

	// Inofficial
	BlockSolDiscontinuity Blockname = "SOLUTION/DISCONTINUITY" // Solution discontinuities.
)

type Decoder

type Decoder struct {
	Header *Header
	// contains filtered or unexported fields
}

Decoder reads and decodes the SINEX input stream.

Example (Estimates)

Loop over the epochs of a observation data input stream.

r, err := os.Open("testdata/igs20P21161.snx")
if err != nil {
	log.Fatal(err)
}
defer r.Close()

dec, err := NewDecoder(r)
if err != nil {
	log.Fatal(err)
}

var estimates []Estimate
for name, err := range dec.Blocks() {
	if err != nil {
		log.Fatal(err)
	}

	if name == BlockSolEstimate {
		for _, err := range dec.BlockLines() { // Reads the next line into buffer.
			if err != nil {
				log.Fatal(err)
			}

			var est Estimate
			err := dec.Decode(&est)
			if err != nil {
				log.Fatal(err)
			}
			estimates = append(estimates, est)

			// Do something with est
			// fmt.Printf("%s: %.5f\n", est.SiteCode, est.Value)
		}
	}
}

for rec := range AllStationCoordinates(estimates) {
	fmt.Printf("%v\n", rec)
}

func NewDecoder

func NewDecoder(r io.Reader) (*Decoder, error)

NewDecoder returns a new decoder that reads from r. The header line and FILE/REFERENCE block will be read implicitely. If not existant, ErrMandatoryBlockNotFound will be returned.

It is the caller's responsibility to call Close on the underlying reader when done!

func (*Decoder) BlockLines

func (dec *Decoder) BlockLines() iter.Seq2[string, error]

BlockLines returns an iterator over all lines in the current block. It reads the current line into the internal buffer. It returns a single-use iterator.

func (*Decoder) Blocks

func (dec *Decoder) Blocks() iter.Seq2[Blockname, error]

Blocks returns an iterator over all blocks in the stream. The underlying reader is at the begin of the block. It returns a single-use iterator.

func (*Decoder) CurrentBlock

func (dec *Decoder) CurrentBlock() string

Returns the name of the current block.

func (*Decoder) Decode

func (dec *Decoder) Decode(out Unmarshaler) error

Decode the current line in buffer into out.

func (*Decoder) GetFileReference

func (dec *Decoder) GetFileReference() FileReference

Return the FILE/REFERENCE data.

func (*Decoder) GoToBlock

func (dec *Decoder) GoToBlock(name Blockname) error

GoToBlock keeps on reading until the wanted block is found or the reader is already in the wanted block. In general prefer using dec.NextBlock(). ErrNotfound is returned in case of not being found.

func (*Decoder) Line

func (dec *Decoder) Line() string

Line returns the current Line in buffer.

type Discontinuity

type Discontinuity struct {
	SiteCode  SiteCode          // 4-char site code, e.g. WTZR.
	ParType   ParameterType     // The type of the parameter.
	Idx       int               // soln number, beginning with 1, not identical as soln in estimate.
	Type      DiscontinuityType // Discontinuity type.
	StartTime time.Time         // Start time of the data.
	EndTime   time.Time         // End time of the data.
	Event     string            // Event explaination text, e.g. info for earth quake, equipment changes.
}

Discontinuity describes a discontinuity e.g. in the solution. Note this block is not official.

func (*Discontinuity) UnmarshalSINEX

func (dis *Discontinuity) UnmarshalSINEX(in string) error

Unmarshall a SOLUTION/DISCONTINUITY record.

type DiscontinuityType

type DiscontinuityType string

DiscontinuityType identifies the type of discontinuity.

const (
	DiscontinuityTypePos        DiscontinuityType = "P" // discontinuity for position.
	DiscontinuityTypeVel        DiscontinuityType = "V" // discontinuity for velocity.
	DiscontinuityTypeAnnual     DiscontinuityType = "A" // discontinuity for annnual.
	DiscontinuityTypeSemiAnnual DiscontinuityType = "S" // discontinuity for semmi Annual.
	DiscontinuityTypeExpPSD     DiscontinuityType = "E" // discontinuity for Exponential Post-sesmic Relaxation.
)

type Estimate

type Estimate struct {
	Idx            int           // Index of estimated parameters, beginning with 1.
	ParType        ParameterType // The type of the parameter.
	SiteCode       SiteCode      // 4-char site code, e.g. WTZR.
	PointCode      string        // A 2-char code identifying physical monument within a site.
	SolID          string        // Solution ID at a Site/Point code for which the parameter is estimated.
	Epoch          time.Time     // Epoch at which the estimated parameter is valid.
	Unit           string        // Units used for the estimates and sigmas.
	ConstraintCode string        // Constraint code applied to the parameter.
	Value          float64       // Estimated value of the parameter.
	Stddev         float64       // Estimated standard deviation for the parameter.
}

Estimate stores the estimated solution parameters.

func (*Estimate) UnmarshalSINEX

func (est *Estimate) UnmarshalSINEX(in string) error

Unmarshall a SOLUTION/ESTIMATE record.

type FileReference

type FileReference struct {
	Description string // Organization(s).
	Output      string // File contents.
	Contact     string // Contact information.
	Software    string // SW used to generate the file.
	Hardware    string // Hardware on which above software was run.
	Input       string // Input used to generate this solution.
}

FileReference provides information on the Organization, point of contact, the software and hardware involved in the creation of the file.

type Header struct {
	Version            string               // Format version.
	Agency             string               // Agency creating the file.
	AgencyDataProvider string               // Agency providing the data in the file.
	CreationTime       time.Time            // Creation time of the file.
	StartTime          time.Time            // Start time of the data.
	EndTime            time.Time            // End time of the data.
	ObsTech            ObservationTechnique // Technique(s) used to generate the SINEX solution.
	NumEstimates       int                  // parameters estimated
	ConstraintCode     int                  // Single digit indicating the constraints:  0-fixed/tight constraints, 1-significant constraints, 2-unconstrained.
	SolutionTypes      []string             // Solution types contained in this SINEX file. Each character in this field may be one of the following:

}

Header containes the information from the SINEX Header line.

func (*Header) UnmarshalSINEX

func (hdr *Header) UnmarshalSINEX(in string) error

Unmarshall the header line.

type ObservationTechnique

type ObservationTechnique int

ObservationTechnique used to arrive at the solutions obtained in this SINEX file, e.g. SLR, GPS, VLBI. It should be consistent with the IERS convention.

const (
	ObsTechCombined ObservationTechnique = iota + 1
	ObsTechDORIS
	ObsTechSLR
	ObsTechLLR
	ObsTechGPS
	ObsTechVLBI
)

Observation techniques.

func (ObservationTechnique) String

func (techn ObservationTechnique) String() string

type ParameterType

type ParameterType string

ParameterType identifies the type of parameter.

const (
	ParameterTypeSTAX ParameterType = "STAX" // Station X coordinate in m.
	ParameterTypeSTAY ParameterType = "STAY" // Station Y coordinate in m.
	ParameterTypeSTAZ ParameterType = "STAZ" // Station Z coordinate in m.

)

type Receiver

type Receiver struct {
	SiteCode  SiteCode             // 4-char site code, e.g. WTZR.
	PointCode string               // A 2-char code identifying physical monument within a site.
	SolID     string               // Solution ID at a Site/Point code for which the parameter is estimated.
	ObsTech   ObservationTechnique // Technique(s) used to generate the SINEX solution.
	*gnss.Receiver
}

Receiver for GNSS.

func (*Receiver) UnmarshalSINEX

func (recv *Receiver) UnmarshalSINEX(in string) error

Unmarshall a SITE/RECEIVER record.

type Site

type Site struct {
	Code        SiteCode // 4-charID site code, e.g. WTZR.
	PointCode   string   // A 2-char code identifying physical monument within a site.
	DOMESNumber string
	ObsTech     ObservationTechnique // Technique(s) used to generate the SINEX solution.
	Description string               // Site description, e.g. city.
	Lon         string               // Longitude
	Lat         string               // Latitude
	Height      float64

	Receivers []*gnss.Receiver
	Antennas  []*gnss.Antenna
}

Site provides general information for each site. See also site.Site{}

func (*Site) UnmarshalSINEX

func (s *Site) UnmarshalSINEX(in string) error

Unmarshall a SITE/ID record.

type SiteCode

type SiteCode = string

SiteCode is the site identifier, usually the FourCharID.

type StationCoordinates

type StationCoordinates struct {
	SiteCode       SiteCode   // 4-char site code, e.g. WTZR.
	PointCode      string     // A 2-char code identifying physical monument within a site.
	SolID          string     // Solution ID at a Site/Point code for which the parameter is estimated.
	Epoch          time.Time  // Epoch at which the estimated parameter is valid.
	Unit           string     // Units used for the estimates and sigmas.
	ConstraintCode string     // Constraint code applied to the parameter.
	Values         [3]float64 // The XYZ-coordinates.
	Stddev         [3]float64 // Estimated standard deviation for the coordinates.
}

type Unmarshaler

type Unmarshaler interface {
	UnmarshalSINEX(string) error
}

Jump to

Keyboard shortcuts

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