Esempio n. 1
0
    def test_GaN_synthetic_empty(self):
        # Reconstruct empty for displacements
        empty_param = self.default_GaN_param()
        del empty_param["object_names"]
        carrier = (np.array(empty_param["sideband_pos"], dtype=float) - 1024) / 2048
        carrier /= np.dot(carrier, carrier)
        reconstruct_average(empty_param, verbose=self.VERBOSE)
        with h5py.File(empty_param["output"], "r") as output:
            empty = output["empty"][...]

        # Create displacements from empty hologram
        shift = np.angle(rescale_fourier(empty, (2048, 2048))) / 2.0 / np.pi
        displacement_file = self.touch_temp_output()
        with h5py.File(displacement_file, "w") as output:
            output.create_dataset("dx", data=shift * carrier[0])
            output.create_dataset("dy", data=shift * carrier[1])

        # Reconstruct data
        object_param = self.default_GaN_param()
        object_param["empty_names"] = "/dev/null/some_invalid_filename"
        object_param["empty_override"] = "/dev/null/some_invalid_filename"
        object_param["synthesize_empty"] = True
        object_param["camera_distortions"] = [displacement_file + "?dx", displacement_file + "?dy"]
        reconstruct_average(object_param, verbose=self.VERBOSE)
        with h5py.File(object_param["output"], "r") as output:
            new_empty = output["empty"][...]
            data_convergence = output["data"].attrs["convergence"]

        # Test for empty equivalence
        np.testing.assert_allclose(np.angle(empty / new_empty)[10:-10, 10:-10], 0.0, atol=0.1)

        # Test for data convergence
        self.assertTrue(np.allclose(data_convergence[-1], 5.1516e+11, rtol=1e-4))
        delta = (data_convergence[1:] - data_convergence[:-1]) / data_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))
Esempio n. 2
0
    def test_GaN_separate_empty_and_object(self):
        # Reconstruct empty
        empty_param = self.default_GaN_param()
        del empty_param["object_names"]
        reconstruct_average(empty_param, verbose=self.VERBOSE)
        with h5py.File(empty_param["output"], "r") as output:
            empty_convergence = output["empty"].attrs["convergence"]

        # Test for empty convergence
        self.assertTrue(np.allclose(empty_convergence[-1], self.GAN_EMPTY_CONVERGENCE_384, rtol=1e-4))
        delta = (empty_convergence[1:] - empty_convergence[:-1]) / empty_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))

        # Reconstruct data
        object_param = self.default_GaN_param()
        object_param["empty_names"] = "/dev/null/some_invalid_filename"
        object_param["empty_override"] = empty_param["output"] + "?empty"
        reconstruct_average(object_param, verbose=self.VERBOSE)
        with h5py.File(object_param["output"], "r") as output:
            data_convergence = output["data"].attrs["convergence"]

        # Test for data convergence
        self.assertTrue(np.allclose(data_convergence[-1], self.GAN_DATA_CONVERGENCE_256, rtol=1e-4))
        delta = (data_convergence[1:] - data_convergence[:-1]) / data_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))
Esempio n. 3
0
    def test_GaN_single_empty_and_object(self):
        # Reconstruct empty
        param = self.default_GaN_param()
        param["object_last"] = 1
        param["empty_last"] = 1
        reconstruct_average(param, verbose=self.VERBOSE)
        with h5py.File(param["output"], "r") as output:
            data = output["data"][...]
            empty = output["empty"][...]

        # Test for shape
        self.assertEqual(data.shape, (param["object_size"],) * 2)
        self.assertEqual(empty.shape, (param["empty_size"],) * 2)
Esempio n. 4
0
    def test_GaN_no_empty(self):
        param = self.default_GaN_param()
        del param["empty_names"]
        del param["empty_size"]
        reconstruct_average(param, verbose=self.VERBOSE)
        with h5py.File(param["output"], "r") as output:
            self.assertFalse("empty" in output)
            data_convergence = output["data"].attrs["convergence"]

        # Test for data convergence
        self.assertTrue(np.allclose(data_convergence[-1], 5.6592e14, rtol=1e-4))
        delta = (data_convergence[1:] - data_convergence[:-1]) / data_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))
Esempio n. 5
0
    def test_GaN_no_objects(self):
        param = self.default_GaN_param()
        del param["object_names"]
        reconstruct_average(param, verbose=self.VERBOSE)
        with h5py.File(param["output"], "r") as output:
            self.assertFalse("data" in output)
            self.assertFalse("variance" in output)
            empty_convergence = output["empty"].attrs["convergence"]

        # Test for empty convergence
        self.assertTrue(np.allclose(empty_convergence[-1], self.GAN_EMPTY_CONVERGENCE_384, rtol=1e-4))
        delta = (empty_convergence[1:] - empty_convergence[:-1]) / empty_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))
Esempio n. 6
0
    def test_GaN_example(self):
        param = self.default_GaN_param()
        reconstruct_average(param, verbose=self.VERBOSE)
        with h5py.File(param["output"], "r") as output:
            data_convergence = output["data"].attrs["convergence"]
            empty_convergence = output["empty"].attrs["convergence"]

        # Test for empty convergence
        self.assertTrue(np.allclose(empty_convergence[-1], self.GAN_EMPTY_CONVERGENCE_384, rtol=1e-4))
        delta = (empty_convergence[1:] - empty_convergence[:-1]) / empty_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))

        # Test for data convergence
        self.assertTrue(np.allclose(data_convergence[-1], self.GAN_DATA_CONVERGENCE_256, rtol=1e-4))
        delta = (data_convergence[1:] - data_convergence[:-1]) / data_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))
Esempio n. 7
0
    def test_GaN_non_square_roi(self):
        param = self.default_GaN_param()
        param["object_last"] = 5    # Smaller series for speed
        param["empty_last"] = 5
        param["roi"] = [256, 640, 1792, 1408]
        reconstruct_average(param, verbose=self.VERBOSE)
        with h5py.File(param["output"], "r") as output:
            data_convergence = output["data"].attrs["convergence"]
            empty_convergence = output["empty"].attrs["convergence"]

        # Test for empty convergence
        delta = (empty_convergence[1:] - empty_convergence[:-1]) / empty_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))

        # Test for data convergence
        delta = (data_convergence[1:] - data_convergence[:-1]) / data_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))
Esempio n. 8
0
    def test_GaN_example_other_sizes(self):
        param = self.default_GaN_param()
        param["object_size"] = 384
        param["empty_size"] = 512
        reconstruct_average(param, verbose=self.VERBOSE)
        with h5py.File(param["output"], "r") as output:
            data_convergence = output["data"].attrs["convergence"]
            empty_convergence = output["empty"].attrs["convergence"]

        # Test for empty convergence
        self.assertTrue(np.allclose(empty_convergence[-1], self.GAN_EMPTY_CONVERGENCE_384 * (384.0/512.0)**2, rtol=0.1))
        delta = (empty_convergence[1:] - empty_convergence[:-1]) / empty_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))

        # Test for data convergence
        self.assertTrue(np.allclose(data_convergence[-1], self.GAN_DATA_CONVERGENCE_256 * (256.0/384.0)**2, rtol=0.1))
        delta = (data_convergence[1:] - data_convergence[:-1]) / data_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))
Esempio n. 9
0
    def test_GaN_example_disabled_pyfftw(self):
        from holoaverage.fft import pyfftw_present, disable_pyfftw
        if not pyfftw_present():
            return      # Disable test: already tested by other test
        disable_pyfftw()

        param = self.default_GaN_param()
        reconstruct_average(param, verbose=self.VERBOSE)
        with h5py.File(param["output"], "r") as output:
            data_convergence = output["data"].attrs["convergence"]
            empty_convergence = output["empty"].attrs["convergence"]

        # Test for empty convergence
        self.assertTrue(np.allclose(empty_convergence[-1], self.GAN_EMPTY_CONVERGENCE_384, rtol=1e-4))
        delta = (empty_convergence[1:] - empty_convergence[:-1]) / empty_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))

        # Test for data convergence
        self.assertTrue(np.allclose(data_convergence[-1], 1.337719e8, rtol=1e-4))
        delta = (data_convergence[1:] - data_convergence[:-1]) / data_convergence[:-1]
        self.assertTrue(np.all(delta < +1e-4))