Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ build-docs:
cd docs && make html

dev:
pip install black==21.4b2 coverage isort flake8 flake8-bugbear flake8-comprehensions
pip install black==22.3.0 coverage isort flake8 flake8-bugbear flake8-comprehensions
pip install --upgrade mistune==0.8.4 sphinx sphinx-rtd-theme recommonmark m2r2
pip install -r docs/requirements.txt

Expand Down
10 changes: 5 additions & 5 deletions dosma/core/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,11 +935,11 @@ def _compute_r2_matrix(_x, _y, _popts):
xp = get_array_module(_y)

_x = _x.flatten()
_xs = xp.stack([_x ** i for i in range(len(_popts) - 1, -1, -1)], axis=-1)
_xs = xp.stack([_x**i for i in range(len(_popts) - 1, -1, -1)], axis=-1)
yhat = _xs @ _popts # (M, K)

residuals = yhat - _y
ss_res = xp.sum(residuals ** 2, axis=0)
ss_res = xp.sum(residuals**2, axis=0)
ss_tot = xp.sum((_y - xp.mean(_y, axis=0, keepdims=True)) ** 2, axis=0)
return 1 - (ss_res / (ss_tot + eps))

Expand Down Expand Up @@ -1030,7 +1030,7 @@ def _fit_internal(_x, _y):
popt, _ = sop.curve_fit(func, _x, _y, p0=p0, ftol=ftol, **kwargs)

residuals = _y - func(_x, *popt)
ss_res = np.sum(residuals ** 2)
ss_res = np.sum(residuals**2)
ss_tot = np.sum((_y - np.mean(_y)) ** 2)
r_squared = 1 - (ss_res / (ss_tot + eps))

Expand Down Expand Up @@ -1078,7 +1078,7 @@ def _fit_internal(_x, _y):
popt = xp.polyfit(_x, _y, deg, rcond=rcond, w=w)

residuals = _y - xp.polyval(popt, _x)
ss_res = xp.sum(residuals ** 2)
ss_res = xp.sum(residuals**2)
ss_tot = xp.sum((_y - xp.mean(_y)) ** 2)
r_squared = 1 - (ss_res / (ss_tot + eps))

Expand Down Expand Up @@ -1178,7 +1178,7 @@ def func(t, a, b):
popt, _ = sop.curve_fit(func, x, y, p0=p0, maxfev=100, ftol=1e-5)

residuals = y - func(x, popt[0], popt[1])
ss_res = np.sum(residuals ** 2)
ss_res = np.sum(residuals**2)
ss_tot = np.sum((y - np.mean(y)) ** 2)

r_squared = 1 - (ss_res / (ss_tot + __EPSILON__))
Expand Down
4 changes: 2 additions & 2 deletions dosma/core/io/dicom_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,8 +687,8 @@ def _update_np_dtype(arr: np.ndarray, bit_depth: int):
dtype_dict = {
8: [(np.int8, -128, 127), (np.uint8, 0, 255)],
16: [
(np.uint16, 0, 2 ** 16 - 1),
(np.int16, -(2 ** 15), 2 ** 15),
(np.uint16, 0, 2**16 - 1),
(np.int16, -(2**15), 2**15),
(np.float16, -6.55e4, 6.55e4 - 1),
],
}
Expand Down
2 changes: 1 addition & 1 deletion dosma/core/med_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ def volume(self, value):
def pixel_spacing(self):
"""tuple[float]: Pixel spacing in order of current orientation."""
vecs = self._affine[:3, :3]
ps = tuple(np.sqrt(np.sum(vecs ** 2, axis=0)))
ps = tuple(np.sqrt(np.sum(vecs**2, axis=0)))

assert len(ps) == 3, "Pixel spacing must have length of 3"
return ps
Expand Down
4 changes: 2 additions & 2 deletions dosma/models/oaiunet2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __load_keras_model__(self, input_shape, force_weights=False):
if type(input_shape) is not tuple or len(input_shape) != 3 or input_shape[2] != 1:
raise ValueError("input_size must be a tuple of size (height, width, 1)")

nfeatures = [2 ** feat * 32 for feat in np.arange(6)]
nfeatures = [2**feat * 32 for feat in np.arange(6)]
depth = len(nfeatures)

conv_ptr = []
Expand Down Expand Up @@ -198,7 +198,7 @@ def __load_keras_model__(self, input_shape):
if type(input_shape) is not tuple or len(input_shape) != 3 or input_shape[2] != 1:
raise ValueError("input_size must be a tuple of size (height, width, 1)")

nfeatures = [2 ** feat * 32 for feat in np.arange(6)]
nfeatures = [2**feat * 32 for feat in np.arange(6)]
depth = len(nfeatures)

conv_ptr = []
Expand Down
4 changes: 2 additions & 2 deletions dosma/models/stanford_qdess.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __load_keras_model__(self, input_shape):
if type(input_shape) is not tuple or len(input_shape) != 3 or input_shape[2] != 1:
raise ValueError("input_size must be a tuple of size (height, width, 1)")

nfeatures = [2 ** feat * 32 for feat in np.arange(6)]
nfeatures = [2**feat * 32 for feat in np.arange(6)]
depth = len(nfeatures)

conv_ptr = []
Expand Down Expand Up @@ -170,7 +170,7 @@ def generate_mask(self, volume: MedicalVolume):

vol_copy = deepcopy(volume)
if ndim == 4:
vol_copy = np.sqrt(np.sum(vol_copy ** 2, axis=-1))
vol_copy = np.sqrt(np.sum(vol_copy**2, axis=-1))

# reorient to the sagittal plane
vol_copy.reformat(SAGITTAL, inplace=True)
Expand Down
4 changes: 2 additions & 2 deletions dosma/scan_sequences/mri/qdess.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ def _combine_echoes(self, method="rss"):
assert (~xp.iscomplex(echo1)).all() and (~xp.iscomplex(echo2)).all()

if method == "rss":
vol = xp.sqrt(echo1 ** 2 + echo2 ** 2)
vol = xp.sqrt(echo1**2 + echo2**2)
elif method == "rms":
vol = xp.sqrt((echo1 ** 2 + echo2 ** 2) / 2)
vol = xp.sqrt((echo1**2 + echo2**2) / 2)
else:
raise ValueError(f"`method={method}` is not supported")

Expand Down
16 changes: 8 additions & 8 deletions dosma/tissues/femoral_cartilage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ class FemoralCartilage(Tissue):
# Keys correspond to integer representing bit location for each region
# bit string: 'T D S M L A C P' (stored as integer)
# Coronal Keys
_POSTERIOR_KEY = 2 ** 0
_CENTRAL_KEY = 2 ** 1
_ANTERIOR_KEY = 2 ** 2
_POSTERIOR_KEY = 2**0
_CENTRAL_KEY = 2**1
_ANTERIOR_KEY = 2**2
_CORONAL_KEYS = [_POSTERIOR_KEY, _CENTRAL_KEY, _ANTERIOR_KEY]

# Sagittal Keys
_MEDIAL_KEY = 2 ** 3
_LATERAL_KEY = 2 ** 4
_MEDIAL_KEY = 2**3
_LATERAL_KEY = 2**4
_SAGITTAL_KEYS = [_MEDIAL_KEY, _LATERAL_KEY]

# Axial Keys
_DEEP_KEY = 2 ** 5
_SUPERFICIAL_KEY = 2 ** 6
_TOTAL_AXIAL_KEY = 2 ** 7
_DEEP_KEY = 2**5
_SUPERFICIAL_KEY = 2**6
_TOTAL_AXIAL_KEY = 2**7
_AXIAL_KEYS = [_DEEP_KEY, _SUPERFICIAL_KEY, _TOTAL_AXIAL_KEY]

# Do not change order of below.
Expand Down
2 changes: 1 addition & 1 deletion dosma/utils/geometry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def cart2pol(x, y):
Returns:
tuple[float, float]: radius (rho) and angle (phi).
"""
rho = np.sqrt(x ** 2 + y ** 2)
rho = np.sqrt(x**2 + y**2)
phi = np.arctan2(y, x)

phi = phi * (180 / np.pi) # degrees
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def run(self):
"flake8-bugbear",
"flake8-comprehensions",
"isort",
"black==21.4b2",
"black==22.3.0",
"simpleitk",
"sphinx",
"sphinxcontrib.bibtex",
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_med_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_math(self):
assert np.all(mv2._volume == 2)
assert np.all(out._volume == 0)

out = mv1 ** mv2
out = mv1**mv2
assert np.all(mv1._volume == 1)
assert np.all(mv2._volume == 2)
assert np.all(out._volume == 1)
Expand Down