@@ -351,12 +351,32 @@ def __init__(self, **kwargs):
351351 self ._pmd_coef_defined = kwargs .get ('pmd_coef_defined' , kwargs ['pmd_coef' ] is True )
352352
353353 # Loss Coefficient
354- if isinstance (kwargs ['loss_coef' ], dict ):
355- self ._loss_coef = asarray (kwargs ['loss_coef' ]['value' ]) * 1e-3 # lineic loss dB/m
356- self ._f_loss_ref = asarray (kwargs ['loss_coef' ]['frequency' ]) # Hz
354+ # Support total_loss (dB) as an alternative to loss_coef (dB/km).
355+ # When total_loss is provided, it represents the total fiber attenuation
356+ # (excluding connectors), as typically measured by OTDR.
357+ # The effective loss_coef is then derived as total_loss / length.
358+ self ._total_loss = None
359+ if 'total_loss' in kwargs and kwargs ['total_loss' ] is not None :
360+ total_loss = kwargs ['total_loss' ]
361+ if isinstance (total_loss , dict ):
362+ # Frequency-dependent total loss: {value: [...], frequency: [...]}
363+ self ._total_loss = asarray (total_loss ['value' ]) # dB
364+ self ._f_loss_ref = asarray (total_loss ['frequency' ]) # Hz
365+ self ._loss_coef = self ._total_loss / (self ._length * 1e-3 ) # dB/km -> dB/m (*1e-3)
366+ self ._loss_coef = self ._loss_coef * 1e-3 # dB/m
367+ else :
368+ self ._total_loss = asarray (float (total_loss )) # dB
369+ self ._f_loss_ref = asarray (self ._ref_frequency ) # Hz
370+ self ._loss_coef = asarray (self ._total_loss / (self ._length * 1e-3 )) * 1e-3 # dB/m
371+ elif 'loss_coef' in kwargs :
372+ if isinstance (kwargs ['loss_coef' ], dict ):
373+ self ._loss_coef = asarray (kwargs ['loss_coef' ]['value' ]) * 1e-3 # lineic loss dB/m
374+ self ._f_loss_ref = asarray (kwargs ['loss_coef' ]['frequency' ]) # Hz
375+ else :
376+ self ._loss_coef = asarray (kwargs ['loss_coef' ]) * 1e-3 # lineic loss dB/m
377+ self ._f_loss_ref = asarray (self ._ref_frequency ) # Hz
357378 else :
358- self ._loss_coef = asarray (kwargs ['loss_coef' ]) * 1e-3 # lineic loss dB/m
359- self ._f_loss_ref = asarray (self ._ref_frequency ) # Hz
379+ raise KeyError ('loss_coef' )
360380 # Lumped Losses
361381 self ._lumped_losses = kwargs ['lumped_losses' ] if 'lumped_losses' in kwargs else array ([])
362382 self ._latency = self ._length / (c / self ._n1 ) # s
@@ -446,6 +466,10 @@ def ref_wavelength(self):
446466 def ref_frequency (self ):
447467 return self ._ref_frequency
448468
469+ @property
470+ def total_loss (self ):
471+ return self ._total_loss
472+
449473 @property
450474 def loss_coef (self ):
451475 return self ._loss_coef
@@ -464,7 +488,15 @@ def latency(self):
464488
465489 def asdict (self ):
466490 dictionary = super ().asdict ()
467- dictionary ['loss_coef' ] = self .loss_coef * 1e3
491+ if self ._total_loss is not None :
492+ if self ._total_loss .size > 1 :
493+ dictionary ['total_loss' ] = {'value' : self ._total_loss .tolist (),
494+ 'frequency' : self ._f_loss_ref .tolist ()}
495+ else :
496+ dictionary ['total_loss' ] = float (self ._total_loss )
497+ dictionary .pop ('loss_coef' , None )
498+ else :
499+ dictionary ['loss_coef' ] = self .loss_coef * 1e3
468500 dictionary ['length_units' ] = 'm'
469501 if len (self .lumped_losses ) == 0 :
470502 dictionary .pop ('lumped_losses' )
0 commit comments