Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground #57

Merged
merged 3 commits into from
Feb 14, 2024
Merged
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
7 changes: 5 additions & 2 deletions src/deep_neurographs/swc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions src/deep_neurographs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading