def test_qdcd_normalisation_02(scan2d_from_nxs_01: Scan2D, dcd_norm_01_splev, parsed_dcd_normalisation_01): """ Make sure that our nice splev normalisation does something similar to what would be achieved using a simple cubic scipy.interpolate.interp1D. """ # First, generate some test intensities by dividing by an interp1D function. intensities_0 = np.copy(scan2d_from_nxs_01.intensity) intensities_e_0 = np.copy(scan2d_from_nxs_01.intensity_e) _, dataframe = parsed_dcd_normalisation_01 interp = interp1d(dataframe["qdcd_"], dataframe['adc2'], kind='cubic') test_intensities = intensities_0 / interp(scan2d_from_nxs_01.q_vectors) test_intensities_e = intensities_e_0 / interp(scan2d_from_nxs_01.q_vectors) # Now, carry out the qdcd normalisation as normal. scan2d_from_nxs_01.qdcd_normalisation(dcd_norm_01_splev) # These interpolation methods could be decently different, but lets enforce # that our values are the same to within 1%. for i, test_intensity in enumerate(test_intensities): assert test_intensity == pytest.approx(scan2d_from_nxs_01.intensity[i], rel=0.01) for i, test_inten_e in enumerate(test_intensities_e): assert test_inten_e == pytest.approx(scan2d_from_nxs_01.intensity_e[i], rel=0.01)
def test_profile_qdcd_normalisation(profile_01: Profile, scan2d_from_nxs_01: Scan2D, dcd_norm_01_splev): """ Assert that carrying out the qdcd correction on an instance of Profile is the same thing as doing it on each of its constituent scans. """ profile_01.qdcd_normalisation(dcd_norm_01_splev) scan2d_from_nxs_01.qdcd_normalisation(dcd_norm_01_splev) assert_allclose(profile_01.intensity, scan2d_from_nxs_01.intensity) assert_allclose(profile_01.intensity_e, profile_01.intensity_e)
def test_qdcd_normalisation_01(scan2d_from_nxs_01: Scan2D, dcd_norm_01_splev): """ Make sure that our qdcd normalisation is doing something, and isn't failing silently. (This is a dumb test, but it's really quite hard to test that this is working without just rewriting a division by splev). """ intensities_0 = np.copy(scan2d_from_nxs_01.intensity) intensities_e_0 = np.copy(scan2d_from_nxs_01.intensity_e) scan2d_from_nxs_01.qdcd_normalisation(dcd_norm_01_splev) assert (intensities_0 != scan2d_from_nxs_01.intensity).all() assert (intensities_e_0 != scan2d_from_nxs_01.intensity_e).all()