def as_msindex(self): """ Return a dictionary of selected indices. """ with casa.OpenMS(self.vis) as ms: status = ms.msselect(self.as_msselection(), onlyparse=True) idx = ms.msselectedindices() return idx
def readvis(self, items=visconverter.VisibilityConverter.required_columns, columns=[], interval=0.0, nrow=0, adddefault=True): """ read visibility data accoding to the data selection provided to constructor. columns -- iteration axis interval -- time interval to group together nrow -- number of row for returned data chunk adddefault -- add default sort columns to iteration axis """ vis = self.visparam.vis msselect = self.visparam.as_msselection() datacolumn = self.visparam.datacolumn.lower() items = items.copy() index = items.index('data') if datacolumn == 'corrected': items[index] = 'corrected_data' elif datacolumn == 'residual': items[index] = 'residual_data' with casa.OpenMS(vis) as ms: ms.msselect(msselect, onlyparse=False) # method names depend on CASA version ms_iterinit = getattr(ms, self.iterinit) ms_iterorigin = getattr(ms, self.iterorigin) ms_getdata = getattr(ms, self.getdata) ms_iternext = getattr(ms, self.iternext) # not using new iterator as it doesn't support # reading meta information such as UVW... # iterate through MS using VI/VB2 framework ms_iterinit(columns, interval, nrow, adddefault) more_chunks = ms_iterorigin() chunk_id = 0 while (more_chunks): rec = ms_getdata(items) rec['chunk_id'] = chunk_id yield rec more_chunks = ms_iternext() chunk_id += 1 if chunk_id % 100 == 0: print('\rread {0} visibility chunks'.format(chunk_id), end='', file=sys.stderr) print('\rread {0} visibility chunks'.format(chunk_id), file=sys.stderr) print('DONE reading visibility chunks')
def suggest_imaging_param(visparam): vis = visparam.vis msselect = visparam.as_msselection() with casa.OpenMS(vis) as ms: ms.msselect(msselect, onlyparse=False) data = ms.getdata(['uvw', 'data_desc_id', 'antenna1', 'antenna2']) uvw = data['uvw'] ddid = data['data_desc_id'] antenna1 = data['antenna1'] antenna2 = data['antenna2'] observing_frequency = ImageConfigurationHelper.get_observing_frequency( vis) antenna_diameter = ImageConfigurationHelper.get_antenna_diameter(vis) # maximum antenna primary beam size [arcsec] min_freq = min(observing_frequency.values()) * 1e-9 # Hz -> GHz min_diameter = min(antenna_diameter) primary_beam = ImageConfigurationHelper.calc_primary_beam( min_diameter, min_freq) qa = casa.CreateCasaQuantity() c = qa.convert(qa.constants('c'), 'm/s')['value'] nrow = len(ddid) umax = 0.0 vmax = 0.0 for irow in range(nrow): f = observing_frequency[ddid[irow]] u = uvw[0, irow] / c * f v = uvw[1, irow] / c * f umax = max(umax, u) vmax = max(vmax, v) rad2arcsec = 180.0 / numpy.pi * 3600.0 dl = 1.0 / (2 * umax) * rad2arcsec # rad -> arcsec dm = 1.0 / (2 * vmax) * rad2arcsec # rad -> arcsec M = int(numpy.ceil(primary_beam / dl)) + 12 N = int(numpy.ceil(primary_beam / dm)) + 12 suggested = { 'cell': ['{}arcsec'.format(dl), '{}arcsec'.format(dm)], 'imsize': [M, N] } return suggested