misc
This commit is contained in:
@@ -437,6 +437,7 @@ def transform_2D_propagation(
|
|||||||
log: Union[int, float, bool, str] = "1D",
|
log: Union[int, float, bool, str] = "1D",
|
||||||
skip: int = 1,
|
skip: int = 1,
|
||||||
params: Parameters = None,
|
params: Parameters = None,
|
||||||
|
conserved_quantity: bool = True,
|
||||||
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
) -> tuple[np.ndarray, np.ndarray, np.ndarray]:
|
||||||
"""
|
"""
|
||||||
transforms raws values into plottable values
|
transforms raws values into plottable values
|
||||||
@@ -447,16 +448,20 @@ def transform_2D_propagation(
|
|||||||
values to transform
|
values to transform
|
||||||
plt_range : Union[PlotRange, RangeType]
|
plt_range : Union[PlotRange, RangeType]
|
||||||
range
|
range
|
||||||
x_axis : np.ndarray
|
x_axis : np.ndarray, shape (nt,)
|
||||||
corresponding x values in SI units
|
corresponding x values in SI units
|
||||||
y_axis : np.ndarray
|
y_axis : np.ndarray, shape (n,)
|
||||||
corresponding y values in SI units
|
corresponding y values in SI units
|
||||||
params : Parameters, optional
|
|
||||||
parameters of the simulation
|
|
||||||
log : Union[int, float, bool, str], optional
|
log : Union[int, float, bool, str], optional
|
||||||
see apply_log, by default "1D"
|
see apply_log, by default "1D"
|
||||||
|
params : Parameters, optional
|
||||||
|
parameters of the simulation, used to automatically fill in x and y axes
|
||||||
skip : int, optional
|
skip : int, optional
|
||||||
take one every skip values, by default 1
|
take one every skip values, by default 1 (take all values)
|
||||||
|
conserved_quantity : bool, optional
|
||||||
|
if the target axis is wavelength, the transformation is not linear has to be corrected.
|
||||||
|
This is necessary when values is interpreted as averaged over a bin (e.g. amplitude),
|
||||||
|
but shouldn't be used when it's not the case (e.g. coherence). by default True
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
@@ -484,8 +489,8 @@ def transform_2D_propagation(
|
|||||||
# if params.full_field and plt_range.unit.type == "TIME":
|
# if params.full_field and plt_range.unit.type == "TIME":
|
||||||
# values = envelope_2d(x_axis, values)
|
# values = envelope_2d(x_axis, values)
|
||||||
|
|
||||||
x_axis, values = uniform_axis(x_axis, values, plt_range)
|
x_axis, values = uniform_axis(x_axis, values, plt_range, conserved_quantity)
|
||||||
y_axis, values.T[:] = uniform_axis(y_axis, values.T, None)
|
y_axis, values.T[:] = uniform_axis(y_axis, values.T, None, conserved_quantity)
|
||||||
values = apply_log(values, log)
|
values = apply_log(values, log)
|
||||||
return x_axis[::skip], y_axis, values[:, ::skip]
|
return x_axis[::skip], y_axis, values[:, ::skip]
|
||||||
|
|
||||||
@@ -599,8 +604,7 @@ def transform_mean_values(
|
|||||||
all the values
|
all the values
|
||||||
"""
|
"""
|
||||||
if values.ndim != 2:
|
if values.ndim != 2:
|
||||||
print(f"Shape was {values.shape}. Can only plot 2D arrays")
|
raise ValueError(f"Shape was {values.shape}. Can only plot 2D arrays")
|
||||||
return
|
|
||||||
is_complex, plt_range = prep_plot_axis(values, plt_range, params)
|
is_complex, plt_range = prep_plot_axis(values, plt_range, params)
|
||||||
if is_complex:
|
if is_complex:
|
||||||
values = abs2(values)
|
values = abs2(values)
|
||||||
@@ -957,6 +961,7 @@ def uniform_axis(
|
|||||||
axis: np.ndarray,
|
axis: np.ndarray,
|
||||||
values: np.ndarray,
|
values: np.ndarray,
|
||||||
new_axis_spec: Union[PlotRange, RangeType, str],
|
new_axis_spec: Union[PlotRange, RangeType, str],
|
||||||
|
conserved_quantity: bool = True,
|
||||||
) -> tuple[np.ndarray, np.ndarray]:
|
) -> tuple[np.ndarray, np.ndarray]:
|
||||||
"""
|
"""
|
||||||
given some values(axis), creates a new uniformly spaced axis and interpolates
|
given some values(axis), creates a new uniformly spaced axis and interpolates
|
||||||
@@ -1001,7 +1006,7 @@ def uniform_axis(
|
|||||||
new_axis = tmp_axis
|
new_axis = tmp_axis
|
||||||
values = values[:, ind]
|
values = values[:, ind]
|
||||||
else:
|
else:
|
||||||
if plt_range.unit.type == "WL" and plt_range.conserved_quantity:
|
if plt_range.unit.type == "WL" and conserved_quantity:
|
||||||
values[:, ind] = np.apply_along_axis(units.to_WL, 1, values[:, ind], tmp_axis)
|
values[:, ind] = np.apply_along_axis(units.to_WL, 1, values[:, ind], tmp_axis)
|
||||||
new_axis = np.linspace(tmp_axis.min(), tmp_axis.max(), len(tmp_axis))
|
new_axis = np.linspace(tmp_axis.min(), tmp_axis.max(), len(tmp_axis))
|
||||||
values = linear_interp_2d(tmp_axis, values[:, ind], new_axis)
|
values = linear_interp_2d(tmp_axis, values[:, ind], new_axis)
|
||||||
|
|||||||
@@ -182,11 +182,6 @@ class Propagation:
|
|||||||
return self._load_slice(slice(None))
|
return self._load_slice(slice(None))
|
||||||
|
|
||||||
|
|
||||||
def load_all(path: os.PathLike) -> Spectrum:
|
|
||||||
io = ZipFileIOHandler(path)
|
|
||||||
return Propagation(io).load_all()
|
|
||||||
|
|
||||||
|
|
||||||
def propagation(
|
def propagation(
|
||||||
file_or_params: os.PathLike | Parameters,
|
file_or_params: os.PathLike | Parameters,
|
||||||
params: Parameters | None = None,
|
params: Parameters | None = None,
|
||||||
|
|||||||
Reference in New Issue
Block a user