def sort_vis(self, vislist, spw, mode, width, field, antenna, scan, intent): if isinstance(vislist, str) or len(vislist) == 1: return vislist, field, spw, antenna, scan, intent imhelper = cleanhelper(imtool=self.imager, vis=vislist, casalog=casalog) imhelper.sortvislist(spw=spw, mode=mode, width=width) sorted_idx = list(imhelper.sortedvisindx) # reverse the order sorted_idx.reverse() sorted_vislist = [vislist[i] for i in sorted_idx] fieldsel = SelectionHandler(field) sorted_field = [fieldsel(i) for i in sorted_idx] spwsel = SelectionHandler(spw) sorted_spw = [spwsel(i) for i in sorted_idx] antennasel = SelectionHandler(antenna) sorted_antenna = [antennasel(i) for i in sorted_idx] scansel = SelectionHandler(scan) sorted_scan = [scansel(i) for i in sorted_idx] intentsel = SelectionHandler(intent) sorted_intent = [intentsel(i) for i in sorted_idx] return sorted_vislist, sorted_field, sorted_spw, sorted_antenna, sorted_scan, sorted_intent
def _configure_map_property(self): selection_ids = self.get_selection_idx_for_ms(self.sorted_idx[0]) # stokes if self.stokes == '': self.stokes = 'I' self.imager_param['stokes'] = self.stokes # gridfunction # outfile if os.path.exists(self.outfile) and self.overwrite: os.system('rm -rf %s' % (self.outfile)) if os.path.exists(self.outfile + '.weight') and self.overwrite: os.system('rm -rf %s' % (self.outfile + '.weight')) # cell cell = self.cell if cell == '' or cell[0] == '': # Calc PB grid_factor = 3. casalog.post( "The cell size will be calculated using PB size of antennas in the first MS" ) qPB = self._calc_PB(selection_ids['antenna1']) cell = '%f%s' % (qPB['value'] / grid_factor, qPB['unit']) casalog.post("Using cell size = PB/%4.2F = %s" % (grid_factor, cell)) (cellx, celly) = sdutil.get_cellx_celly(cell, unit='arcmin') self.imager_param['cellx'] = cellx self.imager_param['celly'] = celly # Calculate Pointing center and extent (if necessary) # return a dictionary with keys 'center', 'width', 'height' #imsize = self.imsize imsize = sdutil._to_list(self.imsize, int) or \ sdutil._to_list(self.imsize, numpy.integer) if imsize is None: imsize = self.imsize if hasattr(self.imsize, '__iter__') else [self.imsize] imsize = [int(numpy.ceil(v)) for v in imsize] casalog.post( "imsize is not integers. force converting to integer pixel numbers.", priority="WARN") casalog.post("rounded-up imsize: %s --> %s" % (str(self.imsize), str(imsize))) phasecenter = self.phasecenter if self.phasecenter == "" or \ len(imsize) == 0 or imsize[0] < 1: map_param = self._get_pointing_extent() # imsize if len(imsize) == 0 or imsize[0] < 1: imsize = self._get_imsize(map_param['width'], map_param['height'], cellx, celly) if self.phasecenter != "": casalog.post( "You defined phasecenter but not imsize. The image will cover as wide area as pointing in MS extends, but be centered at phasecenter. This could result in a strange image if your phasecenter is a part from the center of pointings", priority='WARN') if imsize[0] > 1024 or imsize[1] > 1024: casalog.post( "The calculated image pixel number is larger than 1024. It could take time to generate the image depending on your computer resource. Please wait...", priority='WARN') # phasecenter # if empty, it should be determined here... if self.phasecenter == "": phasecenter = map_param['center'] # imsize (nx, ny) = sdutil.get_nx_ny(imsize) self.imager_param['nx'] = nx self.imager_param['ny'] = ny # phasecenter self.imager_param['phasecenter'] = phasecenter self.imager_param['movingsource'] = self.ephemsrcname # channel map imhelper = cleanhelper(self.imager, self.infiles, casalog=casalog) imhelper.sortvislist(self.spw, self.mode, self.width) spwsel = str(',').join([str(spwid) for spwid in selection_ids['spw']]) srestf = self.imager_param['restfreq'] if is_string_type( self.imager_param['restfreq'] ) else "%fHz" % self.imager_param['restfreq'] (imnchan, imstart, imwidth) = imhelper.setChannelizeDefault( self.mode, spwsel, self.field, self.nchan, self.start, self.width, self.imager_param['outframe'], self.veltype, self.imager_param['phasecenter'], srestf) del imhelper # start and width if self.mode == 'velocity': startval = [self.imager_param['outframe'], imstart] widthval = imwidth elif self.mode == 'frequency': startval = [self.imager_param['outframe'], imstart] widthval = imwidth else: #self.mode==channel startval = int(self.start) widthval = int(self.width) if self.nchan < 0: self.nchan = self.allchannels self.imager_param['start'] = startval self.imager_param['step'] = widthval self.imager_param['nchan'] = imnchan #self.nchan
def compile(self): # imaging mode self.imager_param['mode'] = self.mode # Work on selection of the first table in sorted list # to get default restfreq and outframe imhelper = cleanhelper(self.imager, self.infiles, casalog=casalog) imhelper.sortvislist(self.spw, self.mode, self.width) self.sorted_idx = imhelper.sortedvisindx selection_ids = self.get_selection_idx_for_ms(self.sorted_idx[0]) self.__update_subtable_name(self.infiles[self.sorted_idx[0]]) # field fieldid = selection_ids['field'][0] if type( selection_ids['field']) != int else selection_ids['field'] sourceid = -1 self.open_table(self.field_table) source_ids = self.table.getcol('SOURCE_ID') self.close_table() if self.field == '' or fieldid == -1: sourceid = source_ids[0] elif fieldid >= 0 and fieldid < len(source_ids): sourceid = source_ids[fieldid] else: raise ValueError, "No valid field in the first MS." # restfreq if self.restfreq == '' and self.source_table != '': self.open_table(self.source_table) source_ids = self.table.getcol('SOURCE_ID') for i in range(self.table.nrows()): if sourceid == source_ids[i] \ and self.table.iscelldefined('REST_FREQUENCY',i) \ and (selection_ids['spw'] == -1 or \ self.table.getcell('SPECTRAL_WINDOW_ID', i) in selection_ids['spw']): rf = self.table.getcell('REST_FREQUENCY', i) if len(rf) > 0: self.restfreq = self.table.getcell( 'REST_FREQUENCY', i)[0] break self.close_table() casalog.post("restfreq set to %s" % self.restfreq, "INFO") # REST_FREQUENCY column is optional (need retry if not exists) self.imager_param['restfreq'] = self.restfreq # # spw (define representative spw id = spwid_ref) spwid_ref = selection_ids['spw'][0] if type( selection_ids['spw']) != int else selection_ids['spw'] # Invalid spw selection should have handled at msselectiontoindex(). # -1 means all spw are selected. self.open_table(self.spw_table) if spwid_ref < 0: for id in range(self.table.nrows()): if self.table.getcell('NUM_CHAN', id) > 0: spwid_ref = id break if spwid_ref < 0: self.close_table() msg = 'No valid spw id exists in the first table' raise ValueError, msg self.allchannels = self.table.getcell('NUM_CHAN', spwid_ref) freq_chan0 = self.table.getcell('CHAN_FREQ', spwid_ref)[0] freq_inc0 = self.table.getcell('CHAN_WIDTH', spwid_ref)[0] # in case rest frequency is not defined yet. if self.restfreq == '': self.restfreq = '%fHz' % self.table.getcell( 'CHAN_FREQ', spwid_ref).mean() self.imager_param['restfreq'] = self.restfreq casalog.post( "Using mean freq of spw %d as restfreq: %s" % (spwid_ref, self.restfreq), "INFO") self.close_table() self.imager_param['spw'] = -1 #spwid_ref # outframe (force using the current frame) self.imager_param['outframe'] = self.outframe if self.outframe == '': if len(self.infiles) > 1: # The default will be 'LSRK' casalog.post( "Multiple MS inputs. The default outframe is set to 'LSRK'" ) self.imager_param['outframe'] = 'LSRK' else: # get from MS my_ms = gentools(['ms'])[0] my_ms.open(self.infiles[0]) spwinfo = my_ms.getspectralwindowinfo() my_ms.close() del my_ms for key, spwval in spwinfo.items(): if spwval['SpectralWindowId'] == spwid_ref: self.imager_param['outframe'] = spwval['Frame'] casalog.post("Using frequency frame of MS, '%s'" % self.imager_param['outframe']) break if self.imager_param['outframe'] == '': raise Exception, "Internal error of getting frequency frame of spw=%d." % spwid_ref else: casalog.post("Using frequency frame defined by user, '%s'" % self.imager_param['outframe'])
def _configure_map_property(self): selection_ids = self.get_selection_idx_for_ms(self.sorted_idx[0]) # stokes if self.stokes == '': self.stokes = 'I' self.imager_param['stokes'] = self.stokes # gridfunction # outfile if os.path.exists(self.outfile) and self.overwrite: os.system('rm -rf %s'%(self.outfile)) if os.path.exists(self.outfile+'.weight') and self.overwrite: os.system('rm -rf %s'%(self.outfile+'.weight')) # cell cell = self.cell if cell == '' or cell[0] == '': # Calc PB grid_factor = 3. casalog.post("The cell size will be calculated using PB size of antennas in the first MS") qPB = self._calc_PB(selection_ids['antenna1']) cell = '%f%s' % (qPB['value']/grid_factor, qPB['unit']) casalog.post("Using cell size = PB/%4.2F = %s" % (grid_factor, cell)) (cellx,celly) = sdutil.get_cellx_celly(cell, unit='arcmin') self.imager_param['cellx'] = cellx self.imager_param['celly'] = celly # Calculate Pointing center and extent (if necessary) # return a dictionary with keys 'center', 'width', 'height' imsize = self.imsize phasecenter = self.phasecenter if self.phasecenter == "" or \ len(self.imsize) == 0 or self.imsize[0] < 1: map_param = self._get_pointing_extent() # imsize if len(imsize) == 0 or imsize[0] < 1: imsize = self._get_imsize(map_param['width'], map_param['height'], cellx, celly) if self.phasecenter != "": casalog.post("You defined phasecenter but not imsize. The image will cover as wide area as pointing in MS extends, but be centered at phasecenter. This could result in a strange image if your phasecenter is a part from the center of pointings", priority='warn') if imsize[0] > 1024 or imsize[1] > 1024: casalog.post("The calculated image pixel number is larger than 1024. It could take time to generate the image depending on your computer resource. Please wait...", priority='warn') # phasecenter # if empty, it should be determined here... if self.phasecenter == "": phasecenter = map_param['center'] # imsize (nx,ny) = sdutil.get_nx_ny(imsize) self.imager_param['nx'] = nx self.imager_param['ny'] = ny # phasecenter self.imager_param['phasecenter'] = phasecenter self.imager_param['movingsource'] = self.ephemsrcname # channel map imhelper = cleanhelper(self.imager, self.infiles, casalog=casalog) imhelper.sortvislist(self.spw, self.mode, self.width) spwsel = str(',').join([str(spwid) for spwid in selection_ids['spw']]) srestf = self.imager_param['restfreq'] if is_string_type(self.imager_param['restfreq']) else "%fHz" % self.imager_param['restfreq'] (imnchan, imstart, imwidth) = imhelper.setChannelizeDefault(self.mode, spwsel, self.field, self.nchan, self.start, self.width, self.imager_param['outframe'], self.veltype,self.imager_param['phasecenter'], srestf) del imhelper # start and width if self.mode == 'velocity': startval = [self.imager_param['outframe'], imstart] widthval = imwidth elif self.mode == 'frequency': startval = [self.imager_param['outframe'], imstart] widthval = imwidth else: #self.mode==channel startval = int(self.start) widthval = int(self.width) if self.nchan < 0: self.nchan = self.allchannels self.imager_param['start'] = startval self.imager_param['step'] = widthval self.imager_param['nchan'] = imnchan #self.nchan
def compile(self): # imaging mode self.imager_param['mode'] = self.mode # Work on selection of the first table in sorted list # to get default restfreq and outframe imhelper = cleanhelper(self.imager, self.infiles, casalog=casalog) imhelper.sortvislist(self.spw, self.mode, self.width) self.sorted_idx = imhelper.sortedvisindx selection_ids = self.get_selection_idx_for_ms(self.sorted_idx[0]) self.__update_subtable_name(self.infiles[self.sorted_idx[0]]) # field fieldid = selection_ids['field'][0] if type(selection_ids['field']) != int else selection_ids['field'] sourceid=-1 self.open_table(self.field_table) source_ids = self.table.getcol('SOURCE_ID') self.close_table() if self.field == '' or fieldid ==-1: sourceid = source_ids[0] elif fieldid >= 0 and fieldid < len(source_ids): sourceid = source_ids[fieldid] else: raise ValueError, "No valid field in the first MS." # restfreq if self.restfreq=='' and self.source_table != '': self.open_table(self.source_table) source_ids = self.table.getcol('SOURCE_ID') for i in range(self.table.nrows()): if sourceid == source_ids[i] \ and self.table.iscelldefined('REST_FREQUENCY',i) \ and (selection_ids['spw'] == -1 or \ self.table.getcell('SPECTRAL_WINDOW_ID', i) in selection_ids['spw']): rf = self.table.getcell('REST_FREQUENCY',i) if len(rf) > 0: self.restfreq=self.table.getcell('REST_FREQUENCY',i)[0] break self.close_table() casalog.post("restfreq set to %s" % self.restfreq, "INFO") # REST_FREQUENCY column is optional (need retry if not exists) self.imager_param['restfreq'] = self.restfreq # # spw (define representative spw id = spwid_ref) spwid_ref = selection_ids['spw'][0] if type(selection_ids['spw']) != int else selection_ids['spw'] # Invalid spw selection should have handled at msselectiontoindex(). # -1 means all spw are selected. self.open_table(self.spw_table) if spwid_ref < 0: for id in range(self.table.nrows()): if self.table.getcell('NUM_CHAN',id) > 0: spwid_ref = id break if spwid_ref < 0: self.close_table() msg='No valid spw id exists in the first table' raise ValueError, msg self.allchannels = self.table.getcell('NUM_CHAN',spwid_ref) freq_chan0 = self.table.getcell('CHAN_FREQ',spwid_ref)[0] freq_inc0 = self.table.getcell('CHAN_WIDTH',spwid_ref)[0] # in case rest frequency is not defined yet. if self.restfreq=='': self.restfreq = '%fHz' % self.table.getcell('CHAN_FREQ',spwid_ref).mean() self.imager_param['restfreq'] = self.restfreq casalog.post("Using mean freq of spw %d as restfreq: %s" % (spwid_ref, self.restfreq), "INFO") self.close_table() self.imager_param['spw'] = -1 #spwid_ref # outframe (force using the current frame) self.imager_param['outframe'] = self.outframe if self.outframe == '': if len(self.infiles) > 1: # The default will be 'LSRK' casalog.post("Multiple MS inputs. The default outframe is set to 'LSRK'") self.imager_param['outframe'] = 'LSRK' else: # get from MS my_ms = gentools(['ms'])[0] my_ms.open(self.infiles[0]) spwinfo = my_ms.getspectralwindowinfo() my_ms.close() del my_ms for key, spwval in spwinfo.items(): if spwval['SpectralWindowId'] == spwid_ref: self.imager_param['outframe'] = spwval['Frame'] casalog.post("Using frequency frame of MS, '%s'" % self.imager_param['outframe']) break if self.imager_param['outframe'] == '': raise Exception, "Internal error of getting frequency frame of spw=%d." % spwid_ref else: casalog.post("Using frequency frame defined by user, '%s'" % self.imager_param['outframe'])