|
10 | 10 | from matplotlib.axes._axes import Axes |
11 | 11 | from matplotlib.figure import Figure |
12 | 12 | from numpy import dot |
13 | | -from scipy import odr |
| 13 | +from odrpack import odr_fit |
14 | 14 | from scipy.optimize import minimize |
15 | 15 | from scipy.stats import linregress |
16 | 16 | from scipy.stats.distributions import t as tdist |
@@ -508,19 +508,23 @@ def _fit_copo_ODR( |
508 | 508 | sF1 = np.asarray(sF1) |
509 | 509 |
|
510 | 510 | # Parameter estimation |
511 | | - odr_Model = odr.Model(lambda beta, x: inst_copolymer_binary(x, *beta)) |
512 | | - odr_Data = odr.RealData(x=f1, y=F1, sx=sf1, sy=sF1) |
513 | | - odr_ODR = odr.ODR(odr_Data, odr_Model, beta0=r_guess) |
514 | | - solution = odr_ODR.run() |
| 511 | + sol = odr_fit( |
| 512 | + f=lambda x, beta: inst_copolymer_binary(x, *beta), |
| 513 | + xdata=f1, |
| 514 | + ydata=F1, |
| 515 | + weight_x=1 / sf1**2, |
| 516 | + weight_y=1 / sF1**2, |
| 517 | + beta0=np.array(r_guess), |
| 518 | + ) |
515 | 519 |
|
516 | | - if solution.info > 4: # type: ignore |
517 | | - raise FitError(solution.stopreason) |
| 520 | + if not sol.success: |
| 521 | + raise FitError(sol.stopreason) |
518 | 522 |
|
519 | | - r_opt = solution.beta |
520 | | - f1plus = solution.xplus # type: ignore |
| 523 | + r_opt = sol.beta |
| 524 | + f1plus = sol.xplusd |
521 | 525 | if f1.size > 2: |
522 | 526 | # cov_beta is absolute, so rescaling is required |
523 | | - cov = solution.cov_beta * solution.res_var # type: ignore |
| 527 | + cov = sol.cov_beta * sol.res_var |
524 | 528 | else: |
525 | 529 | cov = None |
526 | 530 |
|
|
0 commit comments