From 7c0daa07876c13372bf12cf1efde24790aaa19b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Sierro?= Date: Fri, 4 Jun 2021 14:41:56 +0200 Subject: [PATCH] wl shift issue --- README.md | 5 +++++ src/scgenerator/cli/cli.py | 2 +- src/scgenerator/const.py | 10 +++++++++- src/scgenerator/defaults.py | 1 + src/scgenerator/initialize.py | 10 ++++++---- src/scgenerator/physics/simulate.py | 6 +++++- src/scgenerator/utils.py | 5 +---- testing/configs/custom_field/mean_power.toml | 1 + testing/configs/custom_field/no_change.toml | 1 + testing/configs/custom_field/peak_power.toml | 1 + testing/configs/custom_field/recover1.toml | 1 + testing/configs/custom_field/recover2.toml | 1 + testing/configs/custom_field/wavelength_shift1.toml | 1 + testing/configs/custom_field/wavelength_shift2.toml | 1 + 14 files changed, 35 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index dcc944e..6a74718 100644 --- a/README.md +++ b/README.md @@ -251,3 +251,8 @@ upper_wavelength_interp_limit: float sets the lowest end of this range. If the set value is higher than the higher end of the wavelength window, it is lowered down to that point. default : 1900e-9 +readjust_wavelength : bool + if a custom input field is set, it is likely that the maximum of its corresponding spectrum doesn't lies exactly at the + set wavelength. If this setting is True, the program will override the wavelength parameter so that the maximum of the spectrum + lies on the desired wavelength. + diff --git a/src/scgenerator/cli/cli.py b/src/scgenerator/cli/cli.py index 58fafdc..11a5398 100644 --- a/src/scgenerator/cli/cli.py +++ b/src/scgenerator/cli/cli.py @@ -79,7 +79,7 @@ def merge(args): path_trees = io.build_path_trees(Path(args.path)) if args.output_name is None: - args.output_name = path_trees[-1][0][0].parent.name + " merged" + args.output_name = path_trees[0][-1][0].parent.name + " merged" io.merge(args.output_name, path_trees) diff --git a/src/scgenerator/const.py b/src/scgenerator/const.py index c80359f..226dfff 100644 --- a/src/scgenerator/const.py +++ b/src/scgenerator/const.py @@ -195,6 +195,7 @@ valid_param_types = dict( upper_wavelength_interp_limit=in_range_excl(num, (100e-9, 5000e-9)), frep=num, prev_sim_dir=string(), + readjust_wavelength=boolean, ), ) @@ -242,7 +243,14 @@ valid_variable = dict( "width", "soliton_num", ], - simulation=["behaviors", "raman_type", "tolerated_error", "step_size", "ideal_gas"], + simulation=[ + "behaviors", + "raman_type", + "tolerated_error", + "step_size", + "ideal_gas", + "readjust_wavelength", + ], ) ENVIRON_KEY_BASE = "SCGENERATOR_" diff --git a/src/scgenerator/defaults.py b/src/scgenerator/defaults.py index 530862e..f414b25 100644 --- a/src/scgenerator/defaults.py +++ b/src/scgenerator/defaults.py @@ -27,6 +27,7 @@ default_parameters = dict( lower_wavelength_interp_limit=300e-9, upper_wavelength_interp_limit=1900e-9, ideal_gas=False, + readjust_wavelength=False, ) default_plotting = dict( diff --git a/src/scgenerator/initialize.py b/src/scgenerator/initialize.py index bc71476..9bf761e 100644 --- a/src/scgenerator/initialize.py +++ b/src/scgenerator/initialize.py @@ -511,6 +511,7 @@ def _ensure_consistency_simulation(simulation): "lower_wavelength_interp_limit", "upper_wavelength_interp_limit", "ideal_gas", + "readjust_wavelength", ]: simulation = defaults.get(simulation, param) @@ -715,10 +716,11 @@ def setup_custom_field(params: Dict[str, Any]) -> bool: params["width"], params["peak_power"], params["energy"] = pulse.measure_field( params["t"], params["field_0"] ) - delta_w = params["w_c"][np.argmax(abs2(np.fft.fft(params["field_0"])))] - logger.debug(f"adjusted w by {delta_w}") - params["wavelength"] = units.m.inv(units.m(params["wavelength"]) - delta_w) - _update_frequency_domain(params) + if params.get("readjust_wavelength", False): + delta_w = params["w_c"][np.argmax(abs2(np.fft.fft(params["field_0"])))] + logger.debug(f"adjusted w by {delta_w}") + params["wavelength"] = units.m.inv(units.m(params["wavelength"]) - delta_w) + _update_frequency_domain(params) return True diff --git a/src/scgenerator/physics/simulate.py b/src/scgenerator/physics/simulate.py index 523d532..3f6cf87 100644 --- a/src/scgenerator/physics/simulate.py +++ b/src/scgenerator/physics/simulate.py @@ -75,7 +75,7 @@ class RK4IP: self.sim_dir = io.get_sim_dir(self.id) self.sim_dir.mkdir(exist_ok=True) - self.data_dir = self.sim_dir/self.job_identifier + self.data_dir = self.sim_dir / self.job_identifier self.n_percent = n_percent self.logger = get_logger(self.job_identifier) @@ -698,6 +698,10 @@ def run_simulation_sequence( sim.run() prev = sim.sim_dir path_trees = io.build_path_trees(sim.sim_dir) + + if final_name is None: + final_name = path_trees[0][-1][0].parent.name + " merged" + io.merge(final_name, path_trees) diff --git a/src/scgenerator/utils.py b/src/scgenerator/utils.py index f4f6a98..94ab6d9 100644 --- a/src/scgenerator/utils.py +++ b/src/scgenerator/utils.py @@ -66,10 +66,7 @@ class PBars: def print(self): if "file" not in self.policy: return - if len(self.pbars) > 1: - s = [""] - else: - s = [] + s = [] for pbar in self.pbars: s.append(str(pbar)) self.print_path.write_text("\n".join(s)) diff --git a/testing/configs/custom_field/mean_power.toml b/testing/configs/custom_field/mean_power.toml index 953ec5c..f8aa27e 100644 --- a/testing/configs/custom_field/mean_power.toml +++ b/testing/configs/custom_field/mean_power.toml @@ -2,6 +2,7 @@ dt = 1e-15 field_file = "testing/configs/custom_field/init_field.npz" length = 1 mean_power = 220e-3 +readjust_wavelength = true repetition_rate = 40e6 t_num = 2048 wavelength = 1000e-9 diff --git a/testing/configs/custom_field/no_change.toml b/testing/configs/custom_field/no_change.toml index 288b1fb..7340c20 100644 --- a/testing/configs/custom_field/no_change.toml +++ b/testing/configs/custom_field/no_change.toml @@ -1,6 +1,7 @@ dt = 1e-15 field_file = "testing/configs/custom_field/init_field.npz" length = 1 +readjust_wavelength = true t_num = 2048 wavelength = 1000e-9 z_num = 32 diff --git a/testing/configs/custom_field/peak_power.toml b/testing/configs/custom_field/peak_power.toml index 5ce44f8..5a0509a 100644 --- a/testing/configs/custom_field/peak_power.toml +++ b/testing/configs/custom_field/peak_power.toml @@ -2,6 +2,7 @@ dt = 1e-15 field_file = "testing/configs/custom_field/init_field.npz" length = 1 peak_power = 20000 +readjust_wavelength = true t_num = 2048 wavelength = 1593e-9 z_num = 32 diff --git a/testing/configs/custom_field/recover1.toml b/testing/configs/custom_field/recover1.toml index 52400f3..ad4dd7f 100644 --- a/testing/configs/custom_field/recover1.toml +++ b/testing/configs/custom_field/recover1.toml @@ -2,6 +2,7 @@ dt = 1e-15 input_transmission = 1 length = 1 prev_data_dir = "testing/configs/custom_field/recover_data" +readjust_wavelength = true t_num = 2048 wavelength = 1000e-9 z_num = 32 diff --git a/testing/configs/custom_field/recover2.toml b/testing/configs/custom_field/recover2.toml index 853b8ea..5652c87 100644 --- a/testing/configs/custom_field/recover2.toml +++ b/testing/configs/custom_field/recover2.toml @@ -2,6 +2,7 @@ dt = 1e-15 input_transmission = 0.9 length = 1 prev_data_dir = "testing/configs/custom_field/recover_data" +readjust_wavelength = true t_num = 2048 wavelength = 1000e-9 z_num = 32 diff --git a/testing/configs/custom_field/wavelength_shift1.toml b/testing/configs/custom_field/wavelength_shift1.toml index 1dcca62..554c4cb 100644 --- a/testing/configs/custom_field/wavelength_shift1.toml +++ b/testing/configs/custom_field/wavelength_shift1.toml @@ -15,6 +15,7 @@ wavelength = 1050e-9 behaviors = ["spm", "raman", "ss"] lower_wavelength_interp_limit = 300e-9 raman_type = "agrawal" +readjust_wavelength = true t_num = 16384 time_window = 37e-12 tolerated_error = 1e-11 diff --git a/testing/configs/custom_field/wavelength_shift2.toml b/testing/configs/custom_field/wavelength_shift2.toml index 9aa79ec..aebd67f 100644 --- a/testing/configs/custom_field/wavelength_shift2.toml +++ b/testing/configs/custom_field/wavelength_shift2.toml @@ -16,6 +16,7 @@ wavelength = [1050e-9, 1321e-9, 1593e-9] behaviors = ["spm", "raman", "ss"] lower_wavelength_interp_limit = 300e-9 raman_type = "agrawal" +readjust_wavelength = true t_num = 16384 time_window = 37e-12 tolerated_error = 1e-11