def parameter_check(self): # outfile check sdutil.assert_outfile_canoverwrite_or_nonexistent(self.outfile, 'im', self.overwrite) sdutil.assert_outfile_canoverwrite_or_nonexistent(self.outfile+'.weight', 'im', self.overwrite) # fix spw if type(self.spw) == str: self.spw = self.__format_spw_string(self.spw) # check unit of start and width # fix default if self.mode == 'channel': if self.start == '': self.start = 0 if self.width == '': self.width = 1 else: if self.start == 0: self.start = '' if self.width == 1: self.width = '' # fix unit if self.mode == 'frequency': myunit = 'Hz' elif self.mode == 'velocity': myunit = 'km/s' else: # channel myunit = '' for name in ['start', 'width']: param = getattr(self, name) new_param = self.__format_quantum_unit(param, myunit) if new_param == None: raise ValueError, "Invalid unit for %s in mode %s: %s" % \ (name, self.mode, param) setattr(self, name, new_param) casalog.post("mode='%s': start=%s, width=%s, nchan=%d" % \ (self.mode, self.start, self.width, self.nchan)) # check length of selection parameters if is_string_type(self.infiles): nfile = 1 self.infiles = [ self.infiles ] else: nfile = len(self.infiles) for name in ['field', 'spw', 'antenna', 'scanno']: param = getattr(self, name) if not self.__check_selection_length(param, nfile): raise ValueError, "Length of %s != infiles." % (name) # set convsupport default if self.convsupport >= 0 and self.gridfunction.upper() != 'SF': casalog.post("user defined convsupport is ignored for %s kernel" % self.gridfunction, priority='WARN') self.convsupport=-1
def parameter_check(self): # outfile check sdutil.assert_outfile_canoverwrite_or_nonexistent( self.outfile, 'im', self.overwrite) sdutil.assert_outfile_canoverwrite_or_nonexistent( self.outfile + '.weight', 'im', self.overwrite) # fix spw if type(self.spw) == str: self.spw = self.__format_spw_string(self.spw) # check unit of start and width # fix default if self.mode == 'channel': if self.start == '': self.start = 0 if self.width == '': self.width = 1 else: if self.start == 0: self.start = '' if self.width == 1: self.width = '' # fix unit if self.mode == 'frequency': myunit = 'Hz' elif self.mode == 'velocity': myunit = 'km/s' else: # channel myunit = '' for name in ['start', 'width']: param = getattr(self, name) new_param = self.__format_quantum_unit(param, myunit) if new_param == None: raise ValueError, "Invalid unit for %s in mode %s: %s" % \ (name, self.mode, param) setattr(self, name, new_param) casalog.post("mode='%s': start=%s, width=%s, nchan=%d" % \ (self.mode, self.start, self.width, self.nchan)) # check length of selection parameters if is_string_type(self.infiles): nfile = 1 self.infiles = [self.infiles] else: nfile = len(self.infiles) for name in ['field', 'spw', 'antenna', 'scanno']: param = getattr(self, name) if not self.__check_selection_length(param, nfile): raise ValueError, "Length of %s != infiles." % (name) # set convsupport default if self.convsupport >= 0 and self.gridfunction.upper() != 'SF': casalog.post("user defined convsupport is ignored for %s kernel" % self.gridfunction, priority='WARN') self.convsupport = -1
def parameter_check(self): # by default, the task overwrite infile if len(self.outfile) == 0: self.project = self.infile else: self.project = self.outfile sdutil.assert_outfile_canoverwrite_or_nonexistent( self.project, self.outform, self.overwrite) #check the format of the infile filename = sdutil.get_abspath(self.infile) if isinstance(self.infile, str): if is_scantable(filename): informat = 'ASAP' elif is_ms(filename): informat = 'MS2' else: informat = 'SDFITS' else: informat = 'UNDEFINED' # Check the formats of infile and outfile are identical when overwrite=True. # (CAS-3096). If not, print warning message and exit. outformat = self.outform.upper() if (outformat == 'MS'): outformat = 'MS2' if self.overwrite and os.path.exists(self.project) \ and (sdutil.get_abspath(self.project) == sdutil.get_abspath(self.infile)) \ and (outformat != informat): msg = "The input and output data format must be identical when " msg += "their names are identical and overwrite=True. " msg += "%s and %s given for input and output, respectively." % ( informat, outformat) raise Exception, msg # check restfreq self.rfset = (self.restfreq != '') and (self.restfreq != []) self.restore = self.rfset if self.mode.lower()[0] not in self.valid_modes: raise Exception, "Invalide mode, '%s'" % self.mode # check whether any flag operation is done or not self.anyflag = False
def parameter_check(self): # by default, the task overwrite infile if len(self.outfile)==0: self.project = self.infile else: self.project = self.outfile sdutil.assert_outfile_canoverwrite_or_nonexistent(self.project, self.outform, self.overwrite) #check the format of the infile filename = sdutil.get_abspath(self.infile) if isinstance(self.infile, str): if is_scantable(filename): informat = 'ASAP' elif is_ms(filename): informat = 'MS2' else: informat = 'SDFITS' else: informat = 'UNDEFINED' # Check the formats of infile and outfile are identical when overwrite=True. # (CAS-3096). If not, print warning message and exit. outformat = self.outform.upper() if (outformat == 'MS'): outformat = 'MS2' if self.overwrite and os.path.exists(self.project) \ and (sdutil.get_abspath(self.project) == sdutil.get_abspath(self.infile)) \ and (outformat != informat): msg = "The input and output data format must be identical when " msg += "their names are identical and overwrite=True. " msg += "%s and %s given for input and output, respectively." % (informat, outformat) raise Exception, msg # check restfreq self.rfset = (self.restfreq != '') and (self.restfreq != []) self.restore = self.rfset if self.mode.lower()[0] not in self.valid_modes: raise Exception, "Invalide mode, '%s'" % self.mode # check whether any flag operation is done or not self.anyflag = False
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 initialize(self): # completely override initialize # check expr if self.expr == '': raise Exception, 'expr is undefined' # check spw self.assert_no_channel_selection_in_spw('warn') # check outfile if (self.outfile.strip() == ''): raise Exception("'outfile' must be specified.") sdutil.assert_outfile_canoverwrite_or_nonexistent( self.outfile, self.outform, self.overwrite) # save current insitu parameter and overwrite it self.insitu_saved = sd.rcParams['insitu'] if self.is_disk_storage: sd.rcParams['insitu'] = False
def initialize(self): # completely override initialize # check expr if self.expr=='': raise Exception, 'expr is undefined' # check spw self.assert_no_channel_selection_in_spw('warn') # check outfile if (self.outfile.strip() == ''): raise Exception("'outfile' must be specified.") sdutil.assert_outfile_canoverwrite_or_nonexistent(self.outfile, self.outform, self.overwrite) # save current insitu parameter and overwrite it self.insitu_saved = sd.rcParams['insitu'] if self.is_disk_storage: sd.rcParams['insitu'] = False
def save(self): self.scan.set_selection(None) #sdutil.save(self.scan, self.project, self.outform, self.overwrite) sdutil.assert_outfile_canoverwrite_or_nonexistent(self.project, self.outform, self.overwrite) outform_local = self.outform.upper() if outform_local == 'MS': outform_local = 'MS2' if outform_local not in ['ASAP','ASCII','MS2','SDFITS']: outform_local = 'ASAP' # SHOULD NOT remove infile if disk storage and infile==outfile outfilename = sdutil.get_abspath(self.project) if self.overwrite and os.path.exists(outfilename): if not self.is_disk_storage or \ (outfilename != sdutil.get_abspath(self.infile)): os.system('rm -rf %s' % outfilename) self.scan.save(self.project, outform_local, self.overwrite) if outform_local!='ASCII': casalog.post('Wrote output %s file %s'%(outform_local,self.project))
def save(self): self.scan.set_selection(None) #sdutil.save(self.scan, self.project, self.outform, self.overwrite) sdutil.assert_outfile_canoverwrite_or_nonexistent( self.project, self.outform, self.overwrite) outform_local = self.outform.upper() if outform_local == 'MS': outform_local = 'MS2' if outform_local not in ['ASAP', 'ASCII', 'MS2', 'SDFITS']: outform_local = 'ASAP' # SHOULD NOT remove infile if disk storage and infile==outfile outfilename = sdutil.get_abspath(self.project) if self.overwrite and os.path.exists(outfilename): if not self.is_disk_storage or \ (outfilename != sdutil.get_abspath(self.infile)): os.system('rm -rf %s' % outfilename) self.scan.save(self.project, outform_local, self.overwrite) if outform_local != 'ASCII': casalog.post('Wrote output %s file %s' % (outform_local, self.project))