def showsip1ddata(PHI, fr, ab2, mn2=None, cmax=None, ylab=True, cbar=True): """display SIP phase data as image plot.""" P.cla() ax = P.gca() pal = P.cm.get_cmap() pal.set_under('w') pal.set_bad('w') if isinstance(PHI, pg.Vector): PHI = N.asarray(PHI) im = P.imshow(PHI.reshape((len(ab2), len(fr))), interpolation='nearest', cmap=pal) if cmax is None: cmax = N.max(PHI) im.set_clim((0., cmax)) ax.xaxis.set_label_position('top') P.xlabel('f in Hz') a = [] df = 1 for f in fr[::df]: a.append("%g" % rndig(f)) P.xticks(N.arange(0, len(fr), df), a) xtl = ax.get_xticklabels() for i, xtli in enumerate(xtl): xtli.set_rotation('vertical') if ylab: a = [] yla = 'AB/2' if mn2 is None: for i in range(len(ab2)): a.append(str(ab2[i])) else: yla = yla + '-MN/2' for i in range(len(ab2)): a.append('%g%g' % (rndig(ab2[i]), rndig(mn2[i]))) P.yticks(N.arange(len(ab2)), a) P.ylabel(yla + ' in m') if cbar: P.colorbar(aspect=40, shrink=0.6) P.ylim((len(ab2) - 0.5, -0.5)) P.show() P.ylim((len(ab2) - 0.5, -0.5)) return
def showsip1ddata(PHI, fr, ab2, mn2=None, cmax=None, ylab=True, cbar=True): """display SIP phase data as image plot.""" P.cla() ax = P.gca() pal = P.cm.get_cmap() pal.set_under('w') pal.set_bad('w') if isinstance(PHI, pg.RVector): PHI = N.asarray(PHI) im = P.imshow(PHI.reshape((len(ab2), len(fr))), interpolation='nearest', cmap=pal) if cmax is None: cmax = N.max(PHI) im.set_clim((0., cmax)) ax.xaxis.set_label_position('top') P.xlabel('f in Hz') a = [] df = 1 for f in fr[::df]: a.append("%g" % rndig(f)) P.xticks(N.arange(0, len(fr), df), a) xtl = ax.get_xticklabels() for i, xtli in enumerate(xtl): xtli.set_rotation('vertical') if ylab: a = [] yla = 'AB/2' if mn2 is None: for i in range(len(ab2)): a.append(str(ab2[i])) else: yla = yla + '-MN/2' for i in range(len(ab2)): a.append('%g%g' % (rndig(ab2[i]), rndig(mn2[i]))) P.yticks(N.arange(len(ab2)), a) P.ylabel(yla + ' in m') if cbar: P.colorbar(aspect=40, shrink=0.6) P.ylim((len(ab2) - 0.5, -0.5)) P.show() P.ylim((len(ab2) - 0.5, -0.5)) return
def showmymatrix(mat, x, y, dx=2, dy=1, xlab=None, ylab=None, cbar=None): """What is this good for?.""" plt.imshow(mat, interpolation='nearest') plt.xticks(np.arange(0, len(x), dx), ["%g" % rndig(xi, 2) for xi in x]) plt.yticks(np.arange(0, len(y), dy), ["%g" % rndig(yi, 2) for yi in y]) plt.ylim((len(y) - 0.5, -0.5)) if xlab is not None: plt.xlabel(xlab) if ylab is not None: plt.ylabel(ylab) plt.axis('auto') if cbar is not None: plt.colorbar(orientation=cbar) return
def showmymatrix(mat, x, y, dx=2, dy=1, xlab=None, ylab=None, cbar=None): """What is this good for?.""" plt.imshow(mat, interpolation='nearest') plt.xticks(np.arange(0, len(x), dx), ["%g" % rndig(xi, 2) for xi in x]) plt.yticks(np.arange(0, len(y), dy), ["%g" % rndig(yi, 2) for yi in y]) plt.ylim((len(y) - 0.5, -0.5)) if xlab is not None: plt.xlabel(xlab) if ylab is not None: plt.ylabel(ylab) plt.axis('auto') if cbar is not None: plt.colorbar(orientation=cbar) return
def draw1dmodel__Redundant(x, thk=None, xlab=None, zlab="z in m", islog=True, fs=14, z0=0, **kwargs): """Draw 1d block model defined by value and thickness vectors.""" # if xlab is None: # xlab = "$\\rho$ in $\\Omega$m" if thk is None: # gimli blockmodel (thk+x together) given nl = int(np.floor((len(x) - 1) / 2.)) + 1 thk = np.asarray(x)[:nl - 1] x = np.asarray(x)[nl - 1:nl * 2 - 1] z1 = np.concatenate(([0], np.cumsum(thk))) + z0 z = np.concatenate((z1, [z1[-1] * 1.2])) nl = len(x) # x.size() px = np.zeros((nl * 2, 1)) pz = np.zeros((nl * 2, 1)) for i in range(nl): px[2 * i] = x[i] px[2 * i + 1] = x[i] pz[2 * i + 1] = z[i + 1] if i < nl - 1: pz[2 * i + 2] = z[i + 1] # plt.cla() li = [] if islog: li = plt.semilogx(px, pz, **kwargs) else: li = plt.plot(px, pz, **kwargs) plt.gca().xaxis.set_label_position('top') locs = plt.xticks()[0] if len(locs) < 2: locs = np.hstack((min(x), locs, max(x))) elif len(locs) < 5: locs[0] = max(locs[0], min(x)) locs[-1] = min(locs[-1], max(x)) a = [] for l in locs: a.append('%g' % rndig(l)) plt.xticks(locs, a, fontsize=fs) plt.yticks(fontsize=fs) plt.xlim((np.min(x) * 0.9, np.max(x) * 1.1)) plt.ylim((max(z1) * 1.15, 0.)) if xlab is not None: plt.xlabel(xlab, fontsize=fs) if zlab is not None: plt.ylabel(zlab, fontsize=fs) plt.grid(which='both') # plt.show() return li
def makeSlmData(ab2, mn2, rhoa=None, filename=None): """generate a pygimli data container from ab/2 and mn/2 array.""" data = pg.DataContainer() data.resize(len(ab2)) pos = N.unique(N.hstack((ab2, mn2))) for elx in N.hstack((-pos[::-1], pos)): data.createElectrode(elx, 0., 0.) if filename is not None: f = open(filename, 'w') f.write(str(len(pos) * 2) + '\n#x y z\n') for elx in N.hstack((-pos[::-1], pos)): f.write(str(elx) + '\t0\t0\n') f.write(str(len(ab2)) + '\n#a\tb\tm\tn\tk\trhoa\n') lpos = len(pos) iab = pos.searchsorted(ab2) imn = pos.searchsorted(mn2) if (filename is not None) & (rhoa is None): rhoa = N.ones(len(ab2)) for i in range(len(iab)): # print -pos[iab[i]], -pos[imn[i]], pos[imn[i]], pos[iab[i]] k = (ab2[i]**2 - mn2[i]**2) * N.pi / mn2[i] / 2.0 if filename is not None: f.write(str(lpos - iab[i]) + '\t' + str(lpos + iab[i] + 1) + '\t') f.write(str(lpos - imn[i]) + '\t' + str(lpos + imn[i] + 1) + '\t') f.write(str(rndig(k, 4)) + '\t' + str(rhoa[i]) + '\n') data.createFourPointData(i, int(lpos - iab[i]), int(lpos + iab[i] + 1), int(lpos - imn[i]), int(lpos + imn[i] + 1)) if filename is not None: f.close() data.set('rhoa', pg.asvector(rhoa)) return data
def makeSlmData(ab2, mn2, rhoa=None, filename=None): """generate a pygimli data container from ab/2 and mn/2 array.""" data = pg.DataContainer() data.resize(len(ab2)) pos = N.unique(N.hstack((ab2, mn2))) for elx in N.hstack((-pos[::-1], pos)): data.createElectrode(elx, 0., 0.) if filename is not None: f = open(filename, 'w') f.write(str(len(pos) * 2) + '\n#x y z\n') for elx in N.hstack((-pos[::-1], pos)): f.write(str(elx) + '\t0\t0\n') f.write(str(len(ab2)) + '\n#a\tb\tm\tn\tk\trhoa\n') lpos = len(pos) iab = pos.searchsorted(ab2) imn = pos.searchsorted(mn2) if (filename is not None) & (rhoa is None): rhoa = N.ones(len(ab2)) for i in range(len(iab)): # print -pos[iab[i]], -pos[imn[i]], pos[imn[i]], pos[iab[i]] k = (ab2[i]**2 - mn2[i]**2) * N.pi / mn2[i] / 2.0 if filename is not None: f.write(str(lpos - iab[i]) + '\t' + str(lpos + iab[i] + 1) + '\t') f.write(str(lpos - imn[i]) + '\t' + str(lpos + imn[i] + 1) + '\t') f.write(str(rndig(k, 4)) + '\t' + str(rhoa[i]) + '\n') data.createFourPointData(i, int(lpos - iab[i]), int(lpos + iab[i] + 1), int(lpos - imn[i]), int(lpos + imn[i] + 1)) if filename is not None: f.close() data.set('rhoa', pg.asvector(rhoa)) return data
def ReadAndRemoveEM(filename, readsecond=False, doplot=False, dellast=True, ePhi=0.5, ePerc=1., lam=2000.): """ Read res1file and remove EM effects using a double-Cole-Cole model fr,rhoa,phi,dphi = ReadAndRemoveEM(filename, readsecond/doplot bools) """ fr, rhoa, phi, drhoa, dphi = read1resfile(filename, readsecond, dellast=dellast) # forward problem mesh = pg.createMesh1D(1, 6) # 6 independent parameters f = DoubleColeColeModelling(mesh, pg.asvector(fr), phi[2] / abs(phi[2])) f.regionManager().loadMap("region.control") model = f.createStartVector() # inversion inv = pg.RInversion(phi, f, True, False) inv.setAbsoluteError(phi * ePerc * 0.01 + ePhi / 1000.) inv.setRobustData(True) # inv.setCWeight(pg.RVector(6, 1.0)) # wozu war das denn gut? inv.setMarquardtScheme(0.8) inv.setLambda(lam) inv.setModel(model) erg = inv.run() inv.echoStatus() chi2 = inv.chi2() mod0 = pg.RVector(erg) mod0[0] = 0.0 # set IP term to zero to obtain pure EM term emphi = f.response(mod0) resid = (phi - emphi) * 1000. if doplot: s = "IP: m= " + str(rndig(erg[0])) + " t=" + str(rndig(erg[1])) + \ " c =" + str(rndig(erg[2])) s += " EM: m= " + str(rndig(erg[3])) + " t=" + str(rndig(erg[4])) + \ " c =" + str(rndig(erg[5])) fig = P.figure(1) fig.clf() ax = P.subplot(111) P.errorbar( fr, phi * 1000., yerr=dphi * 1000., fmt='x-', label='measured') ax.set_xscale('log') P.semilogx(fr, emphi * 1000., label='EM term (CC)') P.errorbar(fr, resid, yerr=dphi * 1000., label='IP term') ax.set_yscale('log') P.xlim((min(fr), max(fr))) P.ylim((0.1, max(phi) * 1000.)) P.xlabel('f in Hz') P.ylabel(r'-$\phi$ in mrad') P.grid(True) P.title(s) P.legend(loc=2) # ('measured','2-cole-cole','residual')) fig.show() return N.array(fr), N.array(rhoa), N.array(resid), N.array( phi) * 1e3, dphi, chi2, N.array(emphi) * 1e3
def showsip1dmodel(M, tau, thk, res=None, z=None, cmin=None, cmax=None, islog=True): """ Display an SIP Debye block model as image. """ if z is None: z = N.cumsum(N.hstack((0., thk))) P.cla() pal = P.cm.get_cmap() pal.set_under('w') pal.set_bad('w') if isinstance(M, pg.RVector): M = N.asarray(M) if islog: M = N.log10(M) M = M.reshape((len(z), len(tau))) im = P.imshow(M, interpolation='nearest', cmap=pal) if cmax is None: cmax = N.max(M) if cmax is None: cmax = N.max(M) im.set_clim((cmin, cmax)) a = [] for t in tau[::2]: a.append("%g" % rndig(t * 1000, 2)) P.xticks(N.arange(0, len(tau), 2), a) a = [] for zi in z: a.append(str(zi)) P.yticks(N.arange(len(z)) - 0.5, a) P.xlabel(r'$\tau$ in ms') P.ylabel('z in m') P.ylim((len(z) - 0.5, -0.5)) P.colorbar(orientation='horizontal', aspect=40, shrink=0.6) if res is not None: xl = P.xlim()[1] for i in range(len(res)): P.text(xl, i, r' %g $\Omega$m' % rndig(res[i], 2)) lgm = N.zeros((len(z), 1)) tch = N.zeros((len(z), 1)) lgt = N.log(tau) if islog: M = 10**M for n in range(len(M)): m = N.abs(M[n]) tch[n] = N.sum(m) lgm[n] = N.exp(N.sum(m * lgt) / N.sum(m)) tpos = N.interp(N.log(lgm), N.log(tau), N.arange(len(tau))) P.plot(tpos, N.arange(len(z)), 'w*') P.title('logarithmized spectral chargeability') P.show() return lgm, tch
def showsounding(ab2, rhoa, resp=None, mn2=None, islog=True, xlab=None): """ Display a sounding curve (rhoa over ab/2) and an additional response. """ if xlab is None: xlab = r'$\rho_a$ in $\Omega$m' ab2a = N.asarray(ab2) rhoa = N.asarray(rhoa) if mn2 is None: if islog: l1 = P.loglog(rhoa, ab2, 'rx-', label='observed') else: l1 = P.semilogy(rhoa, ab2, 'rx-', label='observed') P.hold(True) if resp is not None: if islog: l2 = P.loglog(resp, ab2, 'bo-', label='simulated') else: l2 = P.semilogy(resp, ab2, 'bo-', label='simulated') P.legend((l1, l2), ('obs', 'sim'), loc=0) else: for unmi in N.unique(mn2): if islog: l1 = P.loglog(rhoa[mn2 == unmi], ab2a[mn2 == unmi], 'rx-', label='observed') else: l1 = P.semilogy(rhoa[mn2 == unmi], ab2a[mn2 == unmi], 'rx-', label='observed') P.hold(True) if resp is not None: l2 = P.loglog(resp[mn2 == unmi], ab2a[mn2 == unmi], 'bo-', label='simulated') P.legend((l1, l2), ('obs', 'sim')) P.axis('tight') P.ylim((max(ab2), min(ab2))) locs = P.yticks()[0] if len(locs) < 2: locs = N.hstack((min(ab2), locs, max(ab2))) else: locs[0] = max(locs[0], min(ab2)) locs[-1] = min(locs[-1], max(ab2)) a = [] for l in locs: a.append('%g' % rndig(l)) P.yticks(locs, a) locs = P.xticks()[0] a = [] for l in locs: a.append('%g' % rndig(l)) P.xticks(locs, a) P.grid(which='both') P.xlabel(xlab) P.ylabel('AB/2 in m') # P.legend() P.show() return
def showqtresultfit(thk, wc, t2, datvec, resp, t, islog=True, clim=None, nu=3, nv=2): """Show mrs qt result and data fit. Parameters ---------- thk : array of length nlay-1 thickness vector wc : array of length nlay water content vector t2 : array of length nlay relaxation time vector datvec : array of length len(t)*len(Q) data vector t : array time vector islog : bool [True] use logarithms for colour scale clim : tuple of 2 floats color scale of data cube (in nV) nu/nv : int number of rows/columns for subplot Returns ------- ax : mpl.Axes object Examples -------- showqtresultfit(thk,wc,t2,datvec,resp,t,islog=True,clim=None,nu=3,nv=2)""" if clim is None: cma = max(datvec) cmi = min(datvec) if islog: cma = np.log10(cma) cmi = cma - 1.5 clim = (cmi, cma) nt = len(t) nq = len(datvec) / nt si = (nq, nt) fig = plt.figure(1) ax1 = fig.add_subplot(nu, nv, 1) draw1dmodel(wc, thk, islog=False, xlab=r'$\theta$') ax3 = fig.add_subplot(nu, nv, 3) draw1dmodel(t2, thk, xlab='T2* in ms') ax3.set_xticks([0.02, 0.05, 0.1, 0.2, 0.5]) ax3.set_xticklabels(('0.02', '0.05', '0.1', '0.2', '0.5')) ax2 = fig.add_subplot(nu, nv, 2) if islog: plt.imshow(np.log10(np.array(datvec).reshape(si)), interpolation='nearest', aspect='auto') else: plt.imshow(np.array(datvec).reshape(si), interpolation='nearest', aspect='auto') plt.clim(clim) ax4 = fig.add_subplot(nu, nv, 4) if islog: plt.imshow(np.log10(resp.reshape(si)), interpolation='nearest', aspect='auto') else: plt.imshow(resp.reshape(si), interpolation='nearest', aspect='auto') misfit = np.array(datvec - resp) plt.clim(clim) ax5 = fig.add_subplot(nu, nv, 5) plt.hist(misfit, bins=30) plt.axis('tight') plt.grid(which='both') plt.text(plt.xlim()[0], np.mean(plt.ylim()), ' std=%g nV' % rndig(np.std(misfit), 3)) ax6 = fig.add_subplot(nu, nv, 6) plt.imshow(misfit.reshape(si), interpolation='nearest', aspect='auto') ax = [ax1, ax2, ax3, ax4, ax5, ax6] return ax
def draw1dmodel__Redundant(x, thk=None, xlab=None, zlab="z in m", islog=True, fs=14, z0=0, **kwargs): """Draw 1d block model defined by value and thickness vectors.""" # if xlab is None: # xlab = "$\\rho$ in $\\Omega$m" if thk is None: # gimli blockmodel (thk+x together) given nl = int(np.floor((len(x) - 1) / 2.)) + 1 thk = np.asarray(x)[:nl - 1] x = np.asarray(x)[nl - 1:nl * 2 - 1] z1 = np.concatenate(([0], np.cumsum(thk))) + z0 z = np.concatenate((z1, [z1[-1] * 1.2])) nl = len(x) # x.size() px = np.zeros((nl * 2, 1)) pz = np.zeros((nl * 2, 1)) for i in range(nl): px[2 * i] = x[i] px[2 * i + 1] = x[i] pz[2 * i + 1] = z[i + 1] if i < nl - 1: pz[2 * i + 2] = z[i + 1] # plt.cla() li = [] if islog: li = plt.semilogx(px, pz, **kwargs) else: li = plt.plot(px, pz, **kwargs) plt.gca().xaxis.set_label_position('top') locs = plt.xticks()[0] if len(locs) < 2: locs = np.hstack((min(x), locs, max(x))) elif len(locs) < 5: locs[0] = max(locs[0], min(x)) locs[-1] = min(locs[-1], max(x)) a = [] for l in locs: a.append('%g' % rndig(l)) plt.xticks(locs, a, fontsize=fs) plt.yticks(fontsize=fs) plt.xlim((np.min(x) * 0.9, np.max(x) * 1.1)) plt.ylim((max(z1) * 1.15, 0.)) if xlab is not None: plt.xlabel(xlab, fontsize=fs) if zlab is not None: plt.ylabel(zlab, fontsize=fs) plt.grid(which='both') # plt.show() return li
def ReadAndRemoveEM(filename, readsecond=False, doplot=False, dellast=True, ePhi=0.5, ePerc=1., lam=2000.): """ Read res1file and remove EM effects using a double-Cole-Cole model fr,rhoa,phi,dphi = ReadAndRemoveEM(filename, readsecond/doplot bools) """ fr, rhoa, phi, drhoa, dphi = read1resfile(filename, readsecond, dellast=dellast) # forward problem mesh = pg.createMesh1D(1, 6) # 6 independent parameters f = DoubleColeColeModelling(mesh, pg.asvector(fr), phi[2] / abs(phi[2])) f.regionManager().loadMap("region.control") model = f.createStartVector() # inversion inv = pg.RInversion(phi, f, True, False) inv.setAbsoluteError(phi * ePerc * 0.01 + ePhi / 1000.) inv.setRobustData(True) # inv.setCWeight(pg.RVector(6, 1.0)) # wozu war das denn gut? inv.setMarquardtScheme(0.8) inv.setLambda(lam) inv.setModel(model) erg = inv.run() inv.echoStatus() chi2 = inv.chi2() mod0 = pg.RVector(erg) mod0[0] = 0.0 # set IP term to zero to obtain pure EM term emphi = f.response(mod0) resid = (phi - emphi) * 1000. if doplot: s = "IP: m= " + str(rndig(erg[0])) + " t=" + str(rndig(erg[1])) + \ " c =" + str(rndig(erg[2])) s += " EM: m= " + str(rndig(erg[3])) + " t=" + str(rndig(erg[4])) + \ " c =" + str(rndig(erg[5])) fig = P.figure(1) fig.clf() ax = P.subplot(111) P.errorbar( fr, phi * 1000., yerr=dphi * 1000., fmt='x-', label='measured') ax.set_xscale('log') P.semilogx(fr, emphi * 1000., label='EM term (CC)') P.errorbar(fr, resid, yerr=dphi * 1000., label='IP term') ax.set_yscale('log') P.xlim((min(fr), max(fr))) P.ylim((0.1, max(phi) * 1000.)) P.xlabel('f in Hz') P.ylabel(r'-$\phi$ in mrad') P.grid(True) P.title(s) P.legend(loc=2) # ('measured','2-cole-cole','residual')) fig.show() return N.array(fr), N.array(rhoa), N.array(resid), N.array( phi) * 1e3, dphi, chi2, N.array(emphi) * 1e3
def showsip1dmodel(M, tau, thk, res=None, z=None, cmin=None, cmax=None, islog=True): """ Display an SIP Debye block model as image. """ if z is None: z = N.cumsum(N.hstack((0., thk))) P.cla() pal = P.cm.get_cmap() pal.set_under('w') pal.set_bad('w') if isinstance(M, pg.RVector): M = N.asarray(M) if islog: M = N.log10(M) M = M.reshape((len(z), len(tau))) im = P.imshow(M, interpolation='nearest', cmap=pal) if cmax is None: cmax = N.max(M) if cmax is None: cmax = N.max(M) im.set_clim((cmin, cmax)) a = [] for t in tau[::2]: a.append("%g" % rndig(t * 1000, 2)) P.xticks(N.arange(0, len(tau), 2), a) a = [] for zi in z: a.append(str(zi)) P.yticks(N.arange(len(z)) - 0.5, a) P.xlabel(r'$\tau$ in ms') P.ylabel('z in m') P.ylim((len(z) - 0.5, -0.5)) P.colorbar(orientation='horizontal', aspect=40, shrink=0.6) if res is not None: xl = P.xlim()[1] for i in range(len(res)): P.text(xl, i, r' %g $\Omega$m' % rndig(res[i], 2)) lgm = N.zeros((len(z), 1)) tch = N.zeros((len(z), 1)) lgt = N.log(tau) if islog: M = 10**M for n in range(len(M)): m = N.abs(M[n]) tch[n] = N.sum(m) lgm[n] = N.exp(N.sum(m * lgt) / N.sum(m)) tpos = N.interp(N.log(lgm), N.log(tau), N.arange(len(tau))) P.plot(tpos, N.arange(len(z)), 'w*') P.title('logarithmized spectral chargeability') P.show() return lgm, tch
def showsounding(ab2, rhoa, resp=None, mn2=None, islog=True, xlab=None): """ Display a sounding curve (rhoa over ab/2) and an additional response. """ if xlab is None: xlab = r'$\rho_a$ in $\Omega$m' ab2a = N.asarray(ab2) rhoa = N.asarray(rhoa) if mn2 is None: if islog: l1 = P.loglog(rhoa, ab2, 'rx-', label='observed') else: l1 = P.semilogy(rhoa, ab2, 'rx-', label='observed') P.hold(True) if resp is not None: if islog: l2 = P.loglog(resp, ab2, 'bo-', label='simulated') else: l2 = P.semilogy(resp, ab2, 'bo-', label='simulated') P.legend((l1, l2), ('obs', 'sim'), loc=0) else: for unmi in N.unique(mn2): if islog: l1 = P.loglog(rhoa[mn2 == unmi], ab2a[mn2 == unmi], 'rx-', label='observed') else: l1 = P.semilogy(rhoa[mn2 == unmi], ab2a[mn2 == unmi], 'rx-', label='observed') P.hold(True) if resp is not None: l2 = P.loglog(resp[mn2 == unmi], ab2a[mn2 == unmi], 'bo-', label='simulated') P.legend((l1, l2), ('obs', 'sim')) P.axis('tight') P.ylim((max(ab2), min(ab2))) locs = P.yticks()[0] if len(locs) < 2: locs = N.hstack((min(ab2), locs, max(ab2))) else: locs[0] = max(locs[0], min(ab2)) locs[-1] = min(locs[-1], max(ab2)) a = [] for l in locs: a.append('%g' % rndig(l)) P.yticks(locs, a) locs = P.xticks()[0] a = [] for l in locs: a.append('%g' % rndig(l)) P.xticks(locs, a) P.grid(which='both') P.xlabel(xlab) P.ylabel('AB/2 in m') # P.legend() P.show() return
def showqtresultfit(thk, wc, t2, datvec, resp, t, islog=True, clim=None, nu=3, nv=2): """Show mrs qt result and data fit. Parameters ---------- thk : array of length nlay-1 thickness vector wc : array of length nlay water content vector t2 : array of length nlay relaxation time vector datvec : array of length len(t)*len(Q) data vector t : array time vector islog : bool [True] use logarithms for colour scale clim : tuple of 2 floats color scale of data cube (in nV) nu/nv : int number of rows/columns for subplot Returns ------- ax : mpl.Axes object Examples -------- showqtresultfit(thk,wc,t2,datvec,resp,t,islog=True,clim=None,nu=3,nv=2)""" if clim is None: cma = max(datvec) cmi = min(datvec) if islog: cma = np.log10(cma) cmi = cma - 1.5 clim = (cmi, cma) nt = len(t) nq = len(datvec) / nt si = (nq, nt) fig = plt.figure(1) ax1 = fig.add_subplot(nu, nv, 1) draw1dmodel(wc, thk, islog=False, xlab=r'$\theta$') ax3 = fig.add_subplot(nu, nv, 3) draw1dmodel(t2, thk, xlab='T2* in ms') ax3.set_xticks([0.02, 0.05, 0.1, 0.2, 0.5]) ax3.set_xticklabels(('0.02', '0.05', '0.1', '0.2', '0.5')) ax2 = fig.add_subplot(nu, nv, 2) if islog: plt.imshow(np.log10(np.array(datvec).reshape(si)), interpolation='nearest', aspect='auto') else: plt.imshow(np.array(datvec).reshape(si), interpolation='nearest', aspect='auto') plt.clim(clim) ax4 = fig.add_subplot(nu, nv, 4) if islog: plt.imshow(np.log10(resp.reshape(si)), interpolation='nearest', aspect='auto') else: plt.imshow(resp.reshape(si), interpolation='nearest', aspect='auto') misfit = np.array(datvec - resp) plt.clim(clim) ax5 = fig.add_subplot(nu, nv, 5) plt.hist(misfit, bins=30) plt.axis('tight') plt.grid(which='both') plt.text(plt.xlim()[0], np.mean(plt.ylim()), ' std=%g nV' % rndig(np.std(misfit), 3)) ax6 = fig.add_subplot(nu, nv, 6) plt.imshow(misfit.reshape(si), interpolation='nearest', aspect='auto') ax = [ax1, ax2, ax3, ax4, ax5, ax6] return ax