diff --git a/resolve/re/response.py b/resolve/re/response.py index 488d834d86629de56a8db00a5b5dfe33ac177bc1..91cb7da6c7f3b689eec43af48702c30c742f654e 100644 --- a/resolve/re/response.py +++ b/resolve/re/response.py @@ -19,17 +19,21 @@ def get_binbounds(coordinates): def convert_polarization(inp, inp_pol, out_pol): - mat_stokes_to_circular = jnp.array( - [[1, 0, 0, 1], [0, 1, 1j, 0], [0, 1, -1j, 0], [1, 0, 0, -1]] - ) - mat_stokes_to_linear = jnp.array( - [[1, 1, 0, 0], [1, -1, 0, 0], [0, 0, 1, 1j], [0, 0, 1, -1j]] - ) - if set(inp_pol) == {"I", "Q", "U", "V"}: - if set(out_pol) == {"RR", "RL", "LR", "LL"}: - return jnp.tensordot(mat_stokes_to_circular, inp, axes=([0], [0])) - elif set(out_pol) == {"XX", "XY", "YX", "YY"}: - return jnp.tensordot(mat_stokes_to_linear, inp, axes=([0], [0])) + mat_stokes_to_circular = jnp.array([[1,0,0,1], + [0,1,1,0], + [0,1j,-1j,0], + [1,0,0,-1]]) + mat_stokes_to_linear = jnp.array([[1,1,0,0], + [1,-1,0,0], + [0,0,1,1], + [0,0,1j,-1j]]) + if inp_pol == ('I', 'Q', 'U', 'V'): + if jnp.any(inp[0]**2 < inp[1]**2 + inp[2]**2 + inp[3]**2) or jnp.any(inp[0]) <= 0: + raise ValueError('Values for Stokes parameters are inconsistent.') + if out_pol == ('RR', 'RL', 'LR', 'LL'): + return jnp.tensordot(mat_stokes_to_circular, inp, axes=([0],[0])) + elif out_pol == ('XX', 'XY', 'YX', 'YY'): + return jnp.tensordot(mat_stokes_to_linear, inp, axes=([0],[0])) elif inp_pol == ("I",): if out_pol == ("LL", "RR") or out_pol == ("XX", "YY"): new_shp = list(inp.shape)