def __get_grid_parameters(self, calc=False): # CAS-5410 Use private tools inside task scripts qa = qatool() (nx,ny) = self.__get_mapsize() mapcenter = sdutil.get_map_center(self.center) (cellx,celly) = sdutil.get_cellx_celly(self.cell) if calc and \ ((mapcenter.split() != 3) or not qa.compare(cellx, "rad")): #(mapcenter,cellx,celly) = self.__calc_center_and_cell(mapcenter, cellx, celly) (mapcenter,cellx,celly) = self.__get_center_and_cell(nx, ny, mapcenter, cellx, celly) return (nx,ny,cellx,celly,mapcenter)
def __get_grid_parameters(self, calc=False): # CAS-5410 Use private tools inside task scripts qa = qatool() (nx, ny) = self.__get_mapsize() mapcenter = sdutil.get_map_center(self.center) (cellx, celly) = sdutil.get_cellx_celly(self.cell) if calc and \ ((mapcenter.split() != 3) or not qa.compare(cellx, "rad")): #(mapcenter,cellx,celly) = self.__calc_center_and_cell(mapcenter, cellx, celly) (mapcenter, cellx, celly) = self.__get_center_and_cell(nx, ny, mapcenter, cellx, celly) return (nx, ny, cellx, celly, mapcenter)
def __compile(self): # infiles if isinstance(self.infiles, str): self.infiles = [self.infiles] # scantable for temporary use tmpst = sd.scantable(self.infiles[0], False) # scanlist #self.scans = sdutil._to_list(self.scanlist, int) self.scans = tmpst.parse_idx_selection("SCAN", self.scanno) # pollist #self.pols = sdutil._to_list(self.pollist, int) self.pols = tmpst.parse_idx_selection("POL", self.polno) # spw if (self.spw.strip() == '-1'): self.ifno = tmpst.getif(0) else: masklist = tmpst.parse_spw_selection(self.spw) if len(masklist) == 0: raise ValueError, "Invalid spectral window selection. Selection contains no data." self.ifno = masklist.keys()[0] # outfile self.outname = sdutil.get_default_outfile_name(self.infiles[0], self.outfile, self.suffix) sdutil.assert_outfile_canoverwrite_or_nonexistent(self.outname, 'ASAP', self.overwrite) # nx and ny (self.nx, self.ny) = sdutil.get_nx_ny(self.npix) # cellx and celly (self.cellx, self.celly) = sdutil.get_cellx_celly(self.cell) # map center self.mapcenter = sdutil.get_map_center(self.center) del tmpst
def __compile(self): # infiles if isinstance(self.infiles, str): self.infiles = [self.infiles] # scantable for temporary use tmpst = sd.scantable(self.infiles[0], False) # scanlist #self.scans = sdutil._to_list(self.scanlist, int) self.scans = tmpst.parse_idx_selection("SCAN", self.scanno) # pollist #self.pols = sdutil._to_list(self.pollist, int) self.pols = tmpst.parse_idx_selection("POL", self.polno) # spw if (self.spw.strip() == '-1'): self.ifno = tmpst.getif(0) else: masklist = tmpst.parse_spw_selection(self.spw) if len(masklist) == 0: raise ValueError, "Invalid spectral window selection. Selection contains no data." self.ifno = masklist.keys()[0] # outfile self.outname = sdutil.get_default_outfile_name(self.infiles[0], self.outfile, self.suffix) sdutil.assert_outfile_canoverwrite_or_nonexistent( self.outname, 'ASAP', self.overwrite) # nx and ny (self.nx, self.ny) = sdutil.get_nx_ny(self.npix) # cellx and celly (self.cellx, self.celly) = sdutil.get_cellx_celly(self.cell) # map center self.mapcenter = sdutil.get_map_center(self.center) del tmpst
def __compile_for_imaging(self): # pointing data column to use #if pointingcolumn.upper()=="OFFSET": # pointingcolumn="POINTING_OFFSET" # check ephemsrcname and set a proper source name if not given if self.ephemsrcname == '': # assume single source/field # try determine if it is a known ephemeris source self.open_table(self.source_table) src = self.table.getcol('NAME') self.close_table() src = src[0] if src.upper() in self.ephemobjs: self.ephemsrcname = src # imsize (self.nx, self.ny) = sdutil.get_nx_ny(self.imsize) # cell size (self.cellx, self.celly) = sdutil.get_cellx_celly(self.cell, unit='arcmin') if self.cellx == '' or self.celly == '': msg='Unrecognized quantity for cell' raise Exception, msg if self.phasecenter =='' and len(self.ephemsrcname)>0: # if phasecenter is undefined and if it is a moving source, # the phasecneter is set to the position of the moving source # at the time of the first data in the POINTING table. if self.pointingcolumn.upper() =='POINTING_OFFSET': self.phasecenter='AZELGEO 0d0m 0d0m' else: self.open_table(self.observation_table) telname = self.table.getcol('TELESCOPE_NAME') self.close_table() self.open_table(self.pointing_table) t = self.table.getcol('TIME') self.close_table() me.doframe(me.observatory(telname[0])) me.doframe(me.epoch('utc',str(t[0])+'s')) self.phasecenter = me.measure(me.direction(self.ephemsrcname),'AZELGEO')
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 _handle_image_params(imsize, cell, phasecenter, vislist, field, spw, antenna, scan, intent, restfreq, pointingcolumntouse, ephemsrcname): # round-up imsize _imsize = sdutil._to_list(imsize, int) or sdutil._to_list( imsize, numpy.integer) if _imsize is None: _imsize = imsize if hasattr(imsize, '__iter__') else [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(imsize), str(_imsize))) # calculate cell based on PB if it is not given _cell = cell if _cell == '' or _cell[0] == '': # calc PB if isinstance(vislist, str): vis = vislist else: vis = vislist[0] if isinstance(antenna, str): antsel = antenna else: antsel = antenna[0] if antsel == '': antenna_id = 0 else: if len(antsel) > 3 and antsel[:-3] == '&&&': baseline = antsel else: baseline = antsel + '&&&' with open_ms(vis) as ms: ms.msselect({'baseline': baseline}) ndx = ms.msselectedindices() antenna_id = ndx['antenna1'][0] grid_factor = 3. casalog.post( "The cell size will be calculated using PB size of antennas in the first MS" ) qpb = _calc_PB(vis, antenna_id, restfreq) _cell = '%f%s' % (qpb['value'] / grid_factor, qpb['unit']) casalog.post("Using cell size = PB/%4.2F = %s" % (grid_factor, _cell)) # Calculate Pointing center and extent (if necessary) _phasecenter = phasecenter if _phasecenter == '' or len(_imsize) == 0 or _imsize[0] < 1: # return a dictionary with keys 'center', 'width', 'height' map_param = _get_pointing_extent(_phasecenter, vislist, field, spw, antenna, scan, intent, pointingcolumntouse, ephemsrcname) # imsize (cellx, celly) = sdutil.get_cellx_celly(_cell, unit='arcmin') if len(_imsize) == 0 or _imsize[0] < 1: _imsize = _get_imsize(map_param['width'], map_param['height'], cellx, celly) if _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 _phasecenter == "": _phasecenter = map_param['center'] return _imsize, _cell, _phasecenter
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