Пример #1
0
 def __dochannelrange(self, scantab):
     if len(self.spw) > 0:
         sel_org = scantab.get_selection()
         channelrange_dic = scantab.parse_spw_selection(self.spw)
         valid_spw_list = []
         for (k,v) in channelrange_dic.items():
             casalog.post('k=%s, v=%s'%(k,v), priority='DEBUG')
             unique_list = []
             for item in map(list, v):
                 if not item in unique_list:
                     unique_list.append(item)
             casalog.post('unique_list=%s'%(unique_list), priority='DEBUG')
             if len(unique_list) > 1:
                 raise SyntaxError('sdsaveold doesn\'t support multiple channel range selection for spw.')
             elif len(unique_list) == 0:
                 raise SyntaxError('Invalid channel range specification')
             elif numpy.any(numpy.array(map(len, unique_list)) == 0):
                 # empty channel range
                 continue
             nchan = scantab.nchan(k)
             full_range = [0.0, float(nchan-1)]
             if unique_list[0] != full_range:
                 sel = sd.selector()
                 sel.set_ifs(k)
                 scantab.set_selection(sel)
                 sdutil.dochannelrange(scantab, unique_list[0])
                 scantab.set_selection()
             valid_spw_list.append(k)
         sel = sd.selector(sel_org)
         ifs_org = sel.get_ifs()
         ifs_new = list(set(ifs_org) & set(valid_spw_list))
         casalog.post('ifs_new = %s'%(ifs_new))
         sel.set_ifs(ifs_new)
         scantab.set_selection(sel)
Пример #2
0
 def __dochannelrange(self, scantab):
     if len(self.spw) > 0:
         sel_org = scantab.get_selection()
         channelrange_dic = scantab.parse_spw_selection(self.spw)
         valid_spw_list = []
         for (k,v) in channelrange_dic.items():
             casalog.post('k=%s, v=%s'%(k,v), priority='DEBUG')
             unique_list = []
             for item in map(list, v):
                 if not item in unique_list:
                     unique_list.append(item)
             casalog.post('unique_list=%s'%(unique_list), priority='DEBUG')
             if len(unique_list) > 1:
                 raise SyntaxError('sdsave doesn\'t support multiple channel range selection for spw.')
             elif len(unique_list) == 0:
                 raise SyntaxError('Invalid channel range specification')
             elif numpy.any(numpy.array(map(len, unique_list)) == 0):
                 # empty channel range
                 continue
             nchan = scantab.nchan(k)
             full_range = [0.0, float(nchan-1)]
             if unique_list[0] != full_range:
                 sel = sd.selector()
                 sel.set_ifs(k)
                 scantab.set_selection(sel)
                 sdutil.dochannelrange(scantab, unique_list[0])
                 scantab.set_selection()
             valid_spw_list.append(k)
         sel = sd.selector(sel_org)
         ifs_org = sel.get_ifs()
         ifs_new = list(set(ifs_org) & set(valid_spw_list))
         casalog.post('ifs_new = %s'%(ifs_new))
         sel.set_ifs(ifs_new)
         scantab.set_selection(sel)
Пример #3
0
    def asselector(self, rowid=None, rasterid=None, input_selector=None):
        taql = self.astaql(rowid=rowid, rasterid=rasterid)

        if input_selector is None:
            sel = sd.selector(query=taql)
        else:
            sel = sd.selector(input_selector)
            input_query = sel.get_query()
            if len(input_query) == 0:
                sel.set_query(taql)
            else:
                new_query = '(%s) && (%s)' % (input_query, taql)
                sel.set_query(new_query)
        return sel
Пример #4
0
 def asselector(self, rowid=None, rasterid=None, input_selector=None):
     taql = self.astaql(rowid=rowid, rasterid=rasterid)
     
     if input_selector is None:
         sel = sd.selector(query=taql)
     else:
         sel = sd.selector(input_selector)
         input_query = sel.get_query()
         if len(input_query) == 0:
             sel.set_query(taql)
         else:
             new_query = '(%s) && (%s)'%(input_query,taql)
             sel.set_query(new_query)
     return sel
Пример #5
0
 def setup(self):
     s = scantable("data/2011-10-13_1609-MX025.rpf", average=False)
     # make sure this order is always correct - in can be random
     sel = selector()
     sel.set_order = ["SCANNO", "IFNO", "POLNO"]
     s.set_selection(sel)
     self.st = s.copy()
Пример #6
0
 def setup(self):
     s = scantable("data/2011-10-13_1609-MX025.rpf", average=False)
     # make sure this order is always correct - in can be random
     sel = selector()
     sel.set_order = (["SCANNO", "IFNO", "POLNO"])
     s.set_selection(sel)
     self.st = s.copy()
Пример #7
0
 def setup(self):
     s = scantable('data/B68test.nro', average=False, freqref='VREF')
     sel = selector()
     # make sure this order is always correct - it can be random
     sel.set_order(["SCANNO", "POLNO"])
     s.set_selection(sel)
     self.st = s.copy()
     del s
Пример #8
0
def selection_manager(scantab, original_selection, **kwargs):
    sel = sd.selector(original_selection)
    for (k, v) in kwargs.items():
        method_name = 'set_%s' % (k)
        if hasattr(sel, method_name):
            getattr(sel, method_name)(v)
    scantab.set_selection(sel)
    yield scantab
    scantab.set_selection(original_selection)
Пример #9
0
 def test_selection(self):
     sel = selector()
     sel.set_polarisations("YY")
     self.st.set_selection(sel)
     assert_equal(self.st.getpolnos(), [1])
     sel1 = self.st.get_selection()
     assert_equal(sel1.get_pols(), [1])
     self.st.set_selection(pols="XX")
     assert_equal(self.st.getpolnos(), [0])
Пример #10
0
def selection_manager(scantab, original_selection, **kwargs):
    sel = sd.selector(original_selection)
    for (k,v) in kwargs.items():
        method_name = 'set_%s'%(k)
        if hasattr(sel, method_name):
            getattr(sel, method_name)(v)
    scantab.set_selection(sel)
    yield scantab
    scantab.set_selection(original_selection)
Пример #11
0
 def test_selection(self):
     sel = selector()
     sel.set_polarisations("YY")
     self.st.set_selection(sel)
     assert_equal(self.st.getpolnos(), [1])
     sel1 = self.st.get_selection()
     assert_equal(sel1.get_pols(), [1])
     self.st.set_selection(pols="XX")
     assert_equal(self.st.getpolnos(), [0])
Пример #12
0
 def setup(self):
     pth = os.path.dirname(__file__)
     s = scantable(os.path.join(pth, "data", "MOPS.rpf"), average=True)
     sel = selector()
     # make sure this order is always correct - in can be random
     sel.set_order(["SCANNO", "POLNO"])
     s.set_selection(sel)
     self.st = s.copy()
     restfreqs = [86.243]  # 13CO-1/0, SiO the two IF
     self.st.set_restfreqs(restfreqs, "GHz")
Пример #13
0
 def setup(self):
     pth = os.path.dirname(__file__)
     s = scantable(os.path.join(pth, "data", "MOPS.rpf"), average=True)
     sel = selector()
     # make sure this order is always correct - in can be random
     sel.set_order(["SCANNO", "POLNO"])
     s.set_selection(sel)
     self.st = s.copy()
     restfreqs = [86.243]  # 13CO-1/0, SiO the two IF
     self.st.set_restfreqs(restfreqs, "GHz")
Пример #14
0
    def plot( self ):
        """
        """
        from matplotlib import pylab as pl
        from asap import selector
        from asap._asap import srctype as st
        pl.clf()

        # result as a scantable
        s = self.getresult()

        # ON scan
        sel = selector()
        sel.set_types( int(st.pson) )
        s.set_selection( sel )
        diron = numpy.array( s.get_directionval() ).transpose()
        diron[0] = rotate( diron[0] )
        s.set_selection()
        sel.reset()

        # OFF scan
        sel.set_types( int(st.psoff) )
        s.set_selection( sel )
        diroff = numpy.array( s.get_directionval() ).transpose()
        diroff[0] = rotate( diroff[0] )
        s.set_selection()
        sel.reset()
        del s
        del sel

        # plot
        pl.ioff()
        ax=pl.axes()
        ax.set_aspect(1.0)
        pl.plot( diron[0], diron[1], '.', color='blue', label='ON' )
        pl.plot( diroff[0], diroff[1], '.', color='green', label='OFF' )
        [xmin,xmax,ymin,ymax] = pl.axis()
        pl.axis([xmax,xmin,ymin,ymax])
        pl.legend(loc='best',prop={'size':'small'},numpoints=1)
        pl.xlabel( 'R.A. [rad]' )
        pl.ylabel( 'Declination [rad]' )
        pl.title( 'edgemarker result' )
        pl.ion()
        pl.draw()
Пример #15
0
 def __detect_tsysspw(self):
     if len(self.tsysspw) == 0:
         if is_scantable(self.infile):
             sel_org = self.scan.get_selection()
             query_org = sel_org.get_query()
             casalog.post('original query: %s'%(query_org),priority='DEBUG')
             query_new = 'SRCTYPE == 10 && NELEMENTS(TSYS) > 1'
             if len(query_org.strip()) > 0:
                 query_new = '(%s) && (%s)'%(query_org, query_new)
             casalog.post('new query: %s'%(query_new),priority='DEBUG')
             sel = sd.selector(sel_org)
             sel.set_query(query_new)
             try:
                 self.scan.set_selection(sel)
                 self.tsysspw = ','.join(map(str,self.scan.getifnos()))
             except Exception, e:
                 casalog.post('Exception: %s'%(e))
                 self.tsysspw = ''
             finally:
                 self.scan.set_selection(sel_org)
Пример #16
0
s = sd.scantable('IRC+10216_rawACSmod', False)#load the data without averaging		# filein,'IRC.raw.fits'
#Cannot find any matching Tcal at/near the data timestamp. Set Tcal=0.0

#s.summary()				#summary info					# summary
											# fileout,'IRC+10216.reduced.fits'
s.set_fluxunit('K')         		# make 'K' default unit

#scal = sd.calnod(s, [236,237,238,239,248,249,250,251])	# Calibrate HC3N scans		# for i=237,240,2 do begin getps,i,ifnum=0,plnum=0,units='Ta*',
scal = sd.calnod(s, [237,238,239,240,249,250,251,252])	# Calibrate HC3N scans		# for i=237,240,2 do begin getps,i,ifnum=0,plnum=0,units='Ta*',
del s                                   # remove s from memory
# recalculate az/el (NOT needed for GBT data)
antennaname = scal.get_antennaname()
if ( antennaname != 'GBT'): scal.recalc_azel()      # recalculate az/el to 		# tau=0.09 & accum & getps, i, ifnum=0,plnum=1,units='Ta*',
scal.opacity(0.09)			# do opacity correction				# tau=0.09 & accum & end & ave
sel = sd.selector()			# Prepare a selection				# copy,0,9
sel.set_ifs(17)				# select HC3N IF				# for i=250,252,2 do begin getps,i,ifnum=0,plnum=0,units='Ta*',
scal.set_selection(sel)			# get this IF					# tau=0.09 & accum & getps, i, ifnum=0,plnum=1,units='Ta*',
stave = sd.average_time(scal, weight='tintsys')	# average in time			# tau=0.09 & accum & end & ave
spave = stave.average_pol(weight='tsys')	# average polarizations;Tsys-weighted average   # accum
sd.plotter.plot(spave)			# plot						# copy,9,0
											# accum
					# do some smoothing
spave.smooth('boxcar', 5)		# boxcar 5					# boxcar,5
spave.auto_poly_baseline(order=2, threshold=5, chan_avg_limit=4)	# baseline fit order=2	# nfit,2
sd.plotter.plot(spave)			# plot						# baseline

spave.set_unit('GHz')									# freq
sd.plotter.plot(spave)
sd.plotter.set_histogram(hist=True)     # draw spectrum using histogram                 # histogram
sd.plotter.axhline(color='r', linewidth=2) # zline                                       # zline
Пример #17
0
#s.summary()				#summary info					# summary
# fileout,'Orion-S-reduced.fits'
s.set_fluxunit('K')  # make 'K' default unit

#scal = sd.calps(s, [20,21,22,23])		# Calibrate CH3OH scans				# for i=21,24,2 do begin getps,i,ifnum=2,plnum=0,units='Ta*',
scal = sd.calps(
    s, [21, 22, 23, 24]
)  # Calibrate CH3OH scans				# for i=21,24,2 do begin getps,i,ifnum=2,plnum=0,units='Ta*',
del s  # remove s from memory
# recalculate az/el (NOT needed for GBT data)
antennaname = scal.get_antennaname()
if (antennaname != 'GBT'):
    scal.recalc_azel(
    )  # recalculate az/el to 		# tau=0.09 & accum & getps, i, ifnum=2,plnum=1,units='Ta*',
scal.opacity(0.09)  # do opacity correction				# tau=0.09 & accum & end & ave
sel = sd.selector()  # Prepare a selection
sel.set_ifs(2)  # select CH3OH IF
scal.set_selection(sel)  # get this IF
stave = sd.average_time(scal, weight='tintsys')  # average in time
spave = stave.average_pol(
    weight='tsys')  # average polarizations;Tsys-weighted (1/Tsys**2) average
sd.plotter.plot(spave)  # plot

# what is going on with autoscaling?

# do some smoothing
spave.smooth('boxcar', 10)  # boxcar 10					# boxcar,10
#spave.auto_poly_baseline(order=5)	# baseline fit order=5				# nfit,5
# you can also set the baseline region              or
basemask = spave.create_mask([350, 2700],
                             [3500, 7500])  # nregion,[500,3500,5000,7500]
Пример #18
0
    def calc_statistics(self):
        # CAS-5410 Use private tools inside task scripts
        qa = qatool()
        self.savestats = ''
        self.returnstats = {}
        rootidx = []

        #         # Warning for multi-IF data
        #         if len(self.scan.getifnos()) > 1:
        #             casalog.post( 'The scantable contains multiple IF data.', priority='WARN' )
        #             casalog.post( 'Note the same mask(s) are applied to all IFs based on CHANNELS.', priority='WARN' )
        #             casalog.post( 'Baseline ranges may be incorrect for all but IF=%d.\n' % (self.scan.getif(0)), priority='WARN' )

        # backup spec unit
        unit_org = self.scan.get_unit()
        self.scan.set_unit('channel')

        basesel = self.scan.get_selection()
        maskdict = {-1: []}
        if self.spw.strip() not in ['', '*']:
            maskdict = self.scan.parse_spw_selection(self.spw)
        for ifno, masklist in maskdict.items():
            self.masklist = masklist
            if ifno > -1:
                sel = sd.selector(basesel)
                sel.set_ifs([ifno])
                self.scan.set_selection(sel)
                rootidx += list(self.scan._get_root_row_idx())
                del sel
                msg = "Working on IF%s" % (ifno)
                if (self.interactive): print "===%s===" % (msg)
                del msg

            # set mask
            self.__set_mask()

            # set formatter
            self.__set_formatter()

            # set unit labels
            self.__set_unit_labels()

            # calculate statistics
            #statsdict = get_stats(s, msk, formstr)
            self.__calc_stats()
            self.__merge_stats()

            # reset selection
            if ifno > -1: self.scan.set_selection(basesel)

        # restore spec unit
        self.scan.set_unit(unit_org)
        # sort return values in order of root table row idx
        if len(rootidx) > 0:
            self.__sort_stats_order(rootidx)
        # return values instead of lists if nrow = 1.
        if len(self.returnstats[self.returnstats.keys()[0]]) == 1:
            self.__stats_list_to_val()
        # reshape statsdict for return
        for k in ['min', 'max']:
            retsts = {}
            retsts['value'] = self.returnstats.pop('%s_abc' % (k))
            retsts['unit'] = self.xunit
            self.returnstats['%s_abscissa' % (k)] = retsts
        for (k, u) in [('eqw', self.xunit), ('totint', self.intunit)]:
            retsts = {}
            retsts['value'] = self.returnstats[k]
            retsts['unit'] = u
            self.returnstats[k] = retsts
Пример #19
0
    def execute(self):
        self.set_to_scan()
        # backup spec unit
        unit_org = self.scan.get_unit()
        self.scan.set_unit('channel')

        # setup clip threshold
        self.threshold = [None, None]
        if isinstance(self.clipminmax, list):
            if (len(self.clipminmax) == 2):
                self.threshold = self.clipminmax[:]
                self.threshold.sort()
        # loop over spw and flag
        basesel = self.scan.get_selection()
        maskdict = {-1: []}
        if self.spw != '' and self.spw.strip() != '*':
            maskdict = self.scan.parse_spw_selection(self.spw)
        for ifno, masklist in maskdict.items():
            if ifno > -1:
                sel = sd.selector(basesel)
                sel.set_ifs([ifno])
                self.scan.set_selection(sel)
                del sel
                msg = "Working on IF%s" % (ifno)
                if (self.mode.lower().startswith('i')):
                    # interactive mode
                    print "===%s===" % (msg)
                del msg

            mask_array = self.scan.create_mask(
                masklist) if len(masklist) > 0 else [True]
            self.masklist = [] if all(mask_array) else masklist
            if self.mode.lower().startswith('m') and (len(self.masklist) > 0):
                # channel flag
                self.masks = mask_array
            else:
                self.masks = [False for i in xrange(self.scan.nchan())]
            # Pring warnings if channel range selection is found in mode!='manual'
            if (len(self.masklist) > 0) and \
                   not self.mode.lower().startswith('m'):
                casalog.post(
                    "Channel range selection found in IFNO=%d. It would be ignored."
                    % ifno,
                    priority='WARN')

            if self.mode.lower().startswith('i'):
                # interactive mode
                self.interactive_flag()
            else:
                # the other mode
                if (abs(self.plotlevel) > 0):
                    # plot flag and update self.docmdflag by the user input
                    self.prior_plot()

                self.command_flag()

            # reset selection
            if ifno > -1: self.scan.set_selection(basesel)

        # restore spec unit
        self.scan.set_unit(unit_org)

        if not self.anyflag:
            raise Exception, 'No flag operation. Finish without saving'

        if abs(self.plotlevel) > 0:
            self.posterior_plot()
Пример #20
0
    def execute(self):
        self.set_to_scan()
        # backup spec unit
        unit_org = self.scan.get_unit()
        self.scan.set_unit('channel')

        # setup clip threshold
        self.threshold = [None,None]
        if isinstance(self.clipminmax, list):
            if (len(self.clipminmax) == 2):
                self.threshold = self.clipminmax[:]
                self.threshold.sort()
        # loop over spw and flag
        basesel = self.scan.get_selection()
        maskdict = {-1: []}
        if self.spw != '' and self.spw.strip() != '*':
            maskdict = self.scan.parse_spw_selection(self.spw)
        for ifno, masklist in maskdict.items():
            if ifno > -1:
                sel = sd.selector(basesel)
                sel.set_ifs([ifno])
                self.scan.set_selection(sel)
                del sel
                msg = "Working on IF%s" % (ifno)
                if (self.mode.lower().startswith('i')):
                    # interactive mode
                    print "===%s===" % (msg)
                del msg

            mask_array = self.scan.create_mask(masklist) if len(masklist) > 0 else [True]
            self.masklist = [] if all(mask_array) else masklist
            if self.mode.lower().startswith('m') and (len(self.masklist) > 0):
                # channel flag
                self.masks = mask_array
            else:
                self.masks = [False for i in xrange(self.scan.nchan())]
            # Pring warnings if channel range selection is found in mode!='manual'
            if (len(self.masklist) > 0) and \
                   not self.mode.lower().startswith('m'):
                casalog.post("Channel range selection found in IFNO=%d. It would be ignored." % ifno, priority='WARN')

            if self.mode.lower().startswith('i'):
                # interactive mode
                self.interactive_flag()
            else:
                # the other mode
                if (abs(self.plotlevel) > 0):
                    # plot flag and update self.docmdflag by the user input
                    self.prior_plot()

                self.command_flag()

            # reset selection
            if ifno > -1: self.scan.set_selection(basesel)

        # restore spec unit
        self.scan.set_unit(unit_org)

        if not self.anyflag:
            raise Exception, 'No flag operation. Finish without saving'

        if abs(self.plotlevel) > 0:
            self.posterior_plot()
Пример #21
0
    def calc_statistics(self):
        # CAS-5410 Use private tools inside task scripts
        qa = qatool()
        self.savestats = ''
        self.returnstats = {}
        rootidx = []

#         # Warning for multi-IF data
#         if len(self.scan.getifnos()) > 1:
#             casalog.post( 'The scantable contains multiple IF data.', priority='WARN' )
#             casalog.post( 'Note the same mask(s) are applied to all IFs based on CHANNELS.', priority='WARN' )
#             casalog.post( 'Baseline ranges may be incorrect for all but IF=%d.\n' % (self.scan.getif(0)), priority='WARN' )

        # backup spec unit
        unit_org = self.scan.get_unit()
        self.scan.set_unit('channel')
        
        basesel = self.scan.get_selection()
        maskdict = {-1: []}
        if self.spw.strip() not in ['', '*']:
            maskdict = self.scan.parse_spw_selection(self.spw)
        for ifno, masklist in maskdict.items():
            self.masklist = masklist
            if ifno > -1:
                sel = sd.selector(basesel)
                sel.set_ifs([ifno])
                self.scan.set_selection(sel)
                rootidx += list(self.scan._get_root_row_idx())
                del sel
                msg = "Working on IF%s" % (ifno)
                if (self.interactive): print "===%s===" % (msg)
                del msg
            
            # set mask
            self.__set_mask()

            # set formatter
            self.__set_formatter()

            # set unit labels
            self.__set_unit_labels()

            # calculate statistics
            #statsdict = get_stats(s, msk, formstr)
            self.__calc_stats()
            self.__merge_stats()

            # reset selection
            if ifno > -1: self.scan.set_selection(basesel)

        # restore spec unit
        self.scan.set_unit(unit_org)
        # sort return values in order of root table row idx
        if len(rootidx) > 0:
            self.__sort_stats_order(rootidx)
        # return values instead of lists if nrow = 1.
        if len(self.returnstats[ self.returnstats.keys()[0] ]) == 1:
            self.__stats_list_to_val()
        # reshape statsdict for return
        for k in ['min','max']:
            retsts = {}
            retsts['value'] = self.returnstats.pop('%s_abc'%(k))
            retsts['unit'] = self.xunit
            self.returnstats['%s_abscissa'%(k)] = retsts
        for (k,u) in [('eqw',self.xunit),('totint',self.intunit)]:
            retsts = {}
            retsts['value'] = self.returnstats[k]
            retsts['unit'] = u
            self.returnstats[k] = retsts
Пример #22
0
    def execute(self):
        scan = self.worker.scan
        self.__init_blfile()

        nrow = scan.nrow()

        # parse string masklist
        maskdict = scan.parse_spw_selection(self.spw)
        valid_spw_list = []
        for (k, v) in maskdict.items():
            if len(v) > 0 and numpy.all(numpy.array(map(len, v)) > 0):
                valid_spw_list.append(k)

        basesel = scan.get_selection()

        # configure baseline function and its parameters
        self.__configure_baseline()

        for ifno in valid_spw_list:
            lmask = maskdict[ifno]
            sif = str(ifno)
            if len(sif) > 0:
                sel = sd.selector(basesel)
                sel.set_ifs([int(sif)])
                scan.set_selection(sel)
                del sel
                msg = "Working on IF%s" % (sif)
                casalog.post(msg)
                if (self.maskmode == 'interact'): print "===%s===" % (msg)
                del msg

            msk = None

            if (self.maskmode == 'interact'):
                msk = sdutil.interactive_mask(scan,
                                              lmask,
                                              False,
                                              purpose='to baseline spectra')
                msks = scan.get_masklist(msk)
                if len(msks) < 1:
                    msg = 'No channel is selected. Exit without baselining.'
                    casalog.post(msg, priorigy='SEVERE')
                    raise Exception(msg)

                casalog.post('final mask list (' + scan._getabcissalabel() +
                             ') =' + str(msks))
                #header += "   Fit Range: "+str(msks)+"\n"
                del msks
            else:
                # Use baseline mask for regions to INCLUDE in baseline fit
                # Create mask using list, e.g. masklist=[[500,3500],[5000,7500]]
                if (len(lmask) > 0): msk = scan.create_mask(lmask)

            # register IF dependent mask
            self.params['mask'] = msk

            # call target baseline function with appropriate parameter set
            baseline_func = getattr(scan, self.funcname)
            baseline_func(**self.params)

            # reset selection
            if len(sif) > 0: scan.set_selection(basesel)

        ifs_org = basesel.get_ifs()
        ifs_new = list(set(ifs_org) & set(valid_spw_list))
        basesel.set_ifs(ifs_new)
        scan.set_selection(basesel)
Пример #23
0

s = sd.scantable('OrionS_rawACSmod', False)#load the data without averaging		# filein,'Orion-S.raw.fits'

#s.summary()				#summary info					# summary
											# fileout,'Orion-S-reduced.fits'
s.set_fluxunit('K')         		# make 'K' default unit

#scal = sd.calps(s, [20,21,22,23])		# Calibrate CH3OH scans				# for i=21,24,2 do begin getps,i,ifnum=2,plnum=0,units='Ta*',
scal = sd.calps(s, [21,22,23,24])		# Calibrate CH3OH scans				# for i=21,24,2 do begin getps,i,ifnum=2,plnum=0,units='Ta*',
del s                                   # remove s from memory
# recalculate az/el (NOT needed for GBT data)
antennaname = scal.get_antennaname()
if ( antennaname != 'GBT'): scal.recalc_azel()      # recalculate az/el to 		# tau=0.09 & accum & getps, i, ifnum=2,plnum=1,units='Ta*',
scal.opacity(0.09)			# do opacity correction				# tau=0.09 & accum & end & ave
sel = sd.selector()			# Prepare a selection
sel.set_ifs(2)				# select CH3OH IF
scal.set_selection(sel)			# get this IF
stave = sd.average_time(scal, weight='tintsys')	# average in time
spave = stave.average_pol(weight='tsys')	# average polarizations;Tsys-weighted (1/Tsys**2) average
sd.plotter.plot(spave)			# plot

# what is going on with autoscaling?

					# do some smoothing
spave.smooth('boxcar', 10)		# boxcar 10					# boxcar,10
#spave.auto_poly_baseline(order=5)	# baseline fit order=5				# nfit,5
					# you can also set the baseline region              or
basemask = spave.create_mask([350,2700],[3500,7500])                                      # nregion,[500,3500,5000,7500]
spave.poly_baseline(basemask, order=5)							# nfit,5
sd.plotter.plot(spave)			# plot						# baseline
Пример #24
0
    def execute(self):
        scan = self.worker.scan
        self.__init_blfile()

        nrow = scan.nrow()

        # parse string masklist
        maskdict = scan.parse_spw_selection(self.spw)
        valid_spw_list = []
        for (k,v) in maskdict.items():
            if len(v) > 0 and numpy.all(numpy.array(map(len, v)) > 0):
                valid_spw_list.append(k)
        
        basesel = scan.get_selection()

        # configure baseline function and its parameters
        self.__configure_baseline()
        
        for ifno in valid_spw_list:
            lmask = maskdict[ifno]
            sif = str(ifno)
            if len(sif) > 0:
                sel = sd.selector(basesel)
                sel.set_ifs([int(sif)])
                scan.set_selection(sel)
                del sel
                msg = "Working on IF%s" % (sif)
                casalog.post(msg)
                if (self.maskmode == 'interact'): print "===%s===" % (msg)
                del msg

            msk = None

            if (self.maskmode == 'interact'):
                msk = sdutil.interactive_mask(scan, lmask, False, purpose='to baseline spectra')
                msks = scan.get_masklist(msk)
                if len(msks) < 1:
                    msg = 'No channel is selected. Exit without baselining.'
                    casalog.post(msg, priorigy='SEVERE')
                    raise Exception(msg)

                casalog.post( 'final mask list ('+scan._getabcissalabel()+') ='+str(msks) )
                #header += "   Fit Range: "+str(msks)+"\n"
                del msks
            else:
                # Use baseline mask for regions to INCLUDE in baseline fit
                # Create mask using list, e.g. masklist=[[500,3500],[5000,7500]]
                if (len(lmask) > 0): msk = scan.create_mask(lmask)

            # register IF dependent mask
            self.params['mask'] = msk

            # call target baseline function with appropriate parameter set
            baseline_func = getattr(scan, self.funcname)
            baseline_func(**self.params)

            # reset selection
            if len(sif) > 0: scan.set_selection(basesel)

        ifs_org = basesel.get_ifs()
        ifs_new = list(set(ifs_org) & set(valid_spw_list))
        basesel.set_ifs(ifs_new)
        scan.set_selection(basesel)