def analytic_phase(x, t=None, subint=None): """ gets the phase from an amazing variety of signals http://en.wikipedia.org/wiki/Analytic_signal subinterval idea is not debugged and is probably unnecessary may shorten data? """ from scipy.fftpack import hilbert from pyfusion.utils import fix2pi_skips from numpy import zeros, arctan2 # this subinterval idea does not seem necessary and is not debugged if subint != None: subint=powerof2(subint) nsubints = int(len(x)/subint) phs = zeros([nsubints, subint]) for i in range(nsubints): xsub = x[i*subint:(i+1)*subint] phs[i,:] = arctan2(xsub, hilbert(xsub)) phi = phs.flatten() else: y=hilbert(x) # use hilbert twice just to remove DC (lazy) phi = arctan2(y, hilbert(y)) return(fix2pi_skips(phi, sign='+'))
diag_name = 'MP' dev=pyfusion.getDevice("LHD") data=dev.acq.getdata(27233,diag_name) #data.plot_signals() # extract the phi DIrectly from the cfg file Phi = np.array([2*np.pi/360*float(pyfusion.config.get ('Diagnostic:{cn}'. format(cn=c.name), 'Coords_reduced') .split(',')[0]) for c in data.channels]) pl.subplot(121) pl.plot(Phi, linestyle='steps') Phi_circ = fix2pi_skips(np.append(Phi, Phi[0]), around=0) dp = np.diff(Phi_circ) pl.plot(dp, linestyle='steps') pl.figure() pl.subplot(122) phases = [] for N in range(-5, 5): ph = modtwopi(N*dp, offset=0) phases.append(ph) pl.plot(phases[-1], label='N={N}'.format(N=N)) pl.legend() pl.show(block=0) # fake up a clusters file clinds = [[c] for c in np.arange(len(phases))] subset = phases