def GridPlots(curr_id, res): rad = MakeRad(res) fname_band = './dat/' + curr_id + '/Del/Plots/Bands/' + curr_id + '_del_subbands' max_x = 0 max_y = 0 dpi_in = 400 for i in rad: curr_fband = fname_band + '_r{:0.4f}'.format(i) curr_fband = curr_fband + '_dpi' + str(dpi_in) + '.png' cur_x = Image.open(curr_fband).size[0] cur_y = Image.open(curr_fband).size[1] if cur_x > max_x: max_x = cur_x if cur_y > max_y: max_y = cur_y print 'max (x,y) = ({:d},{:d})'.format(max_x,max_y) blank_img = Image.new("RGB", (len(rad) * max_x, max_y), "white") for i in range(len(rad)): cur_x = i * max_x curr_fband = fname_band + '_r{:0.4f}'.format(rad[i]) curr_fband = curr_fband + '_dpi' + str(dpi_in) + '.png' print 'pasting ' + curr_fband blank_img.paste(Image.open(curr_fband), (cur_x, 0)) out_img = './dat/' + curr_id + '/Del/Plots/' + curr_id + '_del_grid_dpi' + str(dpi_in) + '.png' ensure_dir(out_img) blank_img.save(out_img)
def GetNNStatsMany(main_id, min, max): folder = './dat/' + main_id + '/' fname = main_id + 'stats_NN.csv' fout = folder + fname ensure_dir(fout) with open(fout,'w') as f: for i in range(min, max): curr_id = main_id + str(i) [n_s, n_c, r_c, coords] = read(curr_id) stats = GetNNStatsIndiv(curr_id, n_s, n_c, r_c, coords) for s in stats: print s f.write(str(s)) f.write(',') f.write('\n') f.close()
def PlotSk(curr_id): [n_s, n_c, r_c, coords] = readcenters.read(curr_id) print 'plotting Sk...' plt.figure(figsize=(12.0,4.0)) for i in range(0,n_s): fname = './dat/' + curr_id + '/Sk/' + curr_id + '_Sk_' + str(i) + '.txt' [k, Sk] = ReadSk(fname) axes_indiv = plt.subplot(1, n_s + 2, i+1) FormatPlotSk(axes_indiv, 'species {:d}'.format(i)) [popt, pcov, fit_k, fit_Sk] = FitSk(k,Sk) PlotSkFit(popt, pcov, fit_k, fit_Sk, axes_indiv) plt.loglog(k,Sk) # run for all fname = './dat/' + curr_id + '/Sk/' + curr_id + '_Sk_T.txt' [k, Sk] = ReadSk(fname) axes_combined = plt.subplot(1, n_s + 2, n_s+1) FormatPlotSk(axes_combined, 'all species') [popt, pcov, fit_k, fit_Sk] = FitSk(k,Sk) PlotSkFit(popt, pcov, fit_k, fit_Sk, axes_combined) plt.loglog(k,Sk) # run for delaunay fname = './dat/' + curr_id + '/Sk/' + curr_id + '_Sk_del.txt' [k, Sk] = ReadSk(fname) axes_delaunay = plt.subplot(1, n_s + 2, n_s+2) FormatPlotSk(axes_delaunay, 'delaunay') [popt, pcov, fit_k, fit_Sk] = FitSk(k,Sk) PlotSkFit(popt, pcov, fit_k, fit_Sk, axes_delaunay) plt.loglog(k,Sk) fname = curr_id + '_Sk.eps' fout = './dat/' + curr_id + '/Plots/' + fname ensure_dir(fout) plt.suptitle('structure factor, S(k)', fontsize=12) plt.savefig(fout, bbox_inches=0, dpi = 300)
def PlotCenters(curr_id, n_s, n_c, r_c, coords): print 'plotting centers...' plt.figure(figsize=(12.0,4.0)) axes_combined = plt.subplot(1, n_s + 1, n_s+1) axes_combined.grid() plt.axis('scaled') plt.axis([0,1,0,1]) plt.xlabel('x') plt.ylabel('y') plt.title('all species') jet = cm = plt.get_cmap('jet') cNorm = colors.Normalize(vmin=0, vmax=n_s) scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet) for i in range(0,n_s): rad = r_c[i] axes_indiv = plt.subplot(1, n_s + 1, i+1) axes_indiv.grid() colorVal = scalarMap.to_rgba(i) for j in range(n_c[i]): x = coords[i][j][0] y = coords[i][j][1] my_circle_scatter(axes_indiv, [x], [y], radius=rad, alpha=0.5, color=colorVal) my_circle_scatter(axes_combined, [x], [y], radius=rad, alpha=0.5, color=colorVal) plt.axis('scaled') plt.axis([0,1,0,1]) plt.xlabel('x') plt.ylabel('y') plt.title('species {:d}, rad {:0.4f}'.format(i,rad)) fname = curr_id + '_centers.eps' fout = './dat/' + curr_id + '/Plots/' + fname ensure_dir(fout) plt.suptitle('centers', fontsize=12) plt.savefig(fout, bbox_inches=0, dpi = 300)
def GridPlots2(curr_id, res): min = 0 max = 0.5 inc = 0.05 dpi = 400 rad = [i * inc for i in range(0, int(max/inc)+1)] fname_out = './dat/' + curr_id + '/Download/' + curr_id + '_out' fname_band = './dat/' + curr_id + '/Plots/Bands/' + curr_id + '_subbands' max_x = 0 max_y = 0 dpi_in = 400 for r in rad: if r == 0: continue curr_fband = fname_band + '_r{:0.4f}'.format(r) curr_fband = curr_fband + '_dpi' + str(dpi_in) + '.png' cur_x = Image.open(curr_fband).size[0] cur_y = Image.open(curr_fband).size[1] if cur_x > max_x: max_x = cur_x if cur_y > max_y: max_y = cur_y print 'max (x,y) = ({:d},{:d})'.format(max_x,max_y) blank_img = Image.new("RGB", (len(rad) * max_x, max_y), "white") for i in range(len(rad)): if rad[i]==0: continue cur_x = i * max_x curr_fband = fname_band + '_r{:0.4f}'.format(rad[i]) curr_fband = curr_fband + '_dpi' + str(dpi_in) + '.png' print 'pasting ' + curr_fband blank_img.paste(Image.open(curr_fband), (cur_x, 0)) out_img = './dat/' + curr_id + '/Plots/' + curr_id + 'grid_dpi' + str(dpi_in) + '.png' ensure_dir(out_img) blank_img.save(out_img)
def CalcSk(curr_id): fout_Sk = './dat/' + curr_id + '/Sk/' + curr_id + '_Sk_' ensure_dir(fout_Sk) [n_s, n_c, r_c, coords] = readcenters.read(curr_id) N = 0 for i in range(0,n_s): N += n_c[i] total_in = [maxx, maxy, N] for i in range(0,n_s): inputs = [maxx, maxy, n_c[i]] for j in range(0,n_c[i]): tmpx = coords[i][j][0] tmpy = coords[i][j][1] inputs.extend( [ tmpx, tmpy ] ) total_in.extend( [ tmpx, tmpy ] ) outname = fout_Sk + str(i) + '.txt' RunSk(inputs, outname) outname = fout_Sk + 'T.txt' RunSk(total_in, outname) del_fin = './dat/' + curr_id + '/Del/' + curr_id + '_del_T.txt' del_data = list(csv.reader( open(del_fin, 'rb') , delimiter = '\t' )) del_in = [maxx, maxy, len(del_data)] for i in range( len(del_data) ): tmpx = float(del_data[i][0]) tmpy = float(del_data[i][1]) del_in.extend( [tmpx, tmpy] ) outname = fout_Sk + 'del.txt' RunSk(del_in,outname)
def GridPlots(curr_id, res, n_s): min = 0 max = 0.5 inc = 0.05 dpi = 400 rad = [i * inc for i in range(0, int(max/inc)+1)] fname_band = './dat/' + curr_id + '/Plots/Bands/' + curr_id + '_subbands' max_x = 0 max_y = 0 for i in rad: for j in rad: curr_fband = fname_band + '_r{:0.4f}_r{:0.4f}'.format(i,j) curr_fband = curr_fband + '_dpi' + str(dpi) + '.png' cur_x = Image.open(curr_fband).size[0] cur_y = Image.open(curr_fband).size[1] if cur_x > max_x: max_x = cur_x if cur_y > max_y: max_y = cur_y print 'max (x,y) = ({:d},{:d})'.format(max_x,max_y) blank_img = Image.new("RGB", (len(rad) * max_x, len(rad) * max_y), "white") for i in range(len(rad)): for j in range(len(rad)): cur_x = i * max_x cur_y = j * max_y curr_fband = fname_band + '_r{:0.4f}_r{:0.4f}'.format(rad[i],rad[j]) curr_fband = curr_fband + '_dpi' + str(dpi) + '.png' print 'pasting ' + curr_fband blank_img.paste(Image.open(curr_fband), (cur_x, cur_y)) out_img = './dat/' + curr_id + '/Plots/' + curr_id + 'grid_dpi' + str(dpi) + '.png' ensure_dir(out_img) blank_img.save(out_img)
def GetNNStatsDelMany(main_id, min, max): folder = './dat/' + main_id + '/' fname = main_id + 'stats_NN_del.csv' fout = folder + fname ensure_dir(fout) with open(fout,'w') as f: for i in range(min, max): curr_id = main_id + str(i) stats = GetNNStatsDelIndiv(curr_id) for s in stats: print s f.write(str(s)) f.write(',') f.write('\n') f.close()
def CalcBands(curr_id, res): print 'calculating bands...' rad = MakeRad(1) fname_out = './dat/' + curr_id + '/Del/Download/' + curr_id + '_out' fname_band = './dat/' + curr_id + '/Del/' + curr_id + '_del_bands.csv' ensure_dir(fname_band) initiate = 0 if not os.path.exists(fname_band): lines = [[]] lines[0].append('rad') numrows = 0 numcols = 0 numbands_i = 0 initiate = 1 for r in rad: cur_fout = fname_out + '_r{:0.4f}'.format(float(r)) + '.OUT' print 'opening file ' + cur_fout print 'adding bands for', print r if not initiate: lines = list(csv.reader( open(fname_band, 'rb') , delimiter = '\t' )) lines = [line[0].split(',') for line in lines] numrows = len(lines) numcols = len(lines[0]) numbands_i = ((numcols-2)+1)/3 cur_row = numrows print('(rows,cols,bands) = {:d}, {:d}, {:d}'.format(numrows,numcols,numbands_i)) print 'checking if already in file...' changerad = 0 for row in range(1,numrows): print '(cur, new) = ', cur_rad = float('{:0.4f}'.format(float(lines[row][0]))) my_rad = float('{:0.4f}'.format(float(r))) print cur_rad, print ',', print my_rad if(cur_rad == my_rad): print('ALREADY IN FILE') changerad = 1 break if(changerad): continue tmp_bands = 'tmp_bands.del' tmp_bands2 = 'tmp.del' cmd0 = 'cat ' + cur_fout + ' | grep -i \"Range\" > ' + tmp_bands2 cmd1 = 'awk \'{print $4, $10}\' tmp.del > ' + tmp_bands os.system(cmd0) os.system(cmd1) # write all band lines to cur_line cur_line = [] with open(tmp_bands,'r') as fin_bands: bands = [band.split() for band in fin_bands] numbands_f = len(bands) print 'num bands...' + str(numbands_f) # first write all radii cur_line.append(r) prv_lo = 0.0 prv_hi = 0.0 for band in bands: cur_lo = float(band[0]) cur_hi = float(band[1]) if(cur_lo > prv_hi): gap = cur_lo - prv_hi midfreq = (cur_lo + prv_hi)/2 normgap = gap/midfreq else: normgap = 0 if(cur_lo>0): cur_line.append(normgap) cur_line.append(cur_lo) cur_line.append(cur_hi) prv_lo = cur_lo prv_hi = cur_hi cmd0 = 'rm ' + tmp_bands2 cmd1 = 'rm ' + tmp_bands os.system(cmd0) os.system(cmd1) lines.append(cur_line) # add band numbers to topline if exceed existing if(initiate): print 'initating bands' lines[0].append('1L') lines[0].append('1H') for i in range(2,numbands_f+1): col1 = '{:d}to{:d}'.format(i-1,i) col2 = '{:d}L'.format(i) col3 = '{:d}H'.format(i) lines[0].extend([col1,col2,col3]) initiate = 0 elif(numbands_f > numbands_i): print 'adding new bands' for i in range(numbands_i+1,numbands_f+1): col1 = '{:d}to{:d}'.format(i-1,i) col2 = '{:d}L'.format(i) col3 = '{:d}H'.format(i) lines[0].extend([col1,col2,col3]) with open(fname_band, 'w') as f: for line in lines: for el in line: f.write('%s,' % el) f.write('\n') f.close() cur_row = numrows + 1
def PlotSomeBands(curr_id, res, subbands): print 'plotting bands...' rad = MakeRad(res) fname_out = './dat/' + curr_id + '/Del/Download/' + curr_id + '_out' fname_band = './dat/' + curr_id + '/Del/Plots/Bands/' + curr_id + '_del_subbands' ensure_dir(fname_band) min = 0.15 max = 0.60 dpi_in = 400 jet = cm = plt.get_cmap('jet') cNorm = colors.Normalize(vmin=0, vmax=len(subbands)) scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet) for r in rad: curr_fout = fname_out + '_r{:0.4f}.OUT'.format(float(r)) curr_fband = fname_band + '_r{:0.4f}'.format(float(r)) + '_dpi' + str(dpi_in) + '.png' print 'plotting bands for ' + curr_fout tmp_bands = 'tmp_bands.del' tmp_bands2 = 'tmp.del' cmd0 = 'cat ' + curr_fout + ' | grep -i \"Range\" > ' + tmp_bands2 cmd1 = 'awk \'{print $4, $10}\' tmp.del > ' + tmp_bands os.system(cmd0) os.system(cmd1) fig = plt.figure(figsize=(10,10)) ax = fig.gca() ax.set_aspect(5) ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') plt.xticks([]) plt.yticks([0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6]) plt.tick_params(axis='y', which='major', labelsize=2) plt.tick_params(axis='x', which='major', labelsize=0) plt.tick_params(axis='both', which='minor', labelsize=0) plt.setp(ax.get_xticklabels(), visible=False) with open(tmp_bands,'r') as fin_bands: bands = [b.split() for b in fin_bands] for i in range(len(subbands)): colorVal = scalarMap.to_rgba(i) print int(subbands[i-1])+1, cur_hi = float(bands[int(subbands[i-1])][1]) nxt_lo = float(bands[int(subbands[i-1])+1][0]) print cur_hi, print ',', print nxt_lo, if(nxt_lo > cur_hi): print 'gap!' plt.vlines(0, cur_hi, nxt_lo, color=colorVal, linewidths = 100) print '\n' cmd0 = 'rm ' + tmp_bands cmd1 = 'rm ' + tmp_bands2 #os.system(cmd0) #os.system(cmd1) plt.axis([-0.1,0.1,min,max]) ax.yaxis.labelpad = -1 ax.text(0.5,0.97,r, horizontalalignment='center', transform=ax.transAxes) # plt.text(0,5.05,fname_out,size='8',horizontalalignment='center') plt.savefig(curr_fband, format='png', dpi=dpi_in, bbox_inches='tight')
def GetNN(curr_id, n_s, n_c, r_c, coords): print 'getting nearest neighbor information...' plt.figure(figsize=(12.0,4.0)) # do species first for i in range(0,n_s): NN_sp = [] for j in range(0, n_c[i]): curr_nbr = [] pos1 = coords[i][j] for l in range(0 , n_c[i]): if (l == j): continue pos2 = coords[i][l] dist = GetDist(pos1,pos2) curr_nbr.append(dist) tmp_a = np.array(curr_nbr) min = np.min(tmp_a) NN_sp.append(min) axes_indiv = plt.subplot(1, n_s + 1, i+1) axes_indiv.grid() plt.title('species {:d}'.format(i)) tmp_a = np.array(NN_sp) N = len(NN_sp) y,binEdges=np.histogram(NN_sp,bins=N**0.5) bincenters = 0.5*(binEdges[1:]+binEdges[:-1]) pyl.plot(bincenters,y,'-', color='r') plt.hist(NN_sp, bins=int(N**0.5)) mean = np.mean(tmp_a) med = np.median(tmp_a) std = np.std(tmp_a) stats = 'N = {:d}\n\ mean = {:0.4f}\n\ med = {:0.4f}\n\ std = {:0.4f}'.format(N,mean,med,std) plt.text(0.8, 0.8, stats, horizontalalignment='right', verticalalignment='center', transform=axes_indiv.transAxes) NN_all = [] for i in range(0,n_s): for k in range(0, n_c[i]): curr_nbr = [] pos1 = coords[i][k] for j in range(0,n_s): for l in range(0, n_c[j]): if (i==j and k==l): continue pos2 = coords[j][l] dist = GetDist(pos1,pos2) curr_nbr.append(dist) tmp_a = np.array(curr_nbr) min = np.min(tmp_a) NN_all.append(min) axes_combined = plt.subplot(1, n_s + 1, n_s+1) axes_combined.grid() plt.title('all species') tmp_a = np.array(NN_all) N = len(NN_all) y,binEdges=np.histogram(NN_all,bins=N**0.5) bincenters = 0.5*(binEdges[1:]+binEdges[:-1]) pyl.plot(bincenters,y,'-',color='r') plt.hist(NN_all, bins=N**0.5) mean = np.mean(tmp_a) med = np.median(tmp_a) std = np.std(tmp_a) stats = 'N = {:d}\n\ mean = {:0.4f}\n\ med = {:0.4f}\n\ std = {:0.4f}'.format(N,mean,med,std) plt.text(0.8, 0.8, stats, horizontalalignment='right', verticalalignment='center', transform=axes_combined.transAxes) fname = curr_id + '_NN.eps' fout = './dat/' + curr_id + '/Plots/' + fname ensure_dir(fout) plt.suptitle('nearest neighbor distribution', fontsize=12) plt.savefig(fout, bbox_inches=0, dpi = 300)
def CalcBands(curr_id, res, n_s): print 'calculating bands...' rad = tm.MakeRad(res, n_s) fname_out = './dat/' + curr_id + '/Download/' + curr_id + '_out' fname_band = './dat/' + curr_id + '/' + curr_id + '_bands.csv' ensure_dir(fname_band) initiate = 0 if not os.path.exists(fname_band): lines = [[]] for i in range(n_s): lines[0].append('r' + str(i)) numrows = 0 numcols = 0 numbands_i = 0 initiate = 1 for r in rad: cur_fout = fname_out for i in range(0, n_s): cur_fout += '_r{:0.4f}'.format(float(r[i])) cur_fout += '.OUT' print 'opening file ' + cur_fout print 'adding bands for', print r if not initiate: lines = list(csv.reader( open(fname_band, 'rb') , delimiter = '\t' )) lines = [line[0].split(',') for line in lines] numrows = len(lines) numcols = len(lines[0]) numbands_i = ((numcols-2)+1)/3 cur_row = numrows print('(rows,cols,bands) = {:d}, {:d}, {:d}'.format(numrows,numcols,numbands_i)) print 'checking if already in file...' changerad = 0 for row in range(1,numrows): checknum = 0 print '(cur, new) = ', print [ float(i) for i in lines[row][0:n_s] ], print r for c in range(n_s): cur_rad = float('{:0.4f}'.format(float(lines[row][c]))) my_rad = float('{:0.4f}'.format(float(r[c]))) if(cur_rad != my_rad): break checknum = checknum + 1 if(checknum == n_s): print('ALREADY IN FILE') changerad = 1 break if(changerad): break
def PlotBands(curr_id, res, n_s): print 'plotting bands...' rad = tm.MakeRad(res, n_s) fname_out = './dat/' + curr_id + '/Download/' + curr_id + '_out' fname_band = './dat/' + curr_id + '/Plots/Bands/' + curr_id + '_bands' ensure_dir(fname_band) for r in rad: curr_fout = fname_out curr_fband = fname_band for i in range(0, n_s): curr_fout += '_r{:0.4f}'.format(float(r[i])) curr_fband += '_r{:0.4f}'.format(float(r[i])) curr_fout += '.OUT' curr_fband += '.png' print 'plotting bands for ' + curr_fout tmp_bands = 'tmp_bands.del' tmp_bands2 = 'tmp.del' cmd0 = 'cat ' + curr_fout + ' | grep -i \"Range\" > ' + tmp_bands2 cmd1 = 'awk \'{print $4, $10}\' tmp.del > ' + tmp_bands os.system(cmd0) os.system(cmd1) fig = plt.figure(figsize=(10,10)) ax = fig.gca() ax.set_aspect(5) ax.xaxis.set_ticks_position('none') plt.tick_params(axis='y', which='major', labelsize=8) plt.tick_params(axis='x', which='major', labelsize=0) plt.tick_params(axis='both', which='minor', labelsize=0) plt.setp(ax.get_xticklabels(), visible=False) with open(tmp_bands,'r') as fin_bands: bands = [band.split() for band in fin_bands] numbands_f = len(bands) print 'num bands...' + str(numbands_f) prv_lo = 0.0 prv_hi = 0.0 for band in bands: cur_lo = float(band[0]) cur_hi = float(band[1]) #print '(lo, hi) = ({:0.4f}, {:0.4f})'.format(cur_lo, cur_hi) if(cur_lo > prv_hi): plt.vlines(0, prv_hi, cur_lo, color='r', linewidths = 4) prv_lo = cur_lo prv_hi = cur_hi cmd0 = 'rm ' + tmp_bands cmd1 = 'rm ' + tmp_bands2 os.system(cmd0) os.system(cmd1) plt.axis([-0.25,0.25,0,1]) # plt.text(0,5.05,fname_out,size='8',horizontalalignment='center') plt.title(r) plt.savefig(curr_fband, format='png', dpi=300, bbox_inches='tight')