def assign_spectrum(self, nvalue, mvalue): """ change oms spectrum to mark spectrum assigned """ # print("assign_spectrum") # print(f'n , m :{n},{m}') if (nvalue is None or mvalue is None or isinstance(nvalue, float) or isinstance(mvalue, float) or mvalue == 0): msg = f'could not assign None values' LOGGER.critical(msg) raise SpectrumError(msg) startn, stopn = mvalue_to_slots(nvalue, mvalue) # print(f'startn stop n {startn} , {stopn}') # assumes that guardbands are sufficient to ensure that assigning a center channel # at fmin or fmax is OK is startn > self.spectrum_bitmap.n_min if (nvalue <= self.spectrum_bitmap.freq_index_max and nvalue >= self.spectrum_bitmap.freq_index_min and stopn <= self.spectrum_bitmap.n_max and startn > self.spectrum_bitmap.n_min): # verification that both length are identical self.spectrum_bitmap.bitmap[self.spectrum_bitmap.geti(startn):self. spectrum_bitmap.geti(stopn) + 1] = [0] * (stopn - startn + 1) return True else: msg = f'Could not assign n {nvalue}, m {mvalue} values:' +\ f' one or several slots are not available' LOGGER.info(msg) return False
def __init__(self, frequency: array, baud_rate: array, slot_width: array, signal: array, nli: array, ase: array, roll_off: array, chromatic_dispersion: array, pmd: array): indices = argsort(frequency) self._frequency = frequency[indices] self._df = outer(ones(frequency.shape), frequency) - outer( frequency, ones(frequency.shape)) self._number_of_channels = len(self._frequency) self._channel_number = [*range(1, self._number_of_channels + 1)] self._slot_width = slot_width[indices] self._baud_rate = baud_rate[indices] overlap = self._frequency[: -1] + self._slot_width[:-1] / 2 > self._frequency[ 1:] - self._slot_width[1:] / 2 if any(overlap): overlap = [ pair for pair in zip(overlap * self._channel_number[:-1], overlap * self._channel_number[1:]) if pair != (0, 0) ] raise SpectrumError( f'Spectrum required slot widths larger than the frequency spectral distances ' f'between channels: {overlap}.') exceed = self._baud_rate > self._slot_width if any(exceed): raise SpectrumError( f'Spectrum baud rate, including the roll off, larger than the slot width for channels: ' f'{[ch for ch in exceed * self._channel_number if ch]}.') self._signal = signal[indices] self._nli = nli[indices] self._ase = ase[indices] self._roll_off = roll_off[indices] self._chromatic_dispersion = chromatic_dispersion[indices] self._pmd = pmd[indices] pref = lin2db(mean(signal) * 1e3) self._pref = Pref(pref, pref, lin2db(self._number_of_channels))
def __add__(self, other: SpectralInformation): try: return SpectralInformation( frequency=append(self.frequency, other.frequency), slot_width=append(self.slot_width, other.slot_width), signal=append(self.signal, other.signal), nli=append(self.nli, other.nli), ase=append(self.ase, other.ase), baud_rate=append(self.baud_rate, other.baud_rate), roll_off=append(self.roll_off, other.roll_off), chromatic_dispersion=append(self.chromatic_dispersion, other.chromatic_dispersion), pmd=append(self.pmd, other.pmd)) except SpectrumError: raise SpectrumError( 'Spectra cannot be summed: channels overlapping.')
def __init__(self, f_min, f_max, grid, guardband=0.15e12, bitmap=None): # n is the min index including guardband. Guardband is require to be sure # that a channel can be assigned with center frequency fmin (means that its # slot occupation goes below freq_index_min n_min = frequency_to_n(f_min - guardband, grid) n_max = frequency_to_n(f_max + guardband, grid) - 1 self.n_min = n_min self.n_max = n_max self.freq_index_min = frequency_to_n(f_min) self.freq_index_max = frequency_to_n(f_max) self.freq_index = list(range(n_min, n_max + 1)) if bitmap is None: self.bitmap = [1] * (n_max - n_min + 1) elif len(bitmap) == len(self.freq_index): self.bitmap = bitmap else: raise SpectrumError(f'bitmap is not consistant with f_min{f_min} - n: {n_min} and f_max{f_max}- n :{n_max}')
def assign_spectrum(self, nvalue, mvalue): """ change oms spectrum to mark spectrum assigned """ if not isinstance(nvalue, int): raise SpectrumError(f'N must be a signed integer, got {nvalue}') if not isinstance(mvalue, int): raise SpectrumError(f'M must be an integer, got {mvalue}') if mvalue <= 0: raise SpectrumError(f'M must be positive, got {mvalue}') if nvalue > self.spectrum_bitmap.freq_index_max: raise SpectrumError(f'N {nvalue} over the upper spectrum boundary') if nvalue < self.spectrum_bitmap.freq_index_min: raise SpectrumError(f'N {nvalue} below the lower spectrum boundary') startn, stopn = mvalue_to_slots(nvalue, mvalue) if stopn > self.spectrum_bitmap.n_max: raise SpectrumError(f'N {nvalue}, M {mvalue} over the N spectrum bitmap bounds') if startn <= self.spectrum_bitmap.n_min: raise SpectrumError(f'N {nvalue}, M {mvalue} below the N spectrum bitmap bounds') self.spectrum_bitmap.bitmap[self.spectrum_bitmap.geti(startn):self.spectrum_bitmap.geti(stopn) + 1] = [0] * (stopn - startn + 1)
def create_arbitrary_spectral_information( frequency: Union[ndarray, Iterable, int, float], signal: Union[int, float, ndarray, Iterable], baud_rate: Union[int, float, ndarray, Iterable], slot_width: Union[int, float, ndarray, Iterable] = None, roll_off: Union[int, float, ndarray, Iterable] = 0., chromatic_dispersion: Union[int, float, ndarray, Iterable] = 0., pmd: Union[int, float, ndarray, Iterable] = 0.): """This is just a wrapper around the SpectralInformation.__init__() that simplifies the creation of a non-uniform spectral information with NLI and ASE powers set to zero.""" frequency = asarray(frequency) number_of_channels = frequency.size try: signal = full(number_of_channels, signal) baud_rate = full(number_of_channels, baud_rate) roll_off = full(number_of_channels, roll_off) slot_width = full(number_of_channels, slot_width) if slot_width is not None else \ ceil((1 + roll_off) * baud_rate / DEFAULT_SLOT_WIDTH_STEP) * DEFAULT_SLOT_WIDTH_STEP chromatic_dispersion = full(number_of_channels, chromatic_dispersion) pmd = full(number_of_channels, pmd) nli = zeros(number_of_channels) ase = zeros(number_of_channels) return SpectralInformation(frequency=frequency, slot_width=slot_width, signal=signal, nli=nli, ase=ase, baud_rate=baud_rate, roll_off=roll_off, chromatic_dispersion=chromatic_dispersion, pmd=pmd) except ValueError as e: if 'could not broadcast' in str(e): raise SpectrumError('Dimension mismatch in input fields.') else: raise