votes up 1

s should be positive

Package:
scipy
github stars 8546
Exception Class:
ValueError

Raise code

        if not ((0.0 <= phi).all() and (phi <= 2.0 * np.pi).all()):
            raise ValueError('phi should be between [0, 2pi]')
        if w is not None:
            w = np.asarray(w)
            if not (w >= 0.0).all():
                raise ValueError('w should be positive')
        if not s >= 0.0:
            raise ValueError('s should be positive')
        if not 0.0 < eps < 1.0:
            raise ValueError('eps should be between (0, 1)')

        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, tt_, np_, tp_, c, fp, ier = dfitpack.spherfit_smth(theta, phi,
                                                                r, w=w, s=s,

Ways to fix

votes up 3 votes down

A negative value of the parameter s causes this error.

How to reproduce the error:

$ pipenv instlal scipy

import numpy as np


from scipy.interpolate import SmoothSphereBivariateSpline


lut = SmoothSphereBivariateSpline([1,2,3],[1,2,3], [1,2,3],s=-3.5)

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-36-dd5e7a56c8f4> in <module>()  3 from scipy.interpolate import SmoothSphereBivariateSpline  4  ----> 5 lut = SmoothSphereBivariateSpline([1,2,3],[1,2,3], [1,2,3],s=-3.5) 
/usr/local/lib/python3.7/dist-packages/scipy/interpolate/fitpack2.py in __init__(self, theta, phi, r, w, s, eps)  1576 raise ValueError('w should be positive')  1577 if not s >= 0.0: -> 1578 raise ValueError('s should be positive')  1579 if not 0.0 < eps < 1.0:  1580 raise ValueError('eps should be between (0, 1)') 
ValueError: s should be positive

Fixed version of the code:

import numpy as np


from scipy.interpolate import SmoothSphereBivariateSpline


lut = SmoothSphereBivariateSpline([1,2,3],[1,2,3], [1,2,3],s=3.5)

Detailed information can be found here.

Oct 13, 2021 kellemnegasi answer
kellemnegasi 13.5k

Add a possible fix

Please authorize to post fix