nexrad_model/data/
product.rs1use crate::data::{CFPMomentData, MomentData, Radial};
2
3#[cfg(feature = "serde")]
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14pub enum Product {
15 Reflectivity,
17 Velocity,
19 SpectrumWidth,
21 DifferentialReflectivity,
23 DifferentialPhase,
25 CorrelationCoefficient,
27 ClutterFilterPower,
29}
30
31impl Product {
32 pub fn moment_data<'a>(&self, radial: &'a Radial) -> Option<&'a MomentData> {
37 match self {
38 Product::Reflectivity => radial.reflectivity(),
39 Product::Velocity => radial.velocity(),
40 Product::SpectrumWidth => radial.spectrum_width(),
41 Product::DifferentialReflectivity => radial.differential_reflectivity(),
42 Product::DifferentialPhase => radial.differential_phase(),
43 Product::CorrelationCoefficient => radial.correlation_coefficient(),
44 Product::ClutterFilterPower => None,
45 }
46 }
47
48 pub fn cfp_moment_data<'a>(&self, radial: &'a Radial) -> Option<&'a CFPMomentData> {
51 match self {
52 Product::ClutterFilterPower => radial.clutter_filter_power(),
53 _ => None,
54 }
55 }
56
57 pub fn value_range(&self) -> (f32, f32) {
62 match self {
63 Product::Reflectivity => (-32.0, 95.0),
64 Product::Velocity => (-64.0, 64.0),
65 Product::SpectrumWidth => (0.0, 30.0),
66 Product::DifferentialReflectivity => (-2.0, 6.0),
67 Product::DifferentialPhase => (0.0, 360.0),
68 Product::CorrelationCoefficient => (0.0, 1.0),
69 Product::ClutterFilterPower => (-20.0, 20.0),
70 }
71 }
72
73 pub fn unit(&self) -> &'static str {
75 match self {
76 Product::Reflectivity => "dBZ",
77 Product::Velocity => "m/s",
78 Product::SpectrumWidth => "m/s",
79 Product::DifferentialReflectivity => "dB",
80 Product::DifferentialPhase => "°",
81 Product::CorrelationCoefficient => "",
82 Product::ClutterFilterPower => "dB",
83 }
84 }
85
86 pub fn label(&self) -> &'static str {
88 match self {
89 Product::Reflectivity => "Reflectivity",
90 Product::Velocity => "Velocity",
91 Product::SpectrumWidth => "Spectrum Width",
92 Product::DifferentialReflectivity => "Differential Reflectivity",
93 Product::DifferentialPhase => "Differential Phase",
94 Product::CorrelationCoefficient => "Correlation Coefficient",
95 Product::ClutterFilterPower => "Clutter Filter Power",
96 }
97 }
98}