Skip to content

Commit a2ad9f7

Browse files
authored
Timeshift implementation and new transposition methods (#340)
* Implement new Timeshift trait * make error module public * proposing timeshift implementations * Add MSRV job * flate2 by default * Add MSRV badge --------- Signed-off-by: Guillaume W. Bres <[email protected]>
1 parent 4d7c9cd commit a2ad9f7

File tree

8 files changed

+89
-13
lines changed

8 files changed

+89
-13
lines changed

.github/workflows/benchmarks.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ jobs:
3434
submodules: recursive
3535
fetch-depth: 0
3636

37-
- name: Install stable toolchain
37+
- name: Install Rust
3838
uses: dtolnay/rust-toolchain@master
3939
with:
40-
toolchain: stable
40+
toolchain: 1.81.0
41+
override: true
4142

4243
- name: Bench
4344
run: cargo bench --bench ${{ matrix.bench }} -- --sample-size ${{ matrix.sample_size }} > ${{ matrix.bench }}.txt

.github/workflows/daily.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions-rs/toolchain@v1
2323
name: Install Rust
2424
with:
25-
toolchain: stable
25+
toolchain: 1.81.0
2626
override: true
2727

2828
- uses: actions-rs/cargo@v1

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions-rs/toolchain@v1
3434
name: Install Rust
3535
with:
36-
toolchain: stable
36+
toolchain: 1.81.0
3737
override: true
3838

3939
- uses: actions-rs/cargo@v1

Cargo.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@ keywords = ["geo", "gnss", "gps", "galileo"]
1010
categories = ["science", "science::geo", "parsing"]
1111
edition = "2021"
1212
readme = "README.md"
13-
rust-version = "1.64"
1413
exclude = [
1514
"data/*",
1615
]
1716

17+
[package.metadata]
18+
msrv = "1.81"
19+
20+
[package.metadata.docs.rs]
21+
all-features = true
22+
rustdoc-args = ["--cfg", "docrs", "--generate-link-to-definition"]
23+
1824
#####################################################################
1925
# To understand the lib features, please read the following comments.
2026
#
@@ -35,7 +41,7 @@ exclude = [
3541
################################################################
3642

3743
[features]
38-
default = []
44+
default = ["flate2"] # gzip files supported by default
3945

4046
# OBSERVATION RINEX Iterators & methods. Unlocks signal combinations.
4147
obs = []
@@ -105,10 +111,6 @@ full = [
105111
"rtcm",
106112
]
107113

108-
[package.metadata.docs.rs]
109-
all-features = true
110-
rustdoc-args = ["--cfg", "docrs", "--generate-link-to-definition"]
111-
112114
[build-dependencies]
113115
serde_json = { version = "1.0", features = ["preserve_order"] }
114116
serde = { version = "1.0", default-features = false, features = ["derive"] }
@@ -140,7 +142,8 @@ anise = { version = "0.5.3", optional = true }
140142
nalgebra = { version = "0.33.0", optional = true }
141143
hifitime = { version = "4.0.0", features = ["serde", "std"] }
142144
gnss-rs = { version = "2.3.5", features = ["serde", "domes", "cospar"] }
143-
gnss-qc-traits = { version = "0.1.1", features = ["html"], optional = true }
145+
146+
gnss-qc-traits = { git = "https://github.com/rtk-rs/qc-traits", branch = "main", features = ["html"], optional = true }
144147

145148
maud = { version = "0.26", optional = true }
146149

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ RINEX
66
[![crates.io](https://docs.rs/rinex/badge.svg)](https://docs.rs/rinex/)
77
[![crates.io](https://img.shields.io/crates/d/rinex.svg)](https://crates.io/crates/rinex)
88

9+
[![MRSV](https://img.shields.io/badge/MSRV-1.81.0-orange?style=for-the-badge)](https://github.com/rust-lang/rust/releases/tag/1.81.0)
910
[![License](https://img.shields.io/badge/license-MPL_2.0-orange?style=for-the-badge&logo=mozilla)](https://github.com/rtk-rs/rinex/blob/main/LICENSE)
1011

1112
[RINEX (Receiver Independent EXchange)](https://en.wikipedia.org/wiki/RINEX) parser and formatter.

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub mod antex;
3131
pub mod carrier;
3232
pub mod clock;
3333
pub mod doris;
34+
pub mod error;
3435
pub mod hardware;
3536
pub mod hatanaka;
3637
pub mod header;
@@ -47,7 +48,6 @@ pub mod version;
4748
mod bibliography;
4849
mod constants;
4950
mod epoch;
50-
mod error;
5151
mod iterators;
5252
mod leap;
5353
mod linspace;
@@ -190,7 +190,8 @@ pub mod prelude {
190190
#[cfg_attr(docsrs, doc(cfg(feature = "processing")))]
191191
pub mod processing {
192192
pub use qc_traits::{
193-
Decimate, DecimationFilter, Filter, MaskFilter, Masking, Preprocessing, Split,
193+
Decimate, DecimationFilter, Filter, GnssAbsoluteTime, MaskFilter, Masking,
194+
Preprocessing, Split, Timeshift,
194195
};
195196
}
196197

src/processing/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ use crate::prelude::Rinex;
55
mod decim;
66
mod repair;
77
mod split;
8+
mod timeshift;
89

910
impl Preprocessing for Rinex {}

src/processing/timeshift.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use crate::{
2+
observation::{ObsKey, Observations},
3+
prelude::{Header, Rinex, TimeScale},
4+
};
5+
6+
use qc_traits::{GnssAbsoluteTime, Timeshift};
7+
8+
use std::collections::BTreeMap;
9+
10+
impl Timeshift for Header {
11+
fn timeshift(&self, solver: &GnssAbsoluteTime, target: TimeScale) -> Self
12+
where
13+
Self: Sized,
14+
{
15+
let mut s = self.clone();
16+
s.timeshift_mut(solver, target);
17+
s
18+
}
19+
20+
fn timeshift_mut(&mut self, solver: &GnssAbsoluteTime, target: TimeScale) {
21+
if let Some(obs) = &mut self.obs {
22+
if let Some(epoch) = &mut obs.timeof_first_obs {
23+
if let Some(converted) = solver.epoch_time_correction(*epoch, target) {
24+
*epoch = converted;
25+
} else {
26+
obs.timeof_first_obs = None;
27+
}
28+
}
29+
30+
if let Some(epoch) = &mut obs.timeof_last_obs {
31+
if let Some(converted) = solver.epoch_time_correction(*epoch, target) {
32+
*epoch = converted;
33+
} else {
34+
obs.timeof_last_obs = None;
35+
}
36+
}
37+
}
38+
}
39+
}
40+
41+
impl Timeshift for Rinex {
42+
fn timeshift(&self, solver: &GnssAbsoluteTime, target: TimeScale) -> Self
43+
where
44+
Self: Sized,
45+
{
46+
let mut s = self.clone();
47+
s.timeshift_mut(solver, target);
48+
s
49+
}
50+
51+
fn timeshift_mut(&mut self, solver: &GnssAbsoluteTime, target: TimeScale) {
52+
self.header.timeshift_mut(solver, target);
53+
54+
if let Some(obs_rec) = self.record.as_mut_obs() {
55+
let mut new_rec = BTreeMap::<ObsKey, Observations>::new();
56+
57+
for (k, values) in obs_rec.iter() {
58+
if let Some(converted) = solver.epoch_time_correction(k.epoch, target) {
59+
let mut key = k.clone();
60+
key.epoch = converted;
61+
62+
new_rec.insert(key, values.clone());
63+
}
64+
}
65+
66+
*obs_rec = new_rec;
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)