Here are the examples of the python api numpy.polynomial.Polynomial taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
51 Examples
3
Source : test_printing.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_polynomial_str(self):
res = str(poly.Polynomial([0, 1]))
tgt = 'poly([0. 1.])'
assert_equal(res, tgt)
def test_chebyshev_str(self):
3
Source : test_printing.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def test_polynomial_str(self):
res = repr(poly.Polynomial([0, 1]))
tgt = 'Polynomial([0., 1.], domain=[-1, 1], window=[-1, 1])'
assert_equal(res, tgt)
def test_chebyshev_str(self):
3
Source : toysgd.py
with Apache License 2.0
from automl
with Apache License 2.0
from automl
def build_objective_function(self):
if self.instance["family"] == "polynomial":
order = int(self.instance["order"])
if order != 2:
raise NotImplementedError("Only order 2 is currently implemented for polynomial functions.")
self.n_dim = order
coeffs_str = self.instance["coefficients"]
coeffs_str = coeffs_str.strip("[]")
coeffs = [float(item) for item in coeffs_str.split()]
self.objective_function = Polynomial(coef=coeffs)
self.objective_function_deriv = self.objective_function.deriv(m=1) # lambda x0: derivative(self.objective_function, x0, dx=1.0, n=1, args=(), order=3)
self.x_min = - coeffs[1] / (2 * coeffs[0] + 1e-10) # add small epsilon to avoid numerical instabilities
self.f_min = self.objective_function(self.x_min)
self.x_cur = self.get_initial_position()
else:
raise NotImplementedError("No other function families than polynomial are currently supported.")
def get_initial_position(self):
3
Source : try_mlecov.py
with MIT License
from birforce
with MIT License
from birforce
def getpoly(self, params):
ar = np.r_[[1], -params[:self.nar]]
ma = np.r_[[1], params[-self.nma:]]
import numpy.polynomial as poly
return poly.Polynomial(ar), poly.Polynomial(ma)
class MLEGLS(GenericLikelihoodModel):
3
Source : fftarma.py
with MIT License
from birforce
with MIT License
from birforce
def spdpoly(self, w, nma=50):
'''spectral density from MA polynomial representation for ARMA process
References
----------
Cochrane, section 8.3.3
'''
mpoly = np.polynomial.Polynomial(self.arma2ma(nma))
hw = mpoly(np.exp(1j * w))
spd = np.real_if_close(hw * hw.conj() * 0.5/np.pi)
return spd, w
def filter(self, x):
3
Source : arima_process.py
with MIT License
from birforce
with MIT License
from birforce
def __mul__(self, oth):
if isinstance(oth, self.__class__):
ar = (self.arpoly * oth.arpoly).coef
ma = (self.mapoly * oth.mapoly).coef
else:
try:
aroth, maoth = oth
arpolyoth = np.polynomial.Polynomial(aroth)
mapolyoth = np.polynomial.Polynomial(maoth)
ar = (self.arpoly * arpolyoth).coef
ma = (self.mapoly * mapolyoth).coef
except:
raise TypeError('Other type is not a valid type')
return self.__class__(ar, ma, nobs=self.nobs)
def __repr__(self):
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_single_line_one_less(self):
# With 'ascii' style, len(str(p)) is default linewidth - 1 (i.e. 74)
p = poly.Polynomial([123456789, 123456789, 123456789, 1234, 1])
assert_equal(len(str(p)), 74)
assert_equal(str(p), (
'123456789.0 + 123456789.0 x**1 + 123456789.0 x**2 + '
'1234.0 x**3 + 1.0 x**4'
))
def test_num_chars_is_linewidth(self):
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_num_chars_is_linewidth(self):
# len(str(p)) == default linewidth == 75
p = poly.Polynomial([123456789, 123456789, 123456789, 1234, 10])
assert_equal(len(str(p)), 75)
assert_equal(str(p), (
'123456789.0 + 123456789.0 x**1 + 123456789.0 x**2 + '
'1234.0 x**3 +\n10.0 x**4'
))
def test_first_linebreak_multiline_one_less_than_linewidth(self):
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_first_linebreak_multiline_one_less_than_linewidth(self):
# Multiline str where len(first_line) + len(next_term) == lw - 1 == 74
p = poly.Polynomial(
[123456789, 123456789, 123456789, 12, 1, 123456789]
)
assert_equal(len(str(p).split('\n')[0]), 74)
assert_equal(str(p), (
'123456789.0 + 123456789.0 x**1 + 123456789.0 x**2 + '
'12.0 x**3 + 1.0 x**4 +\n123456789.0 x**5'
))
def test_first_linebreak_multiline_on_linewidth(self):
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_first_linebreak_multiline_on_linewidth(self):
# First line is one character longer than previous test
p = poly.Polynomial(
[123456789, 123456789, 123456789, 123, 1, 123456789]
)
assert_equal(str(p), (
'123456789.0 + 123456789.0 x**1 + 123456789.0 x**2 + '
'123.0 x**3 +\n1.0 x**4 + 123456789.0 x**5'
))
@pytest.mark.parametrize(('lw', 'tgt'), (
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_linewidth_printoption(self, lw, tgt):
p = poly.Polynomial(
[0, 10, 200, 3000, 40000, 500000, 600000, 70000, 8000, 900]
)
with printoptions(linewidth=lw):
assert_equal(str(p), tgt)
for line in str(p).split('\n'):
assert_(len(line) < lw)
def test_set_default_printoptions():
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_set_default_printoptions():
p = poly.Polynomial([1, 2, 3])
c = poly.Chebyshev([1, 2, 3])
poly.set_default_printstyle('ascii')
assert_equal(str(p), "1.0 + 2.0 x**1 + 3.0 x**2")
assert_equal(str(c), "1.0 + 2.0 T_1(x) + 3.0 T_2(x)")
poly.set_default_printstyle('unicode')
assert_equal(str(p), "1.0 + 2.0·x¹ + 3.0·x²")
assert_equal(str(c), "1.0 + 2.0·T₁(x) + 3.0·T₂(x)")
with pytest.raises(ValueError):
poly.set_default_printstyle('invalid_input')
def test_complex_coefficients():
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_complex_coefficients():
"""Test both numpy and built-in complex."""
coefs = [0+1j, 1+1j, -2+2j, 3+0j]
# numpy complex
p1 = poly.Polynomial(coefs)
# Python complex
p2 = poly.Polynomial(array(coefs, dtype=object))
poly.set_default_printstyle('unicode')
assert_equal(str(p1), "1j + (1+1j)·x¹ - (2-2j)·x² + (3+0j)·x³")
assert_equal(str(p2), "1j + (1+1j)·x¹ + (-2+2j)·x² + (3+0j)·x³")
poly.set_default_printstyle('ascii')
assert_equal(str(p1), "1j + (1+1j) x**1 - (2-2j) x**2 + (3+0j) x**3")
assert_equal(str(p2), "1j + (1+1j) x**1 + (-2+2j) x**2 + (3+0j) x**3")
@pytest.mark.parametrize(('coefs', 'tgt'), (
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_numeric_object_coefficients(coefs, tgt):
p = poly.Polynomial(coefs)
poly.set_default_printstyle('unicode')
assert_equal(str(p), tgt)
@pytest.mark.parametrize(('coefs', 'tgt'), (
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_nonnumeric_object_coefficients(coefs, tgt):
"""
Test coef fallback for object arrays of non-numeric coefficients.
"""
p = poly.Polynomial(coefs)
poly.set_default_printstyle('unicode')
assert_equal(str(p), tgt)
class TestFormat:
3
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_bad_formatstr(self):
p = poly.Polynomial([1, 2, 0, -1])
with pytest.raises(ValueError):
format(p, '.2f')
class TestRepr:
3
Source : snippet.py
with Apache License 2.0
from dockerizeme
with Apache License 2.0
from dockerizeme
def update_coeff(self, a1,a2):
'''update the AR(2) coefficients choice
and the roots of the AR polynomial'''
# Update the title
ax_coeff.set_title('Choose AR(2) coefficients: '
'$(a_1, a_2)$=(%.2f, %.2f) \n'
'process $X_k = a_1 X_{k-1} + a_2 X_{k-2} + Z_k$'\
% (a1, a2))
# Move the circle
circ.center = a1, a2
# Move the guiding lines
coeff_line.set_data([a1, a1, 0], [0,a2,a2])
# Move the roots:
poly_ar2 = Polynomial([-a2, -a1, 1])
root1, root2 = poly_ar2.roots().astype(complex)
roots_line.set_data([root1.real, root2.real],
[root1.imag, root2.imag])
def update_response(self, a1,a2):
3
Source : trajectory.py
with BSD 3-Clause "New" or "Revised" License
from jgoppert
with BSD 3-Clause "New" or "Revised" License
from jgoppert
def time_scale(self, scale: float):
n = len(self.P[0].coef)
coef_div = np.array([scale**k for k in range(n)])
P_scaled = [Polynomial(Pi.coef / coef_div) for Pi in self.P]
T_scaled = (np.array(self.T) * scale).tolist()
return Trajectory1D(T_scaled, P_scaled)
def coef_array(self) -> np.array:
3
Source : test_printing.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def test_polynomial_str(self):
res = str(poly.Polynomial([0, 1]))
tgt = 'poly([0., 1.])'
assert_(res, tgt)
def test_chebyshev_str(self):
3
Source : test_printing.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def test_polynomial_str(self):
res = repr(poly.Polynomial([0, 1]))
tgt = 'Polynomial([0., 1.])'
assert_(res, tgt)
def test_chebyshev_str(self):
3
Source : arima_process.py
with GNU Affero General Public License v3.0
from nccgroup
with GNU Affero General Public License v3.0
from nccgroup
def __mul__(self, oth):
if isinstance(oth, self.__class__):
ar = (self.arpoly * oth.arpoly).coef
ma = (self.mapoly * oth.mapoly).coef
else:
try:
aroth, maoth = oth
arpolyoth = np.polynomial.Polynomial(aroth)
mapolyoth = np.polynomial.Polynomial(maoth)
ar = (self.arpoly * arpolyoth).coef
ma = (self.mapoly * mapolyoth).coef
except:
print('other is not a valid type')
raise
return self.__class__(ar, ma, nobs=self.nobs)
def __repr__(self):
3
Source : test_printing.py
with Apache License 2.0
from pierreant
with Apache License 2.0
from pierreant
def test_polynomial_str(self):
res = str(poly.Polynomial([0, 1]))
tgt = 'poly([0., 1.])'
assert_(res, tgt)
def test_chebyshev_str(self):
3
Source : test_printing.py
with Apache License 2.0
from pierreant
with Apache License 2.0
from pierreant
def test_polynomial_str(self):
res = repr(poly.Polynomial([0, 1]))
tgt = 'Polynomial([0., 1.])'
assert_(res, tgt)
def test_chebyshev_str(self):
0
Source : test_classes.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def check_add(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 + p2
assert_poly_almost_equal(p2 + p1, p3)
assert_poly_almost_equal(p1 + c2, p3)
assert_poly_almost_equal(c2 + p1, p3)
assert_poly_almost_equal(p1 + tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) + p1, p3)
assert_poly_almost_equal(p1 + np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) + p1, p3)
assert_raises(TypeError, op.add, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.add, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.add, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.add, p1, Polynomial([0]))
def check_sub(Poly):
0
Source : test_classes.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def check_sub(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 - p2
assert_poly_almost_equal(p2 - p1, -p3)
assert_poly_almost_equal(p1 - c2, p3)
assert_poly_almost_equal(c2 - p1, -p3)
assert_poly_almost_equal(p1 - tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) - p1, -p3)
assert_poly_almost_equal(p1 - np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) - p1, -p3)
assert_raises(TypeError, op.sub, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.sub, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.sub, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.sub, p1, Polynomial([0]))
def check_mul(Poly):
0
Source : test_classes.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def check_mul(Poly):
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 * p2
assert_poly_almost_equal(p2 * p1, p3)
assert_poly_almost_equal(p1 * c2, p3)
assert_poly_almost_equal(c2 * p1, p3)
assert_poly_almost_equal(p1 * tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) * p1, p3)
assert_poly_almost_equal(p1 * np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) * p1, p3)
assert_poly_almost_equal(p1 * 2, p1 * Poly([2]))
assert_poly_almost_equal(2 * p1, p1 * Poly([2]))
assert_raises(TypeError, op.mul, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.mul, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.mul, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.mul, p1, Polynomial([0]))
def check_floordiv(Poly):
0
Source : test_classes.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def check_floordiv(Poly):
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 // p2, p1)
assert_poly_almost_equal(p4 // c2, p1)
assert_poly_almost_equal(c4 // p2, p1)
assert_poly_almost_equal(p4 // tuple(c2), p1)
assert_poly_almost_equal(tuple(c4) // p2, p1)
assert_poly_almost_equal(p4 // np.array(c2), p1)
assert_poly_almost_equal(np.array(c4) // p2, p1)
assert_poly_almost_equal(2 // p2, Poly([0]))
assert_poly_almost_equal(p2 // 2, 0.5*p2)
assert_raises(
TypeError, op.floordiv, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(
TypeError, op.floordiv, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.floordiv, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.floordiv, p1, Polynomial([0]))
def check_truediv(Poly):
0
Source : test_classes.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def check_mod(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 % p2, p3)
assert_poly_almost_equal(p4 % c2, p3)
assert_poly_almost_equal(c4 % p2, p3)
assert_poly_almost_equal(p4 % tuple(c2), p3)
assert_poly_almost_equal(tuple(c4) % p2, p3)
assert_poly_almost_equal(p4 % np.array(c2), p3)
assert_poly_almost_equal(np.array(c4) % p2, p3)
assert_poly_almost_equal(2 % p2, Poly([2]))
assert_poly_almost_equal(p2 % 2, Poly([0]))
assert_raises(TypeError, op.mod, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.mod, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.mod, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.mod, p1, Polynomial([0]))
def check_divmod(Poly):
0
Source : test_classes.py
with GNU General Public License v3.0
from adityaprakash-bobby
with GNU General Public License v3.0
from adityaprakash-bobby
def check_divmod(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
quo, rem = divmod(p4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, c2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(c4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, tuple(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(tuple(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, np.array(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(np.array(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p2, 2)
assert_poly_almost_equal(quo, 0.5*p2)
assert_poly_almost_equal(rem, Poly([0]))
quo, rem = divmod(2, p2)
assert_poly_almost_equal(quo, Poly([0]))
assert_poly_almost_equal(rem, Poly([2]))
assert_raises(TypeError, divmod, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, divmod, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, divmod, p1, Chebyshev([0]))
else:
assert_raises(TypeError, divmod, p1, Polynomial([0]))
def check_roots(Poly):
0
Source : test_classes.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_add(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 + p2
assert_poly_almost_equal(p2 + p1, p3)
assert_poly_almost_equal(p1 + c2, p3)
assert_poly_almost_equal(c2 + p1, p3)
assert_poly_almost_equal(p1 + tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) + p1, p3)
assert_poly_almost_equal(p1 + np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) + p1, p3)
assert_raises(TypeError, op.add, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.add, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.add, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.add, p1, Polynomial([0]))
def test_sub(Poly):
0
Source : test_classes.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_sub(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 - p2
assert_poly_almost_equal(p2 - p1, -p3)
assert_poly_almost_equal(p1 - c2, p3)
assert_poly_almost_equal(c2 - p1, -p3)
assert_poly_almost_equal(p1 - tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) - p1, -p3)
assert_poly_almost_equal(p1 - np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) - p1, -p3)
assert_raises(TypeError, op.sub, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.sub, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.sub, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.sub, p1, Polynomial([0]))
def test_mul(Poly):
0
Source : test_classes.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_mul(Poly):
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 * p2
assert_poly_almost_equal(p2 * p1, p3)
assert_poly_almost_equal(p1 * c2, p3)
assert_poly_almost_equal(c2 * p1, p3)
assert_poly_almost_equal(p1 * tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) * p1, p3)
assert_poly_almost_equal(p1 * np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) * p1, p3)
assert_poly_almost_equal(p1 * 2, p1 * Poly([2]))
assert_poly_almost_equal(2 * p1, p1 * Poly([2]))
assert_raises(TypeError, op.mul, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.mul, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.mul, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.mul, p1, Polynomial([0]))
def test_floordiv(Poly):
0
Source : test_classes.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_floordiv(Poly):
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 // p2, p1)
assert_poly_almost_equal(p4 // c2, p1)
assert_poly_almost_equal(c4 // p2, p1)
assert_poly_almost_equal(p4 // tuple(c2), p1)
assert_poly_almost_equal(tuple(c4) // p2, p1)
assert_poly_almost_equal(p4 // np.array(c2), p1)
assert_poly_almost_equal(np.array(c4) // p2, p1)
assert_poly_almost_equal(2 // p2, Poly([0]))
assert_poly_almost_equal(p2 // 2, 0.5*p2)
assert_raises(
TypeError, op.floordiv, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(
TypeError, op.floordiv, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.floordiv, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.floordiv, p1, Polynomial([0]))
def test_truediv(Poly):
0
Source : test_classes.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_mod(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 % p2, p3)
assert_poly_almost_equal(p4 % c2, p3)
assert_poly_almost_equal(c4 % p2, p3)
assert_poly_almost_equal(p4 % tuple(c2), p3)
assert_poly_almost_equal(tuple(c4) % p2, p3)
assert_poly_almost_equal(p4 % np.array(c2), p3)
assert_poly_almost_equal(np.array(c4) % p2, p3)
assert_poly_almost_equal(2 % p2, Poly([2]))
assert_poly_almost_equal(p2 % 2, Poly([0]))
assert_raises(TypeError, op.mod, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, op.mod, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, op.mod, p1, Chebyshev([0]))
else:
assert_raises(TypeError, op.mod, p1, Polynomial([0]))
def test_divmod(Poly):
0
Source : test_classes.py
with MIT License
from alvarobartt
with MIT License
from alvarobartt
def test_divmod(Poly):
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
quo, rem = divmod(p4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, c2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(c4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, tuple(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(tuple(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, np.array(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(np.array(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p2, 2)
assert_poly_almost_equal(quo, 0.5*p2)
assert_poly_almost_equal(rem, Poly([0]))
quo, rem = divmod(2, p2)
assert_poly_almost_equal(quo, Poly([0]))
assert_poly_almost_equal(rem, Poly([2]))
assert_raises(TypeError, divmod, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, divmod, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, divmod, p1, Chebyshev([0]))
else:
assert_raises(TypeError, divmod, p1, Polynomial([0]))
def test_roots(Poly):
0
Source : test_classes.py
with Apache License 2.0
from aws-samples
with Apache License 2.0
from aws-samples
def test_simple_polynomial(self):
# default input
p = Polynomial([1, 2, 3])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,x + 3.0\,x^{2}$')
# translated input
p = Polynomial([1, 2, 3], domain=[-2, 0])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,\left(1.0 + x\right) + 3.0\,\left(1.0 + x\right)^{2}$')
# scaled input
p = Polynomial([1, 2, 3], domain=[-0.5, 0.5])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,\left(2.0x\right) + 3.0\,\left(2.0x\right)^{2}$')
# affine input
p = Polynomial([1, 2, 3], domain=[-1, 0])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,\left(1.0 + 2.0x\right) + 3.0\,\left(1.0 + 2.0x\right)^{2}$')
def test_basis_func(self):
0
Source : test_printing.py
with Apache License 2.0
from dashanji
with Apache License 2.0
from dashanji
def test_simple_polynomial(self):
# default input
p = poly.Polynomial([1, 2, 3])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,x + 3.0\,x^{2}$')
# translated input
p = poly.Polynomial([1, 2, 3], domain=[-2, 0])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,\left(1.0 + x\right) + 3.0\,\left(1.0 + x\right)^{2}$')
# scaled input
p = poly.Polynomial([1, 2, 3], domain=[-0.5, 0.5])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,\left(2.0x\right) + 3.0\,\left(2.0x\right)^{2}$')
# affine input
p = poly.Polynomial([1, 2, 3], domain=[-1, 0])
assert_equal(self.as_latex(p),
r'$x \mapsto 1.0 + 2.0\,\left(1.0 + 2.0x\right) + 3.0\,\left(1.0 + 2.0x\right)^{2}$')
def test_basis_func(self):
0
Source : test_printing.py
with GNU General Public License v3.0
from dnn-security
with GNU General Public License v3.0
from dnn-security
def test_polynomial_str(self, inp, tgt):
res = str(poly.Polynomial(inp))
assert_equal(res, tgt)
@pytest.mark.parametrize(('inp', 'tgt'), (
0
Source : trajectory.py
with BSD 3-Clause "New" or "Revised" License
from jgoppert
with BSD 3-Clause "New" or "Revised" License
from jgoppert
def min_deriv_1d(deriv: int, waypoints: List[List[float]], T: List[float], stop: bool) -> Trajectory1D:
n = deriv * 2 # number of poly coeff (order + 1)
S = np.hstack([0, np.cumsum(T)])
legs = len(T)
assert len(waypoints) == len(T) + 1
def coef_weights(t: float, m: int, t0: float):
"""
Polynomial coefficient weights
:param t: time
:param m: derivative order
"""
w = np.zeros(n)
for k in range(m, n):
w[k] = (t - t0)**(k - m) * math.factorial(k) / \
math.factorial(k - m)
return w
b = np.zeros(n * legs)
A = np.zeros((n * legs, n * legs))
eq = 0
for leg in range(legs):
# first waypoint
if leg == 0:
for m in range(n // 2):
A[eq, n * leg:n * (leg + 1)
] = coef_weights(t=S[leg], m=m, t0=S[leg])
if m == 0:
b[eq] = waypoints[leg]
else:
b[eq] = 0
eq += 1
# any waypoint except for first
else:
for m in range(n // 2 - 1):
if m == 0:
A[eq, n * leg:n *
(leg + 1)] = coef_weights(t=S[leg], m=m, t0=S[leg])
b[eq] = waypoints[leg]
eq += 1
elif stop:
A[eq, n * leg:n *
(leg + 1)] = coef_weights(t=S[leg], m=m, t0=S[leg])
b[eq] = 0
eq += 1
# last waypoint only
if leg == legs - 1:
for m in range(n // 2):
A[eq, n * leg:n *
(leg + 1)] = coef_weights(t=S[leg + 1], m=m, t0=S[leg])
if m == 0:
b[eq] = waypoints[leg + 1]
else:
b[eq] = 0
eq += 1
# continuity
if leg > 0:
for m in range(n // 2 + 1):
A[eq, n * (leg - 1):n * leg] = coef_weights(t=S[leg],
m=m, t0=S[leg - 1])
A[eq, n * leg:n * (leg + 1)] = - \
coef_weights(t=S[leg], m=m, t0=S[leg])
b[eq] = 0
eq += 1
if eq != n * legs:
print('warning: equations: {:d}, coefficients: {:d}'.format(
eq, n * legs))
c = np.linalg.pinv(A).dot(b)
P_list = []
for leg in range(legs):
Pi = Polynomial(c[n * leg:n * (leg + 1)])
P_list.append(Pi)
return Trajectory1D(T, P_list)
def min_deriv_4d(deriv: int, waypoints: List[List[float]], T: List[float], stop: bool) -> Trajectory4D:
0
Source : test_classes.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def check_add(Poly) :
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 + p2
assert_poly_almost_equal(p2 + p1, p3)
assert_poly_almost_equal(p1 + c2, p3)
assert_poly_almost_equal(c2 + p1, p3)
assert_poly_almost_equal(p1 + tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) + p1, p3)
assert_poly_almost_equal(p1 + np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) + p1, p3)
assert_raises(TypeError, p1.__add__, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, p1.__add__, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, p1.__add__, Chebyshev([0]))
else:
assert_raises(TypeError, p1.__add__, Polynomial([0]))
def check_sub(Poly) :
0
Source : test_classes.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def check_sub(Poly) :
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 - p2
assert_poly_almost_equal(p2 - p1, -p3)
assert_poly_almost_equal(p1 - c2, p3)
assert_poly_almost_equal(c2 - p1, -p3)
assert_poly_almost_equal(p1 - tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) - p1, -p3)
assert_poly_almost_equal(p1 - np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) - p1, -p3)
assert_raises(TypeError, p1.__sub__, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, p1.__sub__, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, p1.__sub__, Chebyshev([0]))
else:
assert_raises(TypeError, p1.__sub__, Polynomial([0]))
def check_mul(Poly) :
0
Source : test_classes.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def check_mul(Poly) :
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = p1 * p2
assert_poly_almost_equal(p2 * p1, p3)
assert_poly_almost_equal(p1 * c2, p3)
assert_poly_almost_equal(c2 * p1, p3)
assert_poly_almost_equal(p1 * tuple(c2), p3)
assert_poly_almost_equal(tuple(c2) * p1, p3)
assert_poly_almost_equal(p1 * np.array(c2), p3)
assert_poly_almost_equal(np.array(c2) * p1, p3)
assert_poly_almost_equal(p1 * 2, p1 * Poly([2]))
assert_poly_almost_equal(2 * p1, p1 * Poly([2]))
assert_raises(TypeError, p1.__mul__, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, p1.__mul__, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, p1.__mul__, Chebyshev([0]))
else:
assert_raises(TypeError, p1.__mul__, Polynomial([0]))
def check_floordiv(Poly) :
0
Source : test_classes.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def check_floordiv(Poly) :
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 // p2, p1)
assert_poly_almost_equal(p4 // c2, p1)
assert_poly_almost_equal(c4 // p2, p1)
assert_poly_almost_equal(p4 // tuple(c2), p1)
assert_poly_almost_equal(tuple(c4) // p2, p1)
assert_poly_almost_equal(p4 // np.array(c2), p1)
assert_poly_almost_equal(np.array(c4) // p2, p1)
assert_poly_almost_equal(2 // p2, Poly([0]))
assert_poly_almost_equal(p2 // 2, 0.5*p2)
assert_raises(TypeError, p1.__floordiv__, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, p1.__floordiv__, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, p1.__floordiv__, Chebyshev([0]))
else:
assert_raises(TypeError, p1.__floordiv__, Polynomial([0]))
def check_mod(Poly) :
0
Source : test_classes.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def check_mod(Poly) :
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
assert_poly_almost_equal(p4 % p2, p3)
assert_poly_almost_equal(p4 % c2, p3)
assert_poly_almost_equal(c4 % p2, p3)
assert_poly_almost_equal(p4 % tuple(c2), p3)
assert_poly_almost_equal(tuple(c4) % p2, p3)
assert_poly_almost_equal(p4 % np.array(c2), p3)
assert_poly_almost_equal(np.array(c4) % p2, p3)
assert_poly_almost_equal(2 % p2, Poly([2]))
assert_poly_almost_equal(p2 % 2, Poly([0]))
assert_raises(TypeError, p1.__mod__, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, p1.__mod__, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, p1.__mod__, Chebyshev([0]))
else:
assert_raises(TypeError, p1.__mod__, Polynomial([0]))
def check_divmod(Poly) :
0
Source : test_classes.py
with MIT License
from ktraunmueller
with MIT License
from ktraunmueller
def check_divmod(Poly) :
# This checks commutation, not numerical correctness
c1 = list(random((4,)) + .5)
c2 = list(random((3,)) + .5)
c3 = list(random((2,)) + .5)
p1 = Poly(c1)
p2 = Poly(c2)
p3 = Poly(c3)
p4 = p1 * p2 + p3
c4 = list(p4.coef)
quo, rem = divmod(p4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, c2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(c4, p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, tuple(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(tuple(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p4, np.array(c2))
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(np.array(c4), p2)
assert_poly_almost_equal(quo, p1)
assert_poly_almost_equal(rem, p3)
quo, rem = divmod(p2, 2)
assert_poly_almost_equal(quo, 0.5*p2)
assert_poly_almost_equal(rem, Poly([0]))
quo, rem = divmod(2, p2)
assert_poly_almost_equal(quo, Poly([0]))
assert_poly_almost_equal(rem, Poly([2]))
assert_raises(TypeError, divmod, p1, Poly([0], domain=Poly.domain + 1))
assert_raises(TypeError, divmod, p1, Poly([0], window=Poly.window + 1))
if Poly is Polynomial:
assert_raises(TypeError, divmod, p1, Chebyshev([0]))
else:
assert_raises(TypeError, divmod, p1, Polynomial([0]))
def check_roots(Poly):
0
Source : predictor.py
with GNU General Public License v3.0
from mhvk
with GNU General Public License v3.0
from mhvk
def polynomial(self, index, rphase=None, deriv=0,
t0=None, time_unit=u.min, out_unit=None,
convert=False):
"""Prediction polynomial set up for times in MJD
Parameters
----------
index : int or float
index into the polyco table (or MJD for finding closest)
rphase : None or 'fraction' or 'ignore' or float
Phase zero point; if None, use the one stored in polyco.
(Those are typically large, so one looses some precision.)
Can also set 'fraction' to use the stored one modulo 1, which is
fine for folding, but breaks cycle count continuity between sets,
'ignore' for just keeping the value stored in the coefficients,
or a value that should replace the zero point.
deriv : int
derivative of phase to take (1=frequency, 2=fdot, etc.); default 0
Returns
-------
polynomial : Polynomial
set up for MJDs between mjd_mid +/- span
Notes
-----
Units for the polynomial are cycles/second**deriv. Taking a derivative
outside will be per day (e.g., self.polynomial(1).deriv() gives
frequencies in cycles/day)
"""
out_unit = out_unit or time_unit
try:
index = operator.index(index)
except TypeError:
index = self.searchclosest(index)
window = np.array([-1, 1]) * self['span'][index]/2
polynomial = Polynomial(self['coeff'][index],
window.value, window.value)
polynomial.coef[1] += self['f0'][index].to_value(u.cycle/u.minute)
if deriv == 0:
if rphase is None:
polynomial.coef[0] += self['rphase'][index].value
elif rphase == 'fraction':
polynomial.coef[0] += self['rphase']['frac'][index].value % 1
elif rphase != 'ignore':
polynomial.coef[0] = rphase
else:
polynomial = polynomial.deriv(deriv)
polynomial.coef /= u.min.to(out_unit)**deriv
if t0 is not None:
dt = Time(t0, format='mjd') - self['mjd_mid'][index]
polynomial.domain = (window - dt).to(time_unit).value
if convert:
return polynomial.convert()
else:
return polynomial
def phasepol(self, index, rphase=None, t0=0., time_unit=u.day,
0
Source : bezier.py
with MIT License
from nhthn
with MIT License
from nhthn
def get_furthest_point_from(self, point):
"""Given a point, find the point on this Bezier curve that is furthest
from that point.
The function to maximize is (f_x(t) - x) ** 2 + (f_y(t) - y) ** 2.
Set derivative to zero:
f_x'(t) (f_x(t) - x) + f_y'(t) (f_y(t) - y) = 0
This is a 5th-degree polynomial. Find real roots in the interval [0, 1].
Take all these real roots (some of which may be local maxima) along with
f(0) and f(1) and find the furthest point.
"""
x, y = point
t = np.polynomial.Polynomial([0, 1])
f_x = self.f(t, *self.control_points[:, 0])
f_y = self.f(t, *self.control_points[:, 1])
df_x = f_x.deriv()
df_y = f_y.deriv()
distance = (f_x - x) ** 2 + (f_y - y) ** 2
optimizer = df_x * (f_x - x) + df_y * (f_y - y)
roots = optimizer.roots()
roots = np.real(roots[np.isreal(roots)])
roots = roots[(0 < roots) & (roots < 1)]
roots = np.concatenate([roots, [0, 1]])
t = roots[np.argmax(distance(roots))]
return (f_x(t), f_y(t))
def is_tiny(self, threshold):
0
Source : bearing_seal_element.py
with MIT License
from ross-rotordynamics
with MIT License
from ross-rotordynamics
def __init__(
self,
n,
speed=None,
weight=None,
bearing_length=None,
journal_diameter=None,
radial_clearance=None,
oil_viscosity=None,
**kwargs,
):
self.n = n
self.speed = []
for spd in speed:
if spd == 0:
# replace 0 speed with small value to avoid errors
self.speed.append(0.1)
else:
self.speed.append(spd)
self.weight = weight
self.bearing_length = bearing_length
self.journal_diameter = journal_diameter
self.radial_clearance = radial_clearance
self.oil_viscosity = oil_viscosity
# modified Sommerfeld number or the Ocvirk number
Ss = (
journal_diameter
* speed
* oil_viscosity
* bearing_length**3
/ (8 * radial_clearance**2 * weight)
)
self.modified_sommerfeld = Ss
self.sommerfeld = (Ss / np.pi) * (journal_diameter / bearing_length) ** 2
# find roots
self.roots = []
for s in Ss:
poly = Polynomial(
[
1,
-(4 + np.pi**2 * s**2),
(6 - s**2 * (16 - np.pi**2)),
-4,
1,
]
)
self.roots.append(poly.roots())
# select real root between 0 and 1
self.root = []
for roots in self.roots:
for root in roots:
if (0 < root < 1) and np.isreal(root):
self.root.append(np.real(root))
self.eccentricity = [np.sqrt(root) for root in self.root]
self.attitude_angle = [
np.arctan(np.pi * np.sqrt(1 - e**2) / 4 * e) for e in self.eccentricity
]
coefficients = [
"kxx",
"kxy",
"kyx",
"kyy",
"cxx",
"cxy",
"cyx",
"cyy",
]
coefficients_dict = {coeff: [] for coeff in coefficients}
for e, spd in zip(self.eccentricity, self.speed):
π = np.pi
# fmt: off
h0 = 1 / (π ** 2 * (1 - e ** 2) + 16 * e ** 2) ** (3 / 2)
auu = h0 * 4 * (π ** 2 * (2 - e ** 2) + 16 * e ** 2)
auv = h0 * π * (π ** 2 * (1 - e ** 2) ** 2 - 16 * e ** 4) / (e * np.sqrt(1 - e ** 2))
avu = - h0 * π * (π ** 2 * (1 - e ** 2) * (1 + 2 * e ** 2) + 32 * e ** 2 * (1 + e ** 2)) / (e * np.sqrt(1 - e ** 2))
avv = h0 * 4 * (π ** 2 * (1 + 2 * e ** 2) + 32 * e ** 2 * (1 + e ** 2) / (1 - e ** 2))
buu = h0 * 2 * π * np.sqrt(1 - e ** 2) * (π ** 2 * (1 + 2 * e ** 2) - 16 * e ** 2) / e
buv = bvu = -h0 * 8 * (π ** 2 * (1 + 2 * e ** 2) - 16 * e ** 2)
bvv = h0 * 2 * π * (π ** 2 * (1 - e ** 2) ** 2 + 48 * e ** 2) / (e * np.sqrt(1 - e ** 2))
# fmt: on
for coeff, term in zip(
coefficients, [auu, auv, avu, avv, buu, buv, bvu, bvv]
):
if coeff[0] == "k":
coefficients_dict[coeff].append(weight / radial_clearance * term)
elif coeff[0] == "c":
coefficients_dict[coeff].append(
weight / (radial_clearance * spd) * term
)
super().__init__(self.n, frequency=self.speed, **coefficients_dict, **kwargs)
class BearingElement6DoF(BearingElement):
0
Source : predictor.py
with GNU General Public License v3.0
from theXYZT
with GNU General Public License v3.0
from theXYZT
def polynomial(
self,
index,
rphase=None,
deriv=0,
t0=None,
time_unit=u.min,
out_unit=None,
convert=False,
):
"""Prediction polynomial set up for times in MJD
Parameters
----------
index : int or float
index into the polyco table (or MJD for finding closest)
rphase : None or 'fraction' or 'ignore' or float
Phase zero point; if None, use the one stored in polyco.
(Those are typically large, so one looses some precision.)
Can also set 'fraction' to use the stored one modulo 1, which is
fine for folding, but breaks cycle count continuity between sets,
'ignore' for just keeping the value stored in the coefficients,
or a value that should replace the zero point.
deriv : int
derivative of phase to take (1=frequency, 2=fdot, etc.); default 0
Returns
-------
polynomial : Polynomial
set up for MJDs between mjd_mid +/- span
Notes
-----
Units for the polynomial are cycles/second**deriv. Taking a derivative
outside will be per day (e.g., self.polynomial(1).deriv() gives
frequencies in cycles/day)
"""
out_unit = out_unit or time_unit
try:
index = operator.index(index)
except TypeError:
index = self.searchclosest(index)
window = np.array([-1, 1]) * self["span"][index] / 2
polynomial = Polynomial(self["coeff"][index], window.value, window.value)
polynomial.coef[1] += self["f0"][index].to_value(u.cycle / u.minute)
if deriv == 0:
if rphase is None:
polynomial.coef[0] += self["rphase"][index].value
elif rphase == "fraction":
polynomial.coef[0] += self["rphase"]["frac"][index].value % 1
elif rphase != "ignore":
polynomial.coef[0] = rphase
else:
polynomial = polynomial.deriv(deriv)
polynomial.coef /= u.min.to(out_unit) ** deriv
if t0 is not None:
dt = Time(t0, format="mjd") - self["mjd_mid"][index]
polynomial.domain = (window - dt).to(time_unit).value
if convert:
return polynomial.convert()
else:
return polynomial
def phasepol(self, index, rphase=None, t0=0.0, time_unit=u.day, convert=False):
0
Source : sentinel1_xml_mappings.py
with MIT License
from umr-lops
with MIT License
from umr-lops
def azimuth_fmrate(azimuthtime, t0, c0, c1, c2, polynomial):
"""
decode FM rate information from xml annotations
Parameters
----------
azimuthtime
t0
c0
c1
c2
polynomial
Returns
-------
xarray.Dataset
containing the polynomial coefficient for each of the FM rate along azimuth time coordinates
"""
if ( np.sum([c.size for c in [c0,c1,c2]]) != 0) and (len(polynomial) == 0):
# old IPF annotation
polynomial = np.stack([c0, c1, c2], axis=1)
res = xr.Dataset()
res['t0'] = xr.DataArray(t0,dims=['azimuth_time'],coords={'azimuth_time':azimuthtime})
res['polynomial'] = xr.DataArray([Polynomial(p) for p in polynomial],
dims=['azimuth_time'],
coords={'azimuth_time':azimuthtime})
return res
def image(atrack_time_range, atrack_size, xtrack_size, incidence_angle_mid_swath, azimuth_time_interval,
See More Examples