Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

350 utils #351

Merged
merged 28 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
69c602d
move hazen's main function to hazen.py
sophie22 Jul 3, 2023
24508a9
update entrypoint to hazen.main
sophie22 Jul 3, 2023
f11048c
test_hazenlib is failing without these extra imports
sophie22 Jul 3, 2023
ff7f914
relaxometry task needs a review and fix, to pass tests
sophie22 Jul 3, 2023
d7e3a14
fix missing import for test to pass
sophie22 Jul 3, 2023
74bd882
new line at the end of file
sophie22 Jul 5, 2023
63dc92d
combine utility functions and classes into renamed utils.py
sophie22 Jul 5, 2023
86c6d16
spacing
sophie22 Jul 5, 2023
8f72e82
use new utils in scripts
sophie22 Jul 5, 2023
671aa05
use new utils in test scripts
sophie22 Jul 5, 2023
daabbad
correctly import utils function for spatial resolution
sophie22 Jul 5, 2023
bc1855a
update tests for utils.py script
sophie22 Jul 5, 2023
d258009
rename hazen.py to main.py
sophie22 Jul 5, 2023
d11cc6f
combined into utils
sophie22 Jul 5, 2023
a5bfbaf
fix entry point and importing utils
sophie22 Jul 5, 2023
5882d7f
correct import of Rod class
sophie22 Jul 11, 2023
e9b6a4d
revert creation of a __main__.py
sophie22 Jul 11, 2023
e2da681
move result printing into main()
sophie22 Jul 11, 2023
ce81065
revert test script names
sophie22 Jul 11, 2023
af32a93
return pprint of result
sophie22 Jul 12, 2023
98f1627
QoL changes to utils.py
tomaroberts Jul 17, 2023
561cf33
QoL changes to __init__.py
tomaroberts Jul 17, 2023
04c984e
QoL changes to test_cli.yml
tomaroberts Jul 17, 2023
24b39b0
move unit tests for util funcs to test_utils.py from test_hazenlib
sophie22 Jul 18, 2023
200e951
remove return from main()
sophie22 Jul 18, 2023
de70827
directly call the run() function of the task to capture the result fo…
sophie22 Jul 18, 2023
7ce29ff
remove commented original args
sophie22 Jul 18, 2023
0edef4e
Merge branch 'main' into 350_utils
sophie22 Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hazenlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def main():
else:
result = task.run()

return pp.pformat(result)
print(pp.pformat(result))


if __name__ == "__main__":
result = main()
main()
35 changes: 17 additions & 18 deletions tests/test_hazenlib.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import pydicom
import sys
from tests import TEST_DATA_DIR, TEST_REPORT_DIR
import unittest
import numpy as np
from docopt import docopt
from hazenlib.logger import logger
import hazenlib.utils
from pprint import pprint
import sys
import ast
import os
import pydicom
import hazenlib
from hazenlib.utils import get_dicom_files, is_dicom_file
from hazenlib.tasks.snr import SNR
from hazenlib.relaxometry import main as relaxometry_run


class TestCliParser(unittest.TestCase):
Expand Down Expand Up @@ -46,26 +43,28 @@ def test_main_snr_exception(self):

def test_snr_measured_slice_width(self):
path = str(TEST_DATA_DIR / 'snr' / 'GE')
sys.argv = ["hazen", "snr", path, "--measured_slice_width", "1"]
files = get_dicom_files(path)
# sys.argv = ["hazen", "snr", path, "--measured_slice_width", "1"]
sophie22 marked this conversation as resolved.
Show resolved Hide resolved
snr_task = SNR(data_paths=files, report=False)
result = snr_task.run(measured_slice_width=1)

output = hazenlib.main()
output_dict = ast.literal_eval(output)
dict1 = {'snr_subtraction_measured_SNR_SNR_SAG_MEAS1_23_1': 183.97,
'snr_subtraction_normalised_SNR_SNR_SAG_MEAS1_23_1': 7593.04,
'snr_smoothing_measured_SNR_SNR_SAG_MEAS2_24_1': 183.93,
'snr_smoothing_normalised_SNR_SNR_SAG_MEAS2_24_1': 7591.33,
'snr_smoothing_measured_SNR_SNR_SAG_MEAS1_23_1': 179.94,
'snr_smoothing_normalised_SNR_SNR_SAG_MEAS1_23_1': 7426.54}

self.assertDictEqual(output_dict['SNR_SNR_SAG_MEAS1_23_1'], dict1)
self.assertDictEqual(result['SNR_SNR_SAG_MEAS1_23_1'], dict1)

def test_relaxometry(self):
path = str(TEST_DATA_DIR / 'relaxometry' / 'T1' / 'site3_ge' / 'plate4')
sys.argv = ["hazen", "relaxometry", path, "--plate_number", "4", "--calc_t1"]

output = hazenlib.main()
output_dict = ast.literal_eval(output)
files = get_dicom_files(path)
dicom_objects = [pydicom.read_file(x, force=True) for x in files if is_dicom_file(x)]
# sys.argv = ["hazen", "relaxometry", path, "--plate_number", "4", "--calc_t1"]
sophie22 marked this conversation as resolved.
Show resolved Hide resolved
result = relaxometry_run(dicom_objects, plate_number=4,
calc_t1=True, calc_t2=False, report_path=False, verbose=False)

dict1 = {'Spin Echo_32_2_P4_t1': {'rms_frac_time_difference': 0.13499936644959437}}
self.assertAlmostEqual(dict1['Spin Echo_32_2_P4_t1']['rms_frac_time_difference'],
output_dict['Spin Echo_32_2_P4_t1']['rms_frac_time_difference'], 4)
result['Spin Echo_32_2_P4_t1']['rms_frac_time_difference'], 4)