Skip to main content

astroimsim_data/
detector.rs

1use std::time::Instant;
2use astroimsim_geometry::grid2d::GRID2D;
3use astroimsim_geometry::points::Point;
4use astroimsim_geometry::coordinate_system::{CoordinateSystem, Coordinates};
5use uvex_fitrs::{Fits, Hdu};
6use crate::point_sources::FullSpectrumSourceList;
7use crate::psf_grid::PsfGrid;
8use std::fs;
9
10#[derive(Clone,Debug)]
11pub struct Detector {
12    pub label: &'static str,
13    pub grid: GRID2D,
14    pub data: Vec<Vec<[f64;4]>>,
15}
16
17impl Detector {
18
19    pub fn write(&mut self,label:usize){
20
21
22        let width = self.data[0].len();
23        let height = self.data.len();
24        let shape = [width, height];
25
26        let mut fuv_counts_path = "/Users/mayabasu/Desktop/Output/fuv/".to_string();
27            fuv_counts_path.push_str(label.to_string().as_str());
28        fuv_counts_path.push_str(".fits");
29
30        let mut nuv_counts_path = "/Users/mayabasu/Desktop/Output/nuv/".to_string();
31            nuv_counts_path.push_str(label.to_string().as_str());
32        nuv_counts_path.push_str(".fits");
33
34        let mut fuv_ave_path = "/Users/mayabasu/Desktop/Output/fuv/counts_".to_string();
35            fuv_ave_path.push_str(label.to_string().as_str());
36            fuv_ave_path.push_str(".fits");
37
38
39        let mut nuv_ave_path = "/Users/mayabasu/Desktop/Output/nuv/counts".to_string();
40            nuv_ave_path.push_str(label.to_string().as_str());
41                nuv_ave_path.push_str(".fits");
42
43
44        let fuv_ave:Vec<f64> = self.data.iter().flatten().map(|a|a[0]).collect();
45        let nuv_ave:Vec<f64> = self.data.iter().flatten().map(|a|a[1]).collect();
46        let fuv_counts:Vec<f64> = self.data.iter().flatten().map(|a|a[2]).collect();
47        let nuv_counts:Vec<f64> = self.data.iter().flatten().map(|a|a[3]).collect();
48
49        let mut fuv_primary_hdu = Hdu::new(&shape, fuv_ave);
50        let mut nuv_primary_hdu = Hdu::new(&shape, nuv_ave);
51        let mut fuv_counts_primary_hdu = Hdu::new(&shape, fuv_counts);
52        let mut nuv_counts_primary_hdu = Hdu::new(&shape, nuv_counts);
53        // Insert values in header later
54        //primary_hdu.insert("KEYSTR", "My string");
55        println!("{:?}",fuv_ave_path);
56        Fits::create(fuv_ave_path, fuv_primary_hdu).expect("Failed to create");
57        Fits::create(nuv_ave_path, nuv_primary_hdu).expect("Failed to create");
58        Fits::create(fuv_counts_path, fuv_counts_primary_hdu).expect("Failed to create");
59        Fits::create(nuv_counts_path, nuv_counts_primary_hdu).expect("Failed to create");
60
61
62
63
64
65    }
66
67    pub fn show(path:&str){
68        //Users/mayabasu/Desktop/Output/fuv/1.fits
69
70    }
71}
72
73pub struct DetectorArray{
74    pub label: String,
75    pub detectors: Vec<Detector>,
76    pub coordinate_system: CoordinateSystem
77}
78
79
80
81
82