def test_find_missing_projection_number():
    test_input = [
        EXPECTED_HEADER_FOR_IMAT_LOG_FILE,
        ["ignored line"],
        [
            "timestamp", "Projection:  0  angle: 0.0", "counts before: 12345",
            "counts_after: 45678"
        ],
        [
            "timestamp", "Projection:  1  angle: 0.1", "counts before: 12345",
            "counts_after: 45678"
        ],
        [
            "timestamp", "Projection:  2  angle: 0.2", "counts before: 12345",
            "counts_after: 45678"
        ],
    ]
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert len(logfile.projection_numbers()) == 3
    # nothing missing
    logfile.raise_if_angle_missing(
        ["file_000.tif", "file_001.tif", "file_002.tif"])
    # image file missing
    assert_raises(RuntimeError, logfile.raise_if_angle_missing,
                  ["file_000.tif", "file_002.tif"])
    # image file missing
    assert_raises(RuntimeError, logfile.raise_if_angle_missing,
                  ["file_000.tif", "file_001.tif"])
    assert_raises(
        RuntimeError, logfile.raise_if_angle_missing,
        ["file_000.tif", "file_001.tif", "file_002.tif", "file_003.tif"])
Beispiel #2
0
def test_counts_compare():
    logfile = IMATLogFile(TXT_LOG_FILE, "/tmp/fake")
    logfile_from_csv = IMATLogFile(CSV_LOG_FILE, "/tmp/fake")

    assert len(logfile.counts().value) == len(logfile_from_csv.counts().value)
    assert logfile.counts().value[0] == logfile_from_csv.counts().value[0]
    assert logfile.counts().value[1] == logfile_from_csv.counts().value[1]
    assert logfile.counts().value[2] == logfile_from_csv.counts().value[2]
Beispiel #3
0
def test_parsing_log_file():
    test_input = [["ignored line"], ["ignored line"],
                  [
                      "timestamp", "projection index and angle: 0.100",
                      "counts before", "counts_after"
                  ]]
    logfile = IMATLogFile(test_input)
    assert len(logfile.projection_angles().value) == 1
    assert logfile.projection_angles().value[0] == np.deg2rad(
        0.1), f"Got: {logfile.projection_angles().value[0]}"
def test_parsing_log_file():
    test_input = [
        EXPECTED_HEADER_FOR_IMAT_LOG_FILE, ["ignored line"],
        [
            "timestamp", "Projection:  0  angle: 0.1", "counts before: 12345",
            "counts_after: 45678"
        ]
    ]
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert len(logfile.projection_angles().value) == 1
    assert logfile.projection_angles().value[0] == np.deg2rad(
        0.1), f"Got: {logfile.projection_angles().value[0]}"
    assert logfile.counts().value[0] == (45678 - 12345)
Beispiel #5
0
def test_find_missing_projection_number(test_input):
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert len(logfile.projection_numbers()) == 3
    # nothing missing
    logfile.raise_if_angle_missing(
        ["file_000.tif", "file_001.tif", "file_002.tif"])
    # image file missing
    assert_raises(RuntimeError, logfile.raise_if_angle_missing,
                  ["file_000.tif", "file_002.tif"])
    # image file missing
    assert_raises(RuntimeError, logfile.raise_if_angle_missing,
                  ["file_000.tif", "file_001.tif"])
    assert_raises(
        RuntimeError, logfile.raise_if_angle_missing,
        ["file_000.tif", "file_001.tif", "file_002.tif", "file_003.tif"])
Beispiel #6
0
def load_log(log_file) -> IMATLogFile:
    data = []
    with open(log_file, 'r') as f:
        for line in f:
            data.append(line.strip().split("   "))

    return IMATLogFile(data)
def test_counts():
    test_input = [
        EXPECTED_HEADER_FOR_IMAT_LOG_FILE,
        ["ignored line"],
        [
            "timestamp", "Projection:  0  angle: 0.0", "counts before: 12345",
            "counts_after: 45678"
        ],
        [
            "timestamp", "Projection:  1  angle: 0.1", "counts before: 45678",
            "counts_after: 84678"
        ],
        [
            "timestamp", "Projection:  2  angle: 0.2", "counts before: 84678",
            "counts_after: 124333"
        ],
    ]
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert len(logfile.counts().value) == 3
    assert logfile.counts().value[0] == 45678 - 12345
    assert logfile.counts().value[1] == 84678 - 45678
    assert logfile.counts().value[2] == 124333 - 84678
def generate_csv_logfile() -> IMATLogFile:
    data = [
        CSVLogParser.EXPECTED_HEADER_FOR_IMAT_CSV_LOG_FILE,
        "Sun Feb 10 00:22:04 2019,Projection,0,angle: 0.0,Monitor 3 before: 4577907,Monitor 3 after:  4720271",
        "Sun Feb 10 00:22:37 2019,Projection,1,angle: 0.3152,Monitor 3 before: 4729337,Monitor 3 after:  4871319",
        "Sun Feb 10 00:23:10 2019,Projection,2,angle: 0.6304,Monitor 3 before: 4879923,Monitor 3 after:  5022689",
        "Sun Feb 10 00:23:43 2019,Projection,3,angle: 0.9456,Monitor 3 before: 5031423,Monitor 3 after:  5172216",
        "Sun Feb 10 00:24:16 2019,Projection,4,angle: 1.2608,Monitor 3 before: 5180904,Monitor 3 after:  5322691",
        "Sun Feb 10 00:24:49 2019,Projection,5,angle: 1.576,Monitor 3 before: 5334225,Monitor 3 after:  5475239",
        "Sun Feb 10 00:25:22 2019,Projection,6,angle: 1.8912,Monitor 3 before: 5483964,Monitor 3 after:  5626608",
        "Sun Feb 10 00:25:55 2019,Projection,7,angle: 2.2064,Monitor 3 before: 5635673,Monitor 3 after:  5777316",
        "Sun Feb 10 00:26:29 2019,Projection,8,angle: 2.5216,Monitor 3 before: 5786535,Monitor 3 after:  5929002",
        "Sun Feb 10 00:27:02 2019,Projection,9,angle: 2.8368,Monitor 3 before: 5938142,Monitor 3 after:  6078866",
    ]
    return IMATLogFile(data, "/tmp/fake")
def generate_logfile() -> IMATLogFile:
    data = [
        ["column headers"],  # skipped when parsing
        [""],  # skipped when parsing
        # for each row a list with 4 entries is currently expected
        [
            "Sun Feb 10 00:22:04 2019", "Projection:  0  angle: 0.0",
            "Monitor 3 before:  4577907", "Monitor 3 after:  4720271"
        ],
        [
            "Sun Feb 10 00:22:37 2019", "Projection:  1  angle: 0.3152",
            "Monitor 3 before:  4729337", "Monitor 3 after:  4871319"
        ],
        [
            "Sun Feb 10 00:23:10 2019", "Projection:  2  angle: 0.6304",
            "Monitor 3 before:  4879923", "Monitor 3 after:  5022689"
        ],
        [
            "Sun Feb 10 00:23:43 2019", "Projection:  3  angle: 0.9456",
            "Monitor 3 before:  5031423", "Monitor 3 after:  5172216"
        ],
        [
            "Sun Feb 10 00:24:16 2019", "Projection:  4  angle: 1.2608",
            "Monitor 3 before:  5180904", "Monitor 3 after:  5322691"
        ],
        [
            "Sun Feb 10 00:24:49 2019", "Projection:  5  angle: 1.576",
            "Monitor 3 before:  5334225", "Monitor 3 after:  5475239"
        ],
        [
            "Sun Feb 10 00:25:22 2019", "Projection:  6  angle: 1.8912",
            "Monitor 3 before:  5483964", "Monitor 3 after:  5626608"
        ],
        [
            "Sun Feb 10 00:25:55 2019", "Projection:  7  angle: 2.2064",
            "Monitor 3 before:  5635673", "Monitor 3 after:  5777316"
        ],
        [
            "Sun Feb 10 00:26:29 2019", "Projection:  8  angle: 2.5216",
            "Monitor 3 before:  5786535", "Monitor 3 after:  5929002"
        ],
        [
            "Sun Feb 10 00:27:02 2019", "Projection:  9  angle: 2.8368",
            "Monitor 3 before:  5938142", "Monitor 3 after:  6078866"
        ]
    ]
    return IMATLogFile(data)
def generate_txt_logfile() -> IMATLogFile:
    data = [
        TextLogParser.
        EXPECTED_HEADER_FOR_IMAT_TEXT_LOG_FILE,  # checked if exists, but skipped
        "",  # skipped when parsing
        # for each row a list with 4 entries is currently expected
        "Sun Feb 10 00:22:04 2019   Projection:  0  angle: 0.0   Monitor 3 before:  4577907   Monitor 3 after:  4720271",  # noqa: E501
        "Sun Feb 10 00:22:37 2019   Projection:  1  angle: 0.3152   Monitor 3 before:  4729337   Monitor 3 after:  4871319",  # noqa: E501
        "Sun Feb 10 00:23:10 2019   Projection:  2  angle: 0.6304   Monitor 3 before:  4879923   Monitor 3 after:  5022689",  # noqa: E501
        "Sun Feb 10 00:23:43 2019   Projection:  3  angle: 0.9456   Monitor 3 before:  5031423   Monitor 3 after:  5172216",  # noqa: E501
        "Sun Feb 10 00:24:16 2019   Projection:  4  angle: 1.2608   Monitor 3 before:  5180904   Monitor 3 after:  5322691",  # noqa: E501
        "Sun Feb 10 00:24:49 2019   Projection:  5  angle: 1.576   Monitor 3 before:  5334225   Monitor 3 after:  5475239",  # noqa: E501
        "Sun Feb 10 00:25:22 2019   Projection:  6  angle: 1.8912   Monitor 3 before:  5483964   Monitor 3 after:  5626608",  # noqa: E501
        "Sun Feb 10 00:25:55 2019   Projection:  7  angle: 2.2064   Monitor 3 before:  5635673   Monitor 3 after:  5777316",  # noqa: E501
        "Sun Feb 10 00:26:29 2019   Projection:  8  angle: 2.5216   Monitor 3 before:  5786535   Monitor 3 after:  5929002",  # noqa: E501
        "Sun Feb 10 00:27:02 2019   Projection:  9  angle: 2.8368   Monitor 3 before:  5938142   Monitor 3 after:  6078866",  # noqa: E501
    ]
    return IMATLogFile(data, "/tmp/fake")
def test_source_file():
    test_input = [
        EXPECTED_HEADER_FOR_IMAT_LOG_FILE,
        ["ignored line"],
        [
            "timestamp", "Projection:  0  angle: 0.0", "counts before: 12345",
            "counts_after: 45678"
        ],
        [
            "timestamp", "Projection:  1  angle: 0.1", "counts before: 12345",
            "counts_after: 45678"
        ],
        [
            "timestamp", "Projection:  2  angle: 0.2", "counts before: 12345",
            "counts_after: 45678"
        ],
    ]
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert logfile.source_file == "/tmp/fake"
Beispiel #12
0
def test_parsing_log_file(test_input):
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert len(logfile.projection_angles().value) == 1
    assert logfile.projection_angles().value[0] == np.deg2rad(
        0.1), f"Got: {logfile.projection_angles().value[0]}"
    assert logfile.counts().value[0] == (45678 - 12345)
Beispiel #13
0
def test_source_file(test_input):
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert logfile.source_file == "/tmp/fake"
Beispiel #14
0
def test_raise_if_angles_missing_returns_none_if_no_filename_list():
    logfile = IMATLogFile(TXT_LOG_FILE, "/tmp/fake")
    assert logfile.raise_if_angle_missing(None) is None
Beispiel #15
0
def test_counts(test_input):
    logfile = IMATLogFile(test_input, "/tmp/fake")
    assert len(logfile.counts().value) == 3
    assert logfile.counts().value[0] == 45678 - 12345
    assert logfile.counts().value[1] == 84678 - 45678
    assert logfile.counts().value[2] == 124333 - 84678
Beispiel #16
0
def test_ignore_spaces_at_end_of_log_file_header():
    test_log_file = TXT_LOG_FILE[:]
    test_log_file[0].replace("\n", "         \n")
    logfile = IMATLogFile(test_log_file, "/tmp/fake")
    assert len(logfile.projection_numbers()) == 3
Beispiel #17
0
def load_log(log_file: str) -> IMATLogFile:
    with open(log_file, 'r') as f:
        return IMATLogFile(f.readlines(), log_file)