def addmodel(self, ztop, vp, vs, rh, colorvalue, showvp=True, showvs=True, showrh=True, showpr=True): """same as plotmodel but the data are added to self.depthcoll for display as LineCollections :param self: :param ztop: :param vp: :param vs: :param rh: :param colorvalue: :param showvp: :param showvs: :param showrh: :param showpr: :return: """ if showpr: pr = depthmodel1D(ztop, vp / vs) self.deptcoll['PR']['segments'].append(np.column_stack(pr.dontshow())) self.deptcoll['PR']['colorvalues'].append(colorvalue) if showvp: vp = depthmodel1D(ztop, vp) self.deptcoll['VP']['segments'].append(np.column_stack(vp.dontshow())) self.deptcoll['VP']['colorvalues'].append(colorvalue) if showvs: vs = depthmodel1D(ztop, vs) self.deptcoll['VS']['segments'].append(np.column_stack(vs.dontshow())) self.deptcoll['VS']['colorvalues'].append(colorvalue) if showrh: rh = depthmodel1D(ztop, rh) self.deptcoll['RH']['segments'].append(np.column_stack(rh.dontshow())) self.deptcoll['RH']['colorvalues'].append(colorvalue)
def boundaries(self): """see Parameterizer""" Ztopsup, VPlow, VSlow, RHlow = self.inv(self.MINF) Ztopinf, VPhgh, VShgh, RHhgh = self.inv(self.MSUP) z = np.sort(np.unique(np.concatenate((Ztopinf, Ztopsup)))) def f(Zinf, Zsup, V, which): v1 = depthmodel1D(Zinf, V).interp(z, interpmethod="stairs") v2 = depthmodel1D(Zsup, V).interp(z, interpmethod="stairs") return depthmodel1D( z, which(np.concatenate(([v1], [v2]), axis=0), axis=0)) vplow = f(Ztopinf, Ztopsup, VPlow, np.min) vphgh = f(Ztopinf, Ztopsup, VPhgh, np.max) vslow = f(Ztopinf, Ztopsup, VSlow, np.min) vshgh = f(Ztopinf, Ztopsup, VShgh, np.max) rhlow = f(Ztopinf, Ztopsup, RHlow, np.min) rhhgh = f(Ztopinf, Ztopsup, RHhgh, np.max) prlow = depthmodel1D(z, vphgh.values / vslow.values) prhgh = depthmodel1D(z, vplow.values / vshgh.values) return vplow, vphgh, vslow, vshgh, rhlow, rhhgh, prlow, prhgh
def boundaries(self): """ a method to determine the lowest and highest models, no arguments based on columns VINF and VSUP in the parameterization file warning : the lower model is not necessarily obtained when all parameters reach their lowest boundary (VINF) please return lowest and highest depthmodels stored as depthmodel1D this method is the default behavior, to be customized in subclasses if needed """ Ztopsup, VPlow, VSlow, RHlow = self.inv(self.MINF) Ztopinf, VPhgh, VShgh, RHhgh = self.inv(self.MSUP) z = np.sort(np.unique(np.concatenate((Ztopinf, Ztopsup)))) # -------------------- def f(Zinf, Zsup, V, which): v1 = depthmodel1D(Zinf, V).interp(z, interpmethod="stairs") v2 = depthmodel1D(Zsup, V).interp(z, interpmethod="stairs") return depthmodel1D( z, which(np.concatenate(([v1], [v2]), axis=0), axis=0)) # -------------------- vplow = f(Ztopinf, Ztopsup, VPlow, np.min) vphgh = f(Ztopinf, Ztopsup, VPhgh, np.max) vslow = f(Ztopinf, Ztopsup, VSlow, np.min) vshgh = f(Ztopinf, Ztopsup, VShgh, np.max) rhlow = f(Ztopinf, Ztopsup, RHlow, np.min) rhhgh = f(Ztopinf, Ztopsup, RHhgh, np.max) prlow = depthmodel1D(z, vphgh.values / vslow.values) prhgh = depthmodel1D(z, vplow.values / vshgh.values) return vplow, vphgh, vslow, vshgh, rhlow, rhhgh, prlow, prhgh
def boundaries(self): """see Parameterizer""" Ztopsup, VPlow, VSlow, RHlow = self.inv(self.MINF) Ztopinf, VPhgh, VShgh, RHhgh = self.inv(self.MSUP) z = np.sort(np.unique(np.concatenate((Ztopinf, Ztopsup)))) PRlow = VPlow / VSlow # because it is the way it has been defined in self.inv PRhgh = VPhgh / VShgh del VPlow, VPhgh def f(Zinf, Zsup, V, which): v1 = depthmodel1D(Zinf, V).interp(z, interpmethod="stairs") v2 = depthmodel1D(Zsup, V).interp(z, interpmethod="stairs") return depthmodel1D( z, which(np.concatenate(([v1], [v2]), axis=0), axis=0)) prlow = f(Ztopinf, Ztopsup, PRlow, np.min) prhgh = f(Ztopinf, Ztopsup, PRhgh, np.max) vslow = f(Ztopinf, Ztopsup, VSlow, np.min) vshgh = f(Ztopinf, Ztopsup, VShgh, np.max) rhlow = f(Ztopinf, Ztopsup, RHlow, np.min) rhhgh = f(Ztopinf, Ztopsup, RHhgh, np.max) vplow = depthmodel1D(z, prlow.values * vslow.values) vphgh = depthmodel1D(z, prhgh.values * vshgh.values) return vplow, vphgh, vslow, vshgh, rhlow, rhhgh, prlow, prhgh
def plotmodel(self, ztop, vp, vs, rh, color="k", alpha=0.2, showvp=True, showvs=True, showrh=True, showpr=True, **kwargs): if showpr: pr = depthmodel1D(ztop, vp / vs) if showvp: vp = depthmodel1D(ztop, vp) if showvs: vs = depthmodel1D(ztop, vs) if showrh: rh = depthmodel1D(ztop, rh) if showpr: pr.show(self.axdepth['PR'], color=color, alpha=alpha, **kwargs) if showvp: vp.show(self.axdepth['VP'], color=color, alpha=alpha, **kwargs) if showvs: vs.show(self.axdepth['VS'], color=color, alpha=alpha, **kwargs) if showrh: rh.show(self.axdepth['RH'], color=color, alpha=alpha, **kwargs)
def meanmodel(self): Ztopmean, VPmean, VSmean, RHmean = self.inv(self.MMEAN) vp = depthmodel1D(Ztopmean, VPmean) vs = depthmodel1D(Ztopmean, VSmean) rh = depthmodel1D(Ztopmean, RHmean) pr = depthmodel1D(Ztopmean, VPmean / VSmean) return vp, vs, pr, rh
def dmstats(dms, percentiles=[0.16, 0.5, 0.84], Ndepth=100, Nvalue=100, weights=None): assert np.all([isinstance(dm, depthmodel) for dm in dms]) assert np.all([0 < p < 1 for p in percentiles]) assert len(percentiles) == len(np.unique(percentiles)) if weights is None: weights = np.ones(len(dms)) else: assert len(weights) == len(dms) zmax = -np.inf vsmin, vsmax = np.inf, -np.inf vpmin, vpmax = np.inf, -np.inf rhmin, rhmax = np.inf, -np.inf prmin, prmax = np.inf, -np.inf for dm in dms: zmax = np.max([zmax, 1.1 * dm.vs.z[-1]]) vsmin = np.min([vsmin, dm.vs.values.min()]) vsmax = np.max([vsmax, dm.vs.values.max()]) vpmin = np.min([vpmin, dm.vp.values.min()]) vpmax = np.max([vpmax, dm.vp.values.max()]) rhmin = np.min([rhmin, dm.rh.values.min()]) rhmax = np.max([rhmax, dm.rh.values.max()]) prmin = np.min([prmin, dm.pr().values.min()]) prmax = np.max([prmax, dm.pr().values.max()]) zbins = np.linspace(0., zmax, Ndepth) vspdf = depthpdf(z=zbins, v=np.linspace(vsmin, vsmax, Nvalue)) vppdf = depthpdf(z=zbins, v=np.linspace(vpmin, vpmax, Nvalue)) rhpdf = depthpdf(z=zbins, v=np.linspace(rhmin, rhmax, Nvalue)) prpdf = depthpdf(z=zbins, v=np.linspace(prmin, prmax, Nvalue)) for dm, weight in zip(dms, weights): vspdf.appendN(dm.vs, Ntimes=weight) vppdf.appendN(dm.vp, Ntimes=weight) rhpdf.appendN(dm.rh, Ntimes=weight) prpdf.appendN(dm.pr(), Ntimes=weight) for p in percentiles: zpc, vspc = vspdf.purcentile(p) _, vppc = vppdf.purcentile(p) _, rhpc = rhpdf.purcentile(p) _, prpc = prpdf.purcentile(p) vppc = depthmodel1D(zpc, vppc) # .simplify() vspc = depthmodel1D(zpc, vspc) # .simplify() rhpc = depthmodel1D(zpc, rhpc) # .simplify() prpc = depthmodel1D(zpc, prpc) # .simplify() # dmpc = depthmodel(\).simplify() # yield p, dmpc #, (zmed, vpmed, vsmed, rhmed, prmed) yield p, (vppc, vspc, rhpc, prpc)
def boundaries(self): # default behavior, to be customized if needed Ztopsup, VPlow, VSlow, RHlow = self.inv(self.MINF) Ztopinf, VPhgh, VShgh, RHhgh = self.inv(self.MSUP) z = np.sort(np.unique(np.concatenate((Ztopinf, Ztopsup)))) def f(Zinf, Zsup, V, which): v1 = depthmodel1D(Zinf, V).interp(z, interpmethod="stairs") v2 = depthmodel1D(Zsup, V).interp(z, interpmethod="stairs") return depthmodel1D( z, which(np.concatenate(([v1], [v2]), axis=0), axis=0)) vslow = f(Ztopinf, Ztopsup, VSlow, np.min) vshgh = f(Ztopinf, Ztopsup, VShgh, np.max) vplow = depthmodel1D(z, self.VPvs(VS=vslow.values)) vphgh = depthmodel1D(z, self.VPvs(VS=vshgh.values)) prlow = depthmodel1D(z, vplow.values / vslow.values) prhgh = depthmodel1D(z, vphgh.values / vshgh.values) rhlow = depthmodel1D(z, self.RHvp(VP=vplow.values)) rhhgh = depthmodel1D(z, self.RHvp(VP=vphgh.values)) return vplow, vphgh, vslow, vshgh, rhlow, rhhgh, prlow, prhgh
def dmstats1(dms, percentiles=[0.16, 0.5, 0.84], Ndepth=100, Nvalue=100, weights=None, **mapkwargs): assert np.all([isinstance(dm, depthmodel) for dm in dms]) assert np.all([0 < p < 1 for p in percentiles]) assert len(percentiles) == len(np.unique(percentiles)) if weights is None: weights = np.ones(len(dms)) else: assert len(weights) == len(dms) zmax = -np.inf vsmin, vsmax = np.inf, -np.inf vpmin, vpmax = np.inf, -np.inf rhmin, rhmax = np.inf, -np.inf prmin, prmax = np.inf, -np.inf for dm in dms[:10]: zmax = np.max([zmax, 1.1 * dm.vs.z[-1]]) vsmin = np.min([vsmin, dm.vs.values.min()]) vsmax = np.max([vsmax, dm.vs.values.max()]) vpmin = np.min([vpmin, dm.vp.values.min()]) vpmax = np.max([vpmax, dm.vp.values.max()]) rhmin = np.min([rhmin, dm.rh.values.min()]) rhmax = np.max([rhmax, dm.rh.values.max()]) prmin = np.min([prmin, dm.pr().values.min()]) prmax = np.max([prmax, dm.pr().values.max()]) if vsmin == vsmax: vsmin *= 0.99 vsmax *= 1.01 if vpmin == vpmax: vpmin *= 0.99 vpmax *= 1.01 if rhmin == rhmax: rhmin *= 0.99 rhmax *= 1.01 if prmin == prmax: prmin *= 0.99 prmax *= 1.01 # ---------------------- def JobGen(): for weight, dm in zip(weights, dms): yield Job(weight, dm) # ---------------------- s0 = UserStacker( zmax, Ndepth, vpmin, vpmax, vsmin, vsmax, rhmin, rhmax, prmin, prmax, Nvalue ) # the stacker to be reproduced in each independent workspace (deep copy) with StackAsync(s0, JobGen(), Verbose=False, **mapkwargs) as sa: S = UserStacker(zmax, Ndepth, vpmin, vpmax, vsmin, vsmax, rhmin, rhmax, prmin, prmax, Nvalue) # initiate the final stack for jobids, (s, wname), Tgen, Tpro in sa: # receive partial stacks sa.communicate("Stacker %s stacked %6d jobs in %.6fs" % (wname, len(jobids), Tgen + Tpro)) S += s # merge all partial stacks using method __iadd__ for p in percentiles: zpc, vspc = S.vspdf.purcentile(p) _, vppc = S.vppdf.purcentile(p) _, rhpc = S.rhpdf.purcentile(p) _, prpc = S.prpdf.purcentile(p) vppc = depthmodel1D(zpc, vppc) # .simplify() vspc = depthmodel1D(zpc, vspc) # .simplify() rhpc = depthmodel1D(zpc, rhpc) # .simplify() prpc = depthmodel1D(zpc, prpc) # .simplify() # dmpc = depthmodel(\).simplify() # yield p, dmpc #, (zmed, vpmed, vsmed, rhmed, prmed) yield p, (vppc, vspc, rhpc, prpc)
def f(Zinf, Zsup, V, which): v1 = depthmodel1D(Zinf, V).interp(z, interpmethod="stairs") v2 = depthmodel1D(Zsup, V).interp(z, interpmethod="stairs") return depthmodel1D( z, which(np.concatenate(([v1], [v2]), axis=0), axis=0))