moved examples

This commit is contained in:
2024-02-23 10:27:43 +01:00
parent afe348ebb9
commit 0e3be8fa9f
3 changed files with 40 additions and 33 deletions

View File

@@ -1,3 +1,4 @@
import click
import colorcet as cc import colorcet as cc
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
@@ -6,6 +7,7 @@ from plotapp import PlotApp
import scgenerator as sc import scgenerator as sc
params = sc.Parameters( params = sc.Parameters(
name="Dudley2006 example",
wavelength=835e-9, wavelength=835e-9,
width=50e-15, width=50e-15,
peak_power=10e3, peak_power=10e3,
@@ -35,14 +37,12 @@ params = sc.Parameters(
) )
def compute_manual(): def compute_manual(save: bool):
spec0 = params.compute("spec_0") spec0 = params.compute("spec_0")
w_c, w0, gamma = params.compute("w_c", "w0", "gamma") w_c, w0, gamma = params.compute("w_c", "w0", "gamma")
p = params.compile() p = params.compile()
print(p.dt) print(p.dt)
beta_op = sc.operators.constant_polynomial_dispersion( beta_op = sc.operators.constant_polynomial_dispersion(params.beta2_coefficients, w_c)
params.beta2_coefficients, w_c, params.compute("dispersion_ind")
)
linear = sc.operators.envelope_linear_operator( linear = sc.operators.envelope_linear_operator(
beta_op, beta_op,
# sc.operators.constant_quantity(0), # sc.operators.constant_quantity(0),
@@ -94,7 +94,10 @@ def compute_manual():
def linear(_): def linear(_):
return linear_arr return linear_arr
if save:
prop = sc.propagation("examples/dudley_manual.zip", params) prop = sc.propagation("examples/dudley_manual.zip", params)
else:
prop = sc.propagation(params)
z = [] z = []
for i, (spec, stat) in enumerate( for i, (spec, stat) in enumerate(
sc.solve43(spec0, linear, nonlinear, params.length, 1e-6, 1e-6, 0.9, h_const=20e-6) sc.solve43(spec0, linear, nonlinear, params.length, 1e-6, 1e-6, 0.9, h_const=20e-6)
@@ -106,8 +109,11 @@ def compute_manual():
z.append(stat["z"]) z.append(stat["z"])
def compute_auto(): def compute_auto(save: bool):
if save:
sc.compute(params, True, "examples/dudley2006") sc.compute(params, True, "examples/dudley2006")
else:
sc.compute(params)
def plot(): def plot():
@@ -120,6 +126,15 @@ def plot():
plt.show() plt.show()
if __name__ == "__main__": @click.command()
# compute_auto() @click.option("--show/--no-show", default=False)
@click.option("--save/--no-save", default=False)
def main(show: bool, save: bool):
compute_manual(save)
compute_auto(save)
if show:
plot() plot()
if __name__ == "__main__":
main()

View File

@@ -1,6 +1,7 @@
""" """
series of helper functions series of helper functions
""" """
import os import os
import warnings import warnings
from pathlib import Path from pathlib import Path
@@ -166,19 +167,17 @@ def extend_axis(axis: np.ndarray) -> np.ndarray:
def compute( def compute(
parameters: Parameters, overwrite: bool = False, output: os.PathLike | None = None parameters: Parameters, overwrite: bool = False, output: os.PathLike | None = None
) -> Propagation: ) -> Propagation:
prop_params = parameters.compile()
if output is None: if output is None:
name = Path(parameters.compute("name")).stem + ".zip" prop = propagation(prop_params)
else: else:
path = Path(output) path = Path(output)
name = path.parent / (path.stem + ".zip") name = path.parent / (path.stem + ".zip")
prop_params = parameters.compile()
prop = propagation(name, prop_params, bundle_data=True, overwrite=overwrite) prop = propagation(name, prop_params, bundle_data=True, overwrite=overwrite)
with warnings.catch_warnings(), tqdm(total=prop_params.z_num) as pbar: with warnings.catch_warnings(), tqdm(total=prop_params.z_num) as pbar:
warnings.filterwarnings("error") warnings.filterwarnings("error")
for i, (spec, new_stat) in enumerate( for spec, _ in solve43(
solve43(
prop_params.spec_0, prop_params.spec_0,
prop_params.linear_operator, prop_params.linear_operator,
prop_params.nonlinear_operator, prop_params.nonlinear_operator,
@@ -187,7 +186,6 @@ def compute(
prop_params.tolerated_error, prop_params.tolerated_error,
0.9, 0.9,
targets=prop_params.z_targets, targets=prop_params.z_targets,
)
): ):
pbar.update() pbar.update()
prop.append(spec) prop.append(spec)

View File

@@ -22,16 +22,10 @@ c = 299792458.0
def fft_functions( def fft_functions(
full_field: bool, full_field: bool,
) -> tuple[Callable[[np.ndarray], np.ndarray], Callable[[np.ndarray], np.ndarray]]: ) -> tuple[Callable[[np.ndarray], np.ndarray], Callable[[np.ndarray], np.ndarray]]:
if platform.processor() == "arm":
if full_field: if full_field:
return sfft.rfft, sfft.irfft return sfft.rfft, sfft.irfft
else: else:
return sfft.fft, sfft.ifft return sfft.fft, sfft.ifft
else:
if full_field:
return np.fft.rfft, np.fft.irfft
else:
return np.fft.fft, np.fft.ifft
def expm1_int(y: np.ndarray, dx: float) -> np.ndarray: def expm1_int(y: np.ndarray, dx: float) -> np.ndarray: