jgliss / pyplis

Python toolbox for the analysis of UV SO2 camera data
GNU General Public License v3.0
7 stars 5 forks source link

through_origin parameter is not working correctly in DoasCalibData.fit_calib_polynomial() #3

Closed solvejgdinger closed 6 years ago

solvejgdinger commented 6 years ago

The parameter through_origin does not force the fit through the origin when few data is available. In the below figure I used DoasCalibData.fit_calib_polynomial with through_origin=True (blue curve) and a simple least square fit (red curve, code below). The blue curve does not go through zero whereby it is different than the non-forced curve (see below). I suggest that you replace the additional zero-data with a simpler fit model or a different function.

With through_origin=True figure_5_lstsq

With through_origin=False figure_5

def fit_linear(calib, plot=False):
    """ Simple linear fit with forced origin """
    tau = calib.tau_vec
    scd = calib.doas_vec
    tau = tau[:,np.newaxis]
    a, res, rank, sgl = np.linalg.lstsq(tau, scd)
    if plot:
        fig, ax = plt.subplots()
        plt.plot(tau, scd, 'bo')
        plt.plot(tau, a*tau, 'r-', label='forced origin')
        ax.set_xlabel(r'$\tau$')
        ax.set_ylabel(r'SO$_2$ SCD [molec/cm$^{2}$]')
        ax.grid()
        plt.show()
    return a
jgliss commented 6 years ago

Thanks for this hint. This has been resolved in the latest commit.

NOTE This fix will be included in the next upcoming release and is not included in the current release 1.0.1. In case you need this functionality, please clone the current version of the repo.

Cheers