Esempio n. 1
0
 def H(self, pol=None):
     if pol is None:  # For normalization
         cc = sh.SHCoeffs([1, 0, 0, -1 / np.sqrt(5), 0, 0]) / np.sqrt(
             4 * np.pi)
         if self.optical_axis == [1, 0, 0]:  # x-illumination
             cc = cc.rotate()
         return cc
     out = []
     for j in range(6):
         l, m = util.j2lm(j)
         theta, phi = util.xyz2tp(*pol)
         if l == 0:
             cc = 1.0
         else:
             cc = 0.4
         out.append(cc * util.spZnm(l, m, theta, phi))
     return sh.SHCoeffs(out)
Esempio n. 2
0
    def h(self):
        if self.illuminate_all:
            return tf.TFCoeffs([[1.0, 0, 0, 0, 0, 0], 6 * [0], 6 * [0]])

        n0 = [
            1 + (self.alpha**2) / 4, 0, 0,
            (-1 + (self.alpha**2) / 2) / np.sqrt(5), 0, 0
        ]
        n_2 = 6 * [0]
        n2 = 6 * [0]
        if self.polarizer is not None:
            n_2 = [0, np.sqrt(3 / 5), 0, 0, 0, 0]
            n2 = [0, 0, 0, 0, 0, np.sqrt(3 / 5)]
        if self.optical_axis == [1, 0, 0]:  # x-illumination
            n0 = sh.SHCoeffs(n0).rotate().coeffs
            n_2 = sh.SHCoeffs(n_2).rotate().coeffs
            n2 = sh.SHCoeffs(n2).rotate().coeffs

        return tf.TFCoeffs([n0, n_2, n2])
Esempio n. 3
0
    def H(self, x, y, z):
        if self.detect_all:
            return tf.TFCoeffs([[1.0, 0, 0, 0, 0, 0], 6 * [0], 6 * [0]])

        # Find cylindrical coordinates based on view
        if self.optical_axis == [0, 0, 1]:  # z-detection
            nu = np.sqrt(x**2 + y**2)
            phi_nu = np.arctan2(y, x)
            z_ax = z
        elif self.optical_axis == [1, 0, 0]:  # x-detection
            nu = np.sqrt(y**2 + z**2)
            phi_nu = np.arctan2(z, y)
            z_ax = x

        A1 = self.A1
        A2 = self.A2
        n0 = [
            A1(nu) + (self.alpha**2 / 4) * A2(nu), 0, 0,
            (-A1(nu) + (self.alpha**2 / 2) * A2(nu)) / np.sqrt(5), 0, 0
        ]
        n_2 = 6 * [0]
        n2 = 6 * [0]
        if self.polarizer:
            # TODO: Update these (unused for now)
            n_2 = [
                2 * C(nu) * np.sin(2 * phi_nu), -np.sqrt(0.6) * A(nu), 0,
                (4.0 / np.sqrt(5)) * C(nu) * np.sin(2 * phi_nu), 0, 0
            ]
            n2 = [
                2 * C(nu) * np.cos(2 * phi_nu), 0, 0,
                (4.0 / np.sqrt(5)) * C(nu) * np.cos(2 * phi_nu), 0,
                np.sqrt(0.6) * A(nu)
            ]
        if self.optical_axis == [1, 0, 0]:  # x-detection
            n0 = sh.SHCoeffs(n0).rotate().coeffs
            n_2 = sh.SHCoeffs(n_2).rotate().coeffs
            n2 = sh.SHCoeffs(n2).rotate().coeffs

        ax_weight = np.exp(-(z_ax**2) / (2 * (self.sigma_ax**2)))
        return sh.SHCoeffs(n0) * ax_weight
Esempio n. 4
0
    def h(self, x, y, z):
        if self.detect_all:
            return tf.TFCoeffs([[1.0, 0, 0, 0, 0, 0], 6 * [0], 6 * [0]])

        # Find cylindrical coordinates based on view
        if self.optical_axis == [0, 0, 1]:  # z-detection
            r = np.sqrt(x**2 + y**2)
            phi = np.arctan2(y, x)
            z_ax = z
        elif self.optical_axis == [1, 0, 0]:  # x-detection
            r = np.sqrt(y**2 + z**2)
            phi = np.arctan2(z, y)
            z_ax = x

        a1 = self.a1
        a2 = self.a2
        n0 = [
            a1(r) + (self.alpha**2 / 4) * a2(r), 0, 0,
            (-a1(r) + (self.alpha**2 / 2) * a2(r)) / np.sqrt(5), 0, 0
        ]
        n_2 = 6 * [0]
        n2 = 6 * [0]
        if self.polarizer:
            n_2 = [
                2 * a2(r) * np.sin(2 * phi), -np.sqrt(0.6) * a1(r), 0,
                (4.0 / np.sqrt(5)) * a2(r) * np.sin(2 * phi), 0, 0
            ]
            n2 = [
                2 * a2(r) * np.cos(2 * phi), 0, 0,
                (4.0 / np.sqrt(5)) * a2(r) * np.cos(2 * phi), 0,
                np.sqrt(0.6) * a1(r)
            ]
        if self.optical_axis == [1, 0, 0]:  # x-detection
            n0 = sh.SHCoeffs(n0).rotate().coeffs
            n_2 = sh.SHCoeffs(n_2).rotate().coeffs
            n2 = sh.SHCoeffs(n2).rotate().coeffs

        return tf.TFCoeffs([n0, n_2, n2])
Esempio n. 5
0
    def plot_SVS(self,
                 filename='svs.pdf',
                 n_px=2**6,
                 marks=[[1e-5, 0], [0.5, 0], [1.0, 0], [1.5, 0]]):
        print('Plotting: ' + filename)

        # Layout windows
        inches = 1.5
        rows = self.sigma.shape[-1] + 1
        cols = len(marks) + 1
        f, axs = plt.subplots(rows,
                              cols,
                              figsize=(inches * cols, inches * (rows - 0.75)),
                              gridspec_kw={
                                  'hspace': 0.05,
                                  'wspace': 0.10,
                                  'height_ratios': [1, 1, 1, 0.05]
                              })

        # Label top row with arrow
        axs[0, 0].annotate(
            '',
            xy=(-0.03, 1.1),
            xytext=(0.55, 1.1),
            textcoords='axes fraction',
            xycoords='axes fraction',
            ha='center',
            va='center',
            arrowprops=dict(arrowstyle='<->, head_width=0.05, head_length=0.1',
                            connectionstyle="arc3",
                            linewidth=0.5),
        )
        axs[0, 0].annotate(r'$2\textrm{NA}/\lambda$',
                           xy=(0, 0),
                           xytext=(0.25, 1.2),
                           textcoords='axes fraction',
                           xycoords='axes fraction',
                           ha='center',
                           va='center',
                           fontsize=7)

        # Top row singular values
        for j, ax in enumerate(axs[:-1, 0]):
            ax.axis('off')
            ax.annotate('$j=' + str(j) + '$',
                        xy=(1, 1),
                        xytext=(-0.15, 0.5),
                        textcoords='axes fraction',
                        ha='center',
                        va='center',
                        rotation=90)
            extent = [-2, 2, -2, 2]
            origin = 'lower'
            ax.imshow(self.sigma[:, :, j] / self.sigma_max,
                      cmap="bwr",
                      vmin=-1,
                      vmax=1,
                      interpolation='none',
                      extent=extent,
                      origin=origin)
            ax.set_xlim([-2.05, 2.05])
            ax.set_ylim([-2.05, 2.05])
            levels = [-0.1, -1e-5, 1e-5, 0.1]
            ct = ax.contour(self.sigma[:, :, j] / self.sigma_max,
                            levels,
                            colors='k',
                            linewidths=0.5,
                            extent=extent,
                            origin=origin)
            for mark in marks:
                ax.plot(mark[0] * np.cos(mark[1]),
                        mark[0] * np.sin(mark[1]),
                        'xk',
                        ms=2.5,
                        mew=0.5)

        # Colorbars
        X, Y = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100))
        axs[-1, 0].imshow(X,
                          cmap="bwr",
                          vmin=-1,
                          vmax=1,
                          interpolation='none',
                          extent=[0, 1, 0, 1],
                          origin='lower',
                          aspect='auto')
        axs[-1, 0].contour(
            X,
            levels,
            colors='k',
            linewidths=0.5,
            extent=[0, 1, 0, 1],
            origin='lower',
        )
        axs[-1, 0].set_xlim([0, 1])
        axs[-1, 0].set_ylim([0, 1])
        axs[-1, 0].tick_params(direction='out', bottom=True, top=False)
        axs[-1, 0].xaxis.set_ticks([0, 0.5, 1.0])
        axs[-1, 0].yaxis.set_ticks([])
        for j, ax in enumerate(axs[-1, 1:]):
            ax.axis('off')

        # For saving singular function pngs
        folder = 'singular'
        if not os.path.exists(folder):
            os.makedirs(folder)

        # Object space singular functions
        for j, ax in np.ndenumerate(axs[:-1, 1:]):
            if self.det.optical_axis == [0, 0, 1]:  # z-detection
                u, s, v = self.calc_point_SVD(marks[j[1]][0], marks[j[1]][1],
                                              0)
            elif self.det.optical_axis == [1, 0, 0]:  # x-detection
                u, s, v = self.calc_point_SVD(0, marks[j[1]][0],
                                              marks[j[1]][1])

            # Labels
            if j[0] == 0:
                rho_label = str(marks[j[1]][0])
                if marks[j[1]][0] < 1e-3:
                    rho_label = '0'
                ax.annotate(r'$\rho = ' + rho_label + '$',
                            xy=(1, 1),
                            xytext=(0.5, 1.15),
                            textcoords='axes fraction',
                            ha='center',
                            va='center')
                ax.annotate(r'$\phi_{\rho} = ' + str(marks[j[1]][1]) + '$',
                            xy=(1, 1),
                            xytext=(0.5, 0.95),
                            textcoords='axes fraction',
                            ha='center',
                            va='center')
            ax.axis('off')
            ax.annotate('$\sigma=' +
                        '{:.2f}'.format(s[j[0]] / self.sigma_max) + '$',
                        xy=(1, 1),
                        xytext=(0.5, 0),
                        textcoords='axes fraction',
                        ha='center',
                        va='center')

            # Create singular function plots
            sh = shcoeffs.SHCoeffs(u[:, j[0]])
            shfilename = folder + '/' + str(j[0]) + str(j[1]) + '.png'
            sh.plot_dist(filename=folder + '/' + str(j[0]) + str(j[1]) +
                         '.png',
                         r=1.1)

            from PIL import Image
            im1 = np.asarray(Image.open(shfilename))
            ax.imshow(im1, interpolation='none')

        f.savefig(filename, bbox_inches='tight')