How to use analyze_frames method in ATX

Best Python code snippet using ATX

analyzeFrames.py

Source:analyzeFrames.py Github

copy

Full Screen

1"""2Analyzes an array of frames using one of these methods: 3intensity, centroid, gauss, or PCA4VARIABLE SET BY SCRIPT:5data RESULTS OF ANALYSIS, SHAPE = (NUMFRAMES,NUMDIMENSIONS)6 WHERE NUMDIMENSIONS IS THE NUMBER OF DIMENSIONS OF DATA7 PRODUCED BY THE ANALYSIS METHOD CHOSE8 9v. 2021 01 2710"""11# here define the array of frames to analyze12analyze_frames = frames13# here define the method of tracking14analyze_method = 'pca' # either 'intensity, 'centroid', 'gauss' or 'pca'15# if pca method is chosen, must define pca principle components here16# if other method, can leave these commented out17analyze_components = [ V[0], V[1], V[2] ]18analyze_meanframe = meanframe19# choose to plot tracking results versus frame number also20scatter_plot = True21full_plot = True22## use below to overide parameter values from common.py23######################################################################24analyze_background = False # set to background to use default25analyze_normalize = normalize # set to normalize to use default26############################################################27############################################################28num_frames = len(analyze_frames)29print( num_frames, 'frames loaded for analysis.')30# subtract background if requested31if analyze_background == True:32 print("Background correction will be applied.")33# now perform tracking depending on method chosen34if analyze_method == 'intensity':35 temp = pa.statframes(analyze_frames, back = analyze_background)36 data = temp[:,0:3]37 ylabel = ['max','min','sum']38elif analyze_method == 'centroid':39 temp = pa.statframes(analyze_frames, back = analyze_background)40 data = temp[:,3:8]41 ylabel = ['<x>','<y>','<xx>','<xy>','<yy>']42elif analyze_method == 'gauss':43 data = pa.fitframes(analyze_frames, back = analyze_background)44 ylabel = ['x','y','sigma','amp','err']45elif analyze_method == 'pca':46# meanframe = track_frames.mean(axis=0)47 data = pa.pcaframes(analyze_frames, analyze_meanframe, analyze_components)48 datadim = data.shape[1]49 ylabel = []50 for i in range(datadim):51 ylabel.append('comp {}'.format(i) )52 53else:54 print("Choose intensity, centroid, gauss or pca method.")55numpoints = len(data)56if numpoints > 0:57 print( analyze_method, 'analysis complete.', numpoints, 'frames processed.')58 print("Means of results:")59 print(data.mean(axis=0))60# create plots61if full_plot == True:62 xlabel = 'frame number'63 plot_title = analyze_method + ' analysis plots'64 pa.makeplot(data, xlabel=xlabel, ylabel=ylabel,title=plot_title)65if scatter_plot == True:66 x, y = data[:,0], data[:,1] 67 xmax, ymax = max(x), max(y)68 xmin, ymin = min(x), min(y)69 xcenter = (xmax+xmin)/2.070 ycenter = (ymax+ymin)/2.071 span = max( xmax-xmin, ymax-ymin )72 left = xcenter - 0.55*span73 right = xcenter + 0.55*span74 bottom = ycenter - 0.55*span75 top = ycenter + 0.55*span76 clrs = np.arange(numpoints)*255.0/numpoints77 figc, axc = plt.subplots(2,2,sharex='col',sharey='row')78 figc.suptitle(analyze_method + ' analysis scatter plot ' )79 axc[1,0].set_aspect(1.0)80 axc[1,0].set_xlim(left,right)81 axc[1,0].set_ylim(top,bottom)82 axc[1,0].scatter(x,y,c=clrs,cmap='prism',marker='.',)83 axc[1,0].grid(True)84 axc[0,0].plot(x,range(numpoints),'b.-')85 axc[1,1].plot(range(numpoints),y,'b.-')86 axc[1,0].set_xlabel('x')87 axc[1,0].set_ylabel('y')88 axc[0,0].set_ylabel('frame number')...

Full Screen

Full Screen

librosa_analysis.py

Source:librosa_analysis.py Github

copy

Full Screen

...10 scipy.spatial.distance.pdist(X.T, metric="cosine"))11 return D[:-1, :-1]12def analyze_file(infile, debug=False):13 y, sr = librosa.load(infile, sr=44100)14 return analyze_frames(y, sr, debug)15def analyze_frames(y, sr, debug=False):16 A = {}17 hop_length = 12818 # First, get the track duration19 A['duration'] = float(len(y)) / sr20 # Then, get the beats21 if debug: print "> beat tracking"22 tempo, beats = librosa.beat.beat_track(y, sr, hop_length=hop_length)23 # Push the last frame as a phantom beat24 A['tempo'] = tempo25 A['beats'] = librosa.frames_to_time(26 beats, sr, hop_length=hop_length).tolist()27 if debug: print "beats count: ", len(A['beats'])28 if debug: print "> spectrogram"29 S = librosa.feature.melspectrogram(y, sr,30 n_fft=2048,31 hop_length=hop_length,32 n_mels=80,33 fmax=8000)34 S = S / S.max()35 # A['spectrogram'] = librosa.logamplitude(librosa.feature.sync(S, beats)**2).T.tolist()36 # Let's make some beat-synchronous mfccs37 if debug: print "> mfcc"38 S = librosa.feature.mfcc(S=librosa.logamplitude(S), n_mfcc=40)39 A['timbres'] = librosa.feature.sync(S, beats).T.tolist()40 if debug: print "timbres count: ", len(A['timbres'])41 # And some chroma42 if debug: print "> chroma"43 S = np.abs(librosa.stft(y, hop_length=hop_length))44 # Grab the harmonic component45 H = librosa.decompose.hpss(S)[0]46 # H = librosa.hpss.hpss_median(S, win_P=31, win_H=31, p=1.0)[0]47 A['chroma'] = librosa.feature.sync(librosa.feature.chromagram(S=H, sr=sr),48 beats,49 aggregate=np.median).T.tolist()50 # Relative loudness51 S = S / S.max()52 S = S**253 if debug: print "> dists"54 dists = structure(np.vstack([np.array(A['timbres']).T, np.array(A['chroma']).T]))55 A['dense_dist'] = dists56 edge_lens = [A["beats"][i] - A["beats"][i - 1]57 for i in xrange(1, len(A["beats"]))]58 A["avg_beat_duration"] = np.mean(edge_lens)59 A["med_beat_duration"] = np.median(edge_lens)60 return A61if __name__ == '__main__':62 import sys63 from radiotool.composer import Song64 song = Song(sys.argv[1], cache_dir=None)65 frames = song.all_as_mono()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful