예제 #1
0
def genfits():
    from LeastSquares import leastSquaresFit
    global psrp, orbp, orbx, orbe, orbw, orbt
    global widthp, widthx, widtht, widthe, widthw
    global mf, z
    yvals = {'Orb p': widthp, 'Orb x': widthx, 'Orb t': widtht}
    xvals = {'Orb p': orbp / z, 'Orb x': 1.0 / z, 'Orb t': 1.0 / z}
    xtits = {'Orb p': 'Orb p/z', 'Orb x': '1.0/z', 'Orb t': '1.0/z'}
    for fitvar in ['Orb p', 'Orb x', 'Orb t']:
        vals = []
        for i in range(len(xvals[fitvar])):
            vals.append((xvals[fitvar][i], yvals[fitvar][i]))
        fit = leastSquaresFit(linear, (1.0, 0.0), vals)
        print('%s width = %10.7f * %s + %10.7f  (Acc: %f)' %
              (fitvar, fit[0][0], xtits[fitvar], fit[0][1], fit[1]))
        plotxy(yvals[fitvar],
               xvals[fitvar],
               laby=fitvar + ' Width (Fractional)',
               labx=xtits[fitvar],
               line=None,
               font=2,
               symbol=2,
               color='red',
               device='fits.ps/CPS')
        plotxy([
            fit[0][0] * min(xvals[fitvar]) + fit[0][1],
            fit[0][0] * max(xvals[fitvar]) + fit[0][1]
        ], [min(xvals[fitvar]), max(xvals[fitvar])],
               line=1,
               symbol=None,
               color='blue')
        nextplotpage(1)
    closeplot()
예제 #2
0
def genlogfits():
    from LeastSquares import leastSquaresFit
    global psrp, orbp, orbx, orbe, orbw, orbt
    global widthp, widthx, widtht, widthe, widthw
    global mf, z
    yvals = {'Orb p':log(widthp), 'Orb x':log(widthx), 'Orb t':log(widtht)}
    xvals = {'Orb p':log(orbp/z), 'Orb x':log(1.0/z), 'Orb t':log(1.0/z)}
    xtits = {'Orb p':'log(Orb p/z)', 'Orb x':'log(1.0/z)',
             'Orb t':'log(1.0/z)'}
    for fitvar in ['Orb p', 'Orb x', 'Orb t']:
        vals = []
        for i in range(len(xvals[fitvar])):
            vals.append((xvals[fitvar][i], yvals[fitvar][i]))
        fit = leastSquaresFit(linear, (1.0, 0.0), vals)
        print 'log(%s) width = %10.7f * %s + %10.7f  (Acc: %f)' % (fitvar,
                                                                   fit[0][0],
                                                                   xtits[fitvar],
                                                                   fit[0][1],
                                                                   fit[1])
        plotxy(yvals[fitvar], xvals[fitvar],
               laby='log('+fitvar+') Width (Fractional)',
               labx=xtits[fitvar], line=None, font=2,
               symbol=2, color='red', device='logfits.ps/CPS')
        plotxy([fit[0][0]*min(xvals[fitvar])+fit[0][1],
                fit[0][0]*max(xvals[fitvar])+fit[0][1]],
               [min(xvals[fitvar]), max(xvals[fitvar])],
               line=1, symbol=None, color='blue')
        nextplotpage(1)
    closeplot()
예제 #3
0
             if debugout:
                 # Print the most recent results
                 print '   %s:  Delta = %10.6f   Response = %8.5f' % \
                       (myjob, vals[-1][0], vals[-1][1])
             if showplots and not parallel:
                 # Plot the results of the correlation
                 Pgplot.plotxy(respow, labx='Frequency',
                               laby='Relative Power')
                 a = raw_input("Press enter to continue...")
                 Pgplot.nextplotpage(1)
         # A very rough adaptive stepsize
         if abs(vals[-3][1] - vals[-1][1]) < 0.04:
             ddelta = ddelta * 2.0            
         delta = delta + ddelta
     # Fit a quadratic to the width values
     fit = leastSquaresFit(quadratic, (-1.0, 0.0, 1.0), vals)
     if debugout:
         print '\n   %sfit = %fx^2 + %fx + %f\n' % (myjob, fit[0][0],
                                                    fit[0][1],
                                                    fit[0][2])
     width = 2.0*math.sqrt(-0.5/fit[0][0])
     if parallel:
         newwidths = mpi.gather_string(str(width), 0)
         if myid==0:
             for proc in range(numprocs):
                 psrlist.append(string.atof(newwidths[proc]))
     else:
         psrlist.append(width)
 widths.append(psrlist)
 if debugout:
     print 'Widths are', widths[i]
예제 #4
0
             if debugout:
                 # Print the most recent results
                 print '   %s:  Delta = %10.6f   Response = %8.5f' % \
                       (myjob, vals[-1][0], vals[-1][1])
             if showplots and not parallel:
                 # Plot the results of the correlation
                 Pgplot.plotxy(respow, labx='Frequency',
                               laby='Relative Power')
                 a = raw_input("Press enter to continue...")
                 Pgplot.nextplotpage(1)
         # A very rough adaptive stepsize
         if abs(vals[-3][1] - vals[-1][1]) < 0.04:
             ddelta = ddelta * 2.0            
         delta = delta + ddelta
     # Fit a quadratic to the width values
     fit = leastSquaresFit(quadratic, (-1.0, 0.0, 1.0), vals)
     if debugout:
         print '\n   %sfit = %fx^2 + %fx + %f\n' % (myjob, fit[0][0],
                                                    fit[0][1],
                                                    fit[0][2])
     width = 2.0*math.sqrt(-0.5/fit[0][0])
     if parallel:
         newwidths = mpi.gather_string(str(width), 0)
         if myid==0:
             for proc in range(numprocs):
                 psrlist.append(string.atof(newwidths[proc]))
     else:
         psrlist.append(width)
 widths.append(psrlist)
 if debugout:
     print 'Widths are', widths[i]