phatime.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:jiveplot 作者: haavee 项目源码 文件源码
def phasedbg(plotar, ms2mappings):
    global cache
    if plotar.plotType!='phatime':
        raise RuntimeError, "phasedbg() cannot run on plot type {0}".format( plotar.plotType )
    store = len(cache)==0
    # iterate over all plots and all data sets within the plots
    for k in plotar.keys():
        for d in plotar[k].keys():
            # get a reference to the data set
            dsref = plotar[k][d]
            # get the full data set label - we have access to all the data set's properties (FQ, SB, POL etc)
            n     = plots.join_label(k, d)
            # fit a line through the unwrapped phase 
            unw    = numpy.unwrap(numpy.deg2rad(dsref.yval))
            #coeffs = numpy.polyfit(dsref.xval, unw, 1)
            coeffs = numpy.polyfit(xrange(len(dsref.yval)), unw, 1)
            # evaluate the fitted polynomial at the x-loci
            extray = numpy.polyval(coeffs, dsref.xval)
            # here we could compute the reliability of the fit
            diff   = unw - extray
            # compare std deviation and variance in the residuals after fit
            std_r  = numpy.std(diff)
            var_r  = numpy.var(diff)
            coeffs = numpy.rad2deg(coeffs)
            if var_r<std_r:
                # decide what to do
                if store:
                    cache[n] = coeffs
                else:
                    # check if current key exists in cache; if so
                    # do differencing
                    otherCoeffs = cache.get(n, None)
                    if otherCoeffs is None:
                        print "{0}: not found in cache".format( n )
                    else:
                        delta = otherCoeffs - coeffs
                        print "{0.BL} {0.SB} {0.P}: dRate={1:5.4f} dOff={2:4.1f}".format(n, delta[0], delta[1]+360.0 if delta[1]<0.0 else delta[1])
                # before plotting wrap back to -pi,pi and transform to degrees
                #dsref.extra = [ drawline_fn(n, dsref.xval, numpy.rad2deg(do_wrap(extray))) ]
    if not store:
        cache = {}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号