File: test_if_reponse.py

package info (click to toggle)
python-qmix 1.0.6-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,460 kB
  • sloc: python: 4,312; makefile: 215
file content (48 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Test the module that imports and analyzes IF spectrum data.

Note: This module does not affect the QMix simulations. This module is used
to analyze experimental data. This module is much easier to test by running it
on experimental data and plotting the results.

"""

import numpy as np 
import pytest 

from qmix.exp.if_response import if_response
from qmix.exp.parameters import params as PARAMS


if_data_file = 'tests/exp-data/f230_spectrum.dat'


def test_importing_if_spectrum_data():
    """Try import IF spectrum data. 

    Try it once by passing the file name, and once by passing a Numpy matrix.

    Also, make sure there are no bad values.

    """

    # Import IF response using the file name
    if_data1 = if_response(if_data_file)

    # Import IF response as a Numpy array
    if_data_array = np.genfromtxt(if_data_file, 
                                  skip_header=PARAMS['ifresp_skipheader'], 
                                  usecols=PARAMS['ifresp_usecols'],
                                  delimiter=PARAMS['ifresp_delimiter'])
    if_data2 = if_response(if_data_array)
    if_data2 = if_response(if_data_array.T)

    # Import IF response as a list
    with pytest.raises(ValueError):
        if_data3 = if_response([1, 2, 3])

    # Assert that both arrays are the same
    np.testing.assert_equal(if_data1, if_data2)

    # Assert no bad values
    assert if_data1[1].max() <= PARAMS['ifresp_maxtn']
    assert if_data1[1].min() >= 0.