width=[10., 6.], center_lambda=[center_lambda], noise=100*np.ones(domain.noise_samples)) filter: oc.GenericFilter = oc.GenericFilter(nu_bw=nu_bw, nu_offset=0., center_nu=center_nu) lt.add_link(pulse[0], filter[0]) lt.run(pulse) plot_titles: List[str] = ["Original pulse", r"After flat top filter with " "frequency bandwidth {} THz." .format(round(nu_bw,2))] plot_titles += plot_titles y_datas: List[np.ndarray] = [oc.temporal_power(pulse[0][0].channels), oc.temporal_power(filter[1][0].channels), oc.spectral_power(pulse[0][0].channels), oc.spectral_power(filter[1][0].channels), pulse[0][0].noise, filter[1][0].noise] x_datas: List[np.ndarray] = [pulse[0][0].time, filter[1][0].time, pulse[0][0].nu, filter[1][0].nu, pulse[0][0].domain.noise_omega, filter[1][0].domain.noise_omega] x_labels: List[str] = ['t', 't', 'nu', 'nu', 'nu', 'nu'] y_labels: List[str] = ['P_t', 'P_t', 'P_nu', 'P_nu', 'P (W)', 'P (W)'] nu_range = (center_nu-.1, center_nu+.1) time_range = (bit_width/2.+75., bit_width/2.-75.) noise_range = (x_datas[-1][0], x_datas[-1][-1]) x_ranges = [time_range, time_range, nu_range, nu_range, noise_range] oc.plot2d(x_datas, y_datas, plot_titles=plot_titles, x_labels=x_labels, y_labels=y_labels, split=True, line_opacities=[0.3], x_ranges=x_ranges)
y_datas.append(oc.temporal_power(divider[i][0].channels)) x_datas.append(divider[i][0].time) # Without division arms = 3 pulse = oc.Gaussian(channels=2, peak_power=[10.0, 7.0]) divider = oc.IdealDivider(arms=arms, divide=False, save=True) lt.reset() lt.add_link(pulse[0], divider[0]) lt.run(pulse) plot_titles.extend([ "Original pulse", "Pulses coming out of the ideal " "divider (3 ports) \n with no division." ]) plot_groups.extend([2] + [3 for i in range(arms)]) line_labels.extend([None]) line_labels.extend(["port {}".format(str(i)) for i in range(arms)]) y_datas.extend([oc.temporal_power(pulse[0][0].channels)]) x_datas.extend([pulse[0][0].time]) for i in range(1, arms + 1): y_datas.append(oc.temporal_power(divider[i][0].channels)) x_datas.append(divider[i][0].time) oc.plot2d(x_datas, y_datas, plot_groups=plot_groups, plot_titles=plot_titles, x_labels=['t'], y_labels=['P_t'], line_labels=line_labels, line_opacities=[0.3])
""" from typing import List import numpy as np import optcom as oc # With float omega: float = oc.lambda_to_omega(1552.0) nl_index: oc.NLIndex = oc.NLIndex(medium="SiO2") print(nl_index(omega)) # With numpy ndarray lambdas: np.ndarray = np.linspace(500, 1600, 1000) omegas: np.ndarray = oc.lambda_to_omega(lambdas) res: np.ndarray = nl_index(omegas) x_labels: List[str] = ['Lambda'] y_labels: List[str] = ['n_2'] plot_titles: List[str] = [ "Non linear index as a function of the " "wavelength for Silica core." ] oc.plot2d([lambdas], [res], x_labels=x_labels, y_labels=y_labels, plot_titles=plot_titles, line_opacities=[0.0], y_ranges=[(2.5 * 1e-20, 3.2 * 1e-20)])
import optcom as oc # With float n_clad: float = 1.44 omega: float = oc.lambda_to_omega(1050.0) sellmeier: oc.Sellmeier = oc.Sellmeier("sio2") NA_inst: oc.NumericalAperture = oc.NumericalAperture(sellmeier, n_clad) print(NA_inst(omega)) n_core: float = sellmeier(omega) NA_inst = oc.NumericalAperture(n_core, n_clad) NA: float = NA_inst(omega) print(NA, oc.NumericalAperture.calc_NA(n_core, n_clad)) print(n_core, oc.NumericalAperture.calc_n_core(NA, n_clad)) print(n_clad, oc.NumericalAperture.calc_n_clad(NA, n_core)) # With numpy ndarray lambdas: np.ndarray = np.linspace(900, 1550, 100) omegas: np.ndarray = oc.lambda_to_omega(lambdas) NA_inst = oc.NumericalAperture(sellmeier, n_clad) res: np.ndarray = NA_inst(omegas) x_labels: List[str] = ['Lambda'] y_labels: List[str] = ['Numerical aperture'] plot_titles: List[str] = ["Numercial aperture as a function of the " "wavelength \n for Silica core with constant " "cladding refractive index."] oc.plot2d([lambdas], [res], x_labels=x_labels, y_labels=y_labels, plot_titles=plot_titles, line_opacities=[0.0], y_ranges=[(0.1, 0.2)])
width=[10.0], field_name='field 2 to be saved in file') field_saver_2: oc.SaveFieldToFile = oc.SaveFieldToFile(file_name=file_name, add_fields=True, root_dir=root_dir) 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] = [] with open(file_name, 'rb') as file_to_load: fields.append(pickle.load(file_to_load)[0]) fields.append(pickle.load(file_to_load)[0]) x_datas: List[np.ndarray] = [ fields[0].time, fields[1].time, fields[0].nu, fields[1].nu ] y_datas: List[np.ndarray] = [ oc.temporal_power(fields[0].channels), oc.temporal_power(fields[1].channels), oc.spectral_power(fields[0].channels), oc.spectral_power(fields[1].channels) ] oc.plot2d(x_datas, y_datas, x_labels=["t", "t", "nu", "nu"], y_labels=["P_t", "P_t", "P_nu", "P_nu"], plot_titles=["Gaussian pulse which has been saved"], plot_groups=[0, 0, 1, 1])
order: List[int] = [1, 2, 1] chirp: List[float] = [0.0, 0.5, 0.1] init_phi: List[float] = [0.0, 1.0, 0.0] gssn = oc.Gaussian(channels=channels, center_lambda=center_lambda, position=position, width=width, peak_power=peak_power, rep_freq=rep_freq, offset_nu=offset_nu, order=order, chirp=chirp, init_phi=init_phi, save=True) lt.run(gssn) x_datas: List[np.ndarray] = [gssn[0][0].time, gssn[0][0].nu] y_datas: List[np.ndarray] = [ oc.temporal_power(gssn[0][0].channels), oc.spectral_power(gssn[0][0].channels) ] oc.plot2d(x_datas, y_datas, x_labels=["t", "nu"], y_labels=["P_t", "P_nu"], plot_titles=["Gaussian pulse"], split=True)