def main(): with open("./data/shape-%s/%s%s%sbox-plot--%s-%s-%s-%s-%s-%s.dat"%(load.f_shape,load.debug_str,load.hires_str,load.slice_str,load.f_shape,load.f_param1,load.f_param2,load.f_param3,load.f_param4,load.f_param5),"r") as boxData: fileLines = boxData.readlines() #get number of boxes and protein types. little hokey but it works. in boxData.readlines(), there is exactly one '\n' newline string #for each protein type block. therefor, the number of protein types is equal to the number of times "\n" appears by itself in the list. numProteinTypes = len([line for line in fileLines if line=="\n"]) numNewLines = numProteinTypes #it follows that the total number of lines in the data file, minus the number of blank lines in the data file, is equal to #the number of protein types * the number of box types. divide by number of protein types to get number of box types. numBoxes = (len(fileLines) - numNewLines)/numProteinTypes #grab the names of the proteins used, and the names of the boxes proteinTypeList = [] boxList = [] for line in fileLines: if (line != "\n"): proteinTypeList += [line.split("\t")[0]] boxList += [line.split("\t")[1]] #prune duplicates proteinTypeList = list(set(proteinTypeList)) boxList = list(set(boxList)) #generate list of proteinType and box combinations to feed into stackData plotNameList_D = [] plotNameList_E = [] numProteinTypes_D = 0 numProteinTypes_E = 0 for box in boxList: for proteinType in proteinTypeList: if "D_" in proteinType: plotNameList_D += ["%s-%s"%(box,proteinType)] if "E_" in proteinType: plotNameList_E += ["%s-%s"%(box,proteinType)] #print "" #print "plotNameList before ", plotNameList_D, "\n" new_plotNameList_D = [0]*len(plotNameList_D) P_Ord = [3,0,2,1,7,4,6,5,11,8,10,9] if load.f_param4 == '97.00': P_Ord = [3,0,2,1,11,8,10,9,15,12,14,13,7,4,6,5] if load.f_param4 == '96.00': P_Ord = [15,12,14,13,3,0,2,1,7,4,6,5,11,8,10,9] for i in range(len(P_Ord)): new_plotNameList_D[i] = plotNameList_D[P_Ord[i]] for i in range(len(plotNameList_D)): plotNameList_D[i] = new_plotNameList_D[i] #print "plotNameList after ",plotNameList_D,"\n" plotProteinLabels = ['MinD:ATP (cyto)','MinD:ATP (mem)','MinE:MinD:ATP','MinD:ADP (cyto)'] #pass plotNameList through stackData to generate the list of line data to be plotted plotCurveList_D = stackData(plotNameList_D) plotCurveList_E = stackData(plotNameList_E) #get a time axis for the plot from the length of one of the data sets we have difD = 2.5 # (um)^2 s^- 1 time_step = .1*load.dx*load.dx/difD #sec print_denominator = 1000 #This is from the c++ I wanted to format things the same here. box_time_step = time_step*print_denominator timeAxis = np.linspace(0,box_time_step*len(plotCurveList_D[0]),len(plotCurveList_D[0])) #begin messy code (to deal with matplotlib) - don't judge me start_time_as_frac_of_ten = float(load.f_param6) end_time_as_frac_of_ten = float(load.f_param7) tot_time = len(plotCurveList_D[0])*box_time_step start = int(tot_time*start_time_as_frac_of_ten/10.0/box_time_step) end = int(tot_time*end_time_as_frac_of_ten/10.0/box_time_step) (start, end) = find_period(plotCurveList_D[len(plotCurveList_D)-2]) (start, end) = find_period(np.array(returnData(boxList[len(boxList)-1], 'D_ND'))) # print useful coordination data period = timeAxis[end-1] - timeAxis[start] print 'period is', period firsttime = timeAxis[start] while firsttime > 9*period: firsttime -= period print 'early start time is', firsttime print 'and end time is ',firsttime+period print 'and file numbers are', firsttime*2, 'and', (firsttime+period)*2 # now offset time so it starts at zero timeAxis = timeAxis - timeAxis[start] if load.f_param4 == '97.00' or (load.f_shape == 'triangle' and load.f_param3 == '6.01'): if load.f_param4 == '97.00': start_time_as_frac_of_ten = 0 end_time_as_frac_of_ten = 2.3 if load.f_shape == 'triangle' and load.f_param3 == '6.01': start_time_as_frac_of_ten = 5.00 end_time_as_frac_of_ten = 9.00 start = int(tot_time*start_time_as_frac_of_ten/10.0/box_time_step) end = int(tot_time*end_time_as_frac_of_ten/10.0/box_time_step) #print set(plotCurveList_D[1]).union(set(plotCurveList_D[2])) #get num on each plot for proteinType in proteinTypeList: if "D_" in proteinType: numProteinTypes_D += 1 if "E_" in proteinType: numProteinTypes_E +=1 #plot scales. colors limited for now. colorScale = ["b","g","r","c","m","y"] alphaScale_D = [n/numProteinTypes for n in range(1,numProteinTypes_D+1)] alphaScale_E = [n/numProteinTypes for n in range(1,numProteinTypes_E+1)] #generate the plot #f, (bax,sectionax) = plt.subplots(1, 2) bax = plt.subplot2grid((2,5), (0,0), colspan=4, rowspan=2) sectionax = plt.subplot2grid((2,5), (0,4), colspan=1,rowspan=2) # first plot the section data... sectiondata = np.loadtxt("data/shape-%s/membrane_files/%s%s%ssections-%s-%s-%s-%s-%s-%s.dat" % (load.f_shape,load.debug_str,load.hires_str,load.slice_str,load.f_shape, load.f_param1,load.f_param2,load.f_param3,load.f_param4,load.f_param5)) def plot_sections(sectionax, sectiondata): dx = load.dx x = np.arange(sectiondata.shape[1]*1.0)*dx y = np.arange(sectiondata.shape[0]*1.0)*dx X,Y = np.meshgrid(x,y) inmembrane = np.zeros_like(sectiondata) inmembrane[sectiondata>0] = 1.0 xmax = X[sectiondata>0].max() xmin = X[sectiondata>0].min() ymax = Y[sectiondata>0].max() ymin = Y[sectiondata>0].min() ymean = (Y*inmembrane).sum()/inmembrane.sum() xmean = (X*inmembrane).sum()/inmembrane.sum() yweighted = (Y*sectiondata).sum()/sectiondata.sum() xweighted = (X*sectiondata).sum()/sectiondata.sum() levels = [0.5, 1.5, 2.5, 3.5, 4.5] mycolors = ["w","g","r","m","c","y"] for i in xrange(min(4, len(boxList))): if boxList[i] == 'Right': mycolors[1] = colorScale[i] if boxList[i] == 'Mid': mycolors[2] = colorScale[i] if boxList[i] == 'Left': mycolors[3] = colorScale[i] mycolors = colorScale[1:] if load.f_param4 == '97.00': mycolors = ['g','r','m','c'] if load.f_param4 == '96.00': #rightup = 2, rightdown = 1, leftup = 4, leftdown = 3 mycolors = ['g','r','c','m'] #print mycolors # here we rotate so that the order of sections will match the # box plot. xdir, ydir = xweighted - xmean, yweighted - ymean xdir, ydir = xdir/np.sqrt(xdir**2+ydir**2), ydir/np.sqrt(xdir**2+ydir**2) extraxspace = .5 extrayspace = 0 Yrotated = X*xdir + Y*ydir Xrotated = X*ydir - Y*xdir sectionax.contourf(Xrotated, Yrotated, sectiondata, levels=levels, colors=mycolors) xmin = Xrotated[sectiondata>0].min() xmax = Xrotated[sectiondata>0].max() ymin = Yrotated[sectiondata>0].min() ymax = Yrotated[sectiondata>0].max() sectionax.set_xlim(xmin-extraxspace, xmax) sectionax.set_ylim(ymin-extrayspace, ymax) sectionax.set_aspect('equal') sectionax.set_frame_on(False) sectionax.axes.get_xaxis().set_visible(False) sectionax.axes.get_yaxis().set_visible(False) sectionax.add_artist(AnchoredSizeBar( sectionax.transData, 1.00, # length of the bar in the data reference "1$\mu$", # label of the bar #bbox_to_anchor=(0.,0.,1.,1.), loc=8, # 'best', # location (lower right) pad=-(ymax-ymin)/2.0 + 0.4, borderpad=0.25, sep=3, frameon=False )) plot_sections(sectionax, sectiondata) section_names = ['Bottom Section','Center Section','Top Section'] if load.f_param4 == '97.00': section_names = ['Lower Section','Middle Left Section','Middle Right Section','Upper Section'] # section_names = ['rightup','mid','left','rightdown'] if load.f_param4 == '96.00': section_names = ['Lower Left Section','Lower Right Section','Upper Left Section','Upper Right Section'] # section_names = ['rightdown','rightup','leftdown','leftup'] font=FontProperties() font.set_family('serif') text_adjust = -.2*box_time_step*(end-start) j=0 k=0 for i in range(len(plotCurveList_D[:,0])): if i%(numProteinTypes_D)==0: j+=1 k=0 if i==0: bax.plot(timeAxis[start:end], plotCurveList_D[i, start:end], color=colorScale[j],alpha=alphaScale_D[k]) y_text_label = i*.8/len(plotCurveList_D[:,0]) + .1*np.floor(i/numProteinTypes_D) if load.f_param4 == '97.00' or load.f_param4 == '96.00': y_text_label = i*.8/len(plotCurveList_D[:,0]) + .07*np.floor(i/numProteinTypes_D) y_label = (plotCurveList_D[i, start+int(1/box_time_step)])/2.0 bax.annotate('%s'%plotProteinLabels[i],xy=(1,y_label),xytext=(text_adjust,y_text_label), fontsize=7, fontproperties=font, arrowprops=dict(facecolor='black',shrink=0.05, width=.3, headwidth=5.)) bax.fill_between(timeAxis[start:end], [0 for x in range(len(timeAxis))[start:end]], plotCurveList_D[i, start:end], alpha=alphaScale_D[k],facecolor=colorScale[j]) elif i!=0: bax.plot(timeAxis[start:end], plotCurveList_D[i,start:end], color=colorScale[j],alpha=alphaScale_D[k]) y_text_label = i*.8/len(plotCurveList_D[:,0]) + .1*np.floor(i/numProteinTypes_D) y_label = (plotCurveList_D[i, start+int(1/box_time_step)] + plotCurveList_D[i-1, start+int(1/box_time_step)])/2.0 if load.f_param4 == '97.00' or load.f_param4 == '96.00': y_text_label = i*.8/len(plotCurveList_D[:,0]) + .07*np.floor(i/numProteinTypes_D) bax.annotate('%s'%plotProteinLabels[i%numProteinTypes_D],xy=(1,y_label),xytext=(text_adjust,y_text_label), fontsize=7, fontproperties=font, arrowprops=dict(facecolor='black',shrink=0.05, width=.3, headwidth=5.)) if (i+1)%(numProteinTypes_D)==0: bax.text(-0.2,y_text_label+.04,section_names[int(np.floor(i/numProteinTypes_D))],transform=bax.transAxes,fontsize=9,fontproperties=font,) bax.fill_between(timeAxis[start:end], plotCurveList_D[i-1, start:end], plotCurveList_D[i, start:end], alpha=alphaScale_D[k],facecolor=colorScale[j]) k+=1 bax.set_xlim(timeAxis[start],timeAxis[end-1]) bax.get_yaxis().set_visible(False) bax.set_ylim(0, 1) bax.set_title("MinD protein counts over time") bax.set_xlabel("Time (s)") rax = bax.twinx() rax.set_ylabel('Fraction of proteins in each stage and section',labelpad=-15) rax.yaxis.set_ticklabels([0,"","","","",1.0]) #bax.set_ylabel("Fraction of proteins") # 'A', xy=(Az, Ax), xytext=(1.2,-3.5), # path_effects=texteff, # arrowprops=dict(shrink=0.01, width=1, # headwidth=hw, path_effects=arroweff)) #bax.legend(plotNameList_D,bbox_to_anchor=(0.3,-0.05,1.0,1.0),loc=4,prop={'size':8}).draw_frame(False) plt.savefig(load.print_string("box-plot_D","")) plt.figure() #f, (bax,sectionax) = plt.subplots(1, 2) bax = plt.subplot2grid((2,5), (0,0), colspan=4, rowspan=2) sectionax = plt.subplot2grid((2,5), (0,4), colspan=1,rowspan=2) # First plot the section data... plot_sections(sectionax, sectiondata) j=0 k=0 for i in range(len(plotCurveList_E)): if i%(numProteinTypes_E)==0: j+=1 k=0 if i==0: bax.plot(timeAxis[start:end],plotCurveList_E[i][start:end],color=colorScale[j],alpha=alphaScale_E[k]) bax.fill_between(timeAxis[start:end],[0 for x in range(len(timeAxis))[start:end]],plotCurveList_E[i][start:end],alpha=alphaScale_E[k],facecolor=colorScale[j]) elif i!=0: bax.plot(timeAxis[start:end],plotCurveList_E[i][start:end],color=colorScale[j],alpha=alphaScale_E[k]) bax.fill_between(timeAxis[start:end],plotCurveList_E[i-1][start:end],plotCurveList_E[i][start:end],alpha=alphaScale_E[k],facecolor=colorScale[j]) #print "i is ",i," || k is", k," || j is",j k+=1 bax.set_xlim(timeAxis[start],timeAxis[end-1]) bax.set_ylim(0, 1) bax.set_title("MinE protein counts over time") bax.set_xlabel("Time (s)") bax.set_ylabel("Fraction of proteins") bax.legend(plotNameList_E,bbox_to_anchor=(0.3,-0.05,1.0,1.0),loc="lower right",prop={'size':8}).draw_frame(False) plt.savefig(load.print_string("box-plot_E","")) plt.show() return 0
nlevels = 20 mylevels = np.linspace(0,(1+1.0/nlevels)*maxval,nlevels) Z, Y = np.meshgrid(np.arange(0,proteins[i].dataset[0].shape[1],1), np.arange(0,proteins[i].dataset[0].shape[0],1)) #generate a sequence of .png's for each file (printed time step). these will be used to create a gif. for k in kvals: page = proteins[i].dataset[k] page[page>maxval] = maxval plt.contourf(Y+k*dY, proteins[0].datashape[1]-Z+i*dZ, page, cmap=plt.cm.hot_r, levels=mylevels) plt.axes().get_yaxis().set_ticks([(i+0.5)*dZ for i in range(len(proteinList))]) plt.axes().get_yaxis().set_ticklabels(proteinLabels) plt.axes().get_xaxis().set_ticks([(0.5+k)*dY for k in kvals[::int(2.5*skip_times)]]) plt.axes().get_xaxis().set_ticklabels([int(k*dump_time_step) for k in kvals[::int(2.5*skip_times)]]) plt.axes().set_aspect('equal') plt.axes().get_yaxis().set_ticks_position('none') plt.axes().get_xaxis().set_ticks_position('none') plt.xlabel('time (s)') # I got the colorbar bit here from # http://matplotlib.org/users/tight_layout_guide.html, which explains # the difficulties with tight_layout() and colorbar positioning. from mpl_toolkits.axes_grid1 import make_axes_locatable divider = make_axes_locatable(plt.gca()) cax = divider.append_axes("right", "3%", pad="1%") cbar = plt.colorbar(cax=cax,ticks=[0,maxval]) cbar.ax.set_yticklabels(['0', 'max']) #plt.colorbar(ticks=[]) plt.tight_layout() plt.savefig(load.print_string("image-plot",""))
def main(): with open("./data/shape-%s/%s%s%sbox-plot--%s-%s-%s-%s-%s-%s.dat"%(load.f_shape,load.debug_str,load.hires_str,load.slice_str,load.f_shape,load.f_param1,load.f_param2,load.f_param3,load.f_param4,load.f_param5),"r") as boxData: fileLines = boxData.readlines() #get number of boxes and protein types. little hokey but it works. in boxData.readlines(), there is exactly one '\n' newline string #for each protein type block. therefor, the number of protein types is equal to the number of times "\n" appears by itself in the list. numProteinTypes = len([line for line in fileLines if line=="\n"]) numNewLines = numProteinTypes #it follows that the total number of lines in the data file, minus the number of blank lines in the data file, is equal to #the number of protein types * the number of box types. divide by number of protein types to get number of box types. numBoxes = (len(fileLines) - numNewLines)/numProteinTypes #grab the names of the proteins used, and the names of the boxes proteinTypeList = [] boxList = [] for line in fileLines: if (line != "\n"): proteinTypeList += [line.split("\t")[0]] boxList += [line.split("\t")[1]] #prune duplicates proteinTypeList = list(set(proteinTypeList)) boxList = list(set(boxList)) #generate list of proteinType and box combinations to feed into ckData plotNameList_D = [] plotNameList_E = [] numProteinTypes_D = 0 numProteinTypes_E = 0 numPlots_D = 0 numPlots_E = 0 for box in boxList: for proteinType in proteinTypeList: if "D_" in proteinType and "n" not in proteinType: plotNameList_D += ["%s-%s"%(box,proteinType)] numPlots_D += 1 for proteinType in proteinTypeList: if "D_" in proteinType and "n" not in proteinType: numProteinTypes_D += 1 plotCurveList_D = [] for proteinData in plotNameList_D: splitString = proteinData.split('-') (protein, boxName) = (splitString[0], splitString[1]) plotCurveList_D += [returnData(boxName,protein)] #get a time axis for the plot from the length of one of the data sets we have #timeAxis = range(len(plotCurveList_D[0])) difD = 2.5 # (um)^2 s^- 1 time_step = .1*load.dx*load.dx/difD #sec print_denominator = 1000 #This is from the c++ I wanted to format things the same here. box_time_step = time_step*print_denominator timeAxis = np.linspace(0,box_time_step*len(plotCurveList_D[0]),len(plotCurveList_D[0])) #begin messy code (to deal with matplotlib) - don't judge me #(start, end) = (int(5.3*int(len(timeAxis)/10)),int(5.7*int(len(timeAxis)/10))) (start, end) = find_period(plotCurveList_D[3]) #integral of proteins over time for i in range(numPlots_D): integral = 0 for j in range(len(plotCurveList_D[0])): integral += plotCurveList_D[i][j] #plot scales. colors limited for now. colorScale = ["b","g","r","c","m","y"] alphaScale_D = [n/numProteinTypes_D for n in range(1,numProteinTypes_D+1)] # yLimit = max(plotCurveList_D[0][start:end]) #generate the plot plt.figure() j=0 k=0 for i in range(numPlots_D): if i%(numProteinTypes_D)==0: j+=1 k=0 plt.plot(timeAxis[start:end], plotCurveList_D[i][start:end], color=colorScale[j],alpha=alphaScale_D[k]) k+=1 plt.xlim(timeAxis[start],timeAxis[end-1]) #plt.ylim(0,10000) plt.title("Min D protein counts over time") plt.xlabel("Time (s)") plt.ylabel("Fraction of proteins") plt.legend(plotNameList_D,loc="best",prop={'size':10}) plt.savefig(load.print_string("ave-plot_D","")) return 0
def main(): with open( "./data/shape-%s/%s%s%sbox-plot--%s-%s-%s-%s-%s-%s.dat" % (load.f_shape, load.debug_str, load.hires_str, load.slice_str, load.f_shape, load.f_param1, load.f_param2, load.f_param3, load.f_param4, load.f_param5), "r") as boxData: fileLines = boxData.readlines() #get number of boxes and protein types. little hokey but it works. in boxData.readlines(), there is exactly one '\n' newline string #for each protein type block. therefor, the number of protein types is equal to the number of times "\n" appears by itself in the list. numProteinTypes = len([line for line in fileLines if line == "\n"]) numNewLines = numProteinTypes #it follows that the total number of lines in the data file, minus the number of blank lines in the data file, is equal to #the number of protein types * the number of box types. divide by number of protein types to get number of box types. numBoxes = (len(fileLines) - numNewLines) / numProteinTypes #grab the names of the proteins used, and the names of the boxes proteinTypeList = [] boxList = [] for line in fileLines: if (line != "\n"): proteinTypeList += [line.split("\t")[0]] boxList += [line.split("\t")[1]] #prune duplicates proteinTypeList = list(set(proteinTypeList)) boxList = list(set(boxList)) #generate list of proteinType and box combinations to feed into stackData plotNameList_D = [] plotNameList_E = [] numProteinTypes_D = 0 numProteinTypes_E = 0 for box in boxList: for proteinType in proteinTypeList: if "D_" in proteinType: plotNameList_D += ["%s-%s" % (box, proteinType)] if "E_" in proteinType: plotNameList_E += ["%s-%s" % (box, proteinType)] #print "" #print "plotNameList before ", plotNameList_D, "\n" new_plotNameList_D = [0] * len(plotNameList_D) P_Ord = [3, 0, 2, 1, 7, 4, 6, 5, 11, 8, 10, 9] if load.f_param4 == '97.00': P_Ord = [3, 0, 2, 1, 11, 8, 10, 9, 15, 12, 14, 13, 7, 4, 6, 5] if load.f_param4 == '96.00': P_Ord = [15, 12, 14, 13, 3, 0, 2, 1, 7, 4, 6, 5, 11, 8, 10, 9] for i in range(len(P_Ord)): new_plotNameList_D[i] = plotNameList_D[P_Ord[i]] for i in range(len(plotNameList_D)): plotNameList_D[i] = new_plotNameList_D[i] #print "plotNameList after ",plotNameList_D,"\n" plotProteinLabels = [ 'MinD:ATP (cyto)', 'MinD:ATP (mem)', 'MinE:MinD:ATP', 'MinD:ADP (cyto)' ] #pass plotNameList through stackData to generate the list of line data to be plotted plotCurveList_D = stackData(plotNameList_D) plotCurveList_E = stackData(plotNameList_E) #get a time axis for the plot from the length of one of the data sets we have difD = 2.5 # (um)^2 s^- 1 time_step = .1 * load.dx * load.dx / difD #sec print_denominator = 1000 #This is from the c++ I wanted to format things the same here. box_time_step = time_step * print_denominator timeAxis = np.linspace(0, box_time_step * len(plotCurveList_D[0]), len(plotCurveList_D[0])) #begin messy code (to deal with matplotlib) - don't judge me start_time_as_frac_of_ten = float(load.f_param6) end_time_as_frac_of_ten = float(load.f_param7) tot_time = len(plotCurveList_D[0]) * box_time_step start = int(tot_time * start_time_as_frac_of_ten / 10.0 / box_time_step) end = int(tot_time * end_time_as_frac_of_ten / 10.0 / box_time_step) (start, end) = find_period(plotCurveList_D[len(plotCurveList_D) - 2]) (start, end) = find_period(np.array(returnData(boxList[len(boxList) - 1], 'D_ND'))) # print useful coordination data period = timeAxis[end - 1] - timeAxis[start] print 'period is', period firsttime = timeAxis[start] while firsttime > 9 * period: firsttime -= period print 'early start time is', firsttime print 'and end time is ', firsttime + period print 'and file numbers are', firsttime * 2, 'and', (firsttime + period) * 2 # now offset time so it starts at zero timeAxis = timeAxis - timeAxis[start] if load.f_param4 == '97.00' or (load.f_shape == 'triangle' and load.f_param3 == '6.01'): if load.f_param4 == '97.00': start_time_as_frac_of_ten = 0 end_time_as_frac_of_ten = 2.3 if load.f_shape == 'triangle' and load.f_param3 == '6.01': start_time_as_frac_of_ten = 5.00 end_time_as_frac_of_ten = 9.00 start = int(tot_time * start_time_as_frac_of_ten / 10.0 / box_time_step) end = int(tot_time * end_time_as_frac_of_ten / 10.0 / box_time_step) #print set(plotCurveList_D[1]).union(set(plotCurveList_D[2])) #get num on each plot for proteinType in proteinTypeList: if "D_" in proteinType: numProteinTypes_D += 1 if "E_" in proteinType: numProteinTypes_E += 1 #plot scales. colors limited for now. colorScale = ["b", "g", "r", "c", "m", "y"] alphaScale_D = [ n / numProteinTypes for n in range(1, numProteinTypes_D + 1) ] alphaScale_E = [ n / numProteinTypes for n in range(1, numProteinTypes_E + 1) ] #generate the plot #f, (bax,sectionax) = plt.subplots(1, 2) bax = plt.subplot2grid((2, 5), (0, 0), colspan=4, rowspan=2) sectionax = plt.subplot2grid((2, 5), (0, 4), colspan=1, rowspan=2) # first plot the section data... sectiondata = np.loadtxt( "data/shape-%s/membrane_files/%s%s%ssections-%s-%s-%s-%s-%s-%s.dat" % (load.f_shape, load.debug_str, load.hires_str, load.slice_str, load.f_shape, load.f_param1, load.f_param2, load.f_param3, load.f_param4, load.f_param5)) def plot_sections(sectionax, sectiondata): dx = load.dx x = np.arange(sectiondata.shape[1] * 1.0) * dx y = np.arange(sectiondata.shape[0] * 1.0) * dx X, Y = np.meshgrid(x, y) inmembrane = np.zeros_like(sectiondata) inmembrane[sectiondata > 0] = 1.0 xmax = X[sectiondata > 0].max() xmin = X[sectiondata > 0].min() ymax = Y[sectiondata > 0].max() ymin = Y[sectiondata > 0].min() ymean = (Y * inmembrane).sum() / inmembrane.sum() xmean = (X * inmembrane).sum() / inmembrane.sum() yweighted = (Y * sectiondata).sum() / sectiondata.sum() xweighted = (X * sectiondata).sum() / sectiondata.sum() levels = [0.5, 1.5, 2.5, 3.5, 4.5] mycolors = ["w", "g", "r", "m", "c", "y"] for i in xrange(min(4, len(boxList))): if boxList[i] == 'Right': mycolors[1] = colorScale[i] if boxList[i] == 'Mid': mycolors[2] = colorScale[i] if boxList[i] == 'Left': mycolors[3] = colorScale[i] mycolors = colorScale[1:] if load.f_param4 == '97.00': mycolors = ['g', 'r', 'm', 'c'] if load.f_param4 == '96.00': #rightup = 2, rightdown = 1, leftup = 4, leftdown = 3 mycolors = ['g', 'r', 'c', 'm'] #print mycolors # here we rotate so that the order of sections will match the # box plot. xdir, ydir = xweighted - xmean, yweighted - ymean xdir, ydir = xdir / np.sqrt(xdir**2 + ydir**2), ydir / np.sqrt(xdir**2 + ydir**2) extraxspace = .5 extrayspace = 0 Yrotated = X * xdir + Y * ydir Xrotated = X * ydir - Y * xdir sectionax.contourf(Xrotated, Yrotated, sectiondata, levels=levels, colors=mycolors) xmin = Xrotated[sectiondata > 0].min() xmax = Xrotated[sectiondata > 0].max() ymin = Yrotated[sectiondata > 0].min() ymax = Yrotated[sectiondata > 0].max() sectionax.set_xlim(xmin - extraxspace, xmax) sectionax.set_ylim(ymin - extrayspace, ymax) sectionax.set_aspect('equal') sectionax.set_frame_on(False) sectionax.axes.get_xaxis().set_visible(False) sectionax.axes.get_yaxis().set_visible(False) sectionax.add_artist( AnchoredSizeBar( sectionax.transData, 1.00, # length of the bar in the data reference "1$\mu$", # label of the bar #bbox_to_anchor=(0.,0.,1.,1.), loc=8, # 'best', # location (lower right) pad=-(ymax - ymin) / 2.0 + 0.4, borderpad=0.25, sep=3, frameon=False)) plot_sections(sectionax, sectiondata) section_names = ['Bottom Section', 'Center Section', 'Top Section'] if load.f_param4 == '97.00': section_names = [ 'Lower Section', 'Middle Left Section', 'Middle Right Section', 'Upper Section' ] # section_names = ['rightup','mid','left','rightdown'] if load.f_param4 == '96.00': section_names = [ 'Lower Left Section', 'Lower Right Section', 'Upper Left Section', 'Upper Right Section' ] # section_names = ['rightdown','rightup','leftdown','leftup'] font = FontProperties() font.set_family('serif') text_adjust = -.2 * box_time_step * (end - start) j = 0 k = 0 for i in range(len(plotCurveList_D[:, 0])): if i % (numProteinTypes_D) == 0: j += 1 k = 0 if i == 0: bax.plot(timeAxis[start:end], plotCurveList_D[i, start:end], color=colorScale[j], alpha=alphaScale_D[k]) y_text_label = i * .8 / len(plotCurveList_D[:, 0]) + .1 * np.floor( i / numProteinTypes_D) if load.f_param4 == '97.00' or load.f_param4 == '96.00': y_text_label = i * .8 / len( plotCurveList_D[:, 0]) + .07 * np.floor( i / numProteinTypes_D) y_label = (plotCurveList_D[i, start + int(1 / box_time_step)]) / 2.0 bax.annotate('%s' % plotProteinLabels[i], xy=(1, y_label), xytext=(text_adjust, y_text_label), fontsize=7, fontproperties=font, arrowprops=dict(facecolor='black', shrink=0.05, width=.3, headwidth=5.)) bax.fill_between(timeAxis[start:end], [0 for x in range(len(timeAxis))[start:end]], plotCurveList_D[i, start:end], alpha=alphaScale_D[k], facecolor=colorScale[j]) elif i != 0: bax.plot(timeAxis[start:end], plotCurveList_D[i, start:end], color=colorScale[j], alpha=alphaScale_D[k]) y_text_label = i * .8 / len(plotCurveList_D[:, 0]) + .1 * np.floor( i / numProteinTypes_D) y_label = ( plotCurveList_D[i, start + int(1 / box_time_step)] + plotCurveList_D[i - 1, start + int(1 / box_time_step)]) / 2.0 if load.f_param4 == '97.00' or load.f_param4 == '96.00': y_text_label = i * .8 / len( plotCurveList_D[:, 0]) + .07 * np.floor( i / numProteinTypes_D) bax.annotate('%s' % plotProteinLabels[i % numProteinTypes_D], xy=(1, y_label), xytext=(text_adjust, y_text_label), fontsize=7, fontproperties=font, arrowprops=dict(facecolor='black', shrink=0.05, width=.3, headwidth=5.)) if (i + 1) % (numProteinTypes_D) == 0: bax.text( -0.2, y_text_label + .04, section_names[int(np.floor(i / numProteinTypes_D))], transform=bax.transAxes, fontsize=9, fontproperties=font, ) bax.fill_between(timeAxis[start:end], plotCurveList_D[i - 1, start:end], plotCurveList_D[i, start:end], alpha=alphaScale_D[k], facecolor=colorScale[j]) k += 1 bax.set_xlim(timeAxis[start], timeAxis[end - 1]) bax.get_yaxis().set_visible(False) bax.set_ylim(0, 1) bax.set_title("MinD protein counts over time") bax.set_xlabel("Time (s)") rax = bax.twinx() rax.set_ylabel('Fraction of proteins in each stage and section', labelpad=-15) rax.yaxis.set_ticklabels([0, "", "", "", "", 1.0]) #bax.set_ylabel("Fraction of proteins") # 'A', xy=(Az, Ax), xytext=(1.2,-3.5), # path_effects=texteff, # arrowprops=dict(shrink=0.01, width=1, # headwidth=hw, path_effects=arroweff)) #bax.legend(plotNameList_D,bbox_to_anchor=(0.3,-0.05,1.0,1.0),loc=4,prop={'size':8}).draw_frame(False) plt.savefig(load.print_string("box-plot_D", "")) plt.figure() #f, (bax,sectionax) = plt.subplots(1, 2) bax = plt.subplot2grid((2, 5), (0, 0), colspan=4, rowspan=2) sectionax = plt.subplot2grid((2, 5), (0, 4), colspan=1, rowspan=2) # First plot the section data... plot_sections(sectionax, sectiondata) j = 0 k = 0 for i in range(len(plotCurveList_E)): if i % (numProteinTypes_E) == 0: j += 1 k = 0 if i == 0: bax.plot(timeAxis[start:end], plotCurveList_E[i][start:end], color=colorScale[j], alpha=alphaScale_E[k]) bax.fill_between(timeAxis[start:end], [0 for x in range(len(timeAxis))[start:end]], plotCurveList_E[i][start:end], alpha=alphaScale_E[k], facecolor=colorScale[j]) elif i != 0: bax.plot(timeAxis[start:end], plotCurveList_E[i][start:end], color=colorScale[j], alpha=alphaScale_E[k]) bax.fill_between(timeAxis[start:end], plotCurveList_E[i - 1][start:end], plotCurveList_E[i][start:end], alpha=alphaScale_E[k], facecolor=colorScale[j]) #print "i is ",i," || k is", k," || j is",j k += 1 bax.set_xlim(timeAxis[start], timeAxis[end - 1]) bax.set_ylim(0, 1) bax.set_title("MinE protein counts over time") bax.set_xlabel("Time (s)") bax.set_ylabel("Fraction of proteins") bax.legend(plotNameList_E, bbox_to_anchor=(0.3, -0.05, 1.0, 1.0), loc="lower right", prop={ 'size': 8 }).draw_frame(False) plt.savefig(load.print_string("box-plot_E", "")) plt.show() return 0
page[page > maxval] = maxval plt.contourf(Y + k * dY, proteins[0].datashape[1] - Z + i * dZ, page, cmap=plt.cm.hot_r, levels=mylevels) plt.axes().get_yaxis().set_ticks([(i + 0.5) * dZ for i in range(len(proteinList))]) plt.axes().get_yaxis().set_ticklabels(proteinLabels) plt.axes().get_xaxis().set_ticks([(0.5 + k) * dY for k in kvals[::int(2.5 * skip_times)]]) plt.axes().get_xaxis().set_ticklabels( [int(k * dump_time_step) for k in kvals[::int(2.5 * skip_times)]]) plt.axes().set_aspect('equal') plt.axes().get_yaxis().set_ticks_position('none') plt.axes().get_xaxis().set_ticks_position('none') plt.xlabel('time (s)') # I got the colorbar bit here from # http://matplotlib.org/users/tight_layout_guide.html, which explains # the difficulties with tight_layout() and colorbar positioning. from mpl_toolkits.axes_grid1 import make_axes_locatable divider = make_axes_locatable(plt.gca()) cax = divider.append_axes("right", "3%", pad="1%") cbar = plt.colorbar(cax=cax, ticks=[0, maxval]) cbar.ax.set_yticklabels(['0', 'max']) #plt.colorbar(ticks=[]) plt.tight_layout() plt.savefig(load.print_string("image-plot", ""))
plt.axes().get_xaxis().set_ticklabels(range(len(smeared_data))[::int(2.5*skip_times)]) plt.axes().set_aspect('equal') plt.axes().get_yaxis().set_ticks_position('none') plt.axes().get_xaxis().set_ticks_position('none') if sim_type == 'full_array': plt.axes().set_title('Stochastic Model',x=.2) elif sim_type == 'exact': plt.axes().set_title('Deterministic Model',x=.2) else: print '\nSomething went wrong while writing the title of the plots\n\n' exit(1) plt.xlabel('time (s)') # I got the colorbar bit here from # http://matplotlib.org/users/tight_layout_guide.html, which explains # the difficulties with tight_layout() and colorbar positioning. from mpl_toolkits.axes_grid1 import make_axes_locatable divider = make_axes_locatable(plt.gca()) cax = divider.append_axes("right", "3%", pad="1%") # cbar = plt.colorbar(cax=cax,ticks=[0,maxval]) # cbar.ax.set_yticklabels(['0', 'max']) cbar = plt.colorbar(cax=cax) cbar.set_label('molecules/$\mu^2$') #plt.colorbar(ticks=[]) plt.tight_layout() print 'saving as', load.print_string("single-image-plot","") plt.savefig(load.print_string("single-image-plot",""), transparent=True) #plt.savefig(load.print_string("real-gauss-single-image-plot",""))
plt.figure() plt.axes().set_aspect('equal', 'datalim') plt.ax = plt.gca() font=FontProperties() font.set_family('serif') for i in range(len(tails)-1): radial_length = np.sqrt((tails[i][0]-load.dx*Ny/2.0)**2+(tails[i][1]-load.dx*Nz/2.0)**2) dir_z = (tails[i][0]-load.dx*Nz/2.0)/radial_length dir_y = (tails[i][1]-load.dx*Ny/2.0)/radial_length number_zpos = tails[i][0]+.18*dir_z number_ypos = tails[i][1]+.18*dir_y plt.ax.annotate('',xy=(tails[i+1][0],tails[i+1][1]),xytext=(tails[i][0],tails[i][1]), fontsize=7, arrowprops=dict(color='red',shrink=0.01, width=.3, headwidth=5.)) #plt.ax.text(number_zpos,number_ypos,"%d"%(i+1),fontsize=30,fontproperties=font,color='red') cell_membrane[cell_membrane>0] = 1 cell_x = np.linspace(0,load.dx*len(cell_membrane[0,:]),len(cell_membrane[0,:])) cell_y = np.linspace(0,load.dx*len(cell_membrane[:,0]),len(cell_membrane[:,0])) plt.contour(cell_x,cell_y,cell_membrane, linewidths=2,levels=[.99]) #plt.ax.quiver(X,Y,U,V,scale_units='xy',angles='xy',scale=1) plt.ax.get_yaxis().set_visible(True) plt.ax.get_xaxis().set_visible(True) plt.xlim((0,load.dx*cell_membrane.shape[1])) plt.ylim((0,load.dx*cell_membrane.shape[0])) plt.xlabel("Z grid position") plt.ylabel("Y grid position") #plt.title("Local temporal maxima, global spatial maxima view of %s"%(protein)) plt.savefig(load.print_string("arrow-plot",protein)) plt.show()
plt.axes().get_yaxis().set_ticks_position('none') plt.axes().get_xaxis().set_ticks_position('none') if sim_type == 'full_array': plt.axes().set_title('Stochastic Model',x=.2) elif sim_type == 'exact': plt.axes().set_title('Deterministic Model',x=.2) else: print '\nSomething went wrong while writing the title of the plots\n\n' exit(1) plt.xlabel('time (s)') # I got the colorbar bit here from # http://matplotlib.org/users/tight_layout_guide.html, which explains # the difficulties with tight_layout() and colorbar positioning. from mpl_toolkits.axes_grid1 import make_axes_locatable divider = make_axes_locatable(plt.gca()) cax = divider.append_axes("right", "3%", pad="1%") # cbar = plt.colorbar(cax=cax,ticks=[0,maxval]) # cbar.ax.set_yticklabels(['0', 'max']) cbar = plt.colorbar(cax=cax) cbar.set_label('molecules/$\mu m^2$') #plt.colorbar(ticks=[]) plt.tight_layout() print 'saving as', load.print_string("single-image-plot","") plt.savefig(load.print_string("single-image-plot",""), transparent=True) plt.savefig(load.print_string("single-image-plot","")[:-4]+'.eps', transparent=True) plt.savefig(load.print_string("single-image-plot","")[:-4]+'.png', transparent=True, dpi=500) #plt.savefig(load.print_string("real-gauss-single-image-plot",""))
xy=(tails[i + 1][0], tails[i + 1][1]), xytext=(tails[i][0], tails[i][1]), fontsize=7, arrowprops=dict(color='red', shrink=0.01, width=.3, headwidth=5.)) plt.ax.text(number_zpos, number_ypos, "%d" % (i + 1), fontsize=30, fontproperties=font, color='red') cell_membrane[cell_membrane > 0] = 1 cell_x = np.linspace(0, load.dx * len(cell_membrane[0, :]), len(cell_membrane[0, :])) cell_y = np.linspace(0, load.dx * len(cell_membrane[:, 0]), len(cell_membrane[:, 0])) plt.contour(cell_x, cell_y, cell_membrane, linewidths=2, levels=[.99]) #plt.ax.quiver(X,Y,U,V,scale_units='xy',angles='xy',scale=1) plt.ax.get_yaxis().set_visible(False) plt.ax.get_xaxis().set_visible(False) plt.xlim((0, load.dx * cell_membrane.shape[1])) plt.ylim((0, load.dx * cell_membrane.shape[0])) plt.xlabel("Z grid position") plt.ylabel("Y grid position") #plt.title("Local temporal maxima, global spatial maxima view of %s"%(protein)) plt.savefig(load.print_string("arrow-plot", protein)) plt.show()
if (x+i >= 0 and x+i < new.shape[0]-1 and y+j >= 0 and y+j < new.shape[1]-1): new[x+i,y+j] += data[x,y]*math.exp( -(i*i+j*j)*.05*.05/2.0/sigma/sigma ) return new proteinList = ['NflD'] for protein in proteinList: job_string = "data/shape-%s/%s-%s-%s-%s-%s-%s/" % (load.f_shape,load.f_param1,load.f_param2, load.f_param3,load.f_param4,load.f_param5,load.sim_type) p = re.compile('[.]') job_string = p.sub('_',job_string) data_filename = job_string + protein + '/' + 'time-map.dat' data_file = np.loadtxt(data_filename) print "starting time_map.p for ",data_filename data = gaussian_smear(data_file,.509) timemax = np.max(data) plt.figure() plt.pcolormesh(data,vmin=0) plt.axes().set_aspect('equal') plt.xlim(0,data.shape[1]) plt.ylim(0,data.shape[0]) plt.xlabel("Z grid position") plt.ylabel("Y grid position") plt.title("Time averaged view of %s"%(protein)) plt.colorbar() plt.savefig(load.print_string("time-map",protein))
from __future__ import division import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np import file_loader as load import sys # WIP for protein in load.proteinList: file = np.loadtxt("./data/shape-%s/%s%s%stime-map-%s-%s-%s-%s-%s-%s-%s.dat"%(load.f_shape,load.debug_str,load.hires_str,load.slice_str,protein,load.f_shape,load.f_param1,load.f_param2,load.f_param3,load.f_param4,load.f_param5)) plt.figure() plt.pcolormesh(file) plt.axes().set_aspect('equal') plt.xlim(0,file.shape[1]) plt.ylim(0,file.shape[0]) plt.xlabel("Z grid position") plt.ylabel("Y grid position") plt.title("Time averaged view of %s"%(protein)) plt.colorbar() plt.savefig(load.print_string("time-map",protein))
import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np import file_loader as load import sys #create protein data objects (see file_loader.py) NflE = load.data(protein="NflE") NflD = load.data(protein="NflD") nATP = load.data(protein="nATP") nE = load.data(protein="nE") nADP = load.data(protein="nADP") Nd = load.data(protein="Nd") Nde = load.data(protein="Nde") #compute time average (removing first 10% happens in file loading) def average_location(dataset): tsum = np.zeros_like(dataset[0]) for t in range(nATP.tsteps): tsum += dataset[t] return tsum/(nATP.tsteps) #plot each of the data set time maps individually. for p in [NflE, NflD, nATP, nE, nADP, Nd]: plt.figure() plt.contourf(p.axes[0],p.axes[1],average_location(p.dataset),500) plt.axes().set_aspect('equal', 'datalim') plt.colorbar() plt.savefig(load.print_string("time-map",p))
from __future__ import division import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import sys import pylab import file_loader as load data = np.loadtxt( "./data/shape-%s/membrane_files/%s%s%ssections-%s-%s-%s-%s-%s-%s.dat" % ( load.f_shape, load.debug_str, load.hires_str, load.slice_str, load.f_shape, load.f_param1, load.f_param2, load.f_param3, load.f_param4, load.f_param5, ) ) plt.figure() plt.pcolormesh(data) plt.savefig(load.print_string("sections_plot", ""))
from __future__ import division import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt import sys import pylab import file_loader as load data = np.loadtxt("./data/shape-%s/membrane_files/%s%s%ssections-%s-%s-%s-%s-%s-%s.dat"%(load.f_shape,load.debug_str,load.hires_str,load.slice_str,load.f_shape,load.f_param1,load.f_param2,load.f_param3,load.f_param4,load.f_param5)) plt.figure() plt.pcolormesh(data) plt.savefig(load.print_string("sections_plot",""))