def test_copy_constructor(): v = [0] s = selector(ifs=v) scpy = selector(s) assert_equals(s.get_ifs(), scpy.get_ifs()) scpy.set_beams(v) assert_not_equals(s.get_beams(), scpy.get_beams())
def test_add(): v = [0] s1 = selector(ifs=v) s2 = selector(beams=v) s3 = s1 + s2 assert_equals(s3.get_ifs(), v) assert_equals(s3.get_beams(), v) assert_not_equals(id(s3), id(s1)) assert_not_equals(id(s3), id(s2))
def calnod(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): """ Do full (but a pair of scans at time) processing of GBT Nod data calibration. Adopted from GBTIDL's getnod Parameters: scantab: scantable scannos: a pair of scan numbers, or the first scan number of the pair smooth: box car smoothing order tsysval: optional user specified Tsys value tauval: optional user specified tau value (not implemented yet) tcalval: optional user specified Tcal value verify: Verify calibration if true """ varlist = vars() from asap._asap import stmath from asap._asap import srctype stm = stmath() stm._setinsitu(False) # check for the appropriate data ## s = scantab.get_scan('*_nod*') ## if s is None: ## msg = "The input data appear to contain no Nod observing mode data." ## raise TypeError(msg) s = scantab.copy() sel = selector() sel.set_types( srctype.nod ) try: s.set_selection( sel ) except Exception, e: msg = "The input data appear to contain no Nod observing mode data." raise TypeError(msg)
def constructor(d): p = selector(**d) for k, v in d.items(): meth = getattr(p, 'get_%s' % k) val = v if not hasattr(val, "__len__"): val = [val] assert_equals(meth(), val)
def createTableIn(self, tab): del self.tablein self.tablein = scantable(tab, average=False) if self.ifno < 0: ifno = self.tablein.getif(0) #print 'ifno=',ifno else: ifno = self.ifno sel = selector() sel.set_ifs(ifno) self.tablein.set_selection(sel) self.nchan = len(self.tablein._getspectrum(0)) self.nrow = self.tablein.nrow() del sel
def createTableIn( self, tab ): del self.tablein self.tablein = scantable( tab, average=False ) if self.ifno < 0: ifno = self.tablein.getif(0) #print 'ifno=',ifno else: ifno = self.ifno sel = selector() sel.set_ifs( ifno ) self.tablein.set_selection( sel ) self.nchan = len(self.tablein._getspectrum(0)) self.nrow = self.tablein.nrow() del sel
def _array2dOp(scan, value, mode="ADD", tsys=False, insitu=None, skip_flaggedrow=False): """ This function is workaround on the basic operation of scantable with 2 dimensional float list. scan: scantable operand value: float list operand mode: operation mode (ADD, SUB, MUL, DIV) tsys: if True, operate tsys as well insitu: if False, a new scantable is returned. Otherwise, the array operation is done in-sitsu. skip_flaggedrow: skip operation for row-flagged spectra. """ if insitu is None: insitu = rcParams['insitu'] nrow = scan.nrow() s = None from asap._asap import stmath stm = stmath() stm._setinsitu(insitu) if len(value) == 1: s = scantable(stm._arrayop(scan, value[0], mode, tsys, skip_flaggedrow)) elif len(value) != nrow: raise ValueError('len(value) must be 1 or conform to scan.nrow()') else: from asap._asap import stmath if not insitu: s = scan.copy() else: s = scan # insitu must be True as we go row by row on the same data stm._setinsitu(True) basesel = s.get_selection() # generate a new selector object based on basesel sel = selector(basesel) for irow in range(nrow): sel.set_rows(irow) s.set_selection(sel) if len(value[irow]) == 1: stm._unaryop(s, value[irow][0], mode, tsys, skip_flaggedrow) else: #stm._arrayop( s, value[irow], mode, tsys, 'channel' ) stm._arrayop(s, value[irow], mode, tsys, skip_flaggedrow) s.set_selection(basesel) return s
def _array2dOp( scan, value, mode="ADD", tsys=False, insitu=None, skip_flaggedrow=False): """ This function is workaround on the basic operation of scantable with 2 dimensional float list. scan: scantable operand value: float list operand mode: operation mode (ADD, SUB, MUL, DIV) tsys: if True, operate tsys as well insitu: if False, a new scantable is returned. Otherwise, the array operation is done in-sitsu. skip_flaggedrow: skip operation for row-flagged spectra. """ if insitu is None: insitu = rcParams['insitu'] nrow = scan.nrow() s = None from asap._asap import stmath stm = stmath() stm._setinsitu(insitu) if len( value ) == 1: s = scantable( stm._arrayop( scan, value[0], mode, tsys, skip_flaggedrow ) ) elif len( value ) != nrow: raise ValueError( 'len(value) must be 1 or conform to scan.nrow()' ) else: from asap._asap import stmath if not insitu: s = scan.copy() else: s = scan # insitu must be True as we go row by row on the same data stm._setinsitu( True ) basesel = s.get_selection() # generate a new selector object based on basesel sel = selector(basesel) for irow in range( nrow ): sel.set_rows( irow ) s.set_selection( sel ) if len( value[irow] ) == 1: stm._unaryop( s, value[irow][0], mode, tsys, skip_flaggedrow ) else: #stm._arrayop( s, value[irow], mode, tsys, 'channel' ) stm._arrayop( s, value[irow], mode, tsys, skip_flaggedrow ) s.set_selection(basesel) return s
def calps(scantab, scannos, smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): """ Calibrate GBT position switched data Adopted from GBTIDL getps Currently calps identify the scans as position switched data if source type enum is pson or psoff. The data must contains 'CAL' signal on/off in each integration. To identify 'CAL' on state, the source type enum of poncal and poffcal need to be present. Parameters: scantab: scantable scannos: list of scan numbers smooth: optional box smoothing order for the reference (default is 1 = no smoothing) tsysval: optional user specified Tsys (default is 0.0, use Tsys in the data) tauval: optional user specified Tau tcalval: optional user specified Tcal (default is 0.0, use Tcal value in the data) verify: Verify calibration if true """ varlist = vars() # check for the appropriate data ## s = scantab.get_scan('*_ps*') ## if s is None: ## msg = "The input data appear to contain no position-switch mode data." ## raise TypeError(msg) s = scantab.copy() from asap._asap import srctype sel = selector() sel.set_types(srctype.pson) try: scantab.set_selection(sel) except Exception, e: msg = "The input data appear to contain no position-switch mode data." raise TypeError(msg)
def almacal( scantab, scannos=[], calmode='none', verify=False ): """ Calibrate ALMA data Parameters: scantab: scantable scannos: list of scan number calmode: calibration mode verify: verify calibration """ from asap._asap import stmath stm = stmath() selection=selector() selection.set_scans(scannos) orig = scantab.get_selection() scantab.set_selection(orig+selection) ## ssub = scantab.get_scan( scannos ) ## scal = scantable( stm.almacal( ssub, calmode ) ) scal = scantable( stm.almacal( scantab, calmode ) ) scantab.set_selection(orig) return scal
def almacal(scantab, scannos=[], calmode='none', verify=False): """ Calibrate ALMA data Parameters: scantab: scantable scannos: list of scan number calmode: calibration mode verify: verify calibration """ from asap._asap import stmath stm = stmath() selection = selector() selection.set_scans(scannos) orig = scantab.get_selection() scantab.set_selection(orig + selection) ## ssub = scantab.get_scan( scannos ) ## scal = scantable( stm.almacal( ssub, calmode ) ) scal = scantable(stm.almacal(scantab, calmode)) scantab.set_selection(orig) return scal
def calnod(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): """ Do full (but a pair of scans at time) processing of GBT Nod data calibration. Adopted from GBTIDL's getnod Parameters: scantab: scantable scannos: a pair of scan numbers, or the first scan number of the pair smooth: box car smoothing order tsysval: optional user specified Tsys value tauval: optional user specified tau value (not implemented yet) tcalval: optional user specified Tcal value verify: Verify calibration if true """ varlist = vars() from asap._asap import stmath from asap._asap import srctype stm = stmath() stm._setinsitu(False) # check for the appropriate data ## s = scantab.get_scan('*_nod*') ## if s is None: ## msg = "The input data appear to contain no Nod observing mode data." ## raise TypeError(msg) s = scantab.copy() sel = selector() sel.set_types(srctype.nod) try: s.set_selection(sel) except Exception, e: msg = "The input data appear to contain no Nod observing mode data." raise TypeError(msg)
def calps(scantab, scannos, smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): """ Calibrate GBT position switched data Adopted from GBTIDL getps Currently calps identify the scans as position switched data if source type enum is pson or psoff. The data must contains 'CAL' signal on/off in each integration. To identify 'CAL' on state, the source type enum of poncal and poffcal need to be present. Parameters: scantab: scantable scannos: list of scan numbers smooth: optional box smoothing order for the reference (default is 1 = no smoothing) tsysval: optional user specified Tsys (default is 0.0, use Tsys in the data) tauval: optional user specified Tau tcalval: optional user specified Tcal (default is 0.0, use Tcal value in the data) verify: Verify calibration if true """ varlist = vars() # check for the appropriate data ## s = scantab.get_scan('*_ps*') ## if s is None: ## msg = "The input data appear to contain no position-switch mode data." ## raise TypeError(msg) s = scantab.copy() from asap._asap import srctype sel = selector() sel.set_types( srctype.pson ) try: scantab.set_selection( sel ) except Exception, e: msg = "The input data appear to contain no position-switch mode data." raise TypeError(msg)
# calculate a scaling factor using the formula # -> tsys use to dosigref #ress = dosigref(sig, ref, smooth, tsysval) ress = dosigref(sig, ref, smooth, tsysval, tauval) ### if verify: # get data import numpy precal={} postcal=[] keys=['ps','ps_calon','psr','psr_calon'] types=[srctype.pson,srctype.poncal,srctype.psoff,srctype.poffcal] ifnos=list(ssub.getifnos()) polnos=list(ssub.getpolnos()) sel=selector() for i in range(2): #ss=ssuboff.get_scan('*'+keys[2*i]) ll=[] for j in range(len(ifnos)): for k in range(len(polnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) sel.set_types(types[2*i]) try: #ss.set_selection(sel) ssuboff.set_selection(sel) except: continue #ll.append(numpy.array(ss._getspectrum(0))) ll.append(numpy.array(ssuboff._getspectrum(0)))
def calfs(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): """ Calibrate GBT frequency switched data. Adopted from GBTIDL getfs. Currently calfs identify the scans as frequency switched data if source type enum is fson and fsoff. The data must contains 'CAL' signal on/off in each integration. To identify 'CAL' on state, the source type enum of foncal and foffcal need to be present. Parameters: scantab: scantable scannos: list of scan numbers smooth: optional box smoothing order for the reference (default is 1 = no smoothing) tsysval: optional user specified Tsys (default is 0.0, use Tsys in the data) tauval: optional user specified Tau verify: Verify calibration if true """ varlist = vars() from asap._asap import stmath from asap._asap import srctype stm = stmath() stm._setinsitu(False) # check = scantab.get_scan('*_fs*') # if check is None: # msg = "The input data appear to contain no Nod observing mode data." # raise TypeError(msg) s = scantab.get_scan(scannos) del scantab resspec = scantable(stm._dofs(s, scannos, smooth, tsysval, tauval, tcalval)) ### if verify: # get data ssub = s.get_scan(scannos) #ssubon = ssub.get_scan('*calon') #ssuboff = ssub.get_scan('*[^calon]') sel = selector() sel.set_types([srctype.foncal, srctype.foffcal]) ssub.set_selection(sel) ssubon = ssub.copy() ssub.set_selection() sel.reset() sel.set_types([srctype.fson, srctype.fsoff]) ssub.set_selection(sel) ssuboff = ssub.copy() ssub.set_selection() sel.reset() import numpy precal = {} postcal = [] keys = ['fs', 'fs_calon', 'fsr', 'fsr_calon'] types = [srctype.fson, srctype.foncal, srctype.fsoff, srctype.foffcal] ifnos = list(ssub.getifnos()) polnos = list(ssub.getpolnos()) for i in range(2): #ss=ssuboff.get_scan('*'+keys[2*i]) ll = [] for j in range(len(ifnos)): for k in range(len(polnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) sel.set_types(types[2 * i]) try: #ss.set_selection(sel) ssuboff.set_selection(sel) except: continue ll.append(numpy.array(ss._getspectrum(0))) sel.reset() #ss.set_selection() ssuboff.set_selection() precal[keys[2 * i]] = ll #del ss #ss=ssubon.get_scan('*'+keys[2*i+1]) ll = [] for j in range(len(ifnos)): for k in range(len(polnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) sel.set_types(types[2 * i + 1]) try: #ss.set_selection(sel) ssubon.set_selection(sel) except: continue ll.append(numpy.array(ss._getspectrum(0))) sel.reset() #ss.set_selection() ssubon.set_selection() precal[keys[2 * i + 1]] = ll #del ss #sig=resspec.get_scan('*_fs') #ref=resspec.get_scan('*_fsr') sel.set_types(srctype.fson) resspec.set_selection(sel) sig = resspec.copy() resspec.set_selection() sel.reset() sel.set_type(srctype.fsoff) resspec.set_selection(sel) ref = resspec.copy() resspec.set_selection() sel.reset() for k in range(len(polnos)): for j in range(len(ifnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) try: sig.set_selection(sel) postcal.append(numpy.array(sig._getspectrum(0))) except: ref.set_selection(sel) postcal.append(numpy.array(ref._getspectrum(0))) sel.reset() resspec.set_selection() del sel # plot asaplog.post() asaplog.push( 'Plot only first spectrum for each [if,pol] pairs to verify calibration.' ) asaplog.post('WARN') p = new_asaplot() rcp('lines', linewidth=1) #nr=min(6,len(ifnos)*len(polnos)) nr = len(ifnos) / 2 * len(polnos) titles = [] btics = [] if nr > 3: asaplog.post() asaplog.push('Only first 3 [if,pol] pairs are plotted.') asaplog.post('WARN') nr = 3 p.set_panels(rows=nr, cols=3, nplots=3 * nr, ganged=False) for i in range(3 * nr): b = False if i >= 3 * nr - 3: b = True btics.append(b) for i in range(nr): p.subplot(3 * i) p.color = 0 title = 'raw data IF%s,%s POL%s' % ( ifnos[2 * int(i / len(polnos))], ifnos[2 * int(i / len(polnos)) + 1], polnos[i % len(polnos)]) titles.append(title) #p.set_axes('title',title,fontsize=40) ymin = 1.0e100 ymax = -1.0e100 nchan = s.nchan(ifnos[2 * int(i / len(polnos))]) edge = int(nchan * 0.01) for j in range(4): spmin = min(precal[keys[j]][i][edge:nchan - edge]) spmax = max(precal[keys[j]][i][edge:nchan - edge]) ymin = min(ymin, spmin) ymax = max(ymax, spmax) for j in range(4): if i == 0: p.set_line(label=keys[j]) else: p.legend() p.plot(precal[keys[j]][i]) p.axes.set_ylim(ymin - 0.1 * abs(ymin), ymax + 0.1 * abs(ymax)) if not btics[3 * i]: p.axes.set_xticks([]) p.subplot(3 * i + 1) p.color = 0 title = 'sig data IF%s POL%s' % (ifnos[2 * int(i / len(polnos))], polnos[i % len(polnos)]) titles.append(title) #p.set_axes('title',title) p.legend() ymin = postcal[2 * i][edge:nchan - edge].min() ymax = postcal[2 * i][edge:nchan - edge].max() p.plot(postcal[2 * i]) p.axes.set_ylim(ymin - 0.1 * abs(ymin), ymax + 0.1 * abs(ymax)) if not btics[3 * i + 1]: p.axes.set_xticks([]) p.subplot(3 * i + 2) p.color = 0 title = 'ref data IF%s POL%s' % (ifnos[2 * int(i / len(polnos)) + 1], polnos[i % len(polnos)]) titles.append(title) #p.set_axes('title',title) p.legend() ymin = postcal[2 * i + 1][edge:nchan - edge].min() ymax = postcal[2 * i + 1][edge:nchan - edge].max() p.plot(postcal[2 * i + 1]) p.axes.set_ylim(ymin - 0.1 * abs(ymin), ymax + 0.1 * abs(ymax)) if not btics[3 * i + 2]: p.axes.set_xticks([]) for i in range(3 * nr): p.subplot(i) p.set_axes('title', titles[i], fontsize='medium') x = raw_input('Accept calibration ([y]/n): ') if x.upper() == 'N': p.quit() del p return scantab p.quit() del p ### resspec._add_history("calfs", varlist) return resspec
def calfs(scantab, scannos=[], smooth=1, tsysval=0.0, tauval=0.0, tcalval=0.0, verify=False): """ Calibrate GBT frequency switched data. Adopted from GBTIDL getfs. Currently calfs identify the scans as frequency switched data if source type enum is fson and fsoff. The data must contains 'CAL' signal on/off in each integration. To identify 'CAL' on state, the source type enum of foncal and foffcal need to be present. Parameters: scantab: scantable scannos: list of scan numbers smooth: optional box smoothing order for the reference (default is 1 = no smoothing) tsysval: optional user specified Tsys (default is 0.0, use Tsys in the data) tauval: optional user specified Tau verify: Verify calibration if true """ varlist = vars() from asap._asap import stmath from asap._asap import srctype stm = stmath() stm._setinsitu(False) # check = scantab.get_scan('*_fs*') # if check is None: # msg = "The input data appear to contain no Nod observing mode data." # raise TypeError(msg) s = scantab.get_scan(scannos) del scantab resspec = scantable(stm._dofs(s, scannos, smooth, tsysval,tauval,tcalval)) ### if verify: # get data ssub = s.get_scan(scannos) #ssubon = ssub.get_scan('*calon') #ssuboff = ssub.get_scan('*[^calon]') sel = selector() sel.set_types( [srctype.foncal,srctype.foffcal] ) ssub.set_selection( sel ) ssubon = ssub.copy() ssub.set_selection() sel.reset() sel.set_types( [srctype.fson,srctype.fsoff] ) ssub.set_selection( sel ) ssuboff = ssub.copy() ssub.set_selection() sel.reset() import numpy precal={} postcal=[] keys=['fs','fs_calon','fsr','fsr_calon'] types=[srctype.fson,srctype.foncal,srctype.fsoff,srctype.foffcal] ifnos=list(ssub.getifnos()) polnos=list(ssub.getpolnos()) for i in range(2): #ss=ssuboff.get_scan('*'+keys[2*i]) ll=[] for j in range(len(ifnos)): for k in range(len(polnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) sel.set_types(types[2*i]) try: #ss.set_selection(sel) ssuboff.set_selection(sel) except: continue ll.append(numpy.array(ss._getspectrum(0))) sel.reset() #ss.set_selection() ssuboff.set_selection() precal[keys[2*i]]=ll #del ss #ss=ssubon.get_scan('*'+keys[2*i+1]) ll=[] for j in range(len(ifnos)): for k in range(len(polnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) sel.set_types(types[2*i+1]) try: #ss.set_selection(sel) ssubon.set_selection(sel) except: continue ll.append(numpy.array(ss._getspectrum(0))) sel.reset() #ss.set_selection() ssubon.set_selection() precal[keys[2*i+1]]=ll #del ss #sig=resspec.get_scan('*_fs') #ref=resspec.get_scan('*_fsr') sel.set_types( srctype.fson ) resspec.set_selection( sel ) sig=resspec.copy() resspec.set_selection() sel.reset() sel.set_type( srctype.fsoff ) resspec.set_selection( sel ) ref=resspec.copy() resspec.set_selection() sel.reset() for k in range(len(polnos)): for j in range(len(ifnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) try: sig.set_selection(sel) postcal.append(numpy.array(sig._getspectrum(0))) except: ref.set_selection(sel) postcal.append(numpy.array(ref._getspectrum(0))) sel.reset() resspec.set_selection() del sel # plot asaplog.post() asaplog.push('Plot only first spectrum for each [if,pol] pairs to verify calibration.') asaplog.post('WARN') p=new_asaplot() rcp('lines', linewidth=1) #nr=min(6,len(ifnos)*len(polnos)) nr=len(ifnos)/2*len(polnos) titles=[] btics=[] if nr>3: asaplog.post() asaplog.push('Only first 3 [if,pol] pairs are plotted.') asaplog.post('WARN') nr=3 p.set_panels(rows=nr,cols=3,nplots=3*nr,ganged=False) for i in range(3*nr): b=False if i >= 3*nr-3: b=True btics.append(b) for i in range(nr): p.subplot(3*i) p.color=0 title='raw data IF%s,%s POL%s' % (ifnos[2*int(i/len(polnos))],ifnos[2*int(i/len(polnos))+1],polnos[i%len(polnos)]) titles.append(title) #p.set_axes('title',title,fontsize=40) ymin=1.0e100 ymax=-1.0e100 nchan=s.nchan(ifnos[2*int(i/len(polnos))]) edge=int(nchan*0.01) for j in range(4): spmin=min(precal[keys[j]][i][edge:nchan-edge]) spmax=max(precal[keys[j]][i][edge:nchan-edge]) ymin=min(ymin,spmin) ymax=max(ymax,spmax) for j in range(4): if i==0: p.set_line(label=keys[j]) else: p.legend() p.plot(precal[keys[j]][i]) p.axes.set_ylim(ymin-0.1*abs(ymin),ymax+0.1*abs(ymax)) if not btics[3*i]: p.axes.set_xticks([]) p.subplot(3*i+1) p.color=0 title='sig data IF%s POL%s' % (ifnos[2*int(i/len(polnos))],polnos[i%len(polnos)]) titles.append(title) #p.set_axes('title',title) p.legend() ymin=postcal[2*i][edge:nchan-edge].min() ymax=postcal[2*i][edge:nchan-edge].max() p.plot(postcal[2*i]) p.axes.set_ylim(ymin-0.1*abs(ymin),ymax+0.1*abs(ymax)) if not btics[3*i+1]: p.axes.set_xticks([]) p.subplot(3*i+2) p.color=0 title='ref data IF%s POL%s' % (ifnos[2*int(i/len(polnos))+1],polnos[i%len(polnos)]) titles.append(title) #p.set_axes('title',title) p.legend() ymin=postcal[2*i+1][edge:nchan-edge].min() ymax=postcal[2*i+1][edge:nchan-edge].max() p.plot(postcal[2*i+1]) p.axes.set_ylim(ymin-0.1*abs(ymin),ymax+0.1*abs(ymax)) if not btics[3*i+2]: p.axes.set_xticks([]) for i in range(3*nr): p.subplot(i) p.set_axes('title',titles[i],fontsize='medium') x=raw_input('Accept calibration ([y]/n): ' ) if x.upper() == 'N': p.quit() del p return scantab p.quit() del p ### resspec._add_history("calfs",varlist) return resspec
# calculate a scaling factor using the formula # -> tsys use to dosigref #ress = dosigref(sig, ref, smooth, tsysval) ress = dosigref(sig, ref, smooth, tsysval, tauval) ### if verify: # get data import numpy precal = {} postcal = [] keys = ['ps', 'ps_calon', 'psr', 'psr_calon'] types = [srctype.pson, srctype.poncal, srctype.psoff, srctype.poffcal] ifnos = list(ssub.getifnos()) polnos = list(ssub.getpolnos()) sel = selector() for i in range(2): #ss=ssuboff.get_scan('*'+keys[2*i]) ll = [] for j in range(len(ifnos)): for k in range(len(polnos)): sel.set_ifs(ifnos[j]) sel.set_polarizations(polnos[k]) sel.set_types(types[2 * i]) try: #ss.set_selection(sel) ssuboff.set_selection(sel) except: continue #ll.append(numpy.array(ss._getspectrum(0))) ll.append(numpy.array(ssuboff._getspectrum(0)))
def skydip(data, averagepol=True, tsky=300., plot=False, temperature=288, pressure=101325., humidity=0.5): """Determine the opacity from a set of 'skydip' obervations. This can be any set of observations over a range of elevations, but will ususally be a dedicated (set of) scan(s). Return a list of 'n' opacities for 'n' IFs. In case of averagepol being 'False' a list of 'n*m' elements where 'm' is the number of polarisations, e.g. nIF = 3, nPol = 2 => [if0pol0, if0pol1, if1pol0, if1pol1, if2pol0, if2pol1] The opacity is determined by fitting a first order polynomial to: Tsys(airmass) = p0 + airmass*p1 where airmass = 1/sin(elevation) tau = p1/Tsky Parameters: data: a list of file names or scantables or a single file name or scantable. averagepol: Return the average of the opacities for the polarisations This might be useful to set to 'False' if one polarisation is corrupted (Mopra). If set to 'False', an opacity value per polarisation is returned. tsky: The sky temperature (default 300.0K). This might be read from the data in the future. plot: Plot each fit (airmass vs. Tsys). Default is 'False' """ # quiten output verbose = rcParams["verbose"] rcParams["verbose"] = False try: if plot: from matplotlib import pylab scan = _import_data(data) f = fitter() f.set_function(poly=1) sel = selector() basesel = scan.get_selection() inos = scan.getifnos() pnos = scan.getpolnos() opacities = [] om = model(temperature, pressure, humidity) for ino in inos: sel.set_ifs(ino) opacity = [] fits = [] airms = [] tsyss = [] if plot: pylab.cla() pylab.ioff() pylab.clf() pylab.xlabel("Airmass") pylab.ylabel(r"$T_{sys}$") for pno in pnos: sel.set_polarisations(pno) scan.set_selection(basesel + sel) freq = scan.get_coordinate(0).get_reference_value() / 1e9 freqstr = "%0.4f GHz" % freq tsys = scan.get_tsys() elev = scan.get_elevation() airmass = [1. / math.sin(i) for i in elev] airms.append(airmass) tsyss.append(tsys) f.set_data(airmass, tsys) f.fit() fits.append(f.get_fit()) params = f.get_parameters()["params"] opacity.append(params[1] / tsky) if averagepol: opacities.append(sum(opacity) / len(opacity)) else: opacities += opacity if plot: colors = ['b', 'g', 'k'] n = len(airms) for i in range(n): pylab.plot(airms[i], tsyss[i], 'o', color=colors[i]) pylab.plot(airms[i], fits[i], '-', color=colors[i]) pylab.figtext(0.7, 0.3 - (i / 30.0), r"$\tau_{fit}=%0.2f$" % opacity[i], color=colors[i]) if averagepol: pylab.figtext(0.7, 0.3 - (n / 30.0), r"$\tau_{avg}=%0.2f$" % opacities[-1], color='r') n += 1 pylab.figtext(0.7, 0.3 - (n / 30.0), r"$\tau_{model}=%0.2f$" % om.get_opacities(freq * 1e9), color='grey') pylab.title("IF%d : %s" % (ino, freqstr)) pylab.ion() pylab.draw() raw_input("Hit <return> for next fit...") sel.reset() scan.set_selection(basesel) if plot: pylab.close() return opacities finally: rcParams["verbose"] = verbose
def skydip(data, averagepol=True, tsky=300., plot=False, temperature=288, pressure=101325., humidity=0.5): """Determine the opacity from a set of 'skydip' obervations. This can be any set of observations over a range of elevations, but will ususally be a dedicated (set of) scan(s). Return a list of 'n' opacities for 'n' IFs. In case of averagepol being 'False' a list of 'n*m' elements where 'm' is the number of polarisations, e.g. nIF = 3, nPol = 2 => [if0pol0, if0pol1, if1pol0, if1pol1, if2pol0, if2pol1] The opacity is determined by fitting a first order polynomial to: Tsys(airmass) = p0 + airmass*p1 where airmass = 1/sin(elevation) tau = p1/Tsky Parameters: data: a list of file names or scantables or a single file name or scantable. averagepol: Return the average of the opacities for the polarisations This might be useful to set to 'False' if one polarisation is corrupted (Mopra). If set to 'False', an opacity value per polarisation is returned. tsky: The sky temperature (default 300.0K). This might be read from the data in the future. plot: Plot each fit (airmass vs. Tsys). Default is 'False' """ # quiten output verbose = rcParams["verbose"] rcParams["verbose"] = False try: if plot: from matplotlib import pylab scan = _import_data(data) f = fitter() f.set_function(poly=1) sel = selector() basesel = scan.get_selection() inos = scan.getifnos() pnos = scan.getpolnos() opacities = [] om = model(temperature, pressure, humidity) for ino in inos: sel.set_ifs(ino) opacity = [] fits = [] airms = [] tsyss = [] if plot: pylab.cla() pylab.ioff() pylab.clf() pylab.xlabel("Airmass") pylab.ylabel(r"$T_{sys}$") for pno in pnos: sel.set_polarisations(pno) scan.set_selection(basesel+sel) freq = scan.get_coordinate(0).get_reference_value()/1e9 freqstr = "%0.4f GHz" % freq tsys = scan.get_tsys() elev = scan.get_elevation() airmass = [ 1./math.sin(i) for i in elev ] airms.append(airmass) tsyss.append(tsys) f.set_data(airmass, tsys) f.fit() fits.append(f.get_fit()) params = f.get_parameters()["params"] opacity.append(params[1]/tsky) if averagepol: opacities.append(sum(opacity)/len(opacity)) else: opacities += opacity if plot: colors = ['b','g','k'] n = len(airms) for i in range(n): pylab.plot(airms[i], tsyss[i], 'o', color=colors[i]) pylab.plot(airms[i], fits[i], '-', color=colors[i]) pylab.figtext(0.7,0.3-(i/30.0), r"$\tau_{fit}=%0.2f$" % opacity[i], color=colors[i]) if averagepol: pylab.figtext(0.7,0.3-(n/30.0), r"$\tau_{avg}=%0.2f$" % opacities[-1], color='r') n +=1 pylab.figtext(0.7,0.3-(n/30.0), r"$\tau_{model}=%0.2f$" % om.get_opacities(freq*1e9), color='grey') pylab.title("IF%d : %s" % (ino, freqstr)) pylab.ion() pylab.draw() raw_input("Hit <return> for next fit...") sel.reset() scan.set_selection(basesel) if plot: pylab.close() return opacities finally: rcParams["verbose"] = verbose
def test_reset(): v = [0] s = selector(ifs=v) assert_equals(s.get_ifs(), v) s.reset() assert_true(s.is_empty())