def Vij_beam_correct(j, Vij, centre=None): """Corrects Vij for the beam amplitude. This is required when beam correction has not been done during calibration. Assumes identical beam patterns. Assumes calibrator source is at centre of image""" my_shape = Vij[0, 0, :, :].shape if centre is None: centre = (my_shape[0] / 2, my_shape[1] / 2) # Cal source at image centre logger.warning('Using centre of image as calibrator location') temp = beam_tools.makeUnpolInstrumentalResponse(j[:, :, centre[0], centre[1]], j[:, :, centre[0], centre[1]]) XX = temp[0, 0] YY = temp[1, 1] # XY = temp[0, 1] # YX = temp[1, 0] correction = np.array([[XX, XX ** 0.5 * YY ** 0.5], [XX ** 0.5 * YY ** 0.5, YY]]) # correction=np.array([[XX,XY],[YX,YY]]) # correction=np.array([[XX,1],[1,YY]]) logger.warning('Calibration correction factors: XX=%s, XY=%s, YX=%s, YY=%s' % (correction[0, 0], correction[0, 1], correction[1, 0], correction[1, 1])) # Tile 2x2 correction matrix apply to Vij Vij_corrected = Vij * np.tile(correction[:, :, np.newaxis, np.newaxis], (my_shape[0], my_shape[1])) return Vij_corrected
def Dij_beam_correct(j, Dij, centre=None): """Corrects Dij: Dij'' = E^-1 Dij' (E^H)^-1 This is required when beam correction has not been done during calibration. Assumes identical beam patterns. Uses j at direction 'centre' """ my_shape = Dij.shape if len(my_shape) == 4: if centre is None: centre = (Dij[0, 0, :, :].shape[0] / 2, Dij[0, 0, :, :].shape[1] / 2 ) # Cal source at image centre logger.warning('Using centre of image as calibrator location') # Get jones at location of calibrator source my_j = j[:, :, centre[0], centre[1]] logger.debug('My Jones correction:\n[%s %s]\n[%s %s]' % (my_j[0, 0], my_j[0, 1], my_j[1, 0], my_j[1, 1])) temp = beam_tools.makeUnpolInstrumentalResponse(my_j, my_j) logger.debug('My Jones correction:\n[XX:%s XY:%s]\n[YX:%s YY:%s]' % (temp[0, 0], temp[0, 1], temp[1, 0], temp[1, 1])) out = Dij * 0 # Copy complex array # my_jinv = inv2x2(my_j) # J1^-1 my_jH = np.transpose(my_j.conj()) # J2^H # my_jHinv = inv2x2(my_jH) # (J2^H)^-1 for i in range(my_shape[2]): # Matrix muliply every 2x2 array in the 2-D sky if i % 1000 == 0: logger.debug('Processing %s of %s...' % (i, my_shape[2])) # print 'Processing %s of %s...'%(i,my_shape[2]) for j in range(my_shape[3]): # J1^-1 (Vij (J2^H)^-1) # out[:,:,i,j]=np.dot(my_jinv, np.dot(Dij[:,:,i,j], my_jHinv)) out[:, :, i, j] = np.dot(my_j, np.dot(Dij[:, :, i, j], my_jH)) else: print('FIXME for other lengths!!') return return out