def test_forward_3D(self):
        image_folder = "digits/*.jpg"
        z_stack = z + torch.arange(-5, 5, 1) * opt.mm
        wf = opt.Wavefront.from_images(input_path + image_folder, wavelength,
                                       pixel_pitch)

        propagator = opt.FresnelPropagator(z_stack)
        wf_f = propagator.forward(wf)
        wf_b = propagator.backward(wf_f)

        wf.plot(intensity=defaultdict(
            str, save=True, path=output_path + "digits/", title="start_field"))
        wf_f.plot(intensity=defaultdict(str,
                                        save=True,
                                        path=output_path + "digits/",
                                        title="fresnel_propagated"))
        wf_b.plot(intensity=defaultdict(str,
                                        save=True,
                                        path=output_path + "digits/",
                                        title="fresnel_back_propagated"))

        np.testing.assert_array_almost_equal(
            wf.total_intensity, wf_f.total_intensity,
            decimal=1)  # fixme failling with random phase
        self.assertTrue(wf.assert_equal(wf_b))
    def test_forward_backward(self):
        propagator = opt.FresnelPropagator(z)
        wf_f = propagator.forward(wf)
        wf_b = propagator.backward(wf_f)

        wf.plot(intensity=defaultdict(str, title="start_field"))
        wf_f.plot(intensity=defaultdict(str, title="fresnel_propagated"))
        wf_b.plot(intensity=defaultdict(str, title="fresnel_back_propagated"))

        self.assertAlmostEqual(wf.total_intensity,
                               wf_f.total_intensity,
                               delta=1e-1)  # fixme failling with random phase
        self.assertTrue(wf.assert_equal(wf_b))
    def propagate_opto(self, img_name, wavelength, pixel_scale, z):
        wavelength = wavelength * nm
        pixel_scale = (pixel_scale * um, pixel_scale * um)
        z = z * cm

        square_field = opt.Wavefront.from_images(
            input_path + img_name + '.jpg', wavelength, pixel_scale)

        free_space = opt.FresnelPropagator(z)
        f_end = free_space.forward(square_field)

        f_end.plot(intensity=defaultdict(str, title="OPTO"))

        return f_end
    def test_forward_multi_plane(self):
        z_stack = z + torch.arange(-5, 5, 1) * opt.mm

        propagator = opt.FresnelPropagator(z_stack)
        wf_f = propagator.forward(wf)
        wf_b = propagator.backward(wf_f)

        #wf.plot(intensity=defaultdict(str, save=True, path=output_path+"digits/", title="start_field"))
        wf_f.plot(intensity=defaultdict(str,
                                        save=True,
                                        path=output_path + "multiplane/",
                                        title="prop_plane_"))
        wf_b.plot(intensity=defaultdict(str,
                                        save=True,
                                        path=output_path + "multiplane/",
                                        title="back_prop"))