if oldDAfilename != DAfilename: 1 / 0 # create an error to force reload print("Using old data") except: print("loading {f}".format(f=DAfilename)) da = DA(DAfilename) oldDAfilename = DAfilename da.extract(locals(), "shot,phases,beta,freq,frlow,frhigh,t_mid,amp,a12") print("loading {f}".format(f=clusterfile)) x = np.load(clusterfile) for k in x.keys(): exec("{v}=x['{k}']".format(v=k, k=k)) start_mem = report_mem(msg="cluster_phases") w5 = np.where((dists(subset[clinds[cl][0]], phases[:, sel]) < d_big) & (bw(freq, frlow, frhigh)) & (shot == shot))[0] print(len(w5), len(unique(shot[w5]))) ph5 = phases[w5] wc = np.where(dists(subset[clinds[cl][0]], ph5[:, sel]) < d_med)[0] wcc = np.where(dists(subset[clinds[cl][0]], ph5[:, sel]) < d_sml)[0] sl_red = compact_str(np.unique(shot[w5[wcc]])) sl_green = compact_str(np.unique(shot[w5[wc]])) titl = "red:d<{d_sml:.1g}:{slr}".format(slr=sl_red, d_sml=d_sml) suptitl = "green:d<{d_med:.1g}:{slr}".format(slr=sl_green, d_med=d_med) pl.figure(num="cl[{cl}] delta phase".format(cl=cl)) if clearfigs: pl.clf() for (i, ph) in enumerate(decimate(ph5, limit=1000)):
1 / 0 # create an error to force reload print('Using old data') except: print('loading {f}'.format(f=DAfilename)) da = DA(DAfilename) oldDAfilename = DAfilename da.extract(locals(), 'shot,phases,beta,freq,frlow,frhigh,t_mid,amp,a12') print('loading {f}'.format(f=clusterfile)) x = np.load(clusterfile) for k in x.keys(): exec("{v}=x['{k}']".format(v=k, k=k)) start_mem = report_mem(msg='cluster_phases') w5 = np.where((dists(subset[clinds[cl][0]], phases[:, sel]) < d_big) & (bw(freq, frlow, frhigh)) & (shot == shot))[0] print(len(w5), len(unique(shot[w5]))) ph5 = phases[w5] wc = np.where(dists(subset[clinds[cl][0]], ph5[:, sel]) < d_med)[0] wcc = np.where(dists(subset[clinds[cl][0]], ph5[:, sel]) < d_sml)[0] sl_red = compact_str(np.unique(shot[w5[wcc]])) sl_green = compact_str(np.unique(shot[w5[wc]])) titl = 'red:d<{d_sml:.1g}:{slr}'.format(slr=sl_red, d_sml=d_sml) suptitl = 'green:d<{d_med:.1g}:{slr}'.format(slr=sl_green, d_med=d_med) pl.figure(num='cl[{cl}] delta phase'.format(cl=cl)) if clearfigs: pl.clf() for (i, ph) in enumerate(decimate(ph5, limit=1000)): pl.plot(ph[sel], 'k', linewidth=.03, hold=i > 0)
# this contrivance allows us to test on uniformly distributed phases if uniform_random is not None: print('evaluating {ur}'.format(ur=uniform_random)) phases = eval(uniform_random) shot = np.array(np.shape(phases)[0]*[shot[0]]) freq = np.array(np.shape(phases)[0]*[freq[0]]) frlow = np.array(np.shape(phases)[0]*[0]) frhigh = np.array(np.shape(phases)[0]*[9e9]) t_mid = np.array(np.shape(phases)[0]*[t_mid[-1]]) cc5 = [] # cluster centres for cl in cls: start_mem = report_mem(msg='cluster_phases') # used to where all at once - but as the distance is most expensive, do # shot and freq first w5_shot_freq = np.where((bw(freq,frlow,frhigh)) & (shot==shot))[0]; print(len(w5_shot_freq),len(np.unique(shot[w5_shot_freq]))) # the [:,sel] below is to avoid gather ops on two indices at once. w5=np.where(dists(subset[clinds[cl][0]], phases[w5_shot_freq][:,sel])<d_big)[0]; w5 = w5_shot_freq[w5] # refer back to the original array # old "all at once" way # w5=np.where((dists(subset[clinds[cl][0]], phases[:,sel])<d_big) & (bw(freq,frlow,frhigh)) & (shot==shot))[0]; print(len(w5),len(np.unique(shot[w5]))) print(len(w5),len(np.unique(shot[w5]))) ph5=phases[w5] wc=np.where(dists(subset[clinds[cl][0]], ph5[:,sel])<d_med)[0] if len(wc)<1: raise ValueError('no points within avg radians of {dm} '.format(dm = d_med)) wcc=np.where(dists(subset[clinds[cl][0]], ph5[:,sel])<d_sml)[0] sl_red = compact_str(np.unique(shot[w5[wcc]])) sl_green = compact_str(np.unique(shot[w5[wc]])) xlab='clind {cl}: {f}'.format(f=da.name, cl=cl)