Skip to content

Commit

Permalink
add: plot of pulse collisions with dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzifrancesco committed Jan 22, 2025
1 parent 0f9db5a commit 2c6bd6f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 63 deletions.
3 changes: 3 additions & 0 deletions scripts/debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Just a debug script for functionalities
"""
import numpy as np
import matplotlib.pyplot as plt

Expand Down
85 changes: 85 additions & 0 deletions scripts/modules/plot_collisions_fig1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import numpy as np
from pynlin.nlin import m_th_time_integral_general
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
import os

formatter = ScalarFormatter()
formatter.set_scientific(True)
formatter.set_powerlimits([0, 0])


def plot_illustrative(fiber, pulse, wdm, recompute=False):
"""
Plot of Marco
"""
print("Plotting Fig.1 (pulse collisions)...")
m = [-10, -90]
dgds = [1e-12, 1e-12]
m1 = -10
m2 = -90
dgd_hi = 100e-15
dgd_lo = 1e-16
beta2a = -35e-27 # TODO, check con Marco
beta2b = -75e-27
z = np.linspace(0, fiber.length, 1000)
# 1. the two pulses
cases = [(dgd_hi, beta2a, beta2b, m1),
(dgd_hi, beta2a, beta2b, m2),]
I_list = []
for dgd, beta2a, beta2b, m in cases:
I = np.real(m_th_time_integral_general(pulse, fiber, wdm, (0, 0), (0, 0), 0.0, m, z, dgd, None, beta2a, beta2b))
I_list.append(I)

# 2. the set of pulse peaks:
zw = 1/(pulse.baud_rate * dgd_hi)
m_max = fiber.length / zw
print(f" > m_max: {m_max}")
m_axis = -np.array(range(int(round(m_max))))
peaks = np.zeros(2)[np.newaxis, :].repeat(len(m_axis), axis=0)
z_peaks = np.zeros(2)[np.newaxis, :].repeat(len(m_axis), axis=0)
#
if not os.path.exists("results/fig1_peaks.npy") or recompute:
print(" Computing peaks...")
for im, m in enumerate(m_axis):
print(f" m: {m:>10}")
for ic, (dgd, beta2a, beta2b, _) in enumerate(cases):
I = np.real(m_th_time_integral_general(pulse, fiber, wdm, (0, 0), (0, 0), 0.0, m, z, dgd_hi, None, beta2a, beta2b))
peaks[im, ic] = np.max(I)
z_peaks[im, ic] = z[np.argmax(I)]
np.save("results/fig1_peaks.npy", (peaks, z_peaks))
print(" Done computing and saving peaks.")
else:
print(" Loading peaks...")
peaks, z_peaks = np.load("results/fig1_peaks.npy")
print(" Done loading peaks.")


# 3. Plotting
cases = [(dgd_hi, beta2a, beta2a, m1),
(dgd_lo, beta2b, beta2b, m2),]
colors = ["blue", "grey"]
plt.figure(figsize=(4, 3))
# plotting the pulses
for I in I_list:
plt.plot(z*1e-3, I*1e-12, label=f'try', color="red")
# plotting the peaks
for ip, (peak, z_peak) in enumerate(zip(peaks, z_peaks)):
# print(peak, z_peak)
for ic in range(len(cases)):
if ip == 0:
plt.plot(z_peak[ic]*1e-3, peak[ic]*1e-12,
marker="x",
markersize=0.1,
label='case'+str(ic),
color=colors[ic])
plt.plot(z_peak[ic]*1e-3, peak[ic]*1e-12,
marker="x",
color=colors[ic])
plt.legend()
plt.xlabel(r'$z \; [\mathrm{km}]$')
plt.ylabel(r'$I(z) \; [\mathrm{ps^{-1}}]$')
plt.gca().yaxis.set_major_formatter(formatter)
plt.tight_layout()
plt.savefig("media/1-quovadis.pdf")
print("Done plotting Fig.1.")
81 changes: 18 additions & 63 deletions scripts/noise.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,28 @@
"""
script for finding the overall noise on a single channel
given a fiber link configuration consisting
Finds the overall noise on a single channel
given a fiber link configuration.
Generates figs:
- Statistics of channels over DGD
- NLIN thresholding and approximation
TODO:
- Final computation of the noise including the fB
"""
import pynlin.fiber
from scripts.modules.space_integrals_general import *
from scripts.modules.time_integrals import do_time_integrals
from scripts.modules.load_fiber_values import *
import matplotlib.pyplot as plt
import scipy
import pynlin.fiber
from pynlin.nlin import m_th_time_integral_general
import pynlin.wdm
import pynlin.pulses
from scripts.modules.load_fiber_values import load_group_delay
from modules import cfg
from matplotlib.ticker import ScalarFormatter
formatter = ScalarFormatter()
formatter.set_scientific(True)
formatter.set_powerlimits([0, 0])

def plot_illustrative(fiber, pulse, wdm):
"""
Plot an illustrative case of the time integrals.
"""
m = [-10, -90]
dgds = [1e-12, 1e-12]
m1 = -10
m2 = -90
dgd_hi = 100e-15
dgd_lo = 1e-16
beta2a = -75e-27 # TODO , CHECK
beta2b = -75e-27
z = np.linspace(0, fiber.length, 1000)
# cases=[(dgd, beta2a, beta2b, m),
cases = [(dgd_hi, beta2a, beta2b, m1),
(dgd_hi, beta2a, beta2b, m2),]
I_list = []
for dgd, beta2a, beta2b, m in cases:
I = np.real(m_th_time_integral_general(pulse, fiber, wdm, (0, 0), (0, 0), 0.0, m, z, dgd, None, beta2a, beta2b))
I_list.append(I)

plt.figure(figsize=(4, 3))
for I in I_list:
plt.plot(z*1e-3, I*1e-12, label=f'try')
plt.xlabel(r'$z \; [\mathrm{km}]$')
plt.ylabel(r'$I(z) \; [\mathrm{ps^{-1}}]$')
plt.gca().yaxis.set_major_formatter(formatter)
plt.tight_layout()
plt.savefig("media/quo_vadis.pdf")


from modules.plot_collisions_fig1 import plot_illustrative

cf = cfg.load_toml_to_struct("./input/config_collision.toml")
oi_fit = np.load('oi_fit.npy')
oi_avg = np.load('oi_avg.npy')
Expand All @@ -72,8 +45,6 @@ def plot_illustrative(fiber, pulse, wdm):
n_modes = 4
)

# print(f"beta_2 = {beta2:.9e}")

# make the time integral take as an input (pulse, fiber, wdm)
pulse = pynlin.pulses.GaussianPulse(
baud_rate=cf.baud_rate,
Expand All @@ -93,25 +64,9 @@ def plot_illustrative(fiber, pulse, wdm):
# print(l_freq * 1e-12)
delta = (s_freq - l_freq) * 1e-12
avg = ((s_freq + l_freq) * 1e-12 / 2)
# beta_file = './results/fitBeta.mat'
# mat = scipy.io.loadmat(beta_file)['fitParams'] * 1.0

# beta_file = './results/fitBeta.mat'
# omega = 2 * np.pi * freqs
# omega_norm = scipy.io.loadmat(beta_file)['omega_std']
# omega_n = (omega - scipy.io.loadmat(beta_file)['omega_mean']) / omega_norm
# beta1 = np.zeros((4, len(freqs)))

# write the results file in ../results/general_results.h5 with the correct time integrals
# the file contains, for each interferent channel, the values (z, m, I) of the z
# channel of interest is set to channel 0, and interferent channel index start from 0 for simplicity
# a_chan = (0, 0)
# print("@@@@@@@@ Time integrals @@@@@@@@")
# # do_time_integrals(a_chan, fiber, wdm, pulse, overwrite=True)
# print("@@@@@@@@ Space integrals @@@@@@@@")
# b_chan = (1, 99)
# print("dgd: ", pynlin.nlin.get_dgd(a_chan, b_chan, fiber, wdm))

### Manually set the DGD and beta2 values for both the channels
plot_illustrative(fiber, pulse, wdm)
# compare_interferent(fiber, wdm, pulse, dgd=dgd, beta2a=beta2a, beta2b=beta2b)
plot_illustrative(fiber,
pulse,
wdm,
recompute=True)
8 changes: 8 additions & 0 deletions scripts/optimize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
Optimize the pumps and calculate signal and ASE power evolution
Generates figs:
- Power profiles
"""
import os
import tqdm
from multiprocessing import Pool
Expand Down
4 changes: 4 additions & 0 deletions scripts/watch_convergence.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
When run in background, continously
update a plot of the final channel on off gain.
"""
import numpy as np
import matplotlib.pyplot as plt
from watchdog.observers import Observer
Expand Down

0 comments on commit 2c6bd6f

Please sign in to comment.