pub mod meta; use crate::errors::DataError; use async_trait::async_trait; pub use meta::MetaInfo; use ndarray::iter::Indices; use ndarray::{ s, Array, Array1, Array2, Array3, ArrayBase, Axis, DataMut, Dimension, Ix1, Ix2, Ix3, OwnedRepr, RawDataClone, Slice, ViewRepr, }; use npyz::{npz::NpzArchive, Deserialize}; use num_traits::{AsPrimitive, FromPrimitive, Num}; use std::{self, f64::consts::PI, fmt::Debug, io::BufReader, path::Path}; pub type Radar2d = RadarData2d, OwnedRepr, OwnedRepr>; pub type Radar3d = RadarData3d, OwnedRepr, OwnedRepr, OwnedRepr>; pub type Radar2dRef<'a, T> = RadarData2d, ViewRepr<&'a f64>, ViewRepr<&'a f64>>; pub type Radar3dRef<'a, T> = RadarData3d, ViewRepr<&'a f64>, ViewRepr<&'a f64>, ViewRepr<&'a f64>>; #[derive(Debug, Clone, Copy)] pub enum DataType { F64, I64, U64, F32, I32, U32, I16, U16, I8, U8, } #[derive(Clone, Copy, Debug)] pub enum CoordType { Polar, LatLon, } pub trait MultiDimensionData where T: Num + Clone + PartialEq + PartialOrd, { fn map_by_fn(&mut self, f: F) where F: FnMut(&mut T); } #[derive(Clone)] pub struct RadarData2d where T: Num + Clone + PartialEq + PartialOrd, Raw: ndarray::Data + ndarray::RawDataClone, X: ndarray::Data + ndarray::RawDataClone, Y: ndarray::Data + ndarray::RawDataClone, { pub dim1: ArrayBase, pub dim2: ArrayBase, pub data: ArrayBase, pub fill_value: T, pub coord_type: CoordType, } impl Radar2d where T: Num + Clone + PartialEq + PartialOrd, { pub fn as_ref<'a>(&'a self) -> Radar2dRef<'a, T> { RadarData2d { dim1: self.dim1.view(), dim2: self.dim2.view(), data: self.data.view(), fill_value: self.fill_value.clone(), coord_type: self.coord_type.clone(), } } } #[derive(Clone)] pub struct RadarData3d where T: Num + Clone + PartialEq + PartialOrd, Raw: ndarray::Data + ndarray::RawDataClone, X: ndarray::Data + ndarray::RawDataClone, Y: ndarray::Data + ndarray::RawDataClone, Z: ndarray::Data + ndarray::RawDataClone, { pub dim1: ArrayBase, pub dim2: ArrayBase, pub dim3: ArrayBase, pub data: ArrayBase, pub fill_value: T, pub coord_type: CoordType, } impl RadarData3d where T: Num + Clone + PartialEq + PartialOrd, X: ndarray::Data + ndarray::RawDataClone, Y: ndarray::Data + ndarray::RawDataClone, Z: ndarray::Data + ndarray::RawDataClone, Raw: ndarray::Data + ndarray::RawDataClone, { pub fn index_axis(&self, axis: Axis, slice: usize) -> Radar2dRef { let shape = self.data.shape(); println!("shape: {:?}", shape); let dim1 = self.dim1.view(); let dim2 = self.dim2.view(); let view = self.data.index_axis(axis, slice); RadarData2d { dim1, dim2, data: view, fill_value: self.fill_value.clone(), coord_type: self.coord_type.clone(), } } } impl MultiDimensionData for RadarData3d where T: Num + Clone, T: PartialEq + PartialOrd, X: ndarray::Data + ndarray::RawDataClone, Y: ndarray::Data + ndarray::RawDataClone, Z: ndarray::Data + ndarray::RawDataClone, Raw: ndarray::Data + RawDataClone + DataMut, { fn map_by_fn(&mut self, f: F) where F: FnMut(&mut T), { self.data.map_inplace(f); } } impl MultiDimensionData for RadarData2d where T: Num + Clone, T: PartialEq + PartialOrd, X: ndarray::Data + ndarray::RawDataClone, Y: ndarray::Data + ndarray::RawDataClone, Raw: ndarray::Data + RawDataClone + DataMut, { fn map_by_fn(&mut self, f: F) where F: FnMut(&mut T), { self.data.map_inplace(f); } }