jgdtrans 0.3.1

Coordinate Transformer by Gridded Correction Parameter (par file)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
//! Provides [`Transformer`] etc.
use crate::mesh::MeshUnit;
use crate::{Format, ParData, ParseParError};
use std::hash::RandomState;

/// Improved Kahan–Babuška algorithm
///
/// see: https://en.wikipedia.org/wiki/Kahan_summation_algorithm#Further_enhancements
fn ksum(vs: &[f64]) -> f64 {
    let mut sum = 0.0;
    let mut c = 0.0;
    for v in vs {
        let t = sum + *v;
        c += if sum.ge(v) {
            (sum - t) + v
        } else {
            (v - t) + sum
        };
        sum = t
    }
    sum + c
}

/// The parameter triplet.
///
/// We emphasize that the unit of latitude and longitude is \[sec\], not \[deg\].
///
/// It should fill with 0.0 instead of [`NAN`](f64::NAN)
/// if the parameter does not exist, as the parser does.
///
/// # Example
///
/// ```
/// # use jgdtrans::*;
/// #
/// let parameter = Parameter::new(1., 2., 3.);
/// assert_eq!(parameter.latitude, 1.);
/// assert_eq!(parameter.longitude, 2.);
/// assert_eq!(parameter.altitude, 3.);
/// ```
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Parameter {
    /// The latitude parameter \[sec\]
    pub latitude: f64,
    /// The latitude parameter \[sec\]
    pub longitude: f64,
    /// The altitude parameter \[m\]
    pub altitude: f64,
}

impl From<(f64, f64, f64)> for Parameter {
    #[inline]
    fn from(value: (f64, f64, f64)) -> Self {
        Self {
            latitude: value.0,
            longitude: value.1,
            altitude: value.2,
        }
    }
}

impl From<[f64; 3]> for Parameter {
    #[inline]
    fn from(value: [f64; 3]) -> Self {
        Self {
            latitude: value[0],
            longitude: value[1],
            altitude: value[2],
        }
    }
}

impl Parameter {
    /// Makes a `Parameter`.
    ///
    /// # Example
    ///
    /// ```
    /// # use jgdtrans::*;
    /// #
    /// let parameter = Parameter::new(1., 2., 3.);
    /// assert_eq!(parameter.latitude, 1.);
    /// assert_eq!(parameter.longitude, 2.);
    /// assert_eq!(parameter.altitude, 3.);
    /// ```
    #[inline]
    #[must_use]
    pub const fn new(latitude: f64, longitude: f64, altitude: f64) -> Self {
        Self {
            latitude,
            longitude,
            altitude,
        }
    }

    /// Returns √𝑙𝑎𝑡𝑖𝑡𝑢𝑑𝑒² + 𝑙𝑜𝑛𝑔𝑖𝑡𝑢𝑑𝑒².
    #[inline]
    #[must_use]
    pub fn horizontal(&self) -> f64 {
        // here and [`Correction::horizontal`] are
        // only parts that use not an exact operation
        // defined by IEEE 754, [`f64::hypot`].
        f64::hypot(self.latitude, self.longitude)
    }
}

/// The transformation correction.
///
/// We emphasize that the unit of latitude and longitude
/// is \[deg\], not \[sec\].
///
/// It should fill with 0.0 instead of [`NAN`](f64::NAN).
///
/// # Example
///
/// ```
/// # use jgdtrans::*;
/// #
/// let correction = Correction::new(1., 2., 3.);
/// assert_eq!(correction.latitude, 1.);
/// assert_eq!(correction.longitude, 2.);
/// assert_eq!(correction.altitude, 3.);
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Correction {
    /// The latitude correction \[deg\].
    pub latitude: f64,
    /// The longitude correction \[deg\].
    pub longitude: f64,
    /// The altitude correction \[m\].
    pub altitude: f64,
}

impl Correction {
    /// Makes a [`Correction`].
    ///
    /// # Example
    ///
    /// ```
    /// # use jgdtrans::*;
    /// #
    /// let correction = Correction::new(1., 2., 3.);
    /// assert_eq!(correction.latitude, 1.);
    /// assert_eq!(correction.longitude, 2.);
    /// assert_eq!(correction.altitude, 3.);
    /// ```
    #[inline]
    #[must_use]
    pub const fn new(latitude: f64, longitude: f64, altitude: f64) -> Self {
        Self {
            latitude,
            longitude,
            altitude,
        }
    }

    /// Returns √𝑙𝑎𝑡𝑖𝑡𝑢𝑑𝑒² + 𝑙𝑜𝑛𝑔𝑖𝑡𝑢𝑑𝑒².
    #[inline]
    #[must_use]
    pub fn horizontal(&self) -> f64 {
        // here and [`Parameter::horizontal`] are
        // only parts that use not an exact operation
        // defined by IEEE 754, [`f64::hypot`].
        f64::hypot(self.latitude, self.longitude)
    }
}

/// The statistics of parameter.
///
/// This is a component of the result that [`Transformer::statistics()`] returns.
#[derive(Debug, PartialEq, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StatisticData {
    /// The count of parameters.
    pub count: Option<usize>,
    /// The mean, \[sec\] or \[m\].
    pub mean: Option<f64>,
    /// The standard variance, \[sec\] or \[m\].
    pub std: Option<f64>,
    /// The mean of abs value, 1/𝑛 ∑ᵢ | 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟ᵢ |, \[sec\] or \[m\].
    pub abs: Option<f64>,
    /// The minimum,\[sec\] or \[m\].
    pub min: Option<f64>,
    /// The maximum, \[sec\] or \[m\].
    pub max: Option<f64>,
}

impl StatisticData {
    fn from_array(vs: &[f64]) -> Self {
        if vs.is_empty() {
            return Self {
                count: None,
                mean: None,
                std: None,
                abs: None,
                min: None,
                max: None,
            };
        }

        let sum = ksum(vs);
        let count = vs.len();
        if sum.is_nan() {
            return Self {
                count: Some(count),
                mean: Some(f64::NAN),
                std: Some(f64::NAN),
                abs: Some(f64::NAN),
                min: Some(f64::NAN),
                max: Some(f64::NAN),
            };
        }

        let mut max = f64::MIN;
        let mut min = f64::MAX;
        let mut std: Vec<f64> = Vec::with_capacity(count);
        let mut abs: Vec<f64> = Vec::with_capacity(count);

        for v in vs.iter() {
            // never nan
            max = v.max(max);
            min = v.min(min);
            std.push((sum - *v).powi(2));
            abs.push(v.abs());
        }

        let length = count as f64;
        Self {
            count: Some(count),
            mean: Some(sum / length),
            std: Some((ksum(&std) / length).sqrt()),
            abs: Some(ksum(&abs) / length),
            min: Some(min),
            max: Some(max),
        }
    }
}

/// The statistical summary of parameter.
///
/// This is a result that [`Transformer::statistics()`] returns.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Statistics {
    /// The statistics of latitude.
    pub latitude: StatisticData,
    /// The statistics of longitude.
    pub longitude: StatisticData,
    /// The statistics of altitude.
    pub altitude: StatisticData,
    /// The statistics of horizontal.
    pub horizontal: StatisticData,
}

/// Trait for transformation.
pub trait ParameterSet {
    /// Returns [`MeshUnit`].
    fn mesh_unit(&self) -> MeshUnit;

    /// Returns [`Parameter`] associated with `meshcode`.
    fn get(&self, meshcode: &u32) -> Option<&Parameter>;
}

/// Trait for statistical analysis.
pub trait ParameterData {
    /// Returns all pairs of meshcode and parameter.
    fn to_vec(&self) -> Vec<(&u32, &Parameter)>;
}

/// The coordinate Transformer, and represents a deserializing result of par-formatted data.
///
/// If the parameters is zero, such as the unsupported components,
/// the transformations are identity transformation on such components.
/// For example, the transformation by the TKY2JGD and the PatchJGD par is
/// identity transformation on altitude, and by the PatchJGD(H) par is
/// so on latitude and longitude.
///
/// There is a builder, see [`TransformerBuilder`](crate::TransformerBuilder).
///
/// # Example
///
/// ```
/// # use std::collections::HashMap;
/// # use jgdtrans::*;
/// #
/// // from SemiDynaEXE2023.par
/// let tf = Transformer::new(
///     ParData::new(
///         Format::SemiDynaEXE,
///         HashMap::from([
///             (54401005, Parameter::new(-0.00622, 0.01516, 0.0946)),
///             (54401055, Parameter::new(-0.0062, 0.01529, 0.08972)),
///             (54401100, Parameter::new(-0.00663, 0.01492, 0.10374)),
///             (54401150, Parameter::new(-0.00664, 0.01506, 0.10087)),
///         ])
///     )
/// );
///
/// // forward transformation
/// let origin = Point::new_unchecked(36.10377479, 140.087855041, 2.34);
/// let result = tf.forward(&origin)?;
/// assert_eq!(result.latitude, 36.103773017086695);
/// assert_eq!(result.longitude, 140.08785924333452);
/// assert_eq!(result.altitude, 2.4363138578103);
/// # Ok::<(), TransformError>(())
/// ```
#[derive(Debug)]
pub struct Transformer<T> {
    inner: T,
}

impl<T> Transformer<T> {
    /// Max error of backward transformation.
    ///
    /// Used by [`Transformer::backward`], [`Transformer::backward_corr`]
    /// [`Transformer::backward_unchecked`] and [`Transformer::backward_corr_unchecked`].
    pub const MAX_ERROR: f64 = 5e-14;

    /// Makes a [`Transformer`].
    ///
    /// We note that we provide a builder, see [`TransformerBuilder`](crate::TransformerBuilder).
    ///
    /// # Example
    ///
    /// ```
    /// # use std::collections::HashMap;
    /// # use jgdtrans::*;
    /// # use jgdtrans::mesh::MeshUnit;
    /// #
    /// // from SemiDynaEXE2023.par
    /// let tf = Transformer::new(
    ///     ParData::new(
    ///         Format::SemiDynaEXE,
    ///         HashMap::from([
    ///             (54401005, Parameter::new(-0.00622, 0.01516, 0.0946)),
    ///             (54401055, Parameter::new(-0.0062, 0.01529, 0.08972)),
    ///         ])
    ///     )
    /// );
    ///
    /// assert_eq!(tf.mesh_unit(), MeshUnit::Five);
    /// assert_eq!(tf.get(&54401005), Some(&Parameter::new(-0.00622, 0.01516, 0.0946)));
    /// assert_eq!(tf.get(&54401055), Some(&Parameter::new(-0.0062, 0.01529, 0.08972)));
    /// ```
    #[inline]
    #[must_use]
    pub const fn new(parameter: T) -> Self {
        Self { inner: parameter }
    }
}

impl Transformer<ParData<RandomState>> {
    /// Deserialize par-formatted [`&str`] into a [`Transformer`] with [`ParData`].
    ///
    /// Use `format` argument to specify the format of `s`.
    ///
    /// This fills by 0.0 for altitude parameter when [`Format::TKY2JGD`] or [`Format::PatchJGD`] given,
    /// and for latitude and longitude when [`Format::PatchJGD_H`] or [`Format::HyokoRev`] given.
    ///
    /// # Errors
    ///
    /// Returns [`Err`] when the invalid data found.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::error::Error;
    /// # use jgdtrans::*;
    /// #
    /// let s = r"<15 lines>
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// MeshCode dB(sec)  dL(sec) dH(m)
    /// 12345678   0.00001   0.00002   0.00003";
    /// let tf = Transformer::from_str(&s, Format::SemiDynaEXE)?;
    ///
    /// assert_eq!(tf.mesh_unit(), MeshUnit::Five);
    /// assert_eq!(tf.get(&12345678),  Some(&Parameter::new(0.00001, 0.00002, 0.00003)));
    /// # Ok::<(), Box<dyn Error>>(())
    /// ```
    #[inline]
    pub fn from_str(s: &str, format: Format) -> Result<Self, ParseParError> {
        let data = ParData::from_str(s, format)?;
        Ok(Self::new(data))
    }

    /// Deserialize par-formatted [`&str`] into a [`Transformer`] with description.
    ///
    /// See [`Transformer::from_str`] for detail.
    /// # Errors
    ///
    /// Returns [`Err`] when the invalid data found.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::error::Error;
    /// # use jgdtrans::*;
    /// #
    /// let s = r"<15 lines>
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// # ...
    /// MeshCode dB(sec)  dL(sec) dH(m)
    /// 12345678   0.00001   0.00002   0.00003";
    /// let tf = Transformer::from_str_with_description(
    ///     &s,
    ///     Format::SemiDynaEXE,
    ///     "SemiDyna2023.par".to_string(),
    /// )?;
    ///
    /// assert_eq!(tf.mesh_unit(), MeshUnit::Five);
    /// assert_eq!(tf.get(&12345678), Some(&Parameter::new(0.00001, 0.00002, 0.00003)));
    /// # Ok::<(), Box<dyn Error>>(())
    /// ```
    #[inline]
    pub fn from_str_with_description(
        s: &str,
        format: Format,
        description: String,
    ) -> Result<Self, ParseParError> {
        let mut data = ParData::from_str(s, format)?;
        data.description = Some(description);
        Ok(Self::new(data))
    }
}

impl<T> Transformer<T>
where
    T: ParameterSet,
{
    #[must_use]
    pub fn mesh_unit(&self) -> MeshUnit {
        self.inner.mesh_unit()
    }

    #[must_use]
    pub fn get(&self, meshcode: &u32) -> Option<&Parameter> {
        self.inner.get(meshcode)
    }
}

impl<T> Transformer<T>
where
    T: ParameterData,
{
    /// Returns the statistics of the parameter.
    ///
    /// See [`StatisticData`] for details of result's components.
    ///
    /// # Example
    ///
    /// ```
    /// # use std::collections::HashMap;
    /// # use jgdtrans::*;
    /// #
    /// // from SemiDynaEXE2023.par
    /// let tf = Transformer::new(
    ///     ParData::new(
    ///         Format::SemiDynaEXE,
    ///         HashMap::from([
    ///             (54401005, Parameter::new(-0.00622, 0.01516, 0.0946)),
    ///             (54401055, Parameter::new(-0.0062, 0.01529, 0.08972)),
    ///             (54401100, Parameter::new(-0.00663, 0.01492, 0.10374)),
    ///             (54401150, Parameter::new(-0.00664, 0.01506, 0.10087)),
    ///         ])
    ///     )
    /// );
    ///
    /// let stats = tf.statistics();
    ///
    /// assert_eq!(stats.latitude.count, Some(4));
    /// assert_eq!(stats.latitude.mean, Some(-0.0064225));
    /// assert_eq!(stats.latitude.std, Some(0.019268673410486777));
    /// assert_eq!(stats.latitude.abs, Some(0.006422499999999999));
    /// assert_eq!(stats.latitude.min, Some(-0.00664));
    /// assert_eq!(stats.latitude.max, Some(-0.0062));
    /// ```
    #[must_use]
    pub fn statistics(&self) -> Statistics {
        let mut params = self.inner.to_vec();

        // Ensure summation order
        params.sort_by_key(|(k, _)| *k);

        let temp: Vec<_> = params.iter().map(|(_, p)| p.latitude).collect();
        let latitude = StatisticData::from_array(&temp);

        let temp: Vec<_> = params.iter().map(|(_, p)| p.longitude).collect();
        let longitude = StatisticData::from_array(&temp);

        let temp: Vec<_> = params.iter().map(|(_, p)| p.altitude).collect();
        let altitude = StatisticData::from_array(&temp);

        let temp: Vec<_> = params.iter().map(|(_, p)| p.horizontal()).collect();
        let horizontal = StatisticData::from_array(&temp);

        Statistics {
            latitude,
            longitude,
            altitude,
            horizontal,
        }
    }
}

impl<T> PartialEq for Transformer<T>
where
    T: PartialEq,
{
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.inner.eq(&other.inner)
    }
}

impl<T> Clone for Transformer<T>
where
    T: Clone,
{
    #[inline]
    fn clone(&self) -> Self {
        Self {
            inner: self.inner.clone(),
        }
    }

    #[inline]
    fn clone_from(&mut self, source: &Self) {
        self.inner.clone_from(&source.inner);
    }
}

#[cfg(test)]
mod test {
    use crate::TransformerBuilder;

    use super::*;

    mod test_ksum {
        use super::*;

        #[test]
        fn test_nan() {
            let actual = ksum(&[1., f64::NAN, 1.]);
            assert!(actual.is_nan());
        }
    }

    mod test_transformer {
        use super::*;

        #[allow(non_upper_case_globals)]
        const SemiDynaEXE: [(u32, (f64, f64, f64)); 4] = [
            (54401005, (-0.00622, 0.01516, 0.0946)),
            (54401055, (-0.0062, 0.01529, 0.08972)),
            (54401100, (-0.00663, 0.01492, 0.10374)),
            (54401150, (-0.00664, 0.01506, 0.10087)),
        ];

        #[test]
        fn test_stats() {
            let stats = TransformerBuilder::new()
                .format(Format::SemiDynaEXE)
                .parameters(SemiDynaEXE)
                .build()
                .statistics();

            assert_eq!(
                stats.latitude,
                StatisticData {
                    count: Some(4),
                    mean: Some(-0.0064225),
                    std: Some(0.019268673410486777),
                    abs: Some(0.006422499999999999),
                    min: Some(-0.00664),
                    max: Some(-0.0062)
                }
            );
            assert_eq!(
                stats.longitude,
                StatisticData {
                    count: Some(4),
                    mean: Some(0.0151075),
                    std: Some(0.045322702644480496),
                    abs: Some(0.0151075),
                    min: Some(0.01492),
                    max: Some(0.01529)
                }
            );
            assert_eq!(
                stats.altitude,
                StatisticData {
                    count: Some(4),
                    mean: Some(0.0972325),
                    std: Some(0.29174846730531423),
                    abs: Some(0.0972325),
                    min: Some(0.08972),
                    max: Some(0.10374)
                }
            );

            // Notes, horizontal (f64::hypot)
            // is an only non-exact operation in jgdtrans.
            assert_eq!(
                stats.horizontal,
                StatisticData {
                    count: Some(4),
                    mean: Some(if cfg!(target_os = "linux") {
                        0.016417802947905496
                    } else {
                        0.0164178029479055
                    }),
                    std: Some(if cfg!(target_os = "linux") {
                        0.04925345347374167
                    } else {
                        0.04925345347374168
                    }),
                    abs: Some(if cfg!(target_os = "linux") {
                        0.016417802947905496
                    } else {
                        0.0164178029479055
                    }),
                    min: Some(0.016326766366920303),
                    max: Some(0.016499215132847987)
                }
            );

            let stats = TransformerBuilder::new()
                .format(Format::TKY2JGD)
                .build()
                .statistics();
            assert_eq!(
                stats.latitude,
                StatisticData {
                    count: None,
                    mean: None,
                    std: None,
                    abs: None,
                    min: None,
                    max: None
                }
            );
            assert_eq!(
                stats.longitude,
                StatisticData {
                    count: None,
                    mean: None,
                    std: None,
                    abs: None,
                    min: None,
                    max: None
                }
            );
            assert_eq!(
                stats.altitude,
                StatisticData {
                    count: None,
                    mean: None,
                    std: None,
                    abs: None,
                    min: None,
                    max: None
                }
            );
            assert_eq!(
                stats.horizontal,
                StatisticData {
                    count: None,
                    mean: None,
                    std: None,
                    abs: None,
                    min: None,
                    max: None
                }
            );

            let stats = TransformerBuilder::new()
                .format(Format::SemiDynaEXE)
                .parameters([(54401005, (1., 0.0, f64::NAN))])
                .build()
                .statistics();

            assert_eq!(
                stats.latitude,
                StatisticData {
                    count: Some(1),
                    mean: Some(1.0),
                    std: Some(0.0),
                    abs: Some(1.0),
                    min: Some(1.0),
                    max: Some(1.0)
                }
            );
            assert_eq!(
                stats.longitude,
                StatisticData {
                    count: Some(1),
                    mean: Some(0.0),
                    std: Some(0.0),
                    abs: Some(0.0),
                    min: Some(0.0),
                    max: Some(0.0)
                }
            );
            assert_eq!(stats.altitude.count, Some(1));
            assert!(stats.altitude.mean.unwrap().is_nan());
            assert!(stats.altitude.std.unwrap().is_nan());
            assert!(stats.altitude.abs.unwrap().is_nan());
            assert!(stats.altitude.min.unwrap().is_nan());
            assert!(stats.altitude.max.unwrap().is_nan());
            assert_eq!(
                stats.horizontal,
                StatisticData {
                    count: Some(1),
                    mean: Some(1.0),
                    std: Some(0.0),
                    abs: Some(1.0),
                    min: Some(1.0),
                    max: Some(1.0)
                }
            );
        }
    }
}