-
Notifications
You must be signed in to change notification settings - Fork 12
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
Add hazenlib init tests coverage #144
Changes from 22 commits
9c66202
fd1bea4
98241ce
d3a3217
bf4f53e
507526c
0ee77f6
6b5491b
bc42917
d6137d8
d2d224e
008df9e
39353b7
4afff59
1ee8679
54e6fb1
858c2f2
238be87
f9cc8c4
44c2ddc
2510d13
aef3f7a
51fa679
658eab3
ada0244
0c05753
fdbecc9
28f4690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'] | ||
|
@@ -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: | ||
""" | ||
|
@@ -309,9 +311,29 @@ 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] | ||
|
@@ -338,25 +360,15 @@ def main(): | |
# logging.basicConfig() | ||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
|
||
if not arguments['<task>'] == 'snr' and arguments['--measured_slice_width']: | ||
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)) | ||
return 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 = {} | ||
|
||
for key in relaxometry_cli_args: | ||
relaxometry_args[key[2:]] = arguments[key] | ||
|
||
return pp.pprint(task.main(dicom_objects, report_path=report, | ||
**relaxometry_args)) | ||
return parse_relaxometry_data(task, arguments, dicom_objects, report) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above we need to re-add this relaxometry code due to the earlier branching from develop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still there, I have put this relaxometry code in a function outside the main function. |
||
|
||
return pp.pprint(task.main(dicom_objects, report_path=report)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have you chosen to return the output outside of a pprint object? How does this effect the output the user sees?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not done to change the output the user sees, rather for me to be able to test the function because print returns NONE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean print returns none or pp.pprint returns none? Could you add some screenshots to example outputs to explain what you mean? I don't think we want to change this if we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lucrezia-Cester, would that mean that the user does not see the result printed to the command line when they run the SNR task? Could you try something like the below so we print the result and we also return a value?