From aa5cc33d3e0ca07b70da18ef956f62567bcdcee6 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Bayle <j2b.bayle@gmail.com>
Date: Fri, 10 Jun 2022 17:33:44 +0200
Subject: [PATCH] Add unit tests for MPRs ambiguity

---
 tests/test_ranging.py | 69 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100755 tests/test_ranging.py

diff --git a/tests/test_ranging.py b/tests/test_ranging.py
new file mode 100755
index 0000000..8792992
--- /dev/null
+++ b/tests/test_ranging.py
@@ -0,0 +1,69 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# pylint: disable=missing-module-docstring
+
+import numpy as np
+from pytest import approx
+from lisainstrument import Instrument
+from lisaconstants import c
+
+
+def test_no_prn_ambiguity():
+    """Test that we can use MPRs without ambiguities."""
+
+    pprs = {
+        '12': 8.33242295, '23': 8.30282196, '31': 8.33242298,
+        '13': 8.33159404, '32': 8.30446786, '21': 8.33159402,
+    }
+
+    instru = Instrument(size=100, prn_ambiguity=None, orbits=pprs)
+    assert instru.prn_ambiguity is None
+    instru.disable_clock_noises()
+    instru.disable_ranging_noises()
+    instru.simulate()
+    for mosa in instru.MOSAS:
+        assert instru.mprs[mosa][50:] == approx(pprs[mosa])
+
+    # Setting `prn_ambiguity` to 0 is equivalent to using `None`
+    instru = Instrument(size=100, prn_ambiguity=0)
+    assert instru.prn_ambiguity is None
+
+def test_prn_ambiguity_with_static_orbits():
+    """Test that MPRs follow PRN cycle length for static orbits."""
+
+    pprs = {
+        '12': 8.33242295, '23': 8.30282196, '31': 8.33242298,
+        '13': 8.33159404, '32': 8.30446786, '21': 8.33159402,
+    }
+
+    instru = Instrument(size=100, prn_ambiguity=300E3)
+    assert instru.prn_ambiguity == approx(300E3)
+    instru.disable_clock_noises()
+    instru.disable_ranging_noises()
+    instru.simulate()
+    for mosa in instru.MOSAS:
+        assert instru.mprs[mosa][50:] == approx(pprs[mosa] % (300E3 / c))
+
+    instru = Instrument(size=100, prn_ambiguity=100E3)
+    assert instru.prn_ambiguity == approx(100E3)
+    instru.disable_clock_noises()
+    instru.disable_ranging_noises()
+    instru.simulate()
+    for mosa in instru.MOSAS:
+        assert instru.mprs[mosa][50:] == approx(pprs[mosa] % (100E3 / c))
+
+def test_prn_ambiguity_with_esa_orbits():
+    """Test that MPRs are below ambiguity for realistic orbits."""
+
+    instru = Instrument(
+        size=100, dt=2E5,
+        prn_ambiguity=300E3,
+        aafilter=None, physics_upsampling=1,
+        orbits='tests/esa-trailing-orbits-2-0-dev.h5')
+
+    instru.disable_clock_noises()
+    instru.disable_ranging_noises()
+    instru.simulate()
+
+    for mosa in instru.MOSAS:
+        assert np.all(instru.mprs[mosa][50:] <= 300E3 / c)
-- 
GitLab