예제 #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, self.field_name)
        # 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 -----------------------------------------
        if (self.energy):
            peak_power: List[float] = []
            time_window = domain.time_window * 1e-12  # ps -> s
            for i in range(len(self.energy)):
                peak_power.append(self.energy[i] / time_window)
        else:
            peak_power = self.peak_power
        rep_freq = np.nan
        for i in range(self.channels):  # Nbr of channels
            res = np.zeros(domain.time.shape, dtype=cst.NPFT)
            phi = (self.init_phi[i] -
                   Domain.nu_to_omega(self.offset_nu[i]) * domain.time)
            res += math.sqrt(peak_power[i]) * np.exp(1j * phi)
            field.add_channel(res,
                              Domain.lambda_to_omega(self.center_lambda[i]),
                              rep_freq)

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

        return output_ports, output_fields
예제 #2
0
def test_copy_field(reset_channels, reset_noise, reset_delays):
    """Should fail if no valid copy is returned.
    """
    uni_length = 12
    domain = Domain(samples_per_bit=uni_length, noise_samples=uni_length)
    type = 1
    center_omega = 1550.
    rep_freq = 1e3
    delay = 10.
    field = Field(domain, type)
    field.noise = np.ones(uni_length)
    field.add_channel(np.arange(uni_length), center_omega, rep_freq, delay)
    new_field = field.get_copy('', reset_channels, reset_noise, reset_delays)
    equal_channels = np.array_equal(new_field.channels, field.channels)
    if (not reset_channels):
        assert equal_channels
    else:
        assert not equal_channels
    equal_noise = np.array_equal(new_field.noise, field.noise)
    if (not reset_noise):
        assert equal_noise
    else:
        assert not equal_noise
    equal_delays = np.array_equal(new_field.delays, field.delays)
    if (not reset_delays):
        assert equal_delays
    else:
        assert not equal_delays
예제 #3
0
    def fct(op, right_op, field_channel, type, center_omega, rep_freq, samples,
            *operands):
        res = []
        for operand in operands:
            new_field = Field(Domain(samples_per_bit=samples), type)
            for i, channel in enumerate(field_channel):
                new_field.add_channel(channel, center_omega[i], rep_freq[i])
            if (right_op):  # Right operand operator
                res.append(op(operand, new_field))
            else:  # Left operand operator
                res.append(op(new_field, operand))

        return res
예제 #4
0
def test_same_omega(operator_fixture, op, right_op):
    """Should not fail if the center omega are the same and in the same
    order."""
    length = 12
    field = Field(Domain(samples_per_bit=length), type_op_test)
    center_omegas = [1030., 1025., 1020.]
    rep_freqs = [1., 2., 3.]
    channels = [np.ones(length) * (i + 1) for i in range(len(center_omegas))]
    for i in range(len(center_omegas)):
        field.add_channel(channels[i], center_omegas[i], rep_freqs[i])
    operands = [field]
    res = operator_fixture(op, right_op, channels, type_op_test, center_omegas,
                           rep_freqs, length, *operands)
예제 #5
0
def test_no_common_omegas(operator_fixture, op, right_op):
    """Should not perform math operators if the center omegas are
    different."""
    length = 12
    field = Field(Domain(samples_per_bit=length), type_op_test)
    center_omegas = [1030., 1025., 1020.]
    rep_freqs = [1., 2., 3.]
    channels = [np.ones(length) * (i + 1) for i in range(len(center_omegas))]
    for i in range(len(center_omegas)):
        field.add_channel(channels[i], center_omegas[i], rep_freqs[i])
    operands = [field]
    center_omegas = [1029., 1021.]
    channels = [np.ones(length) * (i + 1) for i in range(len(center_omegas))]
    rep_freqs = [2., 3.]
    res = operator_fixture(op, right_op, channels, type_op_test, center_omegas,
                           rep_freqs, length, *operands)
    field_res = res[0]
    if (len(field_res) == len(field)):
        assert np.array_equal(field_res[:], field[:])
    else:
        assert np.array_equal(field_res[:], np.asarray(channels))
예제 #6
0
        return res

    return fct


# ----------------------------------------------------------------------
# Tests ----------------------------------------------------------------
# ----------------------------------------------------------------------

scale = 2
length = 12
type_op_test = 1
center_omega_op_test = [1550.]
rep_freq_op_test = [1e3]
field_ = Field(Domain(samples_per_bit=length), type_op_test)
field_.add_channel(scale * np.ones(length), center_omega_op_test[0],
                   rep_freq_op_test[0])
operand_args = [
    int(scale),
    float(scale),
    complex(scale), scale * np.ones(length), field_
]


@pytest.mark.field_op
@pytest.mark.parametrize("op, field_channel, op_res, operands", [
    (operator.__iadd__, [np.arange(1, length + 1)],
     np.array([np.arange(1, length + 1) +
               (scale * np.ones(length))]), operand_args),
    (operator.__isub__, [np.arange(1, length + 1)],
     np.array([np.arange(1, length + 1) -
               (scale * np.ones(length))]), operand_args),