Exemple #1
0
    def test_correct(self):
        self.setup.correct_detector_angles(bragg_peak_position=(165, 35))
        print(self.setup.inplane_angle, self.setup.outofplane_angle)
        self.assertTrue(
            np.isclose(self.setup.inplane_angle, 11.940419849886538)
            and np.isclose(self.setup.outofplane_angle, 33.6080130206483)
        )


class TestRepr(unittest.TestCase):
    """Tests related to __repr__."""

    def setUp(self) -> None:
        self.setup = Setup(beamline_name="ID01")

    def test_return_type(self):
        self.assertIsInstance(eval(repr(self.setup)), Setup)

    def test_rocking_angle_str(self):
        self.setup.rocking_angle = "outofplane"
        self.assertIsInstance(eval(repr(self.setup)), Setup)


if __name__ == "__main__":
    run_tests(Test)
    run_tests(TestCheckSetup)
    run_tests(TestCorrectDirectBeam)
    run_tests(TestCorrectDetectorAngles)
    run_tests(TestRepr)
Exemple #2
0
        self.setup.detector.rootdir = self.valid_path
        self.beamline = create_beamline(name="ID01")

    def test_distance_defined(self):
        self.setup.detector.specfile = "defined.spec"

        distance = self.beamline.loader.retrieve_distance(self.setup)
        self.assertTrue(np.isclose(distance, 1.193))

    def test_distance_undefined(self):
        self.setup.detector.specfile = "undefined.spec"

        distance = self.beamline.loader.retrieve_distance(self.setup)
        self.assertTrue(distance is None)


class TestRepr(unittest.TestCase):
    """Tests related to __repr__."""
    def setUp(self) -> None:
        self.loader = create_loader(name="ID01", sample_offsets=(0, 0, 0))

    def test_return_type(self):
        print(repr(self.loader))
        self.assertIsInstance(eval(repr(self.loader)), LoaderID01)


if __name__ == "__main__":
    run_tests(TestRetrieveDistance)
    run_tests(TestInitPath)
    run_tests(TestRepr)
Exemple #3
0
# -*- coding: utf-8 -*-

# BCDI: tools for pre(post)-processing Bragg coherent X-ray diffraction imaging data
#   (c) 07/2017-06/2019 : CNRS UMR 7344 IM2NP
#   (c) 07/2019-05/2021 : DESY PHOTON SCIENCE
#       authors:
#         Jerome Carnis, [email protected]

import unittest
from bcdi.experiment.rotation_matrix import RotationMatrix
from tests.config import run_tests


class Test(unittest.TestCase):
    """Tests related to rotation matrix instantiation."""
    def setUp(self) -> None:
        self.rotmat = RotationMatrix(circle="x+", angle=34)

    def test_instantiation_missing_parameter(self):
        with self.assertRaises(TypeError):
            RotationMatrix()

    def test_repr(self):
        self.assertIsInstance(eval(repr(self.rotmat)), RotationMatrix)


if __name__ == "__main__":
    run_tests(Test)
Exemple #4
0
        with self.assertRaises(TypeError):
            Dummy("dummy", custom_pixelsize=(55e-6, 55e-6))

    def test_unbinned_pixel_size_wrong_value(self):
        with self.assertRaises(ValueError):
            Dummy("dummy", custom_pixelsize=0)

    def test_unbinned_pixel_size_none(self):
        det = Dummy("dummy", custom_pixelsize=None)
        self.assertTupleEqual(det.unbinned_pixel_size, (55e-06, 55e-06))

    def test_unbinned_pixel_size_default(self):
        self.assertTupleEqual(self.det.unbinned_pixel_size, (55e-06, 55e-06))

    def test_unbinned_pixel_size_no_error(self):
        det = Dummy("dummy", custom_pixelsize=100e-6)
        self.assertAlmostEqual(det.unbinned_pixel_size[0], 100e-6)
        self.assertTrue(
            det.unbinned_pixel_size[0] == det.unbinned_pixel_size[1])


if __name__ == "__main__":
    run_tests(TestCreateDetector)
    run_tests(TestDetector)
    run_tests(TestMaxipix)
    run_tests(TestEiger2M)
    run_tests(TestEiger4M)
    run_tests(TestTimepix)
    run_tests(TestMerlin)
    run_tests(TestDummy)
Exemple #5
0
            },
        )
        # "flip_reconstruction" is also key in CONFIG, which means that the overriding
        # by the optional --flip_reconstruction argument from the command line works as
        # expected
        args = self.parser.load_arguments()
        self.assertTrue(args.get("flip_reconstruction") is False)

    def test_load_arguments_cl_params_flip_no_bool(self):
        self.parser = ConfigParser(
            CONFIG,
            {
                "data_dir": str(here),
                "flip_reconstruction": "weirdstring",
                "root_folder": str(here),
            },
        )
        with self.assertRaises(TypeError):
            self.parser.load_arguments()

    def test_instantiate_configparser_no_cla(self):
        self.parser = ConfigParser(CONFIG)
        self.assertIsNone(self.parser.arguments)

    def test_repr(self):
        self.assertIsInstance(eval(repr(self.parser)), ConfigParser)


if __name__ == "__main__":
    run_tests(TestConfigParser)
Exemple #6
0
        self.assertTrue(val is True and flag is True)

    def test_false_expected_1(self):
        val, flag = valid_param(key="align_axis", value="False")
        print(val, flag)
        self.assertTrue(val is False and flag is True)

    def test_false_expected_2(self):
        val, flag = valid_param(key="align_axis", value="false")
        self.assertTrue(val is False and flag is True)

    def test_false_expected_3(self):
        val, flag = valid_param(key="align_axis", value="FALSE")
        self.assertTrue(val is False and flag is True)

    def test_data_dir_none(self):
        val, flag = valid_param(key="data_dir", value="None")
        self.assertTrue(val is None and flag is True)

    def test_data_dir_not_existing(self):
        with self.assertRaises(ValueError):
            valid_param(key="data_dir", value="this_is_not_a_valid_path")

    def test_data_dir_existing(self):
        val, flag = valid_param(key="data_dir", value=THIS_DIR)
        self.assertTrue(val == THIS_DIR and flag is True)


if __name__ == "__main__":
    run_tests(TestParameters)
Exemple #7
0
# -*- coding: utf-8 -*-

# BCDI: tools for pre(post)-processing Bragg coherent X-ray diffraction imaging data
#   (c) 07/2017-06/2019 : CNRS UMR 7344 IM2NP
#   (c) 07/2019-05/2021 : DESY PHOTON SCIENCE
#       authors:
#         Jerome Carnis, [email protected]

import unittest
from bcdi.experiment.diffractometer import Diffractometer
from tests.config import run_tests


class TestRepr(unittest.TestCase):
    """Tests related to __repr__."""

    def setUp(self) -> None:
        self.diffractometer = Diffractometer(name="ID01")

    def test_return_type(self):
        print(repr(self.diffractometer))
        self.assertIsInstance(eval(repr(self.diffractometer)), Diffractometer)


if __name__ == "__main__":
    run_tests(TestRepr)
        )
        self.assertTrue(
            np.allclose(
                self.reference_array,
                aligned_array,
                rtol=1e-09,
                atol=1e-09,
            ))

    def test_method_roll(self):
        aligned_array = reg.shift_array(
            array=self.shifted_array,
            shift=self.shifts,
            interpolation_method="roll",
        )
        self.assertTrue(
            np.allclose(
                self.reference_array,
                aligned_array,
                rtol=1e-09,
                atol=1e-09,
            ))


if __name__ == "__main__":
    run_tests(TestCalcNewPositions)
    run_tests(TestGetShift2D)
    run_tests(TestGetShift2D)
    run_tests(TestShiftArray2D)
    run_tests(TestShiftArray3D)
Exemple #9
0
                                ndim=(2, 1),
                                fix_ndim=False))

    def test_incompatible_shape(self):
        self.assertRaises(
            ValueError,
            valid.valid_ndarray,
            arrays=(self.data, np.zeros((1, 1))),
            ndim=2,
        )

    def test_fix_shape_false(self):
        self.assertTrue(
            valid.valid_ndarray(arrays=(self.data, np.zeros((1, 1))),
                                fix_shape=False))

    def test_invalid_name(self):
        self.assertRaises(TypeError,
                          valid.valid_ndarray,
                          arrays=self.data,
                          name=0)


if __name__ == "__main__":
    run_tests(TestIsFloat)
    run_tests(TestValidContainer)
    run_tests(TestValidKwargs)
    run_tests(TestValidItem)
    run_tests(TestValid1dArray)
    run_tests(TestValidNdArray)
Exemple #10
0
            filename=self.saving_dir + "test.vti",
            voxel_size=(1, 1, 1),
            tuple_array=(self.amp, self.phase),
            tuple_fieldnames=("amp", "phase"),
        )

    def test_savetovti_array_shape(self):
        self.amp = np.ones((2, 2, 2))
        self.assertRaises(
            ValueError,
            gu.save_to_vti,
            filename=self.saving_dir + "test.vti",
            voxel_size=(1, 1, 1),
            tuple_array=(self.amp, self.phase),
            tuple_fieldnames=("amp", "phase"),
        )

    def test_savetovti_fieldnames_wrongtype(self):
        self.assertRaises(
            TypeError,
            gu.save_to_vti,
            filename=self.saving_dir + "test.vti",
            voxel_size=(1, 1, 1),
            tuple_array=(self.amp, self.phase),
            tuple_fieldnames=("amp", 0),
        )


if __name__ == "__main__":
    run_tests(TestSaveToVti)
Exemple #11
0
    def test_transformation_matrix_outofplane_grazing_none(self):
        with self.assertRaises(ValueError):
            self.beamline.transformation_matrix(grazing_angle=None,
                                                rocking_angle="outofplane",
                                                **self.params)

    def test_transformation_matrix_outofplane_grazing_float(self):
        with self.assertRaises(TypeError):
            self.beamline.transformation_matrix(
                grazing_angle=4.5,
                rocking_angle="outofplane",
                **self.params,
            )

    def test_transformation_matrix_energy_scan(self):
        with self.assertRaises(NotImplementedError):
            self.beamline.transformation_matrix(grazing_angle=0,
                                                rocking_angle="energy",
                                                **self.params)


if __name__ == "__main__":
    run_tests(TestBeamline)
    run_tests(TestBeamlineCRISTAL)
    run_tests(TestBeamlineID01)
    run_tests(TestBeamlineNANOMAX)
    run_tests(TestBeamlineP10)
    run_tests(TestBeamlineSIXS)
    run_tests(TestBeamline34ID)
Exemple #12
0
        peak = find_bragg(data=self.data, peak_method="max", binning=(2, 1, 1))
        self.assertTrue(peak == (2, 25, 23))

    def test_binning_2(self):
        peak = find_bragg(data=self.data, peak_method="max", binning=(3, 3, 4))
        self.assertTrue(peak == (3, 75, 92))

    def test_roi_wrong_length(self):
        with self.assertRaises(ValueError):
            find_bragg(data=self.data, peak_method="max", roi=(2, 1, 1))

    def test_roi_wrong_type(self):
        with self.assertRaises(TypeError):
            find_bragg(data=self.data, peak_method="max", roi=(2, 1, 1, 1.2))

    def test_roi(self):
        peak = find_bragg(data=self.data, peak_method="max", roi=(3, 3, 4, 2))
        self.assertTrue(peak == (1, 28, 27))

    def test_bin_roi(self):
        peak = find_bragg(data=self.data,
                          peak_method="max",
                          roi=(3, 3, 4, 2),
                          binning=(3, 3, 4))
        print(peak)
        self.assertTrue(peak == (3, 78, 96))


if __name__ == "__main__":
    run_tests(TestFindBragg)
Exemple #13
0
                        scan_number=1.0)

    def test_exit_function(self):
        with ContextFile(filename=self.filename,
                         open_func=self.open_func) as file:
            pass
        with self.assertRaises(ValueError):
            # file already closed
            try:
                next(file)
            except StopIteration:
                pass

    def test_repr(self):
        ctx = ContextFile(filename=self.filename,
                          open_func=self.open_func,
                          shortname="test")
        print(repr(ctx))
        self.assertIsInstance(eval(repr(ctx)), ContextFile)

    def test_repr_str_none(self):
        ctx = ContextFile(filename=self.filename,
                          open_func=self.open_func,
                          shortname=None)
        print(repr(ctx))
        self.assertIsInstance(eval(repr(ctx)), ContextFile)


if __name__ == "__main__":
    run_tests(TestContextFile)
Exemple #14
0
        self.assertTrue(np.isclose(self.facets.strain_range_avg, 0.0005))

    def test_init_comment(self):
        self.assertTrue(self.facets.comment == "")

    def test_init_title_fontsize(self):
        self.assertTrue(self.facets.title_fontsize == 24)

    def test_init_axes_fontsize(self):
        self.assertTrue(self.facets.axes_fontsize == 18)

    def test_init_legend_fontsize(self):
        self.assertTrue(self.facets.legend_fontsize == 11)

    def test_init_ticks_fontsize(self):
        self.assertTrue(self.facets.ticks_fontsize == 14)

    def test_init_cmap(self):
        self.assertTrue(self.facets.cmap == "viridis")

    def test_init_particle_cmap(self):
        self.assertTrue(self.facets.particle_cmap == "gist_ncar")

    def test_repr(self):
        self.assertIsInstance(eval(repr(self.facets)), Facets)


if __name__ == "__main__":
    run_tests(TestInitFacetsParams)
    run_tests(TestInitFacetsAttributes)