precise

package
v0.35.7 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

Package precise

Package precise provides types and utilities for handling precise GNSS orbit and clock products from various sources (SP3, RINEX CLK, RTCM SSR, etc.).

Core Types

OrbitRecord

Generic representation of a satellite's position (and optionally velocity) at a specific time. This is the common format used across all precise product types.

type OrbitRecord struct {
    Time     time.Time
    System   gnss.System
    SvID     int
    Position coordinates.Vector3D  // ECEF position in meters
    Clock    float64                // Satellite clock bias in seconds
    Velocity *coordinates.Vector3D  // ECEF velocity in m/s (optional)
}
ClockRecord

Represents precise clock data from RINEX CLK files or other sources.

type ClockRecord struct {
    Time      time.Time
    DataType  ClockDataType  // AS, AR, etc.
    Name      string         // Station or satellite ID
    System    int
    SvID      int
    Bias      float64        // Clock bias in seconds
    BiasSig   float64        // Sigma
    Rate      float64        // Clock rate
    // ... additional fields
}
SP3Record (New in refactor-precise branch)

Enhanced representation specifically for SP3 precise orbit products. Combines position and velocity data with product metadata.

type SP3Record struct {
    Time   time.Time
    System gnss.System
    SvID   int

    // Position (always present)
    Position coordinates.Vector3D  // ECEF, kilometers (SP3 native)
    Clock    float64                // Microseconds
    PosSigma coordinates.Vector3D
    ClkSigma int

    // Velocity (optional, nil if not available)
    Velocity     *coordinates.Vector3D  // dm/s
    ClockRate    *float64
    VelSigma     *coordinates.Vector3D
    ClockRateSigma *int

    // Event/prediction flags
    ClockEventFlag    string
    ClockPredictFlag  string
    OrbitManeuverFlag string
    OrbitPredictFlag  string

    // Product metadata
    ProductMeta *SP3ProductMetadata
}

Key Features:

  • Preserves SP3 native units for efficient storage
  • Nullable velocity fields for products that don't include them
  • Embedded product metadata (analysis center, type, reference frame, etc.)
  • Conversion to OrbitRecord with automatic unit conversion
SP3ProductMetadata (New in refactor-precise branch)

Describes the characteristics of an SP3 product source.

type SP3ProductMetadata struct {
    AnalysisCenter   string  // "IGS", "COD", "GRG", "ESA", etc.
    ProductType      string  // "final", "rapid", "ultra-rapid", "predicted"
    ReferenceFrame   string  // "IGS20", "IGS14", "ITRF2020", etc.
    ReferencePoint   string  // "APC" or "CoM"
    Campaign         string  // "operational", "repro3", etc.
    OrbitType        string  // "FIT", "HLM", "BCT", etc.
    GPSWeek          int
    SamplingInterval int     // seconds
}

Use Cases:

  • Filter orbits by analysis center (compare CODE vs IGS)
  • Select product type (final vs rapid vs ultra-rapid)
  • Ensure consistent reference frame across datasets
  • Track reprocessing campaigns for time series analysis

Unit Conventions

Different precise product formats use different units. This package provides explicit handling:

Type Position Units Clock Units Velocity Units
OrbitRecord meters seconds m/s
SP3Record kilometers microseconds dm/s
ClockRecord N/A seconds dimensionless

Use the provided conversion methods:

  • SP3Record.ToOrbitRecord() - Converts SP3 native units to SI units
  • ClockRecords.LinearInterpolateClockBias() - Returns bias in seconds

Collections and Filtering

All record types provide collection types with helper methods:

OrbitRecords
records := precise.OrbitRecords{...}

// Filter by satellite
gps08 := records.FilterBySatellite(gnss.GPS, 8)

// Get time range
start, end := records.GetTimeRange()
SP3Records
sp3Recs := precise.SP3Records{...}

// Filter by satellite and time
filtered := sp3Recs.
    FilterBySatellite(gnss.GPS, 8).
    FilterByTimeRange(start, end)

// Filter by product characteristics
igsFinal := sp3Recs.FilterByProduct("IGS", "final")
codeFinal := sp3Recs.FilterByProduct("COD", "final")

// Get only records with velocity data
withVel := sp3Recs.WithVelocity()

// Convert all to OrbitRecords
orbitRecs := sp3Recs.ToOrbitRecords()
ClockRecords
clocks := precise.ClockRecords{...}

// Filter by satellite
gps08Clocks := clocks.FilterBySatellite(gnss.GPS, 8)

// Interpolate clock bias at specific time
bias, err := precise.LinearInterpolateClockBias(gps08Clocks, targetTime)

// Find nearest clock value
bias, found := precise.GetNearestClock(gps08Clocks, targetTime, tolerance)

Usage Example

package main

import (
    "fmt"
    "time"

    "gitlab.com/earthscope/gnsstools/pkg/common/gnss"
    "gitlab.com/earthscope/gnsstools/pkg/common/gnss/precise"
    "gitlab.com/earthscope/gnsstools/pkg/encoding/sp3"
)

func main() {
    // Load and parse SP3 file
    file, _ := os.Open("COD0OPSFIN_20240010000_01D_05M_ORB.SP3")
    sp3Data, _ := sp3.NewSP3(file)
    _ = sp3Data.Read()

    // Extract product metadata and convert
    productMeta, _ := sp3.ParseProductFromFilename("COD0OPSFIN_20240010000_01D_05M_ORB.SP3")
    sp3Records := sp3Data.ConvertToSP3RecordsWithMetadata(productMeta)

    // Filter for GPS satellite 8
    gps08 := precise.SP3Records(sp3Records).
        FilterBySatellite(gnss.GPS, 8)

    // Convert to standard OrbitRecords (meters, seconds)
    orbitRecs := gps08.ToOrbitRecords()

    // Use in processing
    for _, orb := range orbitRecs {
        fmt.Printf("GPS 08 @ %s: pos=(%.3f, %.3f, %.3f) m\n",
            orb.Time.Format(time.RFC3339),
            orb.Position[0], orb.Position[1], orb.Position[2])

        if orb.Velocity != nil {
            fmt.Printf("  vel=(%.3f, %.3f, %.3f) m/s\n",
                orb.Velocity[0], orb.Velocity[1], orb.Velocity[2])
        }
    }
}

See Also

  • pkg/encoding/sp3 - SP3 file parser with P+V record merging
  • pkg/encoding/sp3/REFACTOR_NOTES.md - Detailed SP3 refactor documentation
  • pkg/position/ppp-ar - PPP with ambiguity resolution using precise products

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoRecordsAvailable indicates no records are available for the requested operation
	ErrNoRecordsAvailable = errors.New("no records available")

	// ErrInterpolationFailed indicates interpolation could not be performed
	ErrInterpolationFailed = errors.New("interpolation failed")

	// ErrSatelliteNotFound indicates the requested satellite was not found in the data
	ErrSatelliteNotFound = errors.New("satellite not found")
)

Functions

func GetNearestClock added in v0.30.1

func GetNearestClock(records ClockRecords, t time.Time, tolerance time.Duration) (float64, bool)

GetNearestClock finds the nearest clock record to the given time within the tolerance Returns the bias and true if found, 0 and false if not found

func LagrangeInterpolateOrbit added in v0.30.1

func LagrangeInterpolateOrbit(records OrbitRecords, t time.Time, order int) (coordinates.Vector3D, error)

LagrangeInterpolateOrbit performs Lagrange polynomial interpolation on orbit records Uses 9-point Lagrange interpolation for sub-centimeter accuracy (recommended for PPP-AR) Falls back to linear interpolation if fewer than 9 points are available

func LinearInterpolateClock added in v0.30.1

func LinearInterpolateClock(records OrbitRecords, t time.Time) (float64, error)

LinearInterpolateClock performs linear interpolation on orbit records to find clock bias at time t Returns the interpolated clock bias in seconds and an error if interpolation fails

func LinearInterpolateClockBias added in v0.30.1

func LinearInterpolateClockBias(records ClockRecords, t time.Time) (float64, error)

LinearInterpolateClockBias performs linear interpolation on clock records to find bias at time t Returns the interpolated clock bias in seconds and an error if interpolation fails

func LinearInterpolateOrbit added in v0.30.1

func LinearInterpolateOrbit(records OrbitRecords, t time.Time) (coordinates.Vector3D, error)

LinearInterpolateOrbit performs linear interpolation on orbit records to find position at time t Returns the interpolated position and an error if interpolation fails

Types

type ClockDataType added in v0.30.1

type ClockDataType string

ClockDataType represents the type of clock data record

const (
	ClockDataTypeAR ClockDataType = "AR" // Analysis receiver clock
	ClockDataTypeAS ClockDataType = "AS" // Analysis satellite clock
	ClockDataTypeCR ClockDataType = "CR" // Calibration receiver clock
	ClockDataTypeDR ClockDataType = "DR" // Discontinuity receiver clock
	ClockDataTypeMS ClockDataType = "MS" // Monitor satellite clock
)

type ClockEpoch added in v0.30.1

type ClockEpoch struct {
	Time    time.Time     `json:"time"`
	Records []ClockRecord `json:"records"`
}

ClockEpoch represents clock data for multiple satellites/receivers at a single epoch

type ClockRecord added in v0.30.1

type ClockRecord struct {
	Time     time.Time     // Epoch of clock estimate
	DataType ClockDataType // Type of clock record (AS, AR, etc.)
	Name     string        // Station name or satellite identifier
	System   int           // GNSS system (for satellite records)
	SvID     int           // Satellite ID (for satellite records)

	// Clock parameters
	Bias     float64 // Clock bias (seconds)
	BiasSig  float64 // Clock bias sigma (seconds)
	Rate     float64 // Clock rate (dimensionless)
	RateSig  float64 // Clock rate sigma (dimensionless)
	Accel    float64 // Clock acceleration (per second)
	AccelSig float64 // Clock acceleration sigma (per second)
}

ClockRecord represents a single clock measurement This is a format-agnostic representation used by RINEX CLK, SP3, RTCM SSR, etc.

type ClockRecords added in v0.30.1

type ClockRecords []ClockRecord

ClockRecords is a collection of clock records with helper methods

func (ClockRecords) FilterBySatellite added in v0.30.1

func (records ClockRecords) FilterBySatellite(system int, svID int) ClockRecords

FilterBySatellite returns all clock records for a specific satellite

type OrbitRecord added in v0.30.1

type OrbitRecord struct {
	Time     time.Time             // Epoch time
	System   gnss.System           // GNSS system (GPS, GLO, GAL, etc.)
	SvID     int                   // Satellite ID
	Position coordinates.Vector3D  // ECEF position in meters
	Clock    float64               // Satellite clock bias in seconds (optional, 0 if not available)
	Velocity *coordinates.Vector3D // ECEF velocity in m/s (optional, nil if not available)
}

OrbitRecord represents a satellite's position (and optionally clock) at a specific time This is a shared type that can be populated from SP3, RTCM SSR, or other precise orbit sources

func GetNearestOrbit added in v0.30.1

func GetNearestOrbit(records OrbitRecords, t time.Time, tolerance time.Duration) (OrbitRecord, bool)

GetNearestOrbit finds the nearest orbit record to the given time within the tolerance Returns the record and true if found, zero value and false if not found

type OrbitRecords added in v0.30.1

type OrbitRecords []OrbitRecord

OrbitRecords is a collection of orbit records with helper methods

func (OrbitRecords) FilterBySatellite added in v0.30.1

func (records OrbitRecords) FilterBySatellite(system gnss.System, svID int) OrbitRecords

FilterBySatellite returns all orbit records for a specific satellite

func (OrbitRecords) GetTimeRange added in v0.30.1

func (records OrbitRecords) GetTimeRange() (start, end time.Time)

GetTimeRange returns the time span covered by these orbit records

type SP3Element

type SP3Element struct {
	Type   string  `json:"type"`
	System int     `json:"system"`
	SvId   int     `json:"satellite"`
	X      float64 `json:"x"`
	Y      float64 `json:"y"`
	Z      float64 `json:"z"`
	Clk    float64 `json:"clk"`
	Xs     int     `json:"x_sigma"`
	Ys     int     `json:"y_sigma"`
	Zs     int     `json:"z_sigma"`
	ClkS   int     `json:"clk_sigma"`
	ClkE   string  `json:"clk_event"`
	ClkP   string  `json:"clk_predict"`
	OrbE   string  `json:"orb_event"`
	OrbP   string  `json:"orb_predict"`
}

SP3Element is deprecated. Use SP3Record instead.

type SP3Epoch

type SP3Epoch struct {
	Time     time.Time    `json:"time"`
	Elements []SP3Element `json:"elements"`
}

SP3Epoch is deprecated. Use SP3Records instead.

type SP3ProductMetadata added in v0.31.0

type SP3ProductMetadata struct {
	AnalysisCenter   string // "IGS", "COD", "GRG", "ESA", "JPL", etc.
	ProductType      string // "final", "rapid", "ultra-rapid", "predicted"
	ReferenceFrame   string // "IGS20", "IGS14", "ITRF2020", etc.
	ReferencePoint   string // "APC" (Antenna Phase Center), "CoM" (Center of Mass)
	Campaign         string // "operational", "repro1", "repro2", "repro3"
	OrbitType        string // "FIT", "HLM", "BCT", etc. (from SP3 header)
	GPSWeek          int    // GPS week number
	SamplingInterval int    // seconds (300, 900, etc.)
}

SP3ProductMetadata describes the source product characteristics These are typically extracted from the filename and SP3 header

type SP3Record added in v0.31.0

type SP3Record struct {
	Time   time.Time
	System gnss.System
	SvID   int

	// Position (always present)
	Position coordinates.Vector3D // ECEF, kilometers (SP3 native units)
	Clock    float64              // microseconds (SP3 native units)

	// Position quality (sigma codes as defined in SP3 spec)
	PosSigma coordinates.Vector3D // mm or base^mm depending on header
	ClkSigma int                  // psec or base^psec

	// Velocity (optional, nil if not available from V records)
	Velocity  *coordinates.Vector3D // dm/s (SP3 native units)
	ClockRate *float64              // 1e-4 microseconds/sec

	// Velocity quality
	VelSigma       *coordinates.Vector3D // 1e-4 dm/s
	ClockRateSigma *int                  // 1e-4 psec/sec

	// Event and prediction flags from SP3 format
	ClockEventFlag    string // " " (none) or "E" (clock event)
	ClockPredictFlag  string // " " (observed) or "P" (predicted)
	OrbitManeuverFlag string // " " (none) or "M" (maneuver)
	OrbitPredictFlag  string // " " (observed) or "P" (predicted)

	// Product metadata (for filtering/comparison in queries)
	ProductMeta *SP3ProductMetadata
}

SP3Record represents a combined position + optional velocity record This is the canonical representation for TileDB storage and API queries Units are preserved in SP3 native format (km, µs, dm/s)

func (*SP3Record) HasProductMetadata added in v0.31.0

func (r *SP3Record) HasProductMetadata() bool

HasProductMetadata returns true if this record has product metadata attached

func (*SP3Record) HasVelocity added in v0.31.0

func (r *SP3Record) HasVelocity() bool

HasVelocity returns true if this record contains velocity data

func (*SP3Record) String added in v0.31.0

func (r *SP3Record) String() string

String returns a human-readable representation of the SP3Record

func (*SP3Record) ToOrbitRecord added in v0.31.0

func (r *SP3Record) ToOrbitRecord() OrbitRecord

ToOrbitRecord converts SP3Record to the generic OrbitRecord format Performs unit conversions: km → m, µs → sec, dm/s → m/s

type SP3Records added in v0.31.0

type SP3Records []SP3Record

SP3Records is a collection of SP3Record with helper methods

func (SP3Records) FilterByProduct added in v0.31.0

func (records SP3Records) FilterByProduct(analysisCenter, productType string) SP3Records

FilterByProduct returns all records matching the specified product criteria

func (SP3Records) FilterBySatellite added in v0.31.0

func (records SP3Records) FilterBySatellite(system gnss.System, svID int) SP3Records

FilterBySatellite returns all records for a specific satellite

func (SP3Records) FilterByTimeRange added in v0.31.0

func (records SP3Records) FilterByTimeRange(start, end time.Time) SP3Records

FilterByTimeRange returns all records within the specified time range

func (SP3Records) GetTimeRange added in v0.31.0

func (records SP3Records) GetTimeRange() (start, end time.Time)

GetTimeRange returns the time span covered by these records

func (SP3Records) ToOrbitRecords added in v0.31.0

func (records SP3Records) ToOrbitRecords() OrbitRecords

ToOrbitRecords converts all SP3Records to OrbitRecords

func (SP3Records) WithVelocity added in v0.31.0

func (records SP3Records) WithVelocity() SP3Records

WithVelocity returns only records that have velocity data

Jump to

Keyboard shortcuts

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