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

Dbodor/prospector fixes #95

Open
wants to merge 8 commits into
base: dbodor/tdd_collapsed
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
27 changes: 9 additions & 18 deletions cvasl/carve.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
from abc import ABC, abstractmethod


from datetime import datetime, date
from datetime import date

import pandas as pd
import SimpleITK as sitk

import numpy
from datetime import datetime, date
import pydicom as dicom
import pandas as pd
import skimage.io as io

from pydicom.multival import MultiValue
from pydicom.sequence import Sequence

Expand Down Expand Up @@ -118,10 +113,10 @@ def get_tag(self):
return self.tag

def items(self, reader, transformer=None):
for file in glob(self.exp, recursive=self.recursive):
for file in glob(self.exp, recursive=self.recursive): #TODO: glob is not callable, what are we trying to loop over here
parsed = reader(file)
if transformer is not None:
full_path = transformer(file)
self.full_path = transformer(file)
yield file, parsed


Expand All @@ -143,7 +138,7 @@ def items(self, reader, transformer=None):
def rename_file(original, target, ext):
dst_file = os.path.basename(original)
dst_file = os.path.splitext(dst_file)[0]
return os.path.join(target, '{}.{}'.format(dst_file, ext))
return os.path.join(target, f'{dst_file}.{ext}')


class PydicomDicomReader:
Expand Down Expand Up @@ -205,6 +200,8 @@ def __init__(
self.exclude_field_types = exclude_field_types
if date_fields:
self.date_fields = date_fields
if time_fields:
self.time_fields = time_fields
if exclude_fields:
self.exclude_fields = exclude_fields

Expand Down Expand Up @@ -263,12 +260,6 @@ def read(self, source):
return pd.DataFrame(columns)


def rename_file(original, target, ext):
dst_file = os.path.basename(original)
dst_file = os.path.splitext(dst_file)[0]
return os.path.join(target, '{}.{}'.format(dst_file, ext))


tag_dictionary = { # 'key' , 'datapoint_name'
'0002|0000': 'File Meta Information Group Length',
'0002|0001': 'File Meta Information Version',
Expand Down Expand Up @@ -438,7 +429,7 @@ def fetch_image(self, dicom_file):
# not a file name.
self.reader.SetFileName(dicom_file)
dcm = self.reader.Execute()
return sitk.GetArrayFromImage(image)
return sitk.GetArrayFromImage(dcm) #TODO check that dcm is correct parameter instead of `image`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is what you meant, correct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do anything on any function that deals with images directly, because we don't have them. You are probably right, but this worked on some version of an image I had. Please hold off until we have our actual images to repair carve.



class SimpleITKDicomReader:
Expand Down Expand Up @@ -567,9 +558,9 @@ def rip_out_array_sitk(dicomfile_directory):
dicom_files = glob.glob(dicomfile_directory + '/*')
reader = sitk.ImageFileReader()
saved_images = []
for i in range(len(dicom_files)):
for file in dicom_files:
# give the reader a filename
reader.SetFileName(dicom_files[i])
reader.SetFileName(file)
# use the reader to read the image
image = reader.Execute()
image_np = sitk.GetArrayFromImage(image)
Expand Down
2 changes: 1 addition & 1 deletion cvasl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def make_parser():
return parser


def main(argv):
def main(argv): #pylint: disable=unused-argument
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it required to pass an argument here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I am used to dealing with command-line argparse. I suppose there could be some clever way to write it without an argument,,, but I don't know it.

"""
This runs the parser and subparsers.
"""
Expand Down
20 changes: 6 additions & 14 deletions cvasl/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
import textwrap
import hashlib
import glob
import math
import pandas as pd
import numpy as np
import scipy
from scipy import signal
import random


class Config:
Expand Down Expand Up @@ -110,13 +105,13 @@ def load(self, location):
found = None
for p in locations:
try:
with open(p) as f:
with open(p, encoding="utf-8") as f:
self._raw = json.load(f)
found = p
break
except json.JSONDecodeError as e:
raise ValueError(
'Cannot parse configuration in {}'.format(p),
f'Cannot parse configuration in {p}',
) from e
except Exception as e:
logging.info('Configuration not found in %s: %s', p, e)
Expand All @@ -128,11 +123,10 @@ def load(self, location):
if root is None:
required = dict(self.default_layout)
del required['bids']
for directory in required.keys():
for directory in required:
if directory not in self._raw:
raise ValueError(
'Configuration in {} is missing required directory {}'
.format(found, directory),
f'Configuration in {found} is missing required directory {directory}',
)
# User specified all concrete directories. Nothing for us to
# do here.
Expand All @@ -150,10 +144,8 @@ def validate(self):
for d in self.required_directories:
if not os.path.isdir(self._loaded[d]):
raise ValueError(
'Required directory {}: {} doesn\'t exist'.format(
d,
self._loaded[d],
))
f'Required directory {d}: {self._loaded[d]} does not exist'
)

def get_directory(self, directory, value=None):
if value is None:
Expand Down
9 changes: 6 additions & 3 deletions cvasl/mold.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os
import glob
import numpy as np
from ipywidgets import IntSlider, Output
import ipywidgets as widgets
import matplotlib.pyplot as plt

Expand Down Expand Up @@ -109,7 +108,7 @@ def plot_slice(self, z):

def n4_debias_sitk(
image_filename,
iteration_vector=[20, 10, 10, 5],
iteration_vector=None,
masking=True
):
"""
Expand All @@ -119,6 +118,10 @@ def n4_debias_sitk(
Need to cite SITK
"""
# TODO: add sitk citation in docstring,

if iteration_vector is None:
iteration_vector = [20, 10, 10, 5]

inputImage = sitk.ReadImage(image_filename)
bits_in_input = inputImage.GetPixelIDTypeAsString()
bit_dictionary = {"Signed 8 bit integer": sitk.sitkInt8,
Expand Down Expand Up @@ -191,7 +194,7 @@ def debias_folder(file_directory, algorithm, processed, force=False):
if algorithm == 'n4_debias_sitk':
array = n4_debias_sitk(file)
elif algorithm == 'alternative_debias_a':
array = alternative_debias_a(file)
array = alternative_debias_a(file) #TODO: what is this?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function doesn't exist. Is it a future to do? In that case, shall we just raise a NotImplementedError for now and add a #TODO about it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly @DaniBodor it's a function we didn't write. And since it deals with images, we should hold off until we are working on images.


else:
array = n4_debias_sitk(file)
Expand Down
8 changes: 3 additions & 5 deletions cvasl/seperated.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import copy
import glob
import os

Expand Down Expand Up @@ -83,11 +82,11 @@ def relate_columns_graphs(dataframe, special_column_name):
a = len(col) # number of rows
b = 1 # number of columns
c = 1 # initialize plot counter
fig = plt.figure(figsize=(10, (len(col)*10)))
fig = plt.figure(figsize=(10, (len(col)*10))) # noqa=F841, pylint: disable=unused-variable
for i in col:
plt.subplot(a, b, c)
plt.scatter(dataframe[i].apply(pd.to_numeric), y)
plt.title('{}, subplot: {}{}{}'.format(i, a, b, c))
plt.title(f'{i}, subplot: {a}{b}{c}')
plt.xlabel(i)
c = c + 1
plt.savefig(("versus" + special_column_name + ".png"))
Expand Down Expand Up @@ -155,8 +154,7 @@ def generate_transformation_matrix(polynomial1, polynomial2):
for i, (c1, c2) in enumerate(zip(polynomial1, polynomial2)):
m[i][i] = c2/c1

return m

return m


def find_original_y_values(polynomial, output_value):
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ dependencies:
- numexpr=2.7.3
- numpy=1.22.3
- pandas
- pydicom
- pycodestyle
- scipy=1.7.3
- scikit-image=0.19.2
- seaborn
- simpleitk=2.2.1
- sphinx=4.5.0
- pydicom



Expand Down