Example #1
0
    def get_target(self):
        gE, gN = self.get_grid()
        mask = self.get_mask()

        east_shifts = gE[mask].ravel()
        north_shifts = gN[mask].ravel()
        llLat, llLon = self.get_ll_anchor()

        ncoords = east_shifts.size

        theta, phi = self.get_incident_angles()

        theta = theta[mask].ravel()
        phi = phi[mask].ravel()

        if ncoords == 0:
            logger.warning('InSAR taget has no valid points,'
                           ' maybe it\'s all water?')
            return

        return self.SatelliteGeneratorTarget(
            scene_patch=self,
            lats=num_full(ncoords, fill_value=llLat),
            lons=num_full(ncoords, fill_value=llLon),
            east_shifts=east_shifts,
            north_shifts=north_shifts,
            theta=theta,
            phi=phi)
Example #2
0
    def __init__(self, scene, **kwargs):
        size = scene.displacement.size

        if scene.frame.spacing == 'meter':
            lats = num_full(size, scene.frame.llLat)
            lons = num_full(size, scene.frame.llLon)
            north_shifts = scene.frame.gridN.data.flatten()
            east_shifts = scene.frame.gridE.data.flatten()

        elif scene.frame.spacing == 'degree':
            lats = scene.frame.gridN.data.flatten() + scene.frame.llLat
            lons = scene.frame.gridE.data.flatten() + scene.frame.llLon
            north_shifts = num.zeros(size)
            east_shifts = num.zeros(size)

        self.scene = scene

        super(KiteSceneTarget, self).__init__(lats=lats,
                                              lons=lons,
                                              north_shifts=north_shifts,
                                              east_shifts=east_shifts,
                                              theta=scene.theta.flatten(),
                                              phi=scene.phi.flatten(),
                                              shape=scene.shape,
                                              **kwargs)
Example #3
0
    def get_target(self):
        gE, gN = self.get_grid()
        mask = self.get_mask()

        east_shifts = gE[mask].ravel()
        north_shifts = gN[mask].ravel()
        llLat, llLon = self.get_ll_anchor()

        ncoords = east_shifts.size

        theta, phi = self.get_incident_angles()

        theta = theta[mask].ravel()
        phi = phi[mask].ravel()

        if ncoords == 0:
            logger.warning('InSAR taget has no valid points,'
                           ' maybe it\'s all water?')
            return

        return self.SatelliteGeneratorTarget(scene_patch=self,
                                             lats=num_full(ncoords,
                                                           fill_value=llLat),
                                             lons=num_full(ncoords,
                                                           fill_value=llLon),
                                             east_shifts=east_shifts,
                                             north_shifts=north_shifts,
                                             theta=theta,
                                             phi=phi)
Example #4
0
def mts2amps(mts,
             projection,
             beachball_type,
             grid_resolution=200,
             mask=True,
             view='top'):

    n_balls = len(mts)
    nx = grid_resolution
    ny = grid_resolution

    x = num.linspace(-1., 1., nx)
    y = num.linspace(-1., 1., ny)

    vecs2 = num.zeros((nx * ny, 2), dtype=num.float64)
    vecs2[:, 0] = num.tile(x, ny)
    vecs2[:, 1] = num.repeat(y, nx)

    ii_ok = vecs2[:, 0]**2 + vecs2[:, 1]**2 <= 1.0
    amps = num_full(nx * ny, num.nan, dtype=num.float64)

    amps[ii_ok] = 0.
    for mt in mts:
        mt = deco_part(mt, beachball_type, view)

        ep, en, et, vp, vn, vt = mt.eigensystem()

        vecs3_ok = inverse_project(vecs2[ii_ok, :], projection)

        to_e = num.vstack((vn, vt, vp))

        vecs_e = num.dot(to_e, vecs3_ok.T).T
        rtp = numpy_xyz2rtp(vecs_e)

        atheta, aphi = rtp[:, 1], rtp[:, 2]
        amps_ok = ep * num.cos(atheta)**2 + (
            en * num.cos(aphi)**2 + et * num.sin(aphi)**2) * num.sin(atheta)**2

        if mask:
            amps_ok[amps_ok > 0] = 1.
            amps_ok[amps_ok < 0] = 0.

        amps[ii_ok] += amps_ok

    return num.reshape(amps, (ny, nx)) / n_balls, x, y
Example #5
0
def mts2amps(mts, projection, beachball_type, grid_resolution=200, mask=True):

    n_balls = len(mts)
    nx = grid_resolution
    ny = grid_resolution

    x = num.linspace(-1., 1., nx)
    y = num.linspace(-1., 1., ny)

    vecs2 = num.zeros((nx * ny, 2), dtype=num.float)
    vecs2[:, 0] = num.tile(x, ny)
    vecs2[:, 1] = num.repeat(y, nx)

    ii_ok = vecs2[:, 0]**2 + vecs2[:, 1]**2 <= 1.0
    amps = num_full(nx * ny, num.nan, dtype=num.float)

    amps[ii_ok] = 0.
    for mt in mts:
        mt = deco_part(mt, beachball_type)

        ep, en, et, vp, vn, vt = mt.eigensystem()

        vecs3_ok = inverse_project(vecs2[ii_ok, :], projection)

        to_e = num.vstack((vn, vt, vp))

        vecs_e = num.dot(to_e, vecs3_ok.T).T
        rtp = numpy_xyz2rtp(vecs_e)

        atheta, aphi = rtp[:, 1], rtp[:, 2]
        amps_ok = ep * num.cos(atheta)**2 + (
            en * num.cos(aphi)**2 + et * num.sin(aphi)**2) * num.sin(atheta)**2

        if mask:
            amps_ok[amps_ok > 0] = 1.
            amps_ok[amps_ok < 0] = 0.

        amps[ii_ok] += amps_ok

    return num.reshape(amps, (ny, nx)) / n_balls, x, y
Example #6
0
    def draw_figures(self, ds, history, optimiser):
        show_mean_residuals = False

        # gms = history.get_sorted_primary_misfits()[::-1]
        models = history.get_sorted_primary_models()[::-1]
        problem = history.problem

        targets = [
            t for t in problem.targets if isinstance(t, PhasePickTarget)
        ]

        # targets.sort(key=lambda t: t.distance_to(problem.base_source))
        # tpaths = sorted(set(t.path for t in targets))

        ntargets = len(targets)
        nmodels = history.nmodels
        tts = num.zeros((nmodels, ntargets, 2))
        distances = num.zeros((nmodels, ntargets))
        azimuths = num.zeros((nmodels, ntargets))

        for imodel in range(nmodels):
            model = models[imodel, :]
            source = problem.get_source(model)
            results = problem.evaluate(model, targets=targets)
            for itarget, result in enumerate(results):
                result = results[itarget]
                tts[imodel, itarget, :] = result.tobs, result.tsyn
                distances[imodel,
                          itarget] = source.distance_to(targets[itarget])

                azimuths[imodel,
                         itarget] = source.azibazi_to(targets[itarget])[0]

        ok = num.all(num.isfinite(tts), axis=2)
        ok = num.all(ok, axis=0)

        targets = [
            target for (itarget, target) in enumerate(targets) if ok[itarget]
        ]
        tts = tts[:, ok, :]
        distances = distances[:, ok]
        azimuths = azimuths[:, ok]
        residuals = tts[:, :, 0] - tts[:, :, 1]
        residual_amax = num.max(num.abs(residuals))
        mean_residuals = num.mean(residuals, axis=0)
        mean_distances = num.mean(distances, axis=0)

        isort = num.array([
            x[2]
            for x in sorted(zip(targets, mean_distances, range(len(targets))),
                            key=lambda x: (x[0].path, x[1]))
        ],
                          dtype=num.int)

        distances = distances[:, isort]
        distance_min = num.min(distances)
        distance_max = num.max(distances)
        azimuths = azimuths[:, isort]
        targets = [targets[i] for i in isort]
        ntargets = len(targets)
        residuals = residuals[:, isort]
        mean_residuals = mean_residuals[isort]

        icolor = num.arange(nmodels)

        norm = mcolors.Normalize(vmin=num.min(icolor), vmax=num.max(icolor))
        cmap = plt.get_cmap('coolwarm')

        napprox = max(1, int(round(
            (self.size_points[1] / self.font_size - 7))))

        npages = (ntargets - 1) // napprox + 1
        ntargets_page = (ntargets - 1) // npages + 1

        for ipage in range(npages):

            ilo, ihi = ipage * ntargets_page, (ipage + 1) * ntargets_page
            ihi = min(len(targets), ihi)

            targets_page = targets[ilo:ihi]
            item = PlotItem(name='fig_%02i' % ipage)

            item.attributes['targets'] = [t.string_id() for t in targets_page]

            fig = plt.figure(figsize=self.size_inch)

            labelpos = mpl_margins(fig,
                                   nw=2,
                                   nh=1,
                                   left=12.,
                                   right=1.,
                                   bottom=5.,
                                   top=1.,
                                   wspace=1.,
                                   units=self.font_size)

            axes1 = fig.add_subplot(1, 3, 1)
            axes2 = fig.add_subplot(1, 3, 2)
            axes3 = fig.add_subplot(1, 3, 3)

            for axes in (axes1, axes2, axes3):
                axes.set_ylim(-0.5, len(targets_page) - 0.5)
                axes.invert_yaxis()
                labelpos(axes, 2.5, 2.0)

            axes1.axvline(0.0, color='black')

            labels = []
            lastpath = None
            for ipos, t in enumerate(targets_page):
                scodes = '.'.join(t.codes)
                if lastpath is None or lastpath != t.path:
                    labels.append(t.path + '.' + scodes)
                    if lastpath is not None:
                        for axes in (axes1, axes2, axes3):
                            axes.axhline(ipos - 0.5, color='black')
                else:
                    labels.append(scodes)

                lastpath = t.path

            for ipos, itarget in enumerate(range(ilo, ihi)):
                axes1.plot(residuals[-1, itarget],
                           ipos,
                           '|',
                           ms=self.font_size,
                           color='black')

                if show_mean_residuals:
                    axes1.plot(mean_residuals[itarget],
                               ipos,
                               's',
                               ms=self.font_size,
                               color='none',
                               mec='black')

                axes1.scatter(residuals[::10, itarget],
                              util.num_full(icolor[::10].size,
                                            ipos,
                                            dtype=num.float),
                              c=icolor[::10],
                              cmap=cmap,
                              norm=norm,
                              alpha=0.5)

                axes2.scatter(distances[::10, itarget] / km,
                              util.num_full(icolor[::10].size,
                                            ipos,
                                            dtype=num.float),
                              c=icolor[::10],
                              cmap=cmap,
                              norm=norm,
                              alpha=0.5)

                axes3.scatter(azimuths[::10, itarget],
                              util.num_full(icolor[::10].size,
                                            ipos,
                                            dtype=num.float),
                              c=icolor[::10],
                              cmap=cmap,
                              norm=norm,
                              alpha=0.5)

            axes1.set_yticks(num.arange(len(labels)))
            axes1.set_yticklabels(labels)
            axes1.set_xlabel('$T_{obs} - T_{syn}$ [s]')
            axes1.set_xlim(-residual_amax, residual_amax)

            axes2.set_xlabel('Distance [km]')
            axes2.set_xlim(distance_min / km, distance_max / km)

            axes3.set_xlabel('Azimuth [deg]')
            axes3.set_xlim(-180., 180.)

            axes2.get_yaxis().set_ticks([])
            axes2.get_yaxis().set_ticks([])

            axes3.get_yaxis().set_ticks([])
            axes3.get_yaxis().set_ticks([])

            yield item, fig