Skip to content

Commit

Permalink
Fix frequency scaling for fiber
Browse files Browse the repository at this point in the history
- wrong parameter was used in parameter
- error message could not read 0-dimensional arrey for 0 and -1 element
- add a test that makes use of the feature

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
Change-Id: Id7f6d6766d5b91a4b9410ad23aaa5e472b8ebb6f
  • Loading branch information
EstherLerouzic committed Jan 16, 2024
1 parent 05e3011 commit 5481b93
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
11 changes: 9 additions & 2 deletions gnpy/core/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,17 @@ def interpolate_parameter_over_spectrum(self, parameter, ref_frequency, spectrum
interpolation = interp1d(ref_frequency, parameter)(spectrum_frequency)
return interpolation
except ValueError:
try:
start = spectrum_frequency[0]
stop = spectrum_frequency[-1]
except IndexError:
# when frequency is a 0-dimensionnal array
start = spectrum_frequency
stop = spectrum_frequency
raise SpectrumError('The spectrum bandwidth exceeds the frequency interval used to define the fiber '
f'{name} in "{type(self).__name__} {self.uid}".'
f'\nSpectrum f_min-f_max: {round(spectrum_frequency[0] * 1e-12, 2)}-'
f'{round(spectrum_frequency[-1] * 1e-12, 2)}'
f'\nSpectrum f_min-f_max: {round(start * 1e-12, 2)}-'
f'{round(stop * 1e-12, 2)}'
f'\n{name} f_min-f_max: {round(ref_frequency[0] * 1e-12, 2)}-'
f'{round(ref_frequency[-1] * 1e-12, 2)}')

Expand Down
4 changes: 2 additions & 2 deletions gnpy/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def __init__(self, **kwargs):
# Chromatic Dispersion
if 'dispersion_per_frequency' in kwargs:
# Frequency-dependent dispersion
self._dispersion = asarray(kwargs['dispersion']['value']) # s/m/m
self._f_dispersion_ref = asarray(kwargs['dispersion']['frequency']) # Hz
self._dispersion = asarray(kwargs['dispersion_per_frequency']['value']) # s/m/m
self._f_dispersion_ref = asarray(kwargs['dispersion_per_frequency']['frequency']) # Hz
self._dispersion_slope = None
elif 'dispersion' in kwargs:
# Single value dispersion
Expand Down
69 changes: 65 additions & 4 deletions tests/test_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
# @Date: 2018-02-02 14:06:55

import pytest

from pathlib import Path
from networkx import dijkstra_path
from numpy import mean, sqrt, ones
import re

from gnpy.core.exceptions import SpectrumError
from gnpy.core.elements import Transceiver, Fiber, Edfa, Roadm
from gnpy.core.utils import db2lin
from gnpy.core.info import create_input_spectral_information
from gnpy.core.network import build_network
from gnpy.tools.json_io import load_network, load_equipment
from pathlib import Path
from networkx import dijkstra_path
from numpy import mean, sqrt, ones
from gnpy.tools.json_io import load_network, load_equipment, network_from_json


network_file_name = Path(__file__).parent.parent / 'tests/LinkforTest.json'
eqpt_library_name = Path(__file__).parent.parent / 'tests/data/eqpt_config.json'
Expand Down Expand Up @@ -125,6 +130,62 @@ def test_dgd(dgd_test, dest):
assert pmd == pytest.approx(expected_pmd)


def wrong_element_propagate():
"""
"""
data = []
data.append({
"error": SpectrumError,
"json_data": {
"elements": [{
"uid": "Elem",
"type": "Fiber",
"type_variety": "SSMF",
"params": {
"dispersion_per_frequency": {
"frequency": [
185.49234135667396e12,
186.05251641137855e12,
188.01312910284463e12,
189.99124726477024e12],
"value": [
1.60e-05,
1.67e-05,
1.7e-05,
1.8e-05]
},
"length": 1.02,
"loss_coef": 2.85,
"length_units": "km",
"att_in": 0.0,
"con_in": 0.0,
"con_out": 0.0
}
}],
"connections": []
},
"expected_msg": 'The spectrum bandwidth exceeds the frequency interval used to define the fiber Chromatic '
+ 'Dispersion in "Fiber Elem".\nSpectrum f_min-f_max: 191.35-196.1\nChromatic Dispersion '
+ 'f_min-f_max: 185.49-189.99'
})
return data


@pytest.mark.parametrize('error, json_data, expected_msg',
[(e['error'], e['json_data'], e['expected_msg']) for e in wrong_element_propagate()])
def test_json_element(error, json_data, expected_msg):
"""
Check that a missing key is correctly raisong the logger
"""
equipment = load_equipment(eqpt_library_name)
network = network_from_json(json_data, equipment)
elem = next(e for e in network.nodes() if e.uid == 'Elem')
si = create_input_spectral_information(f_min=191.3e12, f_max=196.1e12, roll_off=0.15,
baud_rate=32e9, power=1.0e-3, spacing=50.0e9, tx_osnr=45)
with pytest.raises(error, match=re.escape(expected_msg)):
_ = elem(si)


if __name__ == '__main__':
from logging import getLogger, basicConfig, INFO
logger = getLogger(__name__)
Expand Down

0 comments on commit 5481b93

Please sign in to comment.