diff --git a/src/scgenerator/plotting.py b/src/scgenerator/plotting.py index be800c1..121835f 100644 --- a/src/scgenerator/plotting.py +++ b/src/scgenerator/plotting.py @@ -437,6 +437,7 @@ def transform_2D_propagation( log: Union[int, float, bool, str] = "1D", skip: int = 1, params: Parameters = None, + conserved_quantity: bool = True, ) -> tuple[np.ndarray, np.ndarray, np.ndarray]: """ transforms raws values into plottable values @@ -447,16 +448,20 @@ def transform_2D_propagation( values to transform plt_range : Union[PlotRange, RangeType] range - x_axis : np.ndarray + x_axis : np.ndarray, shape (nt,) corresponding x values in SI units - y_axis : np.ndarray + y_axis : np.ndarray, shape (n,) corresponding y values in SI units - params : Parameters, optional - parameters of the simulation log : Union[int, float, bool, str], optional 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 - 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 ------- @@ -484,8 +489,8 @@ def transform_2D_propagation( # if params.full_field and plt_range.unit.type == "TIME": # values = envelope_2d(x_axis, values) - x_axis, values = uniform_axis(x_axis, values, plt_range) - y_axis, values.T[:] = uniform_axis(y_axis, values.T, None) + x_axis, values = uniform_axis(x_axis, values, plt_range, conserved_quantity) + y_axis, values.T[:] = uniform_axis(y_axis, values.T, None, conserved_quantity) values = apply_log(values, log) return x_axis[::skip], y_axis, values[:, ::skip] @@ -599,8 +604,7 @@ def transform_mean_values( all the values """ if values.ndim != 2: - print(f"Shape was {values.shape}. Can only plot 2D arrays") - return + raise ValueError(f"Shape was {values.shape}. Can only plot 2D arrays") is_complex, plt_range = prep_plot_axis(values, plt_range, params) if is_complex: values = abs2(values) @@ -957,6 +961,7 @@ def uniform_axis( axis: np.ndarray, values: np.ndarray, new_axis_spec: Union[PlotRange, RangeType, str], + conserved_quantity: bool = True, ) -> tuple[np.ndarray, np.ndarray]: """ given some values(axis), creates a new uniformly spaced axis and interpolates @@ -1001,7 +1006,7 @@ def uniform_axis( new_axis = tmp_axis values = values[:, ind] 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) new_axis = np.linspace(tmp_axis.min(), tmp_axis.max(), len(tmp_axis)) values = linear_interp_2d(tmp_axis, values[:, ind], new_axis) diff --git a/src/scgenerator/spectra.py b/src/scgenerator/spectra.py index 734cf5b..d176594 100644 --- a/src/scgenerator/spectra.py +++ b/src/scgenerator/spectra.py @@ -182,11 +182,6 @@ class Propagation: return self._load_slice(slice(None)) -def load_all(path: os.PathLike) -> Spectrum: - io = ZipFileIOHandler(path) - return Propagation(io).load_all() - - def propagation( file_or_params: os.PathLike | Parameters, params: Parameters | None = None,