def do_check(na, nbl, nbl_auto): # get nr baselines from nr of antenna self.assertTrue(mbu.nr_of_baselines(na) == nbl) self.assertTrue(mbu.nr_of_baselines(na, False) == nbl) self.assertTrue(mbu.nr_of_baselines(na, True) == nbl_auto) # get nr antenna from nr of baselines self.assertTrue(mbu.nr_of_antenna(nbl) == na) self.assertTrue(mbu.nr_of_antenna(nbl, False) == na) self.assertTrue(mbu.nr_of_antenna(nbl_auto, True) == na)
def register_default_dimensions(self): """ Register the default dimensions for a RIME solver """ # Pull out the configuration options for the basics autocor = self._slvr_cfg.get(Options.AUTO_CORRELATIONS, False) ntime = self._slvr_cfg.get(Options.NTIME) na = self._slvr_cfg.get(Options.NA) nbands = self._slvr_cfg.get(Options.NBANDS) nchan = self._slvr_cfg.get(Options.NCHAN) npol = self._slvr_cfg.get(Options.NPOL) # Register these dimensions on this solver. self.register_dimension('ntime', ntime, description=Options.NTIME_DESCRIPTION) self.register_dimension('na', na, description=Options.NA_DESCRIPTION) self.register_dimension('nbands', nbands, description=Options.NBANDS_DESCRIPTION) self.register_dimension('nchan', nchan, description=Options.NCHAN_DESCRIPTION) self.register_dimension(Options.NPOL, npol, description=Options.NPOL_DESCRIPTION) # Now get the size of the registered dimensions ntime, na, nchan, npol = self.dim_local_size('ntime', 'na', 'nchan', 'npol') # Infer number of baselines from number of antenna, # use this as the default value if not specific # baseline numbers were provided nbl = mbu.nr_of_baselines(na, autocor) nbl = self._slvr_cfg.get(Options.NBL, nbl) # Register the baseline dimension self.register_dimension('nbl', nbl, description=Options.NBL_DESCRIPTION) nbl = self.dim_local_size('nbl') # Register dependent dimensions self.register_dimension('npolchan', nchan * npol, description='Polarised channels') self.register_dimension('nvis', ntime * nbl * nchan, description='Visibilities') # Convert the source types, and their numbers # to their number variables and numbers # { 'point':10 } => { 'npsrc':10 } src_cfg = self._slvr_cfg[Options.SOURCES] src_nr_vars = mbu.sources_to_nr_vars(src_cfg) # Sum to get the total number of sources self.register_dimension('nsrc', sum(src_nr_vars.itervalues()), description=Options.NSRC_DESCRIPTION) # Register the individual source types for src_type, (nr_var, nr_of_src) in zip(src_cfg.iterkeys(), src_nr_vars.iteritems()): self.register_dimension( nr_var, nr_of_src, description='{t} sources'.format(t=src_type), zero_valid=True)
def __init__(self, msfile, auto_correlations=False): super(MeasurementSetLoader, self).__init__() self.tables = {} self.msfile = msfile self.antfile = '::'.join((self.msfile, ANTENNA_TABLE)) self.freqfile = '::'.join((self.msfile, SPECTRAL_WINDOW)) self.fieldfile = '::'.join((self.msfile, FIELD_TABLE)) montblanc.log.info("{lp} Opening Measurement Set {ms}.".format( lp=self.LOG_PREFIX, ms=self.msfile)) # Open the main table ms = pt.table(self.msfile, ack=False) # Hard-code the field ID for now field_id = 0 # Create a view over the MS, ordered by # (1) time (TIME) # (2) baseline (ANTENNA1, ANTENNA2) # (3) band (SPECTRAL_WINDOW_ID via DATA_DESC_ID) ordering_query = ' '.join([ "SELECT FROM $ms", "WHERE FIELD_ID={fid}".format(fid=field_id), "" if auto_correlations else "AND ANTENNA1 != ANTENNA2", "ORDERBY TIME, ANTENNA1, ANTENNA2, " "[SELECT SPECTRAL_WINDOW_ID FROM ::DATA_DESCRIPTION][DATA_DESC_ID]" ]) ordered_ms = pt.taql(ordering_query) # Open main and sub-tables self.tables['main'] = ordered_ms self.tables['ant'] = at = pt.table(self.antfile, ack=False, readonly=True) self.tables['freq'] = ft = pt.table(self.freqfile, ack=False, readonly=True) self.tables['field'] = fit = pt.table(self.fieldfile, ack=False, readonly=True) self.nrows = ordered_ms.nrows() self.na = at.nrows() # Count distinct timesteps in the MS t_query = "SELECT FROM $ordered_ms ORDERBY UNIQUE TIME" self.ntime = pt.taql(t_query).nrows() # Count number of baselines in the MS bl_query = "SELECT FROM $ordered_ms ORDERBY UNIQUE ANTENNA1, ANTENNA2" self.nbl = pt.taql(bl_query).nrows() # Number of channels per band chan_per_band = ft.getcol('NUM_CHAN') # Require the same number of channels per band if not all(chan_per_band[0] == cpb for cpb in chan_per_band): raise ValueError('Channels per band {cpb} are not equal!'.format( cpb=chan_per_band)) # Number of channels equal to sum of channels per band self.nbands = len(chan_per_band) self.nchan = sum(chan_per_band) # Do some logging expected_nbl = mbu.nr_of_baselines(self.na, auto_correlations) autocor_str = ('with auto-correlations' if auto_correlations else 'without auto-correlations') autocor_eq = '({na}x{na1})/2'.format( na=self.na, na1=(self.na + 1 if auto_correlations else self.na - 1)) self.log("Found {na} antenna(s) in the ANTENNA sub-table.".format( na=self.na)) self.log( "Found {nbl} of {ebl}={aeq} possible baseline(s) ({astr}).".format( aeq=autocor_eq, ebl=expected_nbl, astr=autocor_str, nbl=self.nbl)) self.log("Found {nb} band(s), containing {cpb} channels.".format( nb=self.nbands, nc=chan_per_band[0], cpb=chan_per_band)) # Sanity check computed rows vs actual rows computed_rows = self.ntime * self.nbl * self.nbands if not computed_rows == self.nrows: montblanc.log.warn( "{nt} x {nbl} x {nb} = {cr} does not equal " "the number of measurement set rows '{msr}'.".format( nt=self.ntime, nbl=self.nbl, nb=self.nbands, cr=computed_rows, msr=self.nrows))
def register_default_dimensions(self): """ Register the default dimensions for a RIME solver """ # Pull out the configuration options for the basics autocor = self._slvr_cfg.get(Options.AUTO_CORRELATIONS, False) ntime = self._slvr_cfg.get(Options.NTIME) na = self._slvr_cfg.get(Options.NA) nbands = self._slvr_cfg.get(Options.NBANDS) nchan = self._slvr_cfg.get(Options.NCHAN) npol = self._slvr_cfg.get(Options.NPOL) # Register these dimensions on this solver. self.register_dimension('ntime', ntime, description=Options.NTIME_DESCRIPTION) self.register_dimension('na', na, description=Options.NA_DESCRIPTION) self.register_dimension('nbands', nbands, description=Options.NBANDS_DESCRIPTION) self.register_dimension('nchan', nchan, description=Options.NCHAN_DESCRIPTION) self.register_dimension(Options.NPOL, npol, description=Options.NPOL_DESCRIPTION) # Now get the size of the registered dimensions ntime, na, nchan, npol = self.dim_local_size( 'ntime', 'na', 'nchan', 'npol') # Infer number of baselines from number of antenna, # use this as the default value if not specific # baseline numbers were provided nbl = mbu.nr_of_baselines(na, autocor) nbl = self._slvr_cfg.get(Options.NBL, nbl) # Register the baseline dimension self.register_dimension('nbl', nbl, description=Options.NBL_DESCRIPTION) nbl = self.dim_local_size('nbl') # Register dependent dimensions self.register_dimension('npolchan', nchan*npol, description='Polarised channels') self.register_dimension('nvis', ntime*nbl*nchan, description='Visibilities') # Convert the source types, and their numbers # to their number variables and numbers # { 'point':10 } => { 'npsrc':10 } src_cfg = self._slvr_cfg[Options.SOURCES] src_nr_vars = mbu.sources_to_nr_vars(src_cfg) # Sum to get the total number of sources self.register_dimension('nsrc', sum(src_nr_vars.itervalues()), description=Options.NSRC_DESCRIPTION) # Register the individual source types for src_type, (nr_var, nr_of_src) in zip( src_cfg.iterkeys(), src_nr_vars.iteritems()): self.register_dimension(nr_var, nr_of_src, description='{t} sources'.format(t=src_type), zero_valid=True)
def __init__(self, msfile, auto_correlations=False): super(MeasurementSetLoader, self).__init__() self.tables = {} self.msfile = msfile self.antfile = '::'.join((self.msfile, ANTENNA_TABLE)) self.freqfile = '::'.join((self.msfile, SPECTRAL_WINDOW)) self.fieldfile = '::'.join((self.msfile, FIELD_TABLE)) montblanc.log.info("{lp} Opening Measurement Set {ms}.".format( lp=self.LOG_PREFIX, ms=self.msfile)) # Open the main table ms = pt.table(self.msfile, ack=False) # Hard-code the field ID for now field_id = 0 # Create a view over the MS, ordered by # (1) time (TIME) # (2) baseline (ANTENNA1, ANTENNA2) # (3) band (SPECTRAL_WINDOW_ID via DATA_DESC_ID) ordering_query = ' '.join(["SELECT FROM $ms", "WHERE FIELD_ID={fid}".format(fid=field_id), "" if auto_correlations else "AND ANTENNA1 != ANTENNA2", "ORDERBY TIME, ANTENNA1, ANTENNA2, " "[SELECT SPECTRAL_WINDOW_ID FROM ::DATA_DESCRIPTION][DATA_DESC_ID]"]) ordered_ms = pt.taql(ordering_query) # Open main and sub-tables self.tables['main'] = ordered_ms self.tables['ant'] = at = pt.table(self.antfile, ack=False, readonly=True) self.tables['freq'] = ft = pt.table(self.freqfile, ack=False, readonly=True) self.tables['field'] = fit = pt.table(self.fieldfile, ack=False, readonly=True) self.nrows = ordered_ms.nrows() self.na = at.nrows() # Count distinct timesteps in the MS t_query = "SELECT FROM $ordered_ms ORDERBY UNIQUE TIME" self.ntime = pt.taql(t_query).nrows() # Count number of baselines in the MS bl_query = "SELECT FROM $ordered_ms ORDERBY UNIQUE ANTENNA1, ANTENNA2" self.nbl = pt.taql(bl_query).nrows() # Number of channels per band chan_per_band = ft.getcol('NUM_CHAN') # Require the same number of channels per band if not all(chan_per_band[0] == cpb for cpb in chan_per_band): raise ValueError('Channels per band {cpb} are not equal!' .format(cpb=chan_per_band)) # Number of channels equal to sum of channels per band self.nbands = len(chan_per_band) self.nchan = sum(chan_per_band) # Do some logging expected_nbl = mbu.nr_of_baselines(self.na, auto_correlations) autocor_str = ('with auto-correlations' if auto_correlations else 'without auto-correlations') autocor_eq = '({na}x{na1})/2'.format(na=self.na, na1=( self.na+1 if auto_correlations else self.na-1)) self.log("Found {na} antenna(s) in the ANTENNA sub-table.".format( na=self.na)) self.log("Found {nbl} of {ebl}={aeq} possible baseline(s) ({astr}).".format( aeq=autocor_eq, ebl=expected_nbl, astr=autocor_str, nbl=self.nbl)) self.log("Found {nb} band(s), containing {cpb} channels.".format( nb=self.nbands, nc=chan_per_band[0], cpb=chan_per_band)) # Sanity check computed rows vs actual rows computed_rows = self.ntime*self.nbl*self.nbands if not computed_rows == self.nrows: montblanc.log.warn("{nt} x {nbl} x {nb} = {cr} does not equal " "the number of measurement set rows '{msr}'." .format(nt=self.ntime, nbl=self.nbl, nb=self.nbands, cr=computed_rows, msr=self.nrows))