:mod:`ocelot.common.math_op` ============================ .. py:module:: ocelot.common.math_op .. autoapi-nested-parse:: statistical analysis functions, fitting, optimization and the like Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: ocelot.common.math_op.complete_gamma ocelot.common.math_op.conj_sym ocelot.common.math_op.invert_cdf ocelot.common.math_op.rolling_mean ocelot.common.math_op.rolling_window ocelot.common.math_op.convolve ocelot.common.math_op.deconvolve ocelot.common.math_op.peaks ocelot.common.math_op.gs_search ocelot.common.math_op.fit_gauss_2d ocelot.common.math_op.fit_gauss_1d ocelot.common.math_op.fwhm ocelot.common.math_op.fwhm3 ocelot.common.math_op.stats ocelot.common.math_op.find_saturation ocelot.common.math_op.find_nearest_idx ocelot.common.math_op.find_nearest ocelot.common.math_op.n_moment ocelot.common.math_op.std_moment ocelot.common.math_op.bin_array ocelot.common.math_op.bin_scale ocelot.common.math_op.index_of ocelot.common.math_op.corr_f_py ocelot.common.math_op.corr_f_np ocelot.common.math_op.correlation2d ocelot.common.math_op.corr_c_py ocelot.common.math_op.corr_c_np ocelot.common.math_op.correlation2d_center ocelot.common.math_op.mut_coh_func_py ocelot.common.math_op.gauss_fit .. data:: numba_avail :annotation: = True .. function:: complete_gamma(a, z) return 'complete' gamma function .. function:: conj_sym(x) function to make "nearly conjugate symmetric" vector in order to compute matplab IFFT function with 'symmetric' option: MATLAB >> ifft(x, 'symmetric') PYTHON >> numpy.fft.ifft(conj_sym(x)) .. function:: invert_cdf(y, x) Invert cumulative distribution function of the probability distribution Example: -------- # analytical formula for the beam distribution f = lambda x: A * np.exp(-(x - mu) ** 2 / (2. * sigma ** 2)) # we are interesting in range from -30 to 30 e.g. [um] x = np.linspace(-30, 30, num=100) # Inverted cumulative distribution function i_cdf = invert_cdf(y=f(x), x=x) # get beam distribution (200 000 coordinates) tau = i_cdf(np.random.rand(200000)) :param y: array, [y0, y1, y2, ... yn] yi = y(xi) :param x: array, [x0, x1, x2, ... xn] xi :return: function .. function:: rolling_mean(x, window) Fat method for rolling mean Example: -------- X = np.random.rand(10000) X_mean = rolling_mean(X, 500) :param x: np.array, len(a) must be larger than window :param window: int, length of the window :return: np.array, len = len(x) + 1 - window .. function:: rolling_window(x, window) Function return x-array slices with length of the window, which can be used for rolling analysis. Example: -------- X = np.random.rand(10000) X_std = np.std(rolling_window(X, 500), 1) X_mean = np.mean(rolling_window(X, 500), 1) :param x: np.array, len(a) must be larger than window :param window: int, length of the window :return: np.array, shape: (len(a) + 1 - window, window) .. function:: convolve(f, g) FFT based convolution :param f: array :param g: array :return: array, (f * g)[n] .. function:: deconvolve(f, g) FFT based deconvolution :param f: array :param g: array :return: array, .. function:: peaks(x, y, n=0) .. function:: gs_search(f, bracket, tol=1e-06, nmax=50) golden section search .. function:: fit_gauss_2d(x, y, F) .. function:: fit_gauss_1d(x, F) .. function:: fwhm(x, F) .. function:: fwhm3(valuelist, height=0.5, peakpos=-1, total=1) calculates the full width at half maximum (fwhm) of the array. the function will return the fwhm with sub-pixel interpolation. It will start at the maximum position and 'walk' left and right until it approaches the half values. if total==1, it will start at the edges and 'walk' towards peak until it approaches the half values. INPUT: - valuelist: e.g. the list containing the temporal shape of a pulse OPTIONAL INPUT: -peakpos: position of the peak to examine (list index) the global maximum will be used if omitted. if total = 1 - OUTPUT: - peakpos(index), interpolated_width(npoints), [index_l, index_r] .. function:: stats(outputs) return mean, std, median and extreme (farthest from mean) of a time series .. function:: find_saturation(power, z, n_smooth=5) .. function:: find_nearest_idx(array, value) .. function:: find_nearest(array, value) .. function:: n_moment(x, counts, c, n) .. function:: std_moment(x, counts) .. function:: bin_array(array, bin_size) .. function:: bin_scale(scale, bin_size) .. function:: index_of(array, value) .. function:: corr_f_py(corr, val, n_skip=1, norm=1) .. function:: corr_f_np(corr, val, n_skip=1, norm=1, count=0) .. data:: corr_f_nb .. function:: correlation2d(val, norm=0, n_skip=1, use_numba=numba_avail) .. function:: corr_c_py(corr, n_corr, val, norm) .. function:: corr_c_np(corr, n_corr, val, norm) .. data:: corr_c_nb .. function:: correlation2d_center(n_corr, val, norm=0, use_numba=1) .. function:: mut_coh_func_py(J, fld, norm=1) Mutual Coherence function .. data:: mut_coh_func .. function:: gauss_fit(X, Y)