@@ -8,19 +8,19 @@ use crate::{
8
8
#[ derive( Debug , Clone ) ]
9
9
pub struct BuddyCheckArgs {
10
10
/// Search radius in which buddies of an observation will be found. Unit: m
11
- pub radii : SingleOrVec < f32 > ,
11
+ pub radii : SingleOrVec < f64 > ,
12
12
/// The minimum buddies an observation can have (lest it be flagged [`Flag::Isolated`])
13
13
pub min_buddies : SingleOrVec < u32 > ,
14
14
/// The variance threshold for flagging a station. Unit: σ (standard deviations)
15
- pub threshold : f32 ,
15
+ pub threshold : f64 ,
16
16
/// The maximum difference in elevation for a buddy (if negative will not check for height
17
17
/// difference). Unit: m
18
- pub max_elev_diff : f32 ,
18
+ pub max_elev_diff : f64 ,
19
19
/// Linear elevation gradient with height. Unit: ou/m (ou = unit of observation)
20
- pub elev_gradient : f32 ,
20
+ pub elev_gradient : f64 ,
21
21
/// If the standard deviation of values in a neighborhood are less than min_std, min_std will
22
22
/// be used instead
23
- pub min_std : f32 ,
23
+ pub min_std : f64 ,
24
24
/// The number of iterations of buddy_check to perform before returning
25
25
pub num_iterations : u32 ,
26
26
}
@@ -54,7 +54,7 @@ pub struct BuddyCheckArgs {
54
54
/// element is set to true, while all values are always used as buddies for checking the data
55
55
/// quality.
56
56
pub fn buddy_check (
57
- data : & [ Option < f32 > ] ,
57
+ data : & [ Option < f64 > ] ,
58
58
rtree : & SpatialTree ,
59
59
args : & BuddyCheckArgs ,
60
60
obs_to_check : Option < & [ bool ] > ,
@@ -87,7 +87,7 @@ pub fn buddy_check(
87
87
let ( lat, lon, elev) = rtree. get_coords_at_index ( i) ;
88
88
let neighbours = rtree. get_neighbours ( lat, lon, * args. radii . index ( i) , false ) ;
89
89
90
- let mut list_buddies: Vec < f32 > = Vec :: new ( ) ;
90
+ let mut list_buddies: Vec < f64 > = Vec :: new ( ) ;
91
91
92
92
if neighbours. len ( ) >= * args. min_buddies . index ( i) as usize {
93
93
for neighbour in neighbours {
@@ -116,17 +116,17 @@ pub fn buddy_check(
116
116
}
117
117
118
118
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 )
122
122
- mean. powi ( 2 ) ; // TODO: use a better variance algorithm?
123
123
// 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();
125
125
// if std_adjusted < min_std {
126
126
// std_adjusted = min_std
127
127
// }
128
128
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 ( ) ,
130
130
args. min_std ,
131
131
|x, y| x. partial_cmp ( y) . unwrap_or ( std:: cmp:: Ordering :: Equal ) ,
132
132
) ;
@@ -174,7 +174,7 @@ pub fn buddy_check_cache(
174
174
175
175
for i in ( cache. num_leading_points as usize ) ..( series_len - cache. num_trailing_points as usize )
176
176
{
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 ( ) ;
178
178
let spatial_result = buddy_check ( & timeslice, & cache. rtree , args, obs_to_check) ?;
179
179
180
180
for i in 0 ..spatial_result. len ( ) {
0 commit comments