Ejemplo n.º 1
0
import optcom as oc

# Create 2 Gaussian channels
pulse = oc.Gaussian(channels=2,
                    center_lambda=[1030., 1550.],
                    peak_power=[0.5, 1.0])
# Create fiber with a user-defined attenuation coefficient
fiber = oc.Fiber(length=1.0,
                 alpha=[0.4],
                 ATT=True,
                 DISP=True,
                 SPM=True,
                 save_all=True)
# Create an optical layout and link the first port of 'pulse' to the first port of 'fiber'
layout = oc.Layout()
layout.add_link(pulse.get_port(0), fiber.get_port(0))
layout.run_all()
# Extract outputs and plot
time = fiber.storage.time
power = oc.temporal_power(fiber.storage.channels)
space = fiber.storage.space
oc.animation2d(time,
               power,
               space,
               x_label='t',
               y_label='P_t',
               plot_title='My first Optcom example',
               line_labels=['1030. nm channel', '1550. nm channel'])
#filename='example_anim_readme.mp4')
Ejemplo n.º 2
0
        return output_ports, output_fields


if __name__ == "__main__":
    """Give an example of LoadField usage.
    This piece of code is standalone, i.e. can be used in a separate
    file as an example.
    """

    from typing import List

    import numpy as np

    import optcom as oc

    lt: oc.Layout = oc.Layout()
    gssn_1: oc.Gaussian = oc.Gaussian(channels=1, width=[5.0],
                                      field_name='field 1 to be saved in file')
    field_saver_1: oc.SaveField = oc.SaveField()
    gssn_2: oc.Gaussian = oc.Gaussian(channels=1, width=[10.0],
                                      field_name='field 2 to be saved in file')
    field_saver_2: oc.SaveField = oc.SaveField()

    lt.add_links((gssn_1[0], field_saver_1[0]), (gssn_2[0], field_saver_2[0]))
    lt.run(gssn_1, gssn_2)

    fields: List[oc.Field] = field_saver_1.fields + field_saver_2.fields

    lt_: oc.Layout = oc.Layout()
    load_field: oc.LoadField = oc.LoadField(fields=fields)
Ejemplo n.º 3
0
 oc.plot2d(lambdas,
           tf,
           x_labels=['nu'],
           y_labels=['Amplitude (a.u.)'],
           plot_titles=[
               "Transfer function centered at "
               "{} nm with bandwidth {} nm".format(round(center_lambda, 2),
                                                   round(lambda_bw))
           ])
 # Apply on pulse and plot
 bit_width = 1000.
 domain = oc.Domain(samples_per_bit=2**13,
                    bit_width=bit_width,
                    noise_samples=int(1e3),
                    noise_range=(center_lambda - 1.0, center_lambda + 1.0))
 lt: oc.Layout = oc.Layout(domain)
 lambda_bw = 0.05  # nm
 nu_bw = oc.lambda_bw_to_nu_bw(lambda_bw, center_lambda)
 pulse: oc.Gaussian = oc.Gaussian(channels=2,
                                  peak_power=[10.0, 19.0],
                                  width=[10., 6.],
                                  center_lambda=[center_lambda],
                                  noise=100 * np.ones(domain.noise_samples))
 filter: oc.GaussianFilter = oc.GaussianFilter(nu_bw=nu_bw,
                                               nu_offset=0.,
                                               order=1,
                                               center_nu=center_nu)
 lt.add_link(pulse[0], filter[0])
 lt.run(pulse)
 plot_titles: List[str] = [
     "Original pulse", r"After Gaussian filter with "
Ejemplo n.º 4
0
    from typing import Callable, List, Optional

    import numpy as np

    import optcom as oc

    pulse_1: oc.Gaussian = oc.Gaussian(peak_power=[1.0],
                                       center_lambda=[1550.0])
    pulse_2: oc.Gaussian = oc.Gaussian(peak_power=[5.0],
                                       center_lambda=[1030.0])
    pulse_3: oc.Gaussian = oc.Gaussian(peak_power=[10.0],
                                       center_lambda=[976.0])
    # Dummy component to be able to test the not combining case
    pm: oc.IdealPhaseMod = oc.IdealPhaseMod()
    lt: oc.Layout = oc.Layout()

    combiner: oc.IdealCombiner = oc.IdealCombiner(arms=3, combine=False)

    lt.add_links((pulse_1[0], combiner[0]), (pulse_2[0], combiner[1]),
                 (pulse_3[0], combiner[2]), (combiner[3], pm[0]))

    lt.run(pulse_1, pulse_2, pulse_3)

    plot_titles: List[str] = ([
        "Original pulses", "Pulses coming out of the "
        "ideal coupler \n without combination"
    ])
    plot_groups: List[int] = [0, 0, 0, 1]
    line_labels: List[Optional[str]] = ['port 0', 'port 1', 'port 2', None]
Ejemplo n.º 5
0
        return output_ports, output_fields


if __name__ == "__main__":
    """Give an example of Sech usage.
    This piece of code is standalone, i.e. can be used in a separate
    file as an example.
    """

    from typing import Callable, List, Optional

    import numpy as np

    import optcom as oc

    lt: oc.Layout = oc.Layout(oc.Domain(samples_per_bit=4096))

    channels: int = 3
    center_lambda: List[float] = [1552.0, 1549.0, 1596.0]
    position: List[float] = [0.3, 0.5]
    width: List[float] = [5.3, 6.]
    peak_power: List[float] = [1e-3, 2e-3, 6e-3]
    rep_freq: List[float] = [0.03, 0.04]
    offset_nu: List[float] = [1.56, -1.6]
    chirp: List[float] = [0.5, 0.1]
    init_phi: List[float] = [1.0, 0.0]

    sech = oc.Sech(channels=channels,
                   center_lambda=center_lambda,
                   position=position,
                   fwhm=width,
Ejemplo n.º 6
0

if __name__ == "__main__":
    """Give an example of CW usage.
    This piece of code is standalone, i.e. can be used in a separate
    file as an example.
    """

    from typing import List

    import numpy as np

    import optcom as oc

    dm: oc.Domain = oc.Domain(samples_per_bit=512, bit_width=100.0)
    lt: oc.Layout = oc.Layout(dm)

    channels: int = 1
    center_lambda: List[float] = [1552.0, 1549.0, 1596.0]
    peak_power: List[float] = [1e-3, 2e-3, 6e-3]
    offset_nu: List[float] = [0.0, 1.56, -1.6]
    init_phi: List[float] = [1.0, 1.0, 0.0]

    cw: oc.CW = oc.CW(channels=channels,
                      center_lambda=center_lambda,
                      peak_power=peak_power,
                      offset_nu=offset_nu,
                      init_phi=init_phi,
                      save=True)

    lt.run(cw)
Ejemplo n.º 7
0
if __name__ == "__main__":
    """Give an example of FiberCoupler usage.
    This piece of code is standalone, i.e. can be used in a separate
    file as an example.
    """

    import math
    from typing import Callable, List, Optional, Union

    import numpy as np

    import optcom as oc

    noise_samples: int = 100
    lt: oc.Layout = oc.Layout(
        oc.Domain(bit_width=20.0,
                  samples_per_bit=1024,
                  noise_samples=noise_samples))

    Lambda: float = 1030.0
    pulse_1: oc.Gaussian = oc.Gaussian(channels=1,
                                       peak_power=[38.5, 0.5],
                                       fwhm=[1.],
                                       center_lambda=[Lambda],
                                       noise=np.ones(noise_samples) * 12)
    pulse_2: oc.Gaussian = oc.Gaussian(channels=1,
                                       peak_power=[23.5, 0.3],
                                       fwhm=[1.],
                                       center_lambda=[1050.0],
                                       noise=np.ones(noise_samples) * 5)

    steps: int = int(100)
Ejemplo n.º 8
0
    import numpy as np

    import optcom as oc

    plot_groups: List[int] = []
    line_labels: List[Optional[str]] = []
    plot_titles: List[str] = []
    x_datas: List[np.ndarray] = []
    y_datas: List[np.ndarray] = []

    nlse_methods: List[str] = ["ssfm", "ssfm_reduced", "ssfm_symmetric",
                               "ssfm_opti_reduced", "ssfm_super_sym",
                               "ssfm_opti_super_sym", "rk4ip", "rk4ip"]
    # ---------------- NLSE solvers test -------------------------------
    lt: oc.Layout = oc.Layout(oc.Domain(bit_width=100.0, samples_per_bit=4096))

    pulse: oc.Gaussian = oc.Gaussian(channels=2, peak_power=[0.5, 1.0], width=[0.5, 0.8])

    steps: int = int(5e3)
    fiber: oc.Fiber
    SS: bool = True
    for j, nlse_method in enumerate(nlse_methods):
        if (j == len(nlse_methods)-2):  # To compute rk4ip and rk4ip_gnlse
            oc.set_rk4ip_opti_gnlse(False)   # Can make slighty diff. output
        else:
            oc.set_rk4ip_opti_gnlse(True)
        # Propagation
        fiber = oc.Fiber(length=0.2, nlse_method=nlse_method, alpha=[0.5],
                      beta_order=3, gamma=4.0, nl_approx=False, SPM=True,
                      XPM=True, SS=True, RS=True, steps=steps, save=True)