Skip to content

Commit

Permalink
More undos
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-rse committed Nov 17, 2023
1 parent bc64ef9 commit 707f724
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
23 changes: 11 additions & 12 deletions src/skan/csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down
12 changes: 3 additions & 9 deletions src/skan/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/skan/test/test_csr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/skan/test/test_skeleton_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
7 changes: 4 additions & 3 deletions src/skan/test/test_summary_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

0 comments on commit 707f724

Please sign in to comment.