diff --git a/src/deep_neurographs/swc_utils.py b/src/deep_neurographs/swc_utils.py index fd615af..fa76973 100644 --- a/src/deep_neurographs/swc_utils.py +++ b/src/deep_neurographs/swc_utils.py @@ -46,7 +46,10 @@ def process_gsc_zip(bucket, zip_path, min_size=0): for thread in as_completed(threads): swc_id, result = thread.result() if len(result["id"]) > min_size: - swc_dicts[swc_id] = result + try: + swc_dicts[swc_id] = result + except Exception as err: + print(f"{swc_id} - {err}=, {type(err)}=") return swc_dicts @@ -292,7 +295,6 @@ def write_graph(path, graph, color=None): entry, reindex = make_entry(graph, j, reindex[i], r, reindex) entry_list.append(entry) write_list(path, entry_list) - print("finished") def set_radius(graph, i): @@ -301,6 +303,7 @@ def set_radius(graph, i): except: return 2 + def make_entry(graph, i, parent, r, reindex): """ Makes an entry to be written in an swc file. diff --git a/src/deep_neurographs/utils.py b/src/deep_neurographs/utils.py index 39f4f3a..fa68738 100644 --- a/src/deep_neurographs/utils.py +++ b/src/deep_neurographs/utils.py @@ -429,6 +429,26 @@ def write_txt(path, contents): f.close() +# --- coordinate conversions --- +def img_to_patch(xyz, patch_centroid, patch_dims): + half_patch_dims = [patch_dims[i] // 2 for i in range(3)] + patch_coord = xyz - patch_centroid + half_patch_dims + return tuple(patch_coord.astype(int)) + + +def patch_to_img(xyz, patch_centroid, patch_dims): + half_patch_dims = [patch_dims[i] // 2 for i in range(3)] + return np.round(xyz + patch_centroid - half_patch_dims).astype(int) + + +def to_world(xyz, shift=[0, 0, 0]): + return tuple([xyz[i] * ANISOTROPY[i] - shift[i] for i in range(3)]) + + +def to_img(xyz): + return (xyz / ANISOTROPY).astype(int) + + # --- math utils --- def get_avg_std(data, weights=None): avg = np.average(data, weights=weights)