optframework.utils.func.static_method module
- optframework.utils.func.static_method.interpolate_psd(d, psd_data, v0, x_init=None, Q_init=None)[source]
Obtain initial conditions from a PSD data file.
Parameters
- darray_like
Particle size grid on which the PSD should be interpolated. NOTE: This vector contains diameters
- psd_datastr
Complete path (including filename) to datafile in which the PSD is saved.
- v0: float
Total VOLUME the distribution should be scaled to
- x_initarray_like, optional
Particle size grid in the PSD can be manually specified.
- Q_initarray_like, optional
Manually specify the PSD instead of reading it from the file.
Returns
- narray_like
NUMBER concentration vector corresponding to d
- optframework.utils.func.static_method.wrap_with_linear_extrapolation(f_raw, x_sub, y_sub)[source]
Wrap a given interpolator with linear extrapolation on both ends.
- Parameters:
f_raw (callable): Base interpolator function f(x) x_sub, y_sub (array-like): Original data points used for interpolation
- Returns:
f(x): Interpolated + linearly extrapolated function
- optframework.utils.func.static_method.plot_N2D(N, V, V0_tot, ax=None, fig=None, close_all=False, scl_a4=1, figsze=[13.440000000000001, 12.8], THR_N=0.0001, exp_file=None, t_stamp=None)[source]
- optframework.utils.func.static_method.KDE_fit(x_uni_ori, data_ori, bandwidth='scott', kernel_func='epanechnikov')[source]
Fit a Kernel Density Estimation (KDE) model to the original data using the specified kernel function and bandwidth.
Parameters
- x_uni_oriarray-like
The unique values of the data variable. Must be a one-dimensional array.
- data_oriarray-like
The original data corresponding to x_uni_ori. Should be absolute values, not relative.
- bandwidthfloat or {‘scott’, ‘silverman’}, optional
The bandwidth of the kernel. If a float is provided, it defines the bandwidth directly. If a string (‘scott’ or ‘silverman’) is provided, the bandwidth is estimated using one of these methods. Defaults to ‘scott’.
- kernel_func{‘gaussian’, ‘tophat’, ‘epanechnikov’, ‘exponential’, ‘linear’, ‘cosine’}, optional
The kernel to use for the density estimation. Defaults to ‘epanechnikov’.
Returns
- sklearn.neighbors.kde.KernelDensity
The fitted KDE model.
Notes
x_uni_ori must be reshaped into a column vector for compatibility with the KernelDensity class.
Any values in data_ori that are zero or less are adjusted to a small positive value (1e-20) to avoid numerical issues during KDE fitting.
- optframework.utils.func.static_method.KDE_score(kde, x_uni_new)[source]
Evaluate and normalize the KDE model on new data points based on the cumulative distribution function (Q3).
Parameters
- kdesklearn.neighbors.kde.KernelDensity
The fitted KDE model from the method.
- x_uni_newarray-like
New unique data points where the KDE model will be evaluated.
Returns
- array-like
The smoothed and normalized data based on the KDE model.
Notes
The KDE model is evaluated on the new data points by calculating the log density, which is then exponentiated to get the actual density values.
The smoothed data is normalized by dividing by the last value of the cumulative distribution (Q3).