def test_rec_frame(self): rec_frame = ReceptorFrame("linear") assert rec_frame.nrec == 2 rec_frame = ReceptorFrame("circular") assert rec_frame.nrec == 2 rec_frame = ReceptorFrame("stokesI") assert rec_frame.nrec == 1 with self.assertRaises(ValueError): rec_frame = ReceptorFrame("circuloid")
def __init__(self, name='', data=None, location=None, names="%s", xyz=None, mount="alt-az", frame=None, receptor_frame=ReceptorFrame("linear"), diameter=None): # Defaults if data is None and xyz is not None: desc = [('names', '>U6'), ('xyz', '>f8', (3,)), ('diameter', '>f8'), ('mount', '>U5')] nants = xyz.shape[0] if isinstance(names, str): names = [names % ant for ant in range(nants)] if isinstance(mount, str): mount = numpy.repeat(mount, nants) data = numpy.zeros(shape=[nants], dtype=desc) data['names'] = names data['xyz'] = xyz data['mount'] = mount data['diameter'] = diameter self.name = name self.data = data self.location = location self.frame = frame self.receptor_frame = receptor_frame
def __init__(self, data=None, gain: numpy.array = None, time: numpy.array = None, weight: numpy.array = None, residual: numpy.array = None, frequency: numpy.array = None, receptor_frame: ReceptorFrame = ReceptorFrame("linear")): """ Create a gaintable from arrays The definition of gain is: Vobs = g_i g_j^* Vmodel :param gain: [npol, nchan] :param time: :param weight: :param frequency: :returns: Gaintable """ if data is None and gain is not None: nrec = receptor_frame.nrec nrows = gain.shape[0] nants = gain.shape[1] nchan = gain.shape[2] assert len(frequency) == nchan, "Discrepancy in frequency channels" desc = [('gain', '>c16', (nants, nchan, nrec, nrec)), ('weight', '>f8', (nants, nchan, nrec, nrec)), ('residual', '>f8', (nchan, nrec, nrec)), ('time', '>f8')] self.data = numpy.zeros(shape=[nrows], dtype=desc) self.data['gain'] = gain self.data['weight'] = weight self.data['time'] = time self.data['residual'] = residual self.frequency = frequency self.receptor_frame = receptor_frame
def __init__(self, name='', data=None, location=None, names="%s", xyz=None, mount="alt-az", frame=None, receptor_frame=ReceptorFrame("linear"), diameter=None): """Configuration object describing data for processing :param name: :param data: :param location: :param names: :param xyz: :param mount: :param frame: :param receptor_frame: :param diameter: """ if data is None and xyz is not None: desc = [('names', '>U6'), ('xyz', '>f8', (3, )), ('diameter', '>f8'), ('mount', '>U5')] nants = xyz.shape[0] if isinstance(names, str): names = [names % ant for ant in range(nants)] if isinstance(mount, str): mount = numpy.repeat(mount, nants) data = numpy.zeros(shape=[nants], dtype=desc) data['names'] = names data['xyz'] = xyz data['mount'] = mount data['diameter'] = diameter self.name = name self.data = data self.location = location self.frame = frame self.receptor_frame = receptor_frame
def create_visibility_from_ms(msname, channum=0): """ Minimal MS to Visibility converter The MS format is much more general than the ARL Visibility so we cut many corners. This requires casacore to be installed. If not an exception ModuleNotFoundError is raised. Creates a list of Visibilities, one per phasecentre """ try: from casacore.tables import table # pylint: disable=import-error except ModuleNotFoundError: raise ModuleNotFoundError("casacore is not installed") tab = table(msname) print(tab.info()) fields = numpy.unique(tab.getcol('FIELD_ID')) print("Found unique field ids %s" % fields) vis_list = list() for field in fields: # First get the main table information ms = tab.query("FIELD_ID==%d" % field) print("Found %d rows for field %d" % (ms.nrows(), field)) time = ms.getcol('TIME') channels = len(numpy.transpose(ms.getcol('DATA'))[0]) print("Found %d channels" % (channels)) try: vis = ms.getcol('DATA')[:, channum, :] except IndexError: raise IndexError("channel number exceeds max. within ms") weight = ms.getcol('WEIGHT') uvw = -1 * ms.getcol('UVW') antenna1 = ms.getcol('ANTENNA1') antenna2 = ms.getcol('ANTENNA2') integration_time = ms.getcol('INTERVAL') ddid = ms.getcol('DATA_DESC_ID') # Now get info from the subtables spwtab = table('%s/SPECTRAL_WINDOW' % msname, ack=False) cfrequency = spwtab.getcol('CHAN_FREQ') frequency = numpy.array([cfrequency[dd] for dd in ddid])[:, channum] cchannel_bandwidth = spwtab.getcol('CHAN_WIDTH') channel_bandwidth = numpy.array( [cchannel_bandwidth[dd] for dd in ddid])[:, 0] uvw *= frequency[:, numpy.newaxis] / constants.c.to('m/s').value # Get polarisation info # poltab = table('%s/POLARIZATION' % msname, ack=False) # corr_type = poltab.getcol('CORR_TYPE') # TODO: Do interpretation correctly polarisation_frame = PolarisationFrame('stokesIQUV') # Get configuration anttab = table('%s/ANTENNA' % msname, ack=False) mount = anttab.getcol('MOUNT') names = anttab.getcol('NAME') diameter = anttab.getcol('DISH_DIAMETER') xyz = anttab.getcol('POSITION') configuration = Configuration(name='', data=None, location=None, names=names, xyz=xyz, mount=mount, frame=None, receptor_frame=ReceptorFrame("linear"), diameter=diameter) # Get phasecentres fieldtab = table('%s/FIELD' % msname, ack=False) pc = fieldtab.getcol('PHASE_DIR')[field, 0, :] phasecentre = SkyCoord(ra=[pc[0]] * u.rad, dec=pc[1] * u.rad, frame='icrs', equinox='J2000') vis_list.append( Visibility(uvw=uvw, time=time, antenna1=antenna1, antenna2=antenna2, frequency=frequency, vis=vis, weight=weight, imaging_weight=weight, integration_time=integration_time, channel_bandwidth=channel_bandwidth, configuration=configuration, phasecentre=phasecentre, polarisation_frame=polarisation_frame)) return vis_list
def test_congruent(self): for frame in ["linear", "circular", "stokesI"]: assert congruent_polarisation(ReceptorFrame(frame), PolarisationFrame(frame)) assert not congruent_polarisation(ReceptorFrame(frame), PolarisationFrame("stokesIQUV"))
def test_correlate(self): for frame in ["linear", "circular", "stokesI"]: rec_frame = ReceptorFrame(frame) assert correlate_polarisation(rec_frame) == PolarisationFrame(frame)