def plotvector(self, vector, amp=None, color='red', device='/XWIN', step=0): """ dftvector.plotvector(vector, amp=None, color='red', device='/XWIN', step=0) Plot 'vector' in the complex plane. """ x = Numeric.zeros(self.numvect+1, 'd') y = Numeric.zeros(self.numvect+1, 'd') x[1:] = vector.real y[1:] = vector.imag if not amp: amp = 1.1 * umath.maximum(max(umath.absolute(x)), max(umath.absolute(y))) if step: for ii in range(self.numvect): sleep(0.01) plotxy(y[ii:ii+2], x[ii:ii+2], rangex=[-amp, amp], rangey=[-amp, amp], labx='Real Amplitude', laby='Imaginary Amplitude', color=color, aspect=1.0) else: plotxy(y, x, rangex=[-amp, amp], rangey=[-amp, amp], labx='Real Amplitude', laby='Imaginary Amplitude', color=color, aspect=1.0)
def plotvector(self, vector, amp=None, color='red', device='/XWIN', step=0): """ dftvector.plotvector(vector, amp=None, color='red', device='/XWIN', step=0) Plot 'vector' in the complex plane. """ x = Numeric.zeros(self.numvect+1, 'd') y = Numeric.zeros(self.numvect+1, 'd') x[1:] = vector.real y[1:] = vector.imag if not amp: amp = 1.1 * umath.maximum(max(umath.absolute(x)), max(umath.absolute(y))) if step: for ii in xrange(self.numvect): sleep(0.01) plotxy(y[ii:ii+2], x[ii:ii+2], rangex=[-amp, amp], rangey=[-amp, amp], labx='Real Amplitude', laby='Imaginary Amplitude', color=color, aspect=1.0) else: plotxy(y, x, rangex=[-amp, amp], rangey=[-amp, amp], labx='Real Amplitude', laby='Imaginary Amplitude', color=color, aspect=1.0)
as per a sinusoid with maximum at phase=0 (0 < phase < 1). """ rands = n*Num.random.random(num) indices = rands.astype(Num.int) fracts = rands-indices lo = Num.take(xs, indices) hi = Num.take(xs, indices+1) return fracts*(hi-lo)+lo if __name__ == '__main__': from psr_utils import hist from Pgplot import plotxy, closeplot import time if (0): numtrials = 20 numrandnums = 1000000 for funct in [cosine_rand1, cosine_rand2]: times = [] for jj in range(numtrials): tt = time.clock() funct(numrandnums) times.append(time.clock()-tt) print "Average time = ", Num.add.reduce(Num.asarray(times))/numtrials else: rs = Num.arange(n+1, dtype=Num.float)/n plotxy(xs, rs) closeplot() hist(cosine_rand(10000), 100, color='red') closeplot()
corrvect = add_components(rotate_components(amplitudes, phasecorr)) norm = dv.amplitude() / vector_amplitude(corrvect) dv.plotvector(norm * corrvect, color="blue") dv.plot() closeplot() przw = dv.fitrzw(przw, rzw_phase_model) dv.rzwinfo(przw) phasecorr = dv.rzw_phases(przw) corrvect = add_components(dv.rotate(-phasecorr)) dv.plotvector(corrvect, color="red") amplitudes = Numeric.ones(dv.numvect, 'D') corrvect = add_components(rotate_components(amplitudes, phasecorr)) norm = dv.amplitude() / vector_amplitude(corrvect) dv.plotvector(norm * corrvect, color="blue") dv.plot() closeplot() else: dv = dftvector("/raid/data/Ter5_98/Day1-2/Ter5_1-2_bary_DM243_2600530.000.dftvec") dv.plot(step=0.03) closeplot() plotxy(abs(dv.components), dv.timefract) dv.mask(0.0, 0.33) dv.mask(0.41, 0.51) dv.mask(0.60, 1.01) plotxy(abs(dv.components), dv.timefract, color='red') closeplot() dv.plot(color='red') closeplot() plotxy(dv.phases(), dv.timefract)
norm = dv.amplitude() / vector_amplitude(corrvect) dv.plotvector(norm * corrvect, color="blue") dv.plot() closeplot() przw = dv.fitrzw(przw, rzw_phase_model) dv.rzwinfo(przw) phasecorr = dv.rzw_phases(przw) corrvect = add_components(dv.rotate(-phasecorr)) dv.plotvector(corrvect, color="red") amplitudes = Numeric.ones(dv.numvect, 'D') corrvect = add_components(rotate_components(amplitudes, phasecorr)) norm = dv.amplitude() / vector_amplitude(corrvect) dv.plotvector(norm * corrvect, color="blue") dv.plot() closeplot() else: dv = dftvector( "/raid/data/Ter5_98/Day1-2/Ter5_1-2_bary_DM243_2600530.000.dftvec") dv.plot(step=0.03) closeplot() plotxy(abs(dv.components), dv.timefract) dv.mask(0.0, 0.33) dv.mask(0.41, 0.51) dv.mask(0.60, 1.01) plotxy(abs(dv.components), dv.timefract, color='red') closeplot() dv.plot(color='red') closeplot() plotxy(dv.phases(), dv.timefract)