Example #1
0
 def test_crop_bkg_kwargs(self):
     """
     Test crop and bkg sub with kwargs
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser)
     p0 = [
         5,
         5,
         1,
         1,
         1,
         1000,
     ]
     r.crop(
         cropping.crop_around_peak_2d,
         kwargs={"x_size": 20},
     )
     r.bkg_sub(
         background.fit_gaussian_2d,
         kwargs={"p0": p0},
     )
     a2 = np.zeros((3))
     np.any(np.not_equal(unp.nominal_values(r.R), a2))
     np.any(np.not_equal(unp.std_devs(r.R), a2))
     np.any(np.not_equal(r.n_pixels, a2))
Example #2
0
 def test_init_d(self):
     """
     Test init with wrong file path
     """
     with self.assertRaises(FileNotFoundError):
         file_name = path.join(path.dirname(islatu.__file__),
                               "tests/test_files/test_d.dat")
         r = refl_data.Scan(file_name, io.i07_dat_parser)
Example #3
0
 def test_init_e(self):
     """
     Test init with correct file path but q_axis as none
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser, q_axis_name=None)
     assert_equal(len(r.data["file"]), 3)
     assert_almost_equal(unp.nominal_values(r.q), r.data["qdcd"], decimal=5)
Example #4
0
    def test_concatenate(self):
        """
        Test concatenation
        """
        y1 = np.ones(10) * 10
        dy1 = np.ones(10)
        y2 = np.ones(10) * 5
        dy2 = np.ones(10) * 0.5

        x1 = np.arange(1, 11, 1)
        dx1 = np.copy(x1) * 0.05
        x2 = np.arange(8, 18, 1)
        dx2 = np.copy(x2) * 0.05

        scan1 = refl_data.Scan(
            path.join(path.dirname(islatu.__file__),
                      "tests/test_files/test_a.dat"),
            io.i07_dat_parser,
        )
        scan2 = refl_data.Scan(
            path.join(path.dirname(islatu.__file__),
                      "tests/test_files/test_a.dat"),
            io.i07_dat_parser,
        )

        scan1.q = unumpy.uarray(x1, dx1)
        scan1.R = unumpy.uarray(y1, dy1)
        scan2.q = unumpy.uarray(x2, dx2)
        scan2.R = unumpy.uarray(y2, dy2)
        scan_list = [scan1, scan2]

        exp_y1 = unumpy.uarray(np.append(y1, y2), np.append(dy1, dy2))
        exp_x1 = unumpy.uarray(np.append(x1, x2), np.append(dx1, dx2))

        q, r = stitching.concatenate(scan_list)

        assert_almost_equal(unumpy.nominal_values(r),
                            unumpy.nominal_values(exp_y1))
        assert_almost_equal(unumpy.std_devs(r), unumpy.std_devs(exp_y1))
        assert_almost_equal(unumpy.nominal_values(q),
                            unumpy.nominal_values(exp_x1))
        assert_almost_equal(unumpy.std_devs(q), unumpy.std_devs(exp_x1))
Example #5
0
    def test_correct_attentuation(self):
        """
        Test correction of attenutation
        """
        y1 = np.ones(10) * 10
        dy1 = np.ones(10)
        y2 = np.ones(10) * 5
        dy2 = np.ones(10) * 0.5

        x1 = np.arange(1, 11, 1)
        dx1 = np.copy(x1) * 0.05
        x2 = np.arange(8, 18, 1)
        dx2 = np.copy(x2) * 0.05

        scan1 = refl_data.Scan(
            path.join(path.dirname(islatu.__file__),
                      "tests/test_files/test_a.dat"),
            io.i07_dat_parser,
        )
        scan2 = refl_data.Scan(
            path.join(path.dirname(islatu.__file__),
                      "tests/test_files/test_a.dat"),
            io.i07_dat_parser,
        )

        scan1.q = unumpy.uarray(x1, dx1)
        scan1.R = unumpy.uarray(y1, dy1)
        scan2.q = unumpy.uarray(x2, dx2)
        scan2.R = unumpy.uarray(y2, dy2)
        scan_list = [scan1, scan2]

        exp_y1 = np.ones(10) * 10
        exp_dy1 = np.ones(10)
        exp_y2 = np.ones(10) * 10
        exp_dy2 = np.append(np.ones(3) * 0.8164966, np.ones(7) * 1.1547005)

        scan_list = stitching.correct_attentuation(scan_list)

        assert_almost_equal(unumpy.nominal_values(scan_list[0].R), exp_y1)
        assert_almost_equal(unumpy.std_devs(scan_list[0].R), exp_dy1)
        assert_almost_equal(unumpy.nominal_values(scan_list[1].R), exp_y2)
        assert_almost_equal(unumpy.std_devs(scan_list[1].R), exp_dy2)
Example #6
0
 def test_repr(self):
     """
     Test string output
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser, q_axis_name=None)
     assert_equal(
         r.__repr__(),
         "The file: {} contains 3 images from q = 0.0100 to q = 0.0110.".
         format(file_name),
     )
Example #7
0
 def test_resolution_function(self):
     """
     Test resolution_function from pixel
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser)
     r.crop(cropping.crop_around_peak_2d)
     r.bkg_sub(background.fit_gaussian_2d)
     q_store = unp.nominal_values(r.q)
     r.resolution_function(1)
     assert_equal(unp.nominal_values(r.q), q_store)
     np.any(np.not_equal(unp.std_devs(r.q), np.zeros((3))))
Example #8
0
 def test_transmission(self):
     """
     Test transmission correction
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser)
     r.crop(cropping.crop_around_peak_2d)
     r.bkg_sub(background.fit_gaussian_2d)
     r_store = r.R
     r.transmission_normalisation()
     np.any(
         np.not_equal(unp.nominal_values(r.R), unp.nominal_values(r_store)))
Example #9
0
 def test_footprint(self):
     """
     Test footprint corrections
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser)
     r.crop(cropping.crop_around_peak_2d)
     r.bkg_sub(background.fit_gaussian_2d)
     r_store = r.R
     r.footprint_correction(100e-6, 100e-3)
     np.any(
         np.not_equal(unp.nominal_values(r.R), unp.nominal_values(r_store)))
Example #10
0
 def test_crop_bkg(self):
     """
     Test crop and bkg sub
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser)
     r.crop(cropping.crop_around_peak_2d)
     r.bkg_sub(background.fit_gaussian_2d)
     a2 = np.zeros((3))
     np.any(np.not_equal(unp.nominal_values(r.R), a2))
     np.any(np.not_equal(unp.std_devs(r.R), a2))
     np.any(np.not_equal(r.n_pixels, a2))
Example #11
0
 def test_init_a(self):
     """
     Test init with correct file path
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser)
     assert_equal(len(r.data["file"]), 3)
     assert_equal(r.data["file"][0],
                  "islatu/tests/test_files/location/pilatus1/tiff_a.tif")
     assert_equal(r.data["file"][1],
                  "islatu/tests/test_files/location/pilatus1/tiff_b.tif")
     assert_equal(r.data["file"][2],
                  "islatu/tests/test_files/location/pilatus1/tiff_c.tif")
Example #12
0
 def test_qdcd_normalisation(self):
     """
     Test qdcd normalisation
     """
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/qdcd_norm.dat")
     normalisation_metadata, normalisation_data = io.i07_dat_parser(
         file_name)
     itp = splrep(normalisation_data["qdcd_"], normalisation_data["adc2"])
     file_name = path.join(path.dirname(islatu.__file__),
                           "tests/test_files/test_a.dat")
     r = refl_data.Scan(file_name, io.i07_dat_parser)
     r.crop(cropping.crop_around_peak_2d)
     r.bkg_sub(background.fit_gaussian_2d)
     r_store = r.R
     r.qdcd_normalisation(itp)
     np.any(
         np.not_equal(unp.nominal_values(r.R), unp.nominal_values(r_store)))