diff --git a/gnpy/core/elements.py b/gnpy/core/elements.py index 4dbf66d9..ba93dca7 100644 --- a/gnpy/core/elements.py +++ b/gnpy/core/elements.py @@ -160,9 +160,15 @@ class Roadm(Node): #but add channels are not, so we define an effective loss #in the case of add channels if self.per_degree_target_pch_out_db: - temp = next(el['target_pch_out_db'] \ - for el in self.per_degree_target_pch_out_db if el['to_node']==degree) + # find the target power on this degree + try: + temp = next(el['target_pch_out_db'] \ + for el in self.per_degree_target_pch_out_db if el['to_node']==degree) + except StopIteration: + # if no target power is defined on this degree use the global one + temp = self.params.target_pch_out_db else: + # if no per degree target power are defined, use the global one temp = self.params.target_pch_out_db self.effective_pch_out_db = min(pref.p_spani, temp) self.effective_loss = pref.p_spani - self.effective_pch_out_db diff --git a/gnpy/core/network.py b/gnpy/core/network.py index 9f31aa7d..85191a44 100644 --- a/gnpy/core/network.py +++ b/gnpy/core/network.py @@ -316,19 +316,17 @@ def set_egress_amplifier(network, roadm, equipment, pref_total_db): # next_node = next(n for n in network.successors(node)) # next_node = find_last_node(next_node) - try: - if node.params.per_degree_target_pch_out_db: - #find the target power on this degree - # need to change this ! ############################# - prev_dp = next(el["target_pch_out_db"] for el in node.params.per_degree_target_pch_out_db if el["to_node"]==next_node.uid) - node.params = node.params._replace(target_pch_out_db=prev_dp) - else: + if node.per_degree_target_pch_out_db: + # find the target power on this degree + try: + prev_dp = next(el["target_pch_out_db"] for el in \ + node.per_degree_target_pch_out_db if el["to_node"]==next_node.uid) + except StopIteration: + # if no target power is defined on this degree use the global one prev_dp = getattr(node.params, 'target_pch_out_db', 0) - node.params = node.params._replace(target_pch_out_db=prev_dp) - except AttributeError: + else: + # if no per degree target power is given use the global one prev_dp = getattr(node.params, 'target_pch_out_db', 0) - - ####### en fait change pas les elements !, faudrait plusieurs pchtarget dans le roadm dp = prev_dp prev_voa = 0 voa = 0