Beispiel #1
0
def test_signal_size():
    spectrum = np.array([5., 4., 3., 2., 2., 1., 1., 1., 0., 0.])
    ri = ReducedIntensity1D(spectrum)
    pdfgen = PDFGenerator1D(ri)
    pdf = pdfgen.get_pdf(s_min=0, s_max=10)
    assert isinstance(pdf, PairDistributionFunction1D)

    ri = ReducedIntensity1D([spectrum])
    pdfgen = PDFGenerator1D(ri)
    pdf = pdfgen.get_pdf(s_min=0,s_max=10)
    assert isinstance(pdf, PairDistributionFunction1D)

    ri = ReducedIntensity1D([[spectrum]])
    pdfgen = PDFGenerator1D(ri)
    pdf = pdfgen.get_pdf(s_min=0, s_max=10)
    assert isinstance(pdf, PairDistributionFunction1D)

    ri = ReducedIntensity1D([[[spectrum]]])
    pdfgen = PDFGenerator1D(ri)
    pdf = pdfgen.get_pdf(s_min=0, s_max=10)
    shape = pdf.data.shape
    assert shape == (1,1,1,2000)

    ri = ReducedIntensity1D([[[spectrum]]])
    pdfgen = PDFGenerator1D(ri)
    pdf = pdfgen.get_pdf(s_min=0, s_max=10, r_min=0, r_max=8)
    shape = pdf.data.shape
    assert shape == (1,1,1,800)
Beispiel #2
0
    def get_reduced_intensity(self):
        """Obtains a reduced intensity profile from the radial profile.

        Parameters
        ----------
        s_cutoff : list of float
                    A list of the form [s_min, s_max] to change the s_cutoff
                    from the fit.
        Returns
        -------
        ri : ReducedIntensity1D
        """

        s_scale = self.signal.axes_manager.signal_axes[0].scale
        s = np.arange(self.signal.axes_manager.signal_axes[0].size,
                      dtype='float64')
        s *= self.signal.axes_manager.signal_axes[0].scale

        reduced_intensity = (2 * np.pi * s * np.divide(
            (self.signal.data - self.background_fit), self.normalisation))

        ri = ReducedIntensity1D(reduced_intensity)
        ri = transfer_navigation_axes(ri, self.signal)
        ri = transfer_signal_axes(ri, self.signal)

        return ri
def test_get_reduced_intensity(red_int_generator):
    red_int_generator.set_diffraction_calibration(calibration=0.1)
    red_int_generator.fit_atomic_scattering(elements=["Cu"], fracs=[1])
    ri = red_int_generator.get_reduced_intensity()
    assert isinstance(ri, ReducedIntensity1D)

    ri_expected_single = np.array(
        [
            -0.0,
            -0.04491037,
            0.0586241,
            0.40874355,
            0.8446079,
            0.98388682,
            0.26926809,
            -2.08758824,
            -7.25497587,
            -16.97484119,
        ]
    )
    ri_expected_array = np.vstack(
        (ri_expected_single, ri_expected_single, ri_expected_single, ri_expected_single)
    ).reshape(2, 2, 10)
    ri_expected = ReducedIntensity1D(ri_expected_array)

    assert np.allclose(ri.data, ri_expected.data)
def test_multiple_scatter_correction(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.axes_manager.signal_axes[0].scale = 1
    ri.axes_manager.signal_axes[0].offset = 0.5

    ri.fit_thermal_multiple_scattering_correction()

    assert ri.data.shape == (2, 2, 10)
Beispiel #5
0
def test_s_max_statements(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.axes_manager.signal_axes[0].scale = 1
    ri.axes_manager.signal_axes[0].offset = 0.5

    ri.damp_lorch()
    ri.damp_updated_lorch()
    ri.fit_thermal_multiple_scattering_correction(s_max=5, plot=True)
    assert isinstance(ri, ReducedIntensity1D)
def test_damp_low_q_region_erfc(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.axes_manager.signal_axes[0].scale = 1
    ri.axes_manager.signal_axes[0].offset = 0.5

    ri.damp_low_q_region_erfc(scale=20, offset=20)
    compare = np.array([[[0., 1., 1., 1., 1., 1., 1., 1., 1., 1.],
                        [0., 2., 2., 2., 2., 2., 2., 2., 2., 2.]],
                        [[0., 3., 3., 3., 3., 3., 3., 3., 3., 3.],
                        [0., 4., 4., 4., 4., 4., 4., 4., 4., 4.]]])
    assert np.allclose(ri, compare)
Beispiel #7
0
def test_damp_updated_lorch(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.damp_updated_lorch(s_max=10)
    compare = np.array([[[0., 0., 0., 0., 0.,
                          0., 0., 0., 0., 0.],
                         [0., 0.99016512, 0.96107415, 0.91394558, 0.85073648,
                          0.77403683, 0.68693073, 0.5928333, 0.49531303, 0.3979104]],

                        [[0., 1.98033024, 1.92214831, 1.82789116, 1.70147296,
                          1.54807365, 1.37386146, 1.18566661, 0.99062606, 0.7958208],
                         [0., 2.97049536, 2.88322246, 2.74183673, 2.55220944,
                          2.32211048, 2.06079219, 1.77849991, 1.48593909, 1.1937312]]])
    assert np.allclose(ri, compare)
Beispiel #8
0
def test_damp_lorch(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.damp_lorch(s_max=10)
    compare = np.array([[[0., 0., 0., 0., 0.,
                          0., 0., 0., 0., 0.],
                         [0., 0.98363164, 0.93548928, 0.85839369, 0.75682673,
                          0.63661977, 0.50455115, 0.36788301, 0.23387232, 0.1092924]],

                        [[0., 1.96726329, 1.87097857, 1.71678738, 1.51365346,
                          1.27323954, 1.0091023, 0.73576602, 0.46774464, 0.21858481],
                         [0., 2.95089493, 2.80646785, 2.57518107, 2.27048019,
                          1.90985932, 1.51365346, 1.10364903, 0.70161696, 0.32787721]]])
    assert np.allclose(ri, compare)
Beispiel #9
0
def test_damp_low_q_region_erfc(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.damp_low_q_region_erfc(scale=20, offset=1.3)
    compare = np.array([[[0., 0., 0., 0., 0.,
                          0., 0., 0., 0., 0.],
                         [0.03299603, 1., 1., 1., 1.,
                          1., 1., 1., 1., 1.]],

                        [[0.06599206, 2., 2., 2., 2.,
                          2., 2., 2., 2., 2.],
                         [0.09898808, 3., 3., 3., 3.,
                          3., 3., 3., 3., 3.]]])
    assert np.allclose(ri, compare)
def test_damp_updated_lorch(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.axes_manager.signal_axes[0].scale = 1
    ri.axes_manager.signal_axes[0].offset = 0.5

    ri.damp_updated_lorch(s_max=10)
    compare = np.array([[[0.99753477, 0.97796879, 0.9396585 , 0.88420257, 0.81388998,
         0.73157686, 0.64053436, 0.54427698, 0.44638168, 0.35030873],
        [1.99506954, 1.95593757, 1.879317  , 1.76840514, 1.62777996,
         1.46315372, 1.28106873, 1.08855397, 0.89276337, 0.70061746]],

       [[2.99260432, 2.93390636, 2.8189755 , 2.65260771, 2.44166995,
         2.19473058, 1.92160309, 1.63283095, 1.33914505, 1.05092619],
        [3.99013909, 3.91187515, 3.758634  , 3.53681029, 3.25555993,
         2.92630744, 2.56213745, 2.17710793, 1.78552674, 1.40123492]]])
    assert np.allclose(ri, compare)
def test_damp_lorch(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.axes_manager.signal_axes[0].scale = 1
    ri.axes_manager.signal_axes[0].offset = 0.5

    ri.damp_lorch(s_max=10)
    compare = np.array([[[0.99589274, 0.96339776, 0.90031632, 0.81033196, 0.69864659,
         0.57161993, 0.43633259, 0.30010544, 0.17001137, 0.05241541],
        [1.99178547, 1.92679552, 1.80063263, 1.62066392, 1.39729317,
         1.14323987, 0.87266519, 0.60021088, 0.34002274, 0.10483081]],

       [[2.98767821, 2.89019329, 2.70094895, 2.43099587, 2.09593976,
         1.7148598 , 1.30899778, 0.90031632, 0.51003411, 0.15724622],
        [3.98357094, 3.85359105, 3.60126526, 3.24132783, 2.79458634,
         2.28647973, 1.74533037, 1.20042175, 0.68004548, 0.20966163]]])
    assert np.allclose(ri, compare)
Beispiel #12
0
def test_damp_exponential(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.damp_exponential(b=1)
    compare = np.array([[[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                          0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
                          0.00000000e+00, 0.00000000e+00],
                         [1.00000000e+00, 3.67879441e-01, 1.83156389e-02, 1.23409804e-04,
                          1.12535175e-07, 1.38879439e-11, 2.31952283e-16, 5.24288566e-22,
                          1.60381089e-28, 6.63967720e-36]],

                        [[2.00000000e+00, 7.35758882e-01, 3.66312778e-02, 2.46819608e-04,
                          2.25070349e-07, 2.77758877e-11, 4.63904566e-16, 1.04857713e-21,
                          3.20762178e-28, 1.32793544e-35],
                         [3.00000000e+00, 1.10363832e+00, 5.49469167e-02, 3.70229412e-04,
                          3.37605524e-07, 4.16638316e-11, 6.95856849e-16, 1.57286570e-21,
                          4.81143267e-28, 1.99190316e-35]]])
    assert np.allclose(ri, compare)
Beispiel #13
0
def test_multiple_scatter_correction(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.fit_thermal_multiple_scattering_correction()
    compare = np.array([[[0., 0., 0., 0.,
                          0., 0., 0., 0.,
                          0., 0.],
                         [1., 0.14216084, -0.10154346, -0.06092608,
                          0.03655565, 0.06580016, 0.00406174, -0.06904955,
                          0.02843217, 0.58082859]],

                        [[2., 0.28432171, -0.20308691, -0.12185215,
                          0.07311128, 0.13160032, 0.00812348, -0.1380991,
                          0.05686434, 1.16165714],
                         [3., 0.42648258, -0.30463036, -0.18277824,
                          0.10966691, 0.19740047, 0.01218523, -0.20714863,
                          0.08529649, 1.74248558]]])
    assert np.allclose(ri, compare)
def test_damp_exponential(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.axes_manager.signal_axes[0].scale = 1
    ri.axes_manager.signal_axes[0].offset = 0.5

    ri.damp_exponential(b=1)
    compare = np.array([[[7.78800783e-01, 1.05399225e-01, 1.93045414e-03, 4.78511739e-06,
         1.60522806e-09, 7.28772410e-14, 4.47773244e-19, 3.72336312e-25,
         4.19009319e-32, 6.38150345e-40],
        [1.55760157e+00, 2.10798449e-01, 3.86090827e-03, 9.57023478e-06,
         3.21045611e-09, 1.45754482e-13, 8.95546488e-19, 7.44672624e-25,
         8.38018639e-32, 1.27630069e-39]],

       [[2.33640235e+00, 3.16197674e-01, 5.79136241e-03, 1.43553522e-05,
         4.81568417e-09, 2.18631723e-13, 1.34331973e-18, 1.11700894e-24,
         1.25702796e-31, 1.91445103e-39],
        [3.11520313e+00, 4.21596898e-01, 7.72181654e-03, 1.91404696e-05,
         6.42091222e-09, 2.91508964e-13, 1.79109298e-18, 1.48934525e-24,
         1.67603728e-31, 2.55260138e-39]]])
    assert np.allclose(ri, compare)
def test_multiple_scatter_correction(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.axes_manager.signal_axes[0].scale = 1
    ri.axes_manager.signal_axes[0].offset = 0.5

    ri.fit_thermal_multiple_scattering_correction()
    compare = np.array([[[ 0.42246704, -0.110368  , -0.15284384, -0.01678097,
          0.0949349 ,  0.08835281, -0.02154344, -0.11083526,
          0.05333068,  0.81274247],
        [ 0.84493403, -0.22073604, -0.30568769, -0.03356191,
          0.18986983,  0.17670563, -0.04308689, -0.22167055,
          0.10666138,  1.62548517]],

       [[ 1.26740111, -0.33110398, -0.4585315 , -0.05034289,
          0.2848047 ,  0.26505841, -0.06463033, -0.33250579,
          0.15999205,  2.4382275 ],
        [ 1.68986821, -0.44147192, -0.61137534, -0.06712392,
          0.37973953,  0.3534112 , -0.08617371, -0.44334097,
          0.21332267,  3.25096948]]])
    assert np.allclose(ri, compare)
Beispiel #16
0
def test_s_max_statements(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    ri.damp_lorch()
    ri.damp_updated_lorch()
    ri.fit_thermal_multiple_scattering_correction(s_max=5, plot=True)
    assert isinstance(ri, ReducedIntensity1D)
Beispiel #17
0
def test_reduced_intensity1d_init(RedIntData):
    ri = ReducedIntensity1D(RedIntData)
    assert isinstance(ri, ReducedIntensity1D)
def ri_model(request):
    ri = ReducedIntensity1D(request.param)
    m = ri.create_model()
    return m
Beispiel #19
0
def reduced_intensity1d():
    data = np.ones((1, 10)) * np.arange(4).reshape(4, 1)
    data = data.reshape(2, 2, 10)
    ri = ReducedIntensity1D(data)
    return ri