gnpy.tools

Processing of data via json_io. Utilities for Excel conversion in convert and service_sheet. Example code in cli_examples and plots.

gnpy.tools.cli_examples

Common code for CLI examples

gnpy.tools.cli_examples._add_common_options(parser: ArgumentParser, network_default: Path)
gnpy.tools.cli_examples._path_result_json(pathresult)
gnpy.tools.cli_examples._setup_logging(args)
gnpy.tools.cli_examples.load_common_data(equipment_filename, topology_filename, simulation_filename, save_raw_network_filename)

Load common configuration from JSON files

gnpy.tools.cli_examples.path_requests_run(args=None)
gnpy.tools.cli_examples.show_example_data_dir()
gnpy.tools.cli_examples.transmission_main_example(args=None)

gnpy.tools.convert

This module contains utilities for converting between XLS and JSON.

The input XLS file must contain sheets named “Nodes” and “Links”. It may optionally contain a sheet named “Eqpt”.

In the “Nodes” sheet, only the “City” column is mandatory. The column “Type” can be determined automatically given the topology (e.g., if degree 2, ILA; otherwise, ROADM.) Incorrectly specified types (e.g., ILA for node of degree ≠ 2) will be automatically corrected.

In the “Links” sheet, only the first three columns (“Node A”, “Node Z” and “east Distance (km)”) are mandatory. Missing “west” information is copied from the “east” information so that it is possible to input undirected data.

class gnpy.tools.convert.Eqpt(**kwargs)

Bases: object

default_values = {'east_amp_dp': None, 'east_amp_gain': None, 'east_amp_type': '', 'east_att_in': 0, 'east_att_out': None, 'east_tilt_vs_wavelength': 0, 'from_city': '', 'to_city': ''}
update_attr(kwargs)

Bases: object

attribtes from west parse_ept_headers dict +node_a, node_z, west_fiber_con_in, east_fiber_con_in

default_values = {'east_cable': '', 'east_con_in': None, 'east_con_out': None, 'east_distance': 80, 'east_fiber': 'SSMF', 'east_lineic': 0.2, 'east_pmd': 0.1, 'from_city': '', 'to_city': ''}
update_attr(kwargs)
class gnpy.tools.convert.Node(**kwargs)

Bases: object

default_values = {'booster_restriction': '', 'city': '', 'country': '', 'latitude': 0, 'longitude': 0, 'node_type': 'ILA', 'preamp_restriction': '', 'region': '', 'state': ''}
update_attr(kwargs)
class gnpy.tools.convert.Roadm(**kwargs)

Bases: object

default_values = {'from_node': '', 'target_pch_out_db': None, 'to_node': ''}
update_attr(kwargs)
gnpy.tools.convert._do_convert()
gnpy.tools.convert._format_items(items)
gnpy.tools.convert.all_rows(sh, start=0)
gnpy.tools.convert.connect_eqpt(from_, in_, to_)
gnpy.tools.convert.convert_file(input_filename, filter_region=[], output_json_file_name=None)
gnpy.tools.convert.corresp_names(input_filename, network)

a function that builds the correspondance between names given in the excel, and names used in the json, and created by the autodesign. All names are listed

gnpy.tools.convert.corresp_next_node(network, corresp_ila, corresp_roadm)

for each name in corresp dictionnaries find the next node in network and its name given by user in excel. for meshTopology_exampleV2.xls: user ILA name Stbrieuc covers the two direction. convert.py creates 2 different ILA with possible names (depending on the direction and if the eqpt was defined in eqpt sheet) - east edfa in Stbrieuc to Rennes_STA - west edfa in Stbrieuc to Rennes_STA - Edfa0_fiber (Lannion_CAS → Stbrieuc)-F056 - Edfa0_fiber (Rennes_STA → Stbrieuc)-F057 next_nodes finds the user defined name of next node to be able to map the path constraints - east edfa in Stbrieuc to Rennes_STA next node = Rennes_STA - west edfa in Stbrieuc to Rennes_STA next node Lannion_CAS

Edfa0_fiber (Lannion_CAS → Stbrieuc)-F056 and Edfa0_fiber (Rennes_STA → Stbrieuc)-F057 do not exist the function supports fiber splitting, fused nodes and shall only be called if excel format is used for both network and service

gnpy.tools.convert.create_east_eqpt_element(node)

create amplifiers json elements for the east direction. this includes the case where the case of a fused element defined instead of an ILA in eqpt sheet

gnpy.tools.convert.create_roadm_element(node, roadms_by_city)

create the json element for a roadm node, including the different cases: - if there are restrictions - if there are per degree target power defined on a direction direction is defined by the booster name, so that booster must also be created in eqpt sheet if the direction is defined in roadm

gnpy.tools.convert.create_west_eqpt_element(node)

create amplifiers json elements for the west direction. this includes the case where the case of a fused element defined instead of an ILA in eqpt sheet

gnpy.tools.convert.eqpt_connection_by_city(city_name)
gnpy.tools.convert.eqpt_in_city_to_city(in_city, to_city, direction='east')
gnpy.tools.convert.fiber_dest_from_source(city_name)
gnpy.tools.convert.midpoint(city_a, city_b)
gnpy.tools.convert.parse_excel(input_filename)
gnpy.tools.convert.parse_headers(my_sheet, input_headers_dict, headers, start_line, slice_in)

return a dict of header_slice key = column index value = header name

gnpy.tools.convert.parse_row(row, headers)
gnpy.tools.convert.parse_sheet(my_sheet, input_headers_dict, header_line, start_line, column)
gnpy.tools.convert.read_header(my_sheet, line, slice_)

return the list of headers !:= ‘’ header_i = [(header, header_column_index), …] in a {line, slice1_x, slice_y} range

gnpy.tools.convert.read_slice(my_sheet, line, slice_, header)

return the slice range of a given header in a defined range {line, slice_x, slice_y}

gnpy.tools.convert.sanity_check(nodes, links, nodes_by_city, links_by_city, eqpts_by_city)
gnpy.tools.convert.xls_to_json_data(input_filename, filter_region=[])

gnpy.tools.json_io

Loading and saving data from JSON files in GNPy’s internal data format

class gnpy.tools.json_io.Amp(**kwargs)

Bases: _JsonThing

default_values = {'advance_configurations_from_json': None, 'allowed_for_design': False, 'bands': [], 'booster_variety': None, 'dgt': None, 'dual_stage_model': None, 'f_max': 196100000000000.0, 'f_min': 191300000000000.0, 'f_ripple_ref': None, 'gain_flatmax': None, 'gain_min': None, 'gain_ripple': 0, 'multi_band': None, 'nf0': None, 'nf_coef': None, 'nf_fit_coeff': None, 'nf_max': None, 'nf_min': None, 'nf_model': None, 'nf_ripple': 0, 'out_voa_auto': False, 'p_max': None, 'pdl': 0, 'pmd': 0, 'preamp_variety': None, 'raman': False, 'tilt_ripple': 0, 'type_def': '', 'type_variety': ''}
classmethod from_json(filename, **kwargs)
class gnpy.tools.json_io.Fiber(**kwargs)

Bases: _JsonThing

default_values = {'dispersion': None, 'effective_area': None, 'pmd_coef': 0, 'type_variety': ''}
class gnpy.tools.json_io.Model_dual_stage(preamp_variety, booster_variety)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('preamp_variety', 'booster_variety')
classmethod _make(iterable)

Make a new Model_dual_stage object from a sequence or iterable

_replace(**kwds)

Return a new Model_dual_stage object replacing specified fields with new values

booster_variety

Alias for field number 1

preamp_variety

Alias for field number 0

class gnpy.tools.json_io.Model_fg(nf0)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('nf0',)
classmethod _make(iterable)

Make a new Model_fg object from a sequence or iterable

_replace(**kwds)

Return a new Model_fg object replacing specified fields with new values

nf0

Alias for field number 0

class gnpy.tools.json_io.Model_hybrid(nf_ram, gain_ram, edfa_variety)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('nf_ram', 'gain_ram', 'edfa_variety')
classmethod _make(iterable)

Make a new Model_hybrid object from a sequence or iterable

_replace(**kwds)

Return a new Model_hybrid object replacing specified fields with new values

edfa_variety

Alias for field number 2

gain_ram

Alias for field number 1

nf_ram

Alias for field number 0

class gnpy.tools.json_io.Model_openroadm_booster

Bases: object

class gnpy.tools.json_io.Model_openroadm_ila(nf_coef)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('nf_coef',)
classmethod _make(iterable)

Make a new Model_openroadm_ila object from a sequence or iterable

_replace(**kwds)

Return a new Model_openroadm_ila object replacing specified fields with new values

nf_coef

Alias for field number 0

class gnpy.tools.json_io.Model_openroadm_preamp

Bases: object

class gnpy.tools.json_io.Model_vg(nf1, nf2, delta_p, orig_nf_min, orig_nf_max)

Bases: tuple

_asdict()

Return a new dict which maps field names to their values.

_field_defaults = {}
_fields = ('nf1', 'nf2', 'delta_p', 'orig_nf_min', 'orig_nf_max')
classmethod _make(iterable)

Make a new Model_vg object from a sequence or iterable

_replace(**kwds)

Return a new Model_vg object replacing specified fields with new values

delta_p

Alias for field number 2

nf1

Alias for field number 0

nf2

Alias for field number 1

orig_nf_max

Alias for field number 4

orig_nf_min

Alias for field number 3

class gnpy.tools.json_io.RamanFiber(**kwargs)

Bases: Fiber

class gnpy.tools.json_io.Roadm(**kwargs)

Bases: _JsonThing

default_values = {'add_drop_osnr': 100, 'pdl': 0, 'pmd': 0, 'restrictions': {'booster_variety_list': [], 'preamp_variety_list': []}, 'roadm-path-impairments': [], 'type_variety': 'default'}
class gnpy.tools.json_io.SI(**kwargs)

Bases: _JsonThing

default_values = {'baud_rate': 32000000000.0, 'f_max': 196100000000000.0, 'f_min': 191350000000000.0, 'power_dbm': 0, 'power_range_db': [0, 0, 0.5], 'roll_off': 0.15, 'spacing': 50000000000.0, 'sys_margins': 0, 'tx_osnr': 45, 'tx_power_dbm': None}
class gnpy.tools.json_io.Span(**kwargs)

Bases: _JsonThing

default_values = {'EOL': 0, 'con_in': 0, 'con_out': 0, 'delta_power_range_db': None, 'length_units': 'km', 'max_fiber_lineic_loss_for_raman': 0.25, 'max_length': 150, 'max_loss': None, 'padding': 10, 'power_mode': True, 'target_extended_gain': 2.5}
class gnpy.tools.json_io.Transceiver(**kwargs)

Bases: _JsonThing

default_values = {'frequency': None, 'mode': {}, 'type_variety': None}
class gnpy.tools.json_io._JsonThing

Bases: object

update_attr(default_values, kwargs, name)
gnpy.tools.json_io._automatic_spacing(baud_rate)

return the min possible channel spacing for a given baud rate

gnpy.tools.json_io._check_fiber_vs_raman_fiber(equipment)

Ensure that Fiber and RamanFiber with the same name define common properties equally

gnpy.tools.json_io._check_one_request(params, f_max_from_si)

Checks that the requested parameters are consistant (spacing vs nb channel vs transponder mode…)

gnpy.tools.json_io._cls_for(equipment_type)
gnpy.tools.json_io._equipment_from_json(json_data, filename)

build global dictionnary eqpt_library that stores all eqpt characteristics: edfa type type_variety, fiber type_variety from the eqpt_config.json (filename parameter) also read advanced_config_from_json file parameters for edfa if they are available: typically nf_ripple, dfg gain ripple, dgt and nf polynomial nf_fit_coeff if advanced_config_from_json file parameter is not present: use nf_model: requires nf_min and nf_max values boundaries of the edfa gain range

gnpy.tools.json_io._roadm_restrictions_sanity_check(equipment)

verifies that booster and preamp restrictions specified in roadm equipment are listed in the edfa.

gnpy.tools.json_io._spectrum_from_json(json_data)

JSON_data is a list of spectrum partitions each with {f_min, f_max, baud_rate, roll_off, delta_pdb, slot_width, tx_osnr, label} Creates the per freq Carrier’s dict. f_min, f_max, baud_rate, slot_width and roll_off are mandatory label, tx_osnr and delta_pdb are created if not present label should be different for each partition >>> json_data = {‘spectrum’: [{‘f_min’: 193.2e12, ‘f_max’: 193.4e12, ‘slot_width’: 50e9, ‘baud_rate’: 32e9, ‘roll_off’: 0.15, ‘delta_pdb’: 1, ‘tx_osnr’: 45, ‘tx_power_dbm’: -7}, {‘f_min’: 193.4625e12, ‘f_max’: 193.9875e12, ‘slot_width’: 75e9, ‘baud_rate’: 64e9, ‘roll_off’: 0.15}, {‘f_min’: 194.075e12, ‘f_max’: 194.075e12, ‘slot_width’: 100e9, ‘baud_rate’: 90e9, ‘roll_off’: 0.15}, {‘f_min’: 194.2e12, ‘f_max’: 194.35e12, ‘slot_width’: 50e9, ‘baud_rate’: 32e9, ‘roll_off’: 0.15}]} >>> spectrum = _spectrum_from_json(json_data[‘spectrum’]) >>> for k, v in spectrum.items(): … print(f’{k}: {v}’) … 193200000000000.0: Carrier(delta_pdb=1, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=45, tx_power=0.00019952623149688798, label=’0-32.00G’) 193250000000000.0: Carrier(delta_pdb=1, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=45, tx_power=0.00019952623149688798, label=’0-32.00G’) 193300000000000.0: Carrier(delta_pdb=1, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=45, tx_power=0.00019952623149688798, label=’0-32.00G’) 193350000000000.0: Carrier(delta_pdb=1, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=45, tx_power=0.00019952623149688798, label=’0-32.00G’) 193400000000000.0: Carrier(delta_pdb=1, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=45, tx_power=0.00019952623149688798, label=’0-32.00G’) 193462500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 193537500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 193612500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 193687500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 193762500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 193837500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 193912500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 193987500000000.0: Carrier(delta_pdb=0, baud_rate=64000000000.0, slot_width=75000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’1-64.00G’) 194075000000000.0: Carrier(delta_pdb=0, baud_rate=90000000000.0, slot_width=100000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’2-90.00G’) 194200000000000.0: Carrier(delta_pdb=0, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’3-32.00G’) 194250000000000.0: Carrier(delta_pdb=0, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’3-32.00G’) 194300000000000.0: Carrier(delta_pdb=0, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’3-32.00G’) 194350000000000.0: Carrier(delta_pdb=0, baud_rate=32000000000.0, slot_width=50000000000.0, roll_off=0.15, tx_osnr=40, tx_power=0.001, label=’3-32.00G’)

gnpy.tools.json_io._update_dual_stage(equipment)
gnpy.tools.json_io.convert_service_sheet(input_filename, eqpt, network, network_filename=None, output_filename='', bidir=False)
gnpy.tools.json_io.disjunctions_from_json(json_data)

reads the disjunction requests from the json dict and create the list of requested disjunctions for this set of requests

gnpy.tools.json_io.find_equalisation(params, equalization_types)

Find the equalization(s) defined in params. params can be a dict or a Roadm object.

>>> roadm = {'add_drop_osnr': 100, 'pmd': 1, 'pdl': 0.5,
...     'restrictions': {'preamp_variety_list': ['a'], 'booster_variety_list': ['b']},
...     'target_psd_out_mWperGHz': 4e-4}
>>> equalization_types = ['target_pch_out_db', 'target_psd_out_mWperGHz']
>>> find_equalisation(roadm, equalization_types)
{'target_pch_out_db': False, 'target_psd_out_mWperGHz': True}
gnpy.tools.json_io.load_equipment(filename)
gnpy.tools.json_io.load_initial_spectrum(filename)
gnpy.tools.json_io.load_json(filename)
gnpy.tools.json_io.load_network(filename, equipment)
gnpy.tools.json_io.load_requests(filename, eqpt, bidir, network, network_filename)

loads the requests from a json or an excel file into a data string

gnpy.tools.json_io.merge_equalization(params, extra_params)

params contains ROADM element config and extra_params default values from equipment library. If equalization is not defined in ROADM element use the one defined in equipment library. Only one type of equalization must be defined: power (target_pch_out_db) or PSD (target_psd_out_mWperGHz) or PSW (target_out_mWperSlotWidth) params and extra_params are dict

gnpy.tools.json_io.network_from_json(json_data, equipment)
gnpy.tools.json_io.network_to_json(network)
gnpy.tools.json_io.requests_from_json(json_data, equipment)

Extract list of requests from data parsed from JSON

gnpy.tools.json_io.save_json(obj, filename)
gnpy.tools.json_io.save_network(network: DiGraph, filename: str)

Dump the network into a JSON file

Parameters
  • network – network to work on

  • filename – file to write to

gnpy.tools.plots

Graphs and plots usable from a CLI application

gnpy.tools.plots._try_city(node)
gnpy.tools.plots.plot_baseline(network)
gnpy.tools.plots.plot_results(network, path, source, destination)

gnpy.tools.service_sheet

XLS parser that can be called to create a JSON request file in accordance with Yang model for requesting path computation.

See: draft-ietf-teas-yang-path-computation-01.txt

class gnpy.tools.service_sheet.Element

Bases: object

class gnpy.tools.service_sheet.Request(request_id, source, destination, trx_type, mode=None, spacing=None, power=None, nb_channel=None, disjoint_from='', nodes_list=None, is_loose='', path_bandwidth=None)

Bases: Request

class gnpy.tools.service_sheet.Request_element(Request, equipment, bidir)

Bases: Element

property json
property pathrequest
property pathsync
property uid
gnpy.tools.service_sheet.all_rows(sheet, start=0)
gnpy.tools.service_sheet.correct_xlrd_int_to_str_reading(v)
gnpy.tools.service_sheet.correct_xls_route_list(network_filename, network, pathreqlist)

prepares the format of route list of nodes to be consistant with nodes names: remove wrong names, find correct names for ila, roadm and fused if the entry was xls. if it was not xls, all names in list should be exact name in the network.

gnpy.tools.service_sheet.parse_excel(input_filename)
gnpy.tools.service_sheet.parse_row(row, fieldnames)
gnpy.tools.service_sheet.parse_service_sheet(service_sheet)

reads each column according to authorized fieldnames. order is not important.

gnpy.tools.service_sheet.read_service_sheet(input_filename, eqpt, network, network_filename=None, bidir=False)

converts a service sheet into a json structure