-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,728 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//! COSPAR ID number | ||
use thiserror::Error; | ||
|
||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("Invalid COSPAR number")] | ||
InvalidFormat, | ||
} | ||
|
||
/// COSPAR ID number | ||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
pub struct COSPAR { | ||
/// Launch year | ||
year: u16, | ||
/// Launch number for that year, in chronological order. | ||
launch: u16, | ||
/// Up to three letter code representing the sequential | ||
/// identifier of a piece in a Launch. | ||
code: String, | ||
} | ||
|
||
impl std::fmt::Display for COSPAR { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
write!(f, "{:04}-{:03}{}", self.year, self.launch, self.code) | ||
} | ||
} | ||
|
||
impl std::str::FromStr for COSPAR { | ||
type Err = Error; | ||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
if s.len() < 9 { | ||
return Err(Error::InvalidFormat); | ||
} | ||
let offset = s.find('-').ok_or(Error::InvalidFormat)?; | ||
let (year, rem) = s.split_at(offset); | ||
let year = year.parse::<u16>().map_err(|_| Error::InvalidFormat)?; | ||
let launch = rem[1..4] | ||
.trim() | ||
.parse::<u16>() | ||
.map_err(|_| Error::InvalidFormat)?; | ||
Ok(Self { | ||
year, | ||
launch, | ||
code: rem[4..].trim().to_string(), | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::cospar::COSPAR; | ||
use std::str::FromStr; | ||
#[test] | ||
fn cospar() { | ||
for (desc, expected) in [ | ||
( | ||
"2018-080A", | ||
COSPAR { | ||
year: 2018, | ||
launch: 80, | ||
code: "A".to_string(), | ||
}, | ||
), | ||
( | ||
"1996-068A", | ||
COSPAR { | ||
year: 1996, | ||
launch: 68, | ||
code: "A".to_string(), | ||
}, | ||
), | ||
] { | ||
let cospar = COSPAR::from_str(desc).unwrap(); | ||
assert_eq!(cospar, expected); | ||
let recip = cospar.to_string(); | ||
assert_eq!(recip, desc, "cospar reciprocal"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::collections::HashMap; | ||
|
||
use thiserror::Error; | ||
|
||
use crate::{ | ||
domes::Error as DomesParsingError, | ||
observable::Observable, | ||
prelude::{Duration, Epoch}, | ||
}; | ||
|
||
pub(crate) mod record; | ||
pub(crate) mod station; | ||
|
||
pub use record::Record; | ||
pub use station::Station; | ||
|
||
/// DORIS Station & record parsing error | ||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("invalid station")] | ||
InvalidStation, | ||
#[error("failed to parse station id")] | ||
IdParsing, | ||
#[error("invalid station DOMES code")] | ||
DomesError(#[from] DomesParsingError), | ||
#[error("failed to parse beacon generation")] | ||
BeaconGenerationParsing, | ||
#[error("failed to parse `k` factor")] | ||
KfParsing, | ||
} | ||
|
||
/// DORIS Record specific header fields | ||
#[derive(Debug, Clone, Default, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
pub struct HeaderFields { | ||
/// Time of First Measurement, expressed in TAI timescale. | ||
pub time_of_first_obs: Option<Epoch>, | ||
/// Time of Last Measurement, expressed in TAI timescale. | ||
pub time_of_last_obs: Option<Epoch>, | ||
/// List of observables | ||
pub observables: Vec<Observable>, | ||
/// Data scaling, almost 100% of the time present in DORIS measurements. | ||
/// Allows some nano radians precision on phase data for example. | ||
pub scaling: HashMap<Observable, u16>, | ||
/// Reference stations present in this file | ||
pub stations: Vec<Station>, | ||
/// Constant shift between date of the U2 (401.25 MHz) phase measurement | ||
/// and date of the S1 (2.03625 GHz) phase measurement | ||
pub l2_l1_date_offset: Duration, | ||
} | ||
|
||
impl HeaderFields { | ||
/// Retrieve station by ID# | ||
pub(crate) fn get_station(&mut self, id: u16) -> Option<&Station> { | ||
self.stations | ||
.iter() | ||
.filter(|s| s.key == id) | ||
.reduce(|k, _| k) | ||
} | ||
/// Insert a data scaling | ||
pub(crate) fn with_scaling(&mut self, observable: Observable, scaling: u16) { | ||
self.scaling.insert(observable.clone(), scaling); | ||
} | ||
/// Returns scaling to applied to said Observable. | ||
pub(crate) fn scaling(&self, observable: Observable) -> Option<&u16> { | ||
self.scaling.get(&observable) | ||
} | ||
} |
Oops, something went wrong.