Skip to content

Commit

Permalink
change: plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzifrancesco committed Dec 3, 2024
1 parent 602b4c0 commit ee90ab8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 50 deletions.
4 changes: 2 additions & 2 deletions pynlin/nlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def i_func(m, z): return m_th_time_integral_Gaussian(
margin = 10
if isinstance(pulse, NyquistPulse):
print("\033[91m warn: \033[0m The pulse is Nyquist (long-tailed): overriding the number of points!")
n_z_points = 5000
margin = 100
n_z_points = 500
margin = 0

for m in m_list:
print("_"*40)
Expand Down
27 changes: 14 additions & 13 deletions scripts/modules/beta_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@

plt.clf()
for i in range(len(modes)):
plt.semilogy(freqs * 1e-12, nlin_no_cross[i, :], label=mode_names[i], marker='x')
plt.semilogy(freqs * 1e-12, nlin_no_cross[i, :]*1e-30, label=mode_names[i], marker='x')
plt.xlabel('Frequency (THz)')
plt.ylabel('NLIN coeff')
plt.legend()
Expand All @@ -154,38 +154,39 @@
# plt.show()

plt.clf()
plt.figure(figsize=(4, 3.5))
for i in range(4):
plt.semilogy(freqs * 1e-12, nlin[i, :], label=mode_names[i], marker='x')
plt.xlabel('Frequency (THz)')
plt.ylabel('NLIN coeff')
plt.semilogy(freqs * 1e-12, nlin[i, :] * 1e-30, label=mode_names[i], marker='o', ms=2.5, lw=1)
plt.xlabel(r'$f \; [\mathrm{THz}]$')
plt.ylabel(r'$\mathrm{NLIN} \; [\mathrm{km}^2/\mathrm{ps}^{2}]$')
plt.legend()
plt.grid(grid)
plt.tight_layout()
plt.savefig(f"media/dispersion/nlin.png", dpi=dpi)
# plt.show()

plt.clf()
plt.figure(figsize=(4.6, 4))
plt.figure(figsize=(4, 3.5))
for i in range(4):
plt.plot(freqs * 1e-12, beta1[i, :] * 1e9, label=mode_names[i], marker="+", markersize=5)
plt.plot(freqs * 1e-12, beta1[i, :] * 1e9, label=mode_names[i], marker="o", ms=2, lw=1)
minn = np.min(beta1)
maxx = np.max(beta1)

# plt.axvline(205.5, color="gray", ls="dashed" , lw=0.5)
# plt.axvline(196.07, color="gray", ls="dashed", lw=0.5)
# plt.axvline(191.69, color="gray", ls="dashed", lw=0.5)

plt.axvline(190.9, color="red", ls="dotted", lw=1.5)
plt.axvline(200.9, color="red", ls="dotted", lw=1.5)
plt.axvline(190.9, color="grey", ls="--", lw=1.5)
plt.axvline(200.9, color="grey", ls="--", lw=1.5)

# # plt.xticks([185, 193, 196, 206])
# freq_boundaries = [189, 192.7, 197, 206]
# for i, label in enumerate(['L', 'C', 'S', 'E']):
# plt.text(freq_boundaries[i], 4.8924, label, ha='center', va='bottom')

plt.xlabel('Frequency (THz)')
plt.ylabel(r'$\beta_1$ (ns/m)')
plt.legend()
plt.xlabel(r'$f \; [\mathrm{THz}]$')
plt.ylabel(r'$\beta_1 [\mathrm{ns}/\mathrm{m}]$')
# plt.legend()
# plt.grid(grid)
plt.tight_layout()
plt.savefig(f"media/dispersion/beta1.png", dpi=dpi)
Expand All @@ -195,7 +196,7 @@

for i in range(4):
plt.plot(freqs * 1e-12, beta2[i, :] * 1e27, label=mode_names[i])
plt.xlabel('Frequency (THz)')
plt.xlabel(r'$f \; [\mathrm{THz}]$')
plt.ylabel(r'$\beta_2$ (ps$^2$/km)')
plt.legend()
# plt.grid(grid)
Expand Down Expand Up @@ -259,7 +260,7 @@
for i in range(4):
plt.plot(freqs * 1e12, (beta1[i, :] - beta1[1, :])
* 1e12, label=mode_names[i])
plt.xlabel('Frequency (THz)')
plt.xlabel(r'$f \; [\mathrm{THz}]$')
plt.ylabel(r'$\Delta\beta_1$ (ps/m)')
plt.legend()
plt.grid(grid)
Expand Down
110 changes: 75 additions & 35 deletions scripts/modules/nlin_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from numpy import polyval
from pynlin.fiber import *
from pynlin.pulses import *
from pynlin.nlin import compute_all_collisions_time_integrals, get_dgd, X0mm_space_integral
from pynlin.nlin import compute_all_collisions_time_integrals, get_dgd, X0mm_space_integral, get_gvd
from matplotlib.gridspec import GridSpec
import json
rc('text', usetex=True)
Expand Down Expand Up @@ -58,7 +58,7 @@ def get_space_integrals(m, z, I):
return X0mm


beta1_params = load_dummy_group_delay()
beta1_params = load_group_delay()

dpi = 300
grid = False
Expand Down Expand Up @@ -88,47 +88,87 @@ def get_space_integrals(m, z, I):
beta1 = np.array(beta1)
beta2 = np.array(beta2)

pulse = GaussianPulse(
baud_rate=baud_rate,
num_symbols=1e2,
samples_per_symbol=2**5,
rolloff=0.0,
)

n_samples_analytic = 500
n_samples_numeric = 10
dgd1 = 1e-16
dgd2 = 6e-12
# 6e-9 for our fiber
dgds_numeric = np.logspace(np.log10(dgd1), np.log10(dgd2), n_samples_numeric)
dgds_analytic = np.linspace(dgd1, dgd2, n_samples_analytic)
for px in [1, 0]:
if px == 0:
pulse = GaussianPulse(
baud_rate=baud_rate,
num_symbols=1e2,
samples_per_symbol=2**5,
rolloff=0.0,
)
else:
pulse = NyquistPulse(
baud_rate=baud_rate,
num_symbols=1e2,
samples_per_symbol=2**5,
rolloff=0.0,
)

n_samples_analytic = 500
dgd1 = 1e-16
if px == 0:
dgd2 = 6e-12
n_samples_numeric = 10
else:
dgd2 = 1e-15
n_samples_numeric = 3
# 6e-9 for our fiber
dgds_numeric = np.logspace(np.log10(dgd1), np.log10(dgd2), n_samples_numeric)
dgds_analytic = np.linspace(dgd1, dgd2, n_samples_analytic)

zwL_numeric = 1 / (pulse.baud_rate * dgds_numeric * dummy_fiber.length)
zwL_analytic = 1 / (pulse.baud_rate * dgds_analytic * dummy_fiber.length)
zwL_numeric = 1 / (pulse.baud_rate * dgds_numeric * dummy_fiber.length)
zwL_analytic = 1 / (pulse.baud_rate * dgds_analytic * dummy_fiber.length)

partial_nlin = np.zeros(n_samples_numeric)
if False:
for id, dgd in enumerate(dgds_numeric):
# print(f"DGD: {dgd:10.3e}")
z, I, m = compute_all_collisions_time_integrals(
(-1, -1), (-1, -1), dummy_fiber, wdm, pulse, dgd)
# space integrals
X0mm = get_space_integrals(m, z, I)
partial_nlin[id] = np.sum(X0mm**2)
np.save("results/partial_nlin.npy", partial_nlin)
partial_nlin = np.zeros(n_samples_numeric)
a_chan = (-1, -10)
b_chan = (-1, -100)
if False:
for id, dgd in enumerate(dgds_numeric):
# print(f"DGD: {dgd:10.3e}")
z, I, m = compute_all_collisions_time_integrals(
a_chan, b_chan, dummy_fiber, wdm, pulse, dgd)
# space integrals
X0mm = get_space_integrals(m, z, I)
partial_nlin[id] = np.sum(X0mm**2)
if px == 0:
np.save("results/partial_nlin_gaussian.npy", partial_nlin)
else:
np.save("results/partial_nlin_nyquist.npy", partial_nlin)

partial_nlin = np.load("results/partial_nlin.npy")
T = 100e-12
L = dummy_fiber.length
print(partial_nlin)
LDA = - T**2 / get_gvd(a_chan, dummy_fiber, wdm)
LDB = - T**2 / get_gvd(b_chan, dummy_fiber, wdm)
LD_eff = np.sqrt(2) * LDA * LDB / (LDA**2 + LDB**2)
print(LD_eff)
partial_nlin_nyquist = np.load("results/partial_nlin_nyquist.npy")
partial_nlin_gaussian = np.load("results/partial_nlin_gaussian.npy")
LD_eff = LDA
print(f"L/LD_eff = {L/LDA:.2e}, LDA = {LDA:.2e}, LDB = {LDB:.2e}")
# print(partial_nlin)
fig = plt.figure(figsize=(4, 3)) # Overall figure size
analytic_nlin = L / (T * dgds_analytic)
# plt.plot( zwL_analytic, analytic_nlin * 1e-30, color='red', label='approximation')
# plt.scatter(zwL_numeric, partial_nlin * 1e-30, color='green', label='numerics', marker="x")
# plt.xlabel('$z_W/L$')
# plt.gca().invert_xaxis() # Inverts the x-axis
plt.plot( dgds_analytic*1e12, analytic_nlin * 1e-30, color='red', label='approximation')
plt.scatter(dgds_numeric*1e12, partial_nlin * 1e-30, color='green', label='numerics', marker="x")
dgd2 = 6e-12
n_samples_numeric = 10
dgds_numeric_g = np.logspace(np.log10(dgd1), np.log10(dgd2), n_samples_numeric)
dgd2 = 1e-15
n_samples_numeric = 3
dgds_numeric_n = np.logspace(np.log10(dgd1), np.log10(dgd2), n_samples_numeric)

plt.plot(dgds_analytic * 1e12, analytic_nlin *
1e-30, color='red', label='Antonio')
plt.plot(dgds_analytic * 1e12, np.ones_like(dgds_analytic) * (LD_eff / (T * np.sqrt(2 * np.pi))
* np.arcsinh(L / LD_eff))**2 * 1e-30, color='blue', label='Fra')
plt.plot(dgds_analytic * 1e12, np.ones_like(dgds_analytic) * (L / T * 1/(6*np.pi**2))**2
* 1e-30, color='blue', ls="--", label='Marco')
plt.scatter(dgds_numeric_g * 1e12, partial_nlin_gaussian * 1e-30,
color='green', label='Gaussian', marker="x")
plt.scatter(dgds_numeric_n * 1e12, partial_nlin_nyquist * 1e-30,
color='grey', label='Nyquist', marker="x
plt.xlabel('DGD [ps/m]')
plt.legend()
plt.yscale('log')
Expand All @@ -138,11 +178,11 @@ def get_space_integrals(m, z, I):
plt.savefig(f"media/dispersion/partial_NLIN.png", dpi=dpi)

fig = plt.figure(figsize=(4, 3)) # Overall figure size
er = ((L/(T*dgds_numeric))-partial_nlin)/partial_nlin
plt.plot(dgds_numeric*1e12, np.where(er<0.25, er, np.nan), color='red')
er = ((L / (T * dgds_numeric)) - partial_nlin) / partial_nlin
plt.plot(dgds_numeric * 1e12, np.where(er < 0.25, er, np.nan), color='red')
plt.legend()
plt.ylabel('partial NLIN')
plt.xlabel('DGD (ps/m)')
plt.tight_layout()
plt.xscale('log')
plt.savefig(f"media/dispersion/rel_error_of_mecozzi.png", dpi=dpi)
plt.savefig(f"media/dispersion/rel_error_of_mecozzi.png", dpi=dpi)

0 comments on commit ee90ab8

Please sign in to comment.