mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-02 11:07:57 +00:00
145 lines
5.7 KiB
Python
145 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# @Author: Jean-Luc Auge
|
|
# @Date: 2018-02-02 14:06:55
|
|
|
|
from gnpy.core.elements import Edfa
|
|
import numpy as np
|
|
from json import load, dumps
|
|
import pytest
|
|
from gnpy.core.elements import Transceiver, Fiber, Edfa
|
|
from gnpy.core.utils import lin2db, db2lin
|
|
from gnpy.core.info import create_input_spectral_information, SpectralInformation, Channel, Power, Pref
|
|
from gnpy.core.equipment import load_equipment
|
|
from gnpy.core.network import build_network, load_network
|
|
from pathlib import Path
|
|
import filecmp
|
|
|
|
TEST_DIR = Path(__file__).parent
|
|
DATA_DIR = TEST_DIR / 'data'
|
|
test_network = DATA_DIR / 'test_network.json'
|
|
eqpt_library = DATA_DIR / 'eqpt_config.json'
|
|
|
|
# TODO in elements.py code: pytests doesn't pass with 1 channel: interpolate fail
|
|
@pytest.fixture(
|
|
params=[(96, 0.05e12), (60, 0.075e12), (45, 0.1e12), (2, 0.1e12)],
|
|
ids=['50GHz spacing', '75GHz spacing', '100GHz spacing', '2 channels'])
|
|
def nch_and_spacing(request):
|
|
"""parametrize channel count vs channel spacing (Hz)"""
|
|
yield request.param
|
|
|
|
@pytest.fixture()
|
|
def bw():
|
|
"""parametrize signal bandwidth (Hz)"""
|
|
return 45e9
|
|
|
|
@pytest.fixture()
|
|
def setup_edfa():
|
|
"""init edfa class by reading test_network.json file
|
|
remove all gain and nf ripple"""
|
|
# eqpt_library = pytest_eqpt_library()
|
|
equipment = load_equipment(eqpt_library)
|
|
network = load_network(test_network, equipment)
|
|
build_network(network, equipment=equipment)
|
|
edfa = [n for n in network.nodes() if isinstance(n, Edfa)][0]
|
|
|
|
#edfa.params.dgt = np.zeros(96)
|
|
# edfa.params.gain_ripple = np.zeros(96)
|
|
# edfa.params.nf_ripple = np.zeros(96)
|
|
edfa.gain_ripple = np.zeros(96)
|
|
edfa.interpol_nf_ripple = np.zeros(96)
|
|
yield edfa
|
|
|
|
@pytest.fixture()
|
|
def setup_trx():
|
|
"""init transceiver class to access snr and osnr calculations"""
|
|
equipment = load_equipment(eqpt_library)
|
|
network = load_network(test_network, equipment)
|
|
build_network(network, equipment=equipment)
|
|
trx = [n for n in network.nodes() if isinstance(n, Transceiver)][0]
|
|
return trx
|
|
|
|
@pytest.fixture()
|
|
def si(nch_and_spacing, bw):
|
|
"""parametrize a channel comb with nch, spacing and signal bw"""
|
|
nch, spacing = nch_and_spacing
|
|
return create_input_spectral_information(191.3e12, 0.15, bw, 1e-6, spacing, nch, 0)
|
|
|
|
@pytest.mark.parametrize("enabled", [True, False])
|
|
@pytest.mark.parametrize("gain, nf_expected", [(10, 15), (15, 10), (25, 5.8)])
|
|
def test_nf_calc(gain, nf_expected, enabled, setup_edfa, si):
|
|
""" compare the 2 amplifier models (polynomial and estimated from nf_min and max)
|
|
=> nf_model vs nf_poly_fit for boundary gain values: gain_min (and below) & gain_flatmax
|
|
same values are expected between the 2 models
|
|
=> unitary test for Edfa._calc_nf() (and Edfa.interpol_params)"""
|
|
# eqpt_lib()
|
|
edfa = setup_edfa
|
|
frequencies = np.array([c.frequency for c in si.carriers])
|
|
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
|
|
baud_rates = np.array([c.baud_rate for c in si.carriers])
|
|
edfa.operational.gain_target = gain
|
|
# edfa.params.nf_model_enabled = enabled
|
|
pref=Pref(0, 0)
|
|
edfa.interpol_params(frequencies, pin, baud_rates, pref)
|
|
|
|
assert pytest.approx(nf_expected) == edfa.nf[0]
|
|
|
|
@pytest.mark.parametrize("gain", [17, 19, 21, 23])
|
|
def test_compare_nf_models(gain, setup_edfa, si):
|
|
""" compare the 2 amplifier models (polynomial and estimated from nf_min and max)
|
|
=> nf_model vs nf_poly_fit for intermediate gain values:
|
|
between gain_min and gain_flatmax some discrepancy is expected but target < 0.5dB
|
|
=> unitary test for Edfa._calc_nf (and Edfa.interpol_params)"""
|
|
edfa = setup_edfa
|
|
frequencies = np.array([c.frequency for c in si.carriers])
|
|
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
|
|
baud_rates = np.array([c.baud_rate for c in si.carriers])
|
|
edfa.operational.gain_target = gain
|
|
# edfa.params.nf_model_enabled = True
|
|
pref=Pref(0, 0)
|
|
edfa.interpol_params(frequencies, pin, baud_rates, pref)
|
|
nf_model = edfa.nf[0]
|
|
|
|
# edfa.params.nf_model_enabled = False
|
|
edfa.interpol_params(frequencies, pin, baud_rates, pref)
|
|
nf_poly = edfa.nf[0]
|
|
assert pytest.approx(nf_model, abs=0.5) == nf_poly
|
|
|
|
def test_si(si, nch_and_spacing):
|
|
"""basic total power check of the channel comb generation"""
|
|
nch = nch_and_spacing[0]
|
|
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
|
|
p_tot = np.sum(pin)
|
|
expected_p_tot = si.carriers[0].power.signal * nch
|
|
assert pytest.approx(expected_p_tot) == p_tot
|
|
|
|
@pytest.mark.parametrize("gain", [13, 15, 17, 19, 21, 23, 25, 27])
|
|
def test_ase_noise(gain, si, setup_edfa, setup_trx, bw):
|
|
"""testing 3 different ways of calculating osnr:
|
|
1-pin-edfa.nf+58 vs
|
|
2-pout/pase afet propagate
|
|
3-Transceiver osnr_ase_01nm
|
|
=> unitary test for Edfa.noise_profile (Edfa.interpol_params, Edfa.propagate)"""
|
|
edfa = setup_edfa
|
|
frequencies = np.array([c.frequency for c in si.carriers])
|
|
pin = np.array([c.power.signal+c.power.nli+c.power.ase for c in si.carriers])
|
|
baud_rates = np.array([c.baud_rate for c in si.carriers])
|
|
edfa.operational.gain_target = gain
|
|
# edfa.params.nf_model_enabled = False
|
|
pref=Pref(0, 0)
|
|
edfa.interpol_params(frequencies, pin, baud_rates, pref)
|
|
nf = edfa.nf
|
|
pin = lin2db(pin[0]*1e3)
|
|
osnr_expected = pin - nf[0] + 58
|
|
|
|
si = edfa(si)
|
|
pout = np.array([c.power.signal for c in si.carriers])
|
|
pase = np.array([c.power.ase for c in si.carriers])
|
|
osnr = lin2db(pout[0] / pase[0]) - lin2db(12.5e9/bw)
|
|
assert pytest.approx(osnr_expected, abs=0.01) == osnr
|
|
|
|
trx = setup_trx
|
|
si = trx(si)
|
|
osnr = trx.osnr_ase_01nm[0]
|
|
assert pytest.approx(osnr_expected, abs=0.01) == osnr
|