mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-11-03 03:28:04 +00:00
Refactoring: conversion functions instead of gnpy.core.units.UNITS
The TL;DR behind this patch is that it's better to have a utility conversion function instead of having multiplier LUT and open code which implements the conversion. The FiberParams handling looked fishy -- apparently, it was keeping the multiplier around, but it was unconditionally setting the units to meters, anyway. Given that the units were not being preserved anyway (everything got converted to meters), and that the multipler was not used anywhere, let's refactor the code to just convert to meters using our new utility function, and remove the unused argument. Change-Id: Id886d409a4046f980eed569265baefd97db841bd
This commit is contained in:
@@ -14,8 +14,7 @@ from scipy.constants import c, pi
|
||||
from numpy import squeeze, log10, exp
|
||||
|
||||
|
||||
from gnpy.core.units import UNITS
|
||||
from gnpy.core.utils import db2lin
|
||||
from gnpy.core.utils import db2lin, convert_length
|
||||
from gnpy.core.exceptions import ParametersError
|
||||
|
||||
|
||||
@@ -142,9 +141,7 @@ class SimParams(Parameters):
|
||||
class FiberParams(Parameters):
|
||||
def __init__(self, **kwargs):
|
||||
try:
|
||||
self._length_units_factor = UNITS[kwargs['length_units']]
|
||||
self._length = kwargs['length'] * self._length_units_factor # m
|
||||
self._length_units = 'm'
|
||||
self._length = convert_length(kwargs['length'], kwargs['length_units'])
|
||||
# fixed attenuator for padding
|
||||
self._att_in = kwargs['att_in'] if 'att_in' in kwargs else 0
|
||||
# if not defined in the network json connector loss in/out
|
||||
@@ -190,14 +187,6 @@ class FiberParams(Parameters):
|
||||
"""length must be in m"""
|
||||
self._length = length
|
||||
|
||||
@property
|
||||
def length_units(self):
|
||||
return self._length_units
|
||||
|
||||
@property
|
||||
def length_units_factor(self):
|
||||
return self._length_units_factor
|
||||
|
||||
@property
|
||||
def att_in(self):
|
||||
return self._att_in
|
||||
@@ -281,4 +270,5 @@ class FiberParams(Parameters):
|
||||
def asdict(self):
|
||||
dictionary = super().asdict()
|
||||
dictionary['loss_coef'] = self.loss_coef * 1e3
|
||||
dictionary['length_units'] = 'm'
|
||||
return dictionary
|
||||
|
||||
Reference in New Issue
Block a user