def readMS(fn, sbs, column='DATA'): """Return the visibilites and UVW coordinates from a SE607 LOFAR XST format file fn: XST filename column: string, data column sbs: 1-D array of subband IDs returns: vis: visibilities [4, Nsamples, Nsubbands] uvw: UVW coordinates [Nsamples, 3, Nsubbands] freqs: frequencies [Nsubbands] obsdata: [latitude, longitude, LST] """ try: import casacore.tables as tbls except ImportError: print 'ERROR: could not import casacore.tables, cannot read measurement sets' exit(1) MS = tbls.table(fn, readonly=True) data_column = column.upper() uvw = MS.col('UVW').getcol() # [vis id, (u,v,w)] vis = MS.col(data_column).getcol() #[vis id, freq id, stokes id] vis = vis[:,sbs,:] #select subbands MS.close() # lat/long/lst information ANTS = tbls.table(fn + '/ANTENNA') positions = ANTS.col('POSITION').getcol() ant0Lat, ant0Long, ant0hgt = ecef.ecef2geodetic(positions[0,0], positions[0,1], positions[0,2], degrees=False) # use the first antenna in the table to get the array lat/long ANTS.close() SRC = tbls.table(fn + '/SOURCE') direction = SRC.col('DIRECTION').getcol() obsLat = direction[0,1] obsLong = ant0Long LSTangle = direction[0,0] SRC.close() # freq information, convert uvw coordinates SW = tbls.table(fn + '/SPECTRAL_WINDOW') freqs = SW.col('CHAN_FREQ').getcol()[0, sbs] # [nchan] print 'SUBBANDS:', sbs, '(', freqs/1e6, 'MHz)' SW.close() # TODO: check rotation reference is the same as with LOFAR data, north pole is dec=+90, ra=0 # in order to accommodate multiple observations at different times/sidereal times all the positions need to be rotated relative to sidereal time 0 print 'LST:', LSTangle rotAngle = float(LSTangle) - obsLong # adjust LST to that of the Observatory longitutude to make the LST that at Greenwich # to be honest, the next two lines change the LST to make the images come out but i haven't worked out the coordinate transforms, so for now these work without justification rotAngle += np.pi rotAngle *= -1 # Rotation matrix for antenna positions rotMatrix = np.array([[np.cos(rotAngle), -1.*np.sin(rotAngle), 0.], [np.sin(rotAngle), np.cos(rotAngle), 0.], [0., 0., 1.]]) #rotate about the z-axis uvwRot = np.dot(uvw, rotMatrix).reshape(uvw.shape[0], uvw.shape[1], 1) uvwRotRepeat = np.repeat(uvwRot, len(sbs), axis=2) return np.transpose(vis, (2,0,1)), uvwRotRepeat, freqs, [obsLat, obsLong, LSTangle]
def readMS(fn, sbs, column='DATA'): """Return the visibilites and UVW coordinates from a Measurement Set fn: MS filename column: string, data column sbs: 1-D array of subband IDs returns: vis: visibilities [4, Nsamples, Nsubbands] uvw: UVW coordinates [Nsamples, 3, Nsubbands] freqs: frequencies [Nsubbands] obsdata: [latitude, longitude, LST] """ try: import casacore.tables as tbls except ImportError: print 'ERROR: could not import casacore.tables, cannot read measurement sets' exit(1) MS = tbls.table(fn, readonly=True) data_column = column.upper() uvw = MS.col('UVW').getcol() # [vis id, (u,v,w)] vis = MS.col(data_column).getcol() #[vis id, freq id, stokes id] vis = vis[:,sbs,:] #select subbands MS.close() # lat/long/lst information ANTS = tbls.table(fn + '/ANTENNA') positions = ANTS.col('POSITION').getcol() ant0Lat, ant0Long, ant0hgt = ecef.ecef2geodetic(positions[0,0], positions[0,1], positions[0,2], degrees=False) # use the first antenna in the table to get the array lat/long ANTS.close() SRC = tbls.table(fn + '/SOURCE') direction = SRC.col('DIRECTION').getcol() obsLat = direction[0,1] obsLong = ant0Long LSTangle = direction[0,0] SRC.close() # freq information, convert uvw coordinates SW = tbls.table(fn + '/SPECTRAL_WINDOW') freqs = SW.col('CHAN_FREQ').getcol()[0, sbs] # [nchan] print 'SUBBANDS:', sbs, '(', freqs/1e6, 'MHz)' SW.close() # TODO: check rotation reference is the same as with LOFAR data, north pole is dec=+90, ra=0 # in order to accommodate multiple observations at different times/sidereal times all the positions need to be rotated relative to sidereal time 0 print 'LST:', LSTangle rotAngle = float(LSTangle) - obsLong # adjust LST to that of the Observatory longitutude to make the LST that at Greenwich # to be honest, the next two lines change the LST to make the images come out but i haven't worked out the coordinate transforms, so for now these work without justification rotAngle += np.pi rotAngle *= -1 # Rotation matrix for antenna positions rotMatrix = np.array([[np.cos(rotAngle), -1.*np.sin(rotAngle), 0.], [np.sin(rotAngle), np.cos(rotAngle), 0.], [0., 0., 1.]]) #rotate about the z-axis uvwRot = np.dot(uvw, rotMatrix).reshape(uvw.shape[0], uvw.shape[1], 1) uvwRotRepeat = np.repeat(uvwRot, len(sbs), axis=2) return np.transpose(vis, (2,0,1)), uvwRotRepeat, freqs, [obsLat, obsLong, LSTangle]
def lofarArrayLatLong(lofarStation, arrayType='LBA'): """Return the Latitude, Longitude, Elevation of a LOFAR station lofarStation: instance, see lofarConfig.py arrayType: string, LOFAR array type returns: latitude (degs), longitude (degs), elevation (m) """ #lon, lat, elev = lofarStation.antArrays.location[lofarConfig.rcuInfo[fDict['rcu']]['array_type']] arr_xyz = lofarStation.antField.location[arrayType] lat, lon, elev = ecef.ecef2geodetic(arr_xyz[0], arr_xyz[1], arr_xyz[2], degrees=True) print 'LON(deg):', lon, 'LAT(deg):', lat, 'ELEV(m):', elev return lat, lon, elev