Esempio n. 1
0
def test_bkg_sub_02(scan2d_from_nxs_01: Scan2D):
    """
    Make sure that the background subtraction function is doing something.
    """
    region_list = scan2d_from_nxs_01.metadata.background_regions
    scan2d_from_nxs_01.bkg_sub(roi_subtraction, list_of_regions=region_list)

    assert scan2d_from_nxs_01.images[0].bkg != 0
    assert scan2d_from_nxs_01.images[0].bkg_e != 0
Esempio n. 2
0
def test_profile_bkg_sub(profile_01: Profile, scan2d_from_nxs_01: Scan2D):
    """
    Make sure that bkg_sub from the profile is the same as bkg_sub from the
    scan.
    """
    bkg_region = scan2d_from_nxs_01.metadata.background_regions[0]
    profile_01.bkg_sub(roi_subtraction, list_of_regions=[bkg_region])
    scan2d_from_nxs_01.bkg_sub(roi_subtraction, list_of_regions=[bkg_region])

    assert_allclose(profile_01.intensity_e, scan2d_from_nxs_01.intensity_e,
                    1e-4)
    assert_allclose(profile_01.intensity, scan2d_from_nxs_01.intensity, 1e-4)
Esempio n. 3
0
def test_gauss_bkg_01(scan2d_from_nxs_01: Scan2D):
    """
    Make sure that our Gaussian fit background subtraction function is doing
    something.

    Note that this function is not being tested for sensible results because
    this doesn't generally seem to be a sensible technique to use on I07. As
    more instruments are supported, if this technique becomes useful, its
    tests will need to be extended. For now, only the minimum is being done
    to ensure that it is roughly functional.
    """
    scan2d_from_nxs_01.bkg_sub(fit_gaussian_1d)

    assert scan2d_from_nxs_01.images[0].bkg != 0
    assert scan2d_from_nxs_01.images[0].bkg_e != 0
Esempio n. 4
0
def test_bkg_sub_04(scan2d_from_nxs_01: Scan2D, scan2d_from_nxs_01_copy,
                    custom_bkg_region_01):
    """
    Make sure that using two background regions yields a lower uncertainty
    measurement of the background than using just one background region.
    """
    regions_1 = [scan2d_from_nxs_01.metadata.background_regions[0]]
    regions_2 = [scan2d_from_nxs_01.metadata.background_regions[0]
                 ] + [custom_bkg_region_01]
    scan2d_from_nxs_01.bkg_sub(roi_subtraction, list_of_regions=regions_1)
    scan2d_from_nxs_01_copy.bkg_sub(roi_subtraction, list_of_regions=regions_2)

    for i, image_1 in enumerate(scan2d_from_nxs_01.images):
        image_2 = scan2d_from_nxs_01_copy.images[i]
        assert image_1.bkg_e > image_2.bkg_e
Esempio n. 5
0
def test_bkg_sub_03(scan2d_from_nxs_01: Scan2D):
    """
    Make sure that the background subtraction decreases our intensity.
    """
    vals, stdevs = (np.zeros(len(scan2d_from_nxs_01.intensity)),
                    np.zeros(len(scan2d_from_nxs_01.intensity)))

    # Also update the image intensities & errors.
    for i, image in enumerate(scan2d_from_nxs_01.images):
        vals[i], stdevs[i] = image.sum()

    # Store the intensity(Q) to the new value.
    scan2d_from_nxs_01.intensity = np.array(vals)
    scan2d_from_nxs_01.intensity_e = np.array(stdevs)

    region_list = scan2d_from_nxs_01.metadata.background_regions
    scan2d_from_nxs_01.bkg_sub(roi_subtraction, list_of_regions=region_list)

    assert (vals > scan2d_from_nxs_01.intensity).all()
Esempio n. 6
0
def test_gauss_bkg_02(scan2d_from_nxs_01: Scan2D):
    """
    Make sure that carrying out this subtraction decreases our intensity.

    Note that this function is not being tested for sensible results because
    this doesn't generally seem to be a sensible technique to use on I07. As
    more instruments are supported, if this technique becomes useful, its
    tests will need to be extended. For now, only the minimum is being done
    to ensure that it is roughly functional.
    """
    vals = np.zeros(len(scan2d_from_nxs_01.intensity))
    # Also update the image intensities & errors.
    for i, image in enumerate(scan2d_from_nxs_01.images):
        vals[i], _ = image.sum()
    # Store the intensity(Q) to the new value.
    scan2d_from_nxs_01.intensity = np.array(vals)

    intensity_0 = np.copy(scan2d_from_nxs_01.intensity)
    scan2d_from_nxs_01.bkg_sub(fit_gaussian_1d)

    assert (scan2d_from_nxs_01.intensity < intensity_0).all()