def plotdeltatime(fname, k): d = genplotlib.gendict_phase(fname, 'deltatime') md = genplotlib.genlist(d) n = [] for i, v in d.iteritems(): n.append(max(v)) print(n) plt.figure() genplotlib.plotdata(d, md, k, 's', 'Delay (seconds)', 'Time delay', ymin=0.05, ylim=(max(n) + 0.1 * max(n))) plt.savefig('deltatime_summ') plt.figure() genplotlib.plotdata(d, md, k, 'b', 'Delay (seconds)', 'Time delay', ymin=0.05, ylim=(max(n) + 0.1 * max(n))) plt.savefig('deltatime_summ_bar')
def plotdeltaframe(fname, k): d = genplotlib.gendict_phase(fname, 'deltaframe') md = genplotlib.genlist(d) n = [] for i, v in d.iteritems(): n.append(max(v)) print(n) plt.figure() genplotlib.plotdata(d, md, k, 's', 'Delay (frames)', 'Frame delay', ymin=0, ylim=max(n) + 5) plt.savefig('deltaframe_summ') plt.figure() genplotlib.plotdata(d, md, k, 'b', 'Delay (frames)', 'Frame delay', ymin=0, ylim=max(n) + 5) plt.savefig('deltaframe_summ_bar')
def writemeans_gc(gcfname, dyeareafname): peakd, aread, durd = gpl.gendictgc(gcfname) percentpeakd = {} for k, val in peakd.iteritems(): vpercent = [v*100 for v in val] percentpeakd[k] = vpercent percentaread = {} for k, val in aread.iteritems(): vpercent = [v*100 for v in val] percentaread[k] = vpercent dicts = percentpeakd, percentaread, durd mpeakd, maread, mdurd, = map(gpl.genlist, dicts) print(mpeakd) print(maread) dyearead = gpl.gendictgc2(dyeareafname)[3] mdyearead = gpl.genlist(dyearead) #wf.writemeans(mpeakd, expt+'_peakf_means.txt') #wf.writemeans(maread, expt+'_area_means.txt') #wf.writemeans(mdurd, expt+'_dur_means.txt') #wf.writemeans(mdyearead, expt+'_dyearea_means.txt') writemeans(mpeakd, 'peakf_means.txt') writemeans(maread, 'area_means.txt') writemeans(mdurd, 'dur_means.txt') writemeans(mdyearead, 'dyearea_means.txt')
def writemeans_gc(gcfname, dyeareafname): peakd, aread, durd = gpl.gendictgc(gcfname) percentpeakd = {} for k, val in peakd.iteritems(): vpercent = [v * 100 for v in val] percentpeakd[k] = vpercent percentaread = {} for k, val in aread.iteritems(): vpercent = [v * 100 for v in val] percentaread[k] = vpercent dicts = percentpeakd, percentaread, durd mpeakd, maread, mdurd, = map(gpl.genlist, dicts) print(mpeakd) print(maread) dyearead = gpl.gendictgc2(dyeareafname)[3] mdyearead = gpl.genlist(dyearead) #wf.writemeans(mpeakd, expt+'_peakf_means.txt') #wf.writemeans(maread, expt+'_area_means.txt') #wf.writemeans(mdurd, expt+'_dur_means.txt') #wf.writemeans(mdyearead, expt+'_dyearea_means.txt') writemeans(mpeakd, 'peakf_means.txt') writemeans(maread, 'area_means.txt') writemeans(mdurd, 'dur_means.txt') writemeans(mdyearead, 'dyearea_means.txt')
def plotandsavescatterplot(roiname, keylist, fdir='.', ylim=10): """Plots scatter plot from data in 'peakf.txt' and saves it in the summary directory. Run from a data/ or summary/ folder.""" dictdata = genplotlib.gendict(genpeakffname_roi(roiname, fdir)) dictmeans = genplotlib.genlist(dictdata) #~ keylist = genplotlib.genkeylist(dictdata) genplotlib.plotdata(dictdata, dictmeans, keylist, 's', ylabel='Hz', ftitle='Mean pumping ' + 'frequency '+roiname, ylim=ylim) savegraph('dftf_freq_scatter_'+roiname, roiname)
def plotpumpdata(keyfile='keylist', fname='cib_pumps.txt', type='b', ylim=40): cib, pumps = gendictgf(fname) mpumps = genplotlib.genlist(pumps) #keylist = sorted(mpumps.keys()) keylist = cmn.load_keys(keyfile) fig1 = genplotlib.plotdata(pumps, mpumps, keylist, type, ylabel='# of pumps', ftitle = 'Number of ' + 'pumps over 30 seconds', ylim=ylim, ymin=-2) fig1.subplots_adjust(bottom=0.45)
def plotandsavepooledscatterplot(p_peakf_file, roi): """Plots scatter plot from data in 'peakf.txt' and saves it in the summary directory. Run from a data/ or summary/ folder.""" dictdata = genplotlib.gendict(p_peakf_file) dictmeans = genplotlib.genlist(dictdata) keylist = genplotlib.genkeylist(dictdata) genplotlib.plotdata(dictdata, dictmeans, keylist, 's', ylabel='Hz', ftitle='Mean pumping ' + 'frequency '+roi) plt.savefig('pooled_freq_scatter_'+roi)
def plotandsavescatterplot_poolrois(fname, keylist, fdir='.', ylim=10): """Plots bar graph from data in 'peakf_pooled.txt' and saves it in the summary directory. Run from a data/ or summary/ folder.""" dictdata = genplotlib.gendict(fname) dictmeans = genplotlib.genlist(dictdata) #~ keylist = genplotlib.genkeylist(dictdata) genplotlib.plotdata(dictdata, dictmeans, keylist, 's', ylabel='Hz', ftitle='Mean frequency', ylim=ylim) plt.savefig('dftf_freq_scatter_pooled')
def plotdur(k, fname, type='s', ymax=30): plt.figure() d = genplotlib.gendictgc(fname)[2] md = genplotlib.genlist(d) print('Duration') for tastant, values in d.iteritems(): print(tastant, np.max(values)) if type == 'b': genplotlib.plotdata(d, md, k, 'b', 'seconds', 'Duration', 0, ymax, xlabelsize='medium') if type == 's': genplotlib.plotdata(d, md, k, 's', 'seconds', 'Duration', -5, ymax+10, xlabelsize='medium')
def plotpeak(k, fname, type = 's', ymax=1.0): plt.figure() d = genplotlib.gendictgc(fname)[0] md = genplotlib.genlist(d) print('Peak') for tastant, values in d.iteritems(): print(tastant, np.max(values)) if type == 'b': genplotlib.plotdata(d, md, k, 'b', '%', 'Peak deltaF/F', 0, ymax, xlabelsize='medium') if type == 's': genplotlib.plotdata(d, md, k, 's', 'Peak deltaF/F', 'Peak deltaF/F', -0.4, ymax+0.6, xlabelsize='medium')
def plotfreqs(file, type): """Plots the frequencies taken from the summary text files ('fname') with the title 'ftitle'; can plot either per bin or per fly depending on the summary file.""" ftitle = 'Frequencies ({0})'.format(type) d = genplotlib.gendict_freq(file) md = genplotlib.genlist(d) keylist = genplotlib.genkeylist(d) genplotlib.plotdata(d, md, keylist, 's', ftitle=ftitle, err='stdev', ylim=8, ylabel='Hz') name = 'pooled_freqs_{0}'.format(type) plt.savefig(name)
def plotbar(dictdata, keylist, plotname, fdir='.', ylim=10): """Plots bar graph from data in 'peakf.txt' and saves it in the summary directory. Run from a data/ or summary/ folder.""" dictmeans = genplotlib.genlist(dictdata) n = [] for i, v in dictdata.iteritems(): n.append(max(v)) plt.figure() genplotlib.plotdata(d, md, k, 'b', 'Delay (seconds)', 'Time delay', ymin=0.05, ylim=(max(n))) plt.savefig(plotname)
def bg_key(p_peakf_file, keyfile, roi): dictdata = genplotlib.gendict(p_peakf_file) dictmeans = genplotlib.genlist(dictdata) keylist = cmn.load_keys(keyfile) dictdata2 = {} for k in keylist: dictdata2[k] = dictdata[k] genplotlib.plotdata(dictdata2, dictmeans, keylist, 'b', ylabel='Hz', ftitle='Mean pumping frequency', xlabelsize = 'medium') plt.savefig('pooled_dftf_freq_bar_'+roi)
def plotdyearea_3d2(fname, k): plt.figure() d = genplotlib.gendictgc2(fname)[3] #~ print(d) md = genplotlib.genlist(d) print(md) #~ print('Dye Area Max Values') #~ for tastant, values in d.iteritems(): #~ print(tastant, np.max(values)) genplotlib.plotdata(d, md, k, 'b', 'Normalized Area', 'Dye Area', -0.001, 0.05, xlabelsize='medium') plt.savefig('dyearea_b') genplotlib.plotdata(d, md, k, 's', 'Normalized Area', 'Dye Area', -.01, 0.12, xlabelsize='medium') plt.savefig('dyearea_s')
def plotarea(k, fname, type='s', ymax=10): plt.figure() d = genplotlib.gendictgc(fname)[1] md = genplotlib.genlist(d) print('Area') for tastant, values in d.iteritems(): print(tastant, np.max(values)) if type == 'b': genplotlib.plotdata(d, md, k, 'b', 'intensity-seconds', 'Area under curve', 0, ymax, xlabelsize='medium') if type == 's': genplotlib.plotdata(d, md, k, 's', 'Area under curve', 'Area under curve', 0, ymax+15,i xlabelsize='medium')
def plotcibareacirc(cibresultsfile): d = genplotlib.gendict_cibarea_circ(cibresultsfile) md = genplotlib.genlist(d) k = d.keys() genplotlib.plotdata(d, md, k, 'b', 'Normalized cib area', 'Cib area', ymin=0, ylim=100) plt.savefig('pooled_cibareacirc')
def plotandsavepooledscatterplot(p_peakf_file, roi): """Plots scatter plot from data in 'peakf.txt' and saves it in the summary directory. Run from a data/ or summary/ folder.""" dictdata = genplotlib.gendict(p_peakf_file) dictmeans = genplotlib.genlist(dictdata) keylist = genplotlib.genkeylist(dictdata) genplotlib.plotdata(dictdata, dictmeans, keylist, 's', ylabel='Hz', ftitle='Mean pumping ' + 'frequency ' + roi) plt.savefig('pooled_freq_scatter_' + roi)
def plotdeltaframe(fname, k): d = genplotlib.gendict_phase(fname, 'deltaframe') md = genplotlib.genlist(d) n = [] for i, v in d.iteritems(): n.append(max(v)) print(n) plt.figure() genplotlib.plotdata(d, md, k, 's', 'Delay (frames)', 'Frame delay', ymin=0, ylim=max(n)+5) plt.savefig('deltaframe_summ') plt.figure() genplotlib.plotdata(d, md, k, 'b', 'Delay (frames)', 'Frame delay', ymin=0, ylim=max(n)+5) plt.savefig('deltaframe_summ_bar')
def plotpumpdata(keyfile='keylist', fname='cib_pumps.txt', type='b', ylim=40): cib, pumps = gendictgf(fname) mpumps = genplotlib.genlist(pumps) #keylist = sorted(mpumps.keys()) keylist = cmn.load_keys(keyfile) fig1 = genplotlib.plotdata(pumps, mpumps, keylist, type, ylabel='# of pumps', ftitle='Number of ' + 'pumps over 30 seconds', ylim=ylim, ymin=-2) fig1.subplots_adjust(bottom=0.45)
def bg_key(p_peakf_file, keyfile, roi): dictdata = genplotlib.gendict(p_peakf_file) dictmeans = genplotlib.genlist(dictdata) keylist = cmn.load_keys(keyfile) dictdata2 = {} for k in keylist: dictdata2[k] = dictdata[k] genplotlib.plotdata(dictdata2, dictmeans, keylist, 'b', ylabel='Hz', ftitle='Mean pumping frequency', xlabelsize='medium') plt.savefig('pooled_dftf_freq_bar_' + roi)
def plotdeltatime(fname, k): d = genplotlib.gendict_phase(fname, 'deltatime') md = genplotlib.genlist(d) n = [] for i, v in d.iteritems(): n.append(max(v)) print(n) plt.figure() genplotlib.plotdata(d, md, k, 's', 'Delay (seconds)', 'Time delay', ymin=0.05, ylim=(max(n)+0.1*max(n))) plt.savefig('deltatime_summ') plt.figure() genplotlib.plotdata(d, md, k, 'b', 'Delay (seconds)', 'Time delay', ymin=0.05, ylim=(max(n)+0.1*max(n))) plt.savefig('deltatime_summ_bar')
def writemeans_deltatime(fnameread, fnamewrite): d = gpl.gendict_phase(fnameread, 'deltatime') md = gpl.genlist(d) writemeans(md, fnamewrite)
for key, value in sorted(d.iteritems()): try: volperpump = value['cap'] / value['freq'] h.write(key + ',{0},{1},{2},{3}\n'.format( value['cap'], value['freq'], volperpump, value['cond'])) except KeyError: continue except ZeroDivisionError: continue keyfile = os.path.join(makepardir_subexpt(), KEYLIST) K = load_keys(keyfile) dd = gpl.gendict_volperpump(CAP_PEAKFFILE) md = gpl.genlist(dd) n = [] for i, v in dd.iteritems(): n.append(max(v)) print(max(n)) plt.figure() gpl.plotdata(dd, md, K, 's', 'nL', 'Volume per pump', ymin=0,
#! /usr/bin/env python import mn.plot.genplotlib as gpl from mn.cmn.cmn import * import mn.gof.gfplot as gf import sys fname = sys.argv[1] keyfile = sys.argv[2] meansfname = sys.argv[3] def writemeans(dict, meansfile): with open(meansfile, 'w') as f: f.write('Condition,Mean,StdDev,StdError,N,Label\n') for k, v in dict.iteritems(): f.write(k + ',') for x in v: f.write(str(x) + ',') f.write('\n') k = load_keys(keyfile) cib, pumps = gf.gendictgf(fname) mpumps = gpl.genlist(pumps) print(mpumps) writemeans(mpumps, meansfname) #plotbar(mpumps, k, plotname)
m = f.next() cond = m.split(',')[0] left[cond] = [] right[cond] = [] sum[cond] = [] f.next() for l in f: k, r, s = map(str.strip, l.split(',')) k, r, s = map(float, [k, r, s]) left[cond].append(k) right[cond].append(r) sum[cond].append(s) # Generates dictionaries listing the mean values, etc. for these counts. mleft = gpl.genlist(left) mright = gpl.genlist(right) msum = gpl.genlist(sum) k = ['112648', '112204', '423', '112648 + 112204', '112648 + 423', '112204 + 423'] # Writes the mean values, etc. for the sum of the count data into summary files. with open('2011-0915_cellcounts_sum.txt', 'w') as g: g.write('Condition\t[Mean, StdDev, StdErr, n, label]\n') for j in k: g.write('{0} \t {1} \n'.format(j, msum[j])) with open('2011-0915_cellcounts_left.txt', 'w') as g: g.write('Condition\t[Mean, StdDev, StdErr, n, label]\n') for j in k:
for key, value in sorted(d.iteritems()): try: volperpump = value['cap']/value['freq'] h.write(key + ',{0},{1},{2},{3}\n'.format(value['cap'], value['freq'], volperpump, value['cond'])) except KeyError: continue except ZeroDivisionError: continue keyfile = os.path.join(makepardir_subexpt(), KEYLIST) K = load_keys(keyfile) dd = gpl.gendict_volperpump(CAP_PEAKFFILE) md = gpl.genlist(dd) n = [] for i, v in dd.iteritems(): n.append(max(v)) print(max(n)) plt.figure() gpl.plotdata(dd, md, K, 's', 'nL', 'Volume per pump', ymin=0, ylim=max(n)+0.1*max(n)) plt.savefig('volperpump_sc') plt.figure() #gpl.plotdata(dd, md, K, 'b', 'nL', 'Volume per pump', ymin=0, ylim=max(n)+0.1*max(n)) gpl.plotdata(dd, md, K, 'b', 'nL', 'Volume per pump', ymin=0, ylim=4)
"""Plots bar graph from data in 'peakf.txt' and saves it in the summary directory. Run from a data/ or summary/ folder.""" dictmeans = genplotlib.genlist(dictdata) n = [] for i, v in dictdata.iteritems(): n.append(max(v)) plt.figure() genplotlib.plotdata(d, md, k, 'b', 'Delay (seconds)', 'Time delay', ymin=0.05, ylim=(max(n))) plt.savefig(plotname) print(os.path.abspath(os.getcwd())) k = load_keys(keyfile) d = genplotlib.gendict_phase(fname, 'deltatime') print(d) md = genplotlib.genlist(d) print(md) writemeans(md, meansfname) plotbar(d, k, plotname)
x = genresfile_datafolder() if os.path.exists(x) == True: os.remove(x) names = batchfiles('.') for name in names: print os.path.basename(name) os.chdir(name) params = CibData(PARAMS_FILE, RESULTS_FILE) cibdict = params.Gendata() writeresults(cibdict) os.chdir('../../summary') d = genplotlib.gendict_cibarea_circ('cibresults.txt') md = genplotlib.genlist(d) k = d.keys() genplotlib.plotdata(d, md, k, 'b', 'NormCibArea', 'Fraction of cibarium open', ymin=0, ylim=100) plt.savefig('cibareacirc') #plt.figure() #e = genplotlib.gendict_cibarea_dur('cibresults.txt') #me = genplotlib.genlist(e) #genplotlib.plotdata(e, me, k, 'b', 'Duration', 'Duration of Drinking', ymin=0, ylim=200) #plt.savefig('duration') #try: #a = #f = findfraction() #list.append(f)
from mn.cmn.cmn import * import mn.gof.gfplot as gf import sys fname = sys.argv[1] keyfile = sys.argv[2] meansfname = sys.argv[3] def writemeans(dict, meansfile): with open(meansfile, 'w') as f: f.write('Condition,Mean,StdDev,StdError,N,Label\n') for k, v in dict.iteritems(): f.write(k + ',') for x in v: f.write(str(x) + ',') f.write('\n') k = load_keys(keyfile) cib, pumps = gf.gendictgf(fname) mpumps = gpl.genlist(pumps) print(mpumps) writemeans(mpumps, meansfname) #plotbar(mpumps, k, plotname)