misc
This commit is contained in:
@@ -126,7 +126,7 @@ def initial_field(t, shape, t0, peak_power):
|
|||||||
raised when shape is not recognized
|
raised when shape is not recognized
|
||||||
"""
|
"""
|
||||||
if shape == "gaussian":
|
if shape == "gaussian":
|
||||||
return gauss_pulse(t, t0, peak_power)
|
return gaussian_pulse(t, t0, peak_power)
|
||||||
elif shape == "sech":
|
elif shape == "sech":
|
||||||
return sech_pulse(t, t0, peak_power)
|
return sech_pulse(t, t0, peak_power)
|
||||||
else:
|
else:
|
||||||
@@ -352,7 +352,7 @@ def sech_pulse(t, t0, P0, offset=0):
|
|||||||
return np.sqrt(P0) / np.cosh((t - offset) / t0)
|
return np.sqrt(P0) / np.cosh((t - offset) / t0)
|
||||||
|
|
||||||
|
|
||||||
def gauss_pulse(t, t0, P0, offset=0):
|
def gaussian_pulse(t, t0, P0, offset=0):
|
||||||
return np.sqrt(P0) * np.exp(-(((t - offset) / t0) ** 2))
|
return np.sqrt(P0) * np.exp(-(((t - offset) / t0) ** 2))
|
||||||
|
|
||||||
|
|
||||||
@@ -774,16 +774,16 @@ def find_lobe_limits(x_axis, values, debug="", already_sorted=True):
|
|||||||
)
|
)
|
||||||
|
|
||||||
good_roots, left_lim, right_lim = _select_roots(d_spline, d_roots, dd_roots, fwhm_pos)
|
good_roots, left_lim, right_lim = _select_roots(d_spline, d_roots, dd_roots, fwhm_pos)
|
||||||
|
if debug != "":
|
||||||
ax.scatter(
|
ax.scatter(
|
||||||
[left_lim, right_lim],
|
[left_lim, right_lim],
|
||||||
spline_4([left_lim, right_lim]),
|
spline_4([left_lim, right_lim]),
|
||||||
marker="|",
|
marker="|",
|
||||||
label="lobe pos",
|
label="lobe pos",
|
||||||
c=color[5],
|
c=color[5],
|
||||||
)
|
)
|
||||||
ax.legend()
|
ax.legend()
|
||||||
fig.savefig(out_path, bbox_inches="tight")
|
fig.savefig(out_path, bbox_inches="tight")
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@@ -885,19 +885,24 @@ def _detailed_find_lobe_limits(
|
|||||||
# if measurement of the peak is not straightforward, we plot the situation to see
|
# if measurement of the peak is not straightforward, we plot the situation to see
|
||||||
# if the final measurement is good or not
|
# if the final measurement is good or not
|
||||||
|
|
||||||
out_path, fig, ax = plot_setup(out_path=f"measurement_errors_plots/it_{iterations}_{debug}")
|
out_path, fig, ax = (
|
||||||
|
plot_setup(out_path=f"measurement_errors_plots/it_{iterations}_{debug}")
|
||||||
|
if debug != ""
|
||||||
|
else (None, None, None)
|
||||||
|
)
|
||||||
|
|
||||||
new_fwhm_pos = np.array([np.max(left_pos), np.min(right_pos)])
|
new_fwhm_pos = np.array([np.max(left_pos), np.min(right_pos)])
|
||||||
|
|
||||||
# PLOT
|
# PLOT
|
||||||
|
|
||||||
newx = np.linspace(*span(x_axis[l_ind : r_ind + 1]), 1000)
|
|
||||||
color = default_plotting["color_cycle"]
|
color = default_plotting["color_cycle"]
|
||||||
ax.plot(x_axis[l_ind - 5 : r_ind + 6], values[l_ind - 5 : r_ind + 6], c=color[0])
|
if debug != "":
|
||||||
ax.plot(newx, spline_5(newx), c=color[1])
|
newx = np.linspace(*span(x_axis[l_ind : r_ind + 1]), 1000)
|
||||||
ax.scatter(fwhm_pos, spline_4(fwhm_pos), marker="+", label="all fwhm", c=color[2])
|
ax.plot(x_axis[l_ind - 5 : r_ind + 6], values[l_ind - 5 : r_ind + 6], c=color[0])
|
||||||
ax.scatter(peak_pos, spline_4(peak_pos), marker=".", label="peak pos", c=color[3])
|
ax.plot(newx, spline_5(newx), c=color[1])
|
||||||
ax.scatter(new_fwhm_pos, spline_4(new_fwhm_pos), marker="_", label="2 chosen", c=color[4])
|
ax.scatter(fwhm_pos, spline_4(fwhm_pos), marker="+", label="all fwhm", c=color[2])
|
||||||
|
ax.scatter(peak_pos, spline_4(peak_pos), marker=".", label="peak pos", c=color[3])
|
||||||
|
ax.scatter(new_fwhm_pos, spline_4(new_fwhm_pos), marker="_", label="2 chosen", c=color[4])
|
||||||
|
|
||||||
fwhm_pos = new_fwhm_pos
|
fwhm_pos = new_fwhm_pos
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -422,6 +422,35 @@ def transform_2D_propagation(
|
|||||||
log: Union[int, float, bool, str] = "1D",
|
log: Union[int, float, bool, str] = "1D",
|
||||||
skip: int = 1,
|
skip: int = 1,
|
||||||
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
||||||
|
"""transforms raws values into plottable values
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
values : np.ndarray, shape (n, nt)
|
||||||
|
values to transform
|
||||||
|
plt_range : Union[units.PlotRange, RangeType]
|
||||||
|
range
|
||||||
|
params : BareParams
|
||||||
|
parameters of the simulation
|
||||||
|
log : Union[int, float, bool, str], optional
|
||||||
|
see apply_log, by default "1D"
|
||||||
|
skip : int, optional
|
||||||
|
take one every skip values, by default 1
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
np.ndarray
|
||||||
|
x_axis
|
||||||
|
np.ndarray
|
||||||
|
y_axis
|
||||||
|
np.ndarray
|
||||||
|
values
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
ValueError
|
||||||
|
incorrect shape
|
||||||
|
"""
|
||||||
|
|
||||||
if values.ndim != 2:
|
if values.ndim != 2:
|
||||||
raise ValueError(f"shape was {values.shape}. Can only plot 2D array")
|
raise ValueError(f"shape was {values.shape}. Can only plot 2D array")
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ def format_value(name: str, value) -> str:
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return format(value, ".9g")
|
return format(value, ".9g")
|
||||||
elif isinstance(value, (list, tuple, np.ndarray)):
|
elif isinstance(value, (list, tuple, np.ndarray)):
|
||||||
return "-".join([format_value(v) for v in value])
|
return "-".join([str(v) for v in value])
|
||||||
elif isinstance(value, str):
|
elif isinstance(value, str):
|
||||||
p = Path(value)
|
p = Path(value)
|
||||||
if p.exists():
|
if p.exists():
|
||||||
|
|||||||
Reference in New Issue
Block a user