From 707f72475b5f1d104cd4e6dd488b3124375790b7 Mon Sep 17 00:00:00 2001 From: Neil Shephard Date: Fri, 17 Nov 2023 16:03:14 +0000 Subject: [PATCH] More undos --- src/skan/csr.py | 23 +++++++++++------------ src/skan/pipe.py | 12 +++--------- src/skan/test/test_csr.py | 2 +- src/skan/test/test_skeleton_class.py | 4 +++- src/skan/test/test_summary_utils.py | 7 ++++--- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/skan/csr.py b/src/skan/csr.py index 9db5a4a2..3ee461bb 100644 --- a/src/skan/csr.py +++ b/src/skan/csr.py @@ -189,7 +189,7 @@ def has_node_props(self): def csr_to_nbgraph(csr, node_props=None): if node_props is None: - node_props = np.broadcast_to(1, csr.shape[0]) + node_props = np.broadcast_to(1., csr.shape[0]) node_props.flags.writeable = True return NBGraph( csr.indptr, csr.indices, csr.data, @@ -385,9 +385,9 @@ def _build_skeleton_path_graph(graph): visited_data = np.zeros(graph.data.shape, dtype=bool) visited = NBGraphBool( graph.indptr, graph.indices, visited_data, graph.shape, - np.broadcast_to(1, graph.shape[0]) + np.broadcast_to(1., graph.shape[0]) ) - endpoints = degrees != 2 + endpoints = (degrees != 2) endpoint_degrees = degrees[endpoints] num_paths = np.sum(endpoint_degrees) path_indptr = np.zeros(num_paths + buffer_size_offset, dtype=int) @@ -398,9 +398,10 @@ def _build_skeleton_path_graph(graph): # cycles (since each cycle has one index repeated). We don't know # the number of cycles ahead of time, but it is bounded by one quarter # of the number of points. - n_points = graph.indices.size + np.sum( - np.maximum(0, endpoint_degrees - 1) - ) + buffer_size_offset + n_points = ( + graph.indices.size + np.sum(np.maximum(0, endpoint_degrees - 1)) + + buffer_size_offset + ) path_indices = np.zeros(n_points, dtype=int) path_data = np.zeros(path_indices.shape, dtype=float) m, n = _build_paths( @@ -762,9 +763,9 @@ def summarize( [coords_real_dst, values_dst[:, np.newaxis]], axis=1, ) - summary['euclidean_distance'] = np.sqrt( - (coords_real_dst - coords_real_src)**2 - @ np.ones(ndim + int(value_is_height)) + summary['euclidean_distance'] = ( + np.sqrt((coords_real_dst - coords_real_src)**2 + @ np.ones(ndim + int(value_is_height))) ) df = pd.DataFrame(summary) @@ -1010,13 +1011,11 @@ def make_degree_image(skeleton_image): degree_kernel, mode='constant', ) * bool_skeleton - # use dask image for any array other than a numpy array (which isn't # supported yet anyway) else: import dask.array as da from dask_image.ndfilters import convolve as dask_convolve - if isinstance(bool_skeleton, da.Array): degree_image = bool_skeleton * dask_convolve( bool_skeleton.astype(int), degree_kernel, mode='constant' @@ -1131,7 +1130,7 @@ def _normalize_shells(shells, *, center, skeleton_coordinates, spacing): 'the spacing between shells is smaller than the (diagonal) ' f'voxel spacing. The given voxel spacing is {sp}, and the ' f'smallest shell spacing is {sh}.', - stacklevel=2, + stacklevel=2 ) return shell_radii diff --git a/src/skan/pipe.py b/src/skan/pipe.py index aac1e6b2..1310a000 100644 --- a/src/skan/pipe.py +++ b/src/skan/pipe.py @@ -140,15 +140,9 @@ def process_images( with ThreadPoolExecutor(max_workers=num_threads) as ex: future_data = { ex.submit( - process_single_image, - filename, - image_format, - scale_metadata_path, - threshold_radius, - smooth_radius, - brightness_offset, - crop_radius, - smooth_method, + process_single_image, filename, image_format, + scale_metadata_path, threshold_radius, smooth_radius, + brightness_offset, crop_radius, smooth_method ): filename for filename in filenames } diff --git a/src/skan/test/test_csr.py b/src/skan/test/test_csr.py index b1911440..c7117418 100644 --- a/src/skan/test/test_csr.py +++ b/src/skan/test/test_csr.py @@ -201,7 +201,7 @@ def test_transpose_image(): [0, 3, 2, 0, 1, 1, 0], [3, 0, 0, 4, 0, 0, 0], [3, 0, 0, 0, 4, 4, 4]]) ), - ], + ] ) def test_prune_paths( skeleton: np.ndarray, prune_branch: int, target: np.ndarray diff --git a/src/skan/test/test_skeleton_class.py b/src/skan/test/test_skeleton_class.py index 22b22d30..1bc68377 100644 --- a/src/skan/test/test_skeleton_class.py +++ b/src/skan/test/test_skeleton_class.py @@ -5,7 +5,9 @@ import pytest from skan.csr import Skeleton, summarize -from skan._testdata import tinycycle, skeleton1, skeleton2, skeleton3d, skeleton4, junction_first +from skan._testdata import ( + tinycycle, skeleton1, skeleton2, skeleton3d, skeleton4, junction_first + ) def test_tiny_cycle(): diff --git a/src/skan/test/test_summary_utils.py b/src/skan/test/test_summary_utils.py index e76d620d..d3a0448c 100644 --- a/src/skan/test/test_summary_utils.py +++ b/src/skan/test/test_summary_utils.py @@ -16,6 +16,7 @@ def test_find_main(): coords = non_main_df[[ 'coord_src_0', 'coord_src_1', 'coord_dst_0', 'coord_dst_1' ]].to_numpy() - assert np.all( - coords == non_main_edge_start + non_main_edge_finish - ) or np.all(coords == non_main_edge_finish + non_main_edge_start) + assert ( + np.all(coords == non_main_edge_start + non_main_edge_finish) + or np.all(coords == non_main_edge_finish + non_main_edge_start) + )