Ejemplo n.º 1
0
    def update_models(self, model, vpvs):
        logger.debug('### Found new chain model')
        vp, vs, dep = Model.get_stepmodel(model, vpvs=vpvs, mantle=self.mantle)

        self.vs_step = np.roll(self.vs_step, -1, axis=0)  # rolling up models
        nantmp = np.ones(self.modellength) * np.nan
        nantmp[:vs.size] = vs
        self.vs_step[-1] = nantmp

        self.dep_step = np.roll(self.dep_step, -1, axis=0)  # rolling up models
        nantmp = np.ones(self.modellength) * np.nan
        nantmp[:dep.size] = dep
        self.dep_step[-1] = nantmp

        vp, vs, h = Model.get_vp_vs_h(model, vpvs=vpvs, mantle=self.mantle)
        ymod = self.compute_synth(h, vs, vp)

        for i, tline in enumerate(self.targetlines):
            if tline is not None:
                tline.set_ydata(ymod[i])

        # # create LineCollection
        segments = [
            np.column_stack([x, y])
            for x, y in zip(self.vs_step, self.dep_step)
        ]
        self.modelcollection.set_segments(segments)
        a = np.repeat(([0, 1], ), self.capacity, axis=0)
        b = np.array([[v] * 2 for v in self.vpvss])
        segments = [np.column_stack([x, y]) for x, y in zip(b, a)]
        self.vpvscollection.set_segments(segments)
Ejemplo n.º 2
0
    def update_chain(self):
        print('New chain index:', self.chainidx)

        # if new chain is chosen
        self.modelmatrix, self.likes, self.noises, self.vpvss = self.chainarrays[
            self.chainidx]
        nantmp = np.ones(self.modellength) * np.nan

        # reset vs and dep matrix to nan
        self.vs_step = np.ones((self.capacity, self.modellength)) * np.nan
        self.dep_step = np.ones((self.capacity, self.modellength)) * np.nan

        for i, model in enumerate(self.modelmatrix):
            # if nan model, the first element is also nan !
            if ~np.isnan(model[0]):
                vp, vs, dep = Model.get_stepmodel(model,
                                                  vpvs=self.vpvss[i],
                                                  mantle=self.mantle)
                dep[-1] = self.priors['z'][-1] * 1.5

                self.vs_step = np.roll(self.vs_step, -1,
                                       axis=0)  # rolling up models
                vs = nantmp[:vs.size] = vs
                self.vs_step[-1][:vs.size] = vs

                self.dep_step = np.roll(self.dep_step, -1,
                                        axis=0)  # rolling up models
                dep = nantmp[:dep.size] = dep
                self.dep_step[-1][:dep.size] = dep

                # update title
                self.axes[0].set_title('Chain %d' % self.chainidx)

                lastmodel = model
                lastvpvs = self.vpvss[-1]

        # immediately update data fit lines
        vp, vs, h = Model.get_vp_vs_h(lastmodel,
                                      vpvs=lastvpvs,
                                      mantle=self.mantle)
        ymod = self.compute_synth(h, vs, vp)

        for i, tline in enumerate(self.targetlines):
            if tline is not None:
                tline.set_ydata(ymod[i])

        # # create LineCollection and update velocity models
        segments = [
            np.column_stack([x, y])
            for x, y in zip(self.vs_step, self.dep_step)
        ]
        self.modelcollection.set_segments(segments)
        self.likeline.set_ydata(self.likes)
        self.axes[3].set_ylim(
            [np.nanmin(self.likes) * 0.999,
             np.nanmax(self.likes) * 1.001])

        # vpvs
        a = np.repeat(([0, 1], ), self.capacity, axis=0)
        b = np.array([[v] * 2 for v in self.vpvss])
        segments = [np.column_stack([x, y]) for x, y in zip(b, a)]
        self.vpvscollection.set_segments(segments)

        for i, sline in enumerate(self.sigmalines):
            if sline is not None:
                ref = self.targetrefs[i]
                idx = self.targetrefs.index(ref)
                sline.set_ydata(self.noises.T[1::2][idx])

        self.axes[4].set_ylim([
            np.nanmin(self.noises.T[1::2]) * 0.98,
            np.nanmax(self.noises.T[1::2]) * 1.02
        ])
        self.fig.canvas.draw_idle()