Skip to content

Commit c7cd9af

Browse files
committedFeb 5, 2025
Change f32 to f64
1 parent 138b27f commit c7cd9af

17 files changed

+126
-126
lines changed
 

‎src/checks/consistency/greater_than.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{ConsistencyCache, Error, Flag, Timeseries, TimeseriesPair};
77
/// - [`Flag::DataMissing`] if either datum is missing,
88
/// - [`Flag::Fail`] if datum1 + datum1_correction > datum2,
99
/// - [`Flag::Pass`] otherwise.
10-
pub fn greater_than(datum1: Option<f32>, datum2: Option<f32>, datum1_correction: f32) -> Flag {
10+
pub fn greater_than(datum1: Option<f64>, datum2: Option<f64>, datum1_correction: f64) -> Flag {
1111
if datum1.is_none() || datum2.is_none() {
1212
return Flag::DataMissing;
1313
}
@@ -29,7 +29,7 @@ pub fn greater_than(datum1: Option<f32>, datum2: Option<f32>, datum1_correction:
2929
/// - `cache.ratio` is not 1
3030
pub fn greater_than_cache(
3131
cache: &ConsistencyCache,
32-
correction: f32,
32+
correction: f64,
3333
) -> Result<Vec<TimeseriesPair<Flag>>, Error> {
3434
if cache.ratio != 1 {
3535
return Err(Error::InvalidInputShape(String::from(

‎src/checks/consistency/not_equal.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{ConsistencyCache, Error, Flag, Timeseries, TimeseriesPair};
1010
/// - [`Flag::DataMissing`] if either datum is missing,
1111
/// - [`Flag::Fail`] if the difference between datum1 and datum2 is greater than threshold,
1212
/// - [`Flag::Pass`] otherwise.
13-
pub fn not_equal(datum1: Option<f32>, datum2: Option<f32>, threshold: f32) -> Flag {
13+
pub fn not_equal(datum1: Option<f64>, datum2: Option<f64>, threshold: f64) -> Flag {
1414
if datum1.is_none() || datum2.is_none() {
1515
return Flag::DataMissing;
1616
}
@@ -31,7 +31,7 @@ pub fn not_equal(datum1: Option<f32>, datum2: Option<f32>, threshold: f32) -> Fl
3131
/// - `cache.ratio` is not 1
3232
pub fn not_equal_cache(
3333
cache: &ConsistencyCache,
34-
threshold: f32,
34+
threshold: f64,
3535
) -> Result<Vec<TimeseriesPair<Flag>>, Error> {
3636
if cache.ratio != 1 {
3737
return Err(Error::InvalidInputShape(String::from(

‎src/checks/consistency/single_greater_than_any.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use crate::{ConsistencyCache, Flag, Timeseries, TimeseriesPair};
1818
/// plus the adjustment),
1919
/// - [`Flag::Pass`] otherwise.
2020
pub fn single_greater_than_any(
21-
single: Option<f32>,
22-
sequence: &[Option<f32>],
23-
adjustment: f32,
21+
single: Option<f64>,
22+
sequence: &[Option<f64>],
23+
adjustment: f64,
2424
) -> (Flag, Vec<Flag>) {
2525
let single = match single {
2626
Some(value) => value,
@@ -67,7 +67,7 @@ pub fn single_greater_than_any(
6767
/// - `cache.ratio` is 0
6868
pub fn single_greater_than_any_cache(
6969
cache: &ConsistencyCache,
70-
adjustment: f32,
70+
adjustment: f64,
7171
) -> Vec<TimeseriesPair<Flag>> {
7272
let num_series = cache.data.len();
7373
let mut result_vec = Vec::with_capacity(num_series);

‎src/checks/consistency/single_less_than_any.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use crate::{ConsistencyCache, Flag, Timeseries, TimeseriesPair};
1818
/// plus the adjustment),
1919
/// - [`Flag::Pass`] otherwise.
2020
pub fn single_less_than_any(
21-
single: Option<f32>,
22-
sequence: &[Option<f32>],
23-
adjustment: f32,
21+
single: Option<f64>,
22+
sequence: &[Option<f64>],
23+
adjustment: f64,
2424
) -> (Flag, Vec<Flag>) {
2525
let single = match single {
2626
Some(value) => value,
@@ -67,7 +67,7 @@ pub fn single_less_than_any(
6767
/// - `cache.ratio` is 0
6868
pub fn single_less_than_any_cache(
6969
cache: &ConsistencyCache,
70-
adjustment: f32,
70+
adjustment: f64,
7171
) -> Vec<TimeseriesPair<Flag>> {
7272
let num_series = cache.data.len();
7373
let mut result_vec = Vec::with_capacity(num_series);

‎src/checks/consistency/single_outside_sequence.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use crate::{ConsistencyCache, Flag, Timeseries, TimeseriesPair};
1111
/// point did not satisfy the invariant.
1212
/// - [`Flag::Fail`] otherwise.
1313
pub fn single_outside_sequence(
14-
single: Option<f32>,
15-
sequence: &[Option<f32>],
16-
adjustment: f32,
14+
single: Option<f64>,
15+
sequence: &[Option<f64>],
16+
adjustment: f64,
1717
) -> Flag {
1818
let single = match single {
1919
Some(value) => value,
@@ -25,7 +25,7 @@ pub fn single_outside_sequence(
2525
// indicating if any value was missing
2626
let (minmax, missing) = sequence.iter().fold(
2727
(None, false),
28-
|acc: (Option<(f32, f32)>, bool), elem| match elem {
28+
|acc: (Option<(f64, f64)>, bool), elem| match elem {
2929
// if the element wasn't missing...
3030
Some(value) => match acc.0 {
3131
// set the minmax if there isn't already a minmax, or the element is lower
@@ -63,7 +63,7 @@ pub fn single_outside_sequence(
6363
/// - `cache.ratio` is 0
6464
pub fn single_outside_sequence_cache(
6565
cache: &ConsistencyCache,
66-
adjustment: f32,
66+
adjustment: f64,
6767
) -> Vec<TimeseriesPair<Flag>> {
6868
let num_series = cache.data.len();
6969
let mut result_vec = Vec::with_capacity(num_series);

‎src/checks/series/flatline_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{util::Timeseries, DataCache, Error, Flag};
1212
/// - [`Flag::Invalid`] if `data` is empty,
1313
/// - [`Flag::Fail`] if all observations passed in are identical,
1414
/// - [`Flag::Pass`] otherwise.
15-
pub fn flatline_check(data: &[Option<f32>], threshold: f32) -> Flag {
15+
pub fn flatline_check(data: &[Option<f64>], threshold: f64) -> Flag {
1616
if data.contains(&None) {
1717
return Flag::DataMissing;
1818
}
@@ -45,7 +45,7 @@ pub fn flatline_check(data: &[Option<f32>], threshold: f32) -> Flag {
4545
pub fn flatline_check_cache(
4646
cache: &DataCache,
4747
num_points: u8,
48-
threshold: f32,
48+
threshold: f64,
4949
) -> Result<Vec<Timeseries<Flag>>, Error> {
5050
let num_series = cache.data.len();
5151
let mut result_vec = Vec::with_capacity(cache.data.len());

‎src/checks/series/monotonic_decrease_check.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{DataCache, Error, Flag, Timeseries};
1818
/// - [`Flag::Fail`] if there are no increases between consecutive data points in the series
1919
/// AND the total decrease over the series is within the given range
2020
/// - [`Flag::Pass`] otherwise.
21-
pub fn monotonic_decrease_check(data: &[Option<f32>], lower_limit: f32, upper_limit: f32) -> Flag {
21+
pub fn monotonic_decrease_check(data: &[Option<f64>], lower_limit: f64, upper_limit: f64) -> Flag {
2222
if data.is_empty() || data.iter().any(Option::is_none) {
2323
return Flag::DataMissing;
2424
}
@@ -65,8 +65,8 @@ pub fn monotonic_decrease_check(data: &[Option<f32>], lower_limit: f32, upper_li
6565
/// - data has `num_leading_points` or `num_trailing_points` < `window_size`
6666
pub fn monotonic_decrease_check_cache(
6767
cache: &DataCache,
68-
lower_limit: f32,
69-
upper_limit: f32,
68+
lower_limit: f64,
69+
upper_limit: f64,
7070
// TODO: should this maybe be a usize? would require changing the type of num_leading_points
7171
// in DataCache
7272
window_size: u8,
@@ -138,10 +138,10 @@ mod tests {
138138

139139
#[test]
140140
fn test_monotonic_decrease_check() {
141-
let decreasing_sequence: Vec<Option<f32>> = repeat(200.)
141+
let decreasing_sequence: Vec<Option<f64>> = repeat(200.)
142142
.take(25)
143143
.enumerate()
144-
.map(|(i, val)| Some(val - (i as f32 * 0.1)))
144+
.map(|(i, val)| Some(val - (i as f64 * 0.1)))
145145
.collect();
146146
assert_eq!(
147147
monotonic_decrease_check(&decreasing_sequence.clone(), 0.7, 100.),

‎src/checks/series/spike_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub const SPIKE_TRAILING_PER_RUN: u8 = 1;
2121
/// - [`Flag::Fail`] if the difference (explained above) is less than 35% of the sum AND the sum
2222
/// (explained above) is greater than `max`,
2323
/// - [`Flag::Pass`] otherwise.
24-
pub fn spike_check(data: &[Option<f32>; 3], max: f32) -> Flag {
24+
pub fn spike_check(data: &[Option<f64>; 3], max: f64) -> Flag {
2525
if data.contains(&None) {
2626
return Flag::DataMissing;
2727
}
@@ -49,7 +49,7 @@ pub fn spike_check(data: &[Option<f32>; 3], max: f32) -> Flag {
4949
/// - data is invalid
5050
/// - data has `num_leading_points` <= 1
5151
/// - data has `num_trailing_points` <= 1
52-
pub fn spike_check_cache(cache: &DataCache, max: f32) -> Result<Vec<Timeseries<Flag>>, Error> {
52+
pub fn spike_check_cache(cache: &DataCache, max: f64) -> Result<Vec<Timeseries<Flag>>, Error> {
5353
let num_series = cache.data.len();
5454
let mut result_vec = Vec::with_capacity(num_series);
5555
let series_len = match cache.data.first() {

‎src/checks/series/step_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub const STEP_LEADING_PER_RUN: u8 = 1;
1313
/// - [`Flag::Fail`] If the absolute value of the difference between the observed value and it's
1414
/// predecessor is greater than max
1515
/// - [`Flag::Pass`] otherwise.
16-
pub fn step_check(data: &[Option<f32>; 2], max: f32) -> Flag {
16+
pub fn step_check(data: &[Option<f64>; 2], max: f64) -> Flag {
1717
if data.contains(&None) {
1818
return Flag::DataMissing;
1919
}
@@ -33,7 +33,7 @@ pub fn step_check(data: &[Option<f32>; 2], max: f32) -> Flag {
3333
///
3434
/// - data is invalid
3535
/// - data has `num_leading_points` < 1
36-
pub fn step_check_cache(cache: &DataCache, max: f32) -> Result<Vec<Timeseries<Flag>>, Error> {
36+
pub fn step_check_cache(cache: &DataCache, max: f64) -> Result<Vec<Timeseries<Flag>>, Error> {
3737
let num_series = cache.data.len();
3838
let mut result_vec = Vec::with_capacity(num_series);
3939
let series_len = match cache.data.first() {

‎src/checks/single/range_check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{util::Timeseries, DataCache, Flag};
66
/// - [`Flag::DataMissing`] if the observation is missing,
77
/// - [`Flag::Fail`] if it is outside the upper or lower limits,
88
/// - [`Flag::Pass`] otherwise.
9-
pub fn range_check(datum: Option<f32>, lower_limit: f32, upper_limit: f32) -> Flag {
9+
pub fn range_check(datum: Option<f64>, lower_limit: f64, upper_limit: f64) -> Flag {
1010
match datum {
1111
None => Flag::DataMissing,
1212
Some(datum) => {
@@ -21,8 +21,8 @@ pub fn range_check(datum: Option<f32>, lower_limit: f32, upper_limit: f32) -> Fl
2121
/// Apply [`range_check`] to a whole [`DataCache`]
2222
pub fn range_check_cache(
2323
cache: &DataCache,
24-
lower_limit: f32,
25-
upper_limit: f32,
24+
lower_limit: f64,
25+
upper_limit: f64,
2626
) -> Vec<Timeseries<Flag>> {
2727
let num_series = cache.data.len();
2828
let mut result_vec = Vec::with_capacity(num_series);

‎src/checks/single/range_check_humidity.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{util::Timeseries, DataCache, Flag};
77
/// - ([`Flag::Fail`], None) if humidity less than 5% or greater than 105%,
88
/// - ([`Flag::Warn`], Some(100.)) between 100% and 105%,
99
/// - ([`Flag::Pass`], None) otherwise.
10-
pub fn range_check_humidity(datum: Option<f32>) -> (Flag, Option<f32>) {
10+
pub fn range_check_humidity(datum: Option<f64>) -> (Flag, Option<f64>) {
1111
match datum {
1212
None => (Flag::DataMissing, None),
1313
Some(datum) => {
@@ -25,7 +25,7 @@ pub fn range_check_humidity(datum: Option<f32>) -> (Flag, Option<f32>) {
2525
//TODO: is this the optimal return signature for corrections?
2626
/// Apply [`range_check_humidity`] to a whole [`DataCache`]
2727
#[allow(clippy::type_complexity)]
28-
pub fn range_check_humidity_cache(cache: &DataCache) -> Vec<Timeseries<(Flag, Option<f32>)>> {
28+
pub fn range_check_humidity_cache(cache: &DataCache) -> Vec<Timeseries<(Flag, Option<f64>)>> {
2929
let num_series = cache.data.len();
3030
let mut result_vec = Vec::with_capacity(num_series);
3131
let series_len = match cache.data.first() {

‎src/checks/single/range_check_wind_direction.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{util::Timeseries, DataCache, Flag};
88
/// - ([`Flag::Warn`], Some(value + 360)) if the value is between -20 and 0,
99
/// - ([`Flag::Warn`], Some(value - 360)) if the value is between 360 and 380,
1010
/// - ([`Flag::Pass`], None) otherwise.
11-
pub fn range_check_wind_direction(datum: Option<f32>) -> (Flag, Option<f32>) {
11+
pub fn range_check_wind_direction(datum: Option<f64>) -> (Flag, Option<f64>) {
1212
// TODO: get to the bottom of weird -3.0 handling: kvalobs code looks for a value -3.0, and
1313
// avoids flagging that if X_5 (lowest?) is also -3.0. From comments in the code, it looks like
1414
// this has to do with a special param_id?
@@ -36,7 +36,7 @@ pub fn range_check_wind_direction(datum: Option<f32>) -> (Flag, Option<f32>) {
3636
//TODO: is this the optimal return signature for corrections?
3737
/// Apply [`range_check_wind_direction`] to a whole [`DataCache`]
3838
#[allow(clippy::type_complexity)]
39-
pub fn range_check_wind_direction_cache(cache: &DataCache) -> Vec<Timeseries<(Flag, Option<f32>)>> {
39+
pub fn range_check_wind_direction_cache(cache: &DataCache) -> Vec<Timeseries<(Flag, Option<f64>)>> {
4040
let num_series = cache.data.len();
4141
let mut result_vec = Vec::with_capacity(num_series);
4242
let series_len = match cache.data.first() {

‎src/checks/single/special_values_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{util::Timeseries, DataCache, Flag};
66
/// - [`Flag::DataMissing`] if the observation is missing,
77
/// - [`Flag::Fail`] if it matches any of the special values
88
/// - [`Flag::Pass`] otherwise.
9-
pub fn special_values_check(datum: Option<f32>, special_values: &[f32]) -> Flag {
9+
pub fn special_values_check(datum: Option<f64>, special_values: &[f64]) -> Flag {
1010
match datum {
1111
None => Flag::DataMissing,
1212
Some(datum) => {
@@ -21,7 +21,7 @@ pub fn special_values_check(datum: Option<f32>, special_values: &[f32]) -> Flag
2121
/// Apply [`special_values_check`] to a whole [`DataCache`]
2222
pub fn special_values_check_cache(
2323
cache: &DataCache,
24-
special_values: &[f32],
24+
special_values: &[f64],
2525
) -> Vec<Timeseries<Flag>> {
2626
let num_series = cache.data.len();
2727
let mut result_vec = Vec::with_capacity(num_series);

‎src/checks/spatial/buddy_check.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ use crate::{
88
#[derive(Debug, Clone)]
99
pub struct BuddyCheckArgs {
1010
/// Search radius in which buddies of an observation will be found. Unit: m
11-
pub radii: SingleOrVec<f32>,
11+
pub radii: SingleOrVec<f64>,
1212
/// The minimum buddies an observation can have (lest it be flagged [`Flag::Isolated`])
1313
pub min_buddies: SingleOrVec<u32>,
1414
/// The variance threshold for flagging a station. Unit: σ (standard deviations)
15-
pub threshold: f32,
15+
pub threshold: f64,
1616
/// The maximum difference in elevation for a buddy (if negative will not check for height
1717
/// difference). Unit: m
18-
pub max_elev_diff: f32,
18+
pub max_elev_diff: f64,
1919
/// Linear elevation gradient with height. Unit: ou/m (ou = unit of observation)
20-
pub elev_gradient: f32,
20+
pub elev_gradient: f64,
2121
/// If the standard deviation of values in a neighborhood are less than min_std, min_std will
2222
/// be used instead
23-
pub min_std: f32,
23+
pub min_std: f64,
2424
/// The number of iterations of buddy_check to perform before returning
2525
pub num_iterations: u32,
2626
}
@@ -54,7 +54,7 @@ pub struct BuddyCheckArgs {
5454
/// element is set to true, while all values are always used as buddies for checking the data
5555
/// quality.
5656
pub fn buddy_check(
57-
data: &[Option<f32>],
57+
data: &[Option<f64>],
5858
rtree: &SpatialTree,
5959
args: &BuddyCheckArgs,
6060
obs_to_check: Option<&[bool]>,
@@ -87,7 +87,7 @@ pub fn buddy_check(
8787
let (lat, lon, elev) = rtree.get_coords_at_index(i);
8888
let neighbours = rtree.get_neighbours(lat, lon, *args.radii.index(i), false);
8989

90-
let mut list_buddies: Vec<f32> = Vec::new();
90+
let mut list_buddies: Vec<f64> = Vec::new();
9191

9292
if neighbours.len() >= *args.min_buddies.index(i) as usize {
9393
for neighbour in neighbours {
@@ -116,17 +116,17 @@ pub fn buddy_check(
116116
}
117117

118118
if list_buddies.len() >= *args.min_buddies.index(i) as usize {
119-
let mean: f32 = list_buddies.iter().sum::<f32>() / list_buddies.len() as f32;
120-
let variance: f32 = (list_buddies.iter().map(|x| x.powi(2)).sum::<f32>()
121-
/ list_buddies.len() as f32)
119+
let mean: f64 = list_buddies.iter().sum::<f64>() / list_buddies.len() as f64;
120+
let variance: f64 = (list_buddies.iter().map(|x| x.powi(2)).sum::<f64>()
121+
/ list_buddies.len() as f64)
122122
- mean.powi(2); // TODO: use a better variance algorithm?
123123
// let std = variance.sqrt();
124-
// let std_adjusted = (variance + variance / list_buddies.len() as f32).sqrt();
124+
// let std_adjusted = (variance + variance / list_buddies.len() as f64).sqrt();
125125
// if std_adjusted < min_std {
126126
// std_adjusted = min_std
127127
// }
128128
let std_adjusted = std::cmp::max_by(
129-
(variance + variance / list_buddies.len() as f32).sqrt(),
129+
(variance + variance / list_buddies.len() as f64).sqrt(),
130130
args.min_std,
131131
|x, y| x.partial_cmp(y).unwrap_or(std::cmp::Ordering::Equal),
132132
);
@@ -174,7 +174,7 @@ pub fn buddy_check_cache(
174174

175175
for i in (cache.num_leading_points as usize)..(series_len - cache.num_trailing_points as usize)
176176
{
177-
let timeslice: Vec<Option<f32>> = cache.data.iter().map(|fs| fs.values[i]).collect();
177+
let timeslice: Vec<Option<f64>> = cache.data.iter().map(|fs| fs.values[i]).collect();
178178
let spatial_result = buddy_check(&timeslice, &cache.rtree, args, obs_to_check)?;
179179

180180
for i in 0..spatial_result.len() {

0 commit comments

Comments
 (0)
Please sign in to comment.