Skip to content

Commit

Permalink
Neaten stokes code
Browse files Browse the repository at this point in the history
  • Loading branch information
landmanbester committed Nov 23, 2023
1 parent f1442ef commit 220b578
Showing 1 changed file with 28 additions and 104 deletions.
132 changes: 28 additions & 104 deletions pfb/utils/stokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,67 +351,29 @@ def stokes_funcs(data, jones, product, pol):
if jones.ndim == 6: # Full mode
if product == literal('I'):
i = 0
Wsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)


Dsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(C[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

elif product == literal('Q'):
i = 1
Wsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)

Dsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(C[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

elif product == literal('U'):
i = 2
Wsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)
Dsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(C[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

elif product == literal('V'):
i = 3
Wsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)

Dsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(D[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

else:
raise ValueError(f"Unknown polarisation product {product}")

Wsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3),
sm.simplify(sm.expand(W[i,i])))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)


Dsymb = lambdify((gp00, gp01, gp10, gp11,
gq00, gq01, gq10, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(smexpand(C[i])))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

@njit(nogil=True, fastmath=True, inline='always')
def wfunc(gp, gq, W):
gp00 = gp[0,0]
Expand Down Expand Up @@ -465,67 +427,29 @@ def vfunc(gp, gq, W, V):

if product == literal('I'):
i = 0
Wsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)


Dsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(C[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

elif product == literal('Q'):
i = 1
Wsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)

Dsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(C[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

elif product == literal('U'):
i = 2
Wsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)

Dsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(C[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

elif product == literal('V'):
i = 3
Wsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3),
sm.simplify(W[i,i]))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)

Dsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(C[i]))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)
else:
raise ValueError(f"Unknown polarisation product {product}")

Wsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3),
sm.simplify(sm.expand(W[i,i])))
Wjfn = njit(nogil=True, fastmath=True, inline='always')(Wsymb)


Dsymb = lambdify((gp00, gp11,
gq00, gq11,
w0, w1, w2, w3,
v00, v01, v10, v11),
sm.simplify(sm.expand(C[i])))
Djfn = njit(nogil=True, fastmath=True, inline='always')(Dsymb)

@njit(nogil=True, fastmath=True, inline='always')
def wfunc(gp, gq, W):
gp00 = gp[0]
Expand Down

0 comments on commit 220b578

Please sign in to comment.