Skip to content

Commit

Permalink
Merge pull request #144 from GSTT-CSC/add-hazelib.__init__-tests-cove…
Browse files Browse the repository at this point in the history
…rage

Add hazenlib init tests coverage
  • Loading branch information
laurencejackson authored Dec 22, 2021
2 parents 6e23b07 + 28f4690 commit c292347
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 80 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cli-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ jobs:
- name: test snr
if: always() # will always run regardless of whether previous step fails - useful to ensure all CLI functions tested
run: |
set -Eeuxo pipefail
hazen snr tests/data/snr/Siemens --report
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ coverage.xml
**/__pycache__
.idea
logs
*.log
uploads
tests/data/slicepos/results
tests/data/uniformity/results
Expand Down
1 change: 1 addition & 0 deletions Hazen_logger.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

51 changes: 31 additions & 20 deletions hazenlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@
import pydicom
from docopt import docopt
import numpy as np
import cv2
from hazenlib.tools import is_dicom_file


__version__ = '0.5.1'



import hazenlib.exceptions

EXCLUDED_FILES = ['.DS_Store']
Expand All @@ -106,12 +110,10 @@ def rescale_to_byte(array):
image_histogram, bins = np.histogram(array.flatten(), 255)
cdf = image_histogram.cumsum() # cumulative distribution function
cdf = 255 * cdf / cdf[-1] # normalize

# use linear interpolation of cdf to find new pixel values
image_equalized = np.interp(array.flatten(), bins[:-1], cdf)

return image_equalized.reshape(array.shape).astype('uint8')

#

def is_enhanced_dicom(dcm: pydicom.Dataset) -> bool:
"""
Expand Down Expand Up @@ -309,9 +311,25 @@ def get_field_of_view(dcm: pydicom.Dataset):
return fov


def parse_relaxometry_data(task, arguments, dicom_objects, report): #def parse_relaxometry_data(arguments, dicom_objects, report): #

# Relaxometry arguments
relaxometry_cli_args = {'--calc_t1', '--calc_t2', '--plate_number',
'--show_template_fit', '--show_relax_fits',
'--show_rois', '--verbose'}

# Pass arguments with dictionary, stripping initial double dash ('--')
relaxometry_args = {}

for key in relaxometry_cli_args:
relaxometry_args[key[2:]] = arguments[key]

return task.main(dicom_objects, report_path = report,
**relaxometry_args)


def main():
arguments = docopt(__doc__, version=__version__)

task = importlib.import_module(f"hazenlib.{arguments['<task>']}")
folder = arguments['<folder>']
files = [os.path.join(folder, x) for x in os.listdir(folder) if x not in EXCLUDED_FILES]
Expand Down Expand Up @@ -342,22 +360,15 @@ def main():
raise Exception("the (--measured_slice_width) option can only be used with snr")
elif arguments['<task>'] == 'snr' and arguments['--measured_slice_width']:
measured_slice_width = float(arguments['--measured_slice_width'])
return pp.pprint(task.main(dicom_objects, measured_slice_width, report_path=report))


if arguments['<task>'] == 'relaxometry':
# Relaxometry arguments
relaxometry_cli_args = {'--calc_t1', '--calc_t2', '--plate_number',
'--show_template_fit', '--show_relax_fits',
'--show_rois', '--verbose'}

# Pass arguments with dictionary, stripping initial double dash ('--')
relaxometry_args = {}
result = task.main(dicom_objects, measured_slice_width, report_path=report)
elif arguments['<task>'] == 'relaxometry':
result = parse_relaxometry_data(task, arguments, dicom_objects, report)
else:
result = task.main(dicom_objects, report_path=report)

for key in relaxometry_cli_args:
relaxometry_args[key[2:]] = arguments[key]
return pp.pformat(result)

return pp.pprint(task.main(dicom_objects, report_path=report,
**relaxometry_args))

return pp.pprint(task.main(dicom_objects, report_path=report))
def entry_point():
result = main()
print(result)
2 changes: 2 additions & 0 deletions hazenlib/spatial_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ def get_esf(edge_arr, y):
return u, esf




def calculate_mtf_for_edge(dicom, edge, report_path=False):
pixels = dicom.pixel_array
pe = dicom.InPlanePhaseEncodingDirection
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
entry_points={
'console_scripts': [
'hazen = hazenlib:main',
'hazen = hazenlib:entry_point',
],
},
)
Binary file added tests/data/resolution/philips/non_dicom_test.jfif
Binary file not shown.
Loading

0 comments on commit c292347

Please sign in to comment.