def get_bestd(wb, peak_idx, initial, Dguess=-12): """Returns best-fit initial and isotropic D """ x, y = wb.xy_picker(peak_idx=peak_idx, wholeblock=False, heights_instead=False) L3 = [] D3 = [] for k in range(3): L3.append(wb.profiles[k].len_microns) D3.append(Dguess) # best fit initial and corresponding D params = diffusion.params_setup3D(L3, D3, wb.time_seconds, initial=initial, isotropic=True, vinit=False) minimize(func2min, params, args=(x, y), kws={'raypaths' : wb.raypaths, 'show_plot' : False}) bestD = params['log10Dx'].value return bestD
def plotpeaks(wb_list, wbs_list, ilist, dlist, elist, dlist_slow=None, slowb=[False]*6, legidx=13, sidelabels=True, ncol=5, wholeblock=False, peak_idx_list = [0, 1, 2, 4, 5], show_legend=True, dlabel='Isotropic\nDiffusion curve', xtickgrid=[0.2]*6, ytickgrid=[5.]*6): """Takes wb = list of main whole block being plotted, wbs = list of lists of whole block data being plotted in each panel, ilist = list of initials, dlist = list of diffusivities, elist = list of errors""" #### legend #### if show_legend is True: styles = [] for wbs in wbs_list: for wbtoplot in wbs: styleToAdd = styledict[wbtoplot] if styleToAdd not in styles: styles.append(styleToAdd) for sty in styles: axes[legidx].plot(-100, -100, **sty) axes[legidx].plot(-100, -100, '-k', label='"initial"', linewidth=1) axes[legidx].plot(-100, -100, '-g', label=dlabel, linewidth=3) axes[legidx].plot(-100, -100, '--g', label='+/- error log10 D') axes[legidx].legend(fancybox='on', loc=8) # 9 for top axesranges = [range(3), range(3,6), range(6,9), range(9,12), range(12,15)] ### y axis limits and "initial" for r in range(ncol): for ax_idx in axesranges[r]: ax = axes[ax_idx] ax.plot(ax.get_xlim(), [ilist[r], ilist[r]], '-k', linewidth=1) ax.set_ylim(0, tops[r]) xd = [] # x data to plot yd = [] # y data to plot yf = [] ys = [] ax_idx = 0 for idx in range(ncol): # loop through each row of data # get basic data peak_idx = peak_idx_list[idx] initial = ilist[idx] wb = wb_list[idx] wbs = wbs_list[idx] # diffusion curves L3 = [] D3 = [] Dfast = [] Dslow = [] for k in range(3): L3.append(wb.profiles[k].len_microns) D3.append(dlist[idx]) if slowb[idx] is True: D3[1] = dlist_slow[idx] for k in range(3): Dfast.append(D3[k] + elist[idx]) Dslow.append(D3[k] - elist[idx]) params = diffusion.params_setup3D(L3, D3, wb.time_seconds, initial) xdiff, ydiff = diffusion.diffusion3Dwb_params(params, raypaths=wb.raypaths, show_plot=False) params = diffusion.params_setup3D(L3, Dfast, wb.time_seconds, initial) xdiff, yfast = diffusion.diffusion3Dwb_params(params, raypaths=wb.raypaths, show_plot=False) params = diffusion.params_setup3D(L3, Dslow, wb.time_seconds, initial) xdiff, yslow = diffusion.diffusion3Dwb_params(params, need_to_center_x_data=False, raypaths=wb.raypaths, show_plot=False) for k in range(3): m = max(xdiff[k]) xdiff[k] = xdiff[k] / m xd.append(xdiff) yd.append(ydiff) yf.append(yfast) ys.append(yslow) ### side labels #### ylabelloc = 'left' formatter = '{:.2f}' if slowb[idx] is True: subscript = '$_c$' else: subscript = '' if sidelabels is True: axes[15].set_ylabel(''.join(('3645\ncm$^{-1}$\n\nlog$_{10}$D', subscript, '\n', formatter.format(peak_D[0]), '\n+/-', str(er[0]))), rotation=0, ha=ylabelloc, va='center') axes[16].set_ylabel(''.join(('3617\ncm$^{-1}$\n\nlog$_{10}$D', subscript, '\n', formatter.format(peak_D[1]), '\n+/-', str(er[1]))), rotation=0, ha=ylabelloc, va='center') axes[17].set_ylabel(''.join(('3540\ncm$^{-1}$\n\nlog$_{10}$D', subscript, '\n', formatter.format(peak_D[2]), '\n+/-', str(er[2]))), rotation=0, ha=ylabelloc, va='center') axes[18].set_ylabel(''.join(('3443\ncm$^{-1}$\n\nlog$_{10}$D', subscript, '\n', formatter.format(peak_D[4]), '\n+/-', str(er[4]))), rotation=0, ha=ylabelloc, va='center') axes[19].set_ylabel(''.join(('3355\ncm$^{-1}$\n\nlog$_{10}$D', subscript, '\n', formatter.format(peak_D[5]), '\n+/-', str(er[5]))), rotation=0, ha=ylabelloc, va='center') for k in range(3): ax = axes[ax_idx] # Set tick locations xmajorLocator = MultipleLocator(xtickgrid[idx]) ymajorLocator = MultipleLocator(ytickgrid[idx]) ax.xaxis.set_major_locator(xmajorLocator) ax.yaxis.set_major_locator(ymajorLocator) if show_legend is True: if ax_idx < legidx: s = ''.join((string.ascii_uppercase[ax_idx],'.')) elif ax_idx > legidx: s = ''.join((string.ascii_uppercase[ax_idx-1],'.')) else: s = ''.join((string.ascii_uppercase[ax_idx],'.')) ax.text(0.1, ax.get_ylim()[1] - 0.15*ax.get_ylim()[1], s, backgroundcolor='w') # Plot the diffusion curves ax.plot(xd[idx][k], yd[idx][k], '-g', linewidth=3) ax.plot(xd[idx][k], yf[idx][k], '--g') ax.plot(xd[idx][k], ys[idx][k], '--g') # Plot all wb data in wbs list of wholeblocks for wb_idx in range(len(wbs)): if wbs[wb_idx].raypaths[k] == wb.raypaths[k]: xi3, yi3 = wbs[wb_idx].xy_picker(peak_idx=peak_idx, wholeblock=wholeblock, centered=False) xi = xi3[k] yi = yi3[k] # Normalize x L = wbs[wb_idx].profiles[k].len_microns xi = np.array(xi) / L ax.plot(xi, yi, **styledict[wbs[wb_idx]]) # label ray paths if wb.profiles[k].raypath == 'a': R = ''.join(('R || ', wb.profiles[k].raypath,'*')) else: R = ' '.join(('R ||', wb.profiles[k].raypath)) axes[ax_idx].text(0.65, ax.get_ylim()[1] - 0.15*ax.get_ylim()[1], R) ax_idx = ax_idx + 1