Esempio n. 1
0
def r_mat_corr(yerroblist,
               ytimestep,
               y_strlst,
               r_diag,
               corr=0.3,
               tau=1.,
               cut_off=4.):
    """ Creates a correlated R matrix.
    """
    r_corr = np.eye(len(ytimestep))  #MAKE SURE ALL VALUES ARE FLOATS FIRST!!!!
    for i in xrange(len(ytimestep)):
        if y_strlst[i] == 'nee_day' or y_strlst[i] == 'nee_night':
            for j in xrange(len(ytimestep)):
                if y_strlst[j] == 'nee_day' or y_strlst[j] == 'nee_night':
                    if abs(ytimestep[i] - ytimestep[j]) < cut_off:
                        r_corr[i, j] = corr*np.exp(-(abs(float(ytimestep[i])-float(ytimestep[j]))**2)/float(tau)**2) \
                                      + (1-corr)*smp.KroneckerDelta(ytimestep[i], ytimestep[j])
                    if y_strlst[j] == 'nee_day' and y_strlst[i] == 'nee_night':
                        r_corr[i, j] = corr * np.exp(
                            -(abs(float(ytimestep[i]) - float(ytimestep[j]))**
                              2) / float(tau)**2)
                    elif y_strlst[i] == 'nee_day' and y_strlst[
                            j] == 'nee_night':
                        r_corr[i, j] = corr * np.exp(
                            -(abs(float(ytimestep[i]) - float(ytimestep[j]))**
                              2) / float(tau)**2)
        if y_strlst[i] == 'nee':
            for j in xrange(len(ytimestep)):
                if y_strlst[j] == 'nee':
                    if abs(ytimestep[i] - ytimestep[j]) < cut_off:
                        r_corr[i, j] = corr*np.exp(-(abs(float(ytimestep[i])-float(ytimestep[j]))**2)/float(tau)**2) \
                                      + (1-corr)*smp.KroneckerDelta(ytimestep[i], ytimestep[j])
    r = np.dot(np.dot((np.sqrt(r_diag)), r_corr), np.sqrt(r_diag))
    return r_corr, r
Esempio n. 2
0
 def _set_legcoefficients(self):
     """
     set Legrende coefficients
     needs to be a function that can be later evaluated by subsituting 'n'
     """
     # only 3 coefficients are needed to correctly represent
     # the Rayleigh scattering function
     self.ncoefs = 3
     n = sp.Symbol('n')
     self.legcoefs = ((3. / (16. * sp.pi)) * ((4. / 3.) *
                                              sp.KroneckerDelta(0, n) +
                                              (2. / 3.) *
                                              sp.KroneckerDelta(2, n))
                      ).expand()
Esempio n. 3
0
def test_kronecker_delta():
    x = Symbol("x")
    y = Symbol("y")
    e1 = sympy.KroneckerDelta(sympy.Symbol("x"), sympy.Symbol("y"))
    e2 = KroneckerDelta(x, y)
    assert sympify(e1) == e2
    assert e2._sympy_() == e1
Esempio n. 4
0
def KroneckerDelta(i, j, simplify=True):
    """Kronecker delta symbol.

    Return :class:`One` (`i` equals `j`)), :class:`Zero` (`i` and `j` are
    non-symbolic an unequal), or a :class:`ScalarValue` wrapping SymPy's
    :class:`~sympy.functions.special.tensor_functions.KroneckerDelta`.

        >>> i, j = IdxSym('i'), IdxSym('j')
        >>> KroneckerDelta(i, i)
        One
        >>> KroneckerDelta(1, 2)
        Zero
        >>> KroneckerDelta(i, j)
        KroneckerDelta(i, j)

    By default, the Kronecker delta is returned in a simplified form, e.g::

        >>> KroneckerDelta((i+1)/2, (j+1)/2)
        KroneckerDelta(i, j)

    This may be suppressed by setting `simplify` to False::

        >>> KroneckerDelta((i+1)/2, (j+1)/2, simplify=False)
        KroneckerDelta(i/2 + 1/2, j/2 + 1/2)

    Raises:
        TypeError: if `i` or `j` is not an integer or sympy expression. There
            is no automatic sympification of `i` and `j`.
    """
    from qalgebra.core.scalar_algebra import One, ScalarValue

    if not isinstance(i, (int, sympy.Basic)):
        raise TypeError(
            "i is not an integer or sympy expression: %s" % type(i)
        )
    if not isinstance(j, (int, sympy.Basic)):
        raise TypeError(
            "j is not an integer or sympy expression: %s" % type(j)
        )
    if i == j:
        return One
    else:
        delta = sympy.KroneckerDelta(i, j)
        if simplify:
            delta = _simplify_delta(delta)
        return ScalarValue.create(delta)
Esempio n. 5
0
 def _set_legcoefficients(self):
     self.ncoefs = 1
     n = sp.Symbol('n')
     self.legcoefs = (1. / sp.pi) * sp.KroneckerDelta(0, n)
Esempio n. 6
0
import galgebra.ga, sympy, operator, numpy

base = galgebra.ga.Ga('\u0411', coords=sympy.symbols('x:z', real=True))
assert base.mvr() == tuple(
    operator.matmul(*(numpy.array(_) for _ in (
        base.mv(), base.g_inv))))  # base.g_inv is the inverse matrix of base.g
for down in range(base.n):
    for up in range(base.n):
        assert (base.mv()[down]
                | base.mvr()[up]).simplify() == sympy.KroneckerDelta(down, up)
sc.plot_log2D((kmesh[0][:, :, 10], kmesh[1][:, :, 10]),
              phi11[:, :, 10],
              label_S="$\log_{10}{S}$",
              C=10**-2,
              fig_num='a',
              nl=30,
              minS=-1.5)

# In[R-K in multidimensions]

# Functions

dZsy = sympy.Matrix(3, 1, lambda i, j: sympy.var('dZ%d' % (i + 1)))
Msy = sympy.Matrix(
    3, 1, lambda i, j: (-sympy.KroneckerDelta(i, 0) + 2 * ksy[0] * ksy[i] /
                        (ksy.dot(ksy))) * dZsy[2])

x = sympy.symbols("x")
y = sympy.Function("y")
f = y(x)**2 + x
f_np = sympy.lambdify((y(x), x), f)
y0 = 0
xp = np.linspace(0, 1.9, 100)
yp = sp.integrate.odeint(f_np, y0, xp)
xm = np.linspace(0, -5, 100)
ym = sp.integrate.odeint(f_np, y0, xm)
fig, ax = plt.subplots(1, 1, figsize=(4, 4))
plot_direction_field(x, y(x), f, ax=ax)
ax.plot(xm, ym, 'b', lw=2)
ax.plot(xp, yp, 'r', lw=2)