blimpy/calib_utils/stokescal.py
def apply_Mueller(I,Q,U,V, gain_offsets, phase_offsets, chan_per_coarse, feedtype='l'):
    '''
    Returns calibrated Stokes parameters for an observation given an array
    of differential gains and phase differences.
    '''

    #Find shape of data arrays and calculate number of coarse channels
    shape = I.shape
    ax0 = I.shape[0]
    ax1 = I.shape[1]
    nchans = I.shape[2]
    ncoarse = nchans/chan_per_coarse

    #Reshape data arrays to separate coarse channels
    I = np.reshape(I,(ax0,ax1,ncoarse,chan_per_coarse))
    Q = np.reshape(Q,(ax0,ax1,ncoarse,chan_per_coarse))
    U = np.reshape(U,(ax0,ax1,ncoarse,chan_per_coarse))
    V = np.reshape(V,(ax0,ax1,ncoarse,chan_per_coarse))

    #Swap axes 2 and 3 to in order for broadcasting to work correctly
    I = np.swapaxes(I,2,3)
    Q = np.swapaxes(Q,2,3)
    U = np.swapaxes(U,2,3)
    V = np.swapaxes(V,2,3)

    #Apply top left corner of electronics chain inverse Mueller matrix
    a = 1/(1-gain_offsets**2)
    if feedtype=='l':
        Icorr = a*(I-gain_offsets*Q)
        Qcorr = a*(-1*gain_offsets*I+Q)
        I = None
        Q = None
    if feedtype=='c':
        Icorr = a*(I-gain_offsets*V)
        Vcorr = a*(-1*gain_offsets*I+V)
        I = None
        V = None

    #Apply bottom right corner of electronics chain inverse Mueller matrix
    if feedtype=='l':
        Ucorr = U*np.cos(phase_offsets)-V*np.sin(phase_offsets)
        Vcorr = U*np.sin(phase_offsets)+V*np.cos(phase_offsets)
        U = None
        V = None
    if feedtype=='c':
        Qcorr = Q*np.cos(phase_offsets)+U*np.sin(phase_offsets)
        Ucorr = -1*Q*np.sin(phase_offsets)+U*np.cos(phase_offsets)
        Q = None
        U = None

    #Reshape arrays to original shape
    Icorr = np.reshape(np.swapaxes(Icorr,2,3),shape)
    Qcorr = np.reshape(np.swapaxes(Qcorr,2,3),shape)
    Ucorr = np.reshape(np.swapaxes(Ucorr,2,3),shape)
    Vcorr = np.reshape(np.swapaxes(Vcorr,2,3),shape)

    #Return corrected data arrays
    return Icorr,Qcorr,Ucorr,Vcorr
def apply_Mueller(I,Q,U,V, gain_offsets, phase_offsets, chan_per_coarse, feedtype='l'):
    '''
    Returns calibrated Stokes parameters for an observation given an array
    of differential gains and phase differences.
    '''

    #Find shape of data arrays and calculate number of coarse channels
    shape = I.shape
    ax0 = I.shape[0]
    ax1 = I.shape[1]
    nchans = I.shape[2]
    ncoarse = nchans/chan_per_coarse

    #Reshape data arrays to separate coarse channels
    I = np.reshape(I,(ax0,ax1,ncoarse,chan_per_coarse))
    Q = np.reshape(Q,(ax0,ax1,ncoarse,chan_per_coarse))
    U = np.reshape(U,(ax0,ax1,ncoarse,chan_per_coarse))
    V = np.reshape(V,(ax0,ax1,ncoarse,chan_per_coarse))

    #Swap axes 2 and 3 to in order for broadcasting to work correctly
    I = np.swapaxes(I,2,3)
    Q = np.swapaxes(Q,2,3)
    U = np.swapaxes(U,2,3)
    V = np.swapaxes(V,2,3)

    #Apply top left corner of electronics chain inverse Mueller matrix
    a = 1/(1-gain_offsets**2)
    if feedtype=='l':
        Icorr = a*(I-gain_offsets*Q)
        Qcorr = a*(-1*gain_offsets*I+Q)
        I = None
        Q = None
    if feedtype=='c':
        Icorr = a*(I-gain_offsets*V)
        Vcorr = a*(-1*gain_offsets*I+V)
        I = None
        V = None

    #Apply bottom right corner of electronics chain inverse Mueller matrix
    if feedtype=='l':
        Ucorr = U*np.cos(phase_offsets)-V*np.sin(phase_offsets)
        Vcorr = U*np.sin(phase_offsets)+V*np.cos(phase_offsets)
        U = None
        V = None
    if feedtype=='c':
        Qcorr = Q*np.cos(phase_offsets)+U*np.sin(phase_offsets)
        Ucorr = -1*Q*np.sin(phase_offsets)+U*np.cos(phase_offsets)
        Q = None
        U = None

    #Reshape arrays to original shape
    Icorr = np.reshape(np.swapaxes(Icorr,2,3),shape)
    Qcorr = np.reshape(np.swapaxes(Qcorr,2,3),shape)
    Ucorr = np.reshape(np.swapaxes(Ucorr,2,3),shape)
    Vcorr = np.reshape(np.swapaxes(Vcorr,2,3),shape)

    #Return corrected data arrays
    return Icorr,Qcorr,Ucorr,Vcorr
def apply_Mueller ( I , Q , U , V , gain_offsets , phase_offsets , chan_per_coarse , feedtype = 'l' ) : #Find shape of data arrays and calculate number of coarse channels shape = I . shape ax0 = I . shape [ 0 ] ax1 = I . shape [ 1 ] nchans = I . shape [ 2 ] ncoarse = nchans / chan_per_coarse #Reshape data arrays to separate coarse channels I = np . reshape ( I , ( ax0 , ax1 , ncoarse , chan_per_coarse ) ) Q = np . reshape ( Q , ( ax0 , ax1 , ncoarse , chan_per_coarse ) ) U = np . reshape ( U , ( ax0 , ax1 , ncoarse , chan_per_coarse ) ) V = np . reshape ( V , ( ax0 , ax1 , ncoarse , chan_per_coarse ) ) #Swap axes 2 and 3 to in order for broadcasting to work correctly I = np . swapaxes ( I , 2 , 3 ) Q = np . swapaxes ( Q , 2 , 3 ) U = np . swapaxes ( U , 2 , 3 ) V = np . swapaxes ( V , 2 , 3 ) #Apply top left corner of electronics chain inverse Mueller matrix a = 1 / ( 1 - gain_offsets ** 2 ) if feedtype == 'l' : Icorr = a * ( I - gain_offsets * Q ) Qcorr = a * ( - 1 * gain_offsets * I + Q ) I = None Q = None if feedtype == 'c' : Icorr = a * ( I - gain_offsets * V ) Vcorr = a * ( - 1 * gain_offsets * I + V ) I = None V = None #Apply bottom right corner of electronics chain inverse Mueller matrix if feedtype == 'l' : Ucorr = U * np . cos ( phase_offsets ) - V * np . sin ( phase_offsets ) Vcorr = U * np . sin ( phase_offsets ) + V * np . cos ( phase_offsets ) U = None V = None if feedtype == 'c' : Qcorr = Q * np . cos ( phase_offsets ) + U * np . sin ( phase_offsets ) Ucorr = - 1 * Q * np . sin ( phase_offsets ) + U * np . cos ( phase_offsets ) Q = None U = None #Reshape arrays to original shape Icorr = np . reshape ( np . swapaxes ( Icorr , 2 , 3 ) , shape ) Qcorr = np . reshape ( np . swapaxes ( Qcorr , 2 , 3 ) , shape ) Ucorr = np . reshape ( np . swapaxes ( Ucorr , 2 , 3 ) , shape ) Vcorr = np . reshape ( np . swapaxes ( Vcorr , 2 , 3 ) , shape ) #Return corrected data arrays return Icorr , Qcorr , Ucorr , Vcorr
Returns calibrated Stokes parameters for an observation given an array
    of differential gains and phase differences.
Returns calibrated Stokes parameters for an observation given an array of differential gains and phase differences .