rinex

package module
v0.0.0-...-6dad5c3 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

README

rinex

A RINEX Version 3 library.

Installation

Make sure you have a working Go environment. Go version 1.14+ is supported. See the install instructions for Go.

To install, simply run:

$ go get -u github.com/erwiese/rinex

Examples

package main

import (
	"log"

	"github.com/erwiese/rinex"
)

func main() {
	r, _ := os.Open("testdata/white/REYK00ISL_R_20192701000_01H_30S_MO.rnx")
	defer r.Close()

	dec, _ := rinex.NewObsDecoder(r)
	for dec.NextEpoch() {
		epoch := dec.Epoch()
		// Do something with epoch
	}
	if err := dec.Err(); err != nil {
		log.Printf("read epochs: %v", err)
	}
}

Fromats see https://kb.igs.org/hc/en-us/articles/201096516-IGS-Formats

Documentation

Overview

Package rinex provides functions for reading and writing RINEX files.

Index

Examples

Constants

View Source
const (
	// TimeOfClockFormat is the time format within RINEX3 Nav records.
	TimeOfClockFormat string = "2006  1  2 15  4  5"
)

Variables

View Source
var (
	// Rnx2FileNamePattern is the regex for RINEX2 filenames.
	Rnx2FileNamePattern = regexp.MustCompile(`(([a-z0-9]{4})(\d{3})([a-x0])(\d{2})?\.(\d{2})([domnglqfph]))\.?([a-zA-Z0-9]+)?`)

	// Rnx3FileNamePattern is the regex for RINEX3 filenames.
	Rnx3FileNamePattern = regexp.MustCompile(`((([A-Z0-9]{4})(\d)(\d)([A-Z]{3})_([RSU])_((\d{4})(\d{3})(\d{2})(\d{2}))_(\d{2}[A-Z])_?(\d{2}[CZSMHDU])?_([GREJCSM][MNO]))\.(rnx|crx))\.?([a-zA-Z0-9]+)?`)
)
View Source
var (
	// ErrNoHeader is returned when reading RINEX data that does not begin with a RINEX Header.
	ErrNoHeader = errors.New("RINEX: no header")
)

errors

Functions

func ParseDoy

func ParseDoy(year, doy int) time.Time

ParseDoy returns the UTC-Time corresponding to the given year and day of year. Added in Go 1.13 !!!

func UnmarshalEph

func UnmarshalEph(data []byte, eph Eph) error

UnmarshalEph parses the RINEX ephemeris given in lines and stores the result in the value pointed to by eph.

Types

type Coord

type Coord struct {
	X, Y, Z float64
}

Coord defines a XYZ coordinate.

type CoordNEU

type CoordNEU struct {
	N, E, Up float64
}

CoordNEU defines a North-, East-, Up-coordinate or eccentrity

type DiffOptions

type DiffOptions struct {
	SatSys      string // satellite systems GRE...
	CheckHeader bool   // also compare the RINEX header
}

DiffOptions sets options for file comparison.

type Eph

type Eph interface {
	// Validate checks the ephemeris.
	Validate() error
	// contains filtered or unexported methods
}

Eph is the interface that wraps some methods for all types of ephemeris.

func NewEph

func NewEph(sys SatelliteSystem) Eph

NewEph returns a new ephemeris having the concrete type.

type EphBDS

type EphBDS struct {
	PRN PRN
	TOC time.Time
}

EphBDS describes a chinese BDS ephermis.

func (EphBDS) Validate

func (EphBDS) Validate() error

type EphGAL

type EphGAL struct {
	PRN PRN
	TOC time.Time
}

EphGAL describes a Galileo ephermis.

func (EphGAL) Validate

func (EphGAL) Validate() error

type EphGLO

type EphGLO struct {
	PRN PRN
	TOC time.Time
}

EphGLO describes a GLONASS ephermis.

func (EphGLO) Validate

func (EphGLO) Validate() error

type EphGPS

type EphGPS struct {
	PRN PRN

	// Clock
	TOC            time.Time // Time of Clock, clock reference epoch
	ClockBias      float64   // sc clock bias in seconds
	ClockDrift     float64   // sec/sec
	ClockDriftRate float64   // sec/sec2

	IODE   float64 // Issue of Data, Ephemeris
	Crs    float64 // meters
	DeltaN float64 // radians/sec
	M0     float64 // radians

	Cuc   float64 // radians
	Ecc   float64 // Eccentricity
	Cus   float64 // radians
	SqrtA float64 // sqrt(m)

	Toe    float64 // time of ephemeris (sec of GPS week)
	Cic    float64 // radians
	Omega0 float64 // radians
	Cis    float64 // radians

	I0       float64 // radians
	Crc      float64 // meters
	Omega    float64 // radians
	OmegaDot float64 // radians/sec

	IDOT    float64 // radians/sec
	L2Codes float64
	ToeWeek float64 // GPS week (to go with TOE) Continuous
	L2PFlag float64

	URA    float64 // SV accuracy in meters
	Health float64 // SV health (bits 17-22 w 3 sf 1)
	TGD    float64 // seconds
	IODC   float64 // Issue of Data, clock

	Tom         float64 // transmission time of message, seconds of GPS week
	FitInterval float64 // Fit interval in hours
}

EphGPS describes a GPS ephermis.

func (EphGPS) Validate

func (EphGPS) Validate() error

type EphIRNSS

type EphIRNSS struct {
	PRN PRN
	TOC time.Time
}

EphIRNSS describes an indian IRNSS/NavIC ephermis.

func (EphIRNSS) Validate

func (EphIRNSS) Validate() error

type EphQZSS

type EphQZSS struct {
	PRN PRN
	TOC time.Time
}

EphQZSS describes a japanese QZSS ephermis.

func (EphQZSS) Validate

func (EphQZSS) Validate() error

type EphSBAS

type EphSBAS struct {
	PRN PRN
	TOC time.Time
}

EphSBAS describes a SBAS payload.

func (EphSBAS) Validate

func (EphSBAS) Validate() error

type Epoch

type Epoch struct {
	Time    time.Time // epoch time
	Flag    int8
	NumSat  uint8
	ObsList []SatObs
}

Epoch contains a RINEX data epoch.

func (*Epoch) Print

func (epo *Epoch) Print()

Print pretty prints the epoch.

func (*Epoch) PrintTab

func (epo *Epoch) PrintTab(opts Options)

PrintTab prints the epoch in a tabular format.

type NavDecoder struct {
	// The Header is valid after NewNavDecoder or Reader.Reset. The header must not necessarily exist,
	// e.g. if you want to read from a stream. Then ErrNoHeader will be returned.
	Header NavHeader
	// contains filtered or unexported fields
}

A NavDecoder reads and decodes header and data records from a RINEX Nav input stream.

Example (Loop)

Loop over the ephemerides of a input stream.

filepath := "testdata/white/AREG00PER_R_20201690000_01D_MN.rnx"
r, err := os.Open(filepath)
if err != nil {
	log.Fatalf("%v", err)
}
defer r.Close()

dec, err := NewNavDecoder(r)
if err != nil {
	log.Fatalf("%v", err)
}

nEph := 0
for dec.NextEphemeris() {
	nEph++
	eph := dec.Ephemeris()

	// Do something with eph
	_ = eph.Validate()
}
if err := dec.Err(); err != nil {
	log.Printf("reading epehmeris: %v", err)
}

fmt.Println(nEph)
Output:

3612

func NewNavDecoder

func NewNavDecoder(r io.Reader) (*NavDecoder, error)

NewNavDecoder creates a new decoder for RINEX Navigation data. The RINEX header will be read implicitly if it exists. The header must not exist, that is usful e.g. for reading from streams.

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

func (dec *NavDecoder) Ephemeris() Eph

Ephemeris returns the most recent ephemeris generated by a call to NextEphemeris.

func (dec *NavDecoder) Err() error

Err returns the first non-EOF error that was encountered by the decoder.

func (dec *NavDecoder) NextEphemeris() bool

NextEphemeris reads the next Ephemeris into the buffer. It returns false when the scan stops, either by reaching the end of the input or an error.

If there is no header we suppose the format is RINEX3. TODO: read all values

type NavFile struct {
	*RnxFil
	Header NavHeader
}

A NavFile contains fields and methods for RINEX navigation files and includes common methods for handling RINEX Nav files. It is useful e.g. for operations on the RINEX filename. If you do not need these file-related features, use the NavDecoder instead.

func NewNavFile

func NewNavFile(filepath string) (*NavFile, error)

NewNavFile returns a new Navigation File object.

func (f *NavFile) Validate() error

Validate validates the RINEX Nav file. It is valid if no error is returned.

type NavHeader struct {
	RINEXVersion float32         // RINEX Format version
	RINEXType    string          // RINEX File type. O for Obs
	SatSystem    SatelliteSystem // Satellite System. System is "Mixed" if more than one.

	Pgm   string // name of program creating this file
	RunBy string // name of agency creating this file
	Date  string // date and time of file creation TODO time.Time

	Comments []string // * comment lines
	// contains filtered or unexported fields
}

A NavHeader containes the RINEX Navigation Header information. All header parameters are optional and may comprise different types of ionospheric model parameters and time conversion parameters.

func (hdr NavHeader) Validate() error

Validate validates the RINEX Nav file. It is valid if no error is returned.

type Obs

type Obs struct {
	Val float64
	LLI int8 // loss of lock indicator
	SNR int8 // signal-to-noise ratio
}

Obs specifies a RINEX observation.

type ObsDecoder

type ObsDecoder struct {
	// The Header is valid after NewObsDecoder or Reader.Reset. The header must exist,
	// otherwise ErrNoHeader will be returned.
	Header ObsHeader
	// contains filtered or unexported fields
}

ObsDecoder reads and decodes header and data records from a RINEX Obs input stream.

Example (Loop)

Loop over the epochs of a observation data input stream.

filepath := "testdata/white/REYK00ISL_R_20192701000_01H_30S_MO.rnx"
r, err := os.Open(filepath)
if err != nil {
	log.Fatalf("%v", err)
}
defer r.Close()

dec, err := NewObsDecoder(r)
if err != nil {
	log.Fatalf("%v", err)
}

nEpochs := 0
for dec.NextEpoch() {
	nEpochs++
	_ = dec.Epoch()
	// Do something with epoch
}
if err := dec.Err(); err != nil {
	log.Printf("reading epochs: %v", err)
}

fmt.Println(nEpochs)
Output:

120

func NewObsDecoder

func NewObsDecoder(r io.Reader) (*ObsDecoder, error)

NewObsDecoder creates a new decoder for RINEX Observation data. The RINEX header will be read implicitly. The header must exist.

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

func (*ObsDecoder) Epoch

func (dec *ObsDecoder) Epoch() *Epoch

Epoch returns the most recent epoch generated by a call to NextEpoch.

func (*ObsDecoder) Err

func (dec *ObsDecoder) Err() error

Err returns the first non-EOF error that was encountered by the decoder.

func (*ObsDecoder) NextEpoch

func (dec *ObsDecoder) NextEpoch() bool

NextEpoch reads the observations for the next epoch. It returns false when the scan stops, either by reaching the end of the input or an error. TODO: add phase shifts

func (*ObsDecoder) SyncEpoch

func (dec *ObsDecoder) SyncEpoch() SyncEpochs

SyncEpoch returns the current pair of time-synchronized epochs from two RINEX Obs input streams.

type ObsFil

type ObsFil struct {
	*RnxFil
	Header ObsHeader
	Opts   Options
}

ObsFil contains fields and methods for RINEX observation files. Use NewObsFil() to instantiate a new ObsFil.

func NewObsFil

func NewObsFil(filepath string) (*ObsFil, error)

NewObsFil returns a new ObsFil.

func (*ObsFil) Crx2rnx

func (obsFil *ObsFil) Crx2rnx() error

Crx2rnx decompresses a Hatanaka-compressed file. Crx2rnx returns the filepath of the decompressed file. see http://terras.gsi.go.jp/ja/crx2rnx.html

func (*ObsFil) Diff

func (obsFil *ObsFil) Diff(obsFil2 *ObsFil) error

Diff compares two RINEX obs files.

func (*ObsFil) IsHatanakaCompressed

func (obsFil *ObsFil) IsHatanakaCompressed() bool

IsHatanakaCompressed returns true if the obs file is Hatanaka compressed, otherwise false.

func (*ObsFil) Rnx2crx

func (obsFil *ObsFil) Rnx2crx() error

Rnx2crx creates a copy of the file that is Hatanaka-compressed (compact RINEX). Rnx2crx returns the filepath of the compressed file. see http://terras.gsi.go.jp/ja/crx2rnx.html

func (*ObsFil) Stat

func (obsFil *ObsFil) Stat() (stat ObsStat, err error)

Stat gathers some observation statistics.

type ObsHeader

type ObsHeader struct {
	RINEXVersion float32         // RINEX Format version
	RINEXType    string          // RINEX File type. O for Obs
	SatSystem    SatelliteSystem // Satellite System. System is "Mixed" if more than one.

	Pgm   string // name of program creating this file
	RunBy string // name of agency creating this file
	Date  string // date and time of file creation TODO time.Time

	Comments []string // * comment lines

	MarkerName, MarkerNumber, MarkerType string // antennas' marker name, *number and type

	Observer, Agency string

	ReceiverNumber, ReceiverType, ReceiverVersion string
	AntennaNumber, AntennaType                    string

	Position     Coord    // Geocentric approximate marker position [m]
	AntennaDelta CoordNEU // North,East,Up deltas in [m]

	ObsTypes map[string][]string

	SignalStrengthUnit string
	Interval           float64 // Observation interval in seconds
	TimeOfFirstObs     time.Time
	TimeOfLastObs      time.Time
	LeapSeconds        int // The current number of leap seconds
	NSatellites        int // Number of satellites, for which observations are stored in the file
	// contains filtered or unexported fields
}

A ObsHeader provides the RINEX Observation Header information.

type ObsStat

type ObsStat struct {
	NumEpochs      int       `json:"numEpochs"`
	Sampling       int       `json:"sampling"`
	TimeOfFirstObs time.Time `json:"timeOfFirstObs"`
	TimeOfLastObs  time.Time `json:"timeOfLastObs"`
}

ObsStat stores observation statistics.

type Options

type Options struct {
	SatSys string // satellite systems GRE...
}

Options for global settings.

type PRN

type PRN struct {
	Sys SatelliteSystem
	Num int8 // number

}

PRN specifies a GNSS satellite.

func (PRN) String

func (prn PRN) String() string

String is a PRN Stringer.

type RnxFil

type RnxFil struct {
	Path string

	FourCharID     string
	MonumentNumber int
	ReceiverNumber int
	CountryCode    string // ISO 3char
	StartTime      time.Time
	DataSource     string // [RSU]
	FilePeriod     string // 15M, 01D
	DataFreq       string // 30S, not for nav files // TODO make type frequency!!
	DataType       string // The data type abbreviations GO, RO, MN, MM, ...
	Format         string // rnx, crx, etc. Attention: Format and Hatanaka are dependent!
	Compression    string // gz, ...

}

RnxFil contains fields and methods that can be used by all RINEX file types. Usually you won't instantiate a RnxFil directly and use NewObsFil() and NewNavFileReader() instead. Both ObsFil and NavFile embed RnxFil.

func NewFile

func NewFile(filepath string) (*RnxFil, error)

NewFile returns a new RINEX file object.

func (*RnxFil) IsMeteoType

func (f *RnxFil) IsMeteoType() bool

IsMeteoType returns true if the file is a RINEX meteo file type.

func (*RnxFil) IsNavType

func (f *RnxFil) IsNavType() bool

IsNavType returns true if the file is a RINEX navigation file type.

func (*RnxFil) IsObsType

func (f *RnxFil) IsObsType() bool

IsObsType returns true if the file is a RINEX observation file type.

func (*RnxFil) Rnx2Filename

func (f *RnxFil) Rnx2Filename() (string, error)

Rnx2Filename returns the filename following the RINEX2 convention.

Example

Convert a RINEX 3 filename to a RINEX 2 filename.

file, err := NewFile("ALGO00CAN_R_20121601001_15M_01S_GO.rnx")
if err != nil {
	log.Fatalln(err)
}

rnx2name, err := file.Rnx2Filename()
if err != nil {
	log.Fatalln(err)
}
fmt.Println(rnx2name)
Output:

algo160k00.12o

func (*RnxFil) Rnx3Filename

func (f *RnxFil) Rnx3Filename() (string, error)

Rnx3Filename returns the filename following the RINEX3 convention. The file must exist, as we must read the header. The countrycode must come from an external source. DO NOT USE! Must parse header first!

Example

Convert a RINEX 2 filename to a RINEX 3 filename.

file, err := NewFile("testdata/white/brst155h.20o")
if err != nil {
	log.Fatalln(err)
}
file.CountryCode = "FRA"
file.DataSource = "R"

rnx3name, err := file.Rnx3Filename()
if err != nil {
	log.Fatalln(err)
}
fmt.Println(rnx3name)
Output:

BRST00FRA_R_20201550700_01H_30S_MO.rnx

func (*RnxFil) SetStationName

func (f *RnxFil) SetStationName(name string) error

SetStationName sets the station or project name. IGS users should follow XXXXMRCCC (9 char) site and station naming convention described above. GNSS industry users could use the 9 characters to indicate the project name and/or number.

type SatObs

type SatObs struct {
	Prn  PRN
	Obss map[string]Obs // L1C: obs
}

SatObs conatins all observations for a satellite for a epoch.

type SatelliteSystem

type SatelliteSystem int

SatelliteSystem specifies a GNSS.

const (
	SatSysGPS SatelliteSystem = iota + 1
	SatSysGLO
	SatSysGAL
	SatSysQZSS
	SatSysBDS
	SatSysIRNSS
	SatSysSBAS
	SatSysMIXED
)

Available Satellite Systems.

func (SatelliteSystem) Abbr

func (sys SatelliteSystem) Abbr() string

Abbr returns the systems' abbreviation used in RINEX.

func (SatelliteSystem) String

func (sys SatelliteSystem) String() string

type SyncEpochs

type SyncEpochs struct {
	Epo1 *Epoch
	Epo2 *Epoch
}

SyncEpochs contains two epochs from different files with the same timestamp.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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