From 20b977ee350034871091c17bf429b49ec99b467a Mon Sep 17 00:00:00 2001 From: Arjun Desai Date: Thu, 31 Mar 2022 22:42:00 -0700 Subject: [PATCH 1/2] upgrade black to 22.3.0 --- Makefile | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6eda475..b131cbf 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/setup.py b/setup.py index 630c0be..c56ee6d 100644 --- a/setup.py +++ b/setup.py @@ -125,7 +125,7 @@ def run(self): "flake8-bugbear", "flake8-comprehensions", "isort", - "black==21.4b2", + "black==22.3.0", "simpleitk", "sphinx", "sphinxcontrib.bibtex", From e3b0a8ddd26126e512eb05a0f940f37ff22789a0 Mon Sep 17 00:00:00 2001 From: Arjun Desai Date: Thu, 31 Mar 2022 22:43:34 -0700 Subject: [PATCH 2/2] run black 0.22.3 on code --- dosma/core/fitting.py | 10 +++++----- dosma/core/io/dicom_io.py | 4 ++-- dosma/core/med_volume.py | 2 +- dosma/models/oaiunet2d.py | 4 ++-- dosma/models/stanford_qdess.py | 4 ++-- dosma/scan_sequences/mri/qdess.py | 4 ++-- dosma/tissues/femoral_cartilage.py | 16 ++++++++-------- dosma/utils/geometry_utils.py | 2 +- tests/core/test_med_volume.py | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/dosma/core/fitting.py b/dosma/core/fitting.py index 2dedccd..b14e816 100644 --- a/dosma/core/fitting.py +++ b/dosma/core/fitting.py @@ -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)) @@ -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)) @@ -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)) @@ -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__)) diff --git a/dosma/core/io/dicom_io.py b/dosma/core/io/dicom_io.py index 3ea5d82..a97c30c 100644 --- a/dosma/core/io/dicom_io.py +++ b/dosma/core/io/dicom_io.py @@ -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), ], } diff --git a/dosma/core/med_volume.py b/dosma/core/med_volume.py index 3ac2ee4..ac52dcc 100644 --- a/dosma/core/med_volume.py +++ b/dosma/core/med_volume.py @@ -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 diff --git a/dosma/models/oaiunet2d.py b/dosma/models/oaiunet2d.py index 9910d47..1dd4a0f 100644 --- a/dosma/models/oaiunet2d.py +++ b/dosma/models/oaiunet2d.py @@ -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 = [] @@ -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 = [] diff --git a/dosma/models/stanford_qdess.py b/dosma/models/stanford_qdess.py index d83f48b..c133e6b 100644 --- a/dosma/models/stanford_qdess.py +++ b/dosma/models/stanford_qdess.py @@ -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 = [] @@ -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) diff --git a/dosma/scan_sequences/mri/qdess.py b/dosma/scan_sequences/mri/qdess.py index 3358b24..5adda0a 100644 --- a/dosma/scan_sequences/mri/qdess.py +++ b/dosma/scan_sequences/mri/qdess.py @@ -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") diff --git a/dosma/tissues/femoral_cartilage.py b/dosma/tissues/femoral_cartilage.py index e5832e7..e1e9cb1 100644 --- a/dosma/tissues/femoral_cartilage.py +++ b/dosma/tissues/femoral_cartilage.py @@ -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. diff --git a/dosma/utils/geometry_utils.py b/dosma/utils/geometry_utils.py index c46f137..c1061ce 100644 --- a/dosma/utils/geometry_utils.py +++ b/dosma/utils/geometry_utils.py @@ -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 diff --git a/tests/core/test_med_volume.py b/tests/core/test_med_volume.py index aa7aa41..d928d4e 100644 --- a/tests/core/test_med_volume.py +++ b/tests/core/test_med_volume.py @@ -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)