use crate::surveylib::detection::LinkingRequirement;
use crate::surveylib::footprint::Footprint;
use crate::time::Time;
#[derive(Debug, Clone)]
pub struct Epoch {
pub time: Time,
pub m50: Option<f64>,
}
impl Epoch {
pub fn new(time: Time) -> Self {
Self { time, m50: None }
}
pub fn with_depth(time: Time, m50: f64) -> Self {
Self {
time,
m50: Some(m50),
}
}
}
#[derive(Debug, Clone)]
pub struct SurveyDefinition {
pub name: String,
pub footprint: Footprint,
pub epochs: Vec<Epoch>,
pub linking: LinkingRequirement,
}
impl SurveyDefinition {
pub fn epoch_times(&self) -> Vec<Time> {
self.epochs.iter().map(|e| e.time.clone()).collect()
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::time::Timescale;
#[test]
fn epoch_depth_override_is_optional() {
let ts = Timescale::default();
let t = ts.tt_jd(2_456_000.0, None);
assert_eq!(Epoch::new(t.clone()).m50, None);
assert_eq!(Epoch::with_depth(t, 23.5).m50, Some(23.5));
}
#[test]
fn epoch_times_preserve_grid_order() {
let ts = Timescale::default();
let survey = SurveyDefinition {
name: "toy".to_string(),
footprint: Footprint::AllSky,
epochs: (0..5)
.map(|k| Epoch::new(ts.tt_jd(2_456_000.0 + 10.0 * k as f64, None)))
.collect(),
linking: LinkingRequirement::KOfN { k: 2 },
};
let times = survey.epoch_times();
assert_eq!(times.len(), 5);
for (k, t) in times.iter().enumerate() {
assert!((t.tt() - (2_456_000.0 + 10.0 * k as f64)).abs() < 1e-9);
}
}
}