Ejemplo n.º 1
0
def calc_scatter_vals(coeffs,
                      n_strips=21,
                      n_proc=4,
                      ax_clip=AX_CLIP,
                      az_clip=AZ_CLIP,
                      ifuncs=ifuncs):
    out = {'input': {}, 'corr': {}}
    theta_max = 2.55e-4
    thetas = np.linspace(-theta_max, theta_max, 10001)  # 10001
    out['theta'] = thetas

    row_slice = slice(ax_clip, N_AX - ax_clip)
    col_slice = slice(az_clip, N_AZ - az_clip)

    # Compute the column position of axial strips
    displ = displ_x_all[row_slice, col_slice]
    cols = np.linspace(0, displ.shape[1], n_strips + 1).astype(int)
    cols = (cols[1:] + cols[:-1]) // 2
    out['cols'] = cols

    print('Calculating scatter displ (input)')
    theta_arcs, scatter = calc_scatter.calc_scatter(displ[:, cols],
                                                    graze_angle=1.428,
                                                    thetas=thetas,
                                                    n_proc=n_proc)
    print np.std(scatter), np.sum(scatter), np.std(displ[:, cols])
    figure(1)
    clf()
    plot(theta_arcs, scatter)
    scat = out['input']
    scat['img'] = displ.copy()
    scat['vals'] = scatter
    stats = calc_scatter_stats(theta_arcs, scatter)
    scat.update(stats)

    print('Calculating scatter displ (corrected)')
    adj_displ_all = calc_adj_displ(ifuncs, coeffs)
    adj_displ = adj_displ_all[row_slice, col_slice]
    resid = adj_displ - displ

    theta_arcs, scatter = calc_scatter.calc_scatter(resid[:, cols],
                                                    graze_angle=1.428,
                                                    thetas=thetas,
                                                    n_proc=n_proc)
    print np.std(scatter), np.sum(scatter), np.std(displ[:, cols])
    plot(theta_arcs, scatter)
    scat = out['corr']
    scat['img'] = adj_displ.copy()
    scat['vals'] = scatter
    stats = calc_scatter_stats(theta_arcs, scatter)
    scat.update(stats)

    return out
Ejemplo n.º 2
0
def calc_scatter(displ, n_strips=20, ax_clip=None, az_clip=None, n_proc=None):
    """
    Calculate the scatter intensity curve for given input displacement.

    :param displ: displacement image (e.g. residual or figure error)
    :param n_strips: number of evenly spaced strips for scatter intensity
    :param ax_clip: pixels to clip in axial direction
    :param az_clip: pixels to clip in azimuthal direction
    :param n_proc: number of processors to use (do not set in IPython notebook)
    """
    import calc_scatter
    ax_slice, az_slice = get_ax_az_slice((ax_clip, az_clip))
    displ = displ[ax_slice, az_slice]

    theta_max = 2.55e-4
    thetas = np.linspace(-theta_max, theta_max, 10001)  # 10001

    cols = np.linspace(0, displ.shape[1], n_strips + 1).astype(int)
    cols = (cols[1:] + cols[:-1]) // 2

    if not n_proc:
        logger.info('Calculating scatter intensity')
    displ_cols = displ[:, cols]

    thetas, scatter = calc_scatter.calc_scatter(displ_cols,
                                                graze_angle=1.428,
                                                thetas=thetas,
                                                n_proc=n_proc)
    if not n_proc:
        logger.info('Finished calculating scatter intensity')
    stats = calc_scatter_stats(thetas, scatter)
    stats['theta'] = thetas
    stats['scatter'] = scatter

    return stats
Ejemplo n.º 3
0
def calc_scatter_vals(coeffs, n_strips=21, n_proc=4, ax_clip=AX_CLIP,
                      az_clip=AZ_CLIP, ifuncs=ifuncs):
    out = {'input': {}, 'corr': {}}
    theta_max = 2.55e-4
    thetas = np.linspace(-theta_max, theta_max, 10001)  # 10001
    out['theta'] = thetas

    row_slice = slice(ax_clip, N_AX - ax_clip)
    col_slice = slice(az_clip, N_AZ - az_clip)

    # Compute the column position of axial strips
    displ = displ_x_all[row_slice, col_slice]
    cols = np.linspace(0, displ.shape[1], n_strips + 1).astype(int)
    cols = (cols[1:] + cols[:-1]) // 2
    out['cols'] = cols

    print('Calculating scatter displ (input)')
    theta_arcs, scatter = calc_scatter.calc_scatter(
        displ[:, cols], graze_angle=1.428, thetas=thetas, n_proc=n_proc)
    print np.std(scatter), np.sum(scatter), np.std(displ[:, cols])
    figure(1)
    clf()
    plot(theta_arcs, scatter)
    scat = out['input']
    scat['img'] = displ.copy()
    scat['vals'] = scatter
    stats = calc_scatter_stats(theta_arcs, scatter)
    scat.update(stats)

    print('Calculating scatter displ (corrected)')
    adj_displ_all = calc_adj_displ(ifuncs, coeffs)
    adj_displ = adj_displ_all[row_slice, col_slice]
    resid = adj_displ - displ

    theta_arcs, scatter = calc_scatter.calc_scatter(
        resid[:, cols], graze_angle=1.428, thetas=thetas, n_proc=n_proc)
    print np.std(scatter), np.sum(scatter), np.std(displ[:, cols])
    plot(theta_arcs, scatter)
    scat = out['corr']
    scat['img'] = adj_displ.copy()
    scat['vals'] = scatter
    stats = calc_scatter_stats(theta_arcs, scatter)
    scat.update(stats)

    return out
Ejemplo n.º 4
0
    def calc_scatter(self, filename=None, calc_input=True):
        theta_max = 2.55e-4
        self.thetas = np.linspace(-theta_max, theta_max, 10001)  # 10001

        # Compute the column position of axial strips
        displ = self.displ['X']['img']['clip']
        cols = np.linspace(0, displ.shape[1], self.n_strips + 1).astype(int)
        cols = (cols[1:] + cols[:-1]) // 2
        self.scatter['cols'] = cols

        if calc_input:
            logging.info('Calculating scatter displ (input)')
            displ = self.displ['X']['img']['clip'][:, cols]
            thetas, scatter = calc_scatter.calc_scatter(
                displ, graze_angle=1.428, thetas=self.thetas,
                n_proc=self.n_proc)
            scat = self.scatter['input']
            scat['img'] = displ.copy()
            scat['theta'] = thetas
            scat['vals'] = scatter
            hpd, rmsd = calc_scatter_stats(thetas, scatter)
            scat['hpd'] = hpd
            scat['rmsd'] = rmsd

        for corr in self.corr_axes:
            logging.info('Calculating scatter displ (corrected)')
            displ = self.resid['X'][corr]['img']['clip'][:, cols]
            if self.piston_tilt:  # Remove piston and tilt
                remove_piston_tilt(displ)

            thetas, scatter = calc_scatter.calc_scatter(displ,
                                                        graze_angle=1.428,
                                                        thetas=self.thetas,
                                                        n_proc=self.n_proc)
            scat = self.scatter['corr'][corr]
            scat['img'] = displ.copy()
            scat['theta'] = thetas
            scat['vals'] = scatter
            hpd, rmsd = calc_scatter_stats(thetas, scatter)
            scat['hpd'] = hpd
            scat['rmsd'] = rmsd
Ejemplo n.º 5
0
    def calc_scatter(self, filename=None, calc_input=True):
        theta_max = 2.55e-4
        self.thetas = np.linspace(-theta_max, theta_max, 10001)  # 10001

        # Compute the column position of axial strips
        displ = self.displ['X']['img']['clip']
        cols = np.linspace(0, displ.shape[1], self.n_strips + 1).astype(int)
        cols = (cols[1:] + cols[:-1]) // 2
        self.scatter['cols'] = cols

        if calc_input:
            logging.info('Calculating scatter displ (input)')
            displ = self.displ['X']['img']['clip'][:, cols]
            thetas, scatter = calc_scatter.calc_scatter(displ,
                                                        graze_angle=1.428,
                                                        thetas=self.thetas,
                                                        n_proc=self.n_proc)
            scat = self.scatter['input']
            scat['img'] = displ.copy()
            scat['theta'] = thetas
            scat['vals'] = scatter
            stats = calc_scatter_stats(thetas, scatter)
            scat.update(stats)

        for corr in self.corr_axes:
            logging.info('Calculating scatter displ (corrected)')
            displ = self.resid['X'][corr]['img']['clip'][:, cols]
            if self.piston_tilt:  # Remove piston and tilt
                remove_piston_tilt(displ)

            thetas, scatter = calc_scatter.calc_scatter(displ,
                                                        graze_angle=1.428,
                                                        thetas=self.thetas,
                                                        n_proc=self.n_proc)
            scat = self.scatter['corr'][corr]
            scat['img'] = displ.copy()
            scat['theta'] = thetas
            scat['vals'] = scatter
            stats = calc_scatter_stats(thetas, scatter)
            scat.update(stats)
Ejemplo n.º 6
0
    def calc_scatter(self, filename=None, calc_input=True):
        theta_max = 2.55e-4
        self.thetas = np.linspace(-theta_max, theta_max, 10001)  # 10001

        # Compute the column position of axial strips
        displ = self.displ["X"]["img"]["clip"]
        cols = np.linspace(0, displ.shape[1], self.n_strips + 1).astype(int)
        cols = (cols[1:] + cols[:-1]) // 2
        self.scatter["cols"] = cols

        if calc_input:
            logging.info("Calculating scatter displ (input)")
            displ = self.displ["X"]["img"]["clip"][:, cols]
            thetas, scatter = calc_scatter.calc_scatter(
                displ, graze_angle=1.428, thetas=self.thetas, n_proc=self.n_proc
            )
            scat = self.scatter["input"]
            scat["img"] = displ.copy()
            scat["theta"] = thetas
            scat["vals"] = scatter
            stats = calc_scatter_stats(thetas, scatter)
            scat.update(stats)

        for corr in self.corr_axes:
            logging.info("Calculating scatter displ (corrected)")
            displ = self.resid["X"][corr]["img"]["clip"][:, cols]
            if self.piston_tilt:  # Remove piston and tilt
                remove_piston_tilt(displ)

            thetas, scatter = calc_scatter.calc_scatter(
                displ, graze_angle=1.428, thetas=self.thetas, n_proc=self.n_proc
            )
            scat = self.scatter["corr"][corr]
            scat["img"] = displ.copy()
            scat["theta"] = thetas
            scat["vals"] = scatter
            stats = calc_scatter_stats(thetas, scatter)
            scat.update(stats)