def solve_phase_degen(data_xx, data_yy, model_xx, model_yy, ubls, plot=False):#data should be time by ubl at single freq. data * phasegensolution = model
    if data_xx.shape != data_yy.shape or data_xx.shape != model_xx.shape or data_xx.shape != model_yy.shape or data_xx.shape[1] != ubls.shape[0]:
        raise ValueError("Shapes mismatch: %s %s %s %s, ubl shape %s"%(data_xx.shape, data_yy.shape, model_xx.shape, model_yy.shape, ubls.shape))
    A = np.zeros((len(ubls) * 2, 2))
    b = np.zeros(len(ubls) * 2)

    nrow = 0
    for p, (data, model) in enumerate(zip([data_xx, data_yy], [model_xx, model_yy])):
        for u, ubl in enumerate(ubls):
            amp_mask = (np.abs(data[:, u]) > (np.median(np.abs(data[:, u])) / 2.))
            A[nrow] = ubl[:2]
            b[nrow] = omni.medianAngle(np.angle(model[:, u] / data[:, u])[amp_mask])
            nrow += 1

    if plot:
        plt.hist((np.array(A).dot(phase_cal)-b + PI)%TPI-PI)
        plt.title('phase fitting error')
        plt.show()

    #sooolve
    return omni.solve_slope(np.array(A), np.array(b), 1)
Пример #2
0
            bindex = bindex + [[a, int(c.ublindex[u][mask, 2][0])] for a in c.ublindex[u][mask, 2].astype(int)]#inside crossindex
        if not mask.all():
            A = A + (c.antloc[c.ublindex[u][~mask, 0].astype(int)] - c.antloc[int(c.ublindex[u][~mask, 0][0])]).tolist()
            bindex = bindex + [[a, int(c.ublindex[u][~mask, 2][0])] for a in c.ublindex[u][~mask, 2].astype(int)]#inside crossindex
A = np.array(A)[:, :2]
A = np.concatenate((A, -A), axis=0)
bindex = c.subsetbl[c.crossindex[np.array(bindex).astype(int)]]#inside all bl

b = np.empty((len(A), rawdata.shape[1], rawdata.shape[2]), dtype='float32')
for p, pol in enumerate(crosspols.keys()):
    b[p*len(bindex):(p+1)*len(bindex)] = (np.angle(rawdata[p][..., bindex[:,0]]) - np.angle(rawdata[p][..., bindex[:,1]])).transpose((2,0,1))

crosstimer = omni.Timer()
print "Solving cross calibration....",
sys.stdout.flush()
sol = omni.solve_slope(A, b, 1)
#sol[:,flags['xx']] = np.nan
#sol[:,flags['yy']] = np.nan
print "Done.",
sys.stdout.flush()
crosstimer.tick()
if make_plots:
    for i in range(len(sol)):
        plt.subplot('21%i'%(i+1))
        min_period = TPI / min(abs(A[:,i][abs(A[:,i]) > 1]))
        plt.imshow((sol[i]+min_period/2.)%min_period-min_period/2.);plt.colorbar()
    plt.show()
#apply to data
crosscalpar = {}
for pol in ['xx','yy']:
    crosscalpar[pol[0]] = np.ones((rawdata.shape[1], rawdata.shape[2], c.nTotalAnt), dtype='complex64')
Пример #3
0
                               ]  #inside crossindex
A = np.array(A)[:, :2]
A = np.concatenate((A, -A), axis=0)
bindex = c.subsetbl[c.crossindex[np.array(bindex).astype(int)]]  #inside all bl

b = np.empty((len(A), rawdata.shape[1], rawdata.shape[2]), dtype='float32')
for p, pol in enumerate(crosspols.keys()):
    b[p * len(bindex):(p + 1) *
      len(bindex)] = (np.angle(rawdata[p][..., bindex[:, 0]]) -
                      np.angle(rawdata[p][..., bindex[:, 1]])).transpose(
                          (2, 0, 1))

crosstimer = omni.Timer()
print "Solving cross calibration....",
sys.stdout.flush()
sol = omni.solve_slope(A, b, 1)
sol[:, flags['xx']] = np.nan
sol[:, flags['yy']] = np.nan
median_sol = np.array([nanmedian(sol[i]) for i in range(len(sol))])
print "Done.",
sys.stdout.flush()
crosstimer.tick()
if make_plots:
    for i in range(len(sol)):
        plt.subplot('21%i' % (i + 1))
        min_period = TPI / min(abs(A[:, i][abs(A[:, i]) > 1]))
        plt.imshow((sol[i] + min_period / 2.) % min_period - min_period / 2.)
        plt.colorbar()
    plt.show()
#apply to data
crosscalpar = {}