Python scipy.special.ellipk() Examples
The following are 16
code examples of scipy.special.ellipk().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.special
, or try the search function
.
Example #1
Source File: gradshafranov.py From freegs with GNU Lesser General Public License v3.0 | 6 votes |
def Greens(Rc, Zc, R, Z): """ Calculate poloidal flux at (R,Z) due to a unit current at (Rc,Zc) using Greens function """ # Calculate k^2 k2 = 4.*R * Rc / ( (R + Rc)**2 + (Z - Zc)**2 ) # Clip to between 0 and 1 to avoid nans e.g. when coil is on grid point k2 = clip(k2, 1e-10, 1.0 - 1e-10) k = sqrt(k2) # Note definition of ellipk, ellipe in scipy is K(k^2), E(k^2) return (mu0/(2.*pi)) * sqrt(R*Rc) * ( (2. - k2)*ellipk(k2) - 2.*ellipe(k2) ) / k
Example #2
Source File: filter_design.py From lambda-packs with MIT License | 5 votes |
def _kratio(m, k_ratio): m = float(m) if m < 0: m = 0.0 if m > 1: m = 1.0 if abs(m) > EPSILON and (abs(m) + EPSILON) < 1: k = special.ellipk([m, 1 - m]) r = k[0] / k[1] - k_ratio elif abs(m) > EPSILON: r = -k_ratio else: r = 1e20 return abs(r)
Example #3
Source File: filter_design.py From Computable with MIT License | 5 votes |
def _kratio(m, k_ratio): m = float(m) if m < 0: m = 0.0 if m > 1: m = 1.0 if abs(m) > EPSILON and (abs(m) + EPSILON) < 1: k = special.ellipk([m, 1 - m]) r = k[0] / k[1] - k_ratio elif abs(m) > EPSILON: r = -k_ratio else: r = 1e20 return abs(r)
Example #4
Source File: test_basic.py From Computable with MIT License | 5 votes |
def test_ellipk(self): assert_allclose(ellipk(0), pi/2)
Example #5
Source File: test_basic.py From Computable with MIT License | 5 votes |
def test_ellipk(self): elk = special.ellipk(.2) assert_almost_equal(elk,1.659623598610528,11)
Example #6
Source File: test_basic.py From Computable with MIT License | 5 votes |
def test_ellipkinc(self): elkinc = special.ellipkinc(pi/2,.2) elk = special.ellipk(0.2) assert_almost_equal(elkinc,elk,15) alpha = 20*pi/180 phi = 45*pi/180 m = sin(alpha)**2 elkinc = special.ellipkinc(phi,m) assert_almost_equal(elkinc,0.79398143,8) # From pg. 614 of A & S
Example #7
Source File: filter_design.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _kratio(m, k_ratio): m = float(m) if m < 0: m = 0.0 if m > 1: m = 1.0 if abs(m) > EPSILON and (abs(m) + EPSILON) < 1: k = special.ellipk([m, 1 - m]) r = k[0] / k[1] - k_ratio elif abs(m) > EPSILON: r = -k_ratio else: r = 1e20 return abs(r)
Example #8
Source File: test_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_ellipk(self): assert_allclose(ellipk(0), pi/2)
Example #9
Source File: test_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_ellipk(self): elk = special.ellipk(.2) assert_almost_equal(elk,1.659623598610528,11) assert_equal(special.ellipkm1(0.0), np.inf) assert_equal(special.ellipkm1(1.0), pi/2) assert_equal(special.ellipkm1(np.inf), 0.0) assert_equal(special.ellipkm1(np.nan), np.nan) assert_equal(special.ellipkm1(-1), np.nan) assert_allclose(special.ellipk(-10), 0.7908718902387385)
Example #10
Source File: test_basic.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_ellipkinc(self): elkinc = special.ellipkinc(pi/2,.2) elk = special.ellipk(0.2) assert_almost_equal(elkinc,elk,15) alpha = 20*pi/180 phi = 45*pi/180 m = sin(alpha)**2 elkinc = special.ellipkinc(phi,m) assert_almost_equal(elkinc,0.79398143,8) # From pg. 614 of A & S assert_equal(special.ellipkinc(pi/2, 0.0), pi/2) assert_equal(special.ellipkinc(pi/2, 1.0), np.inf) assert_equal(special.ellipkinc(pi/2, -np.inf), 0.0) assert_equal(special.ellipkinc(pi/2, np.nan), np.nan) assert_equal(special.ellipkinc(pi/2, 2), np.nan) assert_equal(special.ellipkinc(0, 0.5), 0.0) assert_equal(special.ellipkinc(np.inf, 0.5), np.inf) assert_equal(special.ellipkinc(-np.inf, 0.5), -np.inf) assert_equal(special.ellipkinc(np.inf, np.inf), np.nan) assert_equal(special.ellipkinc(np.inf, -np.inf), np.nan) assert_equal(special.ellipkinc(-np.inf, -np.inf), np.nan) assert_equal(special.ellipkinc(-np.inf, np.inf), np.nan) assert_equal(special.ellipkinc(np.nan, 0.5), np.nan) assert_equal(special.ellipkinc(np.nan, np.nan), np.nan) assert_allclose(special.ellipkinc(0.38974112035318718, 1), 0.4, rtol=1e-14) assert_allclose(special.ellipkinc(1.5707, -10), 0.79084284661724946)
Example #11
Source File: test_mpmath.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_ellipk(self): assert_mpmath_equal(sc.ellipk, mpmath.ellipk, [Arg(b=1.0)]) assert_mpmath_equal(sc.ellipkm1, lambda m: mpmath.ellipk(1 - m), [Arg(a=0.0)], dps=400)
Example #12
Source File: filter_design.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _kratio(m, k_ratio): m = float(m) if m < 0: m = 0.0 if m > 1: m = 1.0 if abs(m) > EPSILON and (abs(m) + EPSILON) < 1: k = special.ellipk([m, 1 - m]) r = k[0] / k[1] - k_ratio elif abs(m) > EPSILON: r = -k_ratio else: r = 1e20 return abs(r)
Example #13
Source File: filter_design.py From lambda-packs with MIT License | 4 votes |
def band_stop_obj(wp, ind, passb, stopb, gpass, gstop, type): """ Band Stop Objective Function for order minimization. Returns the non-integer order for an analog band stop filter. Parameters ---------- wp : scalar Edge of passband `passb`. ind : int, {0, 1} Index specifying which `passb` edge to vary (0 or 1). passb : ndarray Two element sequence of fixed passband edges. stopb : ndarray Two element sequence of fixed stopband edges. gstop : float Amount of attenuation in stopband in dB. gpass : float Amount of ripple in the passband in dB. type : {'butter', 'cheby', 'ellip'} Type of filter. Returns ------- n : scalar Filter order (possibly non-integer). """ passbC = passb.copy() passbC[ind] = wp nat = (stopb * (passbC[0] - passbC[1]) / (stopb ** 2 - passbC[0] * passbC[1])) nat = min(abs(nat)) if type == 'butter': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = (log10((GSTOP - 1.0) / (GPASS - 1.0)) / (2 * log10(nat))) elif type == 'cheby': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = arccosh(sqrt((GSTOP - 1.0) / (GPASS - 1.0))) / arccosh(nat) elif type == 'ellip': GSTOP = 10 ** (0.1 * gstop) GPASS = 10 ** (0.1 * gpass) arg1 = sqrt((GPASS - 1.0) / (GSTOP - 1.0)) arg0 = 1.0 / nat d0 = special.ellipk([arg0 ** 2, 1 - arg0 ** 2]) d1 = special.ellipk([arg1 ** 2, 1 - arg1 ** 2]) n = (d0[0] * d1[1] / (d0[1] * d1[0])) else: raise ValueError("Incorrect type: %s" % type) return n
Example #14
Source File: filter_design.py From Computable with MIT License | 4 votes |
def band_stop_obj(wp, ind, passb, stopb, gpass, gstop, type): """ Band Stop Objective Function for order minimization. Returns the non-integer order for an analog band stop filter. Parameters ---------- wp : scalar Edge of passband `passb`. ind : int, {0, 1} Index specifying which `passb` edge to vary (0 or 1). passb : ndarray Two element sequence of fixed passband edges. stopb : ndarray Two element sequence of fixed stopband edges. gstop : float Amount of attenuation in stopband in dB. gpass : float Amount of ripple in the passband in dB. type : {'butter', 'cheby', 'ellip'} Type of filter. Returns ------- n : scalar Filter order (possibly non-integer). """ passbC = passb.copy() passbC[ind] = wp nat = (stopb * (passbC[0] - passbC[1]) / (stopb ** 2 - passbC[0] * passbC[1])) nat = min(abs(nat)) if type == 'butter': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = (log10((GSTOP - 1.0) / (GPASS - 1.0)) / (2 * log10(nat))) elif type == 'cheby': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = arccosh(sqrt((GSTOP - 1.0) / (GPASS - 1.0))) / arccosh(nat) elif type == 'ellip': GSTOP = 10 ** (0.1 * gstop) GPASS = 10 ** (0.1 * gpass) arg1 = sqrt((GPASS - 1.0) / (GSTOP - 1.0)) arg0 = 1.0 / nat d0 = special.ellipk([arg0 ** 2, 1 - arg0 ** 2]) d1 = special.ellipk([arg1 ** 2, 1 - arg1 ** 2]) n = (d0[0] * d1[1] / (d0[1] * d1[0])) else: raise ValueError("Incorrect type: %s" % type) return n
Example #15
Source File: filter_design.py From GraphicDesignPatternByPython with MIT License | 4 votes |
def band_stop_obj(wp, ind, passb, stopb, gpass, gstop, type): """ Band Stop Objective Function for order minimization. Returns the non-integer order for an analog band stop filter. Parameters ---------- wp : scalar Edge of passband `passb`. ind : int, {0, 1} Index specifying which `passb` edge to vary (0 or 1). passb : ndarray Two element sequence of fixed passband edges. stopb : ndarray Two element sequence of fixed stopband edges. gstop : float Amount of attenuation in stopband in dB. gpass : float Amount of ripple in the passband in dB. type : {'butter', 'cheby', 'ellip'} Type of filter. Returns ------- n : scalar Filter order (possibly non-integer). """ passbC = passb.copy() passbC[ind] = wp nat = (stopb * (passbC[0] - passbC[1]) / (stopb ** 2 - passbC[0] * passbC[1])) nat = min(abs(nat)) if type == 'butter': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = (log10((GSTOP - 1.0) / (GPASS - 1.0)) / (2 * log10(nat))) elif type == 'cheby': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = arccosh(sqrt((GSTOP - 1.0) / (GPASS - 1.0))) / arccosh(nat) elif type == 'ellip': GSTOP = 10 ** (0.1 * gstop) GPASS = 10 ** (0.1 * gpass) arg1 = sqrt((GPASS - 1.0) / (GSTOP - 1.0)) arg0 = 1.0 / nat d0 = special.ellipk([arg0 ** 2, 1 - arg0 ** 2]) d1 = special.ellipk([arg1 ** 2, 1 - arg1 ** 2]) n = (d0[0] * d1[1] / (d0[1] * d1[0])) else: raise ValueError("Incorrect type: %s" % type) return n
Example #16
Source File: filter_design.py From Splunking-Crime with GNU Affero General Public License v3.0 | 4 votes |
def band_stop_obj(wp, ind, passb, stopb, gpass, gstop, type): """ Band Stop Objective Function for order minimization. Returns the non-integer order for an analog band stop filter. Parameters ---------- wp : scalar Edge of passband `passb`. ind : int, {0, 1} Index specifying which `passb` edge to vary (0 or 1). passb : ndarray Two element sequence of fixed passband edges. stopb : ndarray Two element sequence of fixed stopband edges. gstop : float Amount of attenuation in stopband in dB. gpass : float Amount of ripple in the passband in dB. type : {'butter', 'cheby', 'ellip'} Type of filter. Returns ------- n : scalar Filter order (possibly non-integer). """ passbC = passb.copy() passbC[ind] = wp nat = (stopb * (passbC[0] - passbC[1]) / (stopb ** 2 - passbC[0] * passbC[1])) nat = min(abs(nat)) if type == 'butter': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = (log10((GSTOP - 1.0) / (GPASS - 1.0)) / (2 * log10(nat))) elif type == 'cheby': GSTOP = 10 ** (0.1 * abs(gstop)) GPASS = 10 ** (0.1 * abs(gpass)) n = arccosh(sqrt((GSTOP - 1.0) / (GPASS - 1.0))) / arccosh(nat) elif type == 'ellip': GSTOP = 10 ** (0.1 * gstop) GPASS = 10 ** (0.1 * gpass) arg1 = sqrt((GPASS - 1.0) / (GSTOP - 1.0)) arg0 = 1.0 / nat d0 = special.ellipk([arg0 ** 2, 1 - arg0 ** 2]) d1 = special.ellipk([arg1 ** 2, 1 - arg1 ** 2]) n = (d0[0] * d1[1] / (d0[1] * d1[0])) else: raise ValueError("Incorrect type: %s" % type) return n