gmt_dos_clients_crseo/
pyramid.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use std::{
    ops::{DivAssign, MulAssign, SubAssign},
    sync::Arc,
};

use crseo::{
    wavefrontsensor::{LensletArray, Pyramid, PyramidBuilder},
    Builder,
};
use interface::UniqueIdentifier;
use serde::Serialize;

pub use calibrating::{PyramidCalibrator, PyramidCommand};

use crate::Processor;

use crseo::Frame;

#[derive(Default, Debug, Serialize)]
pub struct PyramidData<T> {
    sx: Vec<T>,
    sy: Vec<T>,
    flux: Vec<T>,
}

impl<T> IntoIterator for PyramidData<T> {
    type Item = T;

    type IntoIter = std::iter::Chain<std::vec::IntoIter<T>, std::vec::IntoIter<T>>;

    fn into_iter(self) -> Self::IntoIter {
        self.sx.into_iter().chain(self.sy.into_iter())
    }
}

#[derive(Default, Debug)]
pub struct PyramidProcessor<T = f32> {
    pub frame: Arc<Frame<T>>,
    lenslet_array: LensletArray,
}

impl From<&Pyramid> for Processor<PyramidProcessor> {
    fn from(value: &Pyramid) -> Self {
        Self(value.into())
    }
}

impl TryFrom<&PyramidBuilder> for Processor<PyramidProcessor> {
    type Error = crseo::CrseoError;

    fn try_from(pymb: &PyramidBuilder) -> Result<Self, Self::Error> {
        Ok((&pymb.clone().build()?).into())
    }
}

impl<T: Default> PyramidProcessor<T> {
    pub fn new(pym: &Pyramid) -> Self {
        Self {
            lenslet_array: pym.lenslet_array,
            ..Default::default()
        }
    }
}

impl From<&Pyramid> for PyramidProcessor<f32> {
    fn from(pym: &Pyramid) -> Self {
        Self {
            lenslet_array: pym.lenslet_array,
            frame: Arc::new(pym.into()),
        }
    }
}

impl SubAssign for PyramidData<f32> {
    fn sub_assign(&mut self, rhs: Self) {
        self.sx
            .iter_mut()
            .zip(self.sy.iter_mut())
            .zip(rhs.sx.into_iter().zip(rhs.sy.into_iter()))
            .for_each(|((sx, sy), (rhs_sx, rhs_sy))| {
                *sx -= rhs_sx;
                *sy -= rhs_sy;
            });
    }
}

impl DivAssign<f32> for PyramidData<f32> {
    fn div_assign(&mut self, rhs: f32) {
        self.sx
            .iter_mut()
            .zip(self.sy.iter_mut())
            .for_each(|(sx, sy)| {
                *sx /= rhs;
                *sy /= rhs;
            })
    }
}

impl MulAssign<f32> for PyramidData<f32> {
    fn mul_assign(&mut self, rhs: f32) {
        self.sx
            .iter_mut()
            .zip(self.sy.iter_mut())
            .for_each(|(sx, sy)| {
                *sx *= rhs;
                *sy *= rhs;
            })
    }
}

mod calibrating;
mod processing;

/// Pyramid measurements actor data type
pub enum PyramidMeasurements {}
impl UniqueIdentifier for PyramidMeasurements {
    type DataType = PyramidData<f32>;
}