use crate::Kinetics::experimental_kinetics::one_experiment_dataset::{
OneFramePlot, TGADataset, TGADomainError,
};
use RustedSciThe::numerical::data_processing::LSQSplines::SolverKind;
use RustedSciThe::numerical::data_processing::splines::SplineKind;
use log::{info, warn};
#[derive(Clone, Debug)]
pub struct ViewRange {
pub t_min: f64,
pub t_max: f64,
}
#[derive(Clone, Debug)]
pub struct PlotSeries {
pub name_x: String,
pub name_y: String,
pub x: Vec<f64>,
pub y: Vec<f64>,
pub segment_starts: Vec<usize>,
}
fn downsample_min_max(points: Vec<(f64, f64)>, max_points: usize) -> Vec<(f64, f64)> {
let len = points.len();
if len <= max_points || max_points == 0 {
return points;
}
if max_points == 1 {
return vec![points[0]];
}
if max_points == 2 {
return vec![points[0], points[len - 1]];
}
if max_points == 3 {
let first_y = points[0].1;
let last_y = points[len - 1].1;
let extreme = (1..len - 1)
.max_by(|&a, &b| {
let deviation = |index: usize| {
let baseline = first_y + (last_y - first_y) * index as f64 / (len - 1) as f64;
(points[index].1 - baseline).abs()
};
deviation(a).total_cmp(&deviation(b))
})
.unwrap_or(1);
let mut indices = [0, extreme, len - 1];
indices.sort_unstable();
return indices.into_iter().map(|index| points[index]).collect();
}
let bucket_count = ((max_points - 2) / 2).max(1);
let interior_len = len - 2;
let mut indices = Vec::with_capacity(max_points);
indices.push(0);
for bucket in 0..bucket_count {
let start = 1 + bucket * interior_len / bucket_count;
let end = 1 + (bucket + 1) * interior_len / bucket_count;
if start >= end {
continue;
}
let mut min_index = start;
let mut max_index = start;
for index in (start + 1)..end {
if points[index].1 < points[min_index].1 {
min_index = index;
}
if points[index].1 > points[max_index].1 {
max_index = index;
}
}
if min_index <= max_index {
indices.extend([min_index, max_index]);
} else {
indices.extend([max_index, min_index]);
}
}
indices.push(len - 1);
indices.dedup();
indices.into_iter().map(|index| points[index]).collect()
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum XY {
X,
Y,
}
impl Default for XY {
fn default() -> Self {
XY::X
}
}
#[derive(Clone, Copy, Debug)]
pub struct Ranges {
pub x_min: f64,
pub x_max: f64,
pub y_min: f64,
pub y_max: f64,
}
impl Default for Ranges {
fn default() -> Self {
Self {
x_min: 0.0,
x_max: 0.0,
y_min: 0.0,
y_max: 0.0,
}
}
}
impl TGADataset {
fn oneframeplot_xy_names(&self) -> Result<(String, String), TGADomainError> {
let oneframe = self.oneframeplot.as_ref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function oneframeplot_xy_names:oneframeplot is not configured".to_string(),
)
})?;
let x_col = oneframe.x.clone().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function oneframeplot_xy_names:oneframeplot.x is not configured".to_string(),
)
})?;
let y_col = oneframe.y.clone().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function oneframeplot_xy_names:oneframeplot.y is not configured".to_string(),
)
})?;
Ok((x_col, y_col))
}
pub fn get_oneframeplot_x_name(&self) -> Result<String, TGADomainError> {
self.oneframeplot_axis_name(XY::X)
}
pub fn get_oneframeplot_y_name(&self) -> Result<String, TGADomainError> {
self.oneframeplot_axis_name(XY::Y)
}
pub fn oneframeplot_axis_name(&self, axis: XY) -> Result<String, TGADomainError> {
let (x, y) = self.oneframeplot_xy_names()?;
Ok(match axis {
XY::X => x,
XY::Y => y,
})
}
pub fn set_oneframeplot_x(mut self, x_col: &str) -> Result<Self, TGADomainError> {
println!("\n setting x");
if !self.schema.columns.contains_key(x_col) {
return Err(TGADomainError::ColumnNotFound(x_col.into()));
}
match self.oneframeplot.as_mut() {
Some(plot) => plot.x = Some(x_col.to_string()),
None => {
self.oneframeplot = Some(OneFramePlot {
x: Some(x_col.to_string()),
y: None,
});
}
}
Ok(self)
}
pub fn set_oneframeplot_y(mut self, y_col: &str) -> Result<Self, TGADomainError> {
println!("\n setting y");
if !self.schema.columns.contains_key(y_col) {
return Err(TGADomainError::ColumnNotFound(y_col.into()));
}
match self.oneframeplot.as_mut() {
Some(plot) => plot.y = Some(y_col.to_string()),
None => {
self.oneframeplot = Some(OneFramePlot {
x: None,
y: Some(y_col.to_string()),
});
}
}
Ok(self)
}
pub fn get_axis_as_vec(&self, axis: XY) -> Result<Vec<f64>, TGADomainError> {
let selected = self.oneframeplot_axis_name(axis)?;
Ok(self.column_as_array1(&selected)?.to_vec())
}
pub fn get_x_as_vec(&self) -> Result<Vec<f64>, TGADomainError> {
let x = XY::X;
let x_vec = self.get_axis_as_vec(x)?;
Ok(x_vec)
}
pub fn get_y_as_vec(&self) -> Result<Vec<f64>, TGADomainError> {
let x_vec = self.get_axis_as_vec(XY::Y)?;
Ok(x_vec)
}
pub fn get_plotseries(&self) -> Result<PlotSeries, TGADomainError> {
let x = self.get_x_as_vec()?;
let y = self.get_y_as_vec()?;
let oneframe = self.oneframeplot.as_ref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function get_plotseries:oneframeplot is not configured".to_string(),
)
})?;
let x_col = oneframe.x.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function get_plotseries:oneframeplot.x is not configured".to_string(),
)
})?;
let y_col = oneframe.y.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function get_plotseries:oneframeplot.y is not configured".to_string(),
)
})?;
let series = PlotSeries {
name_x: x_col.to_string(),
name_y: y_col.to_string(),
segment_starts: if x.is_empty() { Vec::new() } else { vec![0] },
x,
y,
};
Ok(series)
}
pub fn sample_oneframeplot(
&self,
range: Option<ViewRange>,
max_points: usize,
) -> Result<PlotSeries, TGADomainError> {
let oneframe = self.oneframeplot.as_ref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function sample_oneframeplot: oneframeplot is not configured".to_string(),
)
})?;
let x_col = oneframe.x.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function sample_oneframeplot:oneframeplot.x is not configured".to_string(),
)
})?;
let y_col = oneframe.y.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function sample_oneframeplot: oneframeplot.y is not configured".to_string(),
)
})?;
let mut sampled = self.sample_columns(x_col, &[y_col], range, max_points)?;
sampled.pop().ok_or_else(|| {
TGADomainError::InvalidOperation("no data points in selected range".to_string())
})
}
pub fn spline_resample_oneframeplot(
self,
new_time_col: &str,
n_points: usize,
kind: SplineKind,
) -> Result<Self, TGADomainError> {
let oneframe = self.oneframeplot.clone().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function spline_resample_oneframeplot: oneframeplot is not configured".to_string(),
)
})?;
let x_col = oneframe.x.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function spline_resample_oneframeplot: oneframeplot.x is not configured"
.to_string(),
)
})?;
let y_col = oneframe.y.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function spline_resample_oneframeplot: oneframeplot.y is not configured"
.to_string(),
)
})?;
self.spline_resample_columns(x_col, new_time_col, &[y_col], n_points, kind)
}
pub fn spline_resample_oneframeplot_as(
self,
new_time_col: &str,
n_points: usize,
kind: SplineKind,
out_col: Option<&str>,
) -> Result<Self, TGADomainError> {
let oneframe = self.oneframeplot.clone().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function spline_resample_oneframeplot: oneframeplot is not configured".to_string(),
)
})?;
let x_col = oneframe.x.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function spline_resample_oneframeplot: oneframeplot.x is not configured"
.to_string(),
)
})?;
let y_col = oneframe.y.as_deref().ok_or_else(|| {
TGADomainError::InvalidOperation(
"function spline_resample_oneframeplot: oneframeplot.y is not configured"
.to_string(),
)
})?;
self.spline_resample_columns_as(x_col, new_time_col, &[y_col], &[out_col], n_points, kind)
}
pub fn with_x_or_y<F>(self, axis: XY, op: F) -> Result<Self, TGADomainError>
where
F: FnOnce(Self, &str) -> Result<Self, TGADomainError>,
{
let selected = self.oneframeplot_axis_name(axis)?;
op(self, &selected)
}
pub fn with_x_and_y<F>(self, op: F) -> Result<Self, TGADomainError>
where
F: FnOnce(Self, &str, &str) -> Result<Self, TGADomainError>,
{
let (x_col, y_col) = self.oneframeplot_xy_names()?;
op(self, &x_col, &y_col)
}
pub fn cut_before_x_or_y(self, axis: XY, start_value: f64) -> Result<Self, TGADomainError> {
self.with_x_or_y(axis, |ds, selected_col| {
Ok(ds.trim_range(selected_col, start_value, f64::INFINITY))
})
}
pub fn cut_after_x_or_y(self, axis: XY, end_value: f64) -> Result<Self, TGADomainError> {
self.with_x_or_y(axis, |ds, selected_col| {
Ok(ds.trim_range(selected_col, f64::NEG_INFINITY, end_value))
})
}
pub fn cut_range_x_or_y(self, axis: XY, from: f64, to: f64) -> Result<Self, TGADomainError> {
self.with_x_or_y(axis, |ds, selected_col| {
Ok(ds.trim_range(selected_col, from, to))
})
}
pub fn cut_range_inverse_x_or_y(
self,
axis: XY,
from: f64,
to: f64,
) -> Result<Self, TGADomainError> {
self.with_x_or_y(axis, |ds, selected_col| {
Ok(ds.trim_range_inverse(selected_col, from, to))
})
}
pub fn cut_range_inverse_on_column(self, column: &str, from: f64, to: f64) -> Self {
self.trim_range_inverse(column, from, to)
}
pub fn min_distance_to_oneframeplot_point(
&self,
point: (f64, f64),
) -> Result<f64, TGADomainError> {
let (x_col, y_col) = self.oneframeplot_xy_names()?;
println!("\n column: {} ", x_col);
println!("\n column: {} ", y_col);
let df = self.frame.clone().collect()?;
let x = df.column(&x_col)?.f64()?;
let y = df.column(&y_col)?.f64()?;
let mut best: Option<f64> = None;
for (ox, oy) in x.iter().zip(y.iter()) {
if let (Some(px), Some(py)) = (ox, oy) {
let dx = px - point.0;
let dy = py - point.1;
let d = (dx * dx + dy * dy).sqrt();
best = Some(match best {
Some(cur) => cur.min(d),
None => d,
});
}
}
best.ok_or_else(|| {
TGADomainError::InvalidOperation(format!(
"No valid (x, y) points found in columns '{}' and '{}'",
x_col, y_col
))
})
}
pub fn plot_xy_ranges(&self) -> Result<Ranges, TGADomainError> {
let (x_col, y_col) = self.oneframeplot_xy_names()?;
println!("\n column: {} ", x_col);
println!("\n column: {} ", y_col);
let df = self.frame.clone().collect()?;
let x = df.column(&x_col)?.f64()?;
let y = df.column(&y_col)?.f64()?;
let (x_min, x_max) = x
.iter()
.flatten()
.fold(None, |acc: Option<(f64, f64)>, v| {
Some(match acc {
Some((mn, mx)) => (mn.min(v), mx.max(v)),
None => (v, v),
})
})
.ok_or_else(|| {
TGADomainError::InvalidOperation(format!(
"x column '{}' has no valid values",
x_col
))
})?;
let (y_min, y_max) = y
.iter()
.flatten()
.fold(None, |acc: Option<(f64, f64)>, v| {
Some(match acc {
Some((mn, mx)) => (mn.min(v), mx.max(v)),
None => (v, v),
})
})
.ok_or_else(|| {
TGADomainError::InvalidOperation(format!(
"y column '{}' has no valid values",
y_col
))
})?;
Ok(Ranges {
x_min,
x_max,
y_min,
y_max,
})
}
pub fn offset_y_column_in_range_by_x_reference(
self,
offset: f64,
from: f64,
to: f64,
) -> Result<Self, TGADomainError> {
let (x_col, y_col) = self.oneframeplot_xy_names()?;
let r = self.offset_column_in_range_by_reference(&y_col, &x_col, offset, from, to);
Ok(r)
}
pub fn offset_y_column_in_its_range(
self,
offset: f64,
from: f64,
to: f64,
) -> Result<Self, TGADomainError> {
let (_, y_col) = self.oneframeplot_xy_names()?;
let r = self.offset_column_in_its_range(&y_col, offset, from, to);
Ok(r)
}
pub fn offset_x_column_in_its_range(
self,
offset: f64,
from: f64,
to: f64,
) -> Result<Self, TGADomainError> {
let (x_col, _) = self.oneframeplot_xy_names()?;
let r = self.offset_column_in_its_range(&x_col, offset, from, to);
Ok(r)
}
pub fn scale_y_column_in_range_by_x_reference(
self,
s: f64,
from: f64,
to: f64,
) -> Result<Self, TGADomainError> {
let (x_col, y_col) = self.oneframeplot_xy_names()?;
let r = self.scale_column_in_range_by_reference(&y_col, &x_col, s, from, to);
Ok(r)
}
pub fn scale_y_column_in_its_range(
self,
s: f64,
from: f64,
to: f64,
) -> Result<Self, TGADomainError> {
let (_, y_col) = self.oneframeplot_xy_names()?;
let r = self.scale_column_in_its_range(&y_col, s, from, to);
Ok(r)
}
pub fn scale_x_column_in_its_range(
self,
s: f64,
from: f64,
to: f64,
) -> Result<Self, TGADomainError> {
let (x_col, _) = self.oneframeplot_xy_names()?;
let r = self.scale_column_in_its_range(&x_col, s, from, to);
Ok(r)
}
pub fn sample_column(
&self,
col_name: &str,
range: Option<(f64, f64)>,
n_points: usize,
) -> Result<Vec<f64>, TGADomainError> {
let df = self.frame.clone().collect()?;
let col = df.column(col_name)?.f64()?;
let indices: Vec<usize> = col
.iter()
.enumerate()
.filter_map(|(i, val)| {
val.and_then(|v| {
if range.map_or(true, |(min, max)| v >= min && v <= max) {
Some(i)
} else {
None
}
})
})
.collect();
if indices.is_empty() {
return Ok(vec![]);
}
let step = (indices.len() as f64 / n_points as f64).ceil().max(1.0) as usize;
let sampled: Result<Vec<f64>, TGADomainError> = indices
.into_iter()
.step_by(step)
.map(|i| {
col.get(i).ok_or(TGADomainError::InvalidOperation(format!(
"no column number {}",
i
)))
})
.collect();
Ok(sampled?)
}
pub fn sample_columns(
&self,
time_col: &str,
value_cols: &[&str],
range: Option<ViewRange>,
max_points: usize,
) -> Result<Vec<PlotSeries>, TGADomainError> {
if max_points == 0 {
return Err(TGADomainError::InvalidOperation(
"plot sampling requires max_points > 0".to_string(),
));
}
println!("\n column: {} ", time_col);
for &col in value_cols {
println!("\n column: {} ", col);
}
let df = self.frame.clone().collect()?;
let row_count = df.height();
let mut out = Vec::new();
for &col in value_cols {
let time = df.column(time_col)?.f64()?;
let s = df.column(col)?.f64()?;
let mut segments = Vec::<Vec<(f64, f64)>>::new();
let mut current = Vec::new();
for i in 0..row_count {
let pair = time.get(i).zip(s.get(i)).filter(|(t, y)| {
t.is_finite()
&& y.is_finite()
&& range
.as_ref()
.is_none_or(|r| *t >= r.t_min && *t <= r.t_max)
});
if let Some(pair) = pair {
current.push(pair);
} else if !current.is_empty() {
segments.push(std::mem::take(&mut current));
}
}
if !current.is_empty() {
segments.push(current);
}
if segments.is_empty() {
continue;
}
let budget = max_points.max(segments.len());
let mut remaining_budget = budget;
let mut x = Vec::new();
let mut y = Vec::new();
let mut segment_starts = Vec::with_capacity(segments.len());
let segment_count = segments.len();
for (index, segment) in segments.into_iter().enumerate() {
let remaining_segments = segment_count - index;
let segment_budget = (remaining_budget / remaining_segments).max(1);
let sampled = downsample_min_max(segment, segment_budget);
if sampled.is_empty() {
continue;
}
segment_starts.push(x.len());
remaining_budget = remaining_budget.saturating_sub(sampled.len());
for (time, value) in sampled {
x.push(time);
y.push(value);
}
}
out.push(PlotSeries {
name_x: time_col.to_string(),
name_y: col.to_string(),
x,
y,
segment_starts,
});
}
Ok(out)
}
pub fn get_time_col(&self) -> Result<String, TGADomainError> {
let time_col = self
.schema
.time
.as_ref()
.ok_or(TGADomainError::TimeNotBound)?;
Ok(time_col.to_string())
}
pub fn get_mass_col(&self) -> Result<String, TGADomainError> {
let mass_col = self
.schema
.mass
.as_ref()
.ok_or(TGADomainError::MassNotBound)?;
Ok(mass_col.to_string())
}
pub fn get_temperature_col(&self) -> Result<String, TGADomainError> {
let temp_col = self
.schema
.temperature
.as_ref()
.ok_or(TGADomainError::TemperatureNotBound)?;
Ok(temp_col.to_string())
}
pub fn apply_golden_pipeline(
mut self,
config: GoldenPipelineConfig,
) -> Result<(Self, Vec<String>), TGADomainError> {
let time_col = self.get_time_col()?;
let isothermal_temperature = config.isothermal_temperature;
let temperature_col = self.schema.temperature.clone();
let mass_col = self.get_mass_col()?;
if let Some(temperature) = isothermal_temperature {
if !temperature.is_finite() || temperature <= 0.0 {
return Err(TGADomainError::InvalidOperation(
"Isothermal temperature must be finite and above 0 K".into(),
));
}
info!(
"Starting isothermal golden pipeline for time='{}', mass='{}', setpoint={} K, measured_temperature={:?}",
time_col, mass_col, temperature, temperature_col
);
} else {
info!(
"Starting non-isothermal golden pipeline for time='{}', temp='{}', mass='{}'",
time_col,
self.get_temperature_col()?,
mass_col
);
}
let ds = match self.monotony_of_time_check() {
Ok(vector_of_non_monotonic_points) if vector_of_non_monotonic_points.is_empty() => {
info!(
"Input time column '{}' is already strictly monotonic",
time_col
);
self
}
Ok(vector_of_non_monotonic_points) => {
warn!(
"Input time column '{}' is not strictly monotonic; repairing by sorting rows. Violations at values {:?}",
time_col, vector_of_non_monotonic_points
);
self.sort_by_bound_time_inplace()?;
let remaining = self.monotony_of_time_check()?;
if !remaining.is_empty() {
return Err(TGADomainError::TimeNonMonotonic(format!(
"Time remained non-monotonic after sorting by '{}': {:?}",
time_col, remaining
)));
}
info!(
"Input time column '{}' repaired by sorting before golden pipeline",
time_col
);
self
}
Err(err) => {
warn!(
"Input time monotonicity check failed for '{}': {:?}",
time_col, err
);
return Err(err);
}
};
let k = config.k;
let b = config.b;
let time_cut_before = config.time_cut_before;
let time_cut_after = config.time_cut_after;
let averaging_time = config.averaging_time;
let window_size = config.sav_gol_config.window_size;
let poly_degree = config.sav_gol_config.poly_degree;
let deriv = config.sav_gol_config.deriv;
let delta = config.sav_gol_config.delta;
let n_points = config.spline_config.n_points;
let n_internal_points = config.spline_config.n_internal_points;
let degree = config.spline_config.degree;
let temp_col = temperature_col;
let ds = ds.calibrate_mass(k, b, &mass_col)?; let ds = if let Some(time_cut_before) = time_cut_before {
ds.cut_before_time(time_cut_before)?
} else {
ds
};
let ds = if let Some(time_cut_after) = time_cut_after {
ds.cut_after_time(time_cut_after)?
} else {
ds
};
let mut ds = ds
.seconds_to_hours()?
.move_time_to_zero()?
.sg_filter_column(&mass_col, window_size, poly_degree, deriv, delta)?
.dimensionless_mass(0.0, averaging_time / 3600.0, "alpha")?
.conversion(0.0, averaging_time / 3600.0, "eta")?;
let mut resample_columns = vec![mass_col.as_str(), "alpha", "eta"];
if let Some(temp_col) = temp_col.as_deref() {
ds = ds.celsius_to_kelvin()?;
resample_columns.push(temp_col);
}
let mut aligned_output_columns = resample_columns
.iter()
.map(|column| format!("lsq_spline_{column}"))
.collect::<Vec<_>>();
aligned_output_columns.push("time_splined".to_string());
ds = ds.lsq_spline_resample_columns_as(
&time_col,
"time_splined",
&resample_columns,
&vec![None; resample_columns.len()],
n_points,
degree,
n_internal_points,
SolverKind::Banded,
)?;
let trim_columns = aligned_output_columns
.iter()
.map(String::as_str)
.collect::<Vec<_>>();
ds = ds.trim_null_edges_for_columns(&trim_columns)?;
if isothermal_temperature.is_none() {
ds = ds.derive_temperature_rate("dT/dt")?;
}
let ds = ds
.derive_dalpha_dt("dalpha_dt")?
.derive_deta_dt("deta_dt")?;
match ds.monotony_of_time_check() {
Ok(vector_of_non_monotonic_points) if vector_of_non_monotonic_points.is_empty() => {
info!(
"Golden pipeline output time '{}' is strictly monotonic after resampling and trim",
time_col
);
}
Ok(vector_of_non_monotonic_points) => {
return Err(TGADomainError::TimeNonMonotonic(format!(
"Non-monotonic points found after golden pipeline on '{}': {:?}",
time_col, vector_of_non_monotonic_points
)));
}
Err(err) => {
return Err(err);
}
}
let mut new_columns = aligned_output_columns
.iter()
.cloned()
.collect::<Vec<_>>();
if isothermal_temperature.is_none() {
new_columns.push("dT/dt".to_string());
}
new_columns.extend(["dalpha_dt".to_string(), "deta_dt".to_string()]);
println!("\n new columns added by golden pipeline: {:?}", new_columns);
Ok((ds, new_columns))
}
}
#[cfg(test)]
mod plot_sampling_tests {
use super::downsample_min_max;
#[test]
fn min_max_sampling_keeps_narrow_positive_and_negative_spikes() {
let points: Vec<_> = (0..10_000)
.map(|index| {
let value = match index {
4_321 => 100.0,
7_654 => -80.0,
_ => 0.0,
};
(index as f64, value)
})
.collect();
let sampled = downsample_min_max(points, 1_000);
assert!(sampled.len() <= 1_000);
assert_eq!(sampled.first(), Some(&(0.0, 0.0)));
assert_eq!(sampled.last(), Some(&(9_999.0, 0.0)));
assert!(sampled.contains(&(4_321.0, 100.0)));
assert!(sampled.contains(&(7_654.0, -80.0)));
assert!(sampled.windows(2).all(|pair| pair[0].0 < pair[1].0));
}
#[test]
fn min_max_sampling_obeys_small_point_budgets_and_keeps_endpoints() {
let points = vec![(0.0, 0.0), (1.0, 4.0), (2.0, -3.0), (3.0, 0.0)];
for budget in 1..=3 {
let sampled = downsample_min_max(points.clone(), budget);
assert!(sampled.len() <= budget);
assert_eq!(sampled.first(), Some(&points[0]));
if budget >= 2 {
assert_eq!(sampled.last(), Some(&points[3]));
}
}
}
}
#[derive(Debug, Clone)]
pub struct SavGolConfig {
pub window_size: usize,
pub poly_degree: usize,
pub deriv: usize,
pub delta: f64,
}
impl Default for SavGolConfig {
fn default() -> Self {
Self {
window_size: 11,
poly_degree: 3,
deriv: 0,
delta: 1.0,
}
}
}
#[derive(Debug, Clone)]
pub struct SplineConfig {
pub n_points: usize,
pub n_internal_points: usize,
pub degree: usize,
}
impl Default for SplineConfig {
fn default() -> Self {
Self {
n_points: 300,
n_internal_points: 10_000,
degree: 3,
}
}
}
#[derive(Debug, Clone)]
pub struct GoldenPipelineConfig {
pub k: f64,
pub b: f64,
pub time_cut_before: Option<f64>,
pub time_cut_after: Option<f64>,
pub sav_gol_config: SavGolConfig,
pub averaging_time: f64,
pub isothermal_temperature: Option<f64>,
pub spline_config: SplineConfig,
pub save_to_new_experiment: bool,
pub del_old_experiment: bool,
}
impl Default for GoldenPipelineConfig {
fn default() -> Self {
Self {
k: 1.0,
b: 0.0,
time_cut_before: None,
time_cut_after: None,
sav_gol_config: SavGolConfig::default(),
averaging_time: 1000.0,
isothermal_temperature: None,
spline_config: SplineConfig::default(),
save_to_new_experiment: true,
del_old_experiment: false,
}
}
}