Skip to content

Commit

Permalink
Fix merge conflict:
Browse files Browse the repository at this point in the history
  • Loading branch information
AlainKadar committed Nov 12, 2023
2 parents bda2839 + 0a3e272 commit d3fc250
Show file tree
Hide file tree
Showing 208 changed files with 5,496 additions and 23,150 deletions.
28 changes: 28 additions & 0 deletions ContributorAgreement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# StructuralGT Contributor Agreement

These terms apply to your contribution to the StructuralGT Open Source Project ("Project") owned or managed by the Regents of the University of Michigan ("Michigan"), and set out the intellectual property rights you grant to Michigan in the contributed materials. If this contribution is on behalf of a company, the term "you" will also mean the company you identify below. If you agree to be bound by these terms, fill in the information requested below and provide your signature.

1. The term "contribution" means any source code, object code, patch, tool, sample, graphic, specification, manual, documentation, or any other material posted or submitted by you to a project.
2. With respect to any worldwide copyrights, or copyright applications and registrations, in your contribution:
* you hereby assign to Michigan joint ownership, and to the extent that such assignment is or becomes invalid, ineffective or unenforceable, you hereby grant to Michigan a perpetual, irrevocable, non-exclusive, worldwide, no-charge, royalty-free, unrestricted license to exercise all rights under those copyrights. This includes, at Michigan's option, the right to sublicense these same rights to third parties through multiple levels of sublicensees or other licensing arrangements;
* you agree that both Michigan and you can do all things in relation to your contribution as if each of us were the sole owners, and if one of us makes a derivative work of your contribution, the one who makes the derivative work (or has it made) will be the sole owner of that derivative work;
* you agree that you will not assert any moral rights in your contribution against us, our licensees or transferees;
* you agree that we may register a copyright in your contribution and exercise all ownership rights associated with it; and
* you agree that neither of us has any duty to consult with, obtain the consent of, pay or render an accounting to the other for any use or distribution of your contribution.
3. With respect to any patents you own, or that you can license without payment to any third party, you hereby grant to Michigan a perpetual, irrevocable, non-exclusive, worldwide, no-charge, royalty-free license to:
* make, have made, use, sell, offer to sell, import, and otherwise transfer your contribution in whole or in part, alone or in combination with or included in any product, work or materials arising out of the project to which your contribution was submitted; and
* at Michigan's option, to sublicense these same rights to third parties through multiple levels of sublicensees or other licensing arrangements.
4. Except as set out above, you keep all right, title, and interest in your contribution. The rights that you grant to Michigan under these terms are effective on the date you first submitted a contribution to Michigan, even if your submission took place before the date you sign these terms. Any contribution Michigan makes available under any license will also be made available under a suitable Free Software Foundation or Open Source Initiative approved license.
5. With respect to your contribution, you represent that:
* it is an original work and that you can legally grant the rights set out in these terms;
* it does not to the best of your knowledge violate any third party's copyrights, trademarks, patents, or other intellectual property rights; and
you are authorized to sign this contract on behalf of your company (if identified below).
6. The terms will be governed by the laws of the State of Michigan and applicable U.S. Federal Law. Any choice of law rules will not apply.

**By making contribution, you electronically sign and agree to the terms of the StructuralGT Contributor Agreement.**

![by-sa.png](https://licensebuttons.net/l/by-sa/3.0/88x31.png)

Based on the Sun Contributor Agreement - version 1.5.
This document is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License
http://creativecommons.org/licenses/by-sa/3.0/
553 changes: 7 additions & 546 deletions LICENSE.txt

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=================
StructuralGTEdits
=================
============
StructuralGT
============

Overview
========
Expand All @@ -9,13 +9,13 @@ A python package for the extraction and analysis of graphs from 2D and 3D experi
Use
===
To use, clone, build, and install from the `GitHub repository
<https://github.com/AlainKadar/StructuralGTEdits>`__. You will need to install the cython, igraph, and eigen with conda.
<https://github.com/AlainKadar/StructuralGT>`__. You will need to install the cython, igraph, and eigen with conda.

.. code:: bash
conda install igraph eigen cython
git clone https://github.com/AlainKadar/StructuralGTEdits
cd StructuralGTEdits
git clone https://github.com/AlainKadar/StructuralGT
cd StructuralGT
python setup.py install
Example
Expand All @@ -24,7 +24,7 @@ The following minimal example shows how the package can be used to calculate the

.. code:: python
from StructuralGTEdits import physical_networks
from StructuralGT import physical_networks
Nanofibre3DNetwork = physical_networks.StructuralNetwork('Nanofibre_Image_Stack')
Nanofibre3DNetwork.binarize()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ def assignweights(ge, img_bin, weight_type=None, R_j=0, rho_dim=1):
wt = pix_width**2
elif(weight_type=='Length'):
wt = len(ge)
elif(weight_type=='InverseLength'):
wt = len(ge)**-1
else:
raise TypeError('Invalid weight type')

Expand Down
File renamed without changes.
Binary file not shown.
Binary file added StructuralGT/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file added StructuralGT/__pycache__/base.cpython-311.pyc
Binary file not shown.
Binary file added StructuralGT/__pycache__/error.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added StructuralGT/__pycache__/skel_ID.cpython-311.pyc
Binary file not shown.
Binary file not shown.
File renamed without changes.
132 changes: 32 additions & 100 deletions StructuralGTEdits/base.py → StructuralGT/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
#import sknwEdits as sknw
import igraph as ig
import gsd.hoomd
import pandas as pd
Expand Down Expand Up @@ -318,24 +317,24 @@ def debubble(g, elements):
canvas = skeletonize_3d(canvas)/255
canvas = binary_closing(canvas, footprint=elem)

g.skeleton = skeletonize_3d(canvas)/255
g._skeleton = skeletonize_3d(canvas)/255

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran debubble in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)
print('Ran debubble in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

Expand All @@ -345,25 +344,25 @@ def merge_nodes(g, disk_size):
start = time.time()
g.gsd_name = g.gsd_dir + '/merged_' + os.path.split(g.gsd_name)[1]

canvas = g.skeleton
g.skeleton = skel_ID.merge_nodes(canvas, disk_size)
canvas = g._skeleton
g._skeleton = skel_ID.merge_nodes(canvas, disk_size)

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran merge in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)
print('Ran merge in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

Expand All @@ -372,25 +371,25 @@ def prune(g, size):
start = time.time()
g.gsd_name = g.gsd_dir + '/pruned_' + os.path.split(g.gsd_name)[1]

canvas = g.skeleton
g.skeleton = skel_ID.pruning(canvas, size)
canvas = g._skeleton
g._skeleton = skel_ID.pruning(canvas, size)

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran prune in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)
print('Ran prune in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

Expand All @@ -399,27 +398,27 @@ def remove_objects(g, size):
start = time.time()
g.gsd_name = g.gsd_dir + '/cleaned_' + os.path.split(g.gsd_name)[1]

canvas = g.skeleton
g.skeleton = remove_small_objects(canvas, size, connectivity=2)
canvas = g._skeleton
g._skeleton = remove_small_objects(canvas, size, connectivity=2)

if g._2d:
g.skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g.skeleton_3d = np.asarray([g.skeleton])
g._skeleton_3d = np.swapaxes(np.array([g.skeleton]), 2, 1)
g._skeleton_3d = np.asarray([g.skeleton])
else:
g.skeleton_3d = np.asarray(g.skeleton)
g._skeleton_3d = np.asarray(g.skeleton)

positions = np.asarray(np.where(g.skeleton_3d!=0)).T
positions = np.asarray(np.where(g._skeleton_3d!=0)).T
with gsd.hoomd.open(name=g.gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = int(sum(g.skeleton_3d.ravel()))
s.particles.N = int(sum(g._skeleton_3d.ravel()))
s.particles.position = positions
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran remove objects in ', end-start, 'for an image with shape ', g.skeleton_3d.shape)

print('Ran remove objects in ', end-start, 'for an image with shape ', g._skeleton_3d.shape)

return g

def igraph_ANC(directory, I):
start = time.time()
Expand All @@ -439,73 +438,6 @@ def igraph_ANC(directory, I):

return ANC

#Skeletonize=False enables unusual case of writing binary stack to gsd without skeletonizing. Effective for creating direct 3d reconstruction.
#Takes directory where stack is located, and a gsd write filename
#Note when rotate=None, the crop acts upon an origin cornered image but when rotate != None, the image is origin centred and so the crop may contain -ve elements
def stack_to_gsd(stack_directory, gsd_name, crop=None, skeleton=True, rotate=None):
start = time.time()
img_bin=[]
#Initilise i such that it starts at the lowest number belonging to the images in the stack_directory
#First require boolean mask to filter out non image files
olist = np.asarray(sorted(os.listdir(stack_directory)))
mask = list(Q_img(olist[i]) for i in range(len(olist)))
if len(mask) == 0:
raise error.ImageDirectoryError(stack_directory)
name = sorted(olist[mask])[0] #First name
i = int(os.path.splitext(name)[0][5:]) #Strip file type and 'slice' then convert to int
#Generate 3d (or 2d) array from stack
for name in sorted(os.listdir(stack_directory)):
if Q_img(name):
img_slice = cv.imread(stack_directory+'/slice'+str(i)+'.tiff',cv.IMREAD_GRAYSCALE)
if rotate:
image_center = tuple(np.array(img_slice.shape[1::-1]) / 2)
rot_mat = cv.getRotationMatrix2D(image_center, rotate, 1.0)
img_slice = cv.warpAffine(img_slice, rot_mat, img_slice.shape[1::-1], flags=cv.INTER_LINEAR)
upper_directory = os.path.split(stack_directory)[0]
plt.imsave(upper_directory + '/rotated_image.tiff', img_slice, cmap=cm.gray)
img_bin.append(img_slice)
i=i+1
else:
pass
positions = np.asarray(np.where(np.asarray(img_bin) != 0)).T
positions = shift(positions)
if rotate and crop:
positions = oshift(positions)
from numpy import logical_and as a
p = positions.T
positions = p.T[a(a(a(a(a(p[0]>=crop[0],p[0]<=crop[1]),p[1]>=crop[2]),p[1]<=crop[3]),p[2]>=crop[4]),p[2]<=crop[5])]
positions = shift(positions)

if crop is not None and rotate is None:
from numpy import logical_and as a
p = positions.T
positions = p.T[a(a(a(a(a(p[0]>=crop[0],p[0]<=crop[1]),p[1]>=crop[2]),p[1]<=crop[3]),p[2]>=crop[4]),p[2]<=crop[5])]

positions = positions.astype(int)
dims = np.asarray(list(max(positions.T[i])+1 for i in (0,1,2)))
canvas = np.zeros(dims)
canvas[positions.T[0], positions.T[1], positions.T[2]] = 1
img_bin = canvas

#Roll axes such that z=0 for all positions when the graph is 2D
img_bin = np.swapaxes(img_bin, 0, 2)
if skeleton:
img_bin = skeletonize_3d(np.asarray(img_bin))
else:
img_bin = np.asarray(img_bin)
positions = np.asarray(np.where(img_bin != 0)).T



with gsd.hoomd.open(name=gsd_name, mode='w') as f:
s = gsd.hoomd.Frame()
s.particles.N = len(positions)
s.particles.position = shift(positions)
s.particles.types = ['A']
s.particles.typeid = ['0']*s.particles.N
f.append(s)
end = time.time()
print('Ran stack_to_gsd() in ', end-start, 'for gsd with ', len(positions), 'particles')

def add_weights(g, weight_type=None, R_j=0, rho_dim=1):
if not isinstance(weight_type,list) and weight_type is not None: raise TypeError('weight_type must be list, even if single element')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit d3fc250

Please sign in to comment.