Exemple #1
0
def test_run_comparison_function():
    a = parse_spectrum(os.path.join(TEST_FILE_DIR, 'sample_spectrum_a.txt'),
                       skiprows=1)
    b = parse_spectrum(os.path.join(TEST_FILE_DIR, 'sample_spectrum_b.txt'),
                       skiprows=1)

    compare_spectrum(a, b, method='pearson')
Exemple #2
0
def test_spectrum_comparison_basic():
    """
    Compares a spectrum to itself to verify the similarity measures
    are running
    :return:
    """
    specA = parse_spectrum(os.path.join(TEST_FILE_DIR,
                                        'sample_spectrum_a.txt'),
                           skiprows=1)

    specB = parse_spectrum(os.path.join(TEST_FILE_DIR,
                                        'sample_spectrum_b.txt'),
                           skiprows=1)

    pers_aa = compare_spectrum(specA, specA, 'pearson')
    eucl_aa = compare_spectrum(specA, specA, 'euclidean')
    cos_aa = compare_spectrum(specA, specA, 'cosine')
    ruz_aa = compare_spectrum(specA, specA, 'ruzicka')

    pers_bb = compare_spectrum(specB, specB, 'pearson')
    eucl_bb = compare_spectrum(specB, specB, 'euclidean')
    cos_bb = compare_spectrum(specB, specB, 'cosine')
    ruz_bb = compare_spectrum(specB, specB, 'ruzicka')

    assert (pers_aa == 1.0)
    assert (eucl_aa == 0.0)
    assert (ruz_aa == 1.0)
    assert isclose(cos_aa, 1.0)

    assert (pers_bb == 1.0)
    assert (eucl_bb == 0.0)
    assert (ruz_bb == 1.0)
    assert isclose(cos_bb, 1.0)
Exemple #3
0
def test_all_comparisons():
    a = parse_spectrum(os.path.join(TEST_FILE_DIR, 'sample_spectrum_a.txt'),
                       skiprows=1)
    b = parse_spectrum(os.path.join(TEST_FILE_DIR, 'sample_spectrum_b.txt'),
                       skiprows=1)

    all_comparisons = get_all_comparisons()

    for key in all_comparisons.keys():
        _ = compare_spectrum(a, b, method=key)
Exemple #4
0
def test_run_comparison_function_alt_x():
    c = parse_spectrum(os.path.join(TEST_FILE_DIR, 'sample_spectrum_c.txt'),
                       kind='json')
    d = parse_spectrum(os.path.join(TEST_FILE_DIR, 'sample_spectrum_d.txt'),
                       kind='json')

    compare_spectrum(c, c, method='pearson', alt_x='Enorm')

    assert compare_spectrum(c, c, method='pearson', alt_x='Enorm') == 1
    assert 0 < compare_spectrum(c, d, method='pearson', alt_x='Enorm') < 1
    assert compare_spectrum(d, c, method='pearson', alt_x='Enorm') == \
           compare_spectrum(d, c, method='pearson', alt_x='Enorm')
def test_XAS_shift():
    spec1 = parse_spectrum(os.path.join(TEST_FILE_DIR,
                                        'sample_spectrum_c.txt'),
                           kind='json')

    spec2 = deepcopy(spec1)

    spec1.x = np.subtract(spec1.x, 5.0)
    assert (abs(5.0 +
                spec1.get_shift_alignment(spec2, fidelity=20, iterations=3)[0])
            < .1)
Exemple #6
0
def test_parse_spectrum():
    """
    Tests that the parse spectrum function can import a simple
    2D CSV file
    :return:
    """

    speca = parse_spectrum(os.path.join(TEST_FILE_DIR,
                                        'sample_spectrum_a.txt'),
                           skiprows=1)
    assert isinstance(speca, Spectrum)
    assert len(speca) == 417
    assert speca.x[0] == 7570
    assert speca.x[-1] == 8277.18
    assert speca.y[0] == 0.00267023
    assert speca.y[-1] == 0.9949

    specb = parse_spectrum(os.path.join(TEST_FILE_DIR,
                                        'sample_spectrum_b.txt'),
                           skiprows=1)
    assert isinstance(specb, Spectrum)
    assert len(specb) == 417
Exemple #7
0
def test_parse_spectrum_json():
    """
    Tests that the parse spectrum function can import a simple
    2D CSV file
    :return:
    """

    specc = parse_spectrum(os.path.join(TEST_FILE_DIR,
                                        'sample_spectrum_c.txt'),
                           kind='json')

    # print(specc.full_spectrum)

    # TODO FINISH THIS
    assert isinstance(specc, XAS_Spectrum)
Exemple #8
0
def sample_spectrum():
    yield parse_spectrum(os.path.join(TEST_FILE_DIR, 'sample_spectrum_a.txt'),
                         skiprows=1)