|
12 | 12 |
|
13 | 13 | import pytest |
14 | 14 | from numpy import array, zeros, ones, linspace |
15 | | -from numpy.testing import assert_array_equal |
| 15 | +from numpy.testing import assert_array_equal, assert_allclose |
16 | 16 | from gnpy.core.info import create_arbitrary_spectral_information, create_input_spectral_information |
17 | 17 | from gnpy.core.exceptions import SpectrumError |
18 | | -from gnpy.core.utils import dbm2watt |
| 18 | +from gnpy.core.utils import dbm2watt, watt2dbm |
19 | 19 |
|
20 | 20 |
|
21 | 21 | def test_create_arbitrary_spectral_information(): |
@@ -142,3 +142,43 @@ def test_spectral_information_add(): |
142 | 142 | assert_array_equal(si_c_plus_l.channel_number, si_l_plus_c.channel_number) |
143 | 143 | assert_array_equal(si_c_plus_l.number_of_channels, si_l_plus_c.number_of_channels) |
144 | 144 | assert_array_equal(si_c_plus_l.df, si_l_plus_c.df) |
| 145 | + |
| 146 | + |
| 147 | +def test_spectral_information_total_power(): |
| 148 | + """ |
| 149 | + Testing Spectral Information total power computation method. |
| 150 | + """ |
| 151 | + |
| 152 | + tol_lin = 1e-6 |
| 153 | + tol_db = 1e-3 |
| 154 | + |
| 155 | + tx_power = 0.001 |
| 156 | + si = create_input_spectral_information(f_min=191.5e12, f_max=196e12, baud_rate=32e9, spacing=50e9, roll_off=0.1, |
| 157 | + tx_osnr=40.0, tx_power=tx_power) |
| 158 | + |
| 159 | + # Assuming that there is no noise, pch coincides with signal total power |
| 160 | + assert_allclose(sum(si.pch), si.ptot, atol=tol_lin, rtol=0.0) |
| 161 | + assert_allclose(watt2dbm(sum(si.pch)), si.ptot_dbm, atol=tol_db, rtol=0.0) |
| 162 | + assert_allclose(watt2dbm(sum(si.signal)), si.ptot_dbm, atol=tol_db, rtol=0.0) |
| 163 | + |
| 164 | + # Injection of ASE increases total power |
| 165 | + add_ase = tx_power / 100 |
| 166 | + ptot_add_ase = sum(si.pch + add_ase) |
| 167 | + si.add_ase(add_ase) |
| 168 | + |
| 169 | + assert_allclose(watt2dbm(sum(si.pch)), si.ptot_dbm, atol=tol_db, rtol=0.0) |
| 170 | + assert_allclose(watt2dbm(ptot_add_ase), si.ptot_dbm, atol=tol_db, rtol=0.0) |
| 171 | + |
| 172 | + si_sum_signal_expected = 0.09000000000000007 |
| 173 | + assert_allclose(watt2dbm(sum(si.signal)), watt2dbm(si_sum_signal_expected), atol=tol_db, rtol=0.0) |
| 174 | + |
| 175 | + # Injection of NLI does not change total power (only power transfer from pch to nli) |
| 176 | + add_nli = tx_power / 200 |
| 177 | + ptot_before_add_nli_dbm = si.ptot_dbm |
| 178 | + si.add_nli(add_nli) |
| 179 | + |
| 180 | + assert_allclose(watt2dbm(sum(si.pch)), si.ptot_dbm, atol=tol_db, rtol=0.0) |
| 181 | + assert_allclose(ptot_before_add_nli_dbm, si.ptot_dbm, atol=tol_db, rtol=0.0) |
| 182 | + |
| 183 | + si_sum_signal_expected = 0.08955445544554462 |
| 184 | + assert_allclose(watt2dbm(sum(si.signal)), watt2dbm(si_sum_signal_expected), atol=tol_db, rtol=0.0) |
0 commit comments