Files
oopt-gnpy/tests/test_science_utils.py
AndreaDAmico 9a7f94a391 cleaning: minor changes and specific numpy imports in utils and science_utils.
Change-Id: I57cd9075dd0a523a90131fbd8747519cf6554900
2020-11-19 14:57:57 +00:00

49 lines
1.9 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: Alessio Ferrari
"""
Checks that RamanFiber propagates properly the spectral information. In this way, also the RamanSolver and the NliSolver
are tested.
"""
from pathlib import Path
from pandas import read_csv
from numpy.testing import assert_allclose
from gnpy.core.info import create_input_spectral_information
from gnpy.core.elements import RamanFiber
from gnpy.core.parameters import SimParams
from gnpy.core.science_utils import Simulation
from gnpy.tools.json_io import load_json
TEST_DIR = Path(__file__).parent
def test_raman_fiber():
""" Test the accuracy of propagating the RamanFiber."""
# spectral information generation
power = 1e-3
eqpt_params = load_json(TEST_DIR / 'data' / 'eqpt_config.json')
spectral_info_params = eqpt_params['SI'][0]
spectral_info_params.pop('power_dbm')
spectral_info_params.pop('power_range_db')
spectral_info_params.pop('tx_osnr')
spectral_info_params.pop('sys_margins')
spectral_info_input = create_input_spectral_information(power=power, **spectral_info_params)
sim_params = SimParams(**load_json(TEST_DIR / 'data' / 'sim_params.json'))
Simulation.set_params(sim_params)
fiber = RamanFiber(**load_json(TEST_DIR / 'data' / 'raman_fiber_config.json'))
# propagation
spectral_info_out = fiber(spectral_info_input)
p_signal = [carrier.power.signal for carrier in spectral_info_out.carriers]
p_ase = [carrier.power.ase for carrier in spectral_info_out.carriers]
p_nli = [carrier.power.nli for carrier in spectral_info_out.carriers]
expected_results = read_csv(TEST_DIR / 'data' / 'test_science_utils_expected_results.csv')
assert_allclose(p_signal, expected_results['signal'], rtol=1e-3)
assert_allclose(p_ase, expected_results['ase'], rtol=1e-3)
assert_allclose(p_nli, expected_results['nli'], rtol=1e-3)