Beispiel #1
0
 def update_analizer(d):
     print(d)
     self.pol = np.cos(d / 180 * np.pi), np.sin(d / 180 * np.pi)
     self.ray = field2ray2(self.ifield, pol=self.pol, phi=self.phi)
     im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
     self.imax.set_data(im)
     self.fig.canvas.draw_idle()
Beispiel #2
0
 def calculate_image(self, recalc=False, **params):
     """Calculates RGB image.
     
     Parameters
     ----------
     recalc : bool, optional
         If specified, it forces recalculation. Otherwise, result is calculated
         only if calculation parameters have changed.
     params: keyword arguments
         Any additional keyword arguments that are passed dirrectly to 
         set_parameters method.
         
     """
     specter = self.calculate_specter(recalc, **params)
     if recalc or "intensity" in self._updated_parameters:
         if self.intensity is not None:
             if self.mode == "r":
                 norm = -1. / self.intensity
             else:
                 norm = 1. / self.intensity
             self.image = specter2color(specter,
                                        self.cmf,
                                        norm=norm,
                                        gamma=self.gamma,
                                        gray=self.gray)
         else:
             if self.mode == "r":
                 self.image = specter2color(specter,
                                            self.cmf,
                                            norm=-1.,
                                            gamma=self.gamma,
                                            gray=self.gray)
             else:
                 self.image = specter2color(specter,
                                            self.cmf,
                                            gamma=self.gamma,
                                            gray=self.gray)
         if self.sample != 0 and self.sample is not None:
             self.image = nd.rotate(self.image,
                                    self.sample,
                                    reshape=False,
                                    order=1)
     self._updated_parameters.clear()
     return self.image
Beispiel #3
0
        def update_polarizer(d):
            self.polarizer = np.cos(d / 180 * np.pi), np.sin(d / 180 * np.pi)
            field = [
                self.ixfield[i] * self.polarizer[0] +
                self.iyfield[i] * self.polarizer[1] for i in range(self.n)
            ]
            self.ray = field2ray(field, pol=self.analizer, phi=self.phi)

            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()
Beispiel #4
0
 def update_focus(d):
     self.ifield = ipropagate2(self.field,
                               d=d,
                               refind=self.refind,
                               beta=self.beta,
                               phi=self.phi,
                               k0=self.k0,
                               nstep=self.nstep,
                               select="forward")
     self.ray = field2ray2(self.ifield, pol=self.pol, phi=self.phi)
     im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
     self.imax.set_data(im)
     self.fig.canvas.draw_idle()
Beispiel #5
0
        def update_focus(d):
            self.ixfield = ipropagate(self.xfield,
                                      d=d,
                                      refind=self.refind,
                                      beta=self.beta,
                                      phi=self.phi,
                                      k0=self.k0,
                                      nstep=self.nstep)
            self.iyfield = ipropagate(self.yfield,
                                      d=d,
                                      refind=self.refind,
                                      beta=self.beta,
                                      phi=self.phi,
                                      k0=self.k0,
                                      nstep=self.nstep)
            field = [
                self.ixfield[i] * self.polarizer[0] +
                self.iyfield[i] * self.polarizer[1] for i in range(self.n)
            ]
            self.ray = field2ray(field, pol=self.analizer, phi=self.phi)

            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()
Beispiel #6
0
 def update_light(d):
     self.intensity = d
     im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
     self.imax.set_data(im)
     self.fig.canvas.draw_idle()
Beispiel #7
0
    def __init__(self,
                 field,
                 refind=1.5,
                 beta=0.,
                 phi=0.,
                 k0=[1],
                 nstep=16,
                 maxfocus=100):
        self.field = field
        self.pol = (1, 0)
        self.refind = refind
        self.beta = beta
        self.phi = phi
        self.k0 = k0
        self.nstep = nstep
        self.intensity = 1.
        self.cmf = load_tcmf()

        self.fig, self.ax1 = plt.subplots()

        plt.subplots_adjust(bottom=0.25)

        self.ifield = field
        self.ray = field2ray2(field, pol=self.pol, phi=self.phi)
        im = specter2color(self.ray, self.cmf, norm=self.intensity)
        self.imax = self.ax1.imshow(im)  #, animated=True)

        self.axfocus = plt.axes([0.25, 0.15, 0.65, 0.03])
        self.axanalizer = plt.axes([0.25, 0.10, 0.65, 0.03])
        self.axintensity = plt.axes([0.25, 0.05, 0.65, 0.03])
        self.sfocus = Slider(self.axfocus,
                             "focus",
                             -maxfocus,
                             maxfocus,
                             valinit=0.,
                             valfmt='%.1f')
        self.sintensity = Slider(self.axintensity,
                                 "light",
                                 0,
                                 10,
                                 valinit=1.,
                                 valfmt='%.1f')
        self.sanalizer = Slider(self.axanalizer,
                                "analizer",
                                -180,
                                180,
                                valinit=0,
                                valfmt='%.1f')

        def update_focus(d):
            self.ifield = ipropagate2(self.field,
                                      d=d,
                                      refind=self.refind,
                                      beta=self.beta,
                                      phi=self.phi,
                                      k0=self.k0,
                                      nstep=self.nstep,
                                      select="forward")
            self.ray = field2ray2(self.ifield, pol=self.pol, phi=self.phi)
            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()

        def update_light(d):
            self.intensity = d
            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()

        def update_analizer(d):
            print(d)
            self.pol = np.cos(d / 180 * np.pi), np.sin(d / 180 * np.pi)
            self.ray = field2ray2(self.ifield, pol=self.pol, phi=self.phi)
            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()

        self.ids1 = self.sfocus.on_changed(update_focus)
        self.ids2 = self.sintensity.on_changed(update_light)
        self.ids3 = self.sanalizer.on_changed(update_analizer)
Beispiel #8
0
    def __init__(self,
                 xfield,
                 yfield,
                 refind=1.5,
                 beta=0.,
                 phi=0.,
                 k0=[1],
                 nstep=16,
                 maxfocus=100):
        self.xfield = xfield
        self.yfield = yfield
        self.analizer = (0, 1)
        self.polarizer = (1, 0)
        self.refind = refind
        self.beta = beta
        self.phi = phi
        self.k0 = k0
        self.nstep = nstep
        self.intensity = 1.
        self.cmf = load_tcmf()
        self.n = len(xfield)

        self.fig, self.ax1 = plt.subplots()

        plt.subplots_adjust(bottom=0.25)

        self.ixfield = xfield
        self.iyfield = yfield
        self.xray = field2ray(xfield, pol=self.analizer, phi=self.phi)
        self.yray = field2ray(yfield, pol=self.analizer, phi=self.phi)
        self.ray = [
            self.xray[i] * self.polarizer[0] + self.yray[i] * self.polarizer[1]
            for i in range(self.n)
        ]

        im = specter2color(self.ray, self.cmf, norm=self.intensity)
        self.imax = self.ax1.imshow(im)  #, animated=True)

        self.axfocus = plt.axes([0.25, 0.14, 0.65, 0.03])
        self.axanalizer = plt.axes([0.25, 0.10, 0.65, 0.03])
        self.axpolarizer = plt.axes([0.25, 0.06, 0.65, 0.03])
        self.axintensity = plt.axes([0.25, 0.02, 0.65, 0.03])
        self.sfocus = Slider(self.axfocus,
                             "focus",
                             -maxfocus,
                             maxfocus,
                             valinit=0.,
                             valfmt='%.1f')
        self.sintensity = Slider(self.axintensity,
                                 "light",
                                 0,
                                 10,
                                 valinit=1.,
                                 valfmt='%.1f')
        self.sanalizer = Slider(self.axanalizer,
                                "analizer",
                                -180,
                                180,
                                valinit=0,
                                valfmt='%.1f')
        self.spolarizer = Slider(self.axpolarizer,
                                 "polarizer",
                                 -180,
                                 180,
                                 valinit=0,
                                 valfmt='%.1f')

        def update_focus(d):
            self.ixfield = ipropagate(self.xfield,
                                      d=d,
                                      refind=self.refind,
                                      beta=self.beta,
                                      phi=self.phi,
                                      k0=self.k0,
                                      nstep=self.nstep)
            self.iyfield = ipropagate(self.yfield,
                                      d=d,
                                      refind=self.refind,
                                      beta=self.beta,
                                      phi=self.phi,
                                      k0=self.k0,
                                      nstep=self.nstep)
            field = [
                self.ixfield[i] * self.polarizer[0] +
                self.iyfield[i] * self.polarizer[1] for i in range(self.n)
            ]
            self.ray = field2ray(field, pol=self.analizer, phi=self.phi)

            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()

        def update_light(d):
            self.intensity = d
            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()

        def update_analizer(d):
            self.analizer = np.cos(d / 180 * np.pi), np.sin(d / 180 * np.pi)
            field = [
                self.ixfield[i] * self.polarizer[0] +
                self.iyfield[i] * self.polarizer[1] for i in range(self.n)
            ]
            self.ray = field2ray(field, pol=self.analizer, phi=self.phi)

            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()

        def update_polarizer(d):
            self.polarizer = np.cos(d / 180 * np.pi), np.sin(d / 180 * np.pi)
            field = [
                self.ixfield[i] * self.polarizer[0] +
                self.iyfield[i] * self.polarizer[1] for i in range(self.n)
            ]
            self.ray = field2ray(field, pol=self.analizer, phi=self.phi)

            im = specter2color(self.ray, self.cmf, norm=1. / self.intensity)
            self.imax.set_data(im)
            self.fig.canvas.draw_idle()

        self.ids1 = self.sfocus.on_changed(update_focus)
        self.ids2 = self.sintensity.on_changed(update_light)
        self.ids3 = self.sanalizer.on_changed(update_analizer)
        self.ids4 = self.spolarizer.on_changed(update_polarizer)
Beispiel #9
0
im = np.zeros(shape=(ni, nw, 3))

subplots = [plt.subplot(i) for i in (311, 312, 313)]
intensities = np.linspace(0, 1.5, ni)

for k, delta in enumerate((50, 150, 400)):
    ax = subplots[k]
    ax.set_title("D65 + {} nm bandwidth filter".format(delta))

    for i, w in enumerate(ws):
        for j, intensity in enumerate(intensities):
            s = np.zeros(shape=(nw, ), dtype=dtmm.conf.FDTYPE)
            mask = (ws < w + delta / 2.) & (ws > w - delta / 2.)
            s[mask] = intensity  #make band-pass specter
            im[j, i] = dc.specter2color(s, cmf)
#
#    mask = (im[...,0] == 1.) |(im[...,1] == 1.) | (im[...,2] == 1. )
#    im[mask,:]= np.nan

    ax.imshow(im, origin="lower")

    ax.set_xticks([])
    ax.set_yticks(range(ni)[::20])
    ax.set_yticklabels(intensities[::20])
    ax.set_ylabel("intensity [arb.]")

ax.set_xticks(range(nw)[::20])
ax.set_xticklabels(ws[::20])
ax.set_xlabel("Band-pass filter central wavelength [nm]")
plt.show()