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
use eyepiece::{FieldImage, Telescope};

mod manifest;
pub use manifest::IFU;
mod slit;
pub use slit::Slit;

/// IFU throughput definition
pub trait Throughput {
    fn throughput(&self, field_image: &mut FieldImage) -> image::ImageResult<()>;
}

impl Throughput for IFU {
    fn throughput(&self, field_image: &mut FieldImage) -> image::ImageResult<()> {
        let flux0 = field_image.flux();
        // IFU throughput
        field_image.masked(self);
        println!("7 Hex. IFU throughput: {:.3}", field_image.flux() / flux0);
        field_image.save("hex_ifu_field.png", Default::default())?;

        // IFU hexagons throughput
        println!(
            "Individual Hex. throughput: {:.3?}",
            self.iter()
                .map(|hex| field_image.clone().masked(hex).flux() / flux0)
                .collect::<Vec<_>>()
        );
        Ok(())
    }
}

impl Throughput for Telescope {
    fn throughput(&self, field_image: &mut FieldImage) -> image::ImageResult<()> {
        let flux0 = field_image.flux();
        // IFU throughput
        field_image.masked(self);
        println!("Round IFU throughput: {:.3}", field_image.flux() / flux0);
        field_image.save("round_ifu_field.png", Default::default())?;

        Ok(())
    }
}

impl Throughput for Slit {
    fn throughput(&self, field_image: &mut FieldImage) -> image::ImageResult<()> {
        let flux0 = field_image.flux();
        // IFU throughput
        field_image.masked(self);
        println!("Slit IFU throughput: {:.3}", field_image.flux() / flux0);
        field_image.save("slit_ifu_field.png", Default::default())?;

        Ok(())
    }
}