def estimate_param_rippe(measurements, bins, init=None, circ=False):
<EOL>DEFAULT_INIT_RIPPE_PARAMETERS = [<NUM_LIT:1.>, <NUM_LIT>, -<NUM_LIT>]<EOL>d = <NUM_LIT><EOL>def log_residuals(p, y, x):<EOL><INDENT>kuhn, lm, slope, A = p<EOL>rippe = (np.log(A) + np.log(<NUM_LIT>) - <NUM_LIT:3> * np.log(kuhn) +<EOL>slope * (np.log(lm * x) - np.log(kuhn)) +<EOL>(d - <NUM_LIT:2>) / ((np.power((lm * x / kuhn), <NUM_LIT:2>) + d)))<EOL>err = y - rippe<EOL>return err<EOL><DEDENT>def peval(x, param):<EOL><INDENT>if circ:<EOL><INDENT>l_cont = x.max()<EOL>n = param[<NUM_LIT:1>] * x / param[<NUM_LIT:0>]<EOL>n0 = param[<NUM_LIT:1>] * x[<NUM_LIT:0>] / param[<NUM_LIT:0>]<EOL>n_l = param[<NUM_LIT:1>] * l_cont / param[<NUM_LIT:0>]<EOL>s = n * (n_l - n) / n_l<EOL>s0 = n0 * (n_l - n0) / n_l<EOL>norm_lin = (param[<NUM_LIT:3>] * (<NUM_LIT> * (param[<NUM_LIT:0>] ** -<NUM_LIT>) *<EOL>np.power(n0, (param[<NUM_LIT:2>])) *<EOL>np.exp((d - <NUM_LIT:2>) / ((np.power(n0, <NUM_LIT:2>) + d)))))<EOL>norm_circ = (param[<NUM_LIT:3>] * (<NUM_LIT> * (param[<NUM_LIT:0>] ** -<NUM_LIT>) *<EOL>np.power(s0, (param[<NUM_LIT:2>])) *<EOL>np.exp((d - <NUM_LIT:2>) / ((np.power(s0, <NUM_LIT:2>) + d)))))<EOL>rippe = (param[<NUM_LIT:3>] * (<NUM_LIT> * (param[<NUM_LIT:0>] ** -<NUM_LIT>) *<EOL>np.power(s, (param[<NUM_LIT:2>])) * np.exp((d - <NUM_LIT:2>) /<EOL>((np.power(s, <NUM_LIT:2>) + d)))) * norm_lin / norm_circ)<EOL><DEDENT>else:<EOL><INDENT>rippe = (param[<NUM_LIT:3>] * (<NUM_LIT> * (param[<NUM_LIT:0>] ** -<NUM_LIT>) *<EOL>np.power((param[<NUM_LIT:1>] * x / param[<NUM_LIT:0>]), (param[<NUM_LIT:2>])) *<EOL>np.exp((d - <NUM_LIT:2>) /<EOL>((np.power((param[<NUM_LIT:1>] * x / param[<NUM_LIT:0>]), <NUM_LIT:2>) + d)))))<EOL><DEDENT>return rippe<EOL><DEDENT>if init is None:<EOL><INDENT>init = DEFAULT_INIT_RIPPE_PARAMETERS<EOL><DEDENT>A = np.sum(measurements)<EOL>p0 = (p for p in init), A<EOL>from scipy.optimize import leastsq<EOL>plsq = leastsq(log_residuals, p0, args=(np.log(measurements), bins))<EOL>y_estim = peval(bins, plsq[<NUM_LIT:0>])<EOL>kuhn_x, lm_x, slope_x, A_x = plsq[<NUM_LIT:0>]<EOL>plsq_out = [kuhn_x, lm_x, slope_x, d, A_x]<EOL>np_plsq = np.array(plsq_out)<EOL>if np.any(np.isnan(np_plsq)) or slope_x >= <NUM_LIT:0>:<EOL><INDENT>warnings.warn("<STR_LIT>")<EOL>plsq_out = p0<EOL><DEDENT>return plsq_out, y_estim<EOL>
Perform least square optimization needed for the rippe_parameters function.