change: dispersion wl shrinked
the wavelength vector used for dipserion calculation has been shrinked. The new way to determine dt via wavelength_window made it so that there wasn't 2 extra points to take gradients with.
This commit is contained in:
@@ -34,21 +34,14 @@ def lambda_for_envelope_dispersion(
|
||||
indices of the original l where the values are valid
|
||||
(i.e. without the two extra on each side)
|
||||
"""
|
||||
su = np.where((l >= wavelength_window[0]) & (l <= wavelength_window[1]))[0]
|
||||
if l[su].min() > 1.01 * wavelength_window[0]:
|
||||
raw_indices = np.where((l >= wavelength_window[0]) & (l <= wavelength_window[1]))[0]
|
||||
if l[raw_indices].min() > 1.01 * wavelength_window[0]:
|
||||
raise ValueError(
|
||||
f"lower range of {1e9*wavelength_window[0]:.1f}nm is not reached by the grid. "
|
||||
f"Minimum of grid is {1e9*l[su].min():.1f}nm. Try a finer grid"
|
||||
f"Minimum of grid is {1e9*l[raw_indices].min():.1f}nm. Try a finer grid"
|
||||
)
|
||||
|
||||
ind_above_cond = su >= len(l) // 2
|
||||
ind_above = su[ind_above_cond]
|
||||
ind_below = su[~ind_above_cond]
|
||||
fu = np.concatenate((ind_below, (ind_below + 2)[-2:], (ind_above - 2)[:2], ind_above))
|
||||
fs = fu[np.argsort(l[fu])[::-1]]
|
||||
l_out = l[fs]
|
||||
ind_out = fs[2:-2]
|
||||
return l_out, ind_out
|
||||
sorted_ind = raw_indices[np.argsort(l[raw_indices])]
|
||||
return l[sorted_ind], sorted_ind[2:-2]
|
||||
|
||||
|
||||
def lambda_for_full_field_dispersion(
|
||||
|
||||
22
tests/test_grid.py
Normal file
22
tests/test_grid.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
import scgenerator as sc
|
||||
|
||||
|
||||
def test_scaling():
|
||||
period = 2
|
||||
nt = 512
|
||||
t = sc.tspace(period, nt)
|
||||
w = sc.wspace(t)
|
||||
dt = t[1] - t[0]
|
||||
assert w[1] - w[0] == pytest.approx(2 * np.pi / (period + dt))
|
||||
assert dt == pytest.approx(period / (nt - 1))
|
||||
|
||||
|
||||
def test_wl_dispersion():
|
||||
t = sc.tspace(t_num=1 << 15, dt=3.8e-15)
|
||||
w = sc.wspace(t)
|
||||
wl = sc.units.m.inv(w + sc.units.nm(1546))
|
||||
wl_disp, ind_disp = sc.fiber.lambda_for_envelope_dispersion(wl, (950e-9, 4000e-9))
|
||||
assert all(np.diff(wl_disp) > 0)
|
||||
Reference in New Issue
Block a user