Add a -spectrum option to input external file to define spectrum

The option is only set for gnpy-transmission-main.

The spectrum file is a list of of spectrum objects, each defining
fmin, fmax and spectrum attributes using the same definition as SI
in eqpt_config.json. the object list should be contiguous spectrum
definitions and not overlapping. For now, I have not integrated the
possibility to directly use transceivers type and mode in the list.
user can define sets of contiguous channels and a label to identify
the spectrum bands. If no label are defined, th program justs uses
the index + baud rate of the spectrum bands as label.

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
Change-Id: Ibc01e59e461e5e933e95d23dacbc5289e275ccf7
This commit is contained in:
EstherLerouzic
2021-08-05 14:34:13 +02:00
parent e851220f81
commit 4b94481ecb
4 changed files with 82 additions and 11 deletions

View File

@@ -15,6 +15,8 @@ import sys
from math import ceil
from numpy import linspace, mean
from pathlib import Path
from copy import deepcopy
import gnpy.core.ansi_escapes as ansi_escapes
from gnpy.core.elements import Transceiver, Fiber, RamanFiber
from gnpy.core.equipment import trx_mode_params
@@ -25,10 +27,11 @@ from gnpy.core.utils import db2lin, lin2db, automatic_nch
from gnpy.topology.request import (ResultElement, jsontocsv, compute_path_dsjctn, requests_aggregation,
BLOCKING_NOPATH, correct_json_route_list,
deduplicate_disjunctions, compute_path_with_disjunction,
PathRequest, compute_constrained_path, propagate)
PathRequest, compute_constrained_path, propagate, update_spectrum_power)
from gnpy.topology.spectrum_assignment import build_oms_list, pth_assign_spectrum
from gnpy.tools.json_io import load_equipment, load_network, load_json, load_requests, save_network, \
requests_from_json, disjunctions_from_json, save_json
requests_from_json, disjunctions_from_json, save_json, load_initial_spectrum,\
_spectrum_from_json
from gnpy.tools.plots import plot_baseline, plot_results
_logger = logging.getLogger(__name__)
@@ -118,6 +121,7 @@ def transmission_main_example(args=None):
parser.add_argument('-pl', '--plot', action='store_true')
parser.add_argument('-l', '--list-nodes', action='store_true', help='list all transceiver nodes')
parser.add_argument('-po', '--power', default=0, help='channel ref power in dBm')
parser.add_argument('-spectrum', '--mixed-rate-spectrum-file', help='user defined mixed rate spectrum json file')
parser.add_argument('source', nargs='?', help='source node')
parser.add_argument('destination', nargs='?', help='destination node')
@@ -195,7 +199,13 @@ def transmission_main_example(args=None):
trx_params['power'] = db2lin(float(args.power)) * 1e-3
params.update(trx_params)
req = PathRequest(**params)
if args.mixed_rate_spectrum_file:
req.initial_spectrum = load_initial_spectrum(args.mixed_rate_spectrum_file, equipment)
print('warning: user input for spectrum used for propagation instead of SI')
nb_channels = len(req.initial_spectrum)
else:
nb_channels = req.nb_channel
print(f'There are {nb_channels} channels propagating')
power_mode = equipment['Span']['default'].power_mode
print('\n'.join([f'Power mode is set to {power_mode}',
f'=> it can be modified in eqpt_config.json - Span']))
@@ -226,8 +236,20 @@ def transmission_main_example(args=None):
power_range = list(linspace(p_start, p_stop, p_num))
except TypeError:
print('invalid power range definition in eqpt_config, should be power_range_db: [lower, upper, step]')
if hasattr(req, 'initial_spectrum'):
record_intial_spectrum = req.initial_spectrum
for dp_db in power_range:
req.power = db2lin(pref_ch_db + dp_db) * 1e-3
# if initial spectrum did not contain any power, now we need to use this one.
# note the initial power defines a differential wrt req.power so that if req.power is set to 2mW (3dBm)
# and initial spectrum was set to 0, this sets a initial per channel delta power to -3dB, so that
# whatever the equalization, -3 dB is applied on all channels (ie initial power in initial spectrum pre-empts
# pow option)
if hasattr(req, 'initial_spectrum'):
# without deepcopy, the previous dp setting is recorded as a user defined and spectrum is not properly
# updated for the power sweep dp_db
req.initial_spectrum = deepcopy(record_intial_spectrum)
update_spectrum_power(req)
if power_mode:
print(f'\nPropagating with input power = {ansi_escapes.cyan}{lin2db(req.power*1e3):.2f} dBm{ansi_escapes.reset}:')
else: