In [45]:
import sys
import sympy
from sympy import *
from sympy import Rational as frac
from sympy.tensor.tensor import TensorIndexType, tensor_indices, tensorhead
init_printing()

# Various scalars
vartheta, varphi = sympy.symbols('vartheta, varphi', real=True)
v, M, nu, delta, R_L = sympy.symbols('v, M, nu, delta, R_L', real=True)
Sigma_n, Sigma_ell, Sigma_lambda = sympy.symbols('Sigma_n, Sigma_ell, Sigma_lambda', real=True)
S_n, S_ell, S_lambda = sympy.symbols('S_n, S_ell, S_lambda', real=True)

# Tell sympy we're just doing Euclidean stuff
Euclidean = TensorIndexType('Euclidean', dummy_fmt='E')
Euclidean.data = [1,1,1]
g = Euclidean.metric
i0,i1,i2,i3 = tensor_indices('i0:4', Euclidean)

# Basis vectors of the source system
nHat, lambdaHat, ellHat = tensorhead(r'\hat{n}, \hat{\lambda}, \hat{\ell}', [Euclidean], [[1]])
nHat.data = [1,0,0]
lambdaHat.data = [0,1,0]
ellHat.data = [0,0,1]

# Spin vectors of the source system
Sigma,S = tensorhead(r'\vec{\Sigma}, \vec{S}', [Euclidean], [[1]])
Sigma.data = [Sigma_n, Sigma_lambda, Sigma_ell]
S.data = [S_n, S_lambda, S_ell]

# Basis vectors of the detector
NHat, PHat, QHat = tensorhead(r'\hat{N}, \hat{P}, \hat{Q}', [Euclidean], [[1]])
NHat.data = [sin(vartheta)*cos(varphi), sin(vartheta)*sin(varphi), cos(vartheta)]
PHat.data = [sin(varphi), -cos(varphi), 0]
QHat.data = [cos(vartheta)*cos(varphi), cos(vartheta)*sin(varphi), -sin(vartheta)]

# This projects the strain field onto the detector
D_jk = ( (PHat(i0)*PHat(i1) - QHat(i0)*QHat(i1)) - sympy.I*(PHat(i0)*QHat(i1) + QHat(i0)*PHat(i1)) )/2;
def complex_h_from_tensor(h_jk):
    return sympy.simplify((h_jk(i0,i1) * D_jk(i2,i3) * g(-i0,-i2) * g(-i1,-i3)).contract_metric(g))
    #return sympy.simplify(h_jk(i0,i1) * D_jk(-i0,-i1))

In [42]:
h_jk = 4*(M/R_L)*nu*v**2*(lambdaHat(i0)*lambdaHat(i1) - nHat(i0)*nHat(i1))

In [43]:
h_jk(i0,i1).data


Out[43]:
array([[-4*M*nu*v**2/R_L, 0, 0],
       [0, 4*M*nu*v**2/R_L, 0],
       [0, 0, 0]], dtype=object)

In [46]:
h = complex_h_from_tensor(h_jk)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-46-7ff4900f58ec> in <module>()
----> 1 h = complex_h_from_tensor(h_jk)

<ipython-input-45-725c74b127ac> in complex_h_from_tensor(h_jk)
     38 D_jk = ( (PHat(i0)*PHat(i1) - QHat(i0)*QHat(i1)) - sympy.I*(PHat(i0)*QHat(i1) + QHat(i0)*PHat(i1)) )/2;
     39 def complex_h_from_tensor(h_jk):
---> 40     return sympy.simplify((h_jk(i0,i1) * D_jk(i2,i3) * g(-i0,-i2) * g(-i1,-i3)).contract_metric(g))
     41     #return sympy.simplify(h_jk(i0,i1) * D_jk(-i0,-i1))

/Users/boyle/.continuum/anaconda/lib/python2.7/site-packages/sympy/tensor/tensor.pyc in __mul__(self, other)
   2334 
   2335     def __mul__(self, other):
-> 2336         tadd = TensAdd(*(x*other for x in self.args))
   2337         if not isinstance(tadd, TensExpr):
   2338             if (self.data is not None):

/Users/boyle/.continuum/anaconda/lib/python2.7/site-packages/sympy/tensor/tensor.pyc in <genexpr>((x,))
   2334 
   2335     def __mul__(self, other):
-> 2336         tadd = TensAdd(*(x*other for x in self.args))
   2337         if not isinstance(tadd, TensExpr):
   2338             if (self.data is not None):

/Users/boyle/.continuum/anaconda/lib/python2.7/site-packages/sympy/tensor/tensor.pyc in __mul__(self, other)
   2817             return tmul
   2818         if isinstance(other, TensAdd):
-> 2819             return TensAdd(*[self*x for x in other.args])
   2820 
   2821         matrix_behavior_kinds = dict()

/Users/boyle/.continuum/anaconda/lib/python2.7/site-packages/sympy/tensor/tensor.pyc in __mul__(self, other)
   2847             matrix_behavior_kinds[key] = v2
   2848 
-> 2849         new_tids = self._tids*other._tids
   2850         coeff = self._coeff*other._coeff
   2851         tmul = TensMul.from_TIDS(coeff, new_tids)

/Users/boyle/.continuum/anaconda/lib/python2.7/site-packages/sympy/tensor/tensor.pyc in __mul__(f, g)
    583 
    584     def __mul__(f, g):
--> 585         return VTIDS(*VTIDS.mul(f, g))
    586 
    587     @staticmethod

/Users/boyle/.continuum/anaconda/lib/python2.7/site-packages/sympy/tensor/tensor.pyc in mul(f, g)
    579         """
    580         components, free, dum = TIDS.mul(f, g)
--> 581         data = VTIDS._contract_ndarray(f.free, g.free, f.data, g.data)
    582         return components, free, dum, data
    583 

AttributeError: 'TIDS' object has no attribute 'data'