예제 #1
0
    def __call__(self, domain: Domain) -> Tuple[List[int], List[Field]]:

        output_ports: List[int] = []
        output_fields: List[Field] = []
        field = Field(domain, cst.OPTI)
        # Bit rate initialization --------------------------------------
        nbr_pulses = []
        for i in range(self.channels):
            if (self.bit_rate[i]):
                nbr_temp = math.floor(domain.time_window * self.bit_rate[i])
                if (nbr_temp):
                    nbr_pulses.append(nbr_temp)
                else:
                    util.warning_terminal(
                        "In component {}: the time window "
                        "is too thin for the bit rate specified, bit rate "
                        "will be ignored".format(self.name))
                    nbr_pulses.append(1)
            else:
                nbr_pulses.append(1)

        rel_pos = []
        for i in range(self.channels):
            pos_step = 1 / nbr_pulses[i]
            if (nbr_pulses[i] % 2):  # Odd
                dist_from_center = nbr_pulses[i] // 2 * pos_step
            else:
                dist_from_center = (nbr_pulses[i] // 2 -
                                    1) * pos_step + pos_step / 2
            rel_pos.append(
                np.linspace(self.position[i] - dist_from_center,
                            self.position[i] + dist_from_center,
                            num=nbr_pulses[i]))
        # Check offset -------------------------------------------------
        for i in range(len(self.offset_nu)):
            if (abs(self.offset_nu[i]) > domain.nu_window):
                self.offset_nu[i] = 0.0
                util.warning_terminal(
                    "The offset of channel {} in component "
                    "{} is bigger than half the frequency window, offset will "
                    "be ignored.".format(str(i), self.name))
        # Field initialization -----------------------------------------
        for i in range(self.channels):  # Nbr of channels
            res = np.zeros(domain.time.shape, dtype=cst.NPFT)
            for j in range(len(rel_pos[i])):
                norm_time = domain.get_shift_time(
                    rel_pos[i][j]) / self.width[i]
                var_time = np.power(norm_time, 2)
                phi = (self.init_phi[i] -
                       Domain.nu_to_omega(self.offset_nu[i]) * domain.time -
                       0.5 * self.chirp[i] * var_time)
                res += (math.sqrt(self.peak_power[i]) / np.cosh(norm_time) *
                        np.exp(1j * phi))
            field.append(res, Domain.lambda_to_omega(self.center_lambda[i]))

        output_fields.append(field)
        output_ports.append(0)

        return output_ports, output_fields
예제 #2
0
    def __call__(self, domain: Domain) -> Tuple[List[int], List[Field]]:

        output_ports: List[int] = []
        output_fields: List[Field] = []
        field: Field = Field(domain, cst.OPTI, self.field_name)
        # Bit rate initialization --------------------------------------
        rel_pos: List[np.ndarray]
        rel_pos = util.pulse_positions_in_time_window(self.channels,
                                                      self.rep_freq,
                                                      domain.time_window,
                                                      self.position)
        # Check offset -------------------------------------------------
        for i in range(len(self.offset_nu)):
            if (abs(self.offset_nu[i]) > domain.nu_window):
                self.offset_nu[i] = 0.0
                util.warning_terminal(
                    "The offset of channel {} in component "
                    "{} is bigger than half the frequency window, offset will "
                    "be ignored.".format(str(i), self.name))
        # Field initialization -----------------------------------------
        width: float
        for i in range(self.channels):  # Nbr of channels
            if (self.fwhm is None):
                width = self.width[i]
            else:
                width = self.fwhm_to_width(self.fwhm[i])
            res: np.ndarray = np.zeros(domain.time.shape, dtype=cst.NPFT)
            for j in range(len(rel_pos[i])):
                norm_time = domain.get_shift_time(rel_pos[i][j]) / width
                var_time = np.power(norm_time, 2)
                phi = (self.init_phi[i] -
                       Domain.nu_to_omega(self.offset_nu[i]) * domain.time -
                       0.5 * self.chirp[i] * var_time)
                res += (math.sqrt(self.peak_power[i]) / np.cosh(norm_time) *
                        np.exp(1j * phi))
            field.add_channel(res,
                              Domain.lambda_to_omega(self.center_lambda[i]),
                              self.rep_freq[i])
            if (self.noise is not None):
                field.noise = self.noise
        output_fields.append(field)
        output_ports.append(0)

        return output_ports, output_fields