def get_edfa_parameters(edfa_json_path, eqipment_json_path): """ This is an utility that, given the JSON files returns to you the parameters needed for the __init__ of GNPy Edfa. Once you have the edfa_params you can instantiate and Edfa as: >>> from gnpy.core.elements import Edfa >>> >>> edfa_instance = Edfa(**edfa_params) :param edfa_json_path: path of the json file with the EDFA parameters :param eqipment_json_path: path of the json file with the equipment :return: edfa_params: a dictionary containing the parameters to properly instantiate the GNPy EDFA """ eqp_file_name = Path(eqipment_json_path) eqp, eqp_dict = _load_equipment(eqp_file_name) file_name = Path(edfa_json_path) with open(file_name, 'r') as file: edfa_params = json.load(file) def_params = edfa_params.setdefault('params', {}) edfa_params['params'] = merge_amplifier_restrictions( def_params, eqp['Edfa']['simple_edfa'].__dict__) edfa_params.pop('type_variety') edfa_params.pop('type') return edfa_params
def test_compare_nf_models(gain, setup_edfa_variable_gain, 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_variable_gain frequencies = array([c.frequency for c in si.carriers]) pin = array( [c.power.signal + c.power.nli + c.power.ase for c in si.carriers]) pin = pin / db2lin(gain) baud_rates = array([c.baud_rate for c in si.carriers]) edfa.operational.gain_target = gain # edfa is variable gain type pref = Pref(0, -gain, lin2db(len(frequencies))) edfa.interpol_params(frequencies, pin, baud_rates, pref) nf_model = edfa.nf[0] # change edfa type variety to a polynomial el_config = { "uid": "Edfa1", "operational": { "gain_target": gain, "tilt_target": 0 }, "metadata": { "location": { "region": "", "latitude": 2, "longitude": 0 } } } equipment = load_equipment(eqpt_library) extra_params = equipment['Edfa']['CienaDB_medium_gain'] temp = el_config.setdefault('params', {}) temp = merge_amplifier_restrictions(temp, extra_params.__dict__) el_config['params'] = temp edfa = Edfa(**el_config) # edfa is variable gain type edfa.interpol_params(frequencies, pin, baud_rates, pref) nf_poly = edfa.nf[0] print(nf_poly, nf_model) assert pytest.approx(nf_model, abs=0.5) == nf_poly
def network_from_json(json_data, equipment): # NOTE|dutc: we could use the following, but it would tie our data format # too closely to the graph library # from networkx import node_link_graph g = DiGraph() for el_config in json_data['elements']: typ = el_config.pop('type') variety = el_config.pop('type_variety', 'default') cls = _cls_for(typ) if typ == 'Fused': # well, there's no variety for the 'Fused' node type pass elif variety in equipment[typ]: extra_params = equipment[typ][variety] temp = el_config.setdefault('params', {}) temp = merge_amplifier_restrictions(temp, extra_params.__dict__) el_config['params'] = temp el_config['type_variety'] = variety elif (typ in ['Fiber', 'RamanFiber' ]) or (typ == 'Edfa' and variety not in ['default', '']): raise ConfigurationError( f'The {typ} of variety type {variety} was not recognized:' '\nplease check it is properly defined in the eqpt_config json file' ) el = cls(**el_config) g.add_node(el) nodes = {k.uid: k for k in g.nodes()} for cx in json_data['connections']: from_node, to_node = cx['from_node'], cx['to_node'] try: if isinstance(nodes[from_node], elements.Fiber): edge_length = nodes[from_node].params.length else: edge_length = 0.01 g.add_edge(nodes[from_node], nodes[to_node], weight=edge_length) except KeyError: raise NetworkTopologyError( f'can not find {from_node} or {to_node} defined in {cx}') return g